public function bind(Database &$db, $table, $joins = null) { if (empty($this->foreign_key)) { $this->foreign_key = Inflect::singularize($table) . '_id'; } return parent::bind($db, $table, $joins); }
public static function generateModel(Database &$db, $table, $name = '', $ns = '', $singular = false) { $data = $db->readFields($table); if (empty($name)) { $name = $singular ? Inflect::singularize($table) : $table; $name = Inflect::camelize($name); } $dir = APP_ROOT . '/models'; if ($ns) { $dir .= '/' . str_replace('\\', '/', trim($ns)); } if (!file_exists($dir)) { mkdir($dir, 0777, true); } $filename = "{$dir}/{$name}.php"; $data['name'] = $name; $data['ns'] = $ns; $data['protecteds'] = self::$protected_fields; $tpl = new Templater(SRC_ROOT); ob_start(); $tpl->render('model_tpl.php', $data); $content = "<?php\n\n" . trim(ob_get_clean()); file_put_contents($filename, $content); return $filename; }
public function getForeignKey($name = '') { if (empty($this->foreign_key)) { $table_name = $this->query->getTable(); $this->foreign_key = Inflect::singularize($table_name) . '_id'; } return $this->foreign_key; }
public function addTable($table, &$model, &$ns = '') { if (empty($model)) { $model = $this->singular ? Inflect::singularize($table) : $table; $model = Inflect::camelize($model); } $ns = trim($ns, '\\'); $ns_model = empty($ns) ? $model : sprintf('\\%s\\%s', $ns, $model); $this->tables[$table] = $ns_model; }
public function run() { if (php_sapi_name() !== 'cli') { // 仅运行于命令行模式 return; } if ($_SERVER['argc'] < 2) { //参数不足 return; } $argv = $_SERVER['argv']; $cmdfile = array_shift($argv); $name = array_shift($argv); $class = Inflect::camelize($name) . 'Command'; @(require_once $class . '.php'); if (class_exists($class)) { $object = new $class($this, $cmdfile, $argv); return $object->execute(); } }
public function run() { if (php_sapi_name() !== 'cli') { // 仅运行于命令行模式 return; } if ($_SERVER['argc'] < 2) { //参数不足 return; } $argv = $_SERVER['argv']; $cmdfile = array_shift($argv); $name = array_shift($argv); $class = Inflect::camelize($name) . 'Command'; require_once $class . '.php'; if ($this->auto_ns) { $class = self::getDeclaredClass($class); } else { $class = class_exists($class) ? $class : null; } if ($class) { $object = new $class($this, $cmdfile, $argv); return $object->execute(); } }
static function generateModel(Database &$W, $M, $A = '', $t = '', $wE = false) { $T = $W->readFields($M); if (empty($A)) { $A = $wE ? Inflect::singularize($M) : $M; $A = Inflect::camelize($A); } $Q = APP_ROOT . '/models'; if ($t) { $Q .= '/' . str_replace('\\', '/', trim($t)); } if (!file_exists($Q)) { mkdir($Q, 0777, true); } $R = "{$Q}/{$A}.php"; $T['name'] = $A; $T['ns'] = $t; $T['protecteds'] = self::$protected_fields; $HC = new Templater(SRC_ROOT); ob_start(); $HC->render('model_tpl.php', $T); $i = "<?php\n\n" . trim(ob_get_clean()); file_put_contents($R, $i); return $R; }
public function test01Flatten() { foreach ($this->samples as $key => $value) { $this->assertEquals($value, Inflect::flatten($key)); } }