예제 #1
0
파일: Container.php 프로젝트: elfet/simple
 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();
 }
 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;
 }
 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
0
 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
0
 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']);
 }
 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;
 }
 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;
 }
 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
0
 /**
  * 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;
 }
 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']);
                         break;
                     case 'php':
                         $driver = new StaticPHPDriver($entity['path']);
                         $chain->addDriver($driver, $entity['namespace']);
                         break;
                     default:
                         throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
                         break;
                 }
             }
             $config->setMetadataDriverImpl($chain);
             foreach ((array) $options['types'] as $typeName => $typeClass) {
                 if (Type::hasType($typeName)) {
                     Type::overrideType($typeName, $typeClass);
                 } else {
                     Type::addType($typeName, $typeClass);
                 }
             }
             $configs[$name] = $config;
         }
         return $configs;
     });
     $app['orm.cache.configurer'] = $app->protect(function ($name, Configuration $config, $options) use($app) {
         $config->setMetadataCacheImpl($app['orm.cache.locator']($name, 'metadata', $options));
         $config->setQueryCacheImpl($app['orm.cache.locator']($name, 'query', $options));
         $config->setResultCacheImpl($app['orm.cache.locator']($name, 'result', $options));
         $config->setHydrationCacheImpl($app['orm.cache.locator']($name, 'hydration', $options));
     });
     $app['orm.cache.locator'] = $app->protect(function ($name, $cacheName, $options) use($app) {
         $cacheNameKey = $cacheName . '_cache';
         if (!isset($options[$cacheNameKey])) {
             $options[$cacheNameKey] = $app['orm.default_cache'];
         }
         if (isset($options[$cacheNameKey]) && !is_array($options[$cacheNameKey])) {
             $options[$cacheNameKey] = array('driver' => $options[$cacheNameKey]);
         }
         if (!isset($options[$cacheNameKey]['driver'])) {
             throw new \RuntimeException("No driver specified for '{$cacheName}'");
         }
         $driver = $options[$cacheNameKey]['driver'];
         $cacheInstanceKey = 'orm.cache.instances.' . $name . '.' . $cacheName;
         if (isset($app[$cacheInstanceKey])) {
             return $app[$cacheInstanceKey];
         }
         $cache = $app['orm.cache.factory']($driver, $options[$cacheNameKey]);
         if (isset($options['cache_namespace']) && $cache instanceof CacheProvider) {
             $cache->setNamespace($options['cache_namespace']);
         }
         return $app[$cacheInstanceKey] = $cache;
     });
     $app['orm.cache.factory.backing_memcache'] = $app->protect(function () {
         return new \Memcache();
     });
     $app['orm.cache.factory.memcache'] = $app->protect(function ($cacheOptions) use($app) {
         if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
             throw new \RuntimeException('Host and port options need to be specified for memcache cache');
         }
         $memcache = $app['orm.cache.factory.backing_memcache']();
         $memcache->connect($cacheOptions['host'], $cacheOptions['port']);
         $cache = new MemcacheCache();
         $cache->setMemcache($memcache);
         return $cache;
     });
     $app['orm.cache.factory.backing_memcached'] = $app->protect(function () {
         return new \Memcached();
     });
     $app['orm.cache.factory.memcached'] = $app->protect(function ($cacheOptions) use($app) {
         if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
             throw new \RuntimeException('Host and port options need to be specified for memcached cache');
         }
         $memcached = $app['orm.cache.factory.backing_memcached']();
         $memcached->addServer($cacheOptions['host'], $cacheOptions['port']);
         $cache = new MemcachedCache();
         $cache->setMemcached($memcached);
         return $cache;
     });
     $app['orm.cache.factory.backing_redis'] = $app->protect(function () {
         return new \Redis();
     });
     $app['orm.cache.factory.redis'] = $app->protect(function ($cacheOptions) use($app) {
         if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
             throw new \RuntimeException('Host and port options need to be specified for redis cache');
         }
         $redis = $app['orm.cache.factory.backing_redis']();
         $redis->connect($cacheOptions['host'], $cacheOptions['port']);
         if (isset($cacheOptions['password'])) {
             $redis->auth($cacheOptions['password']);
         }
         $cache = new RedisCache();
         $cache->setRedis($redis);
         return $cache;
     });
     $app['orm.cache.factory.array'] = $app->protect(function () {
         return new ArrayCache();
     });
     $app['orm.cache.factory.apc'] = $app->protect(function () {
         return new ApcCache();
     });
     $app['orm.cache.factory.xcache'] = $app->protect(function () {
         return new XcacheCache();
     });
     $app['orm.cache.factory.filesystem'] = $app->protect(function ($cacheOptions) {
         if (empty($cacheOptions['path'])) {
             throw new \RuntimeException('FilesystemCache path not defined');
         }
         $cacheOptions += array('extension' => FilesystemCache::EXTENSION, 'umask' => 02);
         return new FilesystemCache($cacheOptions['path'], $cacheOptions['extension'], $cacheOptions['umask']);
     });
     $app['orm.cache.factory'] = $app->protect(function ($driver, $cacheOptions) use($app) {
         switch ($driver) {
             case 'array':
                 return $app['orm.cache.factory.array']();
             case 'apc':
                 return $app['orm.cache.factory.apc']();
             case 'xcache':
                 return $app['orm.cache.factory.xcache']();
             case 'memcache':
                 return $app['orm.cache.factory.memcache']($cacheOptions);
             case 'memcached':
                 return $app['orm.cache.factory.memcached']($cacheOptions);
             case 'filesystem':
                 return $app['orm.cache.factory.filesystem']($cacheOptions);
             case 'redis':
                 return $app['orm.cache.factory.redis']($cacheOptions);
             default:
                 throw new \RuntimeException("Unsupported cache type '{$driver}' specified");
         }
     });
     $app['orm.mapping_driver_chain.locator'] = $app->protect(function ($name = null) use($app) {
         $app['orm.ems.options.initializer']();
         if (null === $name) {
             $name = $app['orm.ems.default'];
         }
         $cacheInstanceKey = 'orm.mapping_driver_chain.instances.' . $name;
         if (isset($app[$cacheInstanceKey])) {
             return $app[$cacheInstanceKey];
         }
         return $app[$cacheInstanceKey] = $app['orm.mapping_driver_chain.factory']($name);
     });
     $app['orm.mapping_driver_chain.factory'] = $app->protect(function ($name) use($app) {
         return new MappingDriverChain();
     });
     $app['orm.add_mapping_driver'] = $app->protect(function (MappingDriver $mappingDriver, $namespace, $name = null) use($app) {
         $app['orm.ems.options.initializer']();
         if (null === $name) {
             $name = $app['orm.ems.default'];
         }
         $driverChain = $app['orm.mapping_driver_chain.locator']($name);
         $driverChain->addDriver($mappingDriver, $namespace);
     });
     $app['orm.generate_psr0_mapping'] = $app->protect(function ($resourceMapping) use($app) {
         $mapping = array();
         foreach ($resourceMapping as $resourceNamespace => $entityNamespace) {
             $directory = $app['psr0_resource_locator']->findFirstDirectory($resourceNamespace);
             if (!$directory) {
                 throw new \InvalidArgumentException("Resources for mapping '{$entityNamespace}' could not be located; Looked for mapping resources at '{$resourceNamespace}'");
             }
             $mapping[$directory] = $entityNamespace;
         }
         return $mapping;
     });
     $app['orm.strategy.naming'] = $app->share(function ($app) {
         return new DefaultNamingStrategy();
     });
     $app['orm.strategy.quote'] = $app->share(function ($app) {
         return new DefaultQuoteStrategy();
     });
     $app['orm.entity_listener_resolver'] = $app->share(function ($app) {
         return new DefaultEntityListenerResolver();
     });
     $app['orm.repository_factory'] = $app->share(function ($app) {
         return new DefaultRepositoryFactory();
     });
     $app['orm.em'] = $app->share(function ($app) {
         $ems = $app['orm.ems'];
         return $ems[$app['orm.ems.default']];
     });
     $app['orm.em.config'] = $app->share(function ($app) {
         $configs = $app['orm.ems.config'];
         return $configs[$app['orm.ems.default']];
     });
 }
 public function setUp()
 {
     parent::setUp();
     if (null !== self::$DI) {
         unset(self::$DI['app']['dbal.provider']);
     }
     self::$DI = new \Pimple();
     ini_set('memory_limit', '4096M');
     \PHPUnit_Framework_Error_Warning::$enabled = true;
     \PHPUnit_Framework_Error_Notice::$enabled = true;
     self::$DI['app'] = self::$DI->share(function ($DI) {
         return $this->loadApp('/lib/Alchemy/Phrasea/Application/Root.php');
     });
     self::$DI['cli'] = self::$DI->share(function ($DI) {
         return $this->loadCLI();
     });
     self::$DI['local-guzzle'] = self::$DI->share(function ($DI) {
         return new Guzzle(self::$DI['app']['conf']->get('servername'));
     });
     self::$DI['client'] = self::$DI->share(function ($DI) {
         return new Client($DI['app'], []);
     });
     self::$DI['user'] = self::$DI->share(function ($DI) {
         return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit']);
     });
     self::$DI['user_1'] = self::$DI->share(function ($DI) {
         return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_1']);
     });
     self::$DI['user_2'] = self::$DI->share(function ($DI) {
         return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_2']);
     });
     self::$DI['user_3'] = self::$DI->share(function ($DI) {
         return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_3']);
     });
     self::$DI['user_guest'] = self::$DI->share(function ($DI) {
         return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_guest']);
     });
     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 "Phraseanet is not set up\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;
 }
 /**
  * @param string $code
  */
 public function rethrow($code)
 {
     $this->_handlers[(string) $code] = $this->_handlers->protect(function ($e) {
         throw $e;
     });
 }
예제 #13
0
            $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
0
    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;