Ejemplo n.º 1
0
 public function getServiceDefinition($id)
 {
     if (empty($this->definitions[$id]) && preg_match('/^([A-Za-z0-9_]+)Table$/', $id, $regs)) {
         $class = ucfirst($id);
         if (class_exists($class, true) && is_subclass_of($class, 'Am_Table')) {
             $def = clone $this->getServiceDefinition('TABLE');
             $def->setClass($class);
             return $def;
         }
     }
     if (empty($this->definitions[$id]) && preg_match('/^([A-Za-z0-9_]+)Record$/', $id, $regs)) {
         $class = ucfirst($regs[1]);
         if (class_exists($class, true) && is_subclass_of($class, 'Am_Record')) {
             $def = clone $this->getServiceDefinition('RECORD');
             $def->setClass($class);
             $def->addArgument(new sfServiceReference($regs[1] . 'Table'));
             return $def;
         }
     }
     return parent::getServiceDefinition($id);
 }
 */
require_once dirname(__FILE__) . '/../lib/lime/lime.php';
require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php';
sfServiceContainerAutoloader::register();
require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php';
$t = new lime_test(4);
$dir = dirname(__FILE__) . '/fixtures/yaml';
// ->dump()
$t->diag('->dump()');
$dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder());
$t->is($dumper->dump(), file_get_contents($dir . '/services1.yml'), '->dump() dumps an empty container as an empty YAML file');
$container = new sfServiceContainerBuilder();
$dumper = new sfServiceContainerDumperYaml($container);
// ->addParameters()
$t->diag('->addParameters()');
$container = (include dirname(__FILE__) . '/fixtures/containers/container8.php');
$dumper = new sfServiceContainerDumperYaml($container);
$t->is($dumper->dump(), file_get_contents($dir . '/services8.yml'), '->dump() dumps parameters');
// ->addService()
$t->diag('->addService()');
$container = (include dirname(__FILE__) . '/fixtures/containers/container9.php');
$dumper = new sfServiceContainerDumperYaml($container);
$t->is($dumper->dump(), str_replace('%path%', dirname(__FILE__) . '/fixtures/includes', file_get_contents($dir . '/services9.yml')), '->dump() dumps services');
$dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new stdClass());
try {
    $dumper->dump();
    $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (RuntimeException $e) {
    $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
Ejemplo n.º 3
0
<?php

require_once __DIR__ . '/../includes/classes.php';
$container = new sfServiceContainerBuilder();
$container->register('foo', 'FooClass')->setConstructor('getInstance')->setArguments(array('foo', new sfServiceReference('foo.baz'), array('%foo%' => 'foo is %foo%'), true, new sfServiceReference('service_container')))->setFile(realpath(__DIR__ . '/../includes/foo.php'))->setShared(false)->addMethodCall('setBar', array('bar'))->addMethodCall('initialize')->setConfigurator('sc_configure');
$container->register('bar', 'FooClass')->setArguments(array('foo', new sfServiceReference('foo.baz'), new sfServiceParameter('foo_bar')))->setShared(true)->setConfigurator(array(new sfServiceReference('foo.baz'), 'configure'));
$container->register('foo.baz', '%baz_class%')->setConstructor('getInstance')->setConfigurator(array('%baz_class%', 'configureStatic1'));
$container->register('foo_bar', 'FooClass');
$container->setParameters(array('baz_class' => 'BazClass', 'foo' => 'bar', 'foo_bar' => new sfServiceReference('foo_bar')));
$container->setAlias('alias_for_foo', 'foo');
return $container;
Ejemplo n.º 4
0
<?php

require_once dirname(__FILE__) . '/../includes/classes.php';
$container = new sfServiceContainerBuilder();
$container->register('foo', 'FooClass')->addArgument(new sfServiceReference('bar'));
return $container;
// ->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');
try {
    $loader->load('foo');
    $t->fail('->load() throws a LogicException if no container is attached to the loader');
} catch (LogicException $e) {
    $t->pass('->load() throws a LogicException if no container is attached to the loader');
}
$loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo')));
$loader->load(array(array(), array('foo' => 'bar')));
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->load() merges current parameters with the loaded ones');
$loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo', 'foo' => 'baz')));
$loader->load(array(array(), array('foo' => 'bar')));
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->load() does not change the already defined parameters');
$loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo')));
$loader->load(array(array(), array('foo' => '%bar%')));
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->load() evaluates the values of the parameters towards already defined ones');
$loader->setServiceContainer($container = new sfServiceContainerBuilder(array('bar' => 'foo')));
$loader->load(array(array(), array('foo' => '%bar%', 'baz' => '%foo%')));
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->load() evaluates the values of the parameters towards already defined ones');
$loader->setServiceContainer($container = new sfServiceContainerBuilder());
$container->register('foo', 'FooClass');
$container->register('bar', 'BarClass');
$loader->load(array(array('baz' => new sfServiceDefinition('BazClass'), 'alias_for_foo' => 'foo'), array()));
$t->is(array_keys($container->getServiceDefinitions()), array('foo', 'bar', 'baz'), '->load() merges definitions already defined ones');
$t->is($container->getAliases(), array('alias_for_foo' => 'foo'), '->load() registers defined aliases');
$loader->setServiceContainer($container = new sfServiceContainerBuilder());
$container->register('foo', 'FooClass');
$loader->load(array(array('foo' => new sfServiceDefinition('BazClass')), array()));
$t->is($container->getServiceDefinition('foo')->getClass(), 'BazClass', '->load() overrides already defined services');
$loader->setServiceContainer($container = new sfServiceContainerBuilder());
$loader->load(array(array(), array('foo' => 'bar')), array(array(), array('bar' => 'foo')));
$t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->load() accepts several resources as argument');
Ejemplo n.º 7
0
<?php

$container = new sfServiceContainerBuilder();
$container->setParameters(array('FOO' => 'bar', 'bar' => 'foo is %foo bar', 'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null')));
return $container;
Ejemplo n.º 8
0
Archivo: unit.php Proyecto: nubee/bee
<?php

require_once dirname(__FILE__) . '/../../lib/core/autoload/nbAutoload.php';
$autoload = nbAutoload::getInstance();
$autoload->register();
$autoload->addDirectory('vendor/', '*.php', true);
$autoload->addDirectory('lib/', '*.php', true);
$autoload->addDirectory('test/lib/', '*.php', true);
// Configures bee variables
$configParser = new nbYamlConfigParser();
nbConfig::set('nb_bee_dir', dirname(__FILE__) . '/../..');
nbConfig::set('nb_config_dir', nbConfig::get('nb_bee_dir') . '/config');
nbConfig::set('nb_test_config_dir', dirname(__FILE__) . '/../config/');
$configParser->parseFile(nbConfig::get('nb_bee_dir') . '/.bee/config.yml', '', true);
$configParser->parseFile(nbConfig::get('nb_config_dir') . '/config.yml', '', true);
$configParser->parseFile(nbConfig::get('nb_test_config_dir') . '/config.yml', '', true);
$serviceContainer = new sfServiceContainerBuilder();
$serviceContainer->register('pluginLoader', 'nbPluginLoader')->addArgument(nbConfig::get('nb_plugins_dir'))->addArgument(new sfServiceReference('commandLoader'))->setShared(true);
$serviceContainer->register('commandLoader', 'nbCommandLoaderWithReset')->setShared(true);
$output = new nbConsoleOutput();
$logger = nbLogger::getInstance();
$logger->setOutput($output);
Ejemplo n.º 9
0
 protected function getDiagramImage($appName)
 {
     $dependencyDiagramImage = sprintf('dependency_diagram_%s_%s.png', $appName, time());
     $dependencyDiagramImageFullPath = dmOs::join(sfConfig::get('sf_web_dir'), 'cache', $dependencyDiagramImage);
     $dotFile = tempnam(sys_get_temp_dir(), 'dm_dependency_');
     if (!$this->context->getFilesystem()->mkdir(dirname($dependencyDiagramImageFullPath))) {
         throw new dmException(sprintf('Can not mkdir %s', $dependencyDiagramImageFullPath));
     }
     $configFiles = array(dmOs::join(sfConfig::get('dm_core_dir'), 'config/dm/services.yml'), dmOs::join(dm::getDir(), sprintf('dm%sPlugin/config/dm/services.yml', dmString::camelize($appName))));
     $projectFile = dmOs::join(sfConfig::get('sf_config_dir'), 'dm/services.yml');
     if (file_exists($projectFile)) {
         $configFiles[] = $projectFile;
     }
     $appFile = dmOs::join(sfConfig::get('sf_apps_dir'), $appName, 'config/dm/services.yml');
     if (file_exists($appFile)) {
         $configFiles[] = $appFile;
     }
     $sc = new sfServiceContainerBuilder();
     $loader = new sfServiceContainerLoaderFileYaml($sc);
     $loader->load($configFiles);
     $sc->setService('dispatcher', $this->context->getEventDispatcher());
     $sc->setService('user', $this->context->getUser());
     $sc->setService('response', $this->context->getResponse());
     $sc->setService('i18n', $this->getI18n());
     $sc->setService('routing', $this->context->getRouting());
     $sc->setService('config_cache', $this->context->getConfigCache());
     $sc->setService('controller', $this->context->getController());
     $sc->setService('logger', $this->context->getLogger());
     $sc->setService('module_manager', $this->context->getModuleManager());
     $sc->setService('context', $this->context);
     $sc->setService('doctrine_manager', Doctrine_Manager::getInstance());
     $dumper = new dmServiceContainerDumperGraphviz($sc);
     $dumper->enableDispatcherLinks($this->withDispatcherLinks);
     file_put_contents($dotFile, $dumper->dump(array('graph' => array('overlap' => 'false', 'splines' => 'true', 'epsilon' => '0.5', 'maxiter' => '30000', 'concentrate' => 'false', 'bgcolor' => 'transparent', 'ratio' => 'fill', 'size' => '25,12'), 'node' => array('fontsize' => 20, 'fontname' => 'Arial', 'shape' => 'Mrecord'), 'edge' => array('fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 1), 'node.instance' => array('fillcolor' => '#ffffff', 'style' => 'filled', 'shape' => 'component'), 'node.definition' => array('fillcolor' => 'transparent'), 'node.missing' => array('fillcolor' => '#ffaaaa', 'style' => 'filled', 'shape' => 'record'))));
     $filesystem = $this->context->getFileSystem();
     //$return = $filesystem->exec(sprintf('dot -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     //$return = $filesystem->exec(sprintf('twopi -Granksep=5 -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     $return = $filesystem->exec(sprintf('neato -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     unlink($dotFile);
     if (!$return) {
         $this->getUser()->logError(sprintf('Diem can not generate the %s dependency diagram. Probably graphviz is not installed on the server.', $appName), false);
         $this->getUser()->logAlert($filesystem->getLastExec('command') . "\n" . $filesystem->getLastExec('output'), false);
     }
     return '/cache/' . $dependencyDiagramImage;
 }
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../lib/lime/lime.php';
require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php';
sfServiceContainerAutoloader::register();
$t = new lime_test(5);
$loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini');
$loader->load(array('parameters.ini'));
$t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'bar'), '->load() takes an array of file names as its first argument');
$loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini');
$loader->load('parameters.ini');
$t->is($container->getParameters(), array('foo' => 'bar', 'bar' => 'bar'), '->load() takes a single file name as its first argument');
$loader = new sfServiceContainerLoaderFileIni($container = new sfServiceContainerBuilder(), dirname(__FILE__) . '/fixtures/ini');
$loader->load(array('parameters.ini', 'parameters1.ini'));
$t->is($container->getParameters(), array('foo' => 'foo', 'bar' => 'foo', 'baz' => 'baz'), '->load() merges parameters from all given files');
try {
    $loader->load('foo.ini');
    $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try {
    @$loader->load('nonvalid.ini');
    $t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
Ejemplo n.º 11
0
require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php';
$t = new lime_test(24);
// cross-check loaders/dumpers
$t->diag('cross-check loaders/dumpers');
$fixtures = array('services1.xml' => 'xml', 'services2.xml' => 'xml', 'services6.xml' => 'xml', 'services8.xml' => 'xml', 'services9.xml' => 'xml', 'services1.yml' => 'yaml', 'services2.yml' => 'yaml', 'services6.yml' => 'yaml');
foreach ($fixtures as $fixture => $type) {
    $loaderClass = 'sfServiceContainerLoaderFile' . ucfirst($type);
    $dumperClass = 'sfServiceContainerDumper' . ucfirst($type);
    $container1 = new sfServiceContainerBuilder();
    $loader1 = new $loaderClass($container1);
    $loader1->load(dirname(__FILE__) . '/fixtures/' . $type . '/' . $fixture);
    $container1->setParameter('path', dirname(__FILE__) . '/fixtures/includes');
    $dumper = new $dumperClass($container1);
    $tmp = tempnam('sf_service_container', 'sf');
    file_put_contents($tmp, $dumper->dump());
    $container2 = new sfServiceContainerBuilder();
    $loader2 = new $loaderClass($container2);
    $loader2->load($tmp);
    $container2->setParameter('path', dirname(__FILE__) . '/fixtures/includes');
    unlink($tmp);
    $t->is(serialize($container1), serialize($container2), 'loading a dump from a previously loaded container returns the same container');
    $t->is($container1->getParameters(), $container2->getParameters(), '->getParameters() returns the same value for both containers');
    $services1 = array();
    foreach ($container1 as $id => $service) {
        $services1[$id] = serialize($service);
    }
    $services2 = array();
    foreach ($container2 as $id => $service) {
        $services2[$id] = serialize($service);
    }
    unset($services1['service_container'], $services2['service_container']);