/** * Write metadata files for all the listed tables. * * @param string $path * @param DbAdapter $db * @param array $tables * @return void */ protected function writeMetadataFiles($path, DbAdapter $db, array $tables) { $inflector = new Inflector(); foreach ($tables as $table) { $columns = $db->describeTable($table); $references = $db->listForeignKeyReferences($table); $uniqueConstraints = $db->listUniqueConstraints($table); $title = $inflector->titleize($table); $replacements = array('{{singular}}' => $inflector->singularize($title), '{{plural}}' => $inflector->pluralize($title), '{{columns}}' => var_export($columns, true), '{{references}}' => var_export($references, true), '{{uniqueConstraints}}' => var_export($uniqueConstraints, true)); file_put_contents("{$path}/{$table}.php", str_replace(array_keys($replacements), $replacements, file_get_contents(__DIR__ . '/db-metadata/template.tpl'))); } }
public function __construct(Table $table, ActivityLog $activityLog = null, Inflector $inflector = null) { $this->table = $table; $this->inflector = $inflector ?: Pimple::getResource('inflector'); $tableName = $table->getTableName(); $inflectedName = $this->inflector->singularize($this->inflector->hyphenize($tableName)); if (!$tableName) { $className = get_class($table); throw new Exception("Cannot create activity log handle for {$className} because no table name is set."); } $this->setActivityLog($activityLog ?: Pimple::getResource('activity-log'))->setName($inflectedName)->setModel($table)->addAlias($tableName); parent::__construct(); }
/** * Generate the model class and dbdeploy delta and then output the path * to each so that they can easily be found for editing. * * @return void */ public function execute() { $inflector = new Inflector(); if (null === $this->modelClass) { $this->modelClass = $inflector->classify($this->name); } $modelFile = $this->paths->getModels() . '/' . $this->modelClass . '.php'; $dbdeployFile = $this->paths->getDb() . '/' . $this->getDbRevision() . '-add-' . $this->name . '.sql'; if ($this->modelAlreadyExists($modelFile)) { return $this->abort("There is a already a model file named \"{$this->modelClass}.php\""); } if ($this->dbdeployFileAlreadyExists($dbdeployFile)) { return $this->abort("There is already a dbdeploy file at \"{$dbdeployFile}\""); } $templateReplacements = array('{{modelClass}}' => $this->modelClass, '{{tableName}}' => $this->name); $this->writeFile($modelFile, str_replace(array_keys($templateReplacements), $templateReplacements, file_get_contents(__DIR__ . '/gen-templates/db-table/ModelClass.tpl'))); $templateReplacements = array('{{tableName}}' => $this->name, '{{primaryKey}}' => $inflector->singularize($this->name) . '_id'); $this->writeFile($dbdeployFile, str_replace(array_keys($templateReplacements), $templateReplacements, file_get_contents(__DIR__ . '/gen-templates/db-table/dbdeploy-delta.sql'))); $this->renderSuccessMessage($dbdeployFile, $modelFile); }
/** * Generate the model class and dbdeploy delta and then output the path * to each so that they can easily be found for editing. * * @return void */ public function execute() { $this->db = $this->runner->connectDb(); $inflector = new Inflector(); $dbdeployFile = $this->paths->getDb() . '/' . $this->getDbRevision() . '-add-' . $this->tableName . '-eav.sql'; if ($this->dbdeployFileAlreadyExists($dbdeployFile)) { return $this->abort("There is already a dbdeploy file at \"{$dbdeployFile}\""); } $templateReplacements = array('{{tableName}}' => $this->tableName, '{{primaryKey}}' => $inflector->singularize($this->tableName) . '_id', '{{primaryKeyColumns}}' => $this->generatePkeyColumnContent(), '{{multiColumnPrimaryKeyIndexes}}' => $this->generateMultiColumnPkeyIndexContent(), '{{primaryKeyForeignKeys}}' => $this->generatePkeyForeignKeyContent(), '{{primaryKeyColumnList}}' => $this->generatePkeyColumnListContent()); $this->writeFile($dbdeployFile, str_replace(array_keys($templateReplacements), $templateReplacements, file_get_contents(__DIR__ . '/gen-templates/eav/eav-tables.sql'))); $this->renderSuccessMessage($dbdeployFile, $modelFile); }
/** * Iterate over the PHP files available in the component's folder to list * all the page this factory is capable of serving. Note that we skip * "component", which is the component class, not a page. * * @return array */ public function listAvailablePages() { $pages = array(); $files = glob($this->getPath() . '/*.php'); $namespace = $this->getComponentNamespace(); foreach ($files as $file) { $urlName = $this->inflector->hyphenize(basename($file, '.php')); $className = $namespace . '\\' . $this->inflector->camelize($urlName); if ('component' !== $urlName) { $pages[] = new Page($urlName, $file, $className); } } return $pages; }
public function testUnaccentSafeForUtf8() { $this->assertEquals('Z', $this->inflector->unaccent('Ž')); }
/** * Apply the filter to the supplied Select object. * * @param Select $select * @param string $conditionSetName * @param array $queryVars * @return Select * @throws InvalidOperator * @throws MissingQueryVar */ public function apply(Select $select, $conditionSetName, array $queryVars) { $this->validate($queryVars); $operator = $queryVars['comp']; $start = null; $end = null; $startObj = null; $startIso = null; $endObj = null; $endIso = null; if ($this->truncateTimestamps) { $format = 'Y-m-d'; } else { $format = 'Y-m-d G:i:s'; } if ($queryVars['start']) { try { $startObj = new DateTime($queryVars['start']); $startIso = $startObj->format($format); } catch (Exception $e) { // If we get input we can't parse, we just throw it out } } if ($queryVars['end']) { try { $endObj = new DateTime($queryVars['end']); $endIso = $endObj->format($format); } catch (Exception $e) { // If we get input we can't parse, we just throw it out } } // If the second input is greater than the first, swap them for the user if ($startObj && $endObj && $endObj < $startObj) { $swapEndIso = $endIso; $endIso = $startIso; $startIso = $swapEndIso; } $methodName = 'filter' . $this->inflector->camelize($operator); return $this->{$methodName}($select, $conditionSetName, $startIso, $endIso); }