コード例 #1
0
ファイル: Generator.php プロジェクト: robsymonds/framework
 /**
  * Take the array of arguments given
  * @param   array   $args
  */
 public function __construct($args)
 {
     $this->_tpl = new Mad_View_Base();
     $this->_tpl->addPath('vendor/Mad/Script/templates');
     $filename = array_shift($args);
     $action = !empty($args) ? array_shift($args) : null;
     $this->_args = $args;
     // generate model stubs
     if (strtolower($action) == 'model') {
         $this->_generateModelStubs();
         // generate migration stubs
     } elseif (strtolower($action) == 'migration') {
         $name = !empty($this->_args) ? array_shift($this->_args) : null;
         $migration = Mad_Support_Inflector::underscore($name);
         $this->_generateMigrationStub($migration);
         // generate controller stubs
     } elseif (strtolower($action) == 'controller') {
         $this->_generateControllerStubs();
         // generate helper stubs
     } elseif (strtolower($action) == 'helper') {
         $this->_generateHelperStubs();
     } elseif (strtolower($action) == 'mailer') {
         $this->_generateMailerStubs();
         // invalid option - show help page
     } else {
         $this->_displayHelp();
     }
 }
コード例 #2
0
ファイル: Base.php プロジェクト: lerre/framework
 public function getJsonClassName()
 {
     return '"' . Mad_Support_Inflector::underscore($this->_className) . '"';
 }
コード例 #3
0
ファイル: ModelTest.php プロジェクト: lerre/framework
 public function humanAttributeName($attr)
 {
     $attr = Mad_Support_Inflector::underscore($attr);
     return ucfirst(str_replace('_', ' ', $attr));
 }
コード例 #4
0
ファイル: Object.php プロジェクト: lerre/framework
 /**
  * Set the value for an attribute in this object.
  * 
  * @param   string  $name
  * @param   mixed   $value
  */
 protected function _setAttribute($name, $value)
 {
     // check for writer proxy method
     $underscore = Mad_Support_Inflector::underscore("set_{$name}");
     $methodName = Mad_Support_Inflector::camelize($underscore, 'lower');
     if (method_exists($this, $methodName)) {
         $this->{$methodName}($value);
     } else {
         $property = "_{$name}";
         if (property_exists($this, $property)) {
             $this->{$property} = $value;
         } else {
             $this->_attrValues[$name] = $value;
         }
     }
 }
コード例 #5
0
ファイル: InflectorTest.php プロジェクト: lerre/framework
 public function testUnderscore()
 {
     // most common scenarios (camelize => underscore)
     $this->assertEquals('derek', Mad_Support_Inflector::underscore('Derek'));
     $this->assertEquals('dereks_test', Mad_Support_Inflector::underscore('dereksTest'));
     $this->assertEquals('dereks_test', Mad_Support_Inflector::underscore('DereksTest'));
     $this->assertEquals('dereks_test', Mad_Support_Inflector::underscore('Dereks_Test'));
     $this->assertEquals('dereks_name_test', Mad_Support_Inflector::underscore('DereksName_Test'));
     // not as common (already underscore)
     $this->assertEquals('derek', Mad_Support_Inflector::underscore('derek'));
     $this->assertEquals('dereks_test', Mad_Support_Inflector::underscore('dereks_test'));
 }
コード例 #6
0
ファイル: Functional.php プロジェクト: lerre/framework
 /**
  * Divine the controller name from the functional test name,
  * since the controller or request may not be available at
  * the time the URL needs to be generated.
  */
 protected function _getControllerNameFromTest()
 {
     $class = get_class($this);
     if (preg_match('/^(.*)ControllerTest$/', $class, $matches) == 0) {
         return null;
     }
     return Mad_Support_Inflector::underscore($matches[1]);
 }
コード例 #7
0
ファイル: Base.php プロジェクト: lerre/framework
 /**
  * The foreign key for the model table. This is determined
  * automatically by the data object if not given in options.
  *
  * Example:
  * in Folder.php
  * <code>
  *  $this->hasMany('Documents');
  *  // returns 'folderid'
  *
  *  $this->hasMany('ChildDocuments', array('foreignKey' => 'parent_folderid'));
  *  // returns 'parent_folderid'
  * </code>
  *
  * @return  string
  */
 public function getFkName()
 {
     if (!isset($this->_fkName)) {
         $macro = $this->getMacro();
         // key was given in options
         if (!empty($this->_options['foreignKey'])) {
             $this->_fkName = $this->_options['foreignKey'];
         } elseif ($macro == 'belongsTo') {
             $associationName = Mad_Support_Inflector::underscore($this->getAssocName());
             $this->_fkName = "{$associationName}_id";
         } else {
             $table = $this->getModel()->tableName();
             $singularTable = Mad_Support_Inflector::singularize($table);
             $this->_fkName = "{$singularTable}_id";
         }
     }
     return $this->_fkName;
 }