// ->resolveValue()
$t->diag('->resolveValue()');
$builder = new sfServiceContainerBuilder();
$t->is($builder->resolveValue('foo'), 'foo', '->resolveValue() returns its argument unmodified if no placeholders are found');
$builder->setParameter('foo', 'bar');
$t->is($builder->resolveValue('I\'m a %foo%'), 'I\'m a bar', '->resolveValue() replaces placeholders by their values');
$builder->setParameter('foo', true);
$t->ok($builder->resolveValue('%foo%') === true, '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
$builder->setParameter('foo', 'bar');
$t->is($builder->resolveValue(array('%foo%' => '%foo%')), array('bar' => 'bar'), '->resolveValue() replaces placeholders in keys and values of arrays');
$t->is($builder->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), array('bar' => array('bar' => array('bar' => 'bar'))), '->resolveValue() replaces placeholders in nested arrays');
$t->is($builder->resolveValue('I\'m a %%foo%%'), 'I\'m a %foo%', '->resolveValue() supports % escaping by doubling it');
$t->is($builder->resolveValue('I\'m a %foo% %%foo %foo%'), 'I\'m a bar %foo bar', '->resolveValue() supports % escaping by doubling it');
try {
    $builder->resolveValue('%foobar%');
    $t->fail('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter');
} catch (InvalidArgumentException $e) {
    $t->pass('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter');
}
try {
    $builder->resolveValue('foo %foobar% bar');
    $t->fail('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter');
} catch (InvalidArgumentException $e) {
    $t->pass('->resolveValue() throws a InvalidArgumentException if a placeholder references a non-existant parameter');
}
// ->resolveServices()
$t->diag('->resolveServices()');
$builder = new sfServiceContainerBuilder();
$builder->register('foo', 'FooClass');
$t->is($builder->resolveServices(new sfServiceReference('foo')), $builder->getService('foo'), '->resolveServices() resolves service references to service instances');
$t->is($builder->resolveServices(array('foo' => array('foo', new sfServiceReference('foo')))), array('foo' => array('foo', $builder->getService('foo'))), '->resolveServices() resolves service references to service instances in nested arrays');
Esempio n. 2
0
 public function getService($id)
 {
     if (empty($this->services[$id])) {
         switch ($id) {
             case 'time':
                 return time();
             case 'sqlDate':
                 return date('Y-m-d', $this->time);
             case 'sqlDateTime':
                 return date('Y-m-d H:i:s', $this->time);
             case 'dateTime':
                 $tz = new DateTimeZone(date_default_timezone_get());
                 $d = new DateTime('@' . $this->time, $tz);
                 $d->setTimezone($tz);
                 return $d;
             case 'plugins':
                 $plugins = new ArrayObject();
                 foreach (array($this->modules, $this->plugins_payment, $this->plugins_protect, $this->plugins_misc, $this->plugins_storage) as $pl) {
                     $plugins[$pl->getId()] = $pl;
                 }
                 $this->services[$id] = $plugins;
                 return $this->services[$id];
             default:
         }
     }
     return parent::getService($id);
 }
Esempio n. 3
0
 public function getService($id)
 {
     if (empty($this->services[$id])) {
         switch ($id) {
             case 'time':
                 return time();
             case 'sqlDate':
                 return date('Y-m-d', $this->time);
             case 'sqlDateTime':
                 return date('Y-m-d H:i:s', $this->time);
             case 'dateTime':
                 $tz = new DateTimeZone(date_default_timezone_get());
                 $d = new DateTime('@' . $this->time, $tz);
                 $d->setTimezone($tz);
                 return $d;
             default:
         }
     }
     return parent::getService($id);
 }