private function _map($closure) { if ($this->isPresent()) { return Optional::fromNullable(Functions::call($closure, $this->object)); } return Optional::absent(); }
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(); }
/** * @test */ public function shouldNegate() { //given $function = FluentFunctions::startsWith("start")->negate(); //when $result = Functions::call($function, "starts with prefix"); //then $this->assertFalse($result); }
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); }
/** * 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)); }; }
/** * 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; }
/** * @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'); }
/** * @test */ public function shouldCheckNull() { //then $this->assertFalse(Functions::call(Functions::notNull(), null)); }
public function matches($argument) { return Functions::call($this, $argument); }