public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array(array(new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\FormatterHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper'), new Nette\DI\Statement('Kdyby\\Console\\Helpers\\PresenterHelper'))))->setInject(FALSE); $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->setInject(FALSE); $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE); $builder->getDefinition('router')->addSetup('Kdyby\\Console\\CliRouter::prependTo($service, ?)', array($this->prefix('@router'))); $builder->getDefinition('nette.presenterFactory')->addSetup('if (method_exists($service, ?)) { $service->setMapping(array(? => ?)); } ' . 'elseif (property_exists($service, ?)) { $service->mapping[?] = ?; }', array('setMapping', 'Kdyby', 'KdybyModule\\*\\*Presenter', 'mapping', 'Kdyby', 'KdybyModule\\*\\*Presenter')); if (!empty($config['url'])) { if (!preg_match('~^https?://[^/]+\\.[a-z]+(/.*)?$~', $config['url'])) { throw new Nette\Utils\AssertionException("The url '{$config['url']}' is not valid, please use this format: 'http://domain.tld/path'."); } $builder->getDefinition('nette.httpRequestFactory')->setClass('Kdyby\\Console\\HttpRequestFactory')->addSetup('setFakeRequestUrl', array($config['url'])); } $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::HELPER_TAG, 'dic'); Nette\Utils\Validators::assert($config, 'array'); foreach ($config['commands'] as $command) { $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command)))); list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command)); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::COMMAND_TAG); } }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $helperClasses = array('Symfony\\Component\\Console\\Helper\\FormatterHelper', 'Symfony\\Component\\Console\\Helper\\QuestionHelper', 'Kdyby\\Console\\Helpers\\PresenterHelper'); $helperClasses = array_map(function ($class) { return new Nette\DI\Statement($class); }, $helperClasses); if (class_exists('Symfony\\Component\\Console\\Helper\\ProgressHelper')) { $helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper', array(false)); } if (class_exists('Symfony\\Component\\Console\\Helper\\DialogHelper')) { $helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper', array(false)); } $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array($helperClasses))->setInject(FALSE); $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->addSetup('injectServiceLocator')->setInject(FALSE); $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::TAG_HELPER, 'dic'); if ($config['disabled']) { return; } $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE); Nette\Utils\Validators::assert($config, 'array'); foreach ($config['commands'] as $command) { $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command)))); list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command)); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::TAG_COMMAND); } }
public function afterCompile(Nette\PhpGenerator\ClassType $class) { $initialize = $class->getMethod('initialize'); $builder = $this->getContainerBuilder(); $options = $this->config; unset($options['bar'], $options['blueScreen']); if (isset($options['logSeverity'])) { $res = 0; foreach ((array) $options['logSeverity'] as $level) { $res |= is_int($level) ? $level : constant($level); } $options['logSeverity'] = $res; } foreach ($options as $key => $value) { if ($value !== NULL) { $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key; $initialize->addBody($builder->formatPhp('Tracy\\Debugger::' . $key . ' = ?;', Nette\DI\Compiler::filterArguments([$value]))); } } $logger = $builder->getDefinition($this->prefix('logger')); if ($logger->getFactory()->getEntity() !== 'Tracy\\Debugger::getLogger') { $initialize->addBody($builder->formatPhp('Tracy\\Debugger::setLogger(?);', [$logger])); } if ($this->debugMode) { foreach ((array) $this->config['bar'] as $item) { $initialize->addBody($builder->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments([$this->prefix('bar'), is_string($item) ? new Nette\DI\Statement($item) : $item]))); } if (!$this->cliMode) { $initialize->addBody('if ($tmp = $this->getByType("Nette\\Http\\Session", FALSE)) { $tmp->start(); Tracy\\Debugger::dispatch(); };'); } } foreach ((array) $this->config['blueScreen'] as $item) { $initialize->addBody($builder->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments([$this->prefix('blueScreen'), $item]))); } }
/** * @param Code\ClassType $class */ public function afterCompile(Code\ClassType $class) { $container = $this->getContainerBuilder(); $init = $class->methods['initialize']; /** @var Code\Method $init */ $blueScreen = 'Nette\\Diagnostics\\Debugger::' . (method_exists('Nette\\Diagnostics\\Debugger', 'getBlueScreen') ? 'getBlueScreen()' : '$blueScreen'); $init->addBody($container->formatPhp($blueScreen . '->addPanel(?);', Nette\DI\Compiler::filterArguments(array('Kdyby\\PayPalExpress\\Diagnostics\\Panel::renderException')))); }
private function getDbalFactory($dbal) { if ($dbal instanceof Nette\DI\Statement) { return Nette\DI\Compiler::filterArguments([$dbal])[0]; } elseif (is_string($dbal) && isset($this->dbals[$dbal])) { return $this->dbals[$dbal]; } else { return NULL; } }
/** * @param string $value * @return ServiceDefinition|NULL */ protected function buildDefinition($value) { if ($value === NULL) { return NULL; } $builder = $this->getContainerBuilder(); $definition = $builder->addDefinition($this->prefix(md5($value))); list($definition->factory) = Compiler::filterArguments(array(is_string($value) ? new Statement($value) : $value)); list($resolverClass) = (array) $builder->normalizeEntity($definition->getFactory()->getEntity()); if (class_exists($resolverClass)) { $definition->setClass($resolverClass); } return $definition; }
protected function loadJobs() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); foreach ($config['jobs'] as $subscriber) { $def = $builder->addDefinition($this->prefix('job.' . md5(Json::encode($subscriber)))); list($def->factory) = Compiler::filterArguments(array(is_string($subscriber) ? new Statement($subscriber) : $subscriber)); list($subscriberClass) = (array) $builder->normalizeEntity($def->factory->entity); if (class_exists($subscriberClass)) { $def->class = $subscriberClass; } $def->setAutowired(false); $def->addTag($config['cronJobTag']); } }
public function loadConfiguration() { $container = $this->getContainerBuilder(); $config = $this->compiler->getConfig(); if (isset($config['nette']['database'])) { // back compatibility $config = $config['nette']['database']; $prefix = 'nette.'; } else { $config = isset($config[$this->name]) ? $config[$this->name] : array(); $prefix = ''; } if (isset($config['dsn'])) { $config = array('default' => $config); } $autowired = TRUE; foreach ((array) $config as $name => $info) { if (!is_array($info)) { continue; } $this->validate($info, $this->databaseDefaults, 'database'); $info += array('autowired' => $autowired) + $this->databaseDefaults; $autowired = FALSE; foreach ((array) $info['options'] as $key => $value) { if (preg_match('#^PDO::\\w+\\z#', $key)) { unset($info['options'][$key]); $info['options'][constant($key)] = $value; } } $connection = $container->addDefinition($prefix . $this->prefix($name))->setClass('Nette\\Database\\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))->setAutowired($info['autowired'])->addSetup('Tracy\\Debugger::getBlueScreen()->addPanel(?)', array('Nette\\Bridges\\DatabaseTracy\\ConnectionPanel::renderException')); if (!$info['reflection']) { $reflection = NULL; } elseif (is_string($info['reflection'])) { $reflection = new Nette\DI\Statement(preg_match('#^[a-z]+\\z#', $info['reflection']) ? 'Nette\\Database\\Reflection\\' . ucfirst($info['reflection']) . 'Reflection' : $info['reflection'], strtolower($info['reflection']) === 'discovered' ? array($connection) : array()); } else { $tmp = Nette\DI\Compiler::filterArguments(array($info['reflection'])); $reflection = reset($tmp); } $container->addDefinition($prefix . $this->prefix("{$name}.context"))->setClass('Nette\\Database\\Context', array($connection, $reflection))->setAutowired($info['autowired']); if ($container->parameters['debugMode'] && $info['debugger']) { $connection->addSetup('Nette\\Database\\Helpers::createDebugPanel', array($connection, !empty($info['explain']), $name)); } } }
public function afterCompile(Nette\PhpGenerator\ClassType $class) { $container = $this->getContainerBuilder(); if ($container->parameters['debugMode']) { $initialize = $class->methods['initialize']; foreach ($this->compiler->getExtensions() as $extension) { if ($extension instanceof ITracyBarPanelsProvider) { foreach ($extension->getTracyBarPanels() as $item) { $initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBar()->addPanel(?);', Nette\DI\Compiler::filterArguments(array(is_string($item) ? new Nette\DI\Statement($item) : $item)))); } } if ($extension instanceof ITracyPanelsProvider) { foreach ($extension->getTracyPanels() as $item) { $initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?);', Nette\DI\Compiler::filterArguments(array($item)))); } } } } }
/** * @inheritdoc */ public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->validateConfig($this->defaults); Validators::assertField($config, 'debugger', 'bool'); $builder->addDefinition($this->prefix('panel'))->setClass('Tracy\\IBarPanel')->setFactory('Ark8\\Security\\Tracy\\AuthorizatorPanel')->setAutowired(FALSE); $builder->addDefinition($this->prefix('resourceFactory'))->setClass('Ark8\\Security\\Resources\\ResourceFactory'); $builder->addDefinition($this->prefix('validator'))->setClass('Ark8\\Security\\Validator'); Validators::assertField($config, 'policy', 'bool'); $builder->addDefinition($this->prefix('authorizator'))->setClass('Nette\\Security\\IAuthorizator')->setFactory('Ark8\\Security\\Authorizators\\AuthorizatorList', [$config['policy']])->setAutowired(FALSE); // will be set to true later $builder->addDefinition($this->prefix('proxy'))->setClass('Nette\\Security\\IAuthorizator')->setFactory('Ark8\\Security\\Authorizators\\ProxyAuthorizator')->setAutowired(FALSE)->addTag($this->prefix(self::AUTHORIZATOR_TAG), -1); Validators::assertField($config, 'authorizators', 'array'); $priority = count($config['authorizators']); foreach ($config['authorizators'] as $class) { list($factory) = Compiler::filterArguments([is_string($class) ? new Statement($class) : $class]); $builder->addDefinition($this->prefix('authorizator.' . $priority))->setClass('Nette\\Security\\IAuthorizator')->setFactory($factory)->setAutowired(FALSE)->addTag($this->prefix(self::AUTHORIZATOR_TAG), $priority--); } }
public function afterCompile(Nette\PhpGenerator\ClassType $class) { $initialize = $class->getMethod('initialize'); $container = $this->getContainerBuilder(); $options = $this->config; unset($options['bar'], $options['blueScreen']); foreach ($options as $key => $value) { if ($value !== NULL) { $initialize->addBody('Tracy\\Debugger::$? = ?;', array($key, $value)); } } if ($this->debugMode) { foreach ((array) $this->config['bar'] as $item) { $initialize->addBody($container->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments(array($this->prefix('bar'), is_string($item) ? new Nette\DI\Statement($item) : $item)))); } } foreach ((array) $this->config['blueScreen'] as $item) { $initialize->addBody($container->formatPhp('$this->getService(?)->addPanel(?);', Nette\DI\Compiler::filterArguments(array($this->prefix('blueScreen'), $item)))); } }
public function loadConfiguration() { parent::loadConfiguration(); $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); Nette\Utils\Validators::assert($config, 'array'); $contentsArguments = [$config['configurationDirectory'], $config['logDirectory']]; if (!is_null($config['logDirectory'])) { $contentsArguments[2] = '@tracy.logger'; } $builder->addDefinition($this->prefix('contents'))->setClass('Trejjam\\Contents\\Contents')->setArguments($contentsArguments); foreach ($config['subTypes'] as $subTypeName => $subType) { $def = $builder->addDefinition($this->prefix('contents.' . md5(Nette\Utils\Json::encode($subType)))); $def->addSetup('setName', [$subTypeName]); $def->setFactory(Nette\DI\Compiler::filterArguments([is_string($subType) ? new Nette\DI\Statement($subType) : $subType])[0]); $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::TAG_CONTENTS_SUBTYPES); } }
private function setupDatabase($config, $name) { $container = $this->getContainerBuilder(); foreach ((array) $config['options'] as $key => $value) { if (preg_match('#^PDO::\\w+\\z#', $key)) { unset($config['options'][$key]); $config['options'][constant($key)] = $value; } } $connection = $container->addDefinition($this->prefix("{$name}.connection"))->setClass(Nette\Database\Connection::class, [$config['dsn'], $config['user'], $config['password'], $config['options']])->setAutowired($config['autowired']); $structure = $container->addDefinition($this->prefix("{$name}.structure"))->setClass(Nette\Database\Structure::class)->setArguments([$connection])->setAutowired($config['autowired']); if (!empty($config['reflection'])) { $conventionsServiceName = 'reflection'; $config['conventions'] = $config['reflection']; if (strtolower($config['conventions']) === 'conventional') { $config['conventions'] = 'Static'; } } else { $conventionsServiceName = 'conventions'; } if (!$config['conventions']) { $conventions = NULL; } elseif (is_string($config['conventions'])) { $conventions = $container->addDefinition($this->prefix("{$name}.{$conventionsServiceName}"))->setClass(preg_match('#^[a-z]+\\z#i', $config['conventions']) ? 'Nette\\Database\\Conventions\\' . ucfirst($config['conventions']) . 'Conventions' : $config['conventions'])->setArguments(strtolower($config['conventions']) === 'discovered' ? [$structure] : [])->setAutowired($config['autowired']); } else { $tmp = Nette\DI\Compiler::filterArguments([$config['conventions']]); $conventions = reset($tmp); } $container->addDefinition($this->prefix("{$name}.context"))->setClass(Nette\Database\Context::class, [$connection, $structure, $conventions])->setAutowired($config['autowired']); if ($config['debugger']) { $connection->addSetup('@Tracy\\BlueScreen::addPanel', ['Nette\\Bridges\\DatabaseTracy\\ConnectionPanel::renderException']); if ($this->debugMode) { $connection->addSetup('Nette\\Database\\Helpers::createDebugPanel', [$connection, !empty($config['explain']), $name]); } } if ($this->name === 'database') { $container->addAlias($this->prefix($name), $this->prefix("{$name}.connection")); $container->addAlias("nette.database.{$name}", $this->prefix($name)); $container->addAlias("nette.database.{$name}.context", $this->prefix("{$name}.context")); } }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $helperClasses = array('Symfony\\Component\\Console\\Helper\\DialogHelper', 'Symfony\\Component\\Console\\Helper\\FormatterHelper', 'Symfony\\Component\\Console\\Helper\\QuestionHelper', 'Kdyby\\Console\\Helpers\\PresenterHelper'); if (class_exists('Symfony\\Component\\Console\\Helper\\ProgressHelper')) { $helperClasses[] = 'Symfony\\Component\\Console\\Helper\\ProgressHelper'; } $helperClasses = array_map(function ($class) { return new Nette\DI\Statement($class); }, $helperClasses); $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array($helperClasses))->setInject(FALSE); $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->addSetup('injectServiceLocator')->setInject(FALSE); $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::HELPER_TAG, 'dic'); if ($config['disabled']) { return; } if (PHP_SAPI === 'cli') { $builder->getDefinition('application')->addSetup('$self = $this; $service->onError[] = function ($app, $e) use ($self) {' . "\n" . "\t" . '$app->errorPresenter = ?;' . "\n" . "\t" . '$app->onShutdown[] = function () { exit(?); };' . "\n" . "\t" . '$self->getService(?)->handleException($e); ' . "\n" . '}', array(FALSE, 254, $this->prefix('application'))); } $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE); $builder->getDefinition('router')->addSetup('Kdyby\\Console\\CliRouter::prependTo($service, ?)', array($this->prefix('@router'))); $builder->getDefinition('nette.presenterFactory')->addSetup('if (method_exists($service, ?)) { $service->setMapping(array(? => ?)); } ' . 'elseif (property_exists($service, ?)) { $service->mapping[?] = ?; }', array('setMapping', 'Kdyby', 'KdybyModule\\*\\*Presenter', 'mapping', 'Kdyby', 'KdybyModule\\*\\*Presenter')); if (!empty($config['url'])) { if (!preg_match('~^https?://[^/]+(/.*)?$~', $config['url'])) { throw new Nette\Utils\AssertionException("The url '{$config['url']}' is not valid, please use this format: 'http://domain.tld/path'."); } $builder->getDefinition('nette.httpRequestFactory')->setClass('Kdyby\\Console\\HttpRequestFactory')->addSetup('setFakeRequestUrl', array($config['url'])); } Nette\Utils\Validators::assert($config, 'array'); foreach ($config['commands'] as $command) { $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command)))); list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command)); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::COMMAND_TAG); } }
public function loadConfiguration() { $container = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); Validators::assert($config['timestampStorage'], 'string|object|null', 'Timestamp storage definition'); Validators::assert($config['maxExecutionTime'], 'integer|null', 'Script max execution time'); Validators::assert($config['criticalSectionTempDir'], 'string', 'Critical section files directory path'); if ($config['timestampStorage'] === NULL) { $storageServiceName = $container->getByType('stekycz\\Cronner\\ITimestampStorage'); $storage = $this->createTimestampStorage($container); if ($storageServiceName) { $storage->setFactory('@' . $storageServiceName); } else { $storage->setClass(self::DEFAULT_STORAGE_CLASS, array($container->expand(self::DEFAULT_STORAGE_DIRECTORY))); } } else { $storage = $this->createTimestampStorage($container); if (is_string($config['timestampStorage']) && $container->getServiceName($config['timestampStorage'])) { $storage->setFactory($config['timestampStorage']); } else { $storage->setClass($config['timestampStorage']->entity, $config['timestampStorage']->arguments); } } $criticalSection = $container->addDefinition($this->prefix("criticalSection"))->setClass('stekycz\\Cronner\\CriticalSection', array($config['criticalSectionTempDir']))->setAutowired(FALSE)->setInject(FALSE); $runner = $container->addDefinition($this->prefix('runner'))->setClass('stekycz\\Cronner\\Cronner', array($storage, $criticalSection, $config['maxExecutionTime'], array_key_exists('debugMode', $config) ? !$config['debugMode'] : TRUE)); Validators::assert($config['tasks'], 'array'); foreach ($config['tasks'] as $task) { $def = $container->addDefinition($this->prefix('task.' . md5(Json::encode($task)))); list($def->factory) = Compiler::filterArguments(array(is_string($task) ? new Statement($task) : $task)); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::TASKS_TAG); } if ($config['bar'] && class_exists('Tracy\\Bar')) { $container->addDefinition($this->prefix('bar'))->setClass('stekycz\\Cronner\\Bar\\Tasks', array($this->prefix('@runner'), $this->prefix('@timestampStorage'))); } }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $this->loadHelperSet($config); $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->addSetup('injectServiceLocator')->setInject(FALSE); if ($config['disabled']) { return; } $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE); Nette\Utils\Validators::assert($config, 'array'); foreach ($config['commands'] as $command) { $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command)))); list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Statement($command) : $command)); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::TAG_COMMAND); } }
public function loadConfiguration() { $container = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $container->addDefinition($this->prefix('cli'))->setClass($config['applicationClass']); Validators::assert($config['commands'], 'array'); Validators::assert($config['console'], 'array'); foreach ($config['commands'] as $key => $command) { $def = $container->addDefinition($this->prefix('command.' . $key)); list($def->factory) = Compiler::filterArguments([is_string($command) ? new Statement($command) : $command]); if (class_exists($def->factory->entity)) { $def->class = $def->factory->entity; } $def->setAutowired(false); $def->setInject(false); $def->addTag(self::TAG_JOSEKI_COMMAND); $def->addTag(self::TAG_KDYBY_COMMAND); } foreach ($config['console'] as $key => $prefix) { $this->consoleDefinitions[$key] = $container->addDefinition($this->prefix('console.' . $key))->setClass('Joseki\\Console\\CleverApplication', [$prefix]); } }
private function setupDatabase(ContainerBuilder $container, array $config) { if (isset($config['dsn'])) { $config = array('default' => $config); } $autowired = true; foreach ((array) $config as $name => $info) { if (!is_array($info)) { continue; } $this->validate($info, $this->databaseDefaults, 'flunorette'); $info += array('autowired' => $autowired) + $this->databaseDefaults; $autowired = false; foreach (array('transactionCounter', 'delimiteMode', 'lazy', 'driverClass') as $option) { if (isset($info[$option])) { $info['options'][$option] = $info[$option]; } } foreach ((array) $info['options'] as $key => $value) { if (preg_match('#^PDO::\\w+\\z#', $key)) { unset($info['options'][$key]); $info['options'][constant($key)] = $value; } } if (!$info['reflection']) { $reflection = null; } elseif (is_string($info['reflection'])) { $reflection = new Statement(preg_match('#^[a-z]+\\z#', $info['reflection']) ? 'Flunorette\\Reflections\\' . ucfirst($info['reflection']) . 'Reflection' : $info['reflection'], strtolower($info['reflection']) === 'discovered' ? array('@self') : array()); } else { $tmp = Compiler::filterArguments(array($info['reflection'])); $reflection = reset($tmp); } $connection = $container->addDefinition($this->prefix($name))->setClass('Flunorette\\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))->setAutowired($info['autowired'])->addSetup('setCacheStorage')->addSetup('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?)', array('Flunorette\\Bridges\\Nette\\Diagnostics\\ConnectionPanel::renderException')); if ($container->parameters['debugMode'] && $info['debugger']) { $connection->addSetup('Flunorette\\Helpers::createDebugPanel', array($connection, !empty($info['explain']), $name)); } } }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); $this->loadHelperSet($config); $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', [$config['name'], $config['version']])->addSetup('setHelperSet', [$this->prefix('@helperSet')])->addSetup('injectServiceLocator')->setInject(FALSE); if ($config['disabled']) { return; } if ($config['application'] && $this->isNetteApplicationPresent()) { $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE); } Nette\Utils\Validators::assert($config, 'array'); foreach ($config['commands'] as $i => $command) { $def = $builder->addDefinition($this->prefix('command.' . $i)); $def->setFactory(Nette\DI\Compiler::filterArguments([is_string($command) ? new Statement($command) : $command])[0]); if (class_exists($def->getEntity())) { $def->setClass($def->getEntity()); } $def->setAutowired(FALSE); $def->setInject(FALSE); $def->addTag(self::TAG_COMMAND); } }
public function afterCompile(ClassType $class) { $initialize = $class->methods['initialize']; $container = $this->getContainerBuilder(); $initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::$bar->addPanel(?);', Compiler::filterArguments([new \Nette\DI\Statement('movi\\Diagnostics\\Stopwatch\\Stopwatch')]))); }
/** * @param string|\stdClass $statement * @return Nette\DI\Statement[] */ public static function filterArgs($statement) { return Nette\DI\Compiler::filterArguments(array(is_string($statement) ? new Nette\DI\Statement($statement) : $statement)); }
/** * @param string|Nette\DI\Statement $statement * @return Nette\DI\Statement */ private static function filterArgs($statement) { $args = Nette\DI\Compiler::filterArguments(array(is_string($statement) ? new Nette\DI\Statement($statement) : $statement)); return $args[0]; }
public function afterCompile(Nette\PhpGenerator\ClassType $class) { $initialize = $class->methods['initialize']; $container = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); // debugger foreach (array('email', 'editor', 'browser', 'strictMode', 'maxLen', 'maxDepth', 'showLocation', 'scream') as $key) { if (isset($config['debugger'][$key])) { $initialize->addBody('Nette\\Diagnostics\\Debugger::$? = ?;', array($key, $config['debugger'][$key])); } } if ($container->parameters['debugMode']) { if ($config['container']['debugger']) { $config['debugger']['bar'][] = 'Nette\\DI\\Diagnostics\\ContainerPanel'; } foreach ((array) $config['debugger']['bar'] as $item) { $initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBar()->addPanel(?);', Nette\DI\Compiler::filterArguments(array(is_string($item) ? new Nette\DI\Statement($item) : $item)))); } foreach ((array) $config['debugger']['blueScreen'] as $item) { $initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?);', Nette\DI\Compiler::filterArguments(array($item)))); } } if (!empty($container->parameters['tempDir'])) { $initialize->addBody('Nette\\Caching\\Storages\\FileStorage::$useDirectories = ?;', array($this->checkTempDir($container->expand('%tempDir%/cache')))); } foreach ((array) $config['forms']['messages'] as $name => $text) { $initialize->addBody('Nette\\Forms\\Rules::$defaultMessages[Nette\\Forms\\Form::?] = ?;', array($name, $text)); } if ($config['session']['autoStart'] === 'smart') { $initialize->addBody('$this->getByType("Nette\\Http\\Session")->exists() && $this->getByType("Nette\\Http\\Session")->start();'); } elseif ($config['session']['autoStart']) { $initialize->addBody('$this->getByType("Nette\\Http\\Session")->start();'); } if ($config['latte']['xhtml']) { $initialize->addBody('Nette\\Utils\\Html::$xhtml = ?;', array(TRUE)); } if (isset($config['security']['frames']) && $config['security']['frames'] !== TRUE) { $frames = $config['security']['frames']; if ($frames === FALSE) { $frames = 'DENY'; } elseif (preg_match('#^https?:#', $frames)) { $frames = "ALLOW-FROM {$frames}"; } $initialize->addBody('header(?);', array("X-Frame-Options: {$frames}")); } foreach ($container->findByTag('run') as $name => $on) { if ($on) { $initialize->addBody('$this->getService(?);', array($name)); } } if (!empty($config['container']['accessors'])) { $definitions = $container->definitions; ksort($definitions); foreach ($definitions as $name => $def) { if (Nette\PhpGenerator\Helpers::isIdentifier($name)) { $type = $def->implement ?: $def->class; $class->addDocument("@property {$type} \${$name}"); } } } $initialize->addBody("@header('Content-Type: text/html; charset=utf-8');"); $initialize->addBody('Nette\\Utils\\SafeStream::register();'); }
/** * @param array * @return array */ protected function getTargets($config) { $targets = $config['targets']; unset($config['processors'], $config['targets']); $targets = array_merge($targets, $config); foreach ($targets as &$target) { $target['type'] = array_map(function ($val) { return ltrim(strtolower($val), '\\'); }, (array) $target['type']); } return Compiler::filterArguments($targets); }
/** * @param string|\stdClass $statement * @return Nette\DI\Statement[] */ protected static function filterArgs($statement) { return Nette\DI\Compiler::filterArguments([is_string($statement) ? new Nette\DI\Statement($statement) : $statement]); }