/** * Paint the element. * * @param \Hoa\Stream\IStream\Out $out Out stream. * @return void */ public function paint(Stream\IStream\Out $out) { $root = $this->getAbstractElementSuperRoot(); $value = $this->computeValue(); $with = '__main__'; if (true === $this->abstract->attributeExists('with')) { $with = $this->abstract->readAttribute('with'); } $translation = $root->getTranslation($with); if (null === $translation) { $out->writeAll($value); return; } $callable = null; $arguments = [$value]; if (true === $this->abstract->attributeExists('n')) { $callable = xcallable($translation, '_n'); $arguments[] = $this->abstract->readAttribute('n'); } else { $callable = xcallable($translation, '_'); } $with = $this->abstract->readCustomAttributes('with'); if (!empty($with)) { foreach ($with as $w) { $arguments[] = $this->computeAttributeValue($w); } } $result = $callable->distributeArguments($arguments); if (false !== strpos($result, '<')) { $this->computeFromString($result); } else { $out->writeAll($result); } return; }
public function __construct($repository) { $this->_readline = new Hoa\Console\Readline(); $git = new Hoa\Console\Processus('git log --pretty=\'format:\' --patch --reverse --raw -z', null, null, $repository); $git->on('output', xcallable($this, 'output')); $git->on('stop', xcallable($this, 'over')); $git->run(); }
public function render() { $this->renderInternal(); Cursor::setStyle('▋', true); do { $this->readline = new Readline(); $this->readline->addMapping('j', xcallable($this, '_bindJ')); $this->readline->addMapping('k', xcallable($this, '_bindK')); $line = $this->readline->readLine(' '); } while (false !== $line && 'quit' !== $line); }
/** * Start the stream reader/writer as if it is a XML document. * * @param \Hoa\Stream\IStream\In $stream Stream to * read/write. * @param bool $initializeNamespace Whether we * initialize * namespaces. * @param mixed $entityResolver Entity resolver. * @param bool $autoSave Whether we * should * auto-save. * @return void * @throws \Hoa\Xml\Exception */ public function __construct(Stream\IStream\In $stream, $initializeNamespace = true, $entityResolver = null, $autoSave = true) { if (true === $autoSave && !$stream instanceof Stream\IStream\Out) { throw new Exception('The stream %s (that has opened %s) must implement ' . '\\Hoa\\Stream\\IStream\\In and \\Hoa\\Stream\\IStream\\Out interfaces.', 0, [get_class($stream), $stream->getStreamName()]); } parent::__construct('\\Hoa\\Xml\\Element\\ReadWrite', $stream, $initializeNamespace, $entityResolver); if (true === $autoSave) { event('hoa://Event/Stream/' . $stream->getStreamName() . ':close-before')->attach(xcallable($this, '_close')); } $this->_autoSave = $autoSave; return; }
/** * Initialize functions mapping. * * @return void */ protected function initializeFunctions() { if (sizeof($this->opa_functions) > 0) { return; } $average = function () { $arguments = func_get_args(); return array_sum($arguments) / count($arguments); }; $this->opa_functions = array('abs' => xcallable('abs'), 'ceil' => xcallable('ceil'), 'floor' => xcallable('floor'), 'int' => xcallable('intval'), 'max' => xcallable('max'), 'min' => xcallable('min'), 'rand' => xcallable('rand'), 'round' => xcallable('round'), 'random' => xcallable('rand'), 'current' => xcallable('caIsCurrentDate'), 'future' => xcallable('caDateEndsInFuture'), 'wc' => xcallable('str_word_count'), 'length' => xcallable('strlen'), 'date' => xcallable('caDateToHistoricTimestamp'), 'formatdate' => xcallable('caFormatDate'), 'formatgmdate' => xcallable('caFormatGMDate'), 'sizeof' => xcallable(function () { return count(func_get_args()); }), 'count' => xcallable(function () { return count(func_get_args()); }), 'age' => xcallable('caCalculateAgeInYears'), 'ageyears' => xcallable('caCalculateAgeInYears'), 'agedays' => xcallable('caCalculateAgeInDays'), 'avgdays' => xcallable('caCalculateDateRangeAvgInDays'), 'average' => xcallable($average), 'avg' => xcallable($average), 'sum' => xcallable(function () { return array_sum(func_get_args()); })); return; }
public function resolve($value) { if (self::STATE_PENDING !== $this->_state) { throw new Exception('This promise is not pending, cannot resolve it.', 0); } try { if ($value instanceof self) { $value->then(xcallable($this, 'resolve'), xcallable($this, 'reject')); return; } $this->setValue($value); $this->_state = self::STATE_FULFILLED; if (null === $this->_deferred) { return; } $this->handle($this->_deferred); } catch (\Exception $e) { $this->reject($e); } return; }
public function case_callable_xcallable() { $this->given($context = new CUT(), $context['foo'] = xcallable($this, 'fakeCallable'))->when($result = $context['foo'])->then->boolean($result)->isTrue(); }
/** * Start the stream reader/writer as if it is a XML document. * * @param \Hoa\Stream\IStream\Out $stream Stream to * read/write. * @param bool $initializeNamespace Whether we * initialize * namespaces. * @param mixed $entityResolver Entity resolver. * @return void */ public function __construct(Stream\IStream\Out $stream, $initializeNamespace = true, $entityResolver = null) { parent::__construct('\\Hoa\\Xml\\Element\\Write', $stream, $initializeNamespace, $entityResolver); event('hoa://Event/Stream/' . $stream->getStreamName() . ':close-before')->attach(xcallable($this, '_close')); return; }
/** * Start a new buffer. * The callable acts like a filter. * * @param mixed $callable Callable. * @param int $size Size. * @return int */ public function newBuffer($callable = null, $size = null) { $last = current(self::$_stack); $hash = $this->getHash(); if (false === $last || $hash != $last[0]) { self::$_stack[] = [0 => $hash, 1 => 1]; } else { ++self::$_stack[key(self::$_stack)][1]; } end(self::$_stack); if (null === $callable) { ob_start(); } else { ob_start(xcallable($callable), null === $size ? 0 : $size); } return $this->getBufferLevel(); }
/** * Add a filter. * Used in the self::getStatistic() method, no in iterator. * A filter is a callable that will receive 3 values about a mark: ID, time * result, and time pourcent. The callable must return a boolean. * * @param mixed $callable Callable. * @return void */ public function filter($callable) { $this->_filters[] = xcallable($callable); return $this; }
/** * Invoke. * * @acccess protected * @param \Hoa\Core\Consistency\Xcallable &$reflection Callable. * @param \ReflectionFunctionAbstract &$reflection Reflection. * @param array &$arguments Arguments. * @param bool $isConstructor Whether * it is a * constructor. * @return mixed * @throws \Exception */ protected function invoke(Core\Consistency\Xcallable &$callable, \ReflectionFunctionAbstract &$reflection, array &$arguments, $isConstructor) { if ($reflection instanceof \ReflectionFunction) { return $reflection->invokeArgs($arguments); } if (false === $isConstructor) { $_callback = $callable->getValidCallback(); $_object = $_callback[0]; return $reflection->invokeArgs($_object, $arguments); } $class = $reflection->getDeclaringClass(); $instance = $class->newInstanceArgs($arguments); $callable = xcallable($instance, '__construct'); $reflection = $callable->getReflection(); return void; }
/** * Return a "*" or "catch all" operator. * * @param Visitor\Element $element The node representing the operator. * * @return \Hoa\Core\Consistency\Xcallable */ protected function getStarOperator(AST\Operator $element) { return xcallable(function () use($element) { return sprintf('%s(%s)', $element->getName(), implode(', ', func_get_args())); }); }
/** * Set an operator. * * @param string $operator Operator. * @param callable $transformer Callable. * * @return self */ public function setOperator($operator, callable $transformer) { $this->operators[$operator] = xcallable($transformer); return $this; }
/** * Initialize WebSocket server * * @return Hoa\Websocket\Server */ public function initWebSocketServer() { $webSocketServer = $this->getWebSocketServer(); $webSocketServer->setLogger($this->getLogger()); if ($this->getNodeClass() !== null) { $webSocketServer->getConnection()->setNodeName($this->getNodeClass()); } $socket = $webSocketServer->getConnection()->getSocket(); $this->getLogger()->log('<fg=yellow>Starting server...</fg=yellow>'); $this->getLogger()->log('Environment: <fg=green>%s</fg=green>', $this->kernelEnvironment); $this->getLogger()->log('Class used:'); $this->getLogger()->log(' Logger : %s', get_class($this->getLogger())); $this->getLogger()->log(' Runner : %s', get_class($this)); $this->getLogger()->log(' WebSocket Server : %s', get_class($webSocketServer)); $this->getLogger()->log(' Socket Server : %s', get_class($socket)); $this->getLogger()->log(' Node : %s', ltrim($webSocketServer->getConnection()->getNodeName(), '\\')); $this->getLogger()->log('<fg=yellow>Listening on %s:%d</fg=yellow>', $socket->getAddress(), $socket->getPort()); $webSocketServer->on('open', xcallable($this, 'onOpen')); $webSocketServer->on('message', xcallable($this, 'onMessage')); $webSocketServer->on('binary-message', xcallable($this, 'onBinaryMessage')); $webSocketServer->on('ping', xcallable($this, 'onPing')); $webSocketServer->on('error', xcallable($this, 'onError')); $webSocketServer->on('close', xcallable($this, 'onClose')); $this->loadEvents(); return $webSocketServer; }
/** * Detach an object to an event. * Please see $this->attach() method. * * @param mixed $callable Callable. * @return \Hoa\Event\Event */ public function detach($callable) { unset($this->_callable[xcallable($callable)->getHash()]); return $this; }
/** * Format an attribute value. * Formatter is of the form: * @attr-formatter="functionName" * Arguments of functionName are declared as: * @attr-formatter-argumentName="argumentValue" * * * @param string $value Value. * @param string $name Name. * @return string */ protected function formatValue($value, $name = null) { $_formatter = $name . 'formatter'; $formatter = $this->abstract->readAttribute($_formatter); $arguments = $this->abstract->readCustomAttributes($_formatter); foreach ($arguments as &$argument) { $argument = $this->_formatValue($this->computeAttributeValue($argument)); } $reflection = xcallable($formatter)->getReflection(); $distribution = []; $placeholder = $this->_formatValue($value); foreach ($reflection->getParameters() as $parameter) { $name = strtolower($parameter->getName()); if (true === array_key_exists($name, $arguments)) { $distribution[$name] = $arguments[$name]; continue; } elseif (null !== $placeholder) { $distribution[$name] = $placeholder; $placeholder = null; } } if ($reflection instanceof \ReflectionMethod) { $value = $reflection->invokeArgs(null, $distribution); } else { $value = $reflection->invokeArgs($distribution); } return $value; }
/** * This method starts the ec2dns eventloop * * @return void */ function run() { try { $this->dns->on('query', xcallable($this, 'onQueryCallback')); $this->dns->run(); } catch (\Hoa\Socket\Exception $e) { throw new \InvalidArgumentException($e->getMessage()); } }
/** * Get a memoization (multiton). * * @param mixed $callable Callable. * @return \Hoa\Cache\Memoize */ public static function getInstance($callable) { $callable = xcallable($callable); $hash = $callable->getHash(); if (!isset(self::$_multiton[$hash])) { self::$_multiton[$hash] = new static(); self::$_multiton[$hash]->_callable = $callable; } return self::$_multiton[$hash]; }
/** * Detach a callable from a listenable component. * * @param string $listenerId Listener ID. * @param mixed $callable Callable. * @return \Hoa\Event\Listener */ public function detach($listenerId, $callable) { unset($this->_callables[$listenerId][xcallable($callable)->getHash()]); return $this; }
/** * Initialize the readline editor. * * @access public * @return void */ public function __construct() { if (OS_WIN) { return; } $this->_mapping["[A"] = xcallable($this, '_bindArrowUp'); $this->_mapping["[B"] = xcallable($this, '_bindArrowDown'); $this->_mapping["[C"] = xcallable($this, '_bindArrowRight'); $this->_mapping["[D"] = xcallable($this, '_bindArrowLeft'); $this->_mapping[""] = xcallable($this, '_bindControlA'); $this->_mapping[""] = xcallable($this, '_bindControlB'); $this->_mapping[""] = xcallable($this, '_bindControlE'); $this->_mapping[""] = xcallable($this, '_bindControlF'); $this->_mapping[""] = $this->_mapping[""] = xcallable($this, '_bindBackspace'); $this->_mapping[""] = xcallable($this, '_bindControlW'); $this->_mapping["\n"] = xcallable($this, '_bindNewline'); $this->_mapping["\t"] = xcallable($this, '_bindTab'); return; }
/** * Component's name. * * @var string */ protected $_name = 'Stream'; /** * ID of the component. * * @param string $id ID of the component. * @return mixed */ public function reachId($id) { return Stream::getStreamHandler($id); } } /** * Flex entity. */ Consistency::flexEntity('Hoa\\Stream\\Stream'); /** * Shutdown method. */ Consistency::registerShutdownFunction(xcallable('Hoa\\Stream\\Stream::_Hoa_Stream')); /** * Add the `hoa://Library/Stream` node. Should be use to reach/get an entry * in the stream register. */ $protocol = Protocol::getInstance(); $protocol['Library'][] = new _Protocol();
public function testInitWebSocketServer() { $this->given($mockWebSocketServer = $this->generateMockWebSocketServer())->given($this->getMockGenerator()->orphanize('__construct'))->given($this->calling($mockWebSocketServer)->on = $mockWebSocketServer)->given($this->calling($mockWebSocketServer)->getConnection = $mockConnection = new \mock\Hoa\Socket\Connection())->given($this->getMockGenerator()->orphanize('__construct'))->given($this->calling($mockConnection)->getSocket = $mockSocket = new \mock\Hoa\Socket())->given($this->calling($mockSocket)->getAddress = $address = uniqid())->given($this->calling($mockSocket)->getPort = $port = uniqid())->given($runner = new mockTestedClass($mockWebSocketServer, $logger = new mockLogger()))->given($runner->addModule($module1 = new testModule1()))->given($runner->addModule($module2 = new testModule2()))->assert('Without node class')->object($runner->initWebSocketServer())->isIdenticalTo($mockWebSocketServer)->mock($logger)->call('log')->exactly(13)->withIdenticalArguments('<fg=yellow>Starting server...</fg=yellow>')->once()->withIdenticalArguments('Environment: <fg=green>%s</fg=green>')->once()->withIdenticalArguments('Class used:')->once()->withIdenticalArguments(' Logger : %s', get_class($logger))->once()->withIdenticalArguments(' Runner : %s', get_class($runner))->once()->withIdenticalArguments(' WebSocket Server : %s', get_class($mockWebSocketServer))->once()->withIdenticalArguments(' Socket Server : %s', get_class($mockSocket))->once()->withIdenticalArguments(' Node : %s', 'Hoa\\Socket\\Node')->once()->withIdenticalArguments('<fg=yellow>Listening on %s:%d</fg=yellow>', $address, $port)->once()->withIdenticalArguments('Listening <fg=green>%s</fg=green> event <fg=yellow>%s</fg=yellow>::<fg=blue>%s</fg=blue>', 'event1', 'Atipik\\Hoa\\WebSocketBundle\\Tests\\Units\\WebSocket\\testModule1', 'onEvent1')->once()->withIdenticalArguments('Listening <fg=green>%s</fg=green> event <fg=yellow>%s</fg=yellow>::<fg=blue>%s</fg=blue>', 'event2', 'Atipik\\Hoa\\WebSocketBundle\\Tests\\Units\\WebSocket\\testModule1', 'onEvent2')->once()->withIdenticalArguments('Listening <fg=green>%s</fg=green> event <fg=yellow>%s</fg=yellow>::<fg=blue>%s</fg=blue>', 'event3', 'Atipik\\Hoa\\WebSocketBundle\\Tests\\Units\\WebSocket\\testModule1', 'onEvent3')->once()->withIdenticalArguments('Listening <fg=green>%s</fg=green> event <fg=yellow>%s</fg=yellow>::<fg=blue>%s</fg=blue>', 'event2', 'Atipik\\Hoa\\WebSocketBundle\\Tests\\Units\\WebSocket\\testModule2', 'onEvent2')->once()->mock($mockWebSocketServer)->call('on')->exactly(6)->withArguments('open', xcallable($runner, 'onOpen'))->once()->withArguments('message', xcallable($runner, 'onMessage'))->once()->withArguments('binary-message', xcallable($runner, 'onBinaryMessage'))->once()->withArguments('ping', xcallable($runner, 'onPing'))->once()->withArguments('error', xcallable($runner, 'onError'))->once()->withArguments('close', xcallable($runner, 'onClose'))->once()->mock($mockConnection)->call('setNodeName')->never()->assert('With node class')->given($runner->setNodeClass($class = uniqid()))->object($runner->initWebSocketServer())->isIdenticalTo($mockWebSocketServer)->mock($mockConnection)->call('setNodeName')->once()->withIdenticalArguments($class); }
throw new Exception('Selector %s is not a valid selector.', 22, $selector); } /** * Destruct XYL object. * * @return void */ public function __destruct() { $protocol = Core::getInstance()->getProtocol(); unset($protocol['Library']['Xyl[' . $this->_i . ']']); return; } } /** * Class \Hoa\Xyl\_Protocol. * * hoa://Library/Xyl component. * * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ class _Protocol extends Core\Protocol { } /** * Flex entity. */ Core\Consistency::flexEntity('Hoa\\Xyl\\Xyl'); event('hoa://Event/Exception')->attach(xcallable('Hoa\\Xyl\\Interpreter\\Common\\Debug', 'receiveException'));
/** * Add a function. * * @param string $name Function name. * @param mixed $callable Callable. * @return void */ public function addFunction($name, $callable = null) { if (null === $callable) { if (false === function_exists($name)) { throw new Math\UnknownFunction('Function %s does not exist, cannot add it.', 2, $name); } $callable = $name; } $this->_functions[$name] = xcallable($callable); return; }
/** * Invoke the encapsulation shunter. * * @param \Hoa\Praspel\Preambler\Handler $preambler Preambler. * @return void * @throws \Hoa\Praspel\Exception\Preambler */ public function __invoke(Handler $preambler) { $callable = $preambler->__getCallable(); $reflection = $callable->getReflection(); $registry = Praspel::getRegistry(); if ($reflection instanceof \ReflectionClass) { $_object = $reflection->newInstance(); $preambler->__setCallable(xcallable($_object, '__construct')); } elseif (!$reflection instanceof \ReflectionMethod) { throw new Praspel\Exception\Preambler('The callable must be a class and a (dynamic) method name.', 0); } else { $callback = $callable->getValidCallback(); if (!is_object($callback[0])) { $reflectionClass = $reflection->getDeclaringClass(); $_reflectionClass = $reflectionClass; while (null === ($constructor = $_reflectionClass->getConstructor()) && false !== ($_reflectionClass = $_reflectionClass->getParentClass())) { } if (null === $constructor) { $_object = $reflectionClass->newInstance(); } else { $className = $_reflectionClass->getName(); $id = $className . '::__construct'; if (!isset($registry[$id])) { $registry[$id] = Praspel::interpret(Praspel::extractFromComment($constructor->getDocComment()), $className); } $assertionChecker = $this->getAssertionChecker(); if (null === $assertionChecker) { $assertionChecker = '\\Hoa\\Praspel\\AssertionChecker'; } $arguments = $assertionChecker::generateData($registry[$id]); $_object = $reflectionClass->newInstanceArgs($arguments); } $preambler->__setCallable(xcallable($_object, $callback[1])); } } $reflectionObject = $preambler->__getReflectionObject($object); $className = $reflectionObject->getName(); $properties = $reflectionObject->getProperties(); foreach ($properties as $property) { $propertyName = $property->getName(); $id = $className . '::$' . $propertyName; if (false === isset($registry[$id])) { $registry[$id] = Praspel::interpret(Praspel::extractFromComment($property->getDocComment()), $className); } $specification = $registry[$id]; if (false === $specification->clauseExists('invariant')) { throw new Praspel\Exception\Preambler('Cannot generate a value from %s because it has no ' . '@invariant clause.', 1, $id); } $preambler->{$propertyName} = $specification->getClause('invariant')->getVariable($propertyName)->sample(); } return; }
/** * Get all operators. * * @return array */ public function getOperators() { foreach ($this->_operators as &$operator) { if (!$operator instanceof Core\Consistency\Xcallable) { $operator = xcallable($operator); } } return $this->_operators; }
/** * Sample one new value. * * @param \Hoa\Math\Sampler $sampler Sampler. * @return mixed */ protected function _sample(Math\Sampler $sampler) { $className = $this[0]->getConstantValue(); $handler = new Praspel\Preambler\Handler(xcallable($className, '__construct')); $preambler = new Praspel\Preambler\EncapsulationShunter(); $preambler($handler); $callback = $handler->__getCallable()->getValidCallback(); return $callback[0]; }
/** * Initialize functions mapping. * * @return void */ protected function initializeFunctions() { static $_functions = null; if (null === $_functions) { $average = function () { $arguments = func_get_args(); return array_sum($arguments) / count($arguments); }; $_functions = new \ArrayObject(['abs' => xcallable('abs'), 'acos' => xcallable('acos'), 'asin' => xcallable('asin'), 'atan' => xcallable('atan'), 'average' => xcallable($average), 'avg' => xcallable($average), 'ceil' => xcallable('ceil'), 'cos' => xcallable('cos'), 'count' => xcallable(function () { return count(func_get_args()); }), 'deg2rad' => xcallable('deg2rad'), 'exp' => xcallable('exp'), 'floor' => xcallable('floor'), 'ln' => xcallable('log'), 'log' => xcallable(function ($value, $base = 10) { return log($value, $base); }), 'max' => xcallable('max'), 'min' => xcallable('min'), 'pow' => xcallable('pow'), 'rad2deg' => xcallable('rad2deg'), 'sin' => xcallable('sin'), 'sqrt' => xcallable('sqrt'), 'sum' => xcallable(function () { return array_sum(func_get_args()); }), 'tan' => xcallable('tan')]); } $this->_functions = $_functions; return; }