public static function getOptions($owner, $name, $options) { if (!is_array($options)) { $type = $options; $options = array(); $options['assoc_type'] = $type; } if (!isset($options['assoc_type'])) { throw new SException('Type of relationship is required.'); } if (!isset($options['class_name'])) { if ($options['assoc_type'] == 'has_many' || $options['assoc_type'] == 'many_to_many') { $options['class_name'] = SInflection::singularize($name); } else { $options['class_name'] = $name; } } $dest = $options['class_name']; // we instanciate the dest class without associations to avoid an infinite loop if (!class_exists($dest)) { SDependencies::requireDependency('models', $dest, get_class($owner)); } $destInstance = new $dest(Null, True); $options['table_name'] = $destInstance->tableName; $options['primary_key'] = $destInstance->identityField; $assocMethod = SInflection::camelize($options['assoc_type']); return self::$assocMethod($owner, $name, $dest, $options); }
public static function requireDependency($layer, $dependency, $relativeTo = null) { list($subdir, $class) = self::dependencySubDir($dependency, $relativeTo); $path = APP_DIR . "/{$layer}/{$subdir}" . SInflection::underscore($class) . '.php'; if (!file_exists($path)) { throw new SException("Missing " . SInflection::singularize($layer) . " {$dependency}"); } require_once $path; }
public function __construct($db, $tableName, $fixturePath, $mode = self::CSV_MODE) { $this->db = $db; $this->mode = $mode; $this->className = ucfirst(SInflection::singularize($tableName)); $this->tableName = $tableName; $this->fixturePath = $fixturePath; $this->readFixtureFile(); }
function testSingular() { $this->assertEqual('product', SInflection::singularize('products')); }