本文整理汇总了PHP中Silex\Application::share方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::share方法的具体用法?PHP Application::share怎么用?PHP Application::share使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::share方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app['ffmpeg.configuration'] = array();
$app['ffmpeg.default.configuration'] = array('ffmpeg.threads' => 4, 'ffmpeg.timeout' => 300, 'ffmpeg.binaries' => array('avconv', 'ffmpeg'), 'ffprobe.timeout' => 30, 'ffprobe.binaries' => array('avprobe', 'ffprobe'));
$app['ffmpeg.logger'] = null;
$app['ffmpeg.configuration.build'] = $app->share(function (Application $app) {
return array_replace($app['ffmpeg.default.configuration'], $app['ffmpeg.configuration']);
});
$app['ffmpeg'] = $app['ffmpeg.ffmpeg'] = $app->share(function (Application $app) {
$configuration = $app['ffmpeg.configuration.build'];
if (isset($configuration['ffmpeg.timeout'])) {
$configuration['timeout'] = $configuration['ffmpeg.timeout'];
}
return FFMpeg::create($configuration, $app['ffmpeg.logger'], $app['ffmpeg.ffprobe']);
});
$app['ffprobe.cache'] = $app->share(function () {
return new ArrayCache();
});
$app['ffmpeg.ffprobe'] = $app->share(function (Application $app) {
$configuration = $app['ffmpeg.configuration.build'];
if (isset($configuration['ffmpeg.timeout'])) {
$configuration['timeout'] = $configuration['ffprobe.timeout'];
}
return FFProbe::create($configuration, $app['ffmpeg.logger'], $app['ffprobe.cache']);
});
}
示例2: 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'));
});
}
示例3: connect
/**
* Returns routes to connect to the given application.
*
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app)
{
$app['role_controller'] = $app->share(function (Application $app) {
return new ReadRoleRestController($app['role_service'], $app['role_reading_service'], $app['current_user'], $app['config']['user_permissions'], $app['role_search_repository'], $app[UserPermissionsServiceProvider::USER_PERMISSIONS_READ_REPOSITORY]);
});
$app['role_edit_controller'] = $app->share(function (Application $app) {
return new EditRoleRestController($app['role_editing_service'], $app['event_command_bus'], new UpdateRoleRequestDeserializer(), $app[LabelServiceProvider::READ_SERVICE]);
});
/** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
$controllers->get('/roles/', 'role_controller:search');
$controllers->post('/roles/', 'role_edit_controller:create');
$controllers->get('/roles/{id}', 'role_controller:get')->bind('role');
$controllers->patch('/roles/{id}', 'role_edit_controller:update');
$controllers->delete('/roles/{id}', 'role_edit_controller:delete');
$controllers->get('/permissions/', 'role_controller:getPermissions');
$controllers->get('/user/permissions/', 'role_controller:getUserPermissions');
$controllers->get('/roles/{roleId}/users/', 'role_controller:getRoleUsers');
$controllers->put('/roles/{roleId}/permissions/{permissionKey}', 'role_edit_controller:addPermission');
$controllers->delete('/roles/{roleId}/permissions/{permissionKey}', 'role_edit_controller:removePermission');
$controllers->get('/roles/{roleId}/labels/', 'role_controller:getRoleLabels');
$controllers->put('/roles/{roleId}/labels/{labelIdentifier}', 'role_edit_controller:addLabel');
$controllers->delete('/roles/{roleId}/labels/{labelIdentifier}', 'role_edit_controller:removeLabel');
$controllers->put('/roles/{roleId}/users/{userId}', 'role_edit_controller:addUser');
$controllers->delete('/roles/{roleId}/users/{userId}', 'role_edit_controller:removeUser');
$controllers->get('/users/{userId}/roles/', 'role_controller:getUserRoles');
$controllers->get('/user/roles/', 'role_controller:getCurrentUserRoles');
return $controllers;
}
示例4: 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;
}
示例5: 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;
}
示例6: register
public function register(Application $app)
{
$app['logger'] = function () use($app) {
return $app['monolog'];
};
if ($bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger')) {
$app['monolog.handler.debug'] = function () use($app) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);
return new DebugHandler($level);
};
}
$app['monolog.logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger';
$app['monolog'] = $app->share(function ($app) {
$log = new $app['monolog.logger.class']($app['monolog.name']);
$log->pushHandler($app['monolog.handler']);
if ($app['debug'] && isset($app['monolog.handler.debug'])) {
$log->pushHandler($app['monolog.handler.debug']);
}
return $log;
});
$app['monolog.handler'] = function () use($app) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);
return new StreamHandler($app['monolog.logfile'], $level, $app['monolog.bubble'], $app['monolog.permission']);
};
$app['monolog.level'] = function () {
return Logger::DEBUG;
};
$app['monolog.listener'] = $app->share(function () use($app) {
return new LogListener($app['logger']);
});
$app['monolog.name'] = 'myapp';
$app['monolog.bubble'] = true;
$app['monolog.permission'] = null;
}
示例7: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['email.support'] = 'noreply@silex.nothing';
$app['logger.message_generator'] = function () use($app) {
$message = \Swift_Message::newInstance();
$message->setSubject('Error report from ' . $_SERVER['HTTP_HOST'])->setFrom($app['email.support'])->setTo($app['email.support']);
return $message;
};
$app['logger.swift_mailer_handler'] = $app->share(function ($app) {
$handler = new SwiftMailerHandler($app['mailer'], $app['logger.message_generator'], Logger::DEBUG);
$handler->setTransport($app['swiftmailer.transport']);
return $handler;
});
if (!$app['debug']) {
if ($this->send_emails) {
$app['monolog'] = $app->share($app->extend('monolog', function ($monolog, $app) {
/** @var $monolog Logger */
$bufferHander = new BufferHandler($app['logger.swift_mailer_handler']);
$fingersCrossedHandler = new FingersCrossedHandler($bufferHander, Logger::ERROR, 200);
$monolog->pushHandler($fingersCrossedHandler);
return $monolog;
}));
}
}
}
示例8: 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);
});
}
示例9: register
public function register(Application $app)
{
$app['nut'] = $app->share(function ($app) {
$console = new NutApplication();
$console->setName('Bolt console tool - Nut');
if ($app instanceof \Bolt\Application) {
$console->setVersion($app->getVersion());
}
$console->addCommands($app['nut.commands']);
return $console;
});
$app['nut.commands'] = $app->share(function ($app) {
return [new Nut\CronRunner($app), new Nut\CacheClear($app), new Nut\Info($app), new Nut\LogTrim($app), new Nut\LogClear($app), new Nut\DatabaseCheck($app), new Nut\DatabaseExport($app), new Nut\DatabaseImport($app), new Nut\DatabasePrefill($app), new Nut\DatabaseRepair($app), new Nut\TestRunner($app), new Nut\ConfigGet($app), new Nut\ConfigSet($app), new Nut\Extensions($app), new Nut\ExtensionsEnable($app), new Nut\ExtensionsDisable($app), new Nut\UserAdd($app), new Nut\UserResetPassword($app), new Nut\UserRoleAdd($app), new Nut\UserRoleRemove($app)];
});
$app['nut.commands.add'] = $app->protect(function (Command $command) use($app) {
$app['nut.commands'] = $app->share($app->extend('nut.commands', function ($commands) use($command) {
$commands[] = $command;
return $commands;
}));
});
// Maintain backwards compatibility
$app['console'] = $app->share(function ($app) {
return $app['nut'];
});
}
示例10: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['application.speakers'] = $app->share(function ($app) {
$userMapper = $app['spot']->mapper('OpenCFP\\Domain\\Entity\\User');
$talkMapper = $app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
$speakerRepository = new SpotSpeakerRepository($userMapper);
return new Speakers(new CallForProposal(new \DateTime($app->config('application.enddate'))), new SentryIdentityProvider($app['sentry'], $speakerRepository), $speakerRepository, new SpotTalkRepository($talkMapper), new EventDispatcher());
});
$app['security.random'] = $app->share(function ($app) {
return new PseudoRandomStringGenerator(new Factory());
});
$app['oauth.resource'] = $app->share(function ($app) {
$sessionStorage = new SessionStorage();
$accessTokenStorage = new AccessTokenStorage();
$clientStorage = new ClientStorage();
$scopeStorage = new ScopeStorage();
$server = new ResourceServer($sessionStorage, $accessTokenStorage, $clientStorage, $scopeStorage);
return $server;
});
$app['application.speakers.api'] = $app->share(function ($app) {
$userMapper = $app['spot']->mapper('OpenCFP\\Domain\\Entity\\User');
$talkMapper = $app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
$speakerRepository = new SpotSpeakerRepository($userMapper);
return new Speakers(new CallForProposal(new \DateTime($app->config('application.enddate'))), new OAuthIdentityProvider($app['oauth.resource'], $speakerRepository), $speakerRepository, new SpotTalkRepository($talkMapper), new EventDispatcher());
});
}
示例11: register
/**
* @inheritdoc
*/
public function register(Application $app)
{
$app['saved_searches_service_factory'] = $app->share(function ($app) {
$consumer = new Consumer($app['config']['uitid']['base_url'], $app['culturefeed_consumer_credentials']);
return new SavedSearchesServiceFactory($consumer);
});
$app['saved_searches'] = $app->share(function (Application $app) {
/* @var \CultuurNet\UDB3\SavedSearches\SavedSearchesServiceFactory $serviceFactory */
$serviceFactory = $app['saved_searches_service_factory'];
$tokenCredentials = $app['culturefeed_token_credentials'];
return $serviceFactory->withTokenCredentials($tokenCredentials);
});
$app['saved_searches_logger'] = $app->share(function (Application $app) {
$logger = new \Monolog\Logger('saved_searches');
$logger->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__ . '/../../log/saved_searches.log'));
return $logger;
});
$app['saved_searches_repository'] = $app->share(function (Application $app) {
$uitIDRepository = new UiTIDSavedSearchRepository($app['saved_searches']);
$uitIDRepository->setLogger($app['saved_searches_logger']);
$user = $app['current_user'];
$fixedRepository = new FixedSavedSearchRepository($user);
$repository = new CombinedSavedSearchRepository($fixedRepository, $uitIDRepository);
return $repository;
});
}
示例12: connect
/**
* @inheritdoc
*/
public function connect(Application $app)
{
$app['event_controller'] = $app->share(function (Application $app) {
return new ReadEventRestController($app['event_service'], $app['event_history_repository']);
});
$app['event_editing_controller'] = $app->share(function (Application $app) {
return new EditEventRestController($app['event_service'], $app['event_editor'], $app['used_labels_memory'], $app['current_user'], $app['media_manager'], $app['event_iri_generator'], $app['offer.security']);
});
/* @var ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
$controllers->get('event/{cdbid}', 'event_controller:get')->bind('event');
$controllers->delete('event/{cdbid}', 'event_editing_controller:deleteEvent');
$controllers->get('event/{cdbid}/history', 'event_controller:history')->bind('event-history');
$controllers->post('event', "event_editing_controller:createEvent");
$controllers->get('event/{cdbid}/permission', 'event_editing_controller:hasPermission');
$controllers->post('event/{itemId}/images', 'event_editing_controller:addImage');
$controllers->post('event/{itemId}/images/main', 'event_editing_controller:selectMainImage');
$controllers->post('event/{itemId}/images/{mediaObjectId}', 'event_editing_controller:updateImage');
$controllers->delete('event/{itemId}/images/{mediaObjectId}', 'event_editing_controller:removeImage');
$controllers->post('event/{cdbid}/nl/description', 'event_editing_controller:updateDescription');
$controllers->post('event/{cdbid}/typical-age-range', 'event_editing_controller:updateTypicalAgeRange');
$controllers->delete('event/{cdbid}/typical-age-range', 'event_editing_controller:deleteTypicalAgeRange');
$controllers->post('event/{cdbid}/major-info', 'event_editing_controller:updateMajorInfo');
$controllers->post('event/{cdbid}/bookingInfo', 'event_editing_controller:updateBookingInfo');
$controllers->post('event/{cdbid}/contactPoint', 'event_editing_controller:updateContactPoint');
$controllers->post('event/{cdbid}/organizer', 'event_editing_controller:updateOrganizer');
$controllers->delete('event/{cdbid}/organizer/{organizerId}', 'event_editing_controller:deleteOrganizer');
return $controllers;
}
示例13: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
if (!isset($app['thumbnails'])) {
$app->register(new Thumbs\ServiceProvider());
}
$app['thumbnails.filesystems'] = ['files', 'themebase'];
$app['thumbnails.filesystem_cache'] = $app->share(function ($app) {
if (!$app['filesystem']->hasFilesystem('web')) {
return null;
}
return $app['filesystem']->getFilesystem('web');
});
$app['thumbnails.cache'] = $app->share(function ($app) {
return $app['cache'];
});
$app['thumbnails.default_image'] = $app->share(function ($app) {
$finder = new Thumbs\Finder($app['filesystem'], ['app', 'themebase', 'files'], new Image());
return $finder->find($app['config']->get('general/thumbnails/notfound_image'));
});
$app['thumbnails.error_image'] = $app->share(function ($app) {
$finder = new Thumbs\Finder($app['filesystem'], ['app', 'themebase', 'files'], new Image());
return $finder->find($app['config']->get('general/thumbnails/error_image'));
});
$app['thumbnails.cache_time'] = $app['config']->get('general/thumbnails/browser_cache_time');
$app['thumbnails.limit_upscaling'] = !$app['config']->get('general/thumbnails/allow_upscale', false);
$app['thumbnails.save_files'] = $app['config']->get('general/thumbnails/save_files');
ImageResource::setNormalizeJpegOrientation($app['config']->get('general/thumbnails/exif_orientation', true));
ImageResource::setQuality($app['config']->get('general/thumbnails/quality', 80));
}
示例14: register
/**
* Registers this service on the given app
*
* @param Silex\Application $app Application instance
*
* @return void
*/
public function register(Application $app)
{
$app['rb'] = $app->share(function () use($app) {
$options = $app['rb.options'];
if ($namespace = isset($options['namespace']) ? $options['namespace'] : '') {
$this->setModelNamespace($namespace);
unset($options['namespace']);
}
$options = array_merge(array('dsn' => null, 'username' => null, 'password' => null, 'freeze' => false), $options);
$rb = new RedBean($options);
$logger = new Logger($app['logger']);
$db = $rb->getDatabaseAdapter()->getDatabase();
$db->setLogger($logger);
$db->setEnableLogging(true);
if (isset($app['redbean.helpers']) && isset($app['redbean.model.helpers'])) {
$modelHelper = new ModelHelper($app['redbean.helpers']);
$modelHelper->attachEventListeners($rb->getRedBean());
foreach ($app['redbean.model.helpers'] as $model => $options) {
$modelHelper->addModel($model, $options);
}
$app['redbean.model_helper'] = $app->share(function () use($modelHelper) {
return $modelHelper;
});
}
return $rb;
});
}
示例15: register
public function register(Application $app)
{
$app['cache.memcached'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\MemcachedCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
$cache = new MemcachedCache();
$cache->setMemcached($app['memcached']);
return $cache;
});
$app['cache.predis'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\PredisCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
return new PredisCache($app['predis.client']);
});
$app['cache.predis_serializer'] = $app->share(function () use($app) {
if (!class_exists('\\Doctrine\\Common\\Cache\\PredisCache')) {
throw new \Exception('You need to include doctrine/common in order to use the cache service');
}
return new SerializingPredisCache($app['predis.client']);
});
$app['cache'] = $app->share(function () use($app) {
if ($app->offsetExists('cache.default')) {
return $app[$app['cache.default']];
}
return $app['memcached'];
});
}