public function testProcess() { $wise = new Wise(); $wise->setGlobalParameters(array('global' => array('value' => 999))); $this->setPropertyValue($this->loader, 'wise', $wise); file_put_contents("{$this->dir}/one.php", '<?php return ' . var_export(array('imports' => array(array('resource' => 'two.php')), 'global' => '%global.value%', 'placeholder' => '%imported.list%', 'sub' => array('inline_placeholder' => 'rand: %imported.list.null%%imported.value%'), '%imported.key%' => 'a value'), true) . ';'); file_put_contents("{$this->dir}/two.php", '<?php return ' . var_export(array('imported' => array('key' => 'replaced_key', 'list' => array('null' => null, 'value' => 123), 'value' => $rand = rand())), true) . ';'); $this->assertEquals(array('imports' => array(array('resource' => 'two.php')), 'global' => 999, 'placeholder' => array('null' => null, 'value' => 123), 'sub' => array('inline_placeholder' => 'rand: ' . $rand), 'replaced_key' => 'a value', 'imported' => array('key' => 'replaced_key', 'list' => array('null' => null, 'value' => 123), 'value' => $rand)), $this->loader->load('one.php')); }
/** * {@inheritDoc} */ public function register(Application $app) { $app['wise'] = $app->share(function () use($app) { $wise = new Wise($app['debug']); $wise->setLoader($app['wise.loader']); $wise->setCollector($app['wise.collector']); $wise->setGlobalParameters($app['wise.options']['parameters']); $wise->setProcessor($app['wise.processor']); if (isset($app['wise.cache_dir'])) { $wise->setCacheDir($app['wise.cache_dir']); } return $wise; }); $app['wise.collector'] = $app->share(function () use($app) { return new Resource\ResourceCollector(); }); $app['wise.loader'] = $app->share(function () use($app) { return new DelegatingLoader($app['wise.loader_resolver']); }); $app['wise.loader_resolver'] = $app->share(function () use($app) { return new LoaderResolver($app['wise.loaders']); }); $app['wise.loaders'] = $app->share(function () use($app) { $loaders = array(new Loader\IniFileLoader($app['wise.locator']), new Loader\PhpFileLoader($app['wise.locator'])); if (class_exists('Herrera\\Json\\Json')) { $loaders[] = new Loader\JsonFileLoader($app['wise.locator']); } if (class_exists('DOMDocument')) { $loaders[] = new Loader\XmlFileLoader($app['wise.locator']); } if (class_exists('Symfony\\Component\\Yaml\\Yaml')) { $loaders[] = new Loader\YamlFileLoader($app['wise.locator']); } foreach ($loaders as $loader) { if ($loader instanceof SilexAwareInterface) { $loader->setSilex($app); } } return $loaders; }); $app['wise.locator'] = $app->share(function () use($app) { return new FileLocator($app['wise.path']); }); $app['wise.options'] = new \ArrayObject(array('config' => array('routes' => 'routes', 'services' => 'services'), 'mode' => $app['debug'] ? 'dev' : 'prod', 'type' => 'json', 'parameters' => array())); $app['wise.processor'] = $app->share(function () use($app) { return new Processor\DelegatingProcessor($app['wise.processor_resolver']); }); $app['wise.processor_resolver'] = $app->share(function () use($app) { return new Processor\ProcessorResolver($app['wise.processors']); }); $app['wise.processors'] = array(); }
public function testSetGlobalParametersInvalid() { $this->setExpectedException('Herrera\\Wise\\Exception\\InvalidArgumentException', 'The $parameters argument must be an array or array accessible object.'); $this->wise->setGlobalParameters(true); }