本文整理汇总了PHP中Interop\Container\ContainerInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::get方法的具体用法?PHP ContainerInterface::get怎么用?PHP ContainerInterface::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interop\Container\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Executa a ação.
*
* @return mixin
*/
public function execute()
{
$oAuthServiceName = $this->params('oAuthService');
$redirectAfterResponse = $this->params()->fromQuery('redirectAfterResponse');
$scopes = $this->params()->fromQuery('scopes', []);
$routeToRedirectAfterResponse = null;
if (is_string($scopes)) {
if (trim($scopes)) {
$scopes = explode(',', $scopes);
} else {
$scopes = [];
}
}
if (!$oAuthServiceName) {
return $this->error('The query param "oAuthService" is required.');
}
if ($redirectAfterResponse) {
if (is_string($redirectAfterResponse)) {
$redirectAfterResponse = CryptQueryParam::decrypt_($redirectAfterResponse);
}
if ($redirectAfterResponse) {
$routeToRedirectAfterResponse = new InternalRoute($redirectAfterResponse);
}
}
AskForAuthorizationResponse::storeDateToUseAfterResponse($routeToRedirectAfterResponse, $oAuthServiceName, $scopes);
/** @var OAuthServiceInterface $oAuthService */
$oAuthService = $this->container->get('Sta\\OAuthConnect\\OAuthService\\' . $oAuthServiceName);
$callbackUrl = $this->getController()->url()->fromRoute('sta/oAuthConnect/response', [], ['force_canonical' => true]);
$authorizeRedirectUri = $oAuthService->getUrlToAskAuthorization($callbackUrl, $scopes);
if (!$authorizeRedirectUri) {
return $this->error('OAuth Service implementation class method ' . get_class($oAuthService) . '::getUrlToAskAuthorization() must return a valid URL.');
}
return $this->getController()->redirect()->toUrl($authorizeRedirectUri);
}
示例2: __invoke
/**
* @param ContainerInterface $container
* @return RpcServiceModelFactory
* @throws ServiceNotCreatedException
*/
public function __invoke(ContainerInterface $container)
{
if (!$container->has(ModulePathSpec::class) || !$container->has(ConfigResourceFactory::class) || !$container->has(ModuleModel::class) || !$container->has('SharedEventManager')) {
throw new ServiceNotCreatedException(sprintf('%s is missing one or more dependencies from ZF\\Configuration', RpcServiceModelFactory::class));
}
return new RpcServiceModelFactory($container->get(ModulePathSpec::class), $container->get(ConfigResourceFactory::class), $container->get('SharedEventManager'), $container->get(ModuleModel::class));
}
示例3: __invoke
/**
* Create and return a DocumentationModel instance.
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return DocumentationModel
* @throws ServiceNotCreatedException
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
if (!$container->has(ConfigResourceFactory::class)) {
throw new ServiceNotCreatedException(sprintf('%s requires that the %s service be present; service not found', DocumentationModel::class, ConfigResourceFactory::class));
}
return new DocumentationModel($container->get(ConfigResourceFactory::class), $container->get(ModuleUtils::class));
}
示例4: __invoke
/**
* @param ContainerInterface $container
* @returns ZendViewRenderer
*/
public function __invoke(ContainerInterface $container)
{
$config = $container->has('config') ? $container->get('config') : [];
$config = isset($config['templates']) ? $config['templates'] : [];
// Configuration
$resolver = new Resolver\AggregateResolver();
$resolver->attach(new Resolver\TemplateMapResolver(isset($config['map']) ? $config['map'] : []), 100);
// Create the renderer
$renderer = new PhpRenderer();
$renderer->setResolver($resolver);
$manager = $container->has(HelperPluginManager::class) ? $container->get(HelperPluginManager::class) : new HelperPluginManager();
// Inject helpers
$this->injectHelpers($renderer, $manager);
// Initialize renderer for HelperPluginManager
$manager->setRenderer($renderer);
// Inject renderer
$view = new ZendViewRenderer($renderer, isset($config['layout']) ? $config['layout'] : null);
// Add template paths
$allPaths = isset($config['paths']) && is_array($config['paths']) ? $config['paths'] : [];
foreach ($allPaths as $namespace => $paths) {
$namespace = is_numeric($namespace) ? null : $namespace;
foreach ((array) $paths as $path) {
$view->addPath($path, $namespace);
}
}
return $view;
}
示例5: __invoke
/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('config');
$config = isset($config['asset_manager']) ? $config['asset_manager'] : array();
$resolver = new AggregateResolver();
if (empty($config['resolvers'])) {
return $resolver;
}
foreach ($config['resolvers'] as $resolverService => $priority) {
$resolverService = $container->get($resolverService);
if (!$resolverService instanceof ResolverInterface) {
throw new Exception\RuntimeException('Service does not implement the required interface ResolverInterface.');
}
if ($resolverService instanceof AggregateResolverAwareInterface) {
$resolverService->setAggregateResolver($resolver);
}
if ($resolverService instanceof MimeResolverAwareInterface) {
$resolverService->setMimeResolver($container->get(MimeResolver::class));
}
if ($resolverService instanceof AssetFilterManagerAwareInterface) {
$resolverService->setAssetFilterManager($container->get(AssetFilterManager::class));
}
$resolver->attach($resolverService, $priority);
}
return $resolver;
}
示例6: __invoke
/**
* Create service
*
* @param ContainerInterface $container
* @return mixed
*/
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config');
$cacheEnabled = isset($config['view']['cache']) ? (bool) $config['view']['cache'] : false;
$layout = isset($config['view']['layout']) && is_string($config['view']['layout']) ? $config['view']['layout'] : 'CargoUI/view/layout/layout.phtml';
return new Main($layout, $cacheEnabled, $container->get(RiotCompiler::class));
}
示例7: __invoke
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config');
$expressive_redirect_handler_config = isset($config['expressive-redirect-handler']) ? $config['expressive-redirect-handler'] : [];
$router = $container->get(RouterInterface::class);
return new RedirectHandlerAction($expressive_redirect_handler_config, $router);
}
示例8: __invoke
/**
* Create and return an instance of the Middleware.
*
* @param Interop\Container\ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return MiddlewareInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$rqlParser = new Rest\Rql\RqlParser();
$responseEncoder = new Rest\ResponseEncoder();
$resourceName = $requestedName;
//is there config for this resource?
$config = $container->get('config');
if (isset($config['resource'][$resourceName]['storeMiddleware'])) {
$storeMiddlewareServiceName = $config['resource'][$resourceName]['storeMiddleware'];
$storeMiddleware = $container->get($storeMiddlewareServiceName);
return new restActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
}
//is there table with same name?
$db = $container->has('db') ? $container->get('db') : null;
if (isset($db)) {
$dbMetadata = new Zend\Db\Metadata\Metadata($db);
$tableNames = $dbMetadata->getTableNames();
if (isset($tableNames[$resourceName])) {
$tableGateway = new TableGateway($resourceName, $db);
$dataStore = new DbTable($tableGateway);
$storeMiddleware = new StoreMiddleware($dataStore);
return new Rest\RestActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
}
}
throw new DataStoresException('Can\'t make RestActionPipe' . ' for resource: ' . $resourceName);
}
示例9: tearDown
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
$adapter = $this->container->get('db');
$tableManagerMysql = new TableManagerMysql($adapter);
$tableManagerMysql->deleteTable($this->object->getStore()->getTable());
$tableManagerMysql->deleteTable($this->object->getQueue()->getStore()->getTable());
}
示例10: __invoke
/**
* @param ContainerInterface $container
* @return TeacherAction
*/
public function __invoke(ContainerInterface $container)
{
$router = $container->get(RouterInterface::class);
$userService = $container->get(TeacherService::class);
$studentWebService = $container->get('StudentWebService');
return new TeacherAction($router, $userService, $studentWebService);
}
示例11: __invoke
/**
* __invoke
*
* @param ContainerInterface $container
*
* @return AxosoftLoggerPsr
*/
public function __invoke($container)
{
$configRoot = $container->get('Config');
$loggerOptions = $configRoot['Reliv\\RcmAxosoft']['errorLogger'];
$api = $container->get('Reliv\\AxosoftApi\\Service\\AxosoftApi');
return new AxosoftLoggerPsr($api, $loggerOptions);
}
示例12: testFactoryWithTemplate
public function testFactoryWithTemplate()
{
$factory = new PageFactory();
$this->container->has(TemplateRendererInterface::class)->willReturn(true);
$this->container->get(TemplateRendererInterface::class)->willReturn($this->prophesize(TemplateRendererInterface::class));
$this->assertTrue($factory instanceof PageFactory);
}
示例13: __invoke
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var $aclCache \Zend\Cache\Storage\StorageInterface */
$aclCache = $container->get('AclCache');
$acl = $aclCache->getItem('Acl');
if (!$acl) {
/* @var $userApi UserApiInterface */
$userApi = $container->get(UserApiInterface::SERVICE_NAME);
$acl = new Acl();
$resources = $userApi->getPermissions();
foreach ($resources as $resource) {
$acl->addResource($resource);
}
$roles = $userApi->getRolesAndParent();
foreach ($roles as $role => $parents) {
$this->addRoleToAcl($role, $roles, $acl);
}
$rolePermissions = $userApi->getRolePermissions();
foreach ($rolePermissions as $role => $permissions) {
$acl->allow($role, $permissions);
}
$deniedRolePermissions = $userApi->getDeniedRolePermissions();
foreach ($deniedRolePermissions as $role => $permissions) {
$acl->deny($role, $permissions);
}
$aclCache->setItem('Acl', $acl);
}
return $acl;
}
示例14: __invoke
/**
* @param ContainerInterface $container
* @return TwigRenderer
*/
public function __invoke(ContainerInterface $container)
{
$config = $container->has('config') ? $container->get('config') : [];
$debug = array_key_exists('debug', $config) ? (bool) $config['debug'] : false;
$config = isset($config['templates']) ? $config['templates'] : [];
$cacheDir = isset($config['cache_dir']) ? $config['cache_dir'] : false;
// Create the engine instance
$loader = new TwigLoader();
$environment = new TwigEnvironment($loader, ['cache' => $debug ? false : $cacheDir, 'debug' => $debug, 'strict_variables' => $debug, 'auto_reload' => $debug]);
// Add extensions
if ($container->has(RouterInterface::class)) {
$environment->addExtension(new TwigExtension($container->get(RouterInterface::class), isset($config['assets_url']) ? $config['assets_url'] : '', isset($config['assets_version']) ? $config['assets_version'] : ''));
}
if ($debug) {
$environment->addExtension(new TwigExtensionDebug());
}
// Inject environment
$twig = new TwigRenderer($environment, isset($config['extension']) ? $config['extension'] : 'html.twig');
// Add template paths
$allPaths = isset($config['paths']) && is_array($config['paths']) ? $config['paths'] : [];
foreach ($allPaths as $namespace => $paths) {
$namespace = is_numeric($namespace) ? null : $namespace;
foreach ((array) $paths as $path) {
$twig->addPath($path, $namespace);
}
}
return $twig;
}
示例15: __invoke
/**
* @param ContainerInterface $container
* @return EventStore
*/
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config');
if (!isset($config['prooph'])) {
throw ConfigurationException::configurationError('Missing prooph config key in application config');
}
if (!isset($config['prooph']['event_store'])) {
throw ConfigurationException::configurationError('Missing key event_store in prooph configuration');
}
$config = $config['prooph']['event_store'];
if (!isset($config['adapter']['type'])) {
throw ConfigurationException::configurationError(sprintf('Event store adapter is missing in configuration'));
}
$adapter = $container->get($config['adapter']['type']);
if (!isset($config['event_emitter'])) {
$eventEmitter = new ProophActionEventEmitter();
} else {
$eventEmitter = $container->get($config['event_emitter']);
}
$eventStore = new EventStore($adapter, $eventEmitter);
$plugins = isset($config['plugins']) ? $config['plugins'] : [];
foreach ($plugins as $pluginAlias) {
$plugin = $container->get($pluginAlias);
if (!$plugin instanceof Plugin) {
throw ConfigurationException::configurationError(sprintf('Plugin %s does not implement the Plugin interface', $pluginAlias));
}
$plugin->setUp($eventStore);
}
return $eventStore;
}