Exemplo n.º 1
0
 /**
  * Static method to create your threads from functions ...
  **/
 public static function call($method, $params)
 {
     $thread = new Caller($method, $params);
     if ($thread->start()) {
         return $thread;
     }
 }
Exemplo n.º 2
0
function mycheck($person, $expected)
{
    $debug = 0;
    # Normal target language polymorphic call
    $ret = $person->id();
    if ($debug) {
        print $ret . "\n";
    }
    check::equal($ret, $expected, "#1 failed");
    # Polymorphic call from C++
    $caller = new Caller();
    $caller->setCallback($person);
    $ret = $caller->call();
    if ($debug) {
        print $ret . "\n";
    }
    check::equal($ret, $expected, "#2 failed");
    # Polymorphic call of object created in target language and passed to
    # C++ and back again
    $baseclass = $caller->baseClass();
    $ret = $baseclass->id();
    if ($debug) {
        print $ret . "\n";
    }
    # TODO: Currently we do not track the dynamic type of returned
    # objects, so in case it's possible that the dynamic type is not equal
    # to the static type, we skip this check.
    if (get_parent_class($person) === false) {
        check::equal($ret, $expected, "#3 failed");
    }
    $caller->resetCallback();
    if ($debug) {
        print "----------------------------------------\n";
    }
}
Exemplo n.º 3
0
 /**
  * Static method to create your threads from functions ...
  **/
 public static function call($method, $params)
 {
     $thread = new Caller($method, $params);
     if ($thread->start()) {
         return $thread;
     }
     /** else throw Nastyness **/
 }
Exemplo n.º 4
0
 private function load()
 {
     if ($this->response) {
         // avoids unnecessary request to the following page after the last one
         $itemsPerPage = $this->response->message->{'items-per-page'};
         $lastPage = ceil($this->count() / $itemsPerPage - 1);
         if ($this->page > $lastPage) {
             $this->items = new \ArrayIterator([]);
             return;
         }
         $offset = $this->page * $itemsPerPage;
     } else {
         $offset = 0;
     }
     $this->parameters['offset'] = $offset;
     $this->response = $this->caller->request($this->resource, $this->parameters);
     $this->items = new \ArrayIterator($this->response->message->items);
 }
Exemplo n.º 5
0
 /**
  * validates getErrors works as expected
  *
  * @author Daniel Sherman
  * @test
  * @depends testConstruct
  * @covers ::getErrors
  */
 public function testGetErrors()
 {
     $test = new Caller('is_string', 'Hello World!');
     $this->assertEquals(['Hello World!'], $test->getErrors());
     $msg = '_Hello_ _World_!';
     $rep = new \Flair\Validation\Replacer(['Hello' => 'Hi', 'World' => 'People']);
     $test = new Caller('is_string', $msg, [], $rep);
     $this->assertEquals(['Hi People!'], $test->getErrors());
 }
<?php

require "tests.php";
require "director_pass_by_value.php";
$passByVal = null;
class director_pass_by_value_Derived extends DirectorPassByValueAbstractBase
{
    function virtualMethod($b)
    {
        global $passByVal;
        $passByVal = $b;
    }
}
# bug was the passByVal global object was destroyed after the call to virtualMethod had finished.
$caller = new Caller();
$caller->call_virtualMethod(new director_pass_by_value_Derived());
$ret = $passByVal->getVal();
if ($ret != 0x12345678) {
    check::fail("Bad return value, got " . dechex($ret));
}
check::done();
Exemplo n.º 7
0
 public static function getAllCountries()
 {
     $caller = new Caller("http://api.worldbank.org/fr/countries?format=json&per_page=262");
     $datas = $caller->dispatch()[1];
     $countries = array();
     foreach ($datas as $country) {
         if ($country->name === "") {
             continue;
         }
         if ($country->region->value === "Agrégats") {
             continue;
         }
         $countries[] = $country->name;
     }
     return $countries;
 }
Exemplo n.º 8
0
    die('skip ZendEngine 2 needed');
}
?>
--FILE--
<?php 
class Caller
{
    public $x = array(1, 2, 3);
    function __call($m, $a)
    {
        echo "Method {$m} called:\n";
        var_dump($a);
        return $this->x;
    }
}
$foo = new Caller();
$a = $foo->test(1, '2', 3.4, true);
var_dump($a);
?>
--EXPECT--
Method test called:
array(4) {
  [0]=>
  int(1)
  [1]=>
  string(1) "2"
  [2]=>
  float(3.4)
  [3]=>
  bool(true)
}
Exemplo n.º 9
0
<?php

# This file illustrates the cross language polymorphism using directors.
require "example.php";
# Class, which overwrites Callback::run().
class PhpCallback extends Callback
{
    function run()
    {
        print "PhpCallback.run()\n";
    }
}
# Create an Caller instance
$caller = new Caller();
# Add a simple C++ callback (caller owns the callback, so
# we disown it first by clearing the .thisown flag).
print "Adding and calling a normal C++ callback\n";
print "----------------------------------------\n";
$callback = new Callback();
$callback->thisown = 0;
$caller->setCallback($callback);
$caller->call();
$caller->delCallback();
print "\n";
print "Adding and calling a PHP callback\n";
print "------------------------------------\n";
# Add a PHP callback.
$callback = new PhpCallback();
$callback->thisown = 0;
$caller->setCallback($callback);
$caller->call();
Exemplo n.º 10
0
{
    protected static $_apiActionToRequestPath = array('search' => 'RestAPI/Products/Search', 'activities' => 'RestAPI/Browse/Activities', 'makes' => 'RestAPI/Fitment/Makes', 'years' => 'RestAPI/Fitment/Years', 'models' => 'RestAPI/Fitment/Models', 'categories' => 'RestAPI/Browse/Categories', 'subcategories' => 'RestAPI/Browse/SubCategories', 'product' => 'RestAPI/Products', 'productattributes' => 'RestAPI/Products/Attributes', 'fitment' => 'RestAPI/Fitment', 'fitmentnotes' => 'RestAPI/Products/FitmentNotes');
    public function request($path, $mandatoryParams = array(), $optionalParams = array())
    {
        $baseUrl = 'http://accessorystream.arinet.com/';
        $appKey = 'N8SZjBuVQoU6EhkxtCi2';
        $path = isset(self::$_apiActionToRequestPath[$path]) ? self::$_apiActionToRequestPath[$path] : $path;
        $url = $baseUrl . $path . (count($mandatoryParams) ? '/' . implode('/', $mandatoryParams) : '') . (count($optionalParams) ? '?' . http_build_query($optionalParams) : '');
        $ch = curl_init();
        curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('applicationKey: ' . $appKey)));
        $result = curl_exec($ch);
        curl_close($ch);
        return $result ? json_decode($result, true) : $result;
    }
}
$time = microtime(true);
foreach ($_POST['params'] as $key => $value) {
    if (!$value) {
        unset($_POST['params'][$key]);
    }
}
foreach ($_POST['options'] as $key => $value) {
    if (!$value) {
        unset($_POST['options'][$key]);
    }
}
$caller = new Caller();
$html = vd($caller->request($_POST['requestType'], $_POST['params'], $_POST['options']), true);
$time = round(microtime(true) - $time, 3);
$responseData = array('dump' => $html, 'time' => $time);
echo json_encode($responseData);