Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 public function genModelFile($dir, $table, $model = '', $ns = '')
 {
     $dir = rtrim($dir, DIRECTORY_SEPARATOR);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $filename = $dir . DIRECTORY_SEPARATOR . $model . '.php';
     if (class_exists($ns . '\\' . $model)) {
         return $filename;
     }
     $data = $this->readFields($table);
     $data['name'] = $model;
     $data['ns'] = $ns;
     $data['mixin'] = null;
     $data['behaviors_in_mixin'] = false;
     $mixin = $ns . '\\' . $model . 'Mixin';
     if (trait_exists($mixin, true)) {
         foreach ($data['fields'] as $field => $default) {
             if (property_exists($mixin, $field)) {
                 unset($data['fields'][$field]);
             }
         }
         $data['mixin'] = $mixin;
         $data['behaviors_in_mixin'] = method_exists($mixin, 'getBehaviors');
     }
     $tpl = new Templater(__DIR__);
     $content = $tpl->render('model_tpl.php', $data);
     $content = "<?php\n\n" . trim($content);
     file_put_contents($filename, $content);
     return $filename;
 }