This class has been auto-generated by the Symfony Dependency Injection Component.
Inheritance: extends Symfony\Component\DependencyInjection\Container
Esempio n. 1
0
 public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
 {
     require_once self::$fixturesPath . '/php/services9.php';
     require_once self::$fixturesPath . '/includes/foo.php';
     require_once self::$fixturesPath . '/includes/classes.php';
     $container = new \ProjectServiceContainer();
     $container->set('bar', $bar = new \stdClass());
     $this->assertSame($bar, $container->getFooService()->bar, '->set() overrides an already defined service');
 }
Esempio n. 2
0
 public function testOverrideServiceWhenUsingADumpedContainer()
 {
     require_once self::$fixturesPath . '/php/services9.php';
     require_once self::$fixturesPath . '/includes/foo.php';
     $container = new \ProjectServiceContainer();
     $container->set('bar', $bar = new \stdClass());
     $container->setParameter('foo_bar', 'foo_bar');
     $this->assertEquals($bar, $container->getBarService(), '->set() overrides an already defined service');
     $this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service');
 }
Esempio n. 3
0
 public function load(ObjectManager $manager)
 {
     $this->feeManager = $this->container->get('wealthbot.manager.fee');
     $this->periodManager = $this->container->get('wealthbot_ria.period.manager');
     /** @var User $userMiles */
     $userMiles = $this->getReference('clientN2');
     $this->createBill($userMiles, '2013-04-03 13:12:00', $manager);
     /** @var User $userEverhart */
     $userEverhart = $this->getReference('clientN3');
     $this->createBill($userEverhart, '2013-07-02 16:15:12', $manager);
 }
Esempio n. 4
0
 /**
  * Authenticate selected user.
  * If you want to test another firewall, look name for it
  * in the security.yml file for "context" value.
  *
  * @param $userName
  * @param $roles
  * @param null $firewallName
  * @return \FOS\UserBundle\Model\UserInterface
  */
 protected function authenticateUser($userName, $roles, $firewallName = null)
 {
     $session = $this->client->getContainer()->get('session');
     if (!$firewallName) {
         $firewallName = $this->getFirewallName();
     }
     $user = $this->container->get('fos_user.user_manager')->findUserByUsername($userName);
     $token = new UsernamePasswordToken($user, null, $firewallName, $roles);
     $session->set('_security_' . $firewallName, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $this->client->getCookieJar()->set($cookie);
     return $user;
 }
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
require_once __DIR__ . '/bootstrap.php';
$file = TEMP_DIR . '/container.php';
$containerConfigCache = new ConfigCache($file, $isDebug = TRUE);
if (!$containerConfigCache->isFresh()) {
    $container = new ContainerBuilder();
    $loader = new YamlFileLoader($container, new FileLocator(TEMP_DIR));
    $loader->load(asfile('config.yml', <<<YAML
parameters:
    mailer.transport: sendmail

services:
    mailer:
        class: Project\\Mailer
        arguments: ['%mailer.transport%']
    newsletter_manager:
        class: Project\\NewsletterManager
        arguments: ["@mailer"]
YAML
));
    $dumper = new PhpDumper($container);
    file_put_contents($file, $dumper->dump());
}
require_once $file;
/** @var \Symfony\Component\DependencyInjection\Container $container */
$container = new ProjectServiceContainer();
dump($container->get('newsletter_manager'));
Esempio n. 6
0
        $this->__foo_baz = new stdClass();
    }
    protected function getBarService()
    {
        return $this->__bar;
    }
    protected function getFooBarService()
    {
        return $this->__foo_bar;
    }
    protected function getFoo_BazService()
    {
        return $this->__foo_baz;
    }
}
$sc = new ProjectServiceContainer();
$t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($sc->__bar), '->getService() looks for a getXXXService() method');
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
$sc->setService('bar', $bar = new stdClass());
$t->isnt(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with a getXXXService() method than one defined with setService()');
try {
    $sc->getService('baba');
    $t->fail('->getService() thrown an \\InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->getService() thrown an \\InvalidArgumentException if the service does not exist');
}
try {
    $sc->baba;
    $t->fail('->__get() thrown an \\InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('->__get() thrown an \\InvalidArgumentException if the service does not exist');
Esempio n. 7
0
try
{
  unset($sc->baba);
  $t->fail('->__unset() thrown an LogicException if you try to remove a service');
}
catch (LogicException $e)
{
  $t->pass('->__unset() thrown an LogicException if you try to remove a service');
}

$t->is(spl_object_hash($sc->getService('foo_bar')), spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when looking for a method');
$t->is(spl_object_hash($sc->getService('foo.baz')), spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when looking for a method');

// Iterator
$t->diag('implements Iterator');
$sc = new ProjectServiceContainer();
$sc->setService('foo', $foo = new stdClass());
$services = array();
foreach ($sc as $id => $service)
{
  $services[$id] = spl_object_hash($service);
}
$t->is($services, array(
  'service_container' => spl_object_hash($sc),
  'bar' => spl_object_hash($sc->__bar),
  'foo_bar' => spl_object_hash($sc->__foo_bar),
  'foo.baz' => spl_object_hash($sc->__foo_baz),
  'foo' => spl_object_hash($foo)),
'Container implements the Iterator interface');

// __call()
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\ContainerInterface;
require __DIR__ . '../../../vendor/autoload.php';
$cachedContainer = __DIR__ . '/cached_container.php';
if (!file_exists($cachedContainer)) {
    $container = new ContainerBuilder();
    $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
    $loader->load('services.yml');
    $container->compile();
    $dump = new PhpDumper($container);
    file_put_contents(__DIR__ . '/cached_container.php', $dump->dump());
}
require $cachedContainer;
$container = new \ProjectServiceContainer();
$container->get('stopwatch')->start('Build container');
$build = $container->get('stopwatch')->stop('Build container');
dump($build->getDuration() . "ms");
runApp($container);
function runApp(ContainerInterface $container)
{
    $container->get('stopwatch')->start('Acquia D8 Workshop');
    // Calculate something.
    $factorial = 1;
    for ($x = 100; $x >= 1; $x--) {
        $factorial = $factorial * $x;
    }
    dump($factorial);
    $stop = $container->get('stopwatch')->stop('Acquia D8 Workshop');
    print_r($stop->getMemory() . "\n");
$sc->setService('bar', $bar = new stdClass());
$t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with setService() than one defined with a getXXXService() method');
try {
    $sc->getService('baba');
    $t->fail('->getService() thrown an InvalidArgumentException if the service does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->getService() thrown an InvalidArgumentException if the service does not exist');
}
try {
    $sc->baba;
    $t->fail('->__get() thrown an InvalidArgumentException if the service does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->__get() thrown an InvalidArgumentException if the service does not exist');
}
try {
    unset($sc->baba);
    $t->fail('->__unset() thrown an LogicException if you try to remove a service');
} catch (LogicException $e) {
    $t->pass('->__unset() thrown an LogicException if you try to remove a service');
}
$t->is(spl_object_hash($sc->getService('foo_bar')), spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when looking for a method');
$t->is(spl_object_hash($sc->getService('foo.baz')), spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when looking for a method');
// Iterator
$t->diag('implements Iterator');
$sc = new ProjectServiceContainer();
$sc->setService('foo', $foo = new stdClass());
$services = array();
foreach ($sc as $id => $service) {
    $services[$id] = spl_object_hash($service);
}
$t->is($services, array('service_container' => spl_object_hash($sc), 'bar' => spl_object_hash($sc->__bar), 'foo_bar' => spl_object_hash($sc->__foo_bar), 'foo.baz' => spl_object_hash($sc->__foo_baz), 'foo' => spl_object_hash($foo)), 'sfServiceContainer implements the Iterator interface');
<?php

require_once 'vendor/autoload.php';
use ContainerTools\ContainerGenerator;
use ContainerTools\Configuration;
$configFolders = preg_split('/,/', $argv[1]);
$isDebug = $argv[2] == 'true';
$isTest = $argv[3] == 'true';
$config = Configuration::fromParameters('./container.cache.php', $configFolders, $isDebug, 'xml');
$config->setTestEnvironment($isTest);
$container = new ContainerGenerator($config);
$container->getContainer();
include_once 'container.cache.php';
$container = new ProjectServiceContainer();
file_put_contents('serialized.container', serialize($container->getServiceIds()));