/** * resolves the instance arguments * * @param array $parameters * @return array */ private function getInstanceArgs(array $parameters) : array { $args = []; foreach ($parameters as $argument) { if ($argument[0] === "@") { $service = substr($argument, 1); if (strpos($service, ":") !== false) { list($service, $method) = explode(":", $service); $serviceInstance = $this->get($service); $arg = $serviceInstance->{$method}(); } else { $arg = $this->get($service); } } elseif ($argument[0] === "%") { $arg = $this->app->parameter(substr($argument, 1)); } else { $arg = $argument; } $args[] = $arg; } return $args; }
public function testCache() { $app = $this->app; $app->setup(function () use($app) { $app->parameter("testparam", "value"); $app->addService("app.service", "AppService", ["@kernel.container", "%testparam", "teststring"]); }); $storage = new \FabysCore\Component\Cache\Storage\FileStorage(__DIR__ . "/tests_tmp"); $app = new Application($storage); $app->setup(function () use($app) { $app->parameter("testparam", "value"); $app->parameter("testparam2", "v"); $app->addService("app.service", "AppService", ["@kernel.container", "%testparam", "teststring"]); $app->addService("app.service2", "AppService", ["@kernel.container", "%testparam", "teststring"]); }); $container = $app->getContainer(); $this->assertFalse($container->has("app.service2")); $this->assertTrue($container->has("app.service")); $this->assertEmpty($app->parameter("testparam2")); $this->assertEquals("value", $app->parameter("testparam")); }