本文整理汇总了PHP中Pimple\Container类的典型用法代码示例。如果您正苦于以下问题:PHP Container类的具体用法?PHP Container怎么用?PHP Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Container $app)
{
$app['ramlToSilex.initializer'] = $app->protect(function () use($app) {
if (!is_readable($ramlFile = $app['ramlToSilex.raml_file'])) {
throw new \RuntimeException("API config file is not readable");
}
$configFile = json_decode(file_get_contents($app['ramlToSilex.config_file']));
$app['ramlToSilex.apiDefinition'] = (new Parser())->parse($ramlFile, false);
$app['ramlToSilex.routes'] = $app['ramlToSilex.apiDefinition']->getResourcesAsUri()->getRoutes();
if (property_exists($configFile, 'routeAccess')) {
$app['ramlToSilex.routeAccess'] = $configFile->routeAccess;
}
if (property_exists($configFile, 'controllers')) {
$app['ramlToSilex.customControllerMapping'] = $configFile->controllers;
}
$app['ramlToSilex.restController'] = $app->factory(function () use($app) {
return new RestController($app);
});
$app['ramlToSilex.routeBuilder'] = $app->factory(function () {
return new RouteBuilder();
});
});
$app['ramlToSilex.builder'] = function () use($app) {
$app['ramlToSilex.initializer']();
$controllers = $app['ramlToSilex.routeBuilder']->build($app, 'ramlToSilex.restController');
$app['controllers']->mount('', $controllers);
};
}
示例2: register
public function register(Container $app)
{
$app['menu_manager'] = function ($app) {
return new MenuManager($app, $app['menu']);
};
$app['menu_manager.security'] = function ($app) {
return new MenuSecurityService($app);
};
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($filesystem, $app) {
$filesystem->addPath(__DIR__ . '/../Resource/views', 'MenuManager');
return $filesystem;
});
$app['twig'] = $app->extend('twig', function ($twig, $app) {
$twig->addFunction(new \Twig_SimpleFunction('menu', function ($which = 'main', Item $item = null, $paramList = [], $activeOnly = false) use($app) {
return $app['menu_manager']->render($which, $item, $paramList, $activeOnly);
}));
$twig->addFunction(new \Twig_SimpleFunction('breadcrumb', function ($paramList = []) use($app) {
return $app['menu_manager']->renderBreadcrumb($paramList);
}));
return $twig;
});
// Current route name
$app->before(function (Request $request) use($app) {
$app['menu_manager']->setCurrentRoute($request->get('_route'));
});
}
示例3: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Container $pimple A container instance
*/
public function register(Container $pimple)
{
$config = $this->configuration;
$pimple['translator'] = function ($c) use($config) {
$translator = new Translator($config);
return $translator;
};
/*
* Translate függvény és a getLocale függvény biztosítása a twighez
*/
$pimple->extend('twig', function ($twig, $c) {
/** @var Twig $mytwig */
$mytwig = $twig;
/** @var Translator $translator */
$translator = $c["translator"];
// Translate függvény biztosítása
$translate = new \Twig_SimpleFunction('translate', function ($message, $params = [], $domain = null, $locale = null) use($translator) {
return $translator->trans($message, $params, $domain, $locale);
});
$mytwig->getTwigEnvironment()->addFunction($translate);
// Aktuális locale biztosítása
$get_locale = new \Twig_SimpleFunction('get_locale', function () use($translator) {
return $translator->getLocale();
});
$mytwig->getTwigEnvironment()->addFunction($get_locale);
// Aktuális locale-ok biztosítása
$get_locales = new \Twig_SimpleFunction('get_locales', function () use($translator) {
return $translator->getFallbackLocales();
});
$mytwig->getTwigEnvironment()->addFunction($get_locales);
return $mytwig;
});
}
示例4: it_resolve_commands
public function it_resolve_commands(Container $container, $command1, $command2)
{
$container->keys()->willReturn(['test1.command', 'test2.command']);
$container->offsetGet('test1.command')->willReturn($command1);
$container->offsetGet('test2.command')->willReturn($command2);
$this->commands()->shouldReturn([$command1, $command2]);
}
示例5: register
public function register(Container $pimple)
{
$pimple['Auth'] = function ($pimple) {
$auth = new Auth($pimple->config('accessKey'), $pimple->config('secretKey'));
return $auth;
};
}
示例6: register
/**
* Register providers
*
* @access public
* @param \Pimple\Container $container
* @return \Pimple\Container
*/
public function register(Container $container)
{
$container['commentEventJob'] = $container->factory(function ($c) {
return new CommentEventJob($c);
});
$container['subtaskEventJob'] = $container->factory(function ($c) {
return new SubtaskEventJob($c);
});
$container['taskEventJob'] = $container->factory(function ($c) {
return new TaskEventJob($c);
});
$container['taskFileEventJob'] = $container->factory(function ($c) {
return new TaskFileEventJob($c);
});
$container['taskLinkEventJob'] = $container->factory(function ($c) {
return new TaskLinkEventJob($c);
});
$container['projectFileEventJob'] = $container->factory(function ($c) {
return new ProjectFileEventJob($c);
});
$container['notificationJob'] = $container->factory(function ($c) {
return new NotificationJob($c);
});
$container['projectMetricJob'] = $container->factory(function ($c) {
return new ProjectMetricJob($c);
});
return $container;
}
示例7: register
public function register(Container $app)
{
$app['restapi.storage'] = function () use($app) {
return new HashedStorage($app['restapi']['storage_path']);
};
$app['restapi.service'] = function () use($app) {
$api = new RestApi($app['db'], $app['restapi']['schema_cache']);
$api->setStorage($app['restapi.storage']);
$api->setDebug($app['debug']);
return $api;
};
if (isset($app['restapi']['auth'])) {
$app['restapi.auth'] = function () use($app) {
$auth = new AuthService($app['restapi']['auth']['users']);
$auth->setTokenOptions($app['restapi']['auth']['token']);
$auth->setCookieOptions($app['restapi']['auth']['cookie']);
return $auth;
};
$app['restapi.listener.auth_checker'] = $app->protect(function (Request $request) use($app) {
if (!($user = $app['restapi.auth']->getAuthenticatedUserFromRequest($request))) {
return new Response(null, 401, ['Content-Type' => 'application/json']);
}
$app['restapi.service']->setUser($user);
});
}
if (isset($app['restapi']['cors'])) {
$app['restapi.middleware.cors'] = function () use($app) {
return new CorsMiddleware($app['restapi']['cors']);
};
}
}
示例8: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['paginator.default_options'] = ['page_name' => 'page', 'page_range' => 5, 'sort_field_name' => 'sort', 'sort_direction_name' => 'direction', 'filter_field_name' => 'filterField', 'filter_value_name' => 'filterValue', 'distinct' => true, 'template' => ['pagination' => 'sliding.html.twig', 'sortable' => 'sortable_link.html.twig', 'filtration' => 'filtration.html.twig']];
$app['paginator.helper.processor'] = function ($app) {
return new Processor($app['url_generator'], $app['translator']);
};
$app['paginator'] = function ($app) {
$reflClass = new \ReflectionClass('Knp\\Bundle\\PaginatorBundle\\KnpPaginatorBundle');
$path = sprintf('%s/Resources/views/Pagination', dirname($reflClass->getFileName()));
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($path));
$paginator = new Paginator($app['dispatcher']);
$paginator->setDefaultPaginatorOptions(['pageParameterName' => $app['paginator.default_options']['page_name'], 'sortFieldParameterName' => $app['paginator.default_options']['sort_field_name'], 'sortDirectionParameterName' => $app['paginator.default_options']['sort_direction_name'], 'filterFieldParameterName' => $app['paginator.default_options']['filter_field_name'], 'filterValueParameterName' => $app['paginator.default_options']['filter_value_name'], 'distinct' => $app['paginator.default_options']['distinct']]);
return $paginator;
};
$app['paginator.subscriber.paginate'] = function () {
return new PaginationSubscriber();
};
$app['paginator.subscriber.sortable'] = function () {
return new SortableSubscriber();
};
$app['paginator.subscriber.filtration'] = function () {
return new FiltrationSubscriber();
};
$app['paginator.subscriber.sliding_pagination'] = function ($app) {
$templateOptions = $app['paginator.default_options']['template'];
$options = ['defaultPaginationTemplate' => $templateOptions['pagination'], 'defaultSortableTemplate' => $templateOptions['sortable'], 'defaultFiltrationTemplate' => $templateOptions['filtration'], 'defaultPageRange' => $app['paginator.default_options']['page_range']];
return new SlidingPaginationSubscriber($options);
};
$app->extend('twig', function (\Twig_Environment $twig, $app) {
$twig->addExtension(new PaginationExtension($app['paginator.helper.processor']));
return $twig;
});
}
示例9: testDump
public function testDump()
{
$container = new Container();
$container['debug'] = false;
$container['charset'] = 'utf-8';
$logger = $this->getLogger();
$container['logger'] = $logger;
$container->register(new TwigServiceProvider());
$twigPath = $this->getTwigPath();
$container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) use($twigPath) {
$twigLoaderFilesystem->addPath($twigPath, 'SaxulumAsseticTwig');
return $twigLoaderFilesystem;
});
$container->register(new AsseticTwigProvider(), array('assetic.asset.root' => $this->getFixturesPath(), 'assetic.asset.asset_root' => $this->getAssetPath()));
/** @var Dumper $dumper */
$dumper = $container['assetic.asset.dumper'];
$dumper->dump();
if (count($logger->entries)) {
var_dump($logger->entries);
}
$this->assertCount(0, $logger->entries);
$this->fileComparsion('css/test-copyfile.css');
$this->fileComparsion('image/test.png');
$this->fileComparsion('css/test-less.css');
$this->fileComparsion('css/test-scss.css');
$this->fileComparsion('css/test-cssmin.css');
$this->fileComparsion('css/test-csscompress.css');
$this->fileComparsion('js/test.js');
}
示例10: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Container $container The Pimple DI container.
* @return void
*/
public function register(Container $container)
{
/**
* @param Container $container The Pimple DI Container.
* @return ConfigInterface
*/
$container['admin/config'] = function (Container $container) {
$appConfig = $container['config'];
return new AdminConfig($appConfig['admin']);
};
$container->extend('admin/config', function (ConfigInterface $adminConfig, Container $container) {
$adminConfig['elfinder'] = new Config($adminConfig['elfinder']);
return $adminConfig;
});
/**
* @param Container $container The Pimple DI Container.
* @return ConfigInterface
*/
$container['elfinder/config'] = function (Container $container) {
return $container['admin/config']['elfinder'];
};
$this->registerAuthenticator($container);
$this->registerAuthorizer($container);
$this->registerUtilities($container);
// Register Access-Control-List (acl)
$container->register(new AclServiceProvider());
}
示例11: register
public function register(Container $container)
{
$cid = $this->cid;
$container[$cid] = $container->factory(function () use($cid, $container) {
$get = function ($key, $default = null) use($container, $cid) {
$key = $cid . '.' . $key;
return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
};
$adapterName = $get('adapter');
switch ($adapterName) {
case 'redis':
$adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]);
break;
case 'file':
$adapter = new AdapterFile($get('dir'));
break;
default:
$adapter = new AdapternotCache();
break;
}
foreach ($get('options', []) as $k => $v) {
$adapter->setOption($k, $v);
}
return new Cache($adapter);
});
}
示例12: test
public function test()
{
$container = new Container();
$container->register(new HttpClientProvider());
$this->assertInstanceOf('Metfan\\RabbitSetup\\Factory\\CurlClientFactory', $container['curl_client_factory']);
$this->assertInstanceOf('Metfan\\RabbitSetup\\Http\\ClientPool', $container['http_client_pool']);
}
示例13: register
public function register(Container $container)
{
$container['simpleform.config.path'] = '';
$container['simpleform.config.cache_path'] = '';
$container['simpleform.config.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Config';
$container['simpleform.forms.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Forms';
$container['simpleform.custom_fields'] = [];
$container['form.types'] = function () {
return [new StringType()];
};
$container['simpleform.config'] = function (Container $container) {
// $coreFieldsNamespace = 'PhpGo\\SimpleAdminBundle\\Form\\Field\\';
$coreFields = ['PhpGo\\SimpleAdminBundle\\Form\\Field\\StringField'];
Forms::registerFields($coreFields);
Forms::registerFields($container['simpleform.custom_fields']);
$container->extend('form.types', function ($types, $container) {
/** @var FieldAbstract $field */
foreach ($container['simpleform.custom_fields'] as $field) {
if ($type = $field::getType()) {
$types[] = $type;
}
}
return $types;
});
$config = $container['simpleform.config.class']::createFromYaml($container['simpleform.config.path']);
return $config;
};
$container['forms'] = function ($container) {
/** @var Forms $forms */
$forms = new $container['simpleform.forms.class']($container['simpleform.config'], $container['form.factory']);
return $forms;
};
}
示例14: register
public function register(Container $app)
{
$app['router.options'] = [];
$app['router.loader_resolver'] = function () {
$fileLocator = new FileLocator();
$loaderResolver = new LoaderResolver([new XmlFileLoader($fileLocator), new PhpFileLoader($fileLocator), new ClosureLoader()]);
if (class_exists('Symfony\\Component\\Yaml\\Parser')) {
$loaderResolver->addLoader(new YamlFileLoader($fileLocator));
}
return $loaderResolver;
};
$app['router'] = function (Application $app) {
$router = new Router(new ClosureLoader(), function () use($app) {
if (isset($app['router.resource'])) {
$userLoader = new DelegatingLoader($app['router.loader_resolver']);
$userRoutes = $userLoader->load($app['router.resource']);
$app['routes']->addCollection($userRoutes);
}
$app->flush();
return $app['routes'];
}, $app['router.options'] + ['debug' => isset($app['debug']) ? $app['debug'] : false, 'matcher_base_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher', 'matcher_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher'], $app['request_context'], $app['logger']);
return $router;
};
$app['request_matcher'] = function (Application $app) {
return $app['router'];
};
$app['url_generator'] = function (Application $app) {
return $app['router'];
};
}
示例15: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
// Load defaults
foreach ($this->settings as $key => $value) {
$key = 'captcha.' . $key;
if (!isset($app[$key])) {
$app[$key] = $value;
}
}
// Instance of builder
$app['captcha.builder'] = function (Application $app) {
return new CaptchaBuilder($app['captcha.phrase'], $app['captcha.phrase_builder']);
};
// Checks captcha
$app['captcha.test'] = $app->protect(function ($phrase) use($app) {
/** @var $builder CaptchaBuilder */
$builder = $app['captcha.builder'];
/** @var $session Session */
$session = $app['session'];
$builder->setPhrase($session->get($app['captcha.session_key']));
return $builder->testPhrase($phrase);
});
// Returns absolute URL to the image
$app['captcha.image_url'] = $app->protect(function () use($app) {
/** @var $urlGenerator UrlGenerator */
$urlGenerator = $app['url_generator'];
return $urlGenerator->generate($app['captcha.route_name'], array(), UrlGenerator::ABSOLUTE_URL);
});
}