本文整理汇总了PHP中Nette\DI\ContainerBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder类的具体用法?PHP ContainerBuilder怎么用?PHP ContainerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupTemplating
/**
* @param \Nette\DI\ContainerBuilder $container
* @param array $config
*/
private function setupTemplating(ContainerBuilder $container, array $config)
{
$def = $container->addDefinition($this->prefix('templateFilesFormatter'))->setClass('Lohini\\Templating\\TemplateFilesFormatter')->addSetup('$skin', [$config['skin']]);
foreach ($config['dirs'] as $dir => $priority) {
$def->addSetup('addDir', Validators::isNumericInt($dir) ? [$priority] : [$container->expand($dir), $priority]);
}
}
示例2: addWebLoader
private function addWebLoader(\Nette\DI\ContainerBuilder $builder, $name, $config)
{
$filesServiceName = $this->prefix($name . 'Files');
$files = $builder->addDefinition($filesServiceName)->setClass('WebLoader\\FileCollection')->setArguments(array($config['sourceDir']));
foreach ($config['files'] as $file) {
// finder support
if (is_array($file) && isset($file['files']) && (isset($file['in']) || isset($file['from']))) {
$finder = \Nette\Utils\Finder::findFiles($file['files']);
unset($file['files']);
foreach ($file as $method => $params) {
call_user_func_array(array($finder, $method), array($params));
}
foreach ($finder as $foundFile) {
$files->addSetup('addFile', array((string) $foundFile));
}
} else {
$files->addSetup('addFile', array($file));
}
}
$files->addSetup('addRemoteFiles', array($config['remoteFiles']));
$compiler = $builder->addDefinition($this->prefix($name . 'Compiler'))->setClass('WebLoader\\Compiler')->setArguments(array('@' . $filesServiceName, $config['namingConvention'], $config['tempDir']));
$compiler->addSetup('setJoinFiles', array($config['joinFiles']));
foreach ($config['filters'] as $filter) {
$compiler->addSetup('addFilter', array($filter));
}
foreach ($config['fileFilters'] as $filter) {
$compiler->addSetup('addFileFilter', array($filter));
}
// todo css media
}
示例3: addWebLoader
private function addWebLoader(ContainerBuilder $builder, $name, $config)
{
$filesServiceName = $this->prefix($name . 'Files');
$files = $builder->addDefinition($filesServiceName)->setClass('WebLoader\\FileCollection')->setArguments(array($config['sourceDir']));
foreach ($this->findFiles($config['files'], $config['sourceDir']) as $file) {
$files->addSetup('addFile', array($file));
}
foreach ($this->findFiles($config['watchFiles'], $config['sourceDir']) as $file) {
$files->addSetup('addWatchFile', array($file));
}
$files->addSetup('addRemoteFiles', array($config['remoteFiles']));
$compiler = $builder->addDefinition($this->prefix($name . 'Compiler'))->setClass('WebLoader\\Compiler')->setArguments(array('@' . $filesServiceName, $config['namingConvention'], $config['tempDir']));
$compiler->addSetup('setJoinFiles', array($config['joinFiles']));
if ($builder->parameters['webloader']['debugger']) {
$compiler->addSetup('@' . $this->prefix('tracyPanel') . '::addLoader', array($name, '@' . $this->prefix($name . 'Compiler')));
}
foreach ($config['filters'] as $filter) {
$compiler->addSetup('addFilter', array($filter));
}
foreach ($config['fileFilters'] as $filter) {
$compiler->addSetup('addFileFilter', array($filter));
}
if (isset($config['debug']) && $config['debug']) {
$compiler->addSetup('enableDebugging');
}
$compiler->addSetup('setCheckLastModified', array($config['checkLastModified']));
// todo css media
}
示例4: createRepositoryService
protected function createRepositoryService($repositoryData, ContainerBuilder $builder, $mapperName)
{
$repositoryName = $this->prefix('repositories.' . $repositoryData['name']);
if (!$builder->hasDefinition($repositoryName)) {
$builder->addDefinition($repositoryName)->setClass($repositoryData['class'])->setArguments(['@' . $mapperName, '@' . $this->prefix('dependencyProvider')])->addSetup('onModelAttach', ['@' . $this->prefix('model')]);
}
}
示例5: setupCompileTemplatesCommand
private function setupCompileTemplatesCommand(ContainerBuilder $builder, array $config)
{
$config = $this->validateConfig($this->compileTemplatesDefaults, $config, 'compileTemplates');
Validators::assertField($config, 'source', 'string|array');
$builder->addDefinition($this->prefix('compileTemplates'))->setClass(CompileTemplatesCommand::class, [array_map(function ($directory) use($builder) {
Validators::assert($directory, 'string');
return Helpers::expand($directory, $builder->parameters);
}, (array) $config['source'])])->addTag(ConsoleExtension::TAG_COMMAND)->setAutowired(false);
}
示例6: getSortedConfigurators
/**
* @param ContainerBuilder $builder
* @return array
*/
private function getSortedConfigurators(ContainerBuilder $builder)
{
$configurators = $builder->findByTag(self::TAG_CONFIGURATOR);
uasort($configurators, function ($a, $b) {
$a = is_numeric($a) ? (double) $a : 0;
$b = is_numeric($b) ? (double) $b : 0;
return $a < $b ? -1 : ($a > $b ? 1 : 0);
});
return $configurators;
}
示例7: configMapper
/**
* Adds mapper service into container
* @return ServiceDefinition
*/
protected function configMapper(ContainerBuilder $builder, array $config)
{
if ($config['defaultEntityNamespace'] !== NULL && !is_string($config['defaultEntityNamespace'])) {
throw new \RuntimeException('DefaultEntityNamespace must be NULL or string, ' . gettype($config['defaultEntityNamespace']) . ' given');
}
$mapper = $builder->addDefinition($this->prefix('mapper'))->setClass($config['mapper'], array($config['defaultEntityNamespace']));
$this->processEntityProviders($mapper, $config);
$this->processUserEntities($mapper, $config);
return $mapper;
}
示例8: getByType
/**
* @param ContainerBuilder $container
* @param string $type
* @return ServiceDefinition|null
*/
private function getByType(ContainerBuilder $container, $type)
{
$definitionas = $container->getDefinitions();
foreach ($definitionas as $definition) {
if ($definition->class === $type) {
return $definition;
}
}
return NULL;
}
示例9: install
public function install(Nette\DI\ContainerBuilder $builder)
{
foreach ($this->listener as $class_name => $on) {
$definition = $builder->getDefinition("annevents." . $class_name);
foreach ($on as $on_name => $data) {
foreach ($data['call'] as $add) {
$definition->addSetup('$service->' . $on_name . '[]=?->' . $add['method'], array($builder->getDefinition('annevents.' . str_replace('\\', '_', $add['class']))));
}
}
}
}
示例10: createSubscribersMap
private function createSubscribersMap(\Nette\DI\ContainerBuilder $builder)
{
$map = [];
foreach ($builder->findByTag(self::TAG_SUBSCRIBER) as $serviceName => $tagProperties) {
$def = $builder->getDefinition($serviceName);
$class = $def->getClass();
$events = $class::getSubscribedEvents();
foreach ($events as $eventName => $callbacks) {
foreach ($callbacks as $function) {
$map[$eventName][] = [$serviceName, $function];
}
}
}
return $map;
}
示例11: findRoutes
/**
* @param Nette\DI\ContainerBuilder $builder
* @return array
*/
private function findRoutes(Nette\DI\ContainerBuilder $builder)
{
/**
* Find all presenters and their routes
*/
$presenters = $builder->findByTag('nette.presenter');
$routes = [];
foreach ($presenters as $presenter) {
$this->findRoutesInPresenter($presenter, $routes);
}
/**
* Return routes sorted by priority
*/
return $this->sortByPriority($routes);
}
示例12: processAuthenticators
/**
* @param ContainerBuilder $container
* @param array $config
*/
private function processAuthenticators(ContainerBuilder $container, array $config)
{
$authentication = $container->addDefinition($this->prefix('authentication'))->setClass('Flame\\Rest\\Security\\Authentication');
if (!$container->parameters['debugMode'] && count($config['ips'])) {
$ipAuthenticator = $container->addDefinition($this->prefix('ipAuthenticator'))->setClass('Flame\\Rest\\Security\\Authenticators\\IpAuthenticator')->setArguments(array($config['ips']));
$authentication->addSetup('addAuthenticator', array($ipAuthenticator));
}
if (!$container->parameters['debugMode'] && count($config['referers'])) {
$refererAuthenticator = $container->addDefinition($this->prefix('refererAuthenticator'))->setClass('Flame\\Rest\\Security\\Authenticators\\RefererAuthenticator')->setArguments(array($config['referers']));
$authentication->addSetup('addAuthenticator', array($refererAuthenticator));
}
foreach ($config['authenticators'] as $k => $authenticatorConfig) {
$authenticator = $container->addDefinition($this->prefix('authenticator' . $k))->setClass($authenticatorConfig);
$authentication->addSetup('addAuthenticator', array($authenticator));
}
}
示例13: prepareNetteDatabase
private function prepareNetteDatabase(\Nette\DI\ContainerBuilder $builder)
{
$ndbConnectionSectionKeys = ['dsn' => NULL, 'user' => NULL, 'password' => NULL];
/** @var \Nette\DI\CompilerExtension $extension */
foreach ($this->compiler->getExtensions('Nette\\Bridges\\DatabaseDI\\DatabaseExtension') as $extension) {
if (array_intersect_key($extension->config, $ndbConnectionSectionKeys)) {
$extensionConfig = $extension->config;
$definitionName = $extension->name . '.default.connection';
$builder->getDefinition($definitionName)->setClass('Testbench\\Mocks\\NetteDatabaseConnectionMock', [$extensionConfig['dsn'], $extensionConfig['user'], $extensionConfig['password'], isset($extensionConfig['options']) ? $extensionConfig['options'] + ['lazy' => TRUE] : []]);
} else {
foreach ($extension->config as $sectionName => $sectionConfig) {
$definitionName = $extension->name . '.' . $sectionName . '.connection';
$builder->getDefinition($definitionName)->setClass('Testbench\\Mocks\\NetteDatabaseConnectionMock', [$sectionConfig['dsn'], $sectionConfig['user'], $sectionConfig['password'], isset($sectionConfig['options']) ? $sectionConfig['options'] + ['lazy' => TRUE] : []]);
}
}
}
}
示例14: loadRoutes
/**
* Routes definition
*
* @param ContainerBuilder $container Container
* @param array $config Config
*
* @return void
*/
protected function loadRoutes(ContainerBuilder $container, $config)
{
$container->addDefinition($this->prefix('storages'))->setClass('MouseOver\\Storage\\Application\\StorageList');
$container->addDefinition($this->prefix('responder'))->setClass('MouseOver\\Storage\\Application\\StorageResponder');
$container->addDefinition($this->prefix('linkResolver'))->setClass('MouseOver\\Storage\\Application\\StorageLinkResolver', [$config['module']]);
$container->getDefinition('nette.latte')->addSetup('MouseOver\\Storage\\Application\\StorageMacros::install($service->getCompiler(), ?)', array($this->prefix('@linkResolver')));
$routesList = $container->addDefinition($this->prefix('storageRoutes'))->setClass('Nette\\Application\\Routers\\RouteList')->setAutowired(false);
$routesList->addSetup('$service[] = new Nette\\Application\\Routers\\Route(?, function ($presenter, $storage, $file) { return ?->handle($storage, $file, $presenter->request->getParameters()); })', array($config['module'] . '/<storage>/<file [a-zA-Z0-9\\-_.\\/]+>', $this->prefix('@responder')));
$container->getDefinition('router')->addSetup('MouseOver\\Storage\\DI\\StorageExtension::prependTo($service, ?)', [$this->prefix('@storageRoutes')]);
}
示例15: processPackages
/**
* @param ContainerBuilder $builder
* @throws \movi\InvalidArgumentException
*/
private function processPackages(ContainerBuilder $builder)
{
$manager = $builder->getDefinition($this->prefix('manager'));
$packages = $builder->parameters['packages'];
if (count($packages) > 0) {
foreach (array_values($packages) as $data) {
$class = $this->getPackageClass($data);
if (class_exists($class)) {
$package = new $class($data);
if (!$package instanceof Package) {
throw new InvalidArgumentException("Package class must be an instance of movi\\Packages\\Package.");
}
} else {
$package = new Package($data);
}
// Compile the package
$package->onCompile($this->compiler);
$this->processExtensions($package->extensions);
$manager->addSetup('addPackage', [$package]);
}
}
}