本文整理汇总了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;
});
}
示例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);
});
}
}
示例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;
}
示例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);
});
}
示例5: setUp
/**
* Bootstrap
*/
public function setUp()
{
parent::setUp();
$app = new Application();
$app->register(new Password(self::DEFAULT_COST));
$this->app = $app;
}
示例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;
}
示例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;
}
示例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);
})]);
});
}
示例9: __construct
public function __construct(SilexApplication $application, $projectDirectory, $name = 'UNKNOWN', $version = 'UNKNOWN')
{
parent::__construct($name, $version);
$this->silexApplication = $application;
$this->projectDirectory = $projectDirectory;
$application->boot();
}
示例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]);
}
示例11: register
public function register(Application $app)
{
$app['log'] = $app->share(function ($app) {
$log = new Bolt\Log($app);
return $log;
});
}
示例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']);
});
}
}
示例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);
});
}
示例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;
}));
}
}
示例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