本文整理汇总了PHP中Pimple::protect方法的典型用法代码示例。如果您正苦于以下问题:PHP Pimple::protect方法的具体用法?PHP Pimple::protect怎么用?PHP Pimple::protect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimple
的用法示例。
在下文中一共展示了Pimple::protect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: createApplication
public function createApplication()
{
$pimple = new \Pimple();
$dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
}));
require SPIKA_ROOT . '/etc/app.php';
$mailer = $this->getMockBuilder('\\Silex\\Provider\\SwiftmailerServiceProvider')->setMethods(array('send'))->disableOriginalConstructor()->getMock();
$mailer->expects(once())->method('send')->with(isInstanceOf('Swift_Message'));
$app['mailer'] = $mailer;
return $app;
}
示例3: register
public function register(\Pimple $container)
{
$container['knp_menu.route.voter'] = $container->share(function (\Pimple $container) {
$voter = new RouteVoter();
$voter->setRequest($container['request_stack']->getCurrentRequest());
return $voter;
});
$container['knp_menu.matcher.configure'] = $container->protect(function (Matcher $matcher) use($container) {
$matcher->addVoter($container['knp_menu.route.voter']);
});
}
示例4: setEndpoint
private function setEndpoint()
{
$dicParams = $this->dic;
$this->dic['endpoint'] = $this->dic->protect(function ($class) use($dicParams) {
$fullPath = '\\Elasticsearch\\Endpoints\\' . $class;
if ($class === 'Bulk' || $class === 'Msearch' || $class === 'MPercolate') {
return new $fullPath($dicParams['transport'], $dicParams['serializer']);
} else {
return new $fullPath($dicParams['transport']);
}
});
}
示例5: testGetMenuAsClosure
public function testGetMenuAsClosure()
{
$pimple = new \Pimple();
$menu = $this->getMock('Knp\\Menu\\ItemInterface');
$pimple['menu'] = $pimple->protect(function ($options, $c) use($menu) {
$c['options'] = $options;
return $menu;
});
$provider = new PimpleProvider($pimple, array('default' => 'menu'));
$this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
$this->assertEquals(array('foo' => 'bar'), $pimple['options']);
}
示例6: createApplication
public function createApplication()
{
$pimple = new \Pimple();
$dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
}), 'currentUser' => array("_id" => "testid", "token" => "testtoken"));
require realpath(__DIR__ . '/../../../') . '/etc/app.php';
$spikadb = $this->getMock('\\Spika\\Db\\DbInterface');
$spikadb->expects($this->any())->method('doSpikaAuth')->will($this->returnValue('jR9hCaktyH51TOxG57J5jqcuymkSC2uWUDdwOy0m'));
$app['spikadb'] = $spikadb;
$spikadb->expects($this->any())->method('createUser')->will($this->returnValue('tempip'));
$spikadb->expects($this->any())->method('findUserById')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findUserByEmail')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findUserByName')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('addContact')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('removeContact')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('getActivitySummary')->will($this->returnValue('total_rows'));
$app['spikadb'] = $spikadb;
return $app;
}
示例7: createApplication
public function createApplication()
{
$pimple = new \Pimple();
$dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
}), 'currentUser' => array("_id" => "testid", "token" => "testtoken"));
require realpath(__DIR__ . '/../../../') . '/etc/app.php';
$spikadb = $this->getMock('\\Spika\\Db\\DbInterface');
$spikadb->expects($this->any())->method('getEmoticons')->will($this->returnValue(array('rows' => array())));
$spikadb->expects($this->any())->method('getEmoticonImage')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('addNewUserMessage')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('getUserMessages')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('addNewGroupMessage')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('getGroupMessages')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('addNewComment')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('getCommentCount')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('getComments')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findMessageById')->will($this->returnValue(array('test' => 'OK')));
$app['spikadb'] = $spikadb;
return $app;
}
示例8: createApplication
public function createApplication()
{
$pimple = new \Pimple();
$dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
}), 'currentUser' => array("_id" => "testid", "token" => "testtoken"));
require realpath(__DIR__ . '/../../../') . '/etc/app.php';
$spikadb = $this->getMock('\\Spika\\Db\\DbInterface');
$spikadb->expects($this->any())->method('createGroup')->will($this->returnValue(array('id' => 'testGroup')));
$spikadb->expects($this->any())->method('updateGroup')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('deleteGroup')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findGroupById')->will($this->returnValue(array('user_id' => 'testid')));
$spikadb->expects($this->any())->method('findGroupByName')->will($this->returnValue(array('user_id' => 'testid')));
$spikadb->expects($this->any())->method('findGroupsByName')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('subscribeGroup')->will($this->returnValue(true));
$spikadb->expects($this->any())->method('unSubscribeGroup')->will($this->returnValue(true));
$spikadb->expects($this->any())->method('findUserById')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findGroupByCategoryId')->will($this->returnValue('OK'));
$spikadb->expects($this->any())->method('findAllGroupCategory')->will($this->returnValue('OK'));
$app['spikadb'] = $spikadb;
return $app;
}
示例9: addFactory
/**
* Add service to container wrapping it before
*
* @param string $name
* @param mixed $data
*/
protected function addFactory($name, $data)
{
if ($data['type'] === self::TYPE_PARAM) {
$this->container[$name] = $this->container->protect($data['function']);
return;
}
$parameters = $this->parametersConfig;
$closure = function ($c) use($data, $parameters) {
$args = array();
// fetch arguments for injecting into object
if (!empty($data['arguments']) && is_array($data['arguments'])) {
foreach ($data['arguments'] as $argument) {
if (is_string($argument) && strlen($argument) > 1 && ($argument[0] == '@' || $argument[0] == '%' && $argument[strlen($argument) - 1] == '%' && strlen($argument) > 2)) {
$name = substr($argument, 1);
switch ($argument[0]) {
case '@':
$args[] = $c[$name];
break;
case '%':
$name = substr($name, 0, -1);
if ($parameters->has($name)) {
$args[] = $parameters->get($name);
}
break;
}
} else {
$args[] = $argument;
}
}
}
$class = new ReflectionClass($data['class']);
return $class->newInstanceArgs($args);
};
if ($data['type'] === self::TYPE_FACTORY) {
$closure = $this->container->factory($closure);
}
$this->container[$name] = $closure;
}
示例10: register
public function register(\Pimple $app)
{
foreach ($this->getOrmDefaults() as $key => $value) {
if (!isset($app[$key])) {
$app[$key] = $value;
}
}
$app['orm.em.default_options'] = array('connection' => 'default', 'mappings' => array(), 'types' => array());
$app['orm.ems.options.initializer'] = $app->protect(function () use($app) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($app['orm.ems.options'])) {
$app['orm.ems.options'] = array('default' => isset($app['orm.em.options']) ? $app['orm.em.options'] : array());
}
$tmp = $app['orm.ems.options'];
foreach ($tmp as $name => &$options) {
$options = array_replace($app['orm.em.default_options'], $options);
if (!isset($app['orm.ems.default'])) {
$app['orm.ems.default'] = $name;
}
}
$app['orm.ems.options'] = $tmp;
});
$app['orm.em_name_from_param_key'] = $app->protect(function ($paramKey) use($app) {
$app['orm.ems.options.initializer']();
if (isset($app[$paramKey])) {
return $app[$paramKey];
}
return $app['orm.ems.default'];
});
$app['orm.ems'] = $app->share(function ($app) {
$app['orm.ems.options.initializer']();
$ems = new \Pimple();
foreach ($app['orm.ems.options'] as $name => $options) {
if ($app['orm.ems.default'] === $name) {
// we use shortcuts here in case the default has been overridden
$config = $app['orm.em.config'];
} else {
$config = $app['orm.ems.config'][$name];
}
$ems[$name] = $app->share(function ($ems) use($app, $options, $config) {
return EntityManager::create($app['dbs'][$options['connection']], $config, $app['dbs.event_manager'][$options['connection']]);
});
}
return $ems;
});
$app['orm.ems.config'] = $app->share(function ($app) {
$app['orm.ems.options.initializer']();
$configs = new \Pimple();
foreach ($app['orm.ems.options'] as $name => $options) {
$config = new Configuration();
$app['orm.cache.configurer']($name, $config, $options);
$config->setProxyDir($app['orm.proxies_dir']);
$config->setProxyNamespace($app['orm.proxies_namespace']);
$config->setAutoGenerateProxyClasses($app['orm.auto_generate_proxies']);
$config->setCustomStringFunctions($app['orm.custom.functions.string']);
$config->setCustomNumericFunctions($app['orm.custom.functions.numeric']);
$config->setCustomDatetimeFunctions($app['orm.custom.functions.datetime']);
$config->setCustomHydrationModes($app['orm.custom.hydration_modes']);
$config->setClassMetadataFactoryName($app['orm.class_metadata_factory_name']);
$config->setDefaultRepositoryClassName($app['orm.default_repository_class']);
$config->setEntityListenerResolver($app['orm.entity_listener_resolver']);
$config->setRepositoryFactory($app['orm.repository_factory']);
$config->setNamingStrategy($app['orm.strategy.naming']);
$config->setQuoteStrategy($app['orm.strategy.quote']);
$chain = $app['orm.mapping_driver_chain.locator']($name);
foreach ((array) $options['mappings'] as $entity) {
if (!is_array($entity)) {
throw new \InvalidArgumentException("The 'orm.em.options' option 'mappings' should be an array of arrays.");
}
if (!empty($entity['resources_namespace'])) {
$entity['path'] = $app['psr0_resource_locator']->findFirstDirectory($entity['resources_namespace']);
}
if (isset($entity['alias'])) {
$config->addEntityNamespace($entity['alias'], $entity['namespace']);
}
switch ($entity['type']) {
case 'annotation':
$useSimpleAnnotationReader = isset($entity['use_simple_annotation_reader']) ? $entity['use_simple_annotation_reader'] : true;
$driver = $config->newDefaultAnnotationDriver((array) $entity['path'], $useSimpleAnnotationReader);
$chain->addDriver($driver, $entity['namespace']);
break;
case 'yml':
$driver = new YamlDriver($entity['path']);
$chain->addDriver($driver, $entity['namespace']);
break;
case 'simple_yml':
$driver = new SimplifiedYamlDriver(array($entity['path'] => $entity['namespace']));
$chain->addDriver($driver, $entity['namespace']);
break;
case 'xml':
$driver = new XmlDriver($entity['path']);
$chain->addDriver($driver, $entity['namespace']);
break;
case 'simple_xml':
$driver = new SimplifiedXmlDriver(array($entity['path'] => $entity['namespace']));
$chain->addDriver($driver, $entity['namespace']);
//.........这里部分代码省略.........
示例11: setUp
//.........这里部分代码省略.........
});
self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_not_admin']);
});
self::$DI['user_alt1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt1']);
});
self::$DI['user_alt2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt2']);
});
self::$DI['user_template'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_template']);
});
self::$DI['registration_1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_1']);
});
self::$DI['registration_2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_2']);
});
self::$DI['registration_3'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_3']);
});
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
});
self::$DI['oauth2-app-user_notAdmin'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user_notAdmin']);
});
self::$DI['logger'] = self::$DI->share(function () {
$logger = new Logger('tests');
$logger->pushHandler(new NullHandler());
return $logger;
});
self::$DI['collection'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']);
});
self::$DI['collection_no_access'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']);
});
self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']);
});
if (!self::$booted) {
if (!self::$DI['app']['phraseanet.configuration-tester']->isInstalled()) {
echo "[0;31mPhraseanet is not set up[0;37m\n";
exit(1);
}
self::$fixtureIds = array_merge(self::$fixtureIds, json_decode(file_get_contents(__DIR__ . '/../fixtures.json'), true));
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
self::resetUsersRights(self::$DI['app'], self::$DI['user_notAdmin']);
self::$booted = true;
}
self::$DI['lazaret_1'] = self::$DI->share(function ($DI) {
return $DI['app']['EM']->find('Phraseanet:LazaretFile', self::$fixtureIds['lazaret']['lazaret_1']);
});
foreach (range(1, 7) as $i) {
self::$DI['record_' . $i] = self::$DI->share(function ($DI) use($i) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_' . $i]);
});
}
foreach (range(1, 3) as $i) {
self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use($i) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_story_' . $i]);
});
}
self::$DI['record_no_access_resolver'] = self::$DI->protect(function () {
$id = 'no_access';
if (isset(self::$fixtureIds['records'][$id])) {
return self::$fixtureIds['records'][$id];
}
self::$recordsInitialized[] = $id;
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access']);
$record = record_adapter::createFromFile($file, self::$DI['app']);
self::$DI['app']['subdef.generator']->generateSubdefs($record);
self::$fixtureIds['records'][$id] = $record->get_record_id();
return self::$fixtureIds['records'][$id];
});
self::$DI['record_no_access_by_status_resolver'] = self::$DI->protect(function () {
$id = 'no_access_by_status';
if (isset(self::$fixtureIds['records'][$id])) {
return self::$fixtureIds['records'][$id];
}
self::$recordsInitialized[] = $id;
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access_by_status']);
$record = record_adapter::createFromFile($file, self::$DI['app']);
self::$DI['app']['subdef.generator']->generateSubdefs($record);
self::$fixtureIds['records'][$id] = $record->get_record_id();
return self::$fixtureIds['records'][$id];
});
self::$DI['record_no_access'] = self::$DI->share(function ($DI) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_resolver']());
});
self::$DI['record_no_access_by_status'] = self::$DI->share(function ($DI) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_by_status_resolver']());
});
if (!self::$testCaseBooted) {
$this->bootTestCase();
}
self::$testCaseBooted = true;
}
示例12: rethrow
/**
* @param string $code
*/
public function rethrow($code)
{
$this->_handlers[(string) $code] = $this->_handlers->protect(function ($e) {
throw $e;
});
}
示例13: getName
$this->name = $name;
$this->callable = $callable;
$this->options = array_merge(array('node_class' => 'Twig_Node_Expression_Test'), $options);
}
public function getName()
{
return $this->name;
}
public function getCallable()
{
return $this->callable;
}
public function getNodeClass()
{
return $this->options['node_class'];
}
}
}
namespace {
use Symfony\Component\Console\Application;
use Sensio\Command\Build;
$console = new Application('Email-Makr', '0.1');
$c = new \Pimple();
$c['twig'] = $c->share($c->protect(function ($templateDir) {
$loader = new Twig_Loader_Filesystem($templateDir);
$twig = new Twig_Environment($loader);
return $twig;
}));
$console->add(new Build($c['twig']));
$console->run();
}
示例14: function
return new \FP\Larmo\Application\PluginService($pluginsCollection);
});
$container['authinfo'] = $container->share(function ($container) {
return new \FP\Larmo\Infrastructure\Adapter\IniFileAuthInfoProvider($container['config.path.authinfo']);
});
$container['json_schema_validation'] = function () {
return new \FP\Larmo\Application\Adapter\VendorJsonSchemaValidation();
};
$container['packet_validation.service'] = function ($container) {
$validator = $container['json_schema_validation'];
$authinfo = $container['authinfo'];
$plugins = $container['plugins'];
return new \FP\Larmo\Application\PacketValidationService($validator, $authinfo, $plugins);
};
$container['metadata.entity'] = $container->protect(function ($metadata, $authinfo) {
return new FP\Larmo\Domain\Entity\Metadata($authinfo, $metadata['timestamp'], $metadata['authinfo'], $metadata['source']);
});
$container['message_collection.service'] = $container->protect(function ($data) {
$uniqueIDGenerator = new FP\Larmo\Infrastructure\Adapter\PhpUniqidGenerator();
$uniqueIDValueObject = new FP\Larmo\Domain\ValueObject\UniqueId($uniqueIDGenerator);
$messages = new FP\Larmo\Domain\Service\MessageCollection();
foreach ($data as $singleMessage) {
$author = new FP\Larmo\Domain\ValueObject\Author('', '', $singleMessage['author']['email']);
$messages->append(new FP\Larmo\Domain\Entity\Message($singleMessage['type'], $singleMessage['timestamp'], $author, $uniqueIDValueObject, $singleMessage['message']));
}
return $messages;
});
$container['packet.aggregate'] = $container->protect(function ($message, $metadata) {
new FP\Larmo\Domain\Aggregate\Packet($message, $metadata);
});
return $container;