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


PHP Silex\Application类代码示例

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


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

示例1: register

 public function register(Application $app)
 {
     $app['stack'] = $app->share(function ($app) {
         $stack = new Stack($app);
         return $stack;
     });
 }
开发者ID:tesmen,项目名称:tesmen.co,代码行数:7,代码来源:StackServiceProvider.php

示例2: register

 /**
  * Automatically registers all service classes in $this->services array
  * {@inheritdoc}
  * @param Application|\Apitude\Core\Application $app
  */
 public function register(Application $app)
 {
     foreach ($this->services as $key => $class) {
         if (is_numeric($key)) {
             $key = $class;
         }
         $app[$key] = $app->share(function () use($class, $app) {
             $result = new $class();
             $app->initialize($result);
             return $result;
         });
     }
     if (!empty($this->doctrineEventSubscribers)) {
         $config = $app['config'];
         foreach ($this->doctrineEventSubscribers as $class) {
             $config['orm.subscribers'][] = $class;
         }
     }
     if (!empty($this->entityFolders)) {
         if (!isset($config)) {
             $config = $app['config'];
         }
         foreach ($this->entityFolders as $namespace => $path) {
             $config['orm.options']['orm.em.options']['mappings'][] = ['type' => 'annotation', 'namespace' => $namespace, 'path' => $path, 'use_simple_annotation_reader' => false];
         }
     }
     if (isset($config)) {
         $app['config'] = $config;
     }
     if (php_sapi_name() === 'cli' && !empty($this->commands)) {
         $app['base_commands'] = $app->extend('base_commands', function (array $commands) {
             return array_merge($commands, $this->commands);
         });
     }
 }
开发者ID:apitude,项目名称:apitude,代码行数:40,代码来源:AbstractServiceProvider.php

示例3: register

 public function register(Application $app)
 {
     $app['translator'] = $app->share(function ($app) {
         $translator = new Translator($app, $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
         // Handle deprecated 'locale_fallback'
         if (isset($app['locale_fallback'])) {
             $app['locale_fallbacks'] = (array) $app['locale_fallback'];
         }
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     });
     $app['translator.message_selector'] = $app->share(function () {
         return new MessageSelector();
     });
     $app['translator.domains'] = array();
     $app['locale_fallbacks'] = array('en');
     $app['translator.cache_dir'] = null;
 }
开发者ID:shomimn,项目名称:builder,代码行数:25,代码来源:TranslationServiceProvider.php

示例4: register

 /**
  * (non-PHPdoc)
  * @see \Silex\ServiceProviderInterface::register()
  * @param Application $app
  */
 public function register(Application $app)
 {
     $service = $this;
     $app[static::NAME] = $app->protect(function (string $url) use($service) {
         return $service->create($url);
     });
 }
开发者ID:mrprompt,项目名称:silex-soundcloud,代码行数:12,代码来源:SoundCloud.php

示例5: setUp

 /**
  * Bootstrap
  */
 public function setUp()
 {
     parent::setUp();
     $app = new Application();
     $app->register(new Password(self::DEFAULT_COST));
     $this->app = $app;
 }
开发者ID:mrprompt,项目名称:silex-password,代码行数:10,代码来源:PasswordTest.php

示例6: connect

 /**
  * Silex method that exposes routes to the app
  *
  * @param Silex\Application $app Application instance
  *
  * @return Silex\ControllerCollection Object encapsulating crafted routes
  */
 public function connect(Application $app)
 {
     $ctrl = $app['controllers_factory'];
     /**
      * Homepage
      */
     $ctrl->get('/', function () use($app) {
         $root = str_replace('index.php/', '', $app['url_generator']->generate('home'));
         if ($app['request']->getRequestURI() != $root) {
             return $app->redirect($root, Response::HTTP_MOVED_PERMANENTLY);
         }
         return $app['twig']->render('front/partials/home.twig');
     })->bind('home');
     /**
      * Admin root
      */
     $ctrl->get('/admin', function () use($app) {
         return $app->redirect($app['url_generator']->generate($app['config']['admin']['root']));
     });
     /**
      * robots.txt
      */
     $ctrl->get('/robots.txt', function () use($app) {
         $response = new Response('User-agent: *' . PHP_EOL . ($app['debug'] ? 'Disallow: /' : 'Sitemap: ' . $app['url_generator']->generate('home') . 'sitemap.xml'));
         $response->headers->set('Content-Type', 'text/plain');
         return $response;
     });
     return $ctrl;
 }
开发者ID:neemzy,项目名称:patchwork-core,代码行数:36,代码来源:FrontController.php

示例7: register

 public function register(Application $app)
 {
     $this->app = $app;
     $app['session.test'] = false;
     $app['session'] = $app->share(function ($app) {
         if (!isset($app['session.storage'])) {
             if ($app['session.test']) {
                 $app['session.storage'] = $app['session.storage.test'];
             } else {
                 $app['session.storage'] = $app['session.storage.native'];
             }
         }
         return new Session($app['session.storage']);
     });
     $app['session.storage.handler'] = $app->share(function ($app) {
         return new NativeFileSessionHandler($app['session.storage.save_path']);
     });
     $app['session.storage.native'] = $app->share(function ($app) {
         return new NativeSessionStorage($app['session.storage.options'], $app['session.storage.handler']);
     });
     $app['session.storage.test'] = $app->share(function () {
         return new MockFileSessionStorage();
     });
     $app['session.storage.options'] = array();
     $app['session.default_locale'] = 'en';
     $app['session.storage.save_path'] = null;
 }
开发者ID:willianmano,项目名称:minicurso_phpconference2016,代码行数:27,代码来源:SessionServiceProvider.php

示例8: register

 public function register(Application $app)
 {
     $app['schema'] = $app->share(function ($app) {
         return new Manager($app);
     });
     $app['schema.tables'] = $app->share(function (Application $app) {
         /** @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform */
         $platform = $app['db']->getDatabasePlatform();
         return new \Pimple(['authtoken' => $app->share(function () use($platform) {
             return new Table\AuthToken($platform);
         }), 'cron' => $app->share(function () use($platform) {
             return new Table\Cron($platform);
         }), 'log_change' => $app->share(function () use($platform) {
             return new Table\LogChange($platform);
         }), 'log_system' => $app->share(function () use($platform) {
             return new Table\LogSystem($platform);
         }), 'relations' => $app->share(function () use($platform) {
             return new Table\Relations($platform);
         }), 'taxonomy' => $app->share(function () use($platform) {
             return new Table\Taxonomy($platform);
         }), 'users' => $app->share(function () use($platform) {
             return new Table\Users($platform);
         })]);
     });
 }
开发者ID:jkaan,项目名称:timOnlineBolt,代码行数:25,代码来源:DatabaseSchemaProvider.php

示例9: __construct

 public function __construct(SilexApplication $application, $projectDirectory, $name = 'UNKNOWN', $version = 'UNKNOWN')
 {
     parent::__construct($name, $version);
     $this->silexApplication = $application;
     $this->projectDirectory = $projectDirectory;
     $application->boot();
 }
开发者ID:ygeneration666,项目名称:ec,代码行数:7,代码来源:Application.php

示例10: show

 /**
  * @param \Silex\Application $app
  * This function can return listing of node.
  */
 public function show(Application $app)
 {
     header("Content-Type: text/html; charset=UTF-8");
     $client = $app['elasticsearch'];
     $search = $_GET['recherche'];
     $params['index'] = 'elasticsearch_index_csoecsic_content';
     $params['type'] = 'content';
     $ret = $client->indices()->getMapping(array('index' => 'elasticsearch_index_csoecsic_content'));
     $params['body']['query']['match']['_all'] = $search;
     $result = $client->search($params);
     // If no result from node Elasticsearch.
     if ($result && $result['hits']['total'] === 0) {
         $app->abort(404, sprintf('Node %s does not exist.', $search));
     }
     // If result from node Elasticsearch.
     if ($result['hits']['total'] > 0) {
         $nodes = $result['hits']['hits'];
     } else {
         print 'no result for this search';
     }
     $output['title_doc'] = 'Le contenu le plus pertinent :' . $nodes[0]['_source']['title'] . '';
     $output['score'] = 'Le meilleurs résultat de la recherche est :' . $nodes[0]['_score'] . '';
     //return '<p>Le contenu le plus pertinent :' . $nodes[0]['_source']['title'] . '</p>' . '<p>Avec comme score :' . $nodes[0]['_score'] . '</p>';
     /*return $app->render('template/result.php', array('node' => reset($output)));*/
     return $app['twig']->render('index.html.twig', ['result' => $output]);
 }
开发者ID:Thomthomars,项目名称:es-solution,代码行数:30,代码来源:NodeController.php

示例11: register

 public function register(Application $app)
 {
     $app['log'] = $app->share(function ($app) {
         $log = new Bolt\Log($app);
         return $log;
     });
 }
开发者ID:robertkraig,项目名称:bolt,代码行数:7,代码来源:LogServiceProvider.php

示例12: 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 An Application instance
  */
 public function register(Application $app)
 {
     if (!isset($app['locales_allowed'])) {
         throw new \RuntimeException('No locales are specified in your config');
     }
     if (!isset($app['em'])) {
         throw new \RuntimeException('No entity manager has been settled');
     }
     if (!isset($app['ip2locale.ip2country_manager'])) {
         $app['ip2locale.ip2country_manager'] = $app->share(function () use($app) {
             return new IP2CountryManager($app['em']);
         });
     }
     if (isset($app['ip2locale.ip2country_manager_enabled'])) {
         $app['ip2locale.ip2country_manager']->setEnabled($app['ip2locale.ip2country_manager_enabled']);
     }
     if (isset($app['ip2locale.ipv6_enabled'])) {
         $app['ip2locale.ip2country_manager']->setIpv6Enabled($app['ip2locale.ipv6_enabled']);
     }
     if (!isset($app['ip2locale.language_detector'])) {
         $app['ip2locale.language_detector'] = $app->share(function () use($app) {
             return new LanguageDetector();
         });
     }
     if (isset($app['ip2locale.language_detector_enabled'])) {
         $app['ip2locale.language_detector']->setEnabled($app['ip2locale.language_detector_enabled']);
     }
     if (!isset($app['ip2locale.locator'])) {
         $app['ip2locale.locator'] = $app->share(function () use($app) {
             return new IPLocator($app['ip2locale.ip2country_manager'], $app['ip2locale.language_detector'], $app['locales_allowed']);
         });
     }
 }
开发者ID:selmanouni,项目名称:ip2locale,代码行数:41,代码来源:IP2LocaleProvider.php

示例13: register

 public function register(Application $app)
 {
     $app['task-manager.logger'] = $app->share(function (Application $app) {
         $logger = new $app['monolog.logger.class']('task-manager logger');
         $logger->pushHandler(new NullHandler());
         return $logger;
     });
     $app['task-manager'] = $app->share(function (Application $app) {
         $options = $app['task-manager.listener.options'];
         $manager = TaskManager::create($app['dispatcher'], $app['task-manager.logger'], $app['task-manager.task-list'], ['listener_protocol' => $options['protocol'], 'listener_host' => $options['host'], 'listener_port' => $options['port'], 'tick_period' => 1]);
         $manager->addSubscriber($app['ws.task-manager.broadcaster']);
         return $manager;
     });
     $app['task-manager.logger.configuration'] = $app->share(function (Application $app) {
         $conf = array_replace(['enabled' => true, 'level' => 'INFO', 'max-files' => 10], $app['conf']->get(['main', 'task-manager', 'logger'], []));
         $conf['level'] = defined('Monolog\\Logger::' . $conf['level']) ? constant('Monolog\\Logger::' . $conf['level']) : Logger::INFO;
         return $conf;
     });
     $app['task-manager.task-list'] = $app->share(function (Application $app) {
         $conf = $app['conf']->get(['registry', 'executables', 'php-conf-path']);
         $finder = new PhpExecutableFinder();
         $php = $finder->find();
         return new TaskList($app['EM']->getRepository('Phraseanet:Task'), $app['root.path'], $php, $conf);
     });
 }
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:25,代码来源:TaskManagerServiceProvider.php

示例14: register

 /**
  * Register
  *
  * @param Application $app [description]
  *
  * @return void
  */
 public function register(Application $app)
 {
     $app['nn.markdown'] = $app->share(function () {
         return new Markdown();
     });
     if (isset($app["twig"])) {
         $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig, Application $app) {
             $filterParse = new \Twig_SimpleFilter('markdown_parse', function ($text) use($app) {
                 return $app['nn.markdown']->parse($text);
             }, array('is_safe' => array('html')));
             $twig->addFilter($filterParse);
             $filterParseFile = new \Twig_SimpleFilter('markdown_parse_file', function ($filename) use($app) {
                 return $app['nn.markdown']->parseFile($filename);
             }, array('is_safe' => array('html')));
             $fucntionParseLastFile = new \Twig_SimpleFunction('markdown_parse_last_file', function () use($app) {
                 $content = "";
                 $finderLast = $app['nn.markdown']->getNLastFiles(1);
                 foreach ($finderLast as $file) {
                     $content = $file->getContents();
                 }
                 return $app['nn.markdown']->parse($content);
             }, array('is_safe' => array('html')));
             $twig->addFilter($filterParse);
             $twig->addFilter($filterParseFile);
             $twig->addFunction($fucntionParseLastFile);
             return $twig;
         }));
     }
 }
开发者ID:nachonerd,项目名称:silex-markdown-provider,代码行数:36,代码来源:Provider.php

示例15: checkRouteResponse

 protected function checkRouteResponse(Application $app, $path, $expectedContent, $method = 'get', $message = null)
 {
     $app->register(new ServiceControllerServiceProvider());
     $request = Request::create($path, $method);
     $response = $app->handle($request);
     $this->assertEquals($expectedContent, $response->getContent(), $message);
 }
开发者ID:syntropysoftware,项目名称:cryptoffice-frontend,代码行数:7,代码来源:ServiceControllerResolverRouterTest.php


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