示例#1
0
文件: cli.php 项目: netspencer/fuel
 public static function init($args)
 {
     try {
         if (!isset($args[1])) {
             static::help();
             return;
         }
         switch ($args[1]) {
             case 'g':
             case 'generate':
                 switch ($args[2]) {
                     case 'controller':
                     case 'model':
                     case 'view':
                     case 'views':
                     case 'migration':
                         call_user_func('Oil\\Generate::' . $args[2], array_slice($args, 3));
                         break;
                     case 'scaffold':
                         call_user_func('Oil\\Scaffold::generate', array_slice($args, 3));
                         break;
                     default:
                         Generate::help();
                 }
                 break;
             case 'c':
             case 'console':
                 new Console();
             case 'r':
             case 'refine':
                 $task = isset($args[2]) ? $args[2] : null;
                 call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                 break;
             case 'p':
             case 'package':
                 switch ($args[2]) {
                     case 'install':
                     case 'uninstall':
                         call_user_func_array('Oil\\Package::' . $args[2], array_slice($args, 3));
                         break;
                     default:
                         Package::help();
                 }
                 break;
             case '-v':
             case '--version':
                 \Cli::write('Fuel: ' . \Fuel::VERSION);
                 break;
             case 'test':
                 \Fuel::add_package('octane');
                 call_user_func('\\Fuel\\Octane\\Tests::run_' . $args[2], array_slice($args, 3));
                 break;
             default:
                 static::help();
         }
     } catch (Exception $e) {
         \Cli::write(\Cli::color('Error: ' . $e->getMessage(), 'light_red'));
         \Cli::beep();
     }
 }
示例#2
0
 public static function run($task, $args)
 {
     // Make sure something is set
     if ($task === null or $task === 'help') {
         static::help();
         return;
     }
     // Just call and run() or did they have a specific method in mind?
     list($task, $method) = array_pad(explode(':', $task), 2, 'run');
     $task = ucfirst(strtolower($task));
     // Find the task
     if (!($file = \Fuel::find_file('tasks', $task))) {
         throw new Exception(sprintf('Task "%s" does not exist.', $task));
         return;
     }
     require $file;
     $task = '\\Fuel\\Tasks\\' . $task;
     $new_task = new $task();
     // The help option hs been called, so call help instead
     if (\Cli::option('help') && is_callable(array($new_task, 'help'))) {
         $method = 'help';
     }
     if ($return = call_user_func_array(array($new_task, $method), $args)) {
         \Cli::write($return);
     }
 }
示例#3
0
文件: error.php 项目: netspencer/fuel
 public static function show_php_error(\Exception $e)
 {
     $data['type'] = get_class($e);
     $data['severity'] = $e->getCode();
     $data['message'] = $e->getMessage();
     $data['filepath'] = $e->getFile();
     $data['error_line'] = $e->getLine();
     $data['backtrace'] = $e->getTrace();
     $data['severity'] = !isset(static::$levels[$data['severity']]) ? $data['severity'] : static::$levels[$data['severity']];
     if (\Fuel::$is_cli) {
         \Cli::write(\Cli::color($data['severity'] . ' - ' . $data['message'] . ' in ' . \Fuel::clean_path($data['filepath']) . ' on line ' . $data['error_line'], 'red'));
         return;
     }
     $debug_lines = array();
     foreach ($data['backtrace'] as $key => $trace) {
         if (!isset($trace['file'])) {
             unset($data['backtrace'][$key]);
         } elseif ($trace['file'] == COREPATH . 'classes/error.php') {
             unset($data['backtrace'][$key]);
         }
     }
     $debug_lines = array('file' => $data['filepath'], 'line' => $data['error_line']);
     $data['severity'] = !isset(static::$levels[$data['severity']]) ? $data['severity'] : static::$levels[$data['severity']];
     $data['debug_lines'] = \Debug::file_lines($debug_lines['file'], $debug_lines['line']);
     $data['filepath'] = \Fuel::clean_path($debug_lines['file']);
     $data['filepath'] = str_replace("\\", "/", $data['filepath']);
     $data['error_line'] = $debug_lines['line'];
     echo \View::factory('errors' . DS . 'php_error', $data);
 }
示例#4
0
文件: refine.php 项目: nasumi/fuel
	public static function run($task, $args)
	{
		// Just call and run() or did they have a specific method in mind?
		list($task, $method)=array_pad(explode(':', $task), 2, 'run');

		$task = ucfirst(strtolower($task));

		if ( ! $file = \Fuel::find_file('tasks', $task))
		{
			throw new \Exception('Well that didnt work...');
			return;
		}

		require $file;

		$task = '\\Fuel\\Tasks\\'.$task;

		$new_task = new $task;

		// The help option hs been called, so call help instead
		if (\Cli::option('help') && is_callable(array($new_task, 'help')))
		{
			$method = 'help';
		}

		if ($return = call_user_func_array(array($new_task, $method), $args))
		{
			\Cli::write($return);
		}
	}
示例#5
0
文件: sqs.php 项目: inoue2302/phplib
 public static function receive_sqs_for_multi()
 {
     $t1 = microtime(true);
     $pcount = 3;
     $pstack = array();
     for ($i = 1; $i <= $pcount; $i++) {
         $pid = pcntl_fork();
         if ($pid == -1) {
             die('fork できません');
         } else {
             if ($pid) {
                 // 親プロセスの場合
                 $pstack[$pid] = true;
                 if (count($pstack) >= $pcount) {
                     unset($pstack[pcntl_waitpid(-1, $status, WUNTRACED)]);
                 }
             } else {
                 sleep(1);
                 self::receive_sqs_message();
                 exit;
                 //処理が終わったらexitする。
             }
         }
     }
     //先に処理が進んでしまうので待つ
     while (count($pstack) > 0) {
         unset($pstack[pcntl_waitpid(-1, $status, WUNTRACED)]);
     }
     $t2 = microtime(true);
     $process_time = $t2 - $t1;
     \Cli::write("Process time = " . $process_time);
 }
示例#6
0
 /**
  * create the sessions table
  * php oil r session:create
  */
 public static function create()
 {
     // load session config
     \Config::load('session', true);
     if (\Config::get('session.driver') != 'db') {
         // prompt the user to confirm they want to remove the table.
         $continue = \Cli::prompt(\Cli::color('Your current driver type is not set db. Would you like to continue and add the sessions table anyway?', 'yellow'), array('y', 'n'));
         if ($continue === 'n') {
             return \Cli::color('Database sessions table was not created.', 'red');
         }
     }
     if (\DBUtil::table_exists(\Config::get('session.db.table'))) {
         return \Cli::write('Session table already exists.');
     }
     // create the session table using the table name from the config file
     \DBUtil::create_table(\Config::get('session.db.table'), array('session_id' => array('constraint' => 40, 'type' => 'varchar'), 'previous_id' => array('constraint' => 40, 'type' => 'varchar'), 'user_agent' => array('type' => 'text', 'null' => false), 'ip_hash' => array('constraint' => 32, 'type' => 'char'), 'created' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'updated' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'payload' => array('type' => 'longtext')), array('session_id'), false, 'InnoDB', \Config::get('db.default.charset'));
     // make previous_id a unique_key. speeds up query and prevents duplicate id's
     \DBUtil::create_index(\Config::get('session.db.table'), 'previous_id', 'previous_id', 'unique');
     if (\Config::get('session.driver') === 'db') {
         // return success message.
         return \Cli::color('Success! Your session table has been created!', 'green');
     } else {
         // return success message notifying that the driver is not db.
         return \Cli::color('Success! Your session table has been created! Your current session driver type is set to ' . \Config::get('session.driver') . '. In order to use the table you just created to manage your sessions, you will need to set your driver type to "db" in your session config file.', 'green');
     }
 }
 public function run($region_id, $category = false)
 {
     if ($this->spider->scanRegion($region_id, $category)) {
         \Cli::write('Scan finished.');
     } else {
         \Cli::error('No region found / Invalid region id');
     }
 }
 public function foursquare_venue($venue_id, $cycles = 25)
 {
     if ($this->spider->updateFoursquareVenue($venue_id, $cycles)) {
         \Cli::write('Scan finished.');
     } else {
         \Cli::error('No region found / Invalid region id');
     }
 }
示例#9
0
 /**
  * Sync assets to CDN
  */
 public function sync()
 {
     \Cli::write("Syncing user files...");
     Storage::syncFileFields();
     \Cli::write("Syncing static assets...");
     Storage::syncAssets();
     \Cli::write("Done!", 'green');
 }
示例#10
0
 /**
  *
  * @return string
  */
 public function set_reservable()
 {
     \Config::load("base");
     $taskName = __METHOD__;
     \Cli::write(\TaskUtil::decorate(\Config::get("system.code") . " {$taskName} START"));
     $model = new \Model_Task_Setreservable();
     $model->run();
     \Cli::write(\TaskUtil::decorate(\Config::get("system.code") . " {$taskName} END"));
 }
示例#11
0
 public static function down()
 {
     \Config::load('migrate', true);
     $version = \Config::get('migrate.version') - 1;
     if (\Migrate::version($version)) {
         static::_update_version($version);
         \Cli::write('Migrated to version: ' . $version . '.', 'green');
     }
 }
示例#12
0
 /**
  *
  * @return string
  */
 public function run($type)
 {
     \Config::load("base");
     $taskName = "DATA MIGRATION";
     \Cli::write(\TaskUtil::decorate(\Config::get("system.code") . " {$taskName} START"));
     $model = new \Model_Task_Datamigration();
     $model->run($type);
     \Cli::write(\TaskUtil::decorate(\Config::get("system.code") . " {$taskName} END"));
 }
 private function main()
 {
     \Cli::write(sprintf('Fuel %s - PHP %s (%s) (%s) [%s]', \Fuel::VERSION, phpversion(), php_sapi_name(), self::build_date(), PHP_OS));
     // Loop until they break it
     while (TRUE) {
         if (\Cli::$readline_support) {
             readline_completion_function(array(__CLASS__, 'tab_complete'));
         }
         if (!($__line = rtrim(trim(trim(\Cli::input('>>> ')), PHP_EOL), ';'))) {
             continue;
         }
         if ($__line == 'quit') {
             break;
         }
         // Add this line to history
         //$this->history[] = array_slice($this->history, 0, -99) + array($line);
         if (\Cli::$readline_support) {
             readline_add_history($__line);
         }
         if (self::is_immediate($__line)) {
             $__line = "return ({$__line})";
         }
         ob_start();
         // Unset the previous line and execute the new one
         $random_ret = \Str::random();
         try {
             $ret = eval("unset(\$__line); {$__line};");
         } catch (\Exception $e) {
             $ret = $random_ret;
             $__line = $e->getMessage();
         }
         // Error was returned
         if ($ret === $random_ret) {
             \Cli::error('Parse Error - ' . $__line);
             \Cli::beep();
         }
         if (ob_get_length() == 0) {
             if (is_bool($ret)) {
                 echo $ret ? 'true' : 'false';
             } elseif (is_string($ret)) {
                 echo addcslashes($ret, "....ÿ");
             } elseif (!is_null($ret)) {
                 var_export($ret);
             }
         }
         unset($ret);
         $out = ob_get_contents();
         ob_end_clean();
         if (strlen($out) > 0 && substr($out, -1) != PHP_EOL) {
             $out .= PHP_EOL;
         }
         echo $out;
         unset($out);
     }
 }
示例#14
0
 /**
  * Processes customer statistics.
  *
  * @return void
  */
 public static function customer()
 {
     if (!($task = \Service_Statistic_Task::begin('customer'))) {
         return false;
     }
     $data = array();
     $date_ranges = \Service_Statistic_Task::date_ranges('customer');
     foreach ($date_ranges as $range) {
         $begin = \Date::create_from_string($range['begin'], 'mysql');
         $end = \Date::create_from_string($range['end'], 'mysql');
         $date = $begin->format('mysql_date');
         $data[$date] = array();
         $created = \Service_Customer_Statistic::created($begin, $end);
         foreach ($created as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'created', 'value' => $result['total']);
         }
         $deleted = \Service_Customer_Statistic::deleted($begin, $end);
         foreach ($deleted as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'deleted', 'value' => $result['total']);
         }
         $subscribed = \Service_Customer_Statistic::subscribed($begin, $end);
         foreach ($subscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'subscribed', 'value' => $result['total']);
         }
         $unsubscribed = \Service_Customer_Statistic::unsubscribed($begin, $end);
         foreach ($unsubscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'unsubscribed', 'value' => $result['total']);
         }
         $total = \Service_Customer_Statistic::total($end);
         foreach ($total as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total', 'value' => $result['total']);
         }
         $total_active = \Service_Customer_Statistic::total_active($end);
         foreach ($total_active as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total_active', 'value' => $result['total']);
         }
         $total_subscribed = \Service_Customer_Statistic::total_subscribed($end);
         foreach ($total_subscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total_subscribed', 'value' => $result['total']);
         }
     }
     // Save the queried results as statistics.
     foreach ($data as $date => $results) {
         $date = \Date::create_from_string($date, 'mysql_date');
         foreach ($results as $result) {
             $seller = \Service_Seller::find_one($result['seller_id']);
             if (!\Service_Statistic::create($seller, 'customer', $date, $result['name'], $result['value'])) {
                 \Service_Statistic_Task::end($task, 'failed', "Error creating customer.{$result['name']} statistic for seller {$seller->name}.");
                 return;
             }
         }
     }
     \Service_Statistic_Task::end($task);
     \Cli::write('Customer Statistical Calculations Complete', 'green');
 }
示例#15
0
 public static function run()
 {
     $writable_paths = array(APPPATH . 'cache', APPPATH . 'logs', APPPATH . 'tmp', APPPATH . 'config');
     foreach ($writable_paths as $path) {
         if (@chmod($path, 0777)) {
             \Cli::write("\t" . 'Made writable: ' . $path, 'green');
         } else {
             \Cli::write("\t" . 'Failed to make writable: ' . $path, 'red');
         }
     }
 }
 public function up()
 {
     // create default admin user
     $default_password = "******";
     $default_pass_hash = \Auth::instance()->hash_password($default_password);
     for ($i = 1; $i <= 100; $i++) {
         list($id, $row_affected) = \DB::insert('users')->set(array('username' => 'user' . $i, 'password' => $default_pass_hash, 'email' => 'user' . $i . '@somewhere.com', 'group' => $i % 3 == 0 ? 50 : 1, 'last_login' => '', 'login_hash' => '', 'profile_fields' => ''))->execute();
         if ($row_affected <= 0) {
             \Cli::write("failed to user account: user" . $i);
         }
     }
 }
示例#17
0
 public function add($keyword)
 {
     if (!$keyword) {
         \Cli::error('Please provide keyword');
         return;
     }
     if (!\Collection\Keyword::addKeywordToDB($keyword)) {
         \Cli::error('Keyword already exists');
         return;
     }
     \Cli::write('Keyword added.');
 }
示例#18
0
 /**
  * {@inheritdocs}
  */
 protected function write(array $record)
 {
     if (\Fuel::$is_cli) {
         $colors = \Arr::get($this->levels, $record['level'], array('white', null));
         list($fg, $bg) = $colors;
         $message = \Cli::color((string) $record['formatted'], $fg, $bg);
         if ($level >= 300) {
             \Cli::error($message);
         } else {
             \Cli::write($message);
         }
     }
 }
示例#19
0
 public static function down()
 {
     \Config::load('migrations', true);
     if (($version = \Config::get('migrations.version') - 1) < 0) {
         throw new \Oil\Exception('You are already on the first migration.');
     }
     if (\Migrate::version($version)) {
         static::_update_version($version);
         \Cli::write("Migrated to version: {$version}.", 'green');
     } else {
         throw new \Oil\Exception("Migration {$version} does not exist. How did you get here?");
     }
 }
示例#20
0
 public function __construct()
 {
     $shutdown = function () {
         $quiet = \Cli::option('quiet', \Cli::option('q', false));
         $quiet or \Cli::write(PHP_EOL . 'Worker ' . getmypid() . ' is stopping', 'red');
     };
     try {
         pcntl_signal(SIGINT, $shutdown);
         pcntl_signal(SIGINT, function () {
             exit;
         });
     } catch (\PhpErrorException $e) {
     }
     \Event::register('shutdown', $shutdown);
 }
 public function up()
 {
     \DBUtil::create_table('users', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'username' => array('constraint' => 255, 'type' => 'varchar'), 'password' => array('constraint' => 255, 'type' => 'varchar'), 'email' => array('constraint' => 255, 'type' => 'varchar'), 'profile_fields' => array('type' => 'text'), 'group' => array('constraint' => 11, 'type' => 'int'), 'last_login' => array('constraint' => 20, 'type' => 'int'), 'login_hash' => array('constraint' => 255, 'type' => 'varchar')), array('id'));
     // add an admin account
     $admin_username = "******";
     $admin_password = "******";
     $admin_pass_hash = \Auth::instance()->hash_password($admin_password);
     $admin_email = "*****@*****.**";
     $users = \Model_User::factory(array('username' => $admin_username, 'password' => $admin_pass_hash, 'email' => $admin_email, 'profile_fields' => '', 'group' => '', 'last_login' => '', 'login_hash' => ''));
     if ($users and $users->save()) {
         \Cli::write("added admin account");
     } else {
         \Cli::write("failed to add admin account");
     }
 }
示例#22
0
    /**
     * Show help
     *
     * Usage (from command line):
     * 
     * php oil r ratchet:help
     */
    public static function help()
    {
        $output = <<<HELP

Description:
  Task of Ratchet Server

Commands:
  php oil refine ratchet:ws <class_name>
  php oil refine ratchet:wamp <class_name>
  php oil refine ratchet:help

HELP;
        \Cli::write($output);
    }
示例#23
0
 private function main()
 {
     echo sprintf('Fuel %s - PHP %s (%s) (%s) [%s]', \Fuel::VERSION, phpversion(), php_sapi_name(), self::build_date(), PHP_OS) . PHP_EOL;
     // Loop until they break it
     while (TRUE) {
         echo ">>> ";
         if (!($__line = rtrim(trim(trim(fgets(STDIN)), PHP_EOL), ';'))) {
             continue;
         }
         if ($__line == 'quit') {
             break;
         }
         if (self::is_immediate($__line)) {
             $__line = "return ({$__line})";
         }
         ob_start();
         // Unset the previous line and execute the new one
         $ret = eval("unset(\$__line); {$__line};");
         // Error was returned
         if ($ret === false) {
             \Cli::write(\Cli::color('Parse Error - ' . $__line, 'light_red'));
             \Cli::beep();
         }
         if (ob_get_length() == 0) {
             if (is_bool($ret)) {
                 echo $ret ? "true" : "false";
             } else {
                 if (is_string($ret)) {
                     echo addcslashes($ret, "....ÿ");
                 } else {
                     if (!is_null($ret)) {
                         var_export($ret);
                     }
                 }
             }
         }
         unset($ret);
         $out = ob_get_contents();
         ob_end_clean();
         if (strlen($out) > 0 && substr($out, -1) != PHP_EOL) {
             $out .= PHP_EOL;
         }
         echo $out;
         unset($out);
     }
 }
示例#24
0
    public static function help()
    {
        $output = <<<HELP

Usage:
  php oil [r|refine] <taskname>

Description:
    Tasks are classes that can be run through the the command line or set up as a cron job.

Examples:
    php oil refine robots [<message>]
    php oil refine robots:protect

Documentation:
\thttp://fuelphp.com/docs/packages/oil/refine.html
HELP;
        \Cli::write($output);
    }
示例#25
0
    public function generate($args)
    {
        $g = new Generate();
        $g->model($args);
        $singular = strtolower(array_shift($args));
        $model_name = ucfirst($singular);
        $plural = \Inflector::pluralize($singular);
        $filepath = APPPATH . 'classes/controller/' . $plural . '.php';
        $controller = new \View('scaffold/controller');
        $controller->name = $plural;
        $controller->model = $model_name;
        $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => '		$this->template->title = "' . ucfirst($plural) . '";
		$this->template->' . strtolower($plural) . ' = ' . $model_name . '::find(\'all\');'), array('name' => 'view', 'params' => '$id = 0', 'code' => '		$this->template->title = "' . ucfirst($plural) . '";
		$this->template->' . strtolower($singular) . ' = ' . $model_name . '::find($id);'));
        // Write controller
        if (self::write($filepath, $controller)) {
            \Cli::write('Created controller');
        }
    }
示例#26
0
文件: tests.php 项目: hymns/fuel
    public static function help()
    {
        $output = <<<HELP

Usage:
  php oil [t|test] [all|package <packagename>|<classname>]

Description:
    Octane allows you to unit test classes and packages easily through Oil.

Examples:
    php oil test all
    php oil test package oil
    php oil test inflector

Documentation:
\thttp://fuelphp.com/docs/packages/octane/
HELP;
        \Cli::write($output);
    }
示例#27
0
 public function up()
 {
     \DBUtil::create_table('users', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'username' => array('constraint' => 50, 'type' => 'varchar'), 'password' => array('constraint' => 255, 'type' => 'varchar'), 'group' => array('type' => 'int'), 'email' => array('constraint' => 255, 'type' => 'varchar'), 'last_login' => array('constraint' => 25, 'type' => 'varchar'), 'login_hash' => array('constraint' => 255, 'type' => 'varchar'), 'profile_fields' => array('type' => 'text'), 'created_at' => array('constraint' => 11, 'type' => 'int'), 'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_general_ci');
     // add UNIQUE index for username and email fields
     $active_db = \Config::get('db.active');
     $table_prefix = \Config::get('db.' . $active_db . '.table_prefix');
     \DB::query("CREATE UNIQUE INDEX user_username ON " . $table_prefix . "users (username)")->execute();
     \DB::query("CREATE UNIQUE INDEX user_email ON " . $table_prefix . "users (email)")->execute();
     // create default admin user
     $admin_username = "******";
     $admin_password = "******";
     $admin_pass_hash = \Auth::instance()->hash_password($admin_password);
     $admin_email = "*****@*****.**";
     list($id, $row_affected) = \DB::insert('users')->set(array('username' => $admin_username, 'password' => $admin_pass_hash, 'email' => $admin_email, 'group' => 100, 'last_login' => '', 'login_hash' => '', 'profile_fields' => ''))->execute();
     if ($id and $row_affected > 0) {
         \Cli::write("added admin account");
     } else {
         \Cli::write("failed to add admin account");
     }
 }
示例#28
0
 public function mysql()
 {
     $db = \DbConfig::get_params();
     $dbname = $db['dbname'];
     $scheme_sql = 'CREATE DATABASE IF NOT EXISTS `' . $dbname . '`;';
     $scheme_sql .= 'DROP TABLE IF EXISTS `comment`;';
     $scheme_sql .= 'DROP TABLE IF EXISTS `post`;';
     $scheme_sql .= file_get_contents(APPPATH . '../../schema/php_dev.sql');
     foreach (explode(';', $scheme_sql) as $sql) {
         if (preg_match('/^\\n$/u', $sql)) {
             continue;
         }
         $result = \DB::query($sql)->execute();
         if ($result) {
             \Cli::write(\Cli::color($sql, 'green'));
         } else {
             \Cli::error(\Cli::color($sql, 'red'));
         }
     }
 }
示例#29
0
文件: scaffold.php 项目: hymns/fuel
 public function generate($args, $subfolder = 'default')
 {
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) {
         throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Do this first as there is the largest chance of error here
     Generate::model($args);
     // Go through all arguments after the first and make them into field arrays
     $fields = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches);
         $fields[] = array('name' => strtolower($matches[1]), 'type' => $matches[2], 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $data['singular'] = $singular = strtolower(array_shift($args));
     $data['model'] = $model_name = 'Model_' . ucfirst($singular);
     $data['plural'] = $plural = \Inflector::pluralize($singular);
     $data['fields'] = $fields;
     $filepath = APPPATH . 'classes/controller/' . $plural . '.php';
     $controller = \View::factory($subfolder . '/scaffold/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::factory($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/delete', $data)));
     // Write controller
     if (self::write($filepath, $controller)) {
         \Cli::write('Created controller: ' . \Fuel::clean_path($filepath));
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         copy(PKGPATH . 'oil/views/' . $subfolder . '/template.php', $app_template);
         chmod($app_template, 0666);
     }
     // Create view folder if not already there
     if (!is_dir($view_folder = APPPATH . 'views/' . $plural . '/')) {
         mkdir(APPPATH . 'views/' . $plural, 0755);
     }
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         static::write($view_file = $view_folder . $view . '.php', \View::factory($subfolder . '/scaffold/views/' . $view, $data));
         \Cli::write('Created view: ' . \Fuel::clean_path($view_file));
     }
 }
示例#30
0
文件: install.php 项目: nasumi/fuel
	public static function run()
	{
		$writable_paths = array(
			APPPATH . 'cache',
			APPPATH . 'logs',
			APPPATH . 'tmp'
		);

		foreach ($writable_paths as $path)
		{
			if (@chmod($path, 0777))
			{
				\Cli::write("\t" . \Cli::color('Made writable: ' . \Fuel::clean_path($path), 'green'));
			}

			else
			{
				\Cli::write("\t" . \Cli::color('Failed to make writable: ' . \Fuel::clean_path($path), 'red'));
			}
		}
	}