Exemple #1
0
 /**
  * Runa a command in and returns the commandTester object. This method can
  * run either a blend command or a sub-application command
  * @param string $projectFolder
  * @param string $commandName
  * @param string $params
  * @param string $app In case of null it will be set to blend. In case of
  * className as string, the application's class name will be used
  * @return CommandTester
  */
 public static function runCommand($projectFolder, $commandName, array $params = [], $app = null, $runOptions = [])
 {
     $loader = new ClassLoader();
     $curDir = getcwd();
     chdir($projectFolder);
     if ($app === null) {
         $app = new SetupApplication($projectFolder);
     } else {
         if (is_string($app)) {
             $classes = explode('\\', $app);
             $loader->addPsr4("{$classes[0]}\\", $projectFolder . '/src/');
             $loader->register(true);
             $c = new Container();
             $c->defineSingletonWithInterface('app', $app, ['scriptPath' => $projectFolder . '/bin']);
             $app = $c->get('app');
         }
     }
     $commandTester = new CommandTester($app->find($commandName));
     $commandTester->execute($params, $runOptions);
     chdir($curDir);
     $c = null;
     if ($loader) {
         $loader->unregister();
     }
     return $commandTester;
 }
 public function testFactory()
 {
     $app = $this->createApplication();
     ProjectUtil::runCommand(self::$projectFolder, 'datamodel:generate', ['--configclass' => 'Blend\\Tests\\DataModelBuilder\\Command\\CustomizedModelConfig'], $app);
     $loader = new ClassLoader();
     $loader->addPsr4("DALTest\\", self::$projectFolder . '/src/');
     $loader->register();
     $this->assertFileExists(self::$projectFolder . '/src/Database/Common/Model/SysOrder.php');
     $this->assertFileExists(self::$projectFolder . '/src/Database/Common/Model/Base/SysOrder.php');
     $this->assertFileExists(self::$projectFolder . '/src/Database/Common/Factory/SysOrderFactory.php');
     $this->assertFileExists(self::$projectFolder . '/src/Database/Common/Factory/Base/SysOrderFactory.php');
     $c = new Container();
     /* @var $userFactory \DALTest\Database\Common\Factory\SysUserFactory */
     $userFactory = $c->get('DALTest\\Database\\Common\\Factory\\SysUserFactory', ['database' => self::$currentDatabase]);
     /* @var $user \DALTest\Database\Common\Model\SysUser */
     $user = $userFactory->newModel();
     $user->setUserEmail('*****@*****.**');
     $user->setUserPassword('test123');
     $user->setUserName('Johny');
     $userFactory->save($user);
     $this->assertEquals('*****@*****.**', $user->getUserEmail());
     $this->assertEquals(sha1('test123'), $user->getUserPassword());
     $user->setUserEmail('*****@*****.**');
     $user->setNullableColumn('it is not null now');
     $userFactory->save($user);
 }
 private function getCurrentLocale()
 {
     if ($this->container->isDefined(RouteAttribute::LOCALE)) {
         return $this->container->get(RouteAttribute::LOCALE);
     } else {
         return $this->config->get('translation.defaultLocale', null);
     }
 }
Exemple #4
0
 public function get($key, $default = null)
 {
     if ($this->container->isDefined($key)) {
         return $this->container->get($key);
     } else {
         return $default;
     }
 }
 /**
  * @param mixed $type
  * @return SecurityProviderInterface
  */
 private function getSecurityHandler($type)
 {
     $providers = $this->container->getByInterface(SecurityProviderInterface::class);
     foreach ($providers as $provider) {
         /* @var $provider SecurityProviderInterface */
         if ($provider->getHandlerType() === $type) {
             return $provider;
         }
     }
     /* @var $logger LoggerInterface */
     $logger = $this->container->get(LoggerInterface::class);
     $logger->warning("The requested security provides was" . " not met! Check your services", ['type' => $type]);
     return null;
 }
Exemple #6
0
 /**
  * Converts records to models
  * @param array $records array of records
  * @return array array of models
  */
 protected function recordsToModels(&$records)
 {
     if (is_array($records) && count($records) !== 0) {
         foreach ($records as $key => $record) {
             $records[$key] = $this->container->get('model', ['data' => $this->convertFromRecord($record)]);
         }
         return $records;
     } else {
         return $records;
     }
 }
 public function handle(Request $request)
 {
     $this->assertControllerKey($request);
     $controller = $request->attributes->get(RouteAttribute::CONTROLLER);
     if ($this->isArrayDefinition($controller)) {
         $result = $this->container->call($controller[0], $controller[1], array_merge($request->attributes->all(), $request->request->all(), $request->query->all()));
         if ($result instanceof Response) {
             return $result;
         } else {
             if ($request->attributes->get(RouteAttribute::JSON_RESPONSE, false)) {
                 return new JsonResponse($result);
             } else {
                 return new Response($result);
             }
         }
     } else {
         $error = "The controller has an invalid [controller,action] signature!" . " You should check the Route creation!";
         $this->logger->error($error, ['RequestAttributes' => $request->attributes->add(), $request->getPathInfo()]);
         throw new InvalidParameterException($error);
     }
 }
 protected function generateClasses(Schema $schema)
 {
     $this->cleanBeforeBuild($schema);
     /**
      * To build the Models and Factory classes we use the following strategy:
      * First we build a model and gather the $converterInfo, then when we
      * are buidling the Factory class we use the previously built $converterInfo
      * to feed the Factory building. This is primarily done to avoid writing
      * redundant code.
      */
     $conatiner = new Container();
     $converterResolver = function ($schema, $relation, $column, $dbtype, $fqcn) {
         return $this->config->getConverterForField($schema, $relation, $column, $dbtype, $fqcn);
     };
     foreach ($schema->getRelations() as $relation) {
         $allowCustomize = $this->allowCustomize($relation);
         $rootPath = $this->config->getTargetRootFolder();
         $rootNamespace = $this->config->getModelRootNamespace();
         $appNamespace = $this->config->getApplicationNamespace();
         $converterInfo = null;
         foreach ([ModelBuilder::class, FactoryBuilder::class, SchemaBuilder::class] as $builderClass) {
             /* @var $builderClass \Blend\DataModelBuilder\Builder\ClassBuilder */
             $builder = $conatiner->get($builderClass, ['relation' => $relation, 'includeSchema' => !$schema->isSingle()]);
             $builder->setApplicationNamespace($appNamespace);
             $builder->setRootNamespace($rootNamespace);
             $builder->setRootPath($rootPath);
             $builder->setColumnConverterResolver($converterResolver);
             if ($builder instanceof FactoryBuilder) {
                 if (count($converterInfo) !== 0) {
                     $builder->setFieldConverterClass($this->config->getFieldConverterClass());
                 }
                 $builder->setFieldConverterInfo($converterInfo);
                 $builder->setCustomFactoryMethods($this->config->getModelFactoryMethods());
             }
             if ($builder instanceof SchemaBuilder === false) {
                 $builder->build($allowCustomize);
             }
             if ($builder instanceof ModelBuilder) {
                 $converterInfo = $builder->getFieldConverterInfo();
             }
             if ($builder instanceof SchemaBuilder && $this->needSchemaHelper($relation)) {
                 $builder->build(false);
             }
         }
     }
 }
 public function testReplaceScalarTest()
 {
     $c = new Container();
     $c->setScalar('_test', 100);
     $this->assertEquals(100, $c->get('_test'));
     $c->setScalar('_test', 200);
     $this->assertEquals(200, $c->get('_test'));
 }