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; }
/** * Приводит имя к виду соответствующему почтовому стандарту * * @param string $name * * @return string */ protected function canonicalize($name) { $parts = Core_Arrays::map('return strtolower($x);', Core_Strings::split_by('-', trim($name))); foreach ($parts as &$part) { $part = isset(self::$acronyms[$part]) ? self::$acronyms[$part] : (preg_match('{[aeiouyAEIOUY]}', $part) ? ucfirst($part) : strtoupper($part)); } return Core_Arrays::join_with('-', $parts); }
public function test_map() { $this->assertEquals(Core_Arrays::map('return "$x"."1";', $arr = array(1, 2, 3)), array('11', '21', '31')); }
protected function http_to_string($name, $content) { return sprintf("<meta http-equiv=\"%s\" content=\"%s\" />\n", htmlspecialchars(Core_Arrays::join_with('-', Core_Arrays::map('return ucfirst(strtolower($x));', Core_Strings::split_by('_', $name)))), htmlspecialchars($content)); }