PHP Classes

File: tests/apps/filter.php

Recommend this page to a friend!
  Classes of Cesar D. Rodas  >  PHP JSON API Server  >  tests/apps/filter.php  >  Download  
File: tests/apps/filter.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP JSON API Server
Handle REST API requests with functions in scripts
Author: By
Last change:
Date: 4 years ago
Size: 1,297 bytes
 

Contents

Class file image Download
<?php

/**
 * @preRoute xxx
 */
function filter_xx(Array $args)
{
    throw new
RuntimeException("Failed exception");
}

function
is_prime($x) {
   
$middle = ceil($x/2);
    for (
$i = 2; $i <= $middle; ++$i) {
        if (
$x % $i === 0) {
            return
false;
        }
    }

    return
true;
}

/**
 * @initRequest do_fail
 */
function do_fail_initreq()
{
    throw new \
Exception;
}

/**
 * @initRequest retry_later
 */
function retry_later_init(Array $requests, $server) {
    throw new
JSONful\RetryException;
}

/**
 * @initRequest is_prime3
 */
function filter_prime_x(Array $requests, $server)
{
    foreach (
$requests as &$request) {
       
$request['result'] = is_prime($request['q']);
    }
}

/**
 * @initRequest
 */
function filter_prime_1(Array $requests, $server)
{
   
$is_prime = array();
    foreach (
$requests['requests'] as $request) {
        if (
$request[0] === 'is_prime') {
           
$is_prime[$request[1]['q']] = is_prime($request[1]['q']);
        }
    }
   
$server['is_prime'] = $is_prime;
}

/**
 * @initRequest
 */
function filter_prime_2(Array &$requests, $server)
{
    foreach (
$requests['requests'] as &$request) {
        if (
$request[0] === 'is_prime_2') {
           
$request[1]['result'] = is_prime($request[1]['q']);
        }
    }
}

For more information send a message to info at phpclasses dot org.