closure() public static method

public static closure ( $callable, $m = NULL ) : Closure
return Closure
Ejemplo n.º 1
0
 /**
  * @param Container $container
  * @param array $callbacks [optional]
  */
 public function __construct(Container $container, $callbacks = [])
 {
     $this->container = $container;
     /** @var $httpRequest Request */
     $request = $container->getService("httpRequest");
     // Determine production/development mode
     $this->active = !Debugger::$productionMode;
     // # Clean cache
     $this->callbacks["cache"] = ['name' => "Clear cache", 'callback' => Callback::closure($this, "clearCache"), 'args' => [[Cache::ALL => TRUE]]];
     // # Clean session
     $this->callbacks["session"] = ['name' => "Clear session", 'callback' => Callback::closure($this, "clearSession"), 'args' => []];
     // # Clean logs
     $this->callbacks["logs"] = ['name' => "Clear logs", 'callback' => Callback::closure($this, "clearLogs"), 'args' => [[Cache::ALL => TRUE]]];
     // Merge custom callbacks
     $this->callbacks = array_merge($this->callbacks, $callbacks);
     // Check signal receiver
     if ($this->active && ($cb = $request->getQuery("callback-do", FALSE))) {
         if ($cb === "all") {
             $this->onCallbacksCall();
             $this->invokeCallbacks();
         } else {
             $this->onCallbackCall($cb);
             $this->invokeCallback($cb);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $name
  * @param callable $callback
  */
 public function addContentMenu($name, $callback)
 {
     if (isset($this->contentMenu[$name])) {
         throw new InvalidArgumentException(sprintf('Content menu \'%s\' is already exists.', $name));
     }
     $this->contentMenu[$name] = Callback::closure($callback);
 }
Ejemplo n.º 3
0
 /**
  * Reads the specified item from the cache or generate it.
  * @param  mixed key
  * @param  callable
  * @return mixed|NULL
  */
 public function load($key, $fallback = NULL)
 {
     $data = $this->storage->read($this->generateKey($key));
     if ($data === NULL && $fallback) {
         return $this->save($key, Callback::closure($fallback));
     }
     return $data;
 }
Ejemplo n.º 4
0
 /**
  * @param  NSelection $selection
  * @param  string|callable $entity
  * @param  string $refTable
  * @param  string $refColumn
  */
 public function __construct(NSelection $selection, $entity, $refTable = NULL, $refColumn = NULL)
 {
     $this->selection = $selection;
     $this->refTable = $refTable;
     $this->refColumn = $refColumn;
     try {
         NCallback::check($entity);
         $this->entity = NCallback::closure($entity);
     } catch (\Exception $e) {
         $this->entity = $entity;
     }
 }
Ejemplo n.º 5
0
 /**
  * Renders HTML code for custom panel.
  * @return string
  */
 public function getPanel()
 {
     if (!$this->resources) {
         return null;
     }
     $esc = \Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml');
     $click = function ($o, $c = false) {
         return \Tracy\Dumper::toHtml($o, ['collapse' => $c]);
     };
     ob_start();
     include __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
Ejemplo n.º 6
0
 /**
  * @return string
  */
 public function getPanel()
 {
     if (!$this->calls) {
         return NULL;
     }
     ob_start();
     $esc = function ($s) {
         return htmlSpecialChars($s, ENT_QUOTES, 'UTF-8');
     };
     $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) {
         return \Tracy\Dumper::toHtml($o, array('collapse' => $c));
     } : Callback::closure('\\Tracy\\Helpers::clickableDump');
     $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
Ejemplo n.º 7
0
 /**
  * @return string
  */
 public function getPanel()
 {
     if (!$this->calls) {
         return NULL;
     }
     ob_start();
     if (class_exists('Latte\\Runtime\\Filters')) {
         $esc = Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml');
     } else {
         $esc = 'Nette\\Templating\\Helpers::escapeHtml';
     }
     $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) {
         return \Tracy\Dumper::toHtml($o, array('collapse' => $c));
     } : '\\Tracy\\Helpers::clickableDump';
     $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
 public function getClosure()
 {
     return PHP_VERSION_ID < 50400 ? Nette\Utils\Callback::closure($this->value) : parent::getClosure();
 }
Ejemplo n.º 9
0
 /** @return void */
 public function render()
 {
     $template = $this->createTemplate();
     $template->grid = $this;
     $template->defaultTemplate = __DIR__ . '/DataGrid.latte';
     $template->setFile($this->templateFile === NULL ? $this->templateFile = $template->defaultTemplate : $this->templateFile);
     $grid = $this;
     $latte = $template->getLatte();
     $latte->addFilter('translate', $this->translate);
     $latte->addFilter('primaryToString', $this->getRecord()->primaryToString);
     $latte->addFilter('getValue', $this->getRecord()->getValue);
     $latte->addFilter('sortLink', function (Components\Column $c, $m = Helpers::SORT_LINK_SINGLE) use($grid) {
         return Helpers::createSortLink($grid, $c, $m);
     });
     $this->isControlInvalid() && $this->redraw(FALSE, 'flashes');
     $template->form = $template->_form = $form = $this['form'];
     $this->presenter->payload->twiGrid['forms'][$form->elementPrototype->id] = (string) $form->getAction();
     $template->columns = $this->getColumns();
     $template->dataLoader = NCallback::closure($this, 'getData');
     $template->csrfToken = Helpers::getCsrfToken($this->session, $this->sessNamespace);
     $template->rowActions = $this->getRowActions();
     $template->hasRowActions = $template->rowActions !== NULL;
     $template->groupActions = $this->getGroupActions();
     $template->hasGroupActions = $template->groupActions !== NULL;
     $template->hasFilters = $this->filterFactory !== NULL;
     $template->hasInlineEdit = $this->ieContainerFactory !== NULL;
     $template->iePrimary = $this->iePrimary;
     $template->isPaginated = $this->itemsPerPage !== NULL;
     $template->columnCount = count($template->columns) + ($template->hasGroupActions ? 1 : 0) + ($template->hasFilters || $template->hasRowActions ? 1 : 0);
     $template->render();
 }
 /**
  * Adds a method to class.
  * @param  string
  * @param  string
  * @param  mixed   callable
  * @return void
  */
 public static function setExtensionMethod($class, $name, $callback)
 {
     $name = strtolower($name);
     self::$extMethods[$name][$class] = Nette\Utils\Callback::closure($callback);
     self::$extMethods[$name][''] = NULL;
 }
Ejemplo n.º 11
0
 /**
  * __get() implementation.
  * @param  object
  * @param  string  property name
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public static function &get($_this, string $name)
 {
     $class = get_class($_this);
     $uname = ucfirst($name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // property getter
         if ($methods[$m] === 0) {
             $methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $_this->{$m}();
         } else {
             $val = $_this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         if (preg_match('#^(is|get|has)([A-Z]|$)#', $name) && !(new \ReflectionMethod($class, $name))->getNumberOfRequiredParameters()) {
             $source = '';
             foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
                 if (isset($item['file']) && dirname($item['file']) !== __DIR__) {
                     $source = " in {$item['file']}:{$item['line']}";
                     break;
                 }
             }
             trigger_error("Did you forget parentheses after {$name}{$source}?", E_USER_WARNING);
         }
         $val = Callback::closure($_this, $name);
         return $val;
     } elseif (isset($methods['set' . $uname])) {
         // strict class
         throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
     } else {
         // strict class
         $hint = self::getSuggestion(array_merge(array_keys(get_class_vars($class)), self::parseFullDoc($class, '~^[ \\t*]*@property(?:-read)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
         throw new MemberAccessException("Cannot read an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
     }
 }
Ejemplo n.º 12
0
 /**
  * @return string
  */
 public function getPanel()
 {
     if (!$this->queries) {
         return NULL;
     }
     $esc = function ($s) {
         return htmlSpecialChars($s, ENT_QUOTES, 'UTF-8');
     };
     $click = class_exists('Tracy\\Dumper') ? function ($o, $c = FALSE, $d = 4) {
         return Dumper::toHtml($o, array(Dumper::COLLAPSE => $c, Dumper::DEPTH => $d, Dumper::TRUNCATE => 2000));
     } : Nette\Utils\Callback::closure('Tracy\\Helpers::clickableDump');
     $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
     $extractData = function ($object) {
         if ($object instanceof Elastica\Request) {
             $data = $object->getData();
         } elseif ($object instanceof Elastica\Response) {
             $data = $object->getData();
         } else {
             return array();
         }
         if ($object instanceof Elastica\Request) {
             $json = Json::decode((string) $object);
             return $json->data;
         }
         try {
             return !is_array($data) ? Json::decode($data, Json::FORCE_ARRAY) : $data;
         } catch (Nette\Utils\JsonException $e) {
             try {
                 return array_map(function ($row) {
                     return Json::decode($row, Json::FORCE_ARRAY);
                 }, explode("\n", trim($data)));
             } catch (Nette\Utils\JsonException $e) {
                 return $data;
             }
         }
     };
     $processedQueries = array();
     $allQueries = $this->queries;
     foreach ($allQueries as $authority => $requests) {
         /** @var Elastica\Request[] $item */
         foreach ($requests as $i => $item) {
             $processedQueries[$authority][$i] = $item;
             if (isset($item[3])) {
                 continue;
                 // exception, do not re-execute
             }
             if (stripos($item[0]->getPath(), '_search') === FALSE || $item[0]->getMethod() !== 'GET') {
                 continue;
                 // explain only search queries
             }
             if (!is_array($data = $extractData($item[0]))) {
                 continue;
             }
             try {
                 $response = $this->client->request($item[0]->getPath(), $item[0]->getMethod(), $item[0]->getData(), array('explain' => 1) + $item[0]->getQuery());
                 // replace the search response with the explained response
                 $processedQueries[$authority][$i][1] = $response;
             } catch (\Exception $e) {
                 // ignore
             }
         }
     }
     ob_start();
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
Ejemplo n.º 13
0
 /**
  * @param $name
  * @throws MemberAccessException
  * @return mixed
  */
 public function &__get($name)
 {
     if (!isset($this->autowireProperties[$name])) {
         return parent::__get($name);
     }
     if (empty($this->autowireProperties[$name]['value'])) {
         if (!empty($this->autowireProperties[$name]['factory'])) {
             $factory = Callback::closure($this->autowirePropertiesLocator->getService($this->autowireProperties[$name]['factory']), 'create');
             $this->autowireProperties[$name]['value'] = Callback::invokeArgs($factory, $this->autowireProperties[$name]['arguments']);
         } else {
             $this->autowireProperties[$name]['value'] = $this->autowirePropertiesLocator->getByType($this->autowireProperties[$name]['type']);
         }
     }
     return $this->autowireProperties[$name]['value'];
 }
Ejemplo n.º 14
0
 /**
  * __get() implementation.
  * @param  object
  * @param  string  property name
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public static function &get($_this, $name)
 {
     $class = get_class($_this);
     $uname = ucfirst($name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // property getter
         if ($methods[$m] === 0) {
             $methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $_this->{$m}();
         } else {
             $val = $_this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         $val = Callback::closure($_this, $name);
         return $val;
     } elseif (isset($methods['set' . $uname])) {
         // strict class
         throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
     } else {
         // strict class
         $hint = self::getSuggestion(array_merge(array_keys(get_class_vars($class)), self::parseFullDoc($class, '~^[ \\t*]*@property(?:-read)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
         throw new MemberAccessException("Cannot read an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
     }
 }
Ejemplo n.º 15
0
 /**
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public function &__get($name)
 {
     $class = get_class($this);
     $uname = ucfirst($name);
     if ($prop = ObjectMixin::getMagicProperty($class, $name)) {
         // property getter
         if (!($prop & 0b1)) {
             throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
         }
         $m = ($prop & 0b10 ? 'get' : 'is') . $uname;
         if ($prop & 0b100) {
             // return by reference
             return $this->{$m}();
         } else {
             $val = $this->{$m}();
             return $val;
         }
     } elseif ($name === '') {
         throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (($methods =& ObjectMixin::getMethods($class)) && isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // old property getter
         trigger_error("Add annotation @property for {$class}::\${$name} or use {$m}()" . ObjectMixin::getSource(), E_USER_DEPRECATED);
         if ($methods[$m] === 0) {
             $methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $this->{$m}();
         } else {
             $val = $this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         trigger_error("Accessing methods as properties via \$obj->{$name} is deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
         $val = Callback::closure($this, $name);
         return $val;
     } elseif (isset($methods['set' . $uname])) {
         // property getter
         throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
     } else {
         ObjectMixin::strictGet($class, $name);
     }
 }
Ejemplo n.º 16
0
 /**
  * @param  mixed $callback
  * @return DataGrid
  */
 public function setValueGetter($callback)
 {
     $this->valueGetter = NCallback::closure($callback);
     return $this;
 }
Ejemplo n.º 17
0
 /**
  * Rebuilds class list cache.
  * @return void
  */
 public function rebuild()
 {
     $this->rebuilt = TRUE;
     // prevents calling rebuild() or updateFile() in tryLoad()
     $this->getCache()->save($this->getKey(), Nette\Utils\Callback::closure($this, 'rebuildCallback'));
 }
 protected function beforeRender()
 {
     parent::beforeRender();
     $this->template->addonVotes = Callback::closure($this->addonVotes, 'calculatePopularity');
 }
Ejemplo n.º 19
0
 /**
  * @param string $methodName
  * @return void
  */
 public static function register($methodName = 'addDynamic')
 {
     if (self::$registered) {
         Nette\Forms\Container::extensionMethod(self::$registered, function () {
             throw new Nette\MemberAccessException();
         });
     }
     Nette\Forms\Container::extensionMethod($methodName, function (Nette\Forms\Container $_this, $name, $factory, $createDefault = 0, $forceDefault = FALSE) {
         $control = new Container($factory, $createDefault, $forceDefault);
         $control->currentGroup = $_this->currentGroup;
         return $_this[$name] = $control;
     });
     if (self::$registered) {
         return;
     }
     SubmitButton::extensionMethod('addRemoveOnClick', function (SubmitButton $_this, $callback = NULL) {
         $_this->setValidationScope(FALSE);
         $_this->onClick[] = function (SubmitButton $button) use($callback) {
             $replicator = $button->lookup(__NAMESPACE__ . '\\Container');
             /** @var Container $replicator */
             if (is_callable($callback)) {
                 Callback::invoke($callback, $replicator, $button->parent);
             }
             if ($form = $button->getForm(FALSE)) {
                 $form->onSuccess = array();
             }
             $replicator->remove($button->parent);
         };
         return $_this;
     });
     SubmitButton::extensionMethod('addCreateOnClick', function (SubmitButton $_this, $allowEmpty = FALSE, $callback = NULL) {
         $_this->onClick[] = function (SubmitButton $button) use($allowEmpty, $callback) {
             $replicator = $button->lookup(__NAMESPACE__ . '\\Container');
             /** @var Container $replicator */
             if (!is_bool($allowEmpty)) {
                 $callback = Callback::closure($allowEmpty);
                 $allowEmpty = FALSE;
             }
             if ($allowEmpty === TRUE || $replicator->isAllFilled() === TRUE) {
                 $newContainer = $replicator->createOne();
                 if (is_callable($callback)) {
                     Callback::invoke($callback, $replicator, $newContainer);
                 }
             }
             $button->getForm()->onSuccess = array();
         };
         return $_this;
     });
     self::$registered = $methodName;
 }
Ejemplo n.º 20
0
 /**
  * @param \Doctrine\DBAL\Connection $connection
  * @return Panel
  */
 public static function register(Doctrine\DBAL\Connection $connection)
 {
     $panel = new static();
     /** @var Panel $panel */
     $panel->setConnection($connection);
     $panel->registerBarPanel(static::getDebuggerBar());
     static::getDebuggerBlueScreen()->addPanel(Callback::closure($panel, 'renderQueryException'));
     return $panel;
 }
Ejemplo n.º 21
0
 /**
  * @param Doctrine\ORM\EntityManager $em
  * @return Panel
  */
 public function bindEntityManager(Doctrine\ORM\EntityManager $em)
 {
     if ($this->em !== NULL) {
         throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is already bound to entity manager.");
     }
     $this->em = $em;
     if ($this->em instanceof Kdyby\Doctrine\EntityManager) {
         $this->em->bindTracyPanel($this);
     }
     if ($this->connection === NULL) {
         $this->bindConnection($em->getConnection());
     }
     Debugger::getBlueScreen()->addPanel(Callback::closure($this, 'renderEntityManagerException'));
     return $this;
 }
Ejemplo n.º 22
0
 public function getClosure($object = NULL)
 {
     return PHP_VERSION_ID < 50400 ? Nette\Utils\Callback::closure($object ?: parent::getDeclaringClass()->getName(), $this->getName()) : parent::getClosure($object);
 }
 /**
  * Html code for DebuggerBar Tab
  * @return string
  */
 public function getTab()
 {
     return self::render(__DIR__ . '/templates/tab.phtml', array('src' => function ($file) {
         return \Nette\Templating\Helpers::dataStream(file_get_contents($file));
     }, 'esc' => \Nette\Utils\Callback::closure('Nette\\Templating\\Helpers::escapeHtml')));
 }
Ejemplo n.º 24
0
 /**
  * __get() implementation.
  * @param  object
  * @param  string  property name
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public static function &get($_this, $name)
 {
     $class = get_class($_this);
     $uname = ucfirst($name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // property getter
         if ($methods[$m] === 0) {
             $methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $_this->{$m}();
         } else {
             $val = $_this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         $val = Callback::closure($_this, $name);
         return $val;
     } else {
         // strict class
         $type = isset($methods['set' . $uname]) ? 'a write-only' : 'an undeclared';
         throw new MemberAccessException("Cannot read {$type} property {$class}::\${$name}.");
     }
 }
Ejemplo n.º 25
0
 public function beforeCompile()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig();
     $self = $this;
     $registerToLatte = function (Nette\DI\ServiceDefinition $def) use($self) {
         $def->addSetup('?->onCompile[] = function($engine) { Kdyby\\Translation\\Latte\\TranslateMacros::install($engine->getCompiler()); }', array('@self'))->addSetup('addFilter', array('translate', array($self->prefix('@helpers'), 'translate')))->addSetup('addFilter', array('getTranslator', array($self->prefix('@helpers'), 'getTranslator')));
     };
     $latteFactoryService = $builder->getByType('Nette\\Bridges\\ApplicationLatte\\ILatteFactory') ?: 'nette.latteFactory';
     if ($builder->hasDefinition($latteFactoryService)) {
         $registerToLatte($builder->getDefinition($latteFactoryService));
     }
     if ($builder->hasDefinition('nette.latte')) {
         $registerToLatte($builder->getDefinition('nette.latte'));
     }
     $applicationService = $builder->getByType('Nette\\Application\\Application') ?: 'application';
     $builder->getDefinition($applicationService)->addSetup('$service->onRequest[] = ?', array(array($this->prefix('@userLocaleResolver.param'), 'onRequest')));
     if ($config['debugger'] && interface_exists('Tracy\\IBarPanel')) {
         $builder->getDefinition($applicationService)->addSetup('$self = $this; $service->onStartup[] = function () use ($self) { $self->getService(?); }', array($this->prefix('default')))->addSetup('$service->onRequest[] = ?', array(array($this->prefix('@panel'), 'onRequest')));
     }
     Kdyby\Translation\Diagnostics\Panel::registerBluescreen();
     $extractor = $builder->getDefinition($this->prefix('extractor'));
     foreach ($builder->findByTag(self::EXTRACTOR_TAG) as $extractorId => $meta) {
         Validators::assert($meta, 'string:2..');
         $extractor->addSetup('addExtractor', array($meta, '@' . $extractorId));
         $builder->getDefinition($extractorId)->setAutowired(FALSE)->setInject(FALSE);
     }
     $writer = $builder->getDefinition($this->prefix('writer'));
     foreach ($builder->findByTag(self::DUMPER_TAG) as $dumperId => $meta) {
         Validators::assert($meta, 'string:2..');
         $writer->addSetup('addDumper', array($meta, '@' . $dumperId));
         $builder->getDefinition($dumperId)->setAutowired(FALSE)->setInject(FALSE);
     }
     $this->loaders = array();
     foreach ($builder->findByTag(self::LOADER_TAG) as $loaderId => $meta) {
         Validators::assert($meta, 'string:2..');
         $builder->getDefinition($loaderId)->setAutowired(FALSE)->setInject(FALSE);
         $this->loaders[$meta] = $loaderId;
     }
     $builder->getDefinition($this->prefix('loader'))->addSetup('injectServiceIds', array($this->loaders))->setInject(FALSE);
     foreach ($this->compiler->getExtensions() as $extension) {
         if (!$extension instanceof ITranslationProvider) {
             continue;
         }
         $config['dirs'] = array_merge($config['dirs'], array_values($extension->getTranslationResources()));
     }
     if ($dirs = array_values(array_filter($config['dirs'], Callback::closure('is_dir')))) {
         foreach ($dirs as $dir) {
             $builder->addDependency($dir);
         }
         $this->loadResourcesFromDirs($dirs);
     }
 }
Ejemplo n.º 26
0
 /**
  * __get() implementation.
  * @param  object
  * @param  string  property name
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public static function &get($_this, $name)
 {
     $class = get_class($_this);
     $uname = ucfirst($name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // property getter
         if ($methods[$m] === 0) {
             $methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $_this->{$m}();
         } else {
             $val = $_this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         if (preg_match('#^(is|get|has)([A-Z]|$)#', $name) && !(new \ReflectionMethod($class, $name))->getNumberOfRequiredParameters()) {
             trigger_error("Did you forget parentheses after {$name}" . self::getSource() . '?', E_USER_WARNING);
         }
         $val = Callback::closure($_this, $name);
         return $val;
     } elseif (isset($methods['set' . $uname])) {
         // property getter
         throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
     } else {
         self::strictGet($class, $name);
     }
 }