本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setSynthetic方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setSynthetic方法的具体用法?PHP Definition::setSynthetic怎么用?PHP Definition::setSynthetic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setSynthetic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreatorReturnsNullIfSyntheticServiceIsRequested
/**
* Ensures that the creator returns null if a synthetic service is requested.
*/
public function testCreatorReturnsNullIfSyntheticServiceIsRequested()
{
$definition = new Definition();
$definition->setSynthetic(true);
$this->container->setDefinition('my.service', $definition);
$this->assertNull($this->creator->create('my.service'));
}
示例2: ifDefinitionIsSyntheticSkipsValidation
/**
* @test
*/
public function ifDefinitionIsSyntheticSkipsValidation()
{
$definition = new Definition();
$definition->setSynthetic(true);
$argumentsValidator = $this->createMockArgumentsValidator();
$argumentsValidator->expects($this->never())->method('validate');
$validator = new DefinitionArgumentsValidator($this->createMockConstructorResolver(), $argumentsValidator);
$validator->validate($definition);
}
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:12,代码来源:DefinitionArgumentsValidatorTest.php
示例3: testContainerOverridedAndNewMethods
/**
* test every new and overrided method provided by BackBee\DependencyInjection\Container.
*
* @covers ::get
* @covers ::getContainerValues
* @covers ::getContainerParameters
* @covers ::getContainerServices
* @covers ::isLoaded
*/
public function testContainerOverridedAndNewMethods()
{
// build container to apply every tests on
$container = new Container();
// setting random parameters
$container->setParameter('random_parameter', 'this is a test');
// creating a definition without any tag (definition of service with id `date_without_tag`)
$definition = new Definition('DateTime');
$container->setDefinition('date_without_tag', $definition);
// creating a definition with one tag, `test` (definition of service with id `date_with_tag`)
$definition = new Definition('BackBee\\DependencyInjection\\Tests\\ContainerTest_Resources\\DateTime');
$definition->addTag('test');
$container->setDefinition('date_with_tag', $definition);
// creating a definition for a synthetic service (definition of service with id `synthetic_service`)
$definition = new Definition();
$definition->setSynthetic(true);
$container->setDefinition('synthetic_service', $definition);
// setting into container a service as listener with id `listener`
$container->set('listener', new TestListener());
// creating a new event dispatcher and prepare it for testing the dispatch of event on get of tagged service
// from the container
$event_dispatcher = new Dispatcher();
$event_dispatcher->setContainer($container);
$event_dispatcher->addListener('service.tagged.test', array('@listener', 'onGetServiceTaggedTestEvent'));
$container->set('event.dispatcher', $event_dispatcher);
// basic test for the listener
$this->assertEquals('bar', $container->get('listener')->getFoo());
// tests of Container::isLoaded() method
$this->assertFalse($container->isLoaded('date_without_tag'));
$container->get('date_without_tag');
$this->assertTrue($container->isLoaded('date_without_tag'));
// checks that getting a service without the `test` tag won't change listener's foo value
$this->assertEquals('bar', $container->get('listener')->getFoo());
// tests to get a service with tag to check if the value of foo from listener has changed
// and if the timestamp of the service `date_with_tag` has changed correctly
$container->get('date_with_tag');
$this->assertEquals('foo', $container->get('listener')->getFoo());
$this->assertEquals(self::NEW_DATE_WITH_TAG_VALUE, $container->get('date_with_tag')->getTimestamp());
// tests that if we get a synthetic service which we didn't define it yet Container::get() will return null
$this->assertEquals(null, $container->get('synthetic_service'));
// test for Container::getContainerValues()
$paramter_key_string = '%random_parameter%';
$this->assertEquals('this is a test', $container->getContainerValues($paramter_key_string));
$service_string_id = '@listener';
$this->assertEquals($container->get('listener')->getFoo(), $container->getContainerValues($service_string_id)->getFoo());
// Test that there is no events to dispatch if the tag name is `dumpable`
$container->set('listener', new TestListener());
$event_dispatcher->addListener('service.tagged.dumpable', array('@listener', 'onGetServiceTaggedTestEvent'));
$definition = new Definition('DateTime');
$definition->addTag('dumpable', array('dispatch_event' => false));
$container->setDefinition('dumpable_date', $definition);
$container->get('dumpable_date');
$this->assertEquals('bar', $container->get('listener')->getFoo());
}
示例4: testSyntheticDefinitionCanHaveNoClass
public function testSyntheticDefinitionCanHaveNoClass()
{
$definition = new Definition();
$definition->setSynthetic(true);
$containerBuilder = new ContainerBuilder();
$validator = new ServiceDefinitionValidator($containerBuilder, $this->createMockDefinitionArgumentsValidator(), $this->createMockMethodCallsValidator());
try {
$validator->validate($definition);
} catch (DefinitionHasNoClassException $e) {
$this->fail('Synthetic definitions should be allowed to have no class');
}
}
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:12,代码来源:ServiceDefinitionValidatorTest.php
示例5: getAllParameters
private function getAllParameters()
{
$service = new Definition();
$service->setClass('stdClass');
$service->setAbstract(true);
$service->setFactoryClass('stdClass');
$service->setFactoryMethod('get');
$service->setFactoryService('service.fact');
$service->setFile('/file.php');
$service->setLazy(true);
$service->addMethodCall('methodCall1');
$service->addMethodCall('methodCall2', array('arg1', 'arg2'));
$service->addMethodCall('methodCall3', array(new Reference('arg.one')));
$service->setProperty('prop1', 'val1');
$service->setProperty('prop2', new Reference('prop.one'));
$service->setPublic(false);
$service->setScope('request');
$service->setSynchronized(true);
$service->setSynthetic(true);
return new ServiceElement('service.two', $service);
}
示例6: parseDefinition
/**
* Parses a definition.
*
* @param string $id
* @param array $service
* @param string $file
*
* @throws InvalidArgumentException When tags are invalid
*/
private function parseDefinition($id, $service, $file)
{
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
}
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));
}
static::checkDefinition($id, $service, $file);
if (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (bool) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
foreach ($service as $key => $value) {
if (!in_array($key, array('alias', 'public'))) {
@trigger_error(sprintf('The configuration key "%s" is unsupported for alias definition "%s" in "%s". Allowed configuration keys 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);
}
}
return;
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
} else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['shared'])) {
$definition->setShared($service['shared']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['lazy'])) {
$definition->setLazy($service['lazy']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (array_key_exists('deprecated', $service)) {
$definition->setDeprecated(true, $service['deprecated']);
}
if (isset($service['factory'])) {
$definition->setFactory($this->parseCallable($service['factory'], 'factory', $id, $file));
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['properties'])) {
$definition->setProperties($this->resolveServices($service['properties']));
}
if (isset($service['configurator'])) {
$definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
}
if (isset($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));
}
foreach ($service['calls'] as $call) {
if (isset($call['method'])) {
$method = $call['method'];
$args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
} else {
$method = $call[0];
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
}
$definition->addMethodCall($method, $args);
}
}
if (isset($service['tags'])) {
if (!is_array($service['tags'])) {
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
foreach ($service['tags'] as $tag) {
if (!is_array($tag)) {
throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
if (!isset($tag['name'])) {
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
}
if (!is_string($tag['name']) || '' === $tag['name']) {
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
}
$name = $tag['name'];
//.........这里部分代码省略.........
示例7: getApplicationContainer
/**
* @param array $loadedApplications
*
* @return ApplicationContainerBuilder
*/
public function getApplicationContainer(&$loadedApplications = array())
{
if (!$this->containerBuilderCompiled) {
if (count($loadedApplications) == 0) {
$parent = true;
} else {
$parent = false;
}
foreach ($this->parentApplications as $app) {
if (in_array(get_class($app), $loadedApplications)) {
continue;
}
$loadedApplications[] = get_class($app);
$this->containerBuilder->merge($app->getApplicationContainer($loadedApplications));
}
$this->configure($this->containerBuilder);
foreach ($this->getConfigurationFiles() as $file) {
$this->containerBuilder->import($file);
}
if ($parent) {
//setting syntetic services
$definition = new Definition();
$definition->setSynthetic(true);
//inserting container as service
$this->containerBuilder->setDefinition('container', $definition);
$this->containerBuilder->set('container', $this->containerBuilder);
//inserting application as service
$this->containerBuilder->setDefinition('application', clone $definition);
$this->containerBuilder->set('application', $this);
$this->containerBuilder->compile();
}
}
return $this->containerBuilder;
}
示例8: createSyntheticDefinition
private function createSyntheticDefinition()
{
$syntheticDefinition = new Definition();
$syntheticDefinition->setSynthetic(true);
return $syntheticDefinition;
}
示例9: parseDefinition
/**
* Parses a definition.
*
* @param string $id
* @param array $service
* @param string $file
*
* @throws InvalidArgumentException When tags are invalid
*/
private function parseDefinition($id, $service, $file)
{
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
}
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 (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (bool) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
return;
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
} else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['synchronized'])) {
$definition->setSynchronized($service['synchronized']);
}
if (isset($service['lazy'])) {
$definition->setLazy($service['lazy']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (isset($service['factory'])) {
if (is_string($service['factory'])) {
if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
$parts = explode(':', $service['factory']);
$definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
} else {
$definition->setFactory($service['factory']);
}
} else {
$definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
}
}
if (isset($service['factory_class'])) {
$definition->setFactoryClass($service['factory_class']);
}
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
$definition->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['properties'])) {
$definition->setProperties($this->resolveServices($service['properties']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition->setConfigurator($service['configurator']);
} else {
$definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
}
}
if (isset($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));
}
foreach ($service['calls'] as $call) {
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
$definition->addMethodCall($call[0], $args);
}
}
if (isset($service['tags'])) {
if (!is_array($service['tags'])) {
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
foreach ($service['tags'] as $tag) {
//.........这里部分代码省略.........
示例10: initializeContainer
/**
* Initializes service container
* @see http://symfony.com/doc/current/components/dependency_injection/index.html
*/
protected function initializeContainer()
{
$container = new ContainerBuilder();
$clientDefinition = new Definition();
$clientDefinition->setSynthetic(true);
$container->setDefinition('client', $clientDefinition);
$container->set('client', $this);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Resources/config'));
$loader->load('services.yml');
$loader->load('api_services.yml');
$loader->load('mapper_services.yml');
$this->container = $container;
}
示例11: process
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process(ContainerBuilder $container)
{
$twigDefinition = new Definition('Twig_Environment');
$twigDefinition->setSynthetic(true);
$container->setDefinition('twig', $twigDefinition);
}
示例12: testHasSyntheticService
public function testHasSyntheticService()
{
$this->given($definition = new DependencyInjection\Definition('stdClass'), $definition->setSynthetic(false), $syntheticDef = new DependencyInjection\Definition('stdClass'), $syntheticDef->setSynthetic(true), $container = new DependencyInjection\ContainerBuilder(), $container->addDefinitions(['service' => $definition, 'serviceSynthetic' => $syntheticDef]))->if($asserter = $this->newTestedInstance())->and($asserter->setWith($container))->then->object($asserter->hasSyntheticService('serviceSynthetic'))->isIdenticalTo($asserter)->exception(function () use($asserter) {
$asserter->hasSyntheticService('service');
})->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage('Service "service" is not synthetic');
}
示例13: buildDefinition
/**
* Build a definition from the definition's array provided as current method parameter.
*
* @param array $array the raw definition's array
*
* @return Symfony\Component\DependencyInjection\Definition the definition object
*/
private function buildDefinition(array $array)
{
$definition = null;
if (isset($array['parent'])) {
$definition = new DefinitionDecorator($array['parent']);
} else {
$definition = new Definition();
}
if (isset($array['synthetic'])) {
$definition->setSynthetic($array['synthetic']);
}
$this->setDefinitionClass($definition, $array);
$this->setDefinitionArguments($definition, $array);
$this->setDefinitionFactory($definition, $array);
$this->setDefinitionTags($definition, $array);
$this->setDefinitionMethodCalls($definition, $array);
$this->setDefinitionProperties($definition, $array);
$this->setDefinitionConfigurator($definition, $array);
return $definition;
}
示例14: parseDefinition
protected function parseDefinition($id, $service, $file)
{
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
} else {
if (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (bool) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
return;
}
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
} else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
$definition->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition->setConfigurator($service['configurator']);
} else {
$definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
}
}
if (isset($service['calls'])) {
foreach ($service['calls'] as $call) {
$definition->addMethodCall($call[0], $this->resolveServices($call[1]));
}
}
if (isset($service['tags'])) {
foreach ($service['tags'] as $tag) {
$name = $tag['name'];
unset($tag['name']);
$definition->addTag($name, $tag);
}
}
$this->container->setDefinition($id, $definition);
}
示例15: testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer
public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer()
{
$container = new ContainerBuilder();
$def = new Definition('stdClass');
$def->setSynthetic(true);
$container->setDefinition('a', $def);
$container->compile();
$container->set('a', $a = new \stdClass());
$this->assertEquals($a, $container->get('a'));
}