示例#1
0
 /**
  * Строит сервис.
  * 
  * @param bool $global
  *
  * @return void
  */
 protected function buildService($global = false)
 {
     $abc = $this->abc;
     $component = '\\ABC\\Abc\\Components\\' . $this->serviceId . '\\' . $this->serviceId;
     $typeService = $global ? 'setAsShared' : 'set';
     $this->container->{$typeService}($this->serviceId, function () use($component, $abc) {
         if (class_exists($component)) {
             return new $component($abc);
         } else {
             AbcError::badFunctionCall('<strong>' . $this->serviceId . '</strong>' . ABC_NOT_FOUND_SERVICE);
         }
     });
 }
 /**
  * Установка маршрутов
  *
  * @return void
  */
 protected function setRoute($default = false)
 {
     if ($default) {
         $this->route = $this->defaultRoute;
     } else {
         foreach ($this->routes as $num => $rout) {
             if (!empty($this->defaultKeys[$num])) {
                 $this->route[$this->defaultKeys[$num]] = $rout;
             } else {
                 AbcError::logic(ABC_ERROR_ROUTES_RULE);
             }
         }
     }
 }
示例#3
0
 /**
  * Ошибка вызова метода
  *
  * @param string $method
  * @param mix $param
  *
  * @return void
  */
 public function __call($method, $param)
 {
     $method = explode('::', $method);
     AbcError::badMethodCall(array_pop($method) . '() ' . ABC_NO_METHOD);
 }
示例#4
0
 /**
  * Возвращает объект билдера
  *
  * @param string $serviceId
  *
  * @return object
  */
 protected function getBuilder($serviceId = null)
 {
     if (empty($serviceId) || !is_string($serviceId)) {
         AbcError::invalidArgument(ABC_INVALID_SERVICE_NAME);
     }
     $builder = new Builder($serviceId, $this);
     return $builder;
 }
示例#5
0
 /**
  * Генерирует меню навигации
  * 
  * @param string $param
  *
  * @return string
  */
 public function createMenu($param = 'num')
 {
     if (is_null($this->total)) {
         AbcError::logic(ABC_NO_TOTAL);
     }
     $this->param = $param;
     $count = ceil($this->total / $this->numRows / $this->numColumns);
     $menu = "\n<!-- Paginator begin -->\n";
     if ($count < 13) {
         $i = 1;
         $cnt = $count;
     } else {
         if ($this->numPage > 10) {
             $menu .= $this->createLink($this->numPage - 10, '-10&lt;', 'top');
         }
         if ($count > 12) {
             if ($this->numPage == 7) {
                 $menu .= $this->createLink(1, 1);
             } elseif ($this->numPage == 8) {
                 $menu .= $this->createLink(1, 1) . $this->createLink(2, 2);
             } elseif ($this->numPage > 7) {
                 $menu .= $this->createLink(1, 1) . $this->createLink(2, 2) . $this->createLink(0, '...', 'top', false);
             }
         }
         if ($this->numPage < 6) {
             $i = 1;
             $cnt = 10;
         } elseif ($this->numPage >= $count) {
             $i = $count - 10;
             $cnt = $count;
         } else {
             $i = $this->numPage - 5;
             $cnt = $count;
         }
         if ($this->numPage < 6) {
             $cnt = $i + 9;
         } elseif ($count - $i > 10) {
             $cnt = $i + 10;
         }
     }
     while ($i <= $cnt) {
         if ($i == $this->numPage) {
             $menu .= $this->createLink($i, $i, 'active', false);
         } else {
             $menu .= $this->createLink($i, $i);
         }
         $i++;
     }
     if ($count > 12) {
         if ($this->numPage < $count - 6) {
             $menu .= $this->createLink(0, '...', 'top', false) . $this->createLink($count - 1, $count - 1);
         }
         if ($this->numPage < $count - 5) {
             $menu .= $this->createLink($count, $count);
         }
     }
     $end = $this->numPage + 10 > $count ? $count : $this->numPage + 10;
     if ($this->numPage < $count - 5 && $count - $this->numPage >= 10) {
         $menu .= $this->createLink($end, '&gt;+10', 'top');
     }
     return $menu . "\n<!-- Paginator end -->\n";
 }
示例#6
0
 /**
  * Проверка корректности настроек
  *
  * @param string $config
  *    
  * @return bool
  */
 protected function checkConfig($config = [])
 {
     extract($config);
     if (!isset($dsn, $user, $pass)) {
         AbcError::invalidArgument(' Component PDO: ' . ABC_WRONG_CONNECTION);
         return false;
     }
     return true;
 }
 /**
  * Возвращает массив маршрутов 
  *
  * @return array
  */
 public function getRouteRule()
 {
     if (!isset($this->config['route_rules'])) {
         return [];
     }
     if (is_array($this->config['route_rules'])) {
         return $this->config['route_rules'];
     }
     if (is_file($this->config['route_rules'])) {
         return $this->parseConfigRoutes($this->config['route_rules']);
     }
     AbcError::badFunctionCall(ABC_UNKNOWN_ROUTES);
 }
 /**
  * Метод проверки повтора оператора
  *
  * @param array $operand
  */
 public function checkDuble($operand)
 {
     if (isset($this->operands[$operand])) {
         AbcError::logic(' Component DbCommand: ' . ABC_SQL_ERROR);
     }
 }
示例#9
0
 /**
  * Обрабатывает параметры для дебаггинга в зависимости от типа.
  *
  * @param string $param
  * @param string $type
  *    
  * @return string
  */
 protected function escape($param, $type)
 {
     switch ($type) {
         case 'i':
             return (int) $param;
         case 'd':
             return "'" . (double) $param . "'";
         case 's':
         case 'b':
             return "'" . $this->mysqli->real_escape_string($param) . "'";
         default:
             AbcError::invalidArgument('Component Mysqli: ' . ABC_NO_MYSQLI_TYPE . $type);
     }
 }
示例#10
0
 /**
  * Проверяет корректность анонимной функции 
  *
  * @param callable $callable
  *
  * @return callable
  */
 protected function validateCallable($callable)
 {
     if (!is_callable($callable)) {
         AbcError::invalidArgument(ABC_INVALID_CALLABLE);
     }
     return $callable;
 }