setArguments() public method

public setArguments ( array $args = [] ) : self
$args array
return self
Exemplo n.º 1
0
 function getAssets()
 {
     $serviceDefinition = new ServiceDefinition();
     $serviceDefinition->setClass('Mike227\\NAssetic\\AssetCollection');
     $serviceDefinition->setArguments(array(array('test6.js'), array(new TestFilter('#FILTER')), __DIR__ . '/../sources/'));
     return array('js1' => new GlobAsset(__DIR__ . '/../sources/test1.*'), 'js2' => array(new GlobAsset(__DIR__ . '/../sources/test2.*'), __DIR__ . '/../sources/test3.js', array(__DIR__ . '/../sources/test4.js', new GlobAsset(__DIR__ . '/../sources/test5.*')), 'serviceDef' => $serviceDefinition));
 }
Exemplo n.º 2
0
 /**
  * @param string $class
  * @return ServiceDefinition
  */
 public function createServiceDefinition($class)
 {
     $definition = new ServiceDefinition();
     $definition->setClass($class);
     $definition->addTag('kdyby.subscriber');
     $definition->setArguments($this->arguments);
     return $definition;
 }
Exemplo n.º 3
0
 public function loadConfiguration()
 {
     $this->_config = $this->getConfig($this->defaults);
     $this->validateConfiguration($this->_config);
     $this->debugMode = $this->_config['debugMode'];
     $builder = $this->containerBuilder;
     // Filters
     $this->filters = $this->_config['filters'];
     $filterManager = $builder->addDefinition($this->prefix('filterManager'))->setClass('Assetic\\FilterManager');
     self::setupFilters($filterManager, $this->filters);
     // Asset manager
     $this->manager = $builder->addDefinition($this->prefix('assetManager'))->setClass('Mike227\\NAssetic\\AssetManager');
     // Environment
     if ($this->_config['environment'] === NULL) {
         $this->_config['environment'] = '@' . $this->prefix('globalEnvironment');
         $GlobalEnvironment = $builder->addDefinition($this->prefix('globalEnvironment'))->setClass('Mike227\\NAssetic\\GlobalEnvironment');
         $GlobalEnvironment->addSetup('addItem', array('configHash', md5(serialize($this->_config))));
     }
     // Assert writer
     $this->writer = $builder->addDefinition($this->prefix('assetWriter'))->setClass('Mike227\\NAssetic\\AssetWriter');
     $this->writer->setArguments(array($this->_config['targetDir'], $this->manager, $this->_config['environment'], $this->_config['writerTempFile']));
     // Assert loader
     $this->loader = $builder->addDefinition($this->prefix('assetLoader'))->setClass('Mike227\\NAssetic\\AssetLoader');
     $this->loader->setArguments(array($this->_config['webPath'], $this->prefix('assetManager'), $this->prefix('assetWriter'), '@container', '@Nette\\Http\\IRequest', $this->_config['environment'], '@Nette\\Caching\\IStorage'));
     // Register Latte macro
     $builder->getDefinition('nette.latte')->addSetup('\\Mike227\\NAssetic\\Latte\\AssetWebPathMacro::install(?->getCompiler())', array('@self'));
     if ($builder->hasDefinition('nette.latteFactory')) {
         $builder->getDefinition('nette.latteFactory')->addSetup('\\Mike227\\NAssetic\\Latte\\AssetWebPathMacro::install(?->getCompiler())', array('@self'));
     }
     // Console commands
     if (PHP_SAPI === 'cli' || substr(PHP_SAPI, 0, 3) === 'cgi') {
         $builder->addDefinition($this->prefix('consoleCommandClearAll'))->setClass('Mike227\\NAssetic\\Console\\Command\\ClearAll')->addTag('kdyby.console.command');
         $builder->addDefinition($this->prefix('consoleCommandClearCollection'))->setClass('Mike227\\NAssetic\\Console\\Command\\ClearCollection')->addTag('kdyby.console.command');
         $builder->addDefinition($this->prefix('consoleCommandWatchChanges'))->setClass('Mike227\\NAssetic\\Console\\Command\\WatchChanges')->addTag('kdyby.console.command');
         $builder->addDefinition($this->prefix('consoleCommandApplyChanges'))->setClass('Mike227\\NAssetic\\Console\\Command\\ApplyChanges')->setArguments(array($this->_config['watcherTempFile'], $this->prefix('@assetManager'), $this->prefix('@assetWriter')))->addTag('kdyby.console.command');
         $builder->addDefinition($this->prefix('consoleAssetWriterHelper'))->setClass('Mike227\\NAssetic\\Console\\Helper\\AssetWriterHelper')->setArguments(array('@container', $this->prefix('assetWriter')))->addTag('kdyby.console.helper');
         $builder->addDefinition($this->prefix('consoleAssetManagerHelper'))->setClass('Mike227\\NAssetic\\Console\\Helper\\AssetManagerHelper')->setArguments(array('@container', $this->prefix('assetManager')))->addTag('kdyby.console.helper');
     }
 }
Exemplo n.º 4
0
 /**
  * Parses single service from configuration file.
  * @return void
  */
 public static function parseService(Nette\DI\ServiceDefinition $definition, $config, $shared = TRUE)
 {
     if ($config === NULL) {
         return;
     } elseif (!is_array($config)) {
         $config = array('class' => NULL, 'factory' => $config);
     }
     $known = $shared ? array('class', 'factory', 'arguments', 'setup', 'autowired', 'run', 'tags') : array('class', 'factory', 'arguments', 'setup', 'autowired', 'tags', 'internal', 'parameters');
     if ($error = array_diff(array_keys($config), $known)) {
         throw new Nette\InvalidStateException("Unknown key '" . implode("', '", $error) . "' in definition of service.");
     }
     $arguments = array();
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = self::filterArguments($config['arguments']);
         $definition->setArguments($arguments);
     }
     if (array_key_exists('class', $config) || array_key_exists('factory', $config)) {
         $definition->class = NULL;
         $definition->factory = NULL;
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|stdClass|null');
         if ($config['class'] instanceof \stdClass) {
             $definition->setClass($config['class']->value, self::filterArguments($config['class']->attributes));
         } else {
             $definition->setClass($config['class'], $arguments);
         }
     }
     if (array_key_exists('factory', $config)) {
         Validators::assertField($config, 'factory', 'callable|stdClass|null');
         if ($config['factory'] instanceof \stdClass) {
             $definition->setFactory($config['factory']->value, self::filterArguments($config['factory']->attributes));
         } else {
             $definition->setFactory($config['factory'], $arguments);
         }
     }
     if (isset($config['setup'])) {
         if (Helpers::takeParent($config['setup'])) {
             $definition->setup = array();
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|stdClass', "setup item #{$id}");
             if ($setup instanceof \stdClass) {
                 Validators::assert($setup->value, 'callable', "setup item #{$id}");
                 $definition->addSetup($setup->value, self::filterArguments($setup->attributes));
             } else {
                 $definition->addSetup($setup);
             }
         }
     }
     $definition->setShared($shared);
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['internal'])) {
         Validators::assertField($config, 'internal', 'bool');
         $definition->setInternal($config['internal']);
     }
     if (isset($config['run'])) {
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Helpers::takeParent($config['tags'])) {
             $definition->tags = array();
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Parses single service from configuration file.
  * @return void
  */
 public static function parseService(ServiceDefinition $definition, $config)
 {
     if ($config === NULL) {
         return;
     } elseif (is_string($config) && interface_exists($config)) {
         $config = ['class' => NULL, 'implement' => $config];
     } elseif ($config instanceof Statement && is_string($config->getEntity()) && interface_exists($config->getEntity())) {
         $config = ['class' => NULL, 'implement' => $config->getEntity(), 'factory' => array_shift($config->arguments)];
     } elseif (!is_array($config) || isset($config[0], $config[1])) {
         $config = ['class' => NULL, 'create' => $config];
     }
     if (array_key_exists('factory', $config)) {
         $config['create'] = $config['factory'];
         unset($config['factory']);
     }
     $known = ['class', 'create', 'arguments', 'setup', 'autowired', 'dynamic', 'inject', 'parameters', 'implement', 'run', 'tags'];
     if ($error = array_diff(array_keys($config), $known)) {
         throw new Nette\InvalidStateException(sprintf("Unknown or deprecated key '%s' in definition of service.", implode("', '", $error)));
     }
     $config = Helpers::filterArguments($config);
     $arguments = [];
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = $config['arguments'];
         $definition->setArguments($arguments);
     }
     if (array_key_exists('class', $config) || array_key_exists('create', $config)) {
         $definition->setClass(NULL);
         $definition->setFactory(NULL);
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|Nette\\DI\\Statement|null');
         if (!$config['class'] instanceof Statement) {
             $definition->setClass($config['class']);
         }
         $definition->setFactory($config['class'], $arguments);
     }
     if (array_key_exists('create', $config)) {
         Validators::assertField($config, 'create', 'callable|Nette\\DI\\Statement|null');
         $definition->setFactory($config['create'], $arguments);
     }
     if (isset($config['setup'])) {
         if (Config\Helpers::takeParent($config['setup'])) {
             $definition->setSetup([]);
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|Nette\\DI\\Statement', "setup item #{$id}");
             $definition->addSetup($setup);
         }
     }
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['implement'])) {
         Validators::assertField($config, 'implement', 'string');
         $definition->setImplement($config['implement']);
         $definition->setAutowired(TRUE);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['dynamic'])) {
         Validators::assertField($config, 'dynamic', 'bool');
         $definition->setDynamic($config['dynamic']);
     }
     if (isset($config['inject'])) {
         Validators::assertField($config, 'inject', 'bool');
         $definition->addTag(Extensions\InjectExtension::TAG_INJECT, $config['inject']);
     }
     if (isset($config['run'])) {
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Config\Helpers::takeParent($config['tags'])) {
             $definition->setTags([]);
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @param string $class
  * @return ServiceDefinition
  * @throws \Nette\InvalidArgumentException
  */
 public function createServiceDefinition($class)
 {
     // Validate annotation attributes
     if (count($this->parameters) === 0) {
         throw new InvalidArgumentException("Annotation  @" . get_class() . " of class {$class} expects one or more parameters.");
     }
     // Create service definition
     $definition = new ServiceDefinition();
     $definition->setClass($class);
     $definition->setInject(TRUE);
     // Parameters for service's constructor
     $serviceParameters = array();
     // One parameter - @DaoManager("Name\Space\EntityClass")
     if (count($this->parameters) === 1 && isset($this->parameters[0])) {
         $entityName = $this->parameters[0];
         $daoParameters = $this->findConstructorDaoParameters($class);
         if (count($daoParameters) === 0) {
             throw new InvalidArgumentException("Annotation  @" . get_class() . ": {$class}::__construct() does not contain attribute with type hint " . self::DAO_CLASS);
         } else {
             if (count($daoParameters) > 1) {
                 throw new InvalidArgumentException("Annotation  @" . get_class() . ": {$class}::__construct() contains multiple attributes with type hint " . self::DAO_CLASS);
             }
         }
         $serviceParameters = array($daoParameters[0] => $this->createDaoStatement($entityName));
     } else {
         foreach ($this->parameters as $attributeName => $entityName) {
             $serviceParameters[$attributeName] = $this->createDaoStatement($entityName);
         }
     }
     $definition->setArguments($serviceParameters);
     return $definition;
 }
Exemplo n.º 7
0
	/**
	 * Parses single service from configuration file.
	 * @return void
	 */
	public static function parseService(ServiceDefinition $definition, $config)
	{
		if ($config === NULL) {
			return;

		} elseif (is_string($config) && interface_exists($config)) {
			$config = array('class' => NULL, 'implement' => $config);

		} elseif ($config instanceof \stdClass && interface_exists($config->value)) {
			$config = array('class' => NULL, 'implement' => $config->value, 'factory' => array_shift($config->attributes));

		} elseif (!is_array($config)) {
			$config = array('class' => NULL, 'create' => $config);
		}

		if (array_key_exists('factory', $config)) {
			$config['create'] = $config['factory'];
			unset($config['factory']);
		};

		$known = array('class', 'create', 'arguments', 'setup', 'autowired', 'inject', 'parameters', 'implement', 'run', 'tags');
		if ($error = array_diff(array_keys($config), $known)) {
			throw new Nette\InvalidStateException(sprintf("Unknown or deprecated key '%s' in definition of service.", implode("', '", $error)));
		}

		$arguments = array();
		if (array_key_exists('arguments', $config)) {
			Validators::assertField($config, 'arguments', 'array');
			$arguments = self::filterArguments($config['arguments']);
			$definition->setArguments($arguments);
		}

		if (array_key_exists('class', $config) || array_key_exists('create', $config)) {
			$definition->class = NULL;
			$definition->factory = NULL;
		}

		if (array_key_exists('class', $config)) {
			Validators::assertField($config, 'class', 'string|stdClass|null');
			if ($config['class'] instanceof \stdClass) {
				$definition->setClass($config['class']->value, self::filterArguments($config['class']->attributes));
			} else {
				$definition->setClass($config['class'], $arguments);
			}
		}

		if (array_key_exists('create', $config)) {
			Validators::assertField($config, 'create', 'callable|stdClass|null');
			if ($config['create'] instanceof \stdClass) {
				$definition->setFactory($config['create']->value, self::filterArguments($config['create']->attributes));
			} else {
				$definition->setFactory($config['create'], $arguments);
			}
		}

		if (isset($config['setup'])) {
			if (Config\Helpers::takeParent($config['setup'])) {
				$definition->setup = array();
			}
			Validators::assertField($config, 'setup', 'list');
			foreach ($config['setup'] as $id => $setup) {
				Validators::assert($setup, 'callable|stdClass', "setup item #$id");
				if ($setup instanceof \stdClass) {
					Validators::assert($setup->value, 'callable', "setup item #$id");
					$definition->addSetup($setup->value, self::filterArguments($setup->attributes));
				} else {
					$definition->addSetup($setup);
				}
			}
		}

		if (isset($config['parameters'])) {
			Validators::assertField($config, 'parameters', 'array');
			$definition->setParameters($config['parameters']);
		}

		if (isset($config['implement'])) {
			Validators::assertField($config, 'implement', 'string');
			$definition->setImplement($config['implement']);
			$definition->setAutowired(TRUE);
		}

		if (isset($config['autowired'])) {
			Validators::assertField($config, 'autowired', 'bool');
			$definition->setAutowired($config['autowired']);
		}

		if (isset($config['inject'])) {
			Validators::assertField($config, 'inject', 'bool');
			$definition->setInject($config['inject']);
		}

		if (isset($config['run'])) {
			$config['tags']['run'] = (bool) $config['run'];
		}

		if (isset($config['tags'])) {
			Validators::assertField($config, 'tags', 'array');
			if (Config\Helpers::takeParent($config['tags'])) {
				$definition->tags = array();
			}
			foreach ($config['tags'] as $tag => $attrs) {
				if (is_int($tag) && is_string($attrs)) {
					$definition->addTag($attrs);
				} else {
					$definition->addTag($tag, $attrs);
				}
			}
		}
	}
Exemplo n.º 8
0
 /**
  * Parses single service definition from configuration.
  * @return void
  */
 public static function loadDefinition(ServiceDefinition $definition, $config)
 {
     if ($config === NULL) {
         return;
     } elseif (is_string($config) && interface_exists($config)) {
         $config = ['class' => NULL, 'implement' => $config];
     } elseif ($config instanceof Statement && is_string($config->getEntity()) && interface_exists($config->getEntity())) {
         $config = ['class' => NULL, 'implement' => $config->getEntity(), 'factory' => array_shift($config->arguments)];
     } elseif (!is_array($config) || isset($config[0], $config[1])) {
         $config = ['class' => NULL, 'factory' => $config];
     }
     if (array_key_exists('create', $config)) {
         trigger_error("Key 'create' is deprecated, use 'factory' or 'class' in configuration.", E_USER_DEPRECATED);
         $config['factory'] = $config['create'];
         unset($config['create']);
     }
     $known = ['class', 'factory', 'arguments', 'setup', 'autowired', 'dynamic', 'inject', 'parameters', 'implement', 'run', 'tags'];
     if ($error = array_diff(array_keys($config), $known)) {
         $hints = array_filter(array_map(function ($error) use($known) {
             return Nette\Utils\ObjectMixin::getSuggestion($known, $error);
         }, $error));
         $hint = $hints ? ", did you mean '" . implode("', '", $hints) . "'?" : '.';
         throw new Nette\InvalidStateException(sprintf("Unknown key '%s' in definition of service{$hint}", implode("', '", $error)));
     }
     $config = Helpers::filterArguments($config);
     if (array_key_exists('class', $config) || array_key_exists('factory', $config)) {
         $definition->setClass(NULL);
         $definition->setFactory(NULL);
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|Nette\\DI\\Statement|null');
         if (!$config['class'] instanceof Statement) {
             $definition->setClass($config['class']);
         }
         $definition->setFactory($config['class']);
     }
     if (array_key_exists('factory', $config)) {
         Validators::assertField($config, 'factory', 'callable|Nette\\DI\\Statement|null');
         $definition->setFactory($config['factory']);
     }
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = $config['arguments'];
         if (!Config\Helpers::takeParent($arguments) && !Nette\Utils\Arrays::isList($arguments) && $definition->getFactory()) {
             $arguments += $definition->getFactory()->arguments;
         }
         $definition->setArguments($arguments);
     }
     if (isset($config['setup'])) {
         if (Config\Helpers::takeParent($config['setup'])) {
             $definition->setSetup([]);
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|Nette\\DI\\Statement|array:1', "setup item #{$id}");
             if (is_array($setup)) {
                 $setup = new Statement(key($setup), array_values($setup));
             }
             $definition->addSetup($setup);
         }
     }
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['implement'])) {
         Validators::assertField($config, 'implement', 'string');
         $definition->setImplement($config['implement']);
         $definition->setAutowired(TRUE);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool|string|array');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['dynamic'])) {
         Validators::assertField($config, 'dynamic', 'bool');
         $definition->setDynamic($config['dynamic']);
     }
     if (isset($config['inject'])) {
         Validators::assertField($config, 'inject', 'bool');
         $definition->addTag(Extensions\InjectExtension::TAG_INJECT, $config['inject']);
     }
     if (isset($config['run'])) {
         trigger_error("Option 'run' is deprecated, use 'run' as tag.", E_USER_DEPRECATED);
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Config\Helpers::takeParent($config['tags'])) {
             $definition->setTags([]);
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }