Exemple #1
0
 protected static function _scan()
 {
     $migrations = array();
     $files = glob(ROX_APP_PATH . '/config/migrations/*.php');
     foreach ($files as $file) {
         if (preg_match('/(?<version>[0-9]+)_(?<name>.*).php/', $file, $matches) == 1) {
             $migrations[$matches['version']] = array('file' => $file, 'name' => $matches['name'], 'class' => Inflector::camelize($matches['name']), 'version' => $matches['version']);
         }
     }
     ksort($migrations);
     return $migrations;
 }
Exemple #2
0
 /**
  * Loads a helper
  *
  * @param string $name
  */
 protected static function _loadHelper($name)
 {
     $name = Inflector::camelize($name);
     $file = ROX_APP_PATH . "/helpers/{$name}Helper.php";
     if (file_exists($file)) {
         require_once $file;
         return $name . 'Helper';
     }
     $file = ROX_FRAMEWORK_PATH . "/template/helper/{$name}.php";
     if (file_exists($file)) {
         require_once $file;
         return '\\rox\\template\\helper\\' . $name;
     }
     throw new Exception("Helper '{$name}' not found");
 }
Exemple #3
0
 public function generate($name, $colDefs = array())
 {
     $name = Inflector::underscore($name);
     $version = gmdate('YmdHis');
     foreach (glob(ROX_APP_PATH . '/config/migrations/*.php') as $file) {
         if (preg_match("/([0-9]+)_{$name}.php/", $file) == 1) {
             throw new Exception("A migration named {$name} already exists");
         }
     }
     $type = static::inferMigrationType($name);
     $class = Inflector::camelize($name);
     $table = static::inferTableName($name);
     $columns = static::parseColumnDefinitions($colDefs);
     $indexes = static::extractIndexes($columns);
     $vars = compact('type', 'class', 'table', 'columns', 'indexes');
     $data = $this->_renderTemplate('migration', $vars, true);
     $this->_writeFile("/config/migrations/{$version}_{$name}.php", $data);
 }
Exemple #4
0
 public function generate($name)
 {
     $vars = array('controller_name' => Inflector::tableize($name), 'controller_class' => Inflector::camelize(Inflector::tableize($name) . '_controller'), 'model_name' => Inflector::underscore(Inflector::singularize($name)), 'model_class' => Inflector::classify($name), 'model_var_name' => Inflector::lowerCamelize(Inflector::classify($name)), 'model_var_plural_name' => Inflector::lowerCamelize(Inflector::tableize($name)), 'friendly_model_name' => Inflector::humanize(Inflector::singularize($name)), 'friendly_controller_name' => Inflector::humanize(Inflector::tableize($name)), 'package_name' => 'App', 'year' => date('Y'));
     $data = $this->_renderTemplate('controller', $vars);
     $this->_writeFile('/controllers/' . $vars['controller_class'] . '.php', $data);
 }
Exemple #5
0
 public static function parseUrl($url, Request $request = null)
 {
     if ($params = self::_parseUrl($url, $request)) {
         $defaults = array('action' => 'index', 'extension' => 'html', 'namespace' => false, 'args' => array());
         $params += $defaults;
         $params['action_method'] = Inflector::lowerCamelize($params['action']) . 'Action';
         $params['controller_class'] = Inflector::camelize($params['controller']) . 'Controller';
         return $params;
     }
     return $params;
 }
Exemple #6
0
	protected function _generateMigration($name) {
		$name = Inflector::underscore($name);

		foreach (glob(ROX_APP_PATH . '/config/migrations/*.php') as $file) {
			if (preg_match("/([0-9]+)_{$name}.php/", $file) == 1) {
				throw new Exception("A migration named {$name} already exists");
			}
		}

		$version = gmdate('YmdHis');

		$data = $this->_renderTemplate('migration', array(
			'class_name' => Inflector::camelize($name),
			'year' => date('Y')
		));

		$this->_writeFile("/config/migrations/{$version}_{$name}.php", $data);
	}
Exemple #7
0
 /**
  * Mailer::send()
  * 
  * @param string $mailerAndEmail
  * @param ...
  * @return mixed
  */
 public static function send($mailerAndEmail)
 {
     if (strpos($mailerAndEmail, '.') == false) {
         throw new Exception('mailer and email should be separated by a period.');
     }
     list($mailer, $email) = explode('.', $mailerAndEmail);
     $mailerClass = Inflector::camelize($mailer . '_mailer');
     $emailMethod = Inflector::lowerCamelize($email);
     $args = array_slice(func_get_args(), 1);
     $mailerInstance = new $mailerClass();
     $mailerInstance->params = array('mailer' => $mailer, 'mailer_class' => $mailerClass, 'email' => $email, 'email_method' => $emailMethod);
     call_user_func_array(array($mailerInstance, $emailMethod), $args);
     return $mailerInstance->_send();
 }
Exemple #8
0
/**
 * RoxPHP
 *
 * Copyright (C) 2008 - 2011 Ramon Torres
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) 2008 - 2011 Ramon Torres
 * @package Rox
 * @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
namespace rox\console;

use rox\Inflector;
use rox\Exception;
require_once dirname(dirname(dirname(__DIR__))) . '/app/config/bootstrap.php';
if ($argc == 1) {
    echo 'usage: rox <command> ...';
    exit(1);
}
try {
    $class = '\\rox\\console\\command\\' . Inflector::camelize($argv[1]);
    $command = new $class();
    $command->header();
    $command->run($argc, $argv);
    exit(0);
} catch (Exception $e) {
    echo sprintf("E: %s (%d)", $e->getMessage(), $e->getCode());
    exit(1);
}