Esempio n. 1
0
 public function __construct($configDir, $environment = 'dev')
 {
     if (!@file_exists("{$configDir}/config.yml")) {
         throw new \Exception("File: {$configDir}/config.yml does not exist.");
     }
     if (!@file_exists("{$configDir}/config_{$environment}.yml")) {
         throw new \Exception("File: {$configDir}/config_{$environment}.yml does not exist.");
     }
     try {
         $config = Yaml\Yaml::parse("{$configDir}/config.yml");
         $configEnv = Yaml\Yaml::parse("{$configDir}/config_{$environment}.yml");
     } catch (Yaml\Exception\ParseException $e) {
         throw new \Exception($e->getMessage());
     }
     $this->config = Arr::merge($config, $configEnv);
     $entityPaths = Arr::get($this->config, 'doctrine.entity.paths', array());
     $proxiesPath = Arr::get($this->config, 'doctrine.proxy.path', '');
     $proxiesNamespace = Arr::get($this->config, 'doctrine.proxy.namespace', '');
     $database = Arr::get($this->config, 'doctrine.database', array());
     $isDevMode = Arr::get($this->config, 'doctrine.isDevMode', TRUE);
     $this->cache = new \Doctrine\Common\Cache\ArrayCache();
     $this->reader = new AnnotationReader();
     $this->driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->reader, $entityPaths);
     $this->config = Setup::createAnnotationMetadataConfiguration($entityPaths, $isDevMode);
     $this->config->setMetadataCacheImpl($this->cache);
     $this->config->setQueryCacheImpl($this->cache);
     $this->config->setMetadataDriverImpl($this->driver);
     $this->config->setProxyDir($proxiesPath);
     $this->config->setProxyNamespace($proxiesNamespace);
     $this->config->setAutoGenerateProxyClasses($isDevMode);
     $this->entityManager = EntityManager::create($database, $this->config);
     $this->platform = $this->entityManager->getConnection()->getDatabasePlatform();
     $this->platform->registerDoctrineTypeMapping('enum', 'string');
 }
 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $container->setParameter('northern_apidoc.route', Arr::get($config, 'route', '/docs'));
     $container->setParameter('northern_apidoc.dirs', Arr::get($config, 'dirs', array()));
     # Continue loading config...
     $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
 }
Esempio n. 3
0
 }
 if (!@file_exists("{$configDir}/config_{$env}.yml")) {
     throw new \Exception("File: {$configDir}/config_{$env}.yml does not exist.");
 }
 try {
     $config = Yaml\Yaml::parse("{$configDir}/config.yml");
     $configEnv = Yaml\Yaml::parse("{$configDir}/config_{$env}.yml");
 } catch (Yaml\Exception\ParseException $e) {
     throw new \Exception($e->getMessage());
 }
 $config = Arr::merge($config, $configEnv);
 //print_r( $config );
 $entityManager = NULL;
 $dbParams = Arr::get($config, 'doctrine.database', []);
 $mappingType = strtolower(Arr::get($config, 'doctrine.mapping.type', 'xml'));
 $paths = Arr::get($config, 'doctrine.mapping.paths', []);
 $mappingPaths = [];
 foreach ($paths as $path) {
     $mappingPaths[] = realpath($path);
 }
 switch ($mappingType) {
     case 'xml':
         $xmlConfig = Setup::createXMLMetadataConfiguration($mappingPaths, $env == 'dev');
         $entityManager = EntityManager::create($dbParams, $xmlConfig);
         break;
     case 'yml':
     case 'yaml':
         //$driver = new YamlDriver( $mappingPaths );
         //$driver->setFileExtension('.yml');
         $ymlConfig = Setup::createYAMLMetadataConfiguration($mappingPaths, $env == 'dev');
         //$ymlConfig->setMetadataDriverImpl( $driver );
Esempio n. 4
0
 /**
  * Updates an existing User.
  *
  * @param  \Northern\Core\Domain\User
  * @param  array $values
  * @throws \Northern\Core\Component\User\Exception\UserValidationException
  */
 public function updateUser(User $user, array $values)
 {
     $password = Arr::extract($values, 'password', NULL);
     $passwordConfirm = Arr::extract($values, 'passwordConfirm', NULL);
     $errors = $this->userValidator->validate($values);
     $errors = $this->userValidator->validateUniqueEmail($user, Arr::get($values, 'email'), $errors);
     if ($password !== NULL and (!empty($password) and !empty($passwordConfirm))) {
         if (empty($password)) {
             $errors->add('password', "The password cannot be left blank.");
         } else {
             if (empty($passwordConfirm)) {
                 $errors->add('password', "The password confirm cannot be left blank.");
             } else {
                 if ($password !== $passwordConfirm) {
                     $errors->add('password', "The password and password confirm fields must be equal.");
                 } else {
                     $user->salt = $this->passwordEncoder->generateSalt();
                     $user->password = $this->passwordEncoder->encodePassword($password, $user->salt);
                 }
             }
         }
     }
     if ($errors->any()) {
         throw new Exception\UserValidationException($errors);
     }
     // Remove the 'password' field here so it's not set overwritten during the
     // entity 'update' method. In fact, in any situation we need to remove the
     // 'password' field here. We remove the passwordConfirm field for consistency.
     unset($values['password']);
     unset($values['passwordConfirm']);
     // Update the user entity with the new validated values.
     $user->update($values);
 }