예제 #1
0
 public function run(Request &$request)
 {
     Log::point(__METHOD__);
     Sokol::checkAccess($this);
     $controller = Sokol::setController(HttpKernel::getController($request));
     return $controller->run($request);
 }
예제 #2
0
파일: Doctrine.php 프로젝트: php-nik/sokol
 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;
 }
예제 #3
0
 public function removeAction(Request &$request)
 {
     if ($id = $request->get('id')) {
         if ($this->remove($id)) {
             return $this->redirect(BASE_URL . Sokol::getCom()->name . '/' . $this->name . '/list');
         }
     }
     $smarty = Smarty::getInstance();
     $smarty->assign('content', 'Item not found');
     return new Response(Smarty::fetchTemplate('index.tpl'));
 }
예제 #4
0
파일: Installer.php 프로젝트: php-nik/sokol
 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();
     }
 }
예제 #5
0
 public static function getController(Request &$request = null)
 {
     if ($request) {
         if ($contr_name = $request->get('_controller', null)) {
             $contr_name_full = $contr_name . self::controllerSuffix;
             $contr_class = Sokol::getCom()->getNamespace() . '\\' . self::controllerDirectory . '\\' . $contr_name_full;
             if (class_exists($contr_class)) {
                 return new $contr_class($contr_name);
             } else {
                 throw new \Exception('Controller ' . $contr_class . ' not found');
             }
         } else {
             throw new \Exception('_controller is empty');
         }
     }
     return NULL;
 }
예제 #6
0
파일: AdminApp.php 프로젝트: php-nik/sokol
 public function run(Request &$request)
 {
     $this->before_run($request);
     Log::point(__METHOD__);
     $this->getRoutes($request);
     $session = Sokol::getSession();
     $user_id = $session->get('user_id');
     if ($user_id) {
         Sokol::setUser($user_id);
     }
     if (Sokol::getUser() != NULL || $request->get('_component') == 'main') {
         Sokol::setCom(HttpKernel::getComponent($request));
         //создаем объект компонента
         $res = Sokol::getCom()->run($request);
         //получаем результаты выволнения компонента
         $this->after_run($res);
         return $res;
     } else {
         return new RedirectResponse(BASE_URL);
     }
 }
예제 #7
0
파일: Onpay.php 프로젝트: php-nik/sokol
 private function responseXml($content = null)
 {
     $response = Sokol::getResponse();
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($content);
     $response->setStatusCode(200);
     return $response;
 }
예제 #8
0
 final function generateUrl($name, $parameters = array(), $absolute = false)
 {
     return Sokol::generateURL($name, $parameters, $absolute);
 }
예제 #9
0
파일: HTML.php 프로젝트: php-nik/sokol
 function formOrder($entity = null)
 {
     //throw new \Exception('test');
     $form_attr = array('method' => 'POST', 'action' => 'order?' . Sokol::getRequest()->getQueryString());
     $input_attr = array('style' => 'width:50px;');
     $submit_attr = array();
     return self::form(self::input_hidden('id', $entity->getId()) . self::input_text('order', $entity->getOrder(), $input_attr) . self::input_submit('submit', 'OK', $submit_attr), $form_attr);
 }
예제 #10
0
파일: Sokol.php 프로젝트: php-nik/sokol
 public static function checkAccess($object)
 {
     $type = Sokol::getUserType();
     $accessControl = isset($object->accessControl) ? $object->accessControl : 5;
     if ($accessControl <= $type) {
         return true;
     } else {
         throw new \Sokol\Exceptions\AccessException('Access denied');
     }
 }
예제 #11
0
파일: BaseApp.php 프로젝트: php-nik/sokol
 public function getRequest()
 {
     return Sokol::getRequest();
 }
예제 #12
0
파일: Form.php 프로젝트: php-nik/sokol
 public function get()
 {
     $html = '<table style="width:100%;">';
     $metadata = $this->getMetadata();
     //echo '<pre>';var_dump($metadata);
     $columns = $this->getColumns();
     $values = $this->getValues();
     $this->getRequired();
     foreach ($columns as $column => $label) {
         if (isset($metadata->associationMappings[$column])) {
             $row = $metadata->associationMappings[$column];
             if (Doctrine::isManyToOne($metadata, $column)) {
                 $class = $row['targetEntity'];
                 $name = $row['fieldName'];
                 $method = 'get_' . $name;
                 $method = Camel::to_camel_case($method);
                 $obj = $this->entity->{$method}();
                 $value = !empty($obj) ? $obj->getId() : 0;
                 $class_meta = Doctrine::getEntityManager()->getClassMetadata($class);
                 if (isset($class_meta->fieldMappings['path_alias'])) {
                     $items = Doctrine::getEntityManager()->getRepository($class)->findBy(array(), array('path_alias' => 'ASC'));
                 } else {
                     $items = Doctrine::getEntityManager()->getRepository($class)->findAll();
                 }
                 $attributes = array('required' => $this->has($name, $this->required), 'style' => 'width: 100%;');
                 $html .= '<tr><td>' . $label . '</td><td>' . self::getSelect($name, $value, $items, $attributes) . '</td></tr>';
             } elseif (Doctrine::isManyToMany($metadata, $column)) {
                 $class = $row['targetEntity'];
                 $name = $row['fieldName'];
                 $method = 'get_' . $name;
                 $method = Camel::to_camel_case($method);
                 $arr = $this->entity->{$method}();
                 $class_meta = Doctrine::getEntityManager()->getClassMetadata($class);
                 if (isset($class_meta->fieldMappings['path_alias'])) {
                     $items = Doctrine::getEntityManager()->getRepository($class)->findBy(array(), array('path_alias' => 'ASC'));
                 } else {
                     $items = Doctrine::getEntityManager()->getRepository($class)->findAll();
                 }
                 $attributes = array('required' => $this->has($name, $this->required), 'style' => 'width: 100%;');
                 $html .= '<tr><td>' . $label . '</td><td>' . self::getMulti($name . '[]', $arr, $items, $attributes) . '</td></tr>';
             }
         } else {
             $row = $metadata->fieldMappings[$column];
             $name = $row['fieldName'];
             $primary = isset($row['id']) && $row['id'] == TRUE;
             $type = $row['type'];
             $length = isset($row['length']) ? $row['length'] : null;
             $value = $values->{$name};
             $attributes = array('required' => $this->has($name, $this->required));
             $html .= '<tr><td>' . $label . '</td><td>' . self::getInput($type, $name, $value, $length, $primary, $attributes) . '</td></tr>';
         }
     }
     $html .= '</table>';
     $html .= HTML::submit('submit', 'Сохранить');
     $form_atr = array('action' => BASE_URL . Sokol::getCom()->name . '/' . Sokol::getController()->name . '/save', 'method' => 'POST', 'style' => 'width: 100%;');
     return HTML::form($html, $form_atr);
 }