Exemplo n.º 1
0
 public static function getEntityManager($smart = FALSE, $path_to_entity = null, $proxyPath = null, $proxyNamespace = null)
 {
     if (empty(self::$em)) {
         if ($path_to_entity === NULL) {
             //$path_to_entity = PATH_ROOT . '/' . Sokol::getApp()->name . '/Entity';
             $path_to_entity = PATH_ROOT . '/Entity';
         }
         $isDev = Sokol::getApp()->isDev;
         $connectionParams = Sokol::getConfig('db');
         //---Table Prefix---
         $tablePrefix = !empty($connectionParams['tablePrefix']) ? $connectionParams['tablePrefix'] : null;
         if ($tablePrefix) {
             $evm = new EventManager();
             $tablePrefix = new TablePrefix($tablePrefix);
             $evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
         }
         //---/Table Prefix---
         if ($smart) {
             self::$em = self::getEmSmart($path_to_entity, $isDev, $connectionParams, $evm);
         } else {
             if ($proxyPath === NULL) {
                 $proxyPath = PATH_ROOT . '/' . Sokol::getApp()->name . '/Proxy';
             }
             if ($proxyNamespace === NULL) {
                 $proxyNamespace = Sokol::getApp()->getNamespace() . '\\Proxy';
             }
             self::$em = self::getEm($path_to_entity, $isDev, $connectionParams, $evm, $proxyPath, $proxyNamespace);
         }
         //подключаем тип данных "html"
         Type::addType('html', 'Sokol\\Doctrine\\Extension\\HtmlType');
         self::$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_html', 'html');
     }
     return self::$em;
 }
Exemplo n.º 2
0
 public static function getComponent(Request &$request = null)
 {
     if ($request) {
         if ($com_name = $request->get('_component', null)) {
             $class_name = Sokol::getApp()->getNamespace() . '\\' . self::componentDirectory . '\\' . $com_name . '\\Component';
             if (class_exists($class_name)) {
                 return new $class_name($com_name);
             } else {
                 throw new \Exception('Component ' . $class_name . ' not found');
             }
         } else {
             throw new \Exception('_component is empty');
         }
     }
     return NULL;
 }
Exemplo n.º 3
0
 public function getRootEntities()
 {
     $path_entities = Sokol::getApp()->getPath() . '/Entity';
     if (is_dir($path_entities)) {
         $mask = $path_entities . '/*.php';
         $entitiesPathes = glob($mask);
         foreach ($entitiesPathes as $k => $row) {
             $entitiesPathes[$k] = '\\' . Sokol::getApp()->name . '\\Entity\\' . basename($row, '.php');
         }
         echo '<pre>';
         var_dump($entitiesPathes);
         return $entitiesPathes;
     } else {
         return array();
     }
 }