当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::protect方法代码示例

本文整理汇总了PHP中Pimple\Container::protect方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::protect方法的具体用法?PHP Container::protect怎么用?PHP Container::protect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimple\Container的用法示例。


在下文中一共展示了Container::protect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * {@inheritdoc}
  */
 public function register(Container $c)
 {
     $c['migrations.apps'] = function ($c) {
         $apps = new Container();
         foreach ($c['migrations.options'] as $key => $options) {
             $apps[$key] = function () use($c, $key, $options) {
                 $db = $c['dbs'][$key];
                 return $c['migrations.create_app']($c['migrations.create_helpers']($db), $c['migrations.create_commands']($db, $options));
             };
         }
         return $apps;
     };
     $c['migrations.create_app'] = $c->protect(function ($helpers, $commands) {
         return ConsoleRunner::createApplication($helpers, $commands);
     });
     $c['migrations.create_helpers'] = $c->protect(function ($db) {
         return new HelperSet(['db' => new ConnectionHelper($db), 'dialog' => new QuestionHelper()]);
     });
     $c['migrations.create_commands'] = $c->protect(function ($db, $options) {
         $config = new Configuration($db);
         if (isset($options['namespace'])) {
             $config->setMigrationsNamespace($options['namespace']);
         }
         $config->setMigrationsDirectory($options['path']);
         $config->registerMigrationsFromDirectory($options['path']);
         if (isset($options['table'])) {
             $config->setMigrationsTableName($options['table']);
         }
         $commands = [new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()];
         foreach ($commands as $command) {
             $command->setMigrationConfiguration($config);
         }
         return $commands;
     });
 }
开发者ID:okeyaki,项目名称:silex-doctrine-migrations,代码行数:38,代码来源:DoctrineMigrationsServiceProvider.php

示例2: 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);
     });
 }
开发者ID:amstaffix,项目名称:silex-captcha,代码行数:32,代码来源:CaptchaServiceProvider.php

示例3: register

 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  */
 public function register(Container $app)
 {
     $app['security.jwt_retrieval.authorization_bearer.strategy'] = function () {
         return new AuthorizationBearerStrategy();
     };
     $app['security.jwt_retrieval.query_parameter.strategy'] = function () {
         return new QueryParameterStrategy();
     };
     $app['security.jwt_retrieval.chain.strategy'] = function () use($app) {
         return new ChainStrategy([$app['security.jwt_retrieval.authorization_bearer.strategy'], $app['security.jwt_retrieval.query_parameter.strategy']]);
     };
     $app['security.entry_point.jwt._proto'] = $app->protect(function () use($app) {
         return function () {
             return new JWTAuthenticationEntryPoint();
         };
     });
     $app['security.authentication_listener.factory.jwt'] = $app->protect(function ($name, $options) use($app) {
         $app['security.authentication_provider.' . $name . '.jwt'] = function () use($app, $options) {
             $encoder = new JWTEncoder($options['secret_key'], reset($options['allowed_algorithms']));
             $decoder = new JWTDecoder($options['secret_key'], $options['allowed_algorithms']);
             $converter = new SecurityUserConverter();
             $userBuilder = new JWTUserBuilder($decoder, $encoder, $converter);
             return new JWTAuthenticationProvider($userBuilder);
         };
         $app['security.authentication_listener.' . $name . '.jwt'] = function () use($app, $name, $options) {
             $strategyName = isset($options['retrieval_strategy']) ? $options['retrieval_strategy'] : 'authorization_bearer';
             return new JWTListener($app['security.token_storage'], $app['security.authentication_manager'], $app['security.jwt_retrieval.' . $strategyName . '.strategy']);
         };
         $app['security.entry_point.' . $name . '.jwt'] = $app['security.entry_point.jwt._proto']($name, $options);
         return array('security.authentication_provider.' . $name . '.jwt', 'security.authentication_listener.' . $name . '.jwt', 'security.entry_point.' . $name . '.jwt', 'pre_auth');
     });
 }
开发者ID:evaneos,项目名称:silex-jwt-provider,代码行数:38,代码来源:SecurityJWTServiceProvider.php

示例4: bind

 /**
  * Bind an abstract definition to a concrete implementation.
  *
  * @param string $abstract
  * @param string|\Closure $concrete
  * @param bool $protect
  */
 public function bind($abstract, $concrete, $protect = false)
 {
     if ($protect) {
         $concrete = $this->container->protect($concrete);
     }
     $this->container[$abstract] = $concrete;
 }
开发者ID:jonsa,项目名称:pimple-ioc,代码行数:14,代码来源:ClassResolver.php

示例5: register

 /**
  * @param Container|Application $app
  */
 public function register(Container $app)
 {
     if (!$app->offsetExists('annot.useServiceControllers')) {
         $app['annot.useServiceControllers'] = true;
     }
     $app["annot"] = function (Container $app) {
         return new AnnotationService($app);
     };
     // A custom auto loader for Doctrine Annotations since it can't handle PSR-4 directory structure
     AnnotationRegistry::registerLoader(function ($class) {
         return class_exists($class);
     });
     // Register ServiceControllerServiceProvider here so the user doesn't have to.
     if ($app['annot.useServiceControllers']) {
         $app->register(new ServiceControllerServiceProvider());
     }
     // this service registers the service controller and can be overridden by the user
     $app['annot.registerServiceController'] = $app->protect(function ($controllerName) use($app) {
         if ($app['annot.useServiceControllers']) {
             $app["{$controllerName}"] = function (Application $app) use($controllerName) {
                 return new $controllerName($app);
             };
         }
     });
     $app['annot.controllerFinder'] = $app->protect(function (Application $app, $dir) {
         return $app['annot']->getFiles($dir, $app['annot.controllerNamespace']);
     });
     /** @noinspection PhpUnusedParameterInspection */
     $app['annot.controller_factory'] = $app->protect(function (Application $app, $controllerName, $methodName, $separator) {
         return $controllerName . $separator . $methodName;
     });
     $app['annot.controllerNamespace'] = '';
 }
开发者ID:jsmith07,项目名称:silex-annotation-provider,代码行数:36,代码来源:AnnotationServiceProvider.php

示例6: register

 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  */
 public function register(Container $app)
 {
     $app['renderer'] = function ($app) {
         return new Renderer($app);
     };
     $app['render'] = $app->protect(function ($view_path, $params = array()) use($app) {
         return $app['renderer']->render($view_path, $params);
     });
     $app['view'] = $app->protect(function ($viewName, $params = array()) use($app) {
         return $app['render'](@$app['config']['views_path'] . '/' . $viewName, $params);
     });
 }
开发者ID:jh9aea,项目名称:promotion_container,代码行数:18,代码来源:RendererProvider.php

示例7: set

 /**
  * @param string $key
  * @param mixed $val
  * @param string $type (optional)
  */
 static function set($key, $val, $type = null)
 {
     if (!static::$pimple) {
         throw new \LogicException('\\Pimple\\Container not set, call init() or setPimple() before using set().');
     }
     if ('factory' == $type) {
         static::$pimple[$key] = static::$pimple->factory($val);
     } elseif ('protect' == $type) {
         static::$pimple[$key] = static::$pimple->protect($val);
     } else {
         static::$pimple[$key] = $val;
     }
 }
开发者ID:cumi,项目名称:pressbooks,代码行数:18,代码来源:class-pb-container.php

示例8: register

 public function register(Container $pimple)
 {
     $pimple['normalizer.link'] = function () use($pimple) {
         return $pimple['normalizer'];
     };
     $pimple['normalizer.image'] = function () use($pimple) {
         return $pimple['normalizer'];
     };
     $pimple['normalizer.redirect'] = function () use($pimple) {
         return $pimple['normalizer'];
     };
     $pimple['normalizer.script'] = function () use($pimple) {
         return $pimple['normalizer'];
     };
     $pimple['normalizer.stylesheet'] = function () use($pimple) {
         return $pimple['normalizer'];
     };
     $pimple['discoverer.link'] = function () use($pimple) {
         return new LinkDiscoverer($pimple['normalizer.link']);
     };
     $pimple['discoverer.image'] = function () use($pimple) {
         return new ImageDiscoverer($pimple['normalizer.image']);
     };
     $pimple['discoverer.script'] = function () use($pimple) {
         return new ScriptDiscoverer($pimple['normalizer.script']);
     };
     $pimple['discoverer.stylesheet'] = function () use($pimple) {
         return new StylesheetDiscoverer($pimple['normalizer.stylesheet']);
     };
     $pimple['discoverer.redirect'] = function () use($pimple) {
         return new RedirectDiscoverer($pimple['normalizer.redirect']);
     };
     $pimple['request_factory.internal_html'] = $pimple->protect(function (UriInterface $uri) use($pimple) {
         return new Request('GET', $uri);
     });
     $pimple['request_factory.internal_asset'] = $pimple->protect(function (UriInterface $uri) use($pimple) {
         return new Request('HEAD', $uri);
     });
     $pimple['matcher.internal_html'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.html']);
     };
     $pimple['matcher.internal_asset'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.asset']);
     };
     $pimple['recursor.internal_html'] = function () use($pimple) {
         return new UriRecursor($pimple['matcher.internal_html'], $pimple['request_factory.internal_html']);
     };
     $pimple['recursor.internal_asset'] = function () use($pimple) {
         return new UriRecursor($pimple['matcher.internal_asset'], $pimple['request_factory.internal_asset']);
     };
 }
开发者ID:LastCallMedia,项目名称:Crawler,代码行数:51,代码来源:RecursionServiceProvider.php

示例9: register

 /**
  * @param Container $app
  */
 public function register(Container $app)
 {
     $app['config.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         $filenames = (array) $app['config.filenames'];
         foreach ($filenames as $path) {
             $path = $app['config.replacements.resolver']($path);
             $app['config.loader']->load($path);
         }
     });
     $app['config.replacements.resolver'] = $app->protect(function ($value) use($app) {
         $replacements = $app['config.replacements'];
         if ([] === $replacements) {
             return $value;
         }
         if (is_array($value)) {
             return array_map(function ($value) use($app) {
                 return $app['config.replacements.resolver']($value);
             }, $value);
         }
         if (!is_string($value)) {
             return $value;
         }
         return $this->resolveString($value, $replacements);
     });
     $app['config.locator'] = function () {
         return new FileLocator();
     };
     $app['config.loader.yml'] = $app->factory(function (Container $app) {
         return new YamlFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app, $app['config.locator']);
     });
     $app['config.loader.resolver'] = function (Container $app) {
         return new LoaderResolver([$app['config.loader.yml'], $app['config.loader.directory'], $app['config.loader.php']]);
     };
     $app['config.loader'] = function (Container $app) {
         return new DelegatingLoader($app['config.loader.resolver']);
     };
     $app['config.filenames'] = [];
     $app['config.replacements'] = [];
 }
开发者ID:sergiors,项目名称:config-service-provider,代码行数:53,代码来源:ConfigServiceProvider.php

示例10: register

 /**
  * @param Container|Application $app
  */
 public function register(Container $app)
 {
     ini_set('log_errors', 1);
     strtoupper(env('APP_ENV')) === 'PRODUCTION' ? ini_set('display_errors', 0) : ini_set('display_errors', 1);
     $app['debug'] = env('DEBUG');
     !$app['debug'] ?: ($app['dump'] = $app->protect(function ($var) {
         return (new VarDumper())::dump($var);
     }));
     /** Register the app error factory */
     $app->error(function (\Exception $e) use($app) {
         // handle HTTP exceptions
         if (get_class($e) === NotFoundHttpException::class) {
             /** @var NotFoundHttpException $e */
             /** @noinspection DegradedSwitchInspection */
             switch ($e->getStatusCode()) {
                 case 404:
                     return response(view('404.html', ['error' => '404 - Page Not Found.']), 404);
                     break;
                 default:
                     $message = 'We are sorry, but something went terribly wrong.';
             }
             return new Response($message);
         }
         // not an HTTP exception
         throw $e;
     });
     if ($app['debug']) {
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
         # core debug utilities
         # note that debug requires that the environment has been loaded
         include_once BOOT . 'assets/debug.php';
     }
 }
开发者ID:formula9,项目名称:framework,代码行数:37,代码来源:ReportingServiceProvider.php

示例11: register

 public function register(Container $container)
 {
     $container['cms.get_post_url_attributes'] = $container->protect(function (Post $post) {
         return ['date' => $post->getCreated()->format('Y/m/d'), 'slug' => $post->getSlug()];
     });
     $container['cms'] = function () use($container) {
         $cms = new CMS($container['em']);
         $postCmsEntity = new CMSEntity(Post::class, PostType::class);
         $postCmsEntity->addColumn('title', function (Post $post) use($container) {
             $href = $container->path('post', $container['cms.get_post_url_attributes']($post));
             return '<a href="' . $href . '">' . $post->getTitle() . '</a>';
         });
         $postCmsEntity->addColumn('slug', 'slug');
         $cms->addCMSEntity($postCmsEntity);
         $pageCmsEntity = new CMSEntity(Page::class, PageType::class);
         $pageCmsEntity->addColumn('title', 'title');
         $pageCmsEntity->addColumn('slug', 'slug');
         $cms->addCMSEntity($pageCmsEntity);
         $menuCMSEntity = new CMSEntity(Menu::class, MenuType::class);
         $menuCMSEntity->addColumn('name', 'name');
         $cms->addCMSEntity($menuCMSEntity);
         $categoryCmsEntity = new CMSEntity(Category::class, CategoryType::class);
         $categoryCmsEntity->addColumn('Name', 'name');
         $cms->addCMSEntity($categoryCmsEntity);
         return $cms;
     };
 }
开发者ID:cmsilex,项目名称:cmsilex,代码行数:27,代码来源:CMSServiceProvider.php

示例12: register

 public function register(Container $app)
 {
     $app['mailer'] = function () {
         $mailer = new \PHPMailer();
         $mailer->CharSet = 'UTF-8';
         return $mailer;
     };
     $app['email'] = $app->factory(function ($c) {
         $mailConfig = $c['config']['mail'];
         $email = $c['mailer'];
         $email->From = $mailConfig['from'];
         if (is_array($mailConfig['to'])) {
             foreach ($mailConfig['to'] as $addr) {
                 $email->addAddress($addr);
             }
         } else {
             $email->addAddress($mailConfig['to']);
         }
         $email->isHTML(true);
         return $email;
     });
     $app['email:send'] = $app->protect(function ($subject, $body) use($app) {
         $email = $app['email'];
         if ($subject and $body) {
             $email->Subject = $subject;
             $email->Body = $body;
         }
         return $email->send();
     });
 }
开发者ID:jh9aea,项目名称:promotion_container,代码行数:30,代码来源:MailerProvider.php

示例13: register

 /**
  * @param Container $container
  */
 public function register(Container $container)
 {
     $container->register(new AnnotationServiceProvider());
     $container['annot.registerServiceController'] = $container->protect(function ($controllerName) use($container) {
         if ($container['annot.useServiceControllers']) {
             $container["{$controllerName}"] = function (Application $app) use($controllerName) {
                 /**
                  * resolve dependency via container
                  */
                 $reflection_class = new \ReflectionClass($controllerName);
                 $params = $reflection_class->getConstructor()->getParameters();
                 $ctor_param = [];
                 foreach ($params as $param) {
                     $class = $param->getClass();
                     if ($class === null) {
                         throw new \InvalidArgumentException("`{$param->getName()}` in {$controllerName}\n                                 constructor must have class type hinting");
                     }
                     $param_class_name = $class->getName();
                     if (!isset($app[$param_class_name])) {
                         throw new \InvalidArgumentException("{$param_class_name} in {$controllerName}\n                                 not found in container");
                     }
                     array_push($ctor_param, $app[$param_class_name]);
                 }
                 return $reflection_class->newInstanceArgs($ctor_param);
             };
         }
     });
 }
开发者ID:digideskio,项目名称:singo,代码行数:31,代码来源:AnnotationRouting.php

示例14: register

 public function register(Container $app)
 {
     $app['twig.loader']->addLoader(new Twig_Loader_Filesystem(__DIR__ . '/../View'));
     $app->extend('twig', function ($twig, $app) {
         $twig->addFilter(new Twig_SimpleFilter('cast_to_array', function ($stdClassObject) {
             return (array) $stdClassObject;
         }));
         return $twig;
     });
     //        $app['twig'] = $app->extend('twig', function ($twig,$app) {
     //            $twig->addGlobal('paginator.range', $app['paginator.range']);
     //            $twig->addExtension(new Twig\TwigPaginatorExtension($app['request_stack']));
     //
     //            return $twig;
     //        });
     $app['paginator'] = $app->protect(function ($currentPageNumber, $totalItemsCount, $itemCountPerPage = null) use($app) {
         if (!$itemCountPerPage && isset($app['paginator.per_page'])) {
             $itemCountPerPage = $app['paginator.per_page'];
         }
         $paginator = new \Paginator\Paginator($currentPageNumber, $totalItemsCount, $itemCountPerPage);
         if (isset($app['paginator.range'])) {
             $paginator->setPageRange($app['paginator.range']);
         }
         if (isset($app['paginator.style'])) {
             $paginator->setDefaultScrollingStyle();
         }
         return $paginator->getPages();
     });
 }
开发者ID:arduanov,项目名称:silex-app,代码行数:29,代码来源:PaginatorServiceProvider.php

示例15: register

 /**
  * @param \Pimple\Container $pimple
  */
 public function register(Container $pimple)
 {
     $pimple['twig.options'] = array();
     $pimple['twig.path'] = array();
     $pimple['twig.templates'] = array();
     $pimple['twig'] = function ($c) {
         $c['twig.options'] = array_replace(array('charset' => isset($c['charset']) ? $c['charset'] : 'UTF-8', 'debug' => isset($c['debug']) ? $c['debug'] : false, 'strict_variables' => isset($c['debug']) ? $c['debug'] : false), $c['twig.options']);
         /** @var \Twig_Environment $twig */
         $twig = $c['twig.environment_factory']($c);
         if (isset($c['debug']) && $c['debug']) {
             $twig->addExtension(new \Twig_Extension_Debug());
         }
         $twig->addExtension(new \Drufony\Bridge\Twig\ThemeExtension());
         $twig->addExtension(new \Drufony\Bridge\Twig\RenderExtension());
         return $twig;
     };
     $pimple['twig.loader.drupal'] = function ($c) {
         return new DrupalLoader($GLOBALS['theme'], $GLOBALS['base_theme_info']);
     };
     $pimple['twig.loader.filesystem'] = function ($c) {
         return new \Twig_Loader_Filesystem($c['twig.path']);
     };
     $pimple['twig.loader.array'] = function ($c) {
         return new \Twig_Loader_Array($c['twig.templates']);
     };
     $pimple['twig.loader.string'] = function ($c) {
         return new \Twig_Loader_String();
     };
     $pimple['twig.loader'] = function ($c) {
         return new \Twig_Loader_Chain(array($c['twig.loader.array'], $c['twig.loader.drupal'], $c['twig.loader.filesystem'], $c['twig.loader.string']));
     };
     $pimple['twig.environment_factory'] = $pimple->protect(function ($c) {
         return new \Twig_Environment($c['twig.loader'], $c['twig.options']);
     });
 }
开发者ID:bangpound,项目名称:drupal-bridge,代码行数:38,代码来源:TwigServiceProvider.php


注:本文中的Pimple\Container::protect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。