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


PHP Application::protect方法代码示例

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


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

示例1: register

 public function register(Application $app)
 {
     $app['csv.exporter.config'] = $app->share(function () {
         $config = new ExporterConfig();
         return $config->setDelimiter(";")->setEnclosure('"')->setEscape("\\")->setToCharset('UTF-8')->setFromCharset('UTF-8');
     });
     $app['csv.exporter'] = $app->share(function ($app) {
         return new Exporter($app['csv.exporter.config']);
     });
     $app['csv.lexer.config'] = $app->share(function ($app) {
         $lexer = new LexerConfig();
         $lexer->setDelimiter(';')->setEnclosure('"')->setEscape("\\")->setToCharset('UTF-8')->setFromCharset('UTF-8');
         return $lexer;
     });
     $app['csv.lexer'] = $app->share(function ($app) {
         return new Lexer($app['csv.lexer.config']);
     });
     $app['csv.interpreter'] = $app->share(function ($app) {
         return new Interpreter();
     });
     $app['csv.response'] = $app->protect(function ($callback) use($app) {
         // set headers to fix ie issues
         $response = new StreamedResponse($callback, 200, ['Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control' => 'no-store, no-cache, must-revalidate', 'Cache-Control' => 'post-check=0, pre-check=0', 'Pragma' => 'no-cache', 'Content-Type' => 'text/csv', 'Cache-Control' => 'max-age=3600, must-revalidate', 'Content-Disposition' => 'max-age=3600, must-revalidate']);
         $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'export.csv'));
     });
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:26,代码来源:CSVServiceProvider.php

示例2: register

 /**
  * {@inheritdoc}
  */
 public function register(Application $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'] = $app->share(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:jdoose,项目名称:silex-captcha,代码行数:32,代码来源:CaptchaServiceProvider.php

示例3: register

 function register(Application $app)
 {
     $this->app = $app;
     $this->log = $app['monolog'];
     $this->session = $app['session'];
     $this->url_generator = $app['url_generator'];
     $app['jira.request_token_url'] = $this->getAbsoluteURL('request_token');
     $app['jira.authorization_url'] = $this->getAbsoluteURL('authorization');
     $app['jira.access_token_url'] = $this->getAbsoluteURL('access_token');
     $app['jira.oauth.client'] = $app->share(function () use($app) {
         if (is_null($this->session->get('oauth'))) {
             $this->log->addError('Jira OAuth client is not initialized correctly.' . 'Please create valid credentials first.');
             throw new \Exception('Jira OAuth client is not initialized');
         }
         $app['jira.token'] = $this->session->get('oauth');
         $oauth = $this->getOAuth();
         return $this->getClient($oauth);
     });
     $app['jira.oauth.temp_credentials'] = $app->protect(function ($redirect = null) {
         return $this->requestTempCredentials($redirect);
     });
     $app['jira.oauth.auth_credentials'] = $app->protect(function ($redirect = null) {
         return $this->requestAuthCredentials($redirect);
     });
     $app['jira.oauth.auth_url'] = $app->share(function () {
         return $this->makeAuthUrl();
     });
     $app['jira.default_redirect'] = $app->share(function () {
         return $this->url_generator->generate($this->config['route_name.default_redirect']);
     });
     $app['jira.controller.provider'] = $app->share(function () {
         return new JiraOAuthControllerProvider();
     });
 }
开发者ID:bmwcarit,项目名称:silex-jira-oauth-provider,代码行数:34,代码来源:JiraOAuthServiceProvider.php

示例4: register

 public function register(Application $app)
 {
     $config = $this->config;
     $app['user'] = null;
     $app['devture_user.roles'] = $config['roles'];
     $app['devture_user.db'] = $app->share(function ($app) use($config) {
         return $app[$config['database_service_id']];
     });
     if ($config['database_type'] === 'relational') {
         $app['devture_user.repository'] = $app->share(function ($app) {
             return new Repository\Relational\UserRepository($app['devture_user.db']);
         });
     } else {
         if ($config['database_type'] === 'mongodb') {
             $app['devture_user.repository'] = $app->share(function ($app) {
                 return new Repository\MongoDB\UserRepository($app['devture_user.db']);
             });
         } else {
             throw new \InvalidArgumentException('Unrecognized database type: ' . $config['database_type']);
         }
     }
     $app['devture_user.password_encoder'] = $app->share(function ($app) use($config) {
         return new Helper\PasswordEncoder($config['blowfish_cost']);
     });
     $app['devture_user.auth_helper'] = $app->share(function ($app) use($config) {
         return new Helper\AuthHelper($app['devture_user.repository'], $app['devture_user.password_encoder'], $config['password_token_salt']);
     });
     $app['devture_user.login_manager'] = $app->share(function ($app) use($config) {
         return new Helper\LoginManager($app['devture_user.auth_helper'], $config['cookie_signing_secret'], $config['cookie_path']);
     });
     $app['devture_user.access_control'] = $app->share(function ($app) {
         return new AccessControl\AccessControl($app);
     });
     $app['devture_user.validator'] = function ($app) {
         return new Validator\UserValidator($app['devture_user.repository'], $app['devture_user.roles']);
     };
     $app['devture_user.form_binder'] = function ($app) {
         $binder = new Form\FormBinder($app['devture_user.validator'], $app['devture_user.password_encoder']);
         $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'user');
         return $binder;
     };
     $app['devture_user.listener.user_from_request_initializer'] = $app->protect(function (Request $request) use($app) {
         $app['user'] = $app['devture_user.login_manager']->createUserFromRequest($request);
     });
     $app['devture_user.listener.csrf_token_manager_salter'] = $app->protect(function (Request $request) use($app) {
         if ($app['user'] instanceof Model\User) {
             $app['devture_framework.csrf_token_manager']->setSalt($app['user']->getUsername());
         }
     });
     $app['devture_user.listener.conditional_session_extender'] = $app->protect(function (Request $request, Response $response) use($app) {
         if ($app['user'] instanceof Model\User) {
             $app['devture_user.login_manager']->extendSessionIfNeeded($app['user'], $request, $response);
         }
     });
     $app['devture_user.twig.user_extension'] = $app->share(function ($app) {
         return new Twig\UserExtension($app['devture_user.access_control'], $app);
     });
     $this->registerConsoleServices($app);
     $this->registerControllerServices($app);
 }
开发者ID:devture,项目名称:silex-user-bundle,代码行数:60,代码来源:ServicesProvider.php

示例5: register

 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app
  */
 public function register(Application $app)
 {
     /**
      * Add closures for getting all the Codebender URLs we need to know.
      */
     $app['codebender'] = $app->protect(function ($uri) {
         return sprintf('%s/%s', $this->codebender_url, ltrim($uri, '/'));
     });
     $app['codebender.builder'] = $app->protect(function () use($app) {
         return $this->builder_url;
     });
     /**
      * Add closures for performing requests against Codebender URLs.
      */
     $app['codebender.get'] = $app->protect(function ($url) use($app) {
         $client = new Client();
         $response = $client->get($url);
         return $response->getBody();
     });
     $app['codebender.post'] = $app->protect(function ($url, $json) use($app) {
         $client = new Client();
         $response = $client->post($url, ['body' => $json]);
         return $response->getBody();
     });
 }
开发者ID:seco,项目名称:BlocklyDuino,代码行数:33,代码来源:CodebenderServiceProvider.php

示例6: register

 /**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $keyLoader = $this->keyLoader;
     $app['security.authentication_listener.factory.hmac'] = $app->protect(function ($name, $options) use($app) {
         if (!isset($app['security.authentication_provider.' . $name . '.hmac'])) {
             $app['security.authentication_provider.' . $name . '.hmac'] = $app['security.authentication_provider.hmac._proto']($name, $options);
         }
         if (!isset($app['security.authentication_listener.' . $name . '.hmac'])) {
             $app['security.authentication_listener.' . $name . '.hmac'] = $app['security.authentication_listener.hmac._proto']($name, $options);
         }
         if (!isset($app['security.entry_point.' . $name . '.hmac'])) {
             $app['security.entry_point.' . $name . '.hmac'] = $app['security.entry_point.hmac._proto']($name, $options);
         }
         return ['security.authentication_provider.' . $name . '.hmac', 'security.authentication_listener.' . $name . '.hmac', 'security.entry_point.' . $name . '.hmac', 'pre_auth'];
     });
     $app['security.hmac.response_listener'] = $app->share(function () {
         return new HmacResponseListener();
     });
     $app['security.authentication_provider.hmac._proto'] = $app->protect(function ($name, $options) use($app, $keyLoader) {
         return $app->share(function () use($keyLoader) {
             return new HmacAuthenticationProvider(new RequestAuthenticator($keyLoader));
         });
     });
     $app['security.authentication_listener.hmac._proto'] = $app->protect(function ($name, $options) use($app) {
         return $app->share(function () use($app, $name) {
             return new HmacAuthenticationListener($app['security.token_storage'], $app['security.authentication_manager'], $app['security.entry_point.' . $name . '.hmac']);
         });
     });
     $app['security.entry_point.hmac._proto'] = $app->protect(function ($name, $options) use($app) {
         return new HmacAuthenticationEntryPoint();
     });
 }
开发者ID:acquia,项目名称:http-hmac-php,代码行数:35,代码来源:HmacSecurityProvider.php

示例7: register

 /**
  * @param Application $app
  */
 public function register(Application $app)
 {
     // define the authentication listener object
     $app['security.authentication_listener.wordpress._proto'] = $app->protect(function ($providerKey, $options) use($app) {
         return $app->share(function () use($app, $providerKey, $options) {
             return new Security\WordpressListener($app['security'], $app['security.authentication_manager'], $options['document_root'], $app['php.wordpress36.bootstrap'], $app['logger']);
         });
     });
     // define the authentication provider object
     $app['security.authentication_provider.wordpress._proto'] = $app->protect(function ($name) use($app) {
         return $app->share(function () use($app, $name) {
             return new Security\WordpressAuthenticationProvider();
         });
     });
     $type = 'wordpress';
     $entryPoint = null;
     $app['security.authentication_listener.factory.' . $type] = $app->protect(function ($name, $options) use($type, $app, $entryPoint) {
         if ($entryPoint && !isset($app['security.entry_point.' . $name . '.' . $entryPoint])) {
             $app['security.entry_point.' . $name . '.' . $entryPoint] = $app['security.entry_point.' . $entryPoint . '._proto']($name, $options);
         }
         if (!isset($app['security.authentication_listener.' . $name . '.' . $type])) {
             $app['security.authentication_listener.' . $name . '.' . $type] = $app['security.authentication_listener.' . $type . '._proto']($name, $options);
         }
         $provider = 'wordpress';
         if (!isset($app['security.authentication_provider.' . $name . '.' . $provider])) {
             $app['security.authentication_provider.' . $name . '.' . $provider] = $app['security.authentication_provider.' . $type . '._proto']($name);
         }
         return array('security.authentication_provider.' . $name . '.' . $provider, 'security.authentication_listener.' . $name . '.' . $type, $entryPoint ? 'security.entry_point.' . $name . '.' . $entryPoint : null, 'pre_auth');
     });
 }
开发者ID:bangpound,项目名称:wordpress-silex-extension,代码行数:33,代码来源:WordpressServiceProvider.php

示例8: 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(Application $app)
 {
     $app['security.jwt_retrieval.authorization_bearer.strategy'] = $app->share(function () {
         return new AuthorizationBearerStrategy();
     });
     $app['security.jwt_retrieval.query_parameter.strategy'] = $app->share(function () {
         return new QueryParameterStrategy();
     });
     $app['security.jwt_retrieval.chain.strategy'] = $app->share(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 $app->share(function () {
             return new JWTAuthenticationEntryPoint();
         });
     });
     $app['security.authentication_listener.factory.jwt'] = $app->protect(function ($name, $options) use($app) {
         $app['security.authentication_provider.' . $name . '.jwt'] = $app->share(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'] = $app->share(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:kurlzor,项目名称:jwt,代码行数:38,代码来源:SecurityJWTServiceProvider.php

示例9: register

 public function register(Application $app)
 {
     $app['app.usuarios.insert'] = $app->protect(function ($data) {
         return $this->insert($data);
     });
     $app['app.usuarios.find'] = $app->protect(function ($data) {
         return $this->find($data);
     });
 }
开发者ID:frnks,项目名称:AutenticationSilexJWT,代码行数:9,代码来源:AppUsuarios.php

示例10: register

 public function register(Application $app)
 {
     $app['logger.class'] = '\\Dafiti\\Silex\\Log\\Logger';
     $app['logger.create'] = $app->protect(function ($name, $level = 'debug', array $handlers = [], array $processors = []) use($app) {
         $logger = new $app['logger.class']($name);
         $level = $logger->translateLevel($level);
         if (empty($handlers)) {
             $stream = sprintf('%s/%s.log', $app['logger.log_folder'], $name);
             $handlers = [new StreamHandler($stream, $level, $app['logger.bubble'], $app['logger.permission'])];
         }
         foreach ($handlers as $handler) {
             $logger->pushHandler($handler);
         }
         foreach ($processors as $processor) {
             $logger->pushProcessor($processor);
         }
         $app['logger.manager']->add($logger);
         return $logger;
     });
     $app['logger.handler'] = $app->protect(new Factory\Handler());
     $app['logger.processor'] = $app->protect(new Factory\Processor());
     $app['logger.factory'] = $app->protect(function (array $loggers) use($app) {
         if (empty($loggers)) {
             throw new \InvalidArgumentException('Empty value is not allowed for loggers');
         }
         foreach ($loggers as $name => $values) {
             $level = 'debug';
             $handlers = [];
             $processors = [];
             if (isset($values['level'])) {
                 $level = $values['level'];
             }
             if (!isset($values['handlers'])) {
                 $values['handlers'] = [];
             }
             if (!isset($values['processors'])) {
                 $values['processors'] = [];
             }
             foreach ($values['handlers'] as $handler) {
                 if (!isset($handler['level'])) {
                     $handler['level'] = $level;
                 }
                 $handlers[] = $app['logger.handler']($handler);
             }
             foreach ($values['processors'] as $processor) {
                 $processors[] = $app['logger.processor']($processor);
             }
             $app['logger.create']($name, $level, $handlers, $processors);
         }
     });
     $app['logger.manager'] = $app->share(function () {
         return new Log\Collection();
     });
     $app['logger.bubble'] = true;
     $app['logger.permission'] = null;
     $app['logger.log_folder'] = null;
 }
开发者ID:dafiti,项目名称:logger-service-provider,代码行数:57,代码来源:LoggerServiceProvider.php

示例11: testWithLoader

 public function testWithLoader()
 {
     $this->app['env.loader'] = $this->app->protect(function () {
         return $_SERVER;
     });
     $this->app->register(new EnvironmentProvider());
     $this->app->boot();
     $this->assertEquals($_SERVER, $this->app['env']->getVars());
 }
开发者ID:stikmanw,项目名称:rest-event-framework,代码行数:9,代码来源:EnvironmentServiceProviderTest.php

示例12: register

 /**
  * (non-PHPdoc)
  * @see \Silex\ServiceProviderInterface::register()
  * @param Application $app
  */
 public function register(Application $app)
 {
     $service = $this;
     $app[static::GENERATE] = $app->protect(function (string $password) use($service) {
         return $service->generate($password, $this->config['cost']);
     });
     $app[static::VERIFY] = $app->protect(function (string $password, string $hash) use($service) {
         return $service->verify($password, $hash);
     });
 }
开发者ID:mrprompt,项目名称:silex-password,代码行数:15,代码来源:Password.php

示例13: register

 /**
  * (non-PHPdoc)
  * @see \Silex\ServiceProviderInterface::register()
  * @param Application $app
  */
 public function register(Application $app)
 {
     Driver::config($this->config);
     $service = $this;
     $app[static::UPLOADER] = $app->protect(function (UploadedFile $file) use($service) {
         return $service->createFromFile($file);
     });
     $app[static::IMPORTER] = $app->protect(function (string $url) use($service) {
         return $service->createFromUrl($url);
     });
 }
开发者ID:mrprompt,项目名称:silex-cloudinary,代码行数:16,代码来源:Cloudinary.php

示例14: register

 public function register(Application $app)
 {
     $app[self::AUTH_VALIDATE_CREDENTIALS] = $app->protect(function ($user, $pass) {
         return $this->validateCredentials($user, $pass);
     });
     $app[self::AUTH_VALIDATE_TOKEN] = $app->protect(function ($token) {
         return $this->validateToken($token);
     });
     $app[self::AUTH_NEW_TOKEN] = $app->protect(function ($user) {
         return $this->getNewTokenForUser($user);
     });
 }
开发者ID:dactivo,项目名称:token,代码行数:12,代码来源:LoginServiceProvider.php

示例15: register

 public function register(Application $app)
 {
     $app['asset.packages'] = $app->share(function ($app) {
         $defaultPackage = new Package($app['asset.version_strategy']('view'));
         $packages = new Packages($defaultPackage);
         $packages->addPackage('bolt', $app['asset.package_factory']('view'));
         $packages->addPackage('extensions', new PathPackage('', $app['asset.version_strategy']('web'), $app['asset.context']));
         $packages->addPackage('files', $app['asset.package_factory']('files'));
         $packages->addPackage('theme', $app['asset.package_factory']('theme'));
         return $packages;
     });
     $app['asset.package_factory'] = $app->protect(function ($name) use($app) {
         return new PathPackage($app['resources']->getUrl($name), $app['asset.version_strategy']($name), $app['asset.context']);
     });
     $app['asset.version_strategy'] = $app->protect(function ($name) use($app) {
         return new Asset\BoltVersionStrategy($app['filesystem']->getFilesystem($name), $app['asset.salt']);
     });
     $app['asset.context'] = $app->share(function () use($app) {
         return new RequestStackContext($app['request_stack']);
     });
     $app['asset.salt.factory'] = function () use($app) {
         return $app['randomgenerator']->generateString(10);
     };
     $app['asset.salt'] = $app->share(function ($app) {
         $file = $app['filesystem']->getFile('cache://.assetsalt');
         try {
             $salt = $file->read();
         } catch (FileNotFoundException $e) {
             $salt = $app['asset.salt.factory'];
             $file->put($salt);
         }
         return $salt;
     });
     $app['asset.injector'] = $app->share(function () {
         $snippets = new Asset\Injector();
         return $snippets;
     });
     $app['asset.queue.file'] = $app->share(function ($app) {
         $queue = new Asset\File\Queue($app['asset.injector'], $app['asset.packages']);
         return $queue;
     });
     $app['asset.queue.snippet'] = $app->share(function ($app) {
         $queue = new Asset\Snippet\Queue($app['asset.injector'], $app['cache'], $app['config'], $app['resources']);
         return $queue;
     });
     $app['asset.queue.widget'] = $app->share(function ($app) {
         $queue = new Asset\Widget\Queue($app['asset.injector'], $app['cache'], $app['render']);
         return $queue;
     });
     $app['asset.queues'] = $app->share(function ($app) {
         return [$app['asset.queue.file'], $app['asset.queue.snippet'], $app['asset.queue.widget']];
     });
 }
开发者ID:robbert-vdh,项目名称:bolt,代码行数:53,代码来源:AssetServiceProvider.php


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