コード例 #1
0
ファイル: BenchTest.php プロジェクト: camspiers/bench
 public function testInvoke()
 {
     $result = invoke(function () {
         return true;
     });
     $this->assertTrue($result);
     $this->assertTrue(is_float(collector()));
 }
コード例 #2
0
ファイル: HelperTest.php プロジェクト: pldin601/php-funky
 public function testInvokeFunction()
 {
     $instance = new Misc\SomeClass();
     $closure = invoke('foo');
     $this->assertEquals('bar', $closure($instance));
     $closure = invoke('staticFoo');
     $this->assertEquals('bar', $closure(Misc\SomeClass::class));
 }
コード例 #3
0
ファイル: Request.php プロジェクト: phpf/yql
 /**
  *	Builds the url and gets the response.
  */
 public function execute($query = null)
 {
     if (!empty($query)) {
         $this->setQuery($query);
     }
     $this->url = $this->baseUrl . '?q=' . urlencode($this->query) . "&format=" . $this->format;
     if ($this->diagnostics) {
         $this->url .= '&diagnostics=true';
     }
     if (!empty($this->env)) {
         $this->url .= '&env=' . urlencode($this->env);
     }
     $result = invoke($this->execute, array('url' => $this->url));
     $this->response = new Response($result, $this);
     return $this;
 }
コード例 #4
0
ファイル: ServiceLocator.php プロジェクト: pframework/p
 /**
  * @param $name
  * @return mixed
  * @throws \RuntimeException
  * @throws \Exception
  */
 public function get($name)
 {
     static $depth = 0;
     static $allNames = array();
     if (!isset($this->services[$name])) {
         throw new \Exception('Service by name ' . $name . ' was not located in this ServiceLocator');
     }
     if ($depth > 99) {
         throw new \RuntimeException('Recursion detected when trying to resolve these services: ' . implode(', ', $allNames));
     }
     if ($this->services[$name] instanceof \Closure && !isset($this->instantiated[$name])) {
         $depth++;
         $allNames[] = $name;
         /** @var $factory \Closure */
         $factory = $this->services[$name];
         $factoryCallable = get_callable($factory);
         $this->services[$name] = invoke($factoryCallable, $this, $this);
         $this->instantiated[$name] = true;
         // allow closure wrapped in a closure
         $depth--;
     }
     if ($depth === 0) {
         while ($allNames) {
             $aName = array_pop($allNames);
             if (isset($this->initializers[$aName . '+'])) {
                 $depth++;
                 /** @var $initializer \Closure */
                 $initializer = $this->initializers[$aName . '+'];
                 if (version_compare(PHP_VERSION, '5.4.0')) {
                     $initializer = $initializer->bindTo($this, __CLASS__);
                 }
                 $initializer($this->services[$aName]);
                 $depth--;
             }
             if ($this->initializers['+']) {
                 foreach ($this->initializers['+'] as $initializer) {
                     if (version_compare(PHP_VERSION, '5.4.0')) {
                         $initializer = $initializer->bindTo($this, __CLASS__);
                     }
                     $initializer($this->services[$aName]);
                 }
             }
             unset($this->services[$aName . '+']);
         }
     }
     return $this->services[$name];
 }
コード例 #5
0
ファイル: Fn.php プロジェクト: eschwartz/Fn
function invokeAll()
{
    $fns = func_get_args();
    // Returns last result
    return array_reduce($fns, function ($carry, $fn) {
        return invoke($fn);
    });
}
コード例 #6
0
ファイル: ajax.php プロジェクト: prashantgajare/civicrm-core
 | You should have received a copy of the GNU Affero General Public   |
 | License along with this program; if not, contact CiviCRM LLC       |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
*/
/**
 * This file returns permissioned data required by dojo hierselect widget.
 *
 */
/**
 * call to invoke function
 *
 */
invoke();
exit;
/**
 * Invoke function that redirects to respective functions
 */
function invoke()
{
    if (!isset($_GET['return'])) {
        return;
    }
    // intialize the system
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config =& CRM_Core_Config::singleton();
    switch ($_GET['return']) {
        case 'states':
コード例 #7
0
ファイル: test.php プロジェクト: elevenone/blowfish
<?php

require __DIR__ . '/vendor/autoload.php';
use mindplay\blowfish\BlowfishService;
test('Entropy functions work as expected', function () {
    $service = new BlowfishService();
    $entropy = invoke($service, 'getEntropy', array(10));
    ok(strlen($entropy) === 10, 'returns 10 bytes of entropy');
    $entropy = invoke($service, 'getEntropy', array(100));
    ok(strlen($entropy) === 100, 'returns 100 bytes of entropy');
});
test('Can hash and check passwords', function () {
    foreach (array(4, 10) as $cost) {
        $service = new BlowfishService($cost);
        foreach (array('x', 'p@s$w0Rd', 'KytmCwqjb6wYPGgEHZ55DRfDanNVWwxnmMMnzCRu72ghQ89S') as $password) {
            $hash = $service->hash($password);
            ok($service->check($password, $hash), 'password verified (with cost ' . $cost . ')', $password);
            ok($service->check($password . '-', $hash) === false, 'invalid password rejected (with cost ' . $cost . ')', $password);
            ok($service->check($password, $hash . '-') === false, 'invalid hash rejected (with cost ' . $cost . ')', $password);
        }
    }
});
exit(status());
// https://gist.github.com/mindplay-dk/4260582
/**
 * @param string   $name     test description
 * @param callable $function test implementation
 */
function test($name, $function)
{
    echo "\n=== {$name} ===\n\n";
コード例 #8
0
ファイル: functions.php プロジェクト: camspiers/bench
/**
 * This function will return a Closure that when executed will
 * time the original function and add the results to the collector
 * 
 * @param callable $fn
 * @param array|void $args
 * @param callable|void $collector
 * @return \Closure
 */
function wrap(callable $fn, $args = [], callable $collector = null)
{
    return function () use($fn, $args, $collector) {
        return invoke($fn, $args, $collector);
    };
}
コード例 #9
0
ファイル: functions.php プロジェクト: nulil/attophp
/**
 * call
 * 
 * @param {callable} $callback
 * @return {mixed} 
 */
function call($callback)
{
    return invoke($callback, array_slice(func_get_args(), 1));
}
コード例 #10
0
<?php

// set your invoked calls here
invoke('AppController');
invoke('AjaxController');
invoke('FormController');
invoke('StoreController', 'wp', 'is_shop');
invoke('ProductController', 'wp', 'is_product');
invoke('AccountController', 'wp', function () {
    return is_page('my-account');
});
invoke('CartController', 'woocommerce_cart_loaded_from_session');
invoke('ContactController', 'wp', function () {
    return is_page('contact-us');
});
invoke('CheckoutController', 'wp', 'is_checkout');
invoke('EventController');
invoke('LoginController');
invoke('PostController');
invoke('UserController');
invoke('AdminController', 'admin_init');
invoke('FeedbackController', 'wp', function () {
    return is_page('Feedback');
});
コード例 #11
0
ファイル: Services.php プロジェクト: ricsr/hello-world
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include_once "ServicesController.php";
$sc = new ServicesController();
$sc . invoke();
include './Template.php';
コード例 #12
0
ファイル: Application.php プロジェクト: pframework/p
 public function trigger($scopeIdentifier, $parameters = array())
 {
     $this->applicationState->pushScope($scopeIdentifier, $parameters);
     if (!isset($this->callbacks[$scopeIdentifier])) {
         $this->applicationState->popScope();
         return;
     }
     foreach (clone $this->callbacks[$scopeIdentifier] as $callback) {
         $result = invoke($callback, $this->applicationState);
         if ($result == ApplicationState::NULLIFY_RESULT) {
             $this->applicationState->setResult(null);
         } elseif (!is_null($result)) {
             $this->applicationState->setResult($result);
         }
     }
     $this->applicationState->popScope();
     return $this;
 }