call() public static method

public static call ( $function, $argument )
Beispiel #1
0
 private function _map($closure)
 {
     if ($this->isPresent()) {
         return Optional::fromNullable(Functions::call($closure, $this->object));
     }
     return Optional::absent();
 }
Beispiel #2
0
 public function init()
 {
     $uri = new Uri();
     $router = new Router($uri);
     $routeRule = $router->findRoute();
     $this->currentController = $routeRule->getController();
     $this->requestContext->setCurrentController($this->currentController);
     $this->currentAction = $routeRule->isActionRequired() ? $routeRule->getAction() : $uri->getAction();
     $this->sessionInitializer->startSession();
     $this->currentControllerObject = $this->controllerFactory->createController($routeRule);
     $this->requestContext->setCurrentControllerObject($this->currentControllerObject);
     $this->_logRequest();
     $afterInitCallback = Config::getValue('callback', 'afterControllerInit');
     if ($afterInitCallback) {
         Functions::call($afterInitCallback, array());
     }
     try {
         ob_start();
         $this->_invokeControllerMethods();
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
     ob_end_flush();
 }
Beispiel #3
0
 /**
  * @test
  */
 public function shouldNegate()
 {
     //given
     $function = FluentFunctions::startsWith("start")->negate();
     //when
     $result = Functions::call($function, "starts with prefix");
     //then
     $this->assertFalse($result);
 }
Beispiel #4
0
 public function extracting()
 {
     $selectors = func_get_args();
     $actual = array();
     if (count($selectors) == 1) {
         $selector = Arrays::first($selectors);
         $actual = Arrays::map($this->actual, Functions::extractExpression($selector, true));
     } else {
         foreach ($this->actual as $item) {
             $extracted = array();
             foreach ($selectors as $selector) {
                 $extracted[] = Functions::call(Functions::extractExpression($selector, true), $item);
             }
             $actual[] = $extracted;
         }
     }
     return self::that($actual);
 }
Beispiel #5
0
 /**
  * Returns the composition of two functions.
  * composition is defined as the function h such that h(a) == A(B(a)) for each a.
  * @param $functionA
  * @param $functionB
  * @return callable
  */
 public static function compose($functionA, $functionB)
 {
     return function ($input) use($functionA, $functionB) {
         return Functions::call($functionA, Functions::call($functionB, $input));
     };
 }
Beispiel #6
0
 /**
  * Returns the number of elements for which the predicate returns true.
  *
  * Example:
  * <code>
  * $array = array(1, 2, 3);
  * $count = Arrays::count($array, function ($element) {
  *      return $element < 3;
  * });
  * </code>
  * Result:
  * <code>
  * 2
  * </code>
  *
  * @param array $elements
  * @param callable $predicate
  * @return int
  */
 public static function count(array $elements, $predicate)
 {
     $count = 0;
     foreach ($elements as $element) {
         if (Functions::call($predicate, $element)) {
             $count++;
         }
     }
     return $count;
 }
Beispiel #7
0
 /**
  * @test
  */
 public function shouldExtractArrayValue()
 {
     //given
     $object = array('key' => 'value');
     //$function = Functions::extract()['key']; only i php 5.4
     $function = Functions::extract()->offsetGet('key');
     //when
     $result = Functions::call($function, $object);
     //then
     Assert::thatString($result)->isEqualTo('value');
 }
Beispiel #8
0
 /**
  * @test
  */
 public function shouldCheckNull()
 {
     //then
     $this->assertFalse(Functions::call(Functions::notNull(), null));
 }
 public function matches($argument)
 {
     return Functions::call($this, $argument);
 }