本文整理汇总了PHP中Alchemy\Phrasea\Application::share方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::share方法的具体用法?PHP Application::share怎么用?PHP Application::share使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alchemy\Phrasea\Application
的用法示例。
在下文中一共展示了Application::share方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_QUIET) {
switch ($output->getVerbosity()) {
default:
case OutputInterface::VERBOSITY_NORMAL:
$level = Logger::WARNING;
break;
case OutputInterface::VERBOSITY_VERBOSE:
$level = Logger::NOTICE;
break;
case OutputInterface::VERBOSITY_VERY_VERBOSE:
$level = Logger::INFO;
break;
case OutputInterface::VERBOSITY_DEBUG:
$level = Logger::DEBUG;
break;
}
$handler = new StreamHandler('php://stdout', $level);
$this->container['monolog'] = $this->container->share($this->container->extend('monolog', function ($logger) use($handler) {
$logger->pushHandler($handler);
return $logger;
}));
$this->container['task-manager.logger'] = $this->container->share($this->container->extend('task-manager.logger', function ($logger) use($handler) {
$logger->pushHandler($handler);
return $logger;
}));
}
return $this->doExecute($input, $output);
}
示例2: testInstall
public function testInstall()
{
$app = new Application(Application::ENV_TEST);
\phrasea::reset_sbasDatas($app['phraseanet.appbox']);
\phrasea::reset_baseDatas($app['phraseanet.appbox']);
$app->bindRoutes();
$parser = new Parser();
$config = $parser->parse(file_get_contents(__DIR__ . '/../../../../../config/configuration.yml'));
$credentials = $config['main']['database'];
$configFile = __DIR__ . '/configuration.yml';
$compiledFile = __DIR__ . '/configuration.yml.php';
@unlink($configFile);
@unlink($compiledFile);
$app['configuration.store'] = $app->share(function () use($configFile, $compiledFile) {
return new Configuration(new Yaml(), new Compiler(), $configFile, $compiledFile, true);
});
$app['conf'] = $app->share(function () use($app) {
return new PropertyAccess($app['configuration.store']);
});
$app['phraseanet.appbox'] = $app->share(function () use($app) {
return new \appbox($app);
});
$abInfo = ['host' => $credentials['host'], 'port' => $credentials['port'], 'user' => $credentials['user'], 'password' => $credentials['password'], 'dbname' => 'ab_setup_test'];
$abConn = $app['dbal.provider']($abInfo);
$dbConn = $app['dbal.provider'](['host' => $credentials['host'], 'port' => $credentials['port'], 'user' => $credentials['user'], 'password' => $credentials['password'], 'dbname' => 'db_setup_test']);
$key = $app['orm.add']($abInfo);
$app['orm.ems.default'] = $key;
$dataPath = __DIR__ . '/../../../../../datas/';
$installer = new Installer($app);
$installer->install(uniqid('admin') . '@example.com', 'sdfsdsd', $abConn, 'http://local.phrasea.test.installer/', $dataPath, $dbConn, 'en');
$this->assertTrue($app['configuration.store']->isSetup());
$this->assertTrue($app['phraseanet.configuration-tester']->isUpToDate());
$databox = current($app->getDataboxes());
$this->assertContains('<path>' . realpath($dataPath) . '/db_setup_test/subdefs</path>', $databox->get_structure());
$conf = $app['configuration.store']->getConfig();
$this->assertArrayHasKey('main', $conf);
$this->assertArrayHasKey('key', $conf['main']);
$this->assertGreaterThan(10, strlen($conf['main']['key']));
@unlink($configFile);
@unlink($compiledFile);
$app['connection.pool.manager']->closeAll();
}
示例3: call_user_func
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Controller\Api\Oauth2;
use Alchemy\Phrasea\Controller\Api\V1;
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent;
use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request;
return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment);
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) {
return new ApiExceptionHandlerSubscriber($app);
});
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
$monolog->pushProcessor(new WebProcessor());
return $monolog;
}));
$app->register(new \API_V1_Timer());
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_START, new ApiLoadStartEvent());
$app->get('/api/', function (Request $request, SilexApplication $app) {
$apiAdapter = new \API_V1_adapter($app);
$result = new \API_V1_result($app, $request, $apiAdapter);
return $result->set_datas(['name' => $app['conf']->get(['registry', 'general', 'title']), 'type' => 'phraseanet', 'description' => $app['conf']->get(['registry', 'general', 'description']), 'documentation' => 'https://docs.phraseanet.com/Devel', 'versions' => ['1' => ['number' => $apiAdapter->get_version(), 'uri' => '/api/v1/', 'authenticationProtocol' => 'OAuth2', 'authenticationVersion' => 'draft#v9', 'authenticationEndPoints' => ['authorization_token' => '/api/oauthv2/authorize', 'access_token' => '/api/oauthv2/token']]]])->get_response();
});
$app->mount('/api/oauthv2', new Oauth2());
$app->mount('/api/v1', new V1());
$app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber($app['phraseanet.exception_handler'], $app['translator']));
示例4: addMocks
protected function addMocks(Application $app)
{
$app['debug'] = true;
$app['form.csrf_provider'] = $app->share(function () {
return new CsrfTestProvider();
});
$app['url_generator'] = $app->share($app->extend('url_generator', function ($generator, $app) {
$host = parse_url($app['conf']->get('servername'), PHP_URL_HOST);
$generator->setContext(new RequestContext('', 'GET', $host));
return $generator;
}));
$app['translator'] = $this->createTranslatorMock();
$app['phraseanet.SE.subscriber'] = $this->getMock('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface');
$app['phraseanet.SE.subscriber']::staticExpects($this->any())->method('getSubscribedEvents')->will($this->returnValue([]));
$app['EM'] = $app->share($app->extend('EM', function ($em) {
$this->initializeSqliteDB();
return $em;
}));
$app['browser'] = $app->share($app->extend('browser', function ($browser) {
$browser->setUserAgent(self::USER_AGENT_FIREFOX8MAC);
return $browser;
}));
$app['notification.deliverer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Notification\\Deliverer')->disableOriginalConstructor()->getMock();
$app['notification.deliverer']->expects($this->any())->method('deliver')->will($this->returnCallback(function () {
$this->fail('Notification deliverer must be mocked');
}));
}
示例5: call_user_func
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaExceptionHandlerSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\BridgeExceptionSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\FirewallSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\JsonRequestSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\DebuggerSubscriber;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Silex\Provider\WebProfilerServiceProvider;
use Sorien\Provider\DoctrineProfilerServiceProvider;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment);
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) {
return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']);
});
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
$monolog->pushProcessor(new WebProcessor());
return $monolog;
}));
$app->before(function (Request $request) use($app) {
if (0 === strpos($request->getPathInfo(), '/setup')) {
if (!$app['phraseanet.configuration-tester']->isInstalled()) {
if (!$app['phraseanet.configuration-tester']->isBlank()) {
if ('setup_upgrade_instructions' !== $app['request']->attributes->get('_route')) {
return $app->redirectPath('setup_upgrade_instructions');
}
}
} elseif (!$app['phraseanet.configuration-tester']->isBlank()) {
return $app->redirectPath('homepage');
示例6: call_user_func
use Alchemy\Phrasea\Controller\Api\Oauth2;
use Alchemy\Phrasea\Controller\Api\Result;
use Alchemy\Phrasea\Controller\Api\V1;
use Alchemy\Phrasea\Core\Event\ApiResultEvent;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment);
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) {
return new ApiExceptionHandlerSubscriber($app);
});
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
$monolog->pushProcessor(new WebProcessor());
return $monolog;
}));
// handle API content negotiation
$app->before(function (Request $request) use($app) {
// register custom API format
$request->setFormat(Result::FORMAT_JSON_EXTENDED, V1::$extendedContentTypes['json']);
$request->setFormat(Result::FORMAT_YAML_EXTENDED, V1::$extendedContentTypes['yaml']);
$request->setFormat(Result::FORMAT_JSONP_EXTENDED, V1::$extendedContentTypes['jsonp']);
$request->setFormat(Result::FORMAT_JSONP, array('text/javascript', 'application/javascript'));
// handle content negociation
$priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript');
foreach (V1::$extendedContentTypes['json'] as $priorities[]) {
示例7: setupApplicationPaths
private function setupApplicationPaths(Application $app)
{
// app root path
$this['root.path'] = realpath(__DIR__ . '/../../..');
// temporary resources default path such as download zip, quarantined documents etc ..
$this['tmp.path'] = $this['root.path'] . '/tmp';
// cache path for dev env
$this['cache.dev.path'] = $app->share(function () use($app) {
$path = sys_get_temp_dir() . '/' . md5($app['root.path']);
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
// cache path (twig, minify, translations, configuration, doctrine metas serializer metas, profiler etc ...)
$this['cache.path'] = $app->share(function () use($app) {
// if ($app->getEnvironment() !== Application::ENV_PROD) {
// return $this['cache.dev.path'];
// }
$path = $app['root.path'] . '/cache';
if ($app['phraseanet.configuration']->isSetup()) {
$path = $app['conf']->get(['main', 'storage', 'cache'], $path);
}
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
$app['cache.paths'] = $app->share(function () use($app) {
return array(self::ENV_DEV => $this['cache.path'], self::ENV_TEST => $this['cache.path'], self::ENV_PROD => $this['cache.path']);
});
// log path
$this['log.path'] = $app->share(function () use($app) {
$path = $this['root.path'] . '/logs';
if ($app['phraseanet.configuration']->isSetup()) {
return $app['conf']->get(['main', 'storage', 'log'], $path);
}
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
// temporary download file path (zip file)
$this['tmp.download.path'] = $app->share(function () use($app) {
$path = $this['tmp.path'] . '/download';
if ($app['phraseanet.configuration']->isSetup()) {
return $app['conf']->get(['main', 'storage', 'download'], $path);
}
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
// quarantined file path
$this['tmp.lazaret.path'] = $app->share(function () use($app) {
$path = $this['tmp.path'] . '/lazaret';
if ($app['phraseanet.configuration']->isSetup()) {
return $app['conf']->get(['main', 'storage', 'quarantine'], $path);
}
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
// document caption file path
$this['tmp.caption.path'] = $app->share(function () use($app) {
$path = $this['tmp.path'] . '/caption';
if ($app['phraseanet.configuration']->isSetup()) {
return $app['conf']->get(['main', 'storage', 'caption'], $path);
}
// ensure path is created
$app['filesystem']->mkdir($path);
return $path;
});
}
示例8: addMocks
protected function addMocks(Application $app)
{
$app['debug'] = true;
$app['form.csrf_provider'] = $app->share(function () {
return new CsrfTestProvider();
});
$app['url_generator'] = $app->share($app->extend('url_generator', function ($generator, $app) {
$host = parse_url($app['conf']->get('servername'), PHP_URL_HOST);
$generator->setContext(new RequestContext('', 'GET', $host ?: $app['conf']->get('servername')));
return $generator;
}));
$app['task-manager.notifier'] = $app->share($app->extend('task-manager.notifier', function (Notifier $notifier) {
$notifier->setTimeout(0.0001);
return $notifier;
}));
$app['translator'] = $this->createTranslatorMock();
$app['phraseanet.SE.subscriber'] = new PhraseanetSeTestSubscriber();
$app['orm.em'] = $app->extend('orm.em', function ($em, $app) {
return $app['orm.ems'][$app['db.test.hash.key']];
});
$app['browser'] = $app->share($app->extend('browser', function ($browser) {
$browser->setUserAgent(self::USER_AGENT_FIREFOX8MAC);
return $browser;
}));
$app['notification.deliverer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Notification\\Deliverer')->disableOriginalConstructor()->getMock();
$app['notification.deliverer']->expects($this->any())->method('deliver')->will($this->returnCallback(function () {
$this->fail('Notification deliverer must be mocked');
}));
}
示例9: call_user_func
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Silex\Application as SilexApplication;
use Silex\Provider\WebProfilerServiceProvider;
use Sorien\Provider\DoctrineProfilerServiceProvider;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment);
$app->register(new OAuth2());
$app->register(new V1());
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) {
$handler = new ApiExceptionHandlerSubscriber($app);
$handler->setLogger($app['monolog']);
return $handler;
});
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
$monolog->pushProcessor(new WebProcessor());
return $monolog;
}));
$app['phraseanet.content-negotiation.priorities'] = array_merge(V1::$extendedContentTypes['json'], V1::$extendedContentTypes['jsonp'], V1::$extendedContentTypes['yaml'], ['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript']);
$app['phraseanet.content-negotiation.custom_formats'] = [Result::FORMAT_JSON_EXTENDED => V1::$extendedContentTypes['json'], Result::FORMAT_YAML_EXTENDED => V1::$extendedContentTypes['yaml'], Result::FORMAT_JSONP_EXTENDED => V1::$extendedContentTypes['jsonp'], Result::FORMAT_JSONP => ['text/javascript', 'application/javascript']];
// handle API content negotiation
$app->before(function (Request $request) {
// set request format according to negotiated content or override format with JSONP if callback parameter is defined
if (trim($request->get('callback')) !== '') {
$request->setRequestFormat(Result::FORMAT_JSONP);
}
// tells whether asked format is extended or not