Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@14: Chris@14: trait FactoryTrait Chris@14: { Chris@14: /** Chris@14: * Sets a factory. Chris@14: * Chris@14: * @param string|array $factory A PHP callable reference Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: final public function factory($factory) Chris@14: { Chris@17: if (\is_string($factory) && 1 === substr_count($factory, ':')) { Chris@14: $factoryParts = explode(':', $factory); Chris@14: Chris@14: throw new InvalidArgumentException(sprintf('Invalid factory "%s": the `service:method` notation is not available when using PHP-based DI configuration. Use "[ref(\'%s\'), \'%s\']" instead.', $factory, $factoryParts[0], $factoryParts[1])); Chris@14: } Chris@14: Chris@14: $this->definition->setFactory(static::processValue($factory, true)); Chris@14: Chris@14: return $this; Chris@14: } Chris@14: }