Ejemplo n.º 1
0
 private function createContainer()
 {
     $container = new ContainerBuilder();
     // retrieve security class
     $values = \Parameters::get('security');
     $class = $values['security']['classes'];
     $session_name = $values['session']['name'];
     // test if class exist and implement interface
     try {
         Assertion::ClassExists($class);
         Assertion::implementsInterface($class, '\\GL\\Core\\Security\\AuthenticationServiceInterface');
     } catch (AssertionFailedException $e) {
         echo $e->getMessage();
         die;
     }
     // Inject mailer
     $container->register('mailer', 'GL\\Core\\Tools\\Mailer');
     // Inject Request
     $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setFactory("Symfony\\Component\\HttpFoundation\\Request::createFromGlobals");
     // Inject Request helper
     $container->register('request_helper', 'GL\\Core\\Helpers\\RequestHelper')->addMethodCall('setRequest', array(new Reference('request')));
     // Inject Twig Service
     $container->register('template', 'GL\\Core\\Templating\\TemplateProvider');
     // Inject RouteCollection
     $container->register('routes', 'Symfony\\Component\\Routing\\RouteCollection')->setFactory("GL\\Core\\Routing\\RouteProvider::GetRouteCollection");
     if (class_exists("\\PHPExcel")) {
         // Inject PHPExcel Wrapper
         $container->register('excel', 'GL\\Core\\Tools\\Excel');
     }
     if (class_exists("\\TCPDF")) {
         // Inject FPDF Wrapper
         $container->register('pdf', 'GL\\Core\\Tools\\PDF');
     }
     // Inject Session
     $container->register('session', 'Symfony\\Component\\HttpFoundation\\Session\\Session')->addMethodCall('setName', array($session_name))->addMethodCall('start');
     // Inject Crsf verifier
     $container->register('crsf', 'GL\\Core\\Security\\FormCrsf')->addArgument(new Reference('session'))->addArgument(new Reference('request'));
     // Inject translator service
     $container->register('translator', 'GL\\Core\\Config\\Translator');
     // Inject Security Service
     $container->register('security', $class)->addArgument(new Reference('session'))->addArgument(new Reference('request'))->addMethodCall('autologin');
     // Inject DebugBar
     $container->register('debug', 'GL\\Core\\Debug\\KLDebugBar');
     // Inject Pdo Object
     $container->register('pdo', 'PDO')->setFactory("GL\\Core\\Helpers\\DbHelper::getPdo");
     // Inject Config
     $container->register('config', 'GL\\Core\\Config\\Config');
     // Inject DbHelper
     $container->register('db', 'GL\\Core\\Helpers\\DbHelper');
     // Inject Redis
     $container->register('redis', 'GL\\Core\\Tools\\Redis');
     // Inject services defined in config/services.yml
     $loader = new YamlFileLoader($container, new FileLocator(SERVICEPATH));
     $loader->load('services.yml');
     $container->compile();
     return $container;
 }
Ejemplo n.º 2
0
 private function testTwig()
 {
     try {
         $class = "Twig_Environment";
         Assertion::ClassExists($class);
     } catch (AssertionFailedException $e) {
         echo "Twig is not installed, add it with 'twig/twig':'1.24' in your composer.json";
         die;
     }
 }
Ejemplo n.º 3
0
 public function getTemplateService($eng = "")
 {
     $ret = null;
     // spécify engine or use default
     $engine = $eng == "" ? TEMPLATE_ENGINE : $eng;
     try {
         Assertion::keyIsset($this->arr, $engine, "Template engine {$engine}  is not defined");
         $class = $this->arr[$engine];
         Assertion::ClassExists($class);
         $ret = new $class();
     } catch (Exception $e) {
     }
     return $ret;
 }
Ejemplo n.º 4
0
 /**
  * 
  * Return a controller instance
  * 
  * @param String $controllername Controller namespace to instanciate
  * @return \GL\Core\Controller\Controller Herited instance of controller
  */
 private function getInstance($controllername)
 {
     try {
         Assertion::ClassExists($controllername);
     } catch (AssertionFailedException $e) {
         echo "Error class {$controllername} does not exists";
         die;
     }
     $instance = new $controllername($this->_controller, $this->_action);
     // add dependency container in the controller instance
     $instance->setContainer($this->_container);
     return $instance;
 }
Ejemplo n.º 5
0
 private function run($instance, $type = "up")
 {
     // test if class exist and implement interface
     try {
         $class = get_class($instance);
         Assertion::ClassExists($class);
         Assertion::implementsInterface($class, '\\GL\\Core\\Migration\\MigrationInterface');
         $max = 0;
         // get all migrations in db
         $migrations = MigrationModel::all();
         // find max batch id version
         if (count($migrations) > 0) {
             $max = $migrations->max('db_version');
         }
         $batchid = $max + 1;
         // retrieve className
         $id = $instance->getUniqueTag();
         // find if this instance was not executed
         $exec = MigrationModel::where('migration', '=', $id)->first();
         $bExec = true;
         if ($exec != null) {
             if ($exec->status == $type) {
                 // always executed
                 $bExec = false;
             }
         }
         if ($bExec) {
             $instance->{$type}();
             // insert in db
             if ($exec == null) {
                 $exec = new MigrationModel();
             }
             $exec->class = $class;
             $exec->migration = $id;
             $exec->status = $type;
             $exec->db_version = $batchid;
             $exec->save();
         }
     } catch (\Exception $ex) {
         echo $ex;
     } catch (AssertionFailedException $e) {
         echo $e;
     }
 }
Ejemplo n.º 6
0
 /**
  * Function execute before action execute
  * @param string $route actual route
  * @return boolean
  */
 public function executeBefores($route)
 {
     $ret = false;
     $fnArray = \Functions::getAll();
     if (isset($fnArray)) {
         foreach ($fnArray as $key => $value) {
             if ($value["type"] == "before") {
                 // for each global function defined
                 $arrRoutes = isset($value["routes"]) ? $value["routes"] : null;
                 $scope = isset($value["scope"]) ? $value["scope"] : "all";
                 $class = $value["class"];
                 // test if class exist and implements interface
                 Assertion::ClassExists($class);
                 Assertion::implementsInterface($class, '\\GL\\Core\\Controller\\BeforeFunctionInterface');
                 $bExecute = $this->IsAllowed($arrRoutes, $route, $scope);
                 if ($bExecute) {
                     $exc = new $class($this->_container);
                     $ret = $exc->execute();
                 }
             }
         }
     }
     return $ret;
 }