本文整理汇总了PHP中Pimple::share方法的典型用法代码示例。如果您正苦于以下问题:PHP Pimple::share方法的具体用法?PHP Pimple::share怎么用?PHP Pimple::share使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple
的用法示例。
在下文中一共展示了Pimple::share方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDIContainer
/**
* @return a new DI container with prefilled values for the news app
*/
function createDIContainer()
{
$container = new \Pimple();
/**
* BASE
*/
$container['API'] = $container->share(function ($c) {
return new API('apptemplate_advanced');
});
$container['Security'] = $container->share(function ($c) {
return new Security($c['API']->getAppName());
});
$container['Request'] = $container->share(function ($c) {
return new Request($_GET, $_POST, $_FILES);
});
/**
* CONTROLLERS
*/
$container['ItemController'] = function ($c) {
return new ItemController($c['API'], $c['Request'], $c['ItemMapper']);
};
$container['SettingsController'] = function ($c) {
return new SettingsController($c['API'], $c['Request']);
};
/**
* MAPPERS
*/
$container['ItemMapper'] = $container->share(function ($c) {
return new ItemMapper($c['API']);
});
return $container;
}
示例2: createDIContainer
/**
* @return a new DI container with prefilled values for the news app
*/
function createDIContainer()
{
$container = new \Pimple();
/**
* BASE
*/
$container['API'] = $container->share(function ($c) {
return new API('apptemplate');
});
$container['Security'] = $container->share(function ($c) {
return new Security($c['API']->getAppName());
});
$container['Request'] = $container->share(function ($c) {
return new Request($c['API']->getUserId(), $_GET, $_POST);
});
/**
* CONTROLLERS
*/
$container['IndexController'] = function ($c) {
return new IndexController($c['API'], $c['Request']);
};
$container['SettingsController'] = function ($c) {
return new SettingsController($c['API'], $c['Request']);
};
$container['AjaxController'] = function ($c) {
return new AjaxController($c['API'], $c['Request']);
};
return $container;
}
示例3: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$mainContainer['core']['db'] = $mainContainer->share(function () {
return \Pelican_Db::getInstance();
});
$mainContainer['core']['listener.ajax_response_render'] = $mainContainer->share(function () {
return new AjaxRenderResponseListener(new \Pelican_Ajax_Adapter_Jquery());
});
}
示例4: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$container = new \Pimple();
$container['profiler'] = $mainContainer->share(function ($container) use($mainContainer) {
$profiler = new Profiler(new FileStorage($mainContainer['config']->get('profiler_path')));
$profiler->addCollector($container['collector.cache']);
$profiler->addCollector($container['collector.database']);
return $profiler;
});
$container['session_storage'] = $mainContainer->share(function () use($mainContainer) {
return new SessionStorage($mainContainer['session']);
});
$container['profiler_manager'] = $mainContainer->share(function ($container) {
return new ProfilerManager($container['profiler']);
});
$container['collector.cache'] = $mainContainer->share(function () {
return new CacheDataCollector();
});
$container['collector.listener'] = $mainContainer->share(function () use($mainContainer) {
return new ListenerDataCollector($mainContainer['core']['dispatcher']);
});
$container['collector.database'] = $mainContainer->share(function () {
return new DatabaseDataCollector();
});
$container['collector.xhprof'] = $mainContainer->share(function () {
return new XhprofDataCollector();
});
$container['listener'] = $mainContainer->share(function ($container) {
return new ProfilerListener($container['profiler']);
});
$container['template_finder'] = $mainContainer->share(function () {
return new Finder();
});
$mainContainer['profiler'] = $container;
}
示例5: register
public function register(\Pimple $pimple)
{
$pimple['db.connection'] = $pimple->share(function () {
$databaseConnector = new DatabaseConnectorService();
return $databaseConnector->getConnection();
});
$pimple['repository'] = $pimple->share(function () {
return new RepositoryService();
});
$pimple['api.auth'] = $pimple->share(function ($pimple) {
$basicAuthenticationService = new BasicAuthenticationService();
$basicAuthenticationService->setPasswordService($pimple['password']);
return $basicAuthenticationService;
});
$pimple['password'] = $pimple->share(function () {
return new PasswordService();
});
$pimple['dispatcher'] = $pimple->share(function () {
return new EventDispatcher();
});
$pimple['logger'] = $pimple->share(function () {
$logger = new Logger('ubirimi.activity');
$IntrospectionProcessor = new IntrospectionProcessor();
$webProcessor = new WebProcessor();
$logger->pushHandler(new StreamHandler(UbirimiContainer::get()['log.path'], Logger::DEBUG));
$logger->pushHandler(new \DbMonologHandler(), Logger::DEBUG);
$logger->pushProcessor($IntrospectionProcessor);
$logger->pushProcessor($webProcessor);
return $logger;
});
$pimple['email'] = $pimple->share(function ($pimple) {
return new EmailService($pimple['session']);
});
$pimple['client'] = $pimple->share(function ($pimple) {
return new ClientService();
});
$pimple['user'] = $pimple->share(function ($pimple) {
return new UserService($pimple['session']);
});
$pimple['login.time'] = $pimple->share(function ($pimple) {
return new LoginTimeService();
});
$pimple['session'] = $pimple->share(function () {
$lastDot = strrpos($_SERVER['SERVER_NAME'], '.');
$secondToLastDot = strrpos($_SERVER['SERVER_NAME'], '.', $lastDot - strlen($_SERVER['SERVER_NAME']) - 1);
$storage = new NativeSessionStorage(array('cookie_domain' => substr($_SERVER['SERVER_NAME'], $secondToLastDot)), new NativeFileSessionHandler());
return new Session($storage, new NamespacedAttributeBag(), new AutoExpireFlashBag());
});
$pimple['warmup'] = $pimple->share(function ($pimple) {
return new WarmUpService($pimple['session']);
});
$pimple['savant'] = $pimple->share(function () {
return new \Savant3(array('template_path' => array(__DIR__ . '/../Yongo/Resources/views/email/', __DIR__ . '/../GeneralSettings/Resources/views/email/', __DIR__ . '/../Calendar/Resources/views/email/', __DIR__ . '/../SvnHosting/Resources/views/email/', __DIR__ . '/../Resources/views/email')));
});
}
示例6: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $container An Container instance
*/
public function register(\Pimple $container)
{
$services = new \Pimple();
$services['factory'] = $container->share(function () use($container) {
return new \Itkg\Core\Cache\Factory($container['cache']['adapters']);
});
$services['listener'] = $container->share(function () use($services, $container) {
return new CacheListener($services['factory']->create($container['config']['cache']['adapter'], $container['config']['cache']), $container['core']['dispatcher']);
});
$container['cache'] = $services;
}
示例7: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$mainContainer['router'] = $mainContainer->share(function () {
return new Router();
});
$mainContainer['request_matcher'] = $mainContainer->share(function ($mainContainer) {
return new RequestMatcher($mainContainer['router']);
});
// listeners
$mainContainer['listener.request_matcher'] = $mainContainer->share(function ($mainContainer) {
return new RequestMatcherListener($mainContainer['request_matcher']);
});
$mainContainer['dispatcher']->addSubscriber($mainContainer['listener.request_matcher']);
}
示例8: register
public function register(\Pimple $pimple)
{
$pimple['issue'] = $pimple->share(function ($pimple) {
return new IssueService($pimple['session']);
});
$pimple['issue.email'] = $pimple->share(function ($pimple) {
return new IssueEmailService($pimple['session'], $pimple['workflow']);
});
$pimple['workflow'] = $pimple->share(function ($pimple) {
return new WorkflowService($pimple['session']);
});
$pimple['project'] = $pimple->share(function ($pimple) {
return new ProjectService($pimple['session']);
});
}
示例9: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer An Container instance
*/
public function register(\Pimple $mainContainer)
{
$mainContainer['listener.response_exception'] = $mainContainer->share(function () {
return new ResponseExceptionListener();
});
$mainContainer['listener.processor_response_render'] = $mainContainer->share(function () {
return new ResponsePostRendererListener();
});
// Response Processors
$mainContainer['response.processor.compress'] = $mainContainer->share(function () {
return new CompressProcessor();
});
$dispatcher = $mainContainer['dispatcher'];
$dispatcher->addSubscriber($mainContainer['listener.response_exception']);
$dispatcher->addSubscriber($mainContainer['listener.processor_response_render']);
}
示例10: register
public function register(\Pimple $container)
{
$container['logger'] = function () use($container) {
return $container['monolog'];
};
if ($bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger')) {
$container['monolog.handler.debug'] = function () use($container) {
return new DebugHandler($container['monolog.level']);
};
}
$container['monolog.logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger';
$container['monolog'] = $container->share(function ($container) {
$log = new $container['monolog.logger.class']($container['monolog.name']);
$log->pushHandler($container['monolog.handler']);
if ($container['debug'] && isset($container['monolog.handler.debug'])) {
$log->pushHandler($container['monolog.handler.debug']);
}
return $log;
});
$container['monolog.handler'] = function () use($container) {
return new StreamHandler($container['monolog.logfile'], $container['monolog.level']);
};
$container['monolog.level'] = function () {
return Logger::DEBUG;
};
$container['monolog.name'] = 'container';
}
示例11: register
public function register(Application $app)
{
$app['mongodbs.options.initializer'] = $app->protect(function () use($app) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($app['mongodbs.options'])) {
$app['mongodbs.options'] = ['default' => isset($app['mongodb.options']) ? $app['mongodb.options'] : []];
}
$app['mongodbs.options'] = array_map(function ($options) use($app) {
return array_replace($app['mongodb.default_options'], $options);
}, $app['mongodbs.options']);
if (!isset($app['mongodbs.default'])) {
$app['mongodbs.default'] = array_keys(array_slice($app['mongodbs.options'], 0, 1))[0];
}
});
$app['mongodbs'] = $app->share(function (Application $app) {
$app['mongodbs.options.initializer']();
$container = new \Pimple();
foreach ($app['mongodbs.options'] as $name => $options) {
$container[$name] = $container->share(function () use($options) {
return new Manager($options['uri'], $options['options'], $options['driverOptions']);
});
}
return $container;
});
$app['mongodb.default_options'] = ['uri' => 'mongodb://localhost:27017', 'options' => [], 'driverOptions' => []];
// shortcuts for the "first" MongoDB
$app['mongodb'] = $app->share(function (Application $app) {
$dbs = $app['mongodbs'];
return $dbs[$app['mongodbs.default']];
});
}
示例12: set
public function set($closure)
{
if ($closure instanceof \Closure) {
if ($this->protect) {
$closure = $this->pimple->protect($closure);
}
if (!empty($this->inject)) {
$factories = array();
foreach ($this->inject as $id) {
$factory = $this->pimple->raw($id);
if (!$factory instanceof \Closure) {
throw new \InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id));
}
$factories[] = $factory;
}
$closure = function ($c) use($closure, $factories) {
$params = array_map(function ($factory) use($c) {
return $factory($c);
}, $factories);
$params[] = $c;
return call_user_func_array($closure, $params);
};
}
if ($this->share) {
$closure = $this->pimple->share($closure);
}
}
$this->pimple[$this->key] = $closure;
$this->restore();
}
示例13: register
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple $mainContainer
*/
public function register(\Pimple $mainContainer)
{
$container = new \Pimple();
$container['deserializer_listener'] = $mainContainer->share(function () {
return new DeserializerListener(SerializerBuilder::create()->build());
});
$container['logger_listener'] = $mainContainer->share(function () {
return new LoggerListener();
});
$container['cache_listener'] = $mainContainer->share(function () use($mainContainer) {
return new CacheListener($mainContainer['core']['dispatcher']);
});
$mainContainer['core']['dispatcher']->addSubscriber($container['cache_listener']);
$mainContainer['core']['dispatcher']->addSubscriber($container['deserializer_listener']);
$mainContainer['core']['dispatcher']->addSubscriber($container['logger_listener']);
$mainContainer['consumer'] = $container;
}
示例14: registerService
/**
* The given closure is call the first time the given service is queried.
* The closure has to return the instance for the given service.
* Created instance will be cached in case $shared is true.
*
* @param string $name name of the service to register another backend for
* @param \Closure $closure the closure to be called on service creation
*/
function registerService($name, \Closure $closure, $shared = true)
{
if ($shared) {
$this[$name] = \Pimple::share($closure);
} else {
$this[$name] = $closure;
}
}
示例15: register
public function register(\Pimple $container)
{
$container['validator'] = $container->share(function ($container) {
$r = new \ReflectionClass('Symfony\\Component\\Validator\\Validator');
if (isset($container['translator'])) {
$container['translator']->addResource('xliff', dirname($r->getFilename()) . '/Resources/translations/validators.' . $container['locale'] . '.xlf', $container['locale'], 'validators');
}
return new Validator($container['validator.mapping.class_metadata_factory'], $container['validator.validator_factory'], isset($container['translator']) ? $container['translator'] : new DefaultTranslator());
});
$container['validator.mapping.class_metadata_factory'] = $container->share(function ($container) {
return new ClassMetadataFactory(new StaticMethodLoader());
});
$container['validator.validator_factory'] = $container->share(function () use($container) {
$validators = isset($container['validator.validator_service_ids']) ? $container['validator.validator_service_ids'] : array();
return new ConstraintValidatorFactory($container, $validators);
});
}