예제 #1
0
파일: Assets.php 프로젝트: techart/tao
 /**
  * @return string
  */
 public function javascript_include_tag($t)
 {
     $result = '';
     foreach ($args = Core_Types::is_array(func_get_arg(1)) ? func_get_arg(1) : array_slice(func_get_args(), 1) as $src) {
         $result .= $t->tags->content_tag('script', '', array('type' => 'text/javascript', 'src' => $this->javascript_path_for($t, $src))) . "\n";
     }
     return $result;
 }
예제 #2
0
파일: Navigation.php 프로젝트: techart/tao
 public function link($name, $url, $title, $arg1 = null, $arg2 = null)
 {
     $this->links[(string) $name] = new WebKit_Navigation_Link($url, $title, Core_Types::is_array($arg1) ? $arg1 : array());
     if ($sublinks = $arg1 instanceof WebKit_Navigation_LinkSet ? $arg1 : ($arg2 instanceof WebKit_Navigation_LinkSet ? $arg2 : null)) {
         $this->links[(string) $name]->sublinks($sublinks);
     }
     return $this;
 }
예제 #3
0
파일: SQL.php 프로젝트: techart/tao
 public function run()
 {
     $args = func_get_args();
     $arg =& $args[0];
     $serial = $this->view ? $this->view->table->serial : null;
     $sql = 'INSERT INTO ' . ($this->table ? $this->table : $this->view->table->name);
     if (count($this->columns) > 0) {
         $columns = $this->columns;
     } elseif ($arg instanceof DB_SQL_Entity) {
         if ($this->view->table->column_exists('type')) {
             $columns = array('type');
         }
         foreach ($arg->attributes as $attr => $value) {
             if ($attr == $serial || $this->view && !$this->view->table->column_exists($attr)) {
                 continue;
             }
             $columns[] = $attr;
         }
     } elseif ($arg instanceof Iterator || $arg instanceof IteratorAggregate || Core_Types::is_array($arg)) {
         foreach ($arg as $attr => $value) {
             if ($attr == $serial || $this->view && !$this->view->table->column_exists($attr)) {
                 continue;
             }
             $columns[] = $attr;
         }
     }
     $sql .= ' (' . Core_Arrays::join_with(', ', $columns) . ")\n";
     $sql .= 'VALUES (' . Core_Arrays::join_with(', ', Core_Arrays::map('return ":$x";', $columns)) . ")\n";
     if ($arg instanceof DB_SQL_Entity ? $arg->before_save() && $arg->before_insert() : true) {
         $rc = DB_SQL::db()->connection->prepare($sql)->bind(count($args) > 1 ? $args : $arg)->execute()->is_successful;
         if ($rc) {
             if ($arg instanceof DB_SQL_Entity) {
                 if ($this->view && $serial && $arg instanceof DB_SQL_Entity) {
                     $arg[$serial] = DB_SQL::db()->connection->last_insert_id();
                 }
                 if ($arg->after_insert()) {
                     $arg->after_save();
                 }
             }
         }
     }
     return $rc;
 }
예제 #4
0
파일: PostgreSQL.php 프로젝트: techart/tao
 /**
  * Преобразует значение в пригодный вид для вставки в sql запрос
  *
  * @param  $value
  *
  * @return mixed
  */
 public function cast_parameter($value)
 {
     switch (true) {
         case $value instanceof Time_DateTime:
             return $value->format(Time::FMT_DEFAULT);
         case Core_Types::is_array($value):
             $str = '{';
             foreach ($value as $e) {
                 $str .= ($str == '{' ? '' : ',') . '"' . ($this->is_castable_parameter($e) ? $this->cast_parameter($e) : $e) . '"';
             }
             return $str . '}';
         case !is_object($value) && (string) (int) $value === (string) $value:
             return (int) $value;
         default:
             return $value;
     }
 }
예제 #5
0
파일: Core.php 프로젝트: techart/tao
 /**
  * Выполняет конфигурирование модуля
  *
  * @param       $module
  * @param array $config
  */
 public static function configure($module, array $config = array())
 {
     foreach (Core_Types::is_array($module) ? $module : array($module => $config) as $k => $v) {
         self::$loader->configure($k, $v);
     }
 }
예제 #6
0
파일: ORM.php 프로젝트: techart/tao
 /**
  * Формирует общий список значений параметров с учетом значений параметров родительских мапперов
  *
  * @param string $expr
  * @param mixed  $parms
  *
  * @return DB_ORM_SQLMapper
  */
 protected function collect_binds($expr, $parms)
 {
     $adapter = $this->connection->adapter;
     if ($adapter->is_castable_parameter($parms)) {
         $parms = $adapter->cast_parameter($parms);
     }
     if ($match = Core_Regexps::match_all('{(?::([a-zA-Z_0-9]+))}', $expr)) {
         foreach ($match[1] as $no => $name) {
             if (Core_Types::is_array($parms) || $parms instanceof ArrayAccess) {
                 $this->binds[$name] = $adapter->cast_parameter(isset($parms[$name]) ? $parms[$name] : $parms[$no]);
             } elseif (is_object($parms)) {
                 $this->binds[$name] = $adapter->cast_parameter($parms->{$name});
             } else {
                 $this->binds[$name] = $adapter->cast_parameter($parms);
             }
         }
     }
     return $this;
 }
예제 #7
0
파일: Curl.php 프로젝트: techart/tao
 protected function encode_parameters(&$parms)
 {
     $result = '';
     if ($parms && (Core_Types::is_array($parms) || $parms instanceof Traversable)) {
         foreach ($parms as $k => $v) {
             $result .= ($result ? '&' : '') . urlencode($k) . '=' . urlencode($v);
         }
     }
     return $result;
 }
예제 #8
0
파일: Data.php 프로젝트: techart/tao
 protected static function convert_arrays(&$source, Data_Hash $target)
 {
     foreach ($source as $k => &$v) {
         if (Core_Types::is_array($v)) {
             self::convert_arrays($v, $target[$k] = Data::Hash());
         } else {
             $target[$k] = $v;
         }
     }
     return $target;
 }
예제 #9
0
파일: Proc.php 프로젝트: techart/tao
 /**
  * Добавляет/устанавливает переменный окружения
  *
  * @param array $env
  *
  * @return Proc_Process
  */
 public function environment(array $env)
 {
     if (!Core_Types::is_array($this->environment)) {
         $this->environment = array();
     }
     foreach ($env as $k => $v) {
         $this->environment[$k] = (string) $v;
     }
     return $this;
 }
예제 #10
0
파일: DB.php 프로젝트: techart/tao
 /**
  * Возвращает все строки результата
  *
  * @params string|array|ArrayAccess $prototype Прототип объекта записи или имя класса такого объекта
  * @params mixed $key  свойство объекта $row
  *
  * @return mixed
  * @throws Core_InvalidArgumentTypeException Не верный $prototype
  */
 public function fetch_all($prototype = null, $key = null)
 {
     switch (true) {
         case $prototype == null:
             $result = Core::make(DB::option('collection_class'));
             break;
         case Core_Types::is_string($prototype):
             $result = Core_Types::reflection_for($prototype)->newInstance();
             break;
         case Core_Types::is_array($prototype):
             $result = $prototype;
             break;
         case $prototype instanceof ArrayAccess:
             $result = clone $prototype;
             break;
         default:
             throw new Core_InvalidArgumentTypeException('prototype', $prototype);
     }
     while ($row = $this->fetch()) {
         if (is_null($key) || !isset($row[$key])) {
             $result[] = $row;
         } else {
             $result[$row[$key]] = $row;
         }
     }
     return $result;
 }
예제 #11
0
파일: Chart.php 프로젝트: techart/tao
 /**
  * @return array
  */
 public function as_array()
 {
     $parms = array();
     foreach ($this->opts as $opt => $val) {
         switch ($opt) {
             case 'chs':
                 // size
             // size
             case 'chtt':
                 // title
             // title
             case 'chtm':
                 // geo area for map
                 $parms[$opt] = $val;
                 break;
             case 'chld':
                 // map countries
                 $parms[$opt] = implode('', $val);
                 break;
             case 'chp':
                 //bar zero_lenes or pie orientatio
                 $parms[$opt] = Core_Types::is_array($val) ? implode(',', array_map(array($this, 'str_to_validurl'), $val)) : $val;
                 break;
             case 'chdl':
                 // legend
             // legend
             case 'chl':
                 // pie chart labels or meter label or QR text encode
             // pie chart labels or meter label or QR text encode
             case 'chls':
                 // line style
                 $parms[$opt] = implode('|', array_map(array($this, 'str_to_validurl'), $val));
                 break;
             case 'chco':
                 // colors
             // colors
             case 'chxt':
                 // axes types
             // axes types
             case 'chg':
                 // grid lines
             // grid lines
             case 'chbh':
                 // bar spacing
                 $parms[$opt] = implode(',', $val);
                 break;
             case 'chm':
                 // markers
                 $m = array();
                 foreach ($val as $v) {
                     $m[] = implode(',', $v);
                 }
                 $parms[$opt] = implode('|', $m);
                 break;
             case 'chxtc':
                 // axes ticks
                 $t = array();
                 foreach ($val as $k => $v) {
                     $t[] = "{$k},{$v}";
                 }
                 $parms[$opt] = implode('|', $t);
                 break;
             case 'chxl':
                 // axes labels
                 $t = array();
                 foreach ($val as $k => $v) {
                     $t[] = "{$k}:|" . implode('|', array_map(array($this, 'str_to_validurl'), $v));
                 }
                 $parms[$opt] = implode('|', $t);
                 break;
             case 'chxp':
                 // axes labels positions
             // axes labels positions
             case 'chxs':
                 // axes styles
             // axes styles
             case 'chxr':
                 // axes ranges
                 $t = array();
                 foreach ($val as $k => $v) {
                     $t[] = "{$k}," . implode(',', array_map(array($this, 'str_to_validurl'), $v));
                 }
                 $parms[$opt] = implode('|', $t);
                 break;
             case '_ss':
                 // scatter sizes
                 $scatter_sizes = $this->encoder->encode_series($val, 0, 100);
                 break;
         }
     }
     if ($this->match_types('p,p3,pc,bhs,bvs,bhg,bvg,map,t,gom')) {
         $this->range->bottom = 0;
     }
     if ($this->match_types('gom')) {
         $this->range->top = 100;
     }
     $parms['cht'] = $this->type;
     $parms['chd'] = $this->encoder->encode_all($this->data, $this->range) . ($scatter_sizes ? $this->encoder->separator . $scatter_sizes : '');
     return $parms;
 }
예제 #12
0
파일: Validation.php 프로젝트: techart/tao
 /**
  * Возвращает значение атрибута объекта.
  *
  * @param mixed   $object       Если не является объектом или массивом, то становится возвращаемым значением.
  * @param string  $attribute    имя атрибута
  * @param boolean $array_access флаг индексного доступа к объекту
  *
  * @return mixed
  */
 protected function value_of_attribute($object, $attribute, $array_access = false)
 {
     return Core_Types::is_object($object) ? $array_access ? $object[$attribute] : $object->{$attribute} : (Core_Types::is_array($object) ? $object[$attribute] : $object);
 }
예제 #13
0
파일: Rest.php 프로젝트: techart/tao
 /**
  * @param string $name
  * @param array  $args
  *
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (!Core_Regexps::match('{_url$}', $name)) {
         throw new Core_MissingMethodException($name);
     }
     $name = Core_Strings::replace($name, 'single_', 'single-');
     $url = '';
     $args = Core_Arrays::reverse($args);
     $parms = Core_Types::is_array($args[0]) ? Core_Arrays::shift($args) : array();
     $parts = Core_Arrays::reverse(Core_Strings::split_by('_', Core_Regexps::replace('{_url$}', '', $name)));
     $last_idx = count($parts) - 1;
     $target = false;
     foreach ($parts as $idx => $part) {
         $part = Core_Strings::replace($part, '-', '_');
         if ($target) {
             if (isset($this->single_names[$part])) {
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($arg = Core_Arrays::shift($args)) ? $arg->id : (string) $arg) . $url;
             } elseif ($idx == $last_idx && (isset($this->resources[$target]) && isset($this->resources[$target]['collection']) && isset($this->resources[$target]['collection'][$part])) || isset($this->single_names[$target]) && isset($this->resources[$this->single_names[$target]]['instance']) && isset($this->resources[$this->single_names[$target]]['instance'][$part])) {
                 $url .= "/{$part}";
             } else {
                 throw new Core_MissingMethodException($name);
             }
         } else {
             if (isset($this->resources[$part])) {
                 $url = "/{$part}{$url}";
                 $target = $part;
             } elseif (isset($this->single_names[$part])) {
                 $id = Core_Arrays::shift($args);
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($id) ? $id->id : (string) $id) . $url;
                 $target = $part;
             } else {
                 throw new Core_MissingMethodException($name);
             }
         }
     }
     return $this->add_keyword_parameters($this->add_path($url) . (isset($args[0]) ? '.' . $args[0] : ".{$this->default_format}"), $parms);
 }
예제 #14
0
파일: Commons.php 프로젝트: techart/tao
 /**
  * Заполняет значение поля из источника $source
  *
  * @param  $source
  */
 public function load($source)
 {
     if (isset($source[$this->name]) && (Core_Types::is_array($source[$this->name]) || $source[$this->name] instanceof ArrayAccess)) {
         $parts = array();
         foreach (array('year' => false, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0) as $k => $v) {
             if (isset($source[$this->name][$k]) && $source[$this->name][$k] != '') {
                 $parts[$k] = (int) $source[$this->name][$k];
             } elseif ($v !== false) {
                 $parts[$k] = $v;
             } else {
                 $parts = false;
                 break;
             }
         }
         $this->value = $parts ? Time::compose($parts['year'], $parts['month'], $parts['day'], $parts['hour'], $parts['minute']) : null;
     }
     return true;
 }