use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
-use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser as YamlParser;
use Symfony\Component\Yaml\Tag\TaggedValue;
use Symfony\Component\Yaml\Yaml;
-use Symfony\Component\ExpressionLanguage\Expression;
/**
* YamlFileLoader loads YAML files service definitions.
// parameters
if (isset($content['parameters'])) {
- if (!is_array($content['parameters'])) {
+ if (!\is_array($content['parameters'])) {
throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $path));
}
// services
$this->anonymousServicesCount = 0;
- $this->anonymousServicesSuffix = ContainerBuilder::hash($path);
- $this->setCurrentDir(dirname($path));
+ $this->anonymousServicesSuffix = '~'.ContainerBuilder::hash($path);
+ $this->setCurrentDir(\dirname($path));
try {
$this->parseDefinitions($content, $path);
} finally {
*/
public function supports($resource, $type = null)
{
- if (!is_string($resource)) {
+ if (!\is_string($resource)) {
return false;
}
- if (null === $type && in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yaml', 'yml'), true)) {
+ if (null === $type && \in_array(pathinfo($resource, PATHINFO_EXTENSION), array('yaml', 'yml'), true)) {
return true;
}
- return in_array($type, array('yaml', 'yml'), true);
+ return \in_array($type, array('yaml', 'yml'), true);
}
/**
return;
}
- if (!is_array($content['imports'])) {
+ if (!\is_array($content['imports'])) {
throw new InvalidArgumentException(sprintf('The "imports" key should contain an array in %s. Check your YAML syntax.', $file));
}
- $defaultDirectory = dirname($file);
+ $defaultDirectory = \dirname($file);
foreach ($content['imports'] as $import) {
- if (!is_array($import)) {
+ if (!\is_array($import)) {
$import = array('resource' => $import);
}
if (!isset($import['resource'])) {
return;
}
- if (!is_array($content['services'])) {
+ if (!\is_array($content['services'])) {
throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
}
$instanceof = $content['services']['_instanceof'];
unset($content['services']['_instanceof']);
- if (!is_array($instanceof)) {
- throw new InvalidArgumentException(sprintf('Service "_instanceof" key must be an array, "%s" given in "%s".', gettype($instanceof), $file));
+ if (!\is_array($instanceof)) {
+ throw new InvalidArgumentException(sprintf('Service "_instanceof" key must be an array, "%s" given in "%s".', \gettype($instanceof), $file));
}
$this->instanceof = array();
$this->isLoadingInstanceof = true;
foreach ($instanceof as $id => $service) {
- if (!$service || !is_array($service)) {
+ if (!$service || !\is_array($service)) {
throw new InvalidArgumentException(sprintf('Type definition "%s" must be a non-empty array within "_instanceof" in %s. Check your YAML syntax.', $id, $file));
}
- if (is_string($service) && 0 === strpos($service, '@')) {
+ if (\is_string($service) && 0 === strpos($service, '@')) {
throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in %s. Check your YAML syntax.', $id, $file));
}
$this->parseDefinition($id, $service, $file, array());
$defaults = $content['services']['_defaults'];
unset($content['services']['_defaults']);
- if (!is_array($defaults)) {
- throw new InvalidArgumentException(sprintf('Service "_defaults" key must be an array, "%s" given in "%s".', gettype($defaults), $file));
+ if (!\is_array($defaults)) {
+ throw new InvalidArgumentException(sprintf('Service "_defaults" key must be an array, "%s" given in "%s".', \gettype($defaults), $file));
}
foreach ($defaults as $key => $default) {
}
if (isset($defaults['tags'])) {
- if (!is_array($tags = $defaults['tags'])) {
+ if (!\is_array($tags = $defaults['tags'])) {
throw new InvalidArgumentException(sprintf('Parameter "tags" in "_defaults" must be an array in %s. Check your YAML syntax.', $file));
}
foreach ($tags as $tag) {
- if (!is_array($tag)) {
+ if (!\is_array($tag)) {
$tag = array('name' => $tag);
}
$name = $tag['name'];
unset($tag['name']);
- if (!is_string($name) || '' === $name) {
+ if (!\is_string($name) || '' === $name) {
throw new InvalidArgumentException(sprintf('The tag name in "_defaults" must be a non-empty string in %s.', $file));
}
}
if (isset($defaults['bind'])) {
- if (!is_array($defaults['bind'])) {
+ if (!\is_array($defaults['bind'])) {
throw new InvalidArgumentException(sprintf('Parameter "bind" in "_defaults" must be an array in %s. Check your YAML syntax.', $file));
}
private function isUsingShortSyntax(array $service)
{
foreach ($service as $key => $value) {
- if (is_string($key) && ('' === $key || '$' !== $key[0])) {
+ if (\is_string($key) && ('' === $key || '$' !== $key[0])) {
return false;
}
}
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
@trigger_error(sprintf('Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0. Rename the "%s" service or define it in XML instead.', $id), E_USER_DEPRECATED);
}
- if (is_string($service) && 0 === strpos($service, '@')) {
+ if (\is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, $alias = new Alias(substr($service, 1)));
if (isset($defaults['public'])) {
$alias->setPublic($defaults['public']);
return;
}
- if (is_array($service) && $this->isUsingShortSyntax($service)) {
+ if (\is_array($service) && $this->isUsingShortSyntax($service)) {
$service = array('arguments' => $service);
}
$service = array();
}
- if (!is_array($service)) {
- throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
+ if (!\is_array($service)) {
+ throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', \gettype($service), $id, $file));
}
$this->checkDefinition($id, $service, $file);
}
foreach ($service as $key => $value) {
- if (!in_array($key, array('alias', 'public'))) {
+ if (!\in_array($key, array('alias', 'public'))) {
@trigger_error(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), E_USER_DEPRECATED);
}
}
}
if (isset($service['calls'])) {
- if (!is_array($service['calls'])) {
+ if (!\is_array($service['calls'])) {
throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
$args = isset($call[1]) ? $this->resolveServices($call[1], $file) : array();
}
- if (!is_array($args)) {
+ if (!\is_array($args)) {
throw new InvalidArgumentException(sprintf('The second parameter for function call "%s" must be an array of its arguments for service "%s" in %s. Check your YAML syntax.', $method, $id, $file));
}
$definition->addMethodCall($method, $args);
}
$tags = isset($service['tags']) ? $service['tags'] : array();
- if (!is_array($tags)) {
+ if (!\is_array($tags)) {
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
}
foreach ($tags as $tag) {
- if (!is_array($tag)) {
+ if (!\is_array($tag)) {
$tag = array('name' => $tag);
}
$name = $tag['name'];
unset($tag['name']);
- if (!is_string($name) || '' === $name) {
+ if (!\is_string($name) || '' === $name) {
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
}
}
if (isset($service['autowiring_types'])) {
- if (is_string($service['autowiring_types'])) {
+ if (\is_string($service['autowiring_types'])) {
$definition->addAutowiringType($service['autowiring_types']);
} else {
- if (!is_array($service['autowiring_types'])) {
+ if (!\is_array($service['autowiring_types'])) {
throw new InvalidArgumentException(sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
foreach ($service['autowiring_types'] as $autowiringType) {
- if (!is_string($autowiringType)) {
+ if (!\is_string($autowiringType)) {
throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
$bindings = isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : array();
if (isset($service['bind'])) {
- if (!is_array($service['bind'])) {
+ if (!\is_array($service['bind'])) {
throw new InvalidArgumentException(sprintf('Parameter "bind" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
}
if (array_key_exists('resource', $service)) {
- if (!is_string($service['resource'])) {
+ if (!\is_string($service['resource'])) {
throw new InvalidArgumentException(sprintf('A "resource" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
$exclude = isset($service['exclude']) ? $service['exclude'] : null;
*/
private function parseCallable($callable, $parameter, $id, $file)
{
- if (is_string($callable)) {
+ if (\is_string($callable)) {
if ('' !== $callable && '@' === $callable[0]) {
throw new InvalidArgumentException(sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $parameter, $id, $callable, substr($callable, 1)));
}
return $callable;
}
- if (is_array($callable)) {
+ if (\is_array($callable)) {
if (isset($callable[0]) && isset($callable[1])) {
return array($this->resolveServices($callable[0], $file), $callable[1]);
}
return $content;
}
- if (!is_array($content)) {
+ if (!\is_array($content)) {
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
}
foreach ($content as $namespace => $data) {
- if (in_array($namespace, array('imports', 'parameters', 'services'))) {
+ if (\in_array($namespace, array('imports', 'parameters', 'services'))) {
continue;
}
if (!$this->container->hasExtension($namespace)) {
$extensionNamespaces = array_filter(array_map(function ($ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
- throw new InvalidArgumentException(sprintf(
- 'There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s',
- $namespace,
- $file,
- $namespace,
- $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'
- ));
+ throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', $namespace, $file, $namespace, $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'));
}
}
if ($value instanceof TaggedValue) {
$argument = $value->getValue();
if ('iterator' === $value->getTag()) {
- if (!is_array($argument)) {
+ if (!\is_array($argument)) {
throw new InvalidArgumentException(sprintf('"!iterator" tag only accepts sequences in "%s".', $file));
}
$argument = $this->resolveServices($argument, $file, $isParameter);
}
}
if ('tagged' === $value->getTag()) {
- if (!is_string($argument) || !$argument) {
+ if (!\is_string($argument) || !$argument) {
throw new InvalidArgumentException(sprintf('"!tagged" tag only accepts non empty string in "%s".', $file));
}
throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag()));
}
- if (is_array($value)) {
+ if (\is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = $this->resolveServices($v, $file, $isParameter);
}
- } elseif (is_string($value) && 0 === strpos($value, '@=')) {
+ } elseif (\is_string($value) && 0 === strpos($value, '@=')) {
if (!class_exists(Expression::class)) {
throw new \LogicException(sprintf('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".'));
}
return new Expression(substr($value, 2));
- } elseif (is_string($value) && 0 === strpos($value, '@')) {
+ } elseif (\is_string($value) && 0 === strpos($value, '@')) {
if (0 === strpos($value, '@@')) {
$value = substr($value, 1);
$invalidBehavior = null;
private function loadFromExtensions(array $content)
{
foreach ($content as $namespace => $values) {
- if (in_array($namespace, array('imports', 'parameters', 'services'))) {
+ if (\in_array($namespace, array('imports', 'parameters', 'services'))) {
continue;
}
- if (!is_array($values) && null !== $values) {
+ if (!\is_array($values) && null !== $values) {
$values = array();
}