示例#1
0
 public function __construct(Table $table)
 {
     $this->table = $table;
     foreach ($this->default as $key => $value) {
         if (method_exists($this, $method = 'token' . C::camelhead($key))) {
             $this->{$method}();
         }
     }
     foreach (C::config('fixed') as $key => $value) {
         $this->default[$key] = $value;
     }
     foreach (C::config('path') as $key => $value) {
         $path = 'path_' . $key;
         $this->{$path} = C::fixslashes($value);
     }
     $this->run();
 }
示例#2
0
 public function __construct($dir)
 {
     $c = C::config();
     C::start('Setting project directory to: ' . $dir . '...');
     if (file_exists(realpath($dir))) {
         $dir = realpath($dir);
     } else {
         !mkdir($dir, 0755, true) || ($dir = realpath($dir));
     }
     $this->tar = C::fixslashes($dir);
     is_dir($this->tar) || C::error('invalid dir');
     C::finish();
     if ($c['server']) {
         C::start('Setting project link: ...');
         isset($c['server']['host'], $c['server']['path']) || C::error('invalid server config');
         $this->rlink = C::fixslashes($c['server']['host']) . str_replace(C::fixslashes($c['server']['path']), '', $this->tar);
         C::finish();
     }
     C::start('Checking config...');
     isset($c['generator']['template']) || C::error('no generator.template');
     isset($c['database']['name']) || C::error('no database.name');
     isset($c['database']['host']) || C::error('no database.host');
     isset($c['database']['username']) || C::error('no database.username');
     isset($c['database']['password']) || C::error('no database.password');
     isset($c['fixed']) || C::error('no fixed');
     isset($c['files']) || C::error('no files');
     C::finish();
     $gen_temp = C::config('generator')['template'];
     !is_array($gen_temp) || ($gen_temp = end($gen_temp));
     C::start('Setting template directory to: ' . $gen_temp . '...');
     file_exists($gen_temp) || C::error('fail');
     $this->dir = C::fixslashes($gen_temp);
     C::finish();
     C::start('Checking lookup path...');
     $paths = C::config('path') ?: array();
     foreach ($paths as $key => $value) {
         $paths[$key] = C::fixslashes($value);
     }
     $this->path = $paths;
     C::config('path', $paths);
     C::finish();
     C::start('Checking files...', 0, 1);
     ob_start();
     $ok = true;
     $nss = array();
     foreach (C::config('files') as $key => $value) {
         C::start('Checking: ' . $key . '...');
         isset($value['name']) || C::error('no key name');
         $msg = 'OK';
         $path = isset($value['path']) ? C::fixslashes($value['path']) : '';
         $e = C::ext($value['name']);
         $path || !isset($paths[$e]) || ($path = $paths[$e]);
         if (isset($value['template'])) {
             $ok = file_exists($this->dir . $value['template']);
             $ok || ($msg = 'file not exists');
         } elseif (isset($value['copyConfig'])) {
             $ok = isset($c[$key]);
             $ok || ($msg = 'no ' . $key . ' in config');
         }
         !$path || ($nss[$key . '_namespace'] = rtrim(strtr($path, '/', '\\'), '\\'));
         C::finish($msg);
         if ($ok) {
             continue;
         } else {
             break;
         }
     }
     C::config('namespaces', $nss);
     C::shiftAll(ob_get_clean(), 1);
     $ok || C::error('Failed');
     C::finish();
     if (isset($c['composer'], $c['composer']['path'])) {
         C::start('Checking composer...');
         exec($c['composer']['path'] . ' -v', $tmp);
         isset($tmp[7]) || C::error('Composer was not installed');
         $this->cmp = $c['composer']['path'];
         !isset($c['composer']['command']) || ($this->cmpCmd = $c['composer']['command']);
         C::finish();
     }
     if (isset($c['generator']['token'])) {
         $this->token = $c['generator']['token'];
     }
     $this->str = $this->dir . $this->str;
     if (isset($c['generator']['structure'])) {
         C::start('Checking structure...');
         if (file_exists($c['generator']['structure'])) {
             $this->str = $c['generator']['structure'];
         } elseif (file_exists($this->dir . $c['generator']['structure'])) {
             $this->str = $this->dir . $c['generator']['structure'];
         } else {
             C::error('Structure doesn\'t exists');
         }
         C::finish();
     }
     C::start('Construct hole database...', 0, 1);
     ob_start();
     C::set('db', new Database($c['database']));
     C::shiftAll(ob_get_clean(), 1);
     C::finish();
     $this->tempDir = C::fixslashes(sys_get_temp_dir()) . 'crudgen/';
 }