/** * Get template data. * * @return array */ public function templateData() { $namespace = Configure::read('App.namespace'); if ($this->plugin) { $namespace = $this->_pluginNamespace($this->plugin); } $table = Inflector::tableize($this->args[0]); if (!empty($this->params['table'])) { $table = $this->params['table']; } $records = false; if ($this->param('data')) { $limit = (int) $this->param('limit'); $fields = $this->param('fields') ?: '*'; if ($fields !== '*') { $fields = explode(',', $fields); } $connection = ConnectionManager::get($this->connection); $query = $connection->newQuery()->from($table)->select($fields); if ($limit) { $query->limit($limit); } $records = $connection->execute($query)->fetchAll('assoc'); $records = $this->prettifyArray($records); } return ['className' => $this->BakeTemplate->viewVars['name'], 'namespace' => $namespace, 'records' => $records, 'table' => $table]; }
private function parse($json) { if (is_array($json)) { foreach ($json as $item) { $this->parse($item); } } else { $json = (array) $json; } foreach ($json as $tablename => $data) { if (!is_array($data)) { $this->parse($data); } else { $table = Inflector::tableize($tablename); $table = $table == 'armours' ? 'armour' : $table; // Hack for non-standard table names $table = TableRegistry::get($table); foreach ($data as $record) { $record = (array) $record; $new = $table->import($record); $result = ['table' => Inflector::humanize($tablename), 'record' => $new->import_name, 'status' => $new->import_action, 'errors' => $new->import_errors]; $this->results[] = $result; } } } }
/** * Returns a counter string for the paged result set * * ### Options * * - `model` The model to use, defaults to PaginatorHelper::defaultModel(); * - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5' * set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing * the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any * custom content you would like. * * @param string|array $options Options for the counter string. See #options for list of keys. * If string it will be used as format. * @return string Counter string. * @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter */ public function counter($options = []) { if (is_string($options)) { $options = ['format' => $options]; } $default = ['model' => $this->defaultModel(), 'format' => 'pages']; $options = \Cake\Utility\Hash::merge($default, $options); $paging = $this->params($options['model']); if (!$paging['pageCount']) { $paging['pageCount'] = 1; } $start = 0; if ($paging['count'] >= 1) { $start = ($paging['page'] - 1) * $paging['perPage'] + 1; } $end = $start + $paging['perPage'] - 1; if ($paging['count'] < $end) { $end = $paging['count']; } switch ($options['format']) { case 'range': case 'pages': $template = 'counter' . ucfirst($options['format']); break; default: $template = 'counterCustom'; $this->templater()->add([$template => $options['format']]); } $map = array_map([$this->Number, 'format'], ['page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, 'end' => $end]); $map += ['model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))]; return $this->templater()->format($template, $map); }
public function main($name = null) { $table = Inflector::tableize($name); $prefix = $this->AutoModel->getPrefix(); $newName = preg_replace('/' . $prefix . '/i', '', $table); // debug(compact('newName', 'table', 'prefix', 'name')); // exit(); parent::main($newName); }
/** * Get template data. * * @return array */ public function templateData() { $namespace = Configure::read('App.namespace'); if ($this->plugin) { $namespace = $this->_pluginNamespace($this->plugin); } $table = Inflector::tableize($this->args[0]); if (!empty($this->params['table'])) { $table = $this->params['table']; } return ['className' => $this->BakeTemplate->viewVars['name'], 'namespace' => $namespace, 'records' => false, 'table' => $table]; }
/** * Returns variables for bake template. * * @param string $actionName action name * @return array */ protected function _getVars($actionName) { $action = $this->detectAction($actionName); if (empty($action)) { $table = $actionName; $action = 'create_table'; } else { list($action, $table) = $action; } $table = Inflector::tableize($table); $name = Inflector::camelize($actionName) . $this->_getLastModifiedTime($table); return [$action, $table, $name]; }
/** * */ public function initialize() { parent::initialize(); /** * Use Builder Helpers */ $this->loadHelper('Flash', ['className' => 'Builder.Flash']); /** * Set default layout for App using Layout/builder */ if ($this->layout === 'default') { $this->layout('builder/default'); } /** * Set form templates */ $_templates = ['dateWidget' => '<ul class="list-inline"><li class="year">{{year}}</li><li class="month">{{month}}</li><li class="day">{{day}}</li><li class="hour">{{hour}}</li><li class="minute">{{minute}}</li><li class="second">{{second}}</li><li class="meridian">{{meridian}}</li></ul>', 'error' => '<div class="help-block">{{content}}</div>', 'help' => '<div class="help-block">{{content}}</div>', 'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}{{help}}</div>', 'inputContainerError' => '<div class="form-group {{type}}{{required}} has-error">{{content}}{{error}}{{help}}</div>', 'checkboxWrapper' => '<div class="checkbox"><label>{{input}}{{label}}</label></div>', 'multipleCheckboxWrapper' => '<div class="checkbox">{{label}}</div>', 'radioInlineFormGroup' => '{{label}}<div class="radio-inline-wrapper">{{input}}</div>', 'radioNestingLabel' => '<div class="radio">{{hidden}}<label{{attrs}}>{{input}}{{text}}</label></div>', 'staticControl' => '<p class="form-control-static">{{content}}</p>', 'inputGroupAddon' => '<span class="{{class}}">{{content}}</span>', 'inputGroupContainer' => '<div class="input-group">{{prepend}}{{content}}{{append}}</div>', 'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>', 'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>', 'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>', 'selectMultiple' => '<select class="form-control" name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>']; /** * */ $this->Form->templates($_templates); /** * Loader base styles using bower_components and default Builder settings */ $this->start('builder-css'); echo $this->Html->css(['/bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css', '/bower_components/bootstrap/dist/css/bootstrap.min.css', '/bower_components/fontawesome/css/font-awesome.min.css', '/bower_components/datatables/media/css/dataTables.bootstrap.min.css', '/bower_components/summernote/dist/summernote.css', '/css/builder/base.css']); $this->end(); /** * Laoder base scripts using bower_components and default Builder settings */ $this->start('builder-script'); echo $this->Html->script(['/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery-ui/jquery-ui.min.js', '/bower_components/bootstrap/dist/js/bootstrap.min.js', '/bower_components/datatables/media/js/jquery.dataTables.min.js', '/bower_components/datatables/media/js/dataTables.bootstrap.js', '/bower_components/summernote/dist/summernote.min.js', '/js/builder/base.js']); $this->end(); /** * Load Builder default constructor element form Builder/Element/constructor */ $this->prepend('builder-element', $this->element('Builder.constructor/default')); /** * If empty 'nav' block, set default navbar using Builder/Element/builder */ if (!$this->fetch('nav')) { $this->assign('nav', $this->element('Builder.builder/navbar-fixed-top')); } /** * Set default title for layout using controller name */ $this->assign('title', Inflector::humanize(Inflector::tableize($this->request->controller))); }
/** * Modify entity * * @param \Cake\Datasource\EntityInterface entity * @param \Cake\ORM\Association table * @param string path prefix * @return void */ protected function _modifyEntity(EntityInterface $entity, Association $table = null, $pathPrefix = '') { if (is_null($table)) { $table = $this->_table; } // unset primary key unset($entity->{$table->primaryKey()}); // unset foreign key if ($table instanceof Association) { unset($entity->{$table->foreignKey()}); } // unset configured foreach ($this->config('remove') as $field) { $field = $this->_fieldByPath($field, $pathPrefix); if ($field) { unset($entity->{$field}); } } // set / prepend / append foreach (['set', 'prepend', 'append'] as $action) { foreach ($this->config($action) as $field => $value) { $field = $this->_fieldByPath($field, $pathPrefix); if ($field) { if ($action == 'prepend') { $value .= $entity->{$field}; } if ($action == 'append') { $value = $entity->{$field} . $value; } $entity->{$field} = $value; } } } // set as new $entity->isNew(true); // modify related entities foreach ($this->config('contain') as $contain) { if (preg_match('/^' . preg_quote($pathPrefix, '/') . '([^.]+)/', $contain, $matches)) { foreach ($entity->{Inflector::tableize($matches[1])} as $related) { if ($related->isNew()) { continue; } $this->_modifyEntity($related, $table->{$matches[1]}, $pathPrefix . $matches[1] . '.'); } } } }
/** * Initialize the fixture. * * @return void * @throws \Cake\ORM\Exception\MissingTableClassException When importing from a table that does not exist. */ public function init() { if ($this->table === null) { list(, $class) = namespaceSplit(get_class($this)); preg_match('/^(.*)Fixture$/', $class, $matches); $table = $class; if (isset($matches[1])) { $table = $matches[1]; } $this->table = Inflector::tableize($table); } if (empty($this->import) && !empty($this->fields)) { $this->_schemaFromFields(); } if (!empty($this->import)) { $this->_schemaFromImport(); } }
public function getUploadPath(Entity $entity, $path, $extension) { $replace = array('%uuid' => String::uuid(), '%id' => $entity->id, '%y' => date('Y'), '%m' => date('m'), '/' => DS); $path = $this->_config['assets_dir'] . DS . Inflector::tableize($entity->source()) . DS . strtr($path, $replace) . '.' . $extension; return $path; }
/** * 获取ViewManager * @return ViewManager */ public function getViewManager() { if (is_null($this->viewManager)) { $controller = $this->getKernel()->getParameter('controller'); $controllerDir = Inflector::tableize(substr($controller, 0, -10)); $viewManager = $this->getKernel()->getContainer()->get('view'); $viewManager->setViewPath($this->getViewPath() . "/templates/{$controllerDir}/"); $viewManager->setLayoutPath($this->getViewPath() . '/layouts/'); $this->viewManager = $viewManager; } return $this->viewManager; }
/** * Returns the table name using the fixture class * * @return string */ protected function _tableFromClass() { list(, $class) = namespaceSplit(get_class($this)); preg_match('/^(.*)Fixture$/', $class, $matches); $table = $class; if (isset($matches[1])) { $table = $matches[1]; } return Inflector::tableize($table); }
/** * Mock a model, maintain fixtures and table association * * @param string $alias The model to get a mock for. * @param mixed $methods The list of methods to mock * @param array $options The config data for the mock's constructor. * @throws \Cake\ORM\Exception\MissingTableClassException * @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject */ public function getMockForModel($alias, array $methods = [], array $options = []) { if (empty($options['className'])) { $class = Inflector::camelize($alias); $className = App::className($class, 'Model/Table', 'Table'); if (!$className) { throw new MissingTableClassException([$alias]); } $options['className'] = $className; } $connectionName = $options['className']::defaultConnectionName(); $connection = ConnectionManager::get($connectionName); list(, $baseClass) = pluginSplit($alias); $options += ['alias' => $baseClass, 'connection' => $connection]; $options += TableRegistry::config($alias); $mock = $this->getMockBuilder($options['className'])->setMethods($methods)->setConstructorArgs([$options])->getMock(); if (empty($options['entityClass']) && $mock->entityClass() === '\\Cake\\ORM\\Entity') { $parts = explode('\\', $options['className']); $entityAlias = Inflector::singularize(substr(array_pop($parts), 0, -5)); $entityClass = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $entityAlias; if (class_exists($entityClass)) { $mock->entityClass($entityClass); } } if (stripos($mock->table(), 'mock') === 0) { $mock->table(Inflector::tableize($baseClass)); } TableRegistry::set($baseClass, $mock); TableRegistry::set($alias, $mock); return $mock; }
/** * Returns a list of all available roles. Will look for a roles array in * Configure first, tries database roles table next. * * @return array List with all available roles * @throws Cake\Core\Exception\Exception */ protected function _getAvailableRoles() { $roles = Configure::read($this->_config['rolesTable']); if (is_array($roles)) { return $roles; } // no roles in Configure AND rolesTable does not exist $tables = ConnectionManager::get('default')->schemaCollection()->listTables(); if (!in_array(Inflector::tableize($this->_config['rolesTable']), $tables)) { throw new Exception('Invalid TinyAuthorize Role Setup (no roles found in Configure or database)'); } // fetch roles from database $rolesTable = TableRegistry::get($this->_config['rolesTable']); $roles = $rolesTable->find('all')->formatResults(function ($results) { return $results->combine('alias', 'id'); })->toArray(); if (!count($roles)) { throw new Exception('Invalid TinyAuthorize Role Setup (rolesTable has no roles)'); } return $roles; }
/** * Detects the action and table from the name of a migration * * @param string $name Name of migration * @return array **/ public function detectAction($name) { if (preg_match('/^(Create|Drop)(.*)/', $name, $matches)) { $action = strtolower($matches[1]) . '_table'; $table = Inflector::tableize(Inflector::pluralize($matches[2])); } elseif (preg_match('/^(Add).+?(?:To)(.*)/', $name, $matches)) { $action = 'add_field'; $table = Inflector::tableize(Inflector::pluralize($matches[2])); } elseif (preg_match('/^(Remove).+?(?:From)(.*)/', $name, $matches)) { $action = 'drop_field'; $table = Inflector::tableize(Inflector::pluralize($matches[2])); } elseif (preg_match('/^(Alter)(.*)/', $name, $matches)) { $action = 'alter_table'; $table = Inflector::tableize(Inflector::pluralize($matches[2])); } else { return []; } return [$action, $table]; }
/** * test that setting new rules clears the inflector caches. * * @return void */ public function testRulesClearsCaches() { $this->assertEquals('Banana', Inflector::singularize('Bananas')); $this->assertEquals('bananas', Inflector::tableize('Banana')); $this->assertEquals('Bananas', Inflector::pluralize('Banana')); Inflector::rules('singular', ['/(.*)nas$/i' => '\\1zzz']); $this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.'); Inflector::rules('plural', ['/(.*)na$/i' => '\\1zzz']); Inflector::rules('irregular', ['corpus' => 'corpora']); $this->assertEquals('Banazzz', Inflector::pluralize('Banana'), 'Was inflected with old rules.'); $this->assertEquals('corpora', Inflector::pluralize('corpus'), 'Was inflected with old irregular form.'); }
/** * Converts the single audit log event array into a Elastica\Document so it can be stored. * * @param array $audit The audit log information * @param string $index The name of the index where the event should be stored * @param array $meta The meta information to append to the meta array * @return Elastica\Document */ public function eventFormatter($audit, $index, $meta = []) { $data = ['@timestamp' => $audit['created'], 'transaction' => $audit['id'], 'type' => $audit['event'] === 'EDIT' ? 'update' : strtolower($audit['event']), 'primary_key' => $audit['entity_id'], 'original' => $audit['original'], 'changed' => $audit['changed'], 'meta' => $meta + ['ip' => $audit['source_ip'], 'url' => $audit['source_url'], 'user' => $audit['source_id']]]; $index = sprintf($index, \DateTime::createFromFormat('Y-m-d H:i:s', $audit['created'])->format('-Y.m.d')); $type = isset($map[$audit['model']]) ? $map[$audit['model']] : Inflector::tableize($audit['model']); return new Document($audit['id'], $data, $type, $index); }
/** * Get the table name for the model being baked. * * Uses the `table` option if it is set. * * @param string $name Table name * @return string */ public function getTable($name) { if (isset($this->params['table'])) { return $this->params['table']; } return Inflector::tableize($name); }
/** * Format Template * * Return a formated template to use as content for a tag * ex : * Hello {{name}} -> Hello John * {{name}} is the property entity * * @param string $pattern a pattern to match * @param Cake\ORM\Entity $entity The entity * @return string * @todo Allow {{model.field}} syntax */ protected function _formatTemplate($pattern, $entity) { $template = preg_replace_callback('/{{([\\w\\.]+)}}/', function ($matches) use($entity) { if (preg_match('/^([_\\w]+)\\.(\\w+)$/', $matches[1], $x)) { $table = TableRegistry::get(Inflector::tableize($x[1])); $matchEntity = $table->get($entity->{$x[1] . '_id'}); return $matchEntity->{$x[2]}; } if ($entity->has($matches[1])) { return $entity->{$matches[1]}; } }, $pattern); return trim($template); }
/** * _getTabLabels * * Re-arrange tabs naming based on the config.ini and fieldNames * to avoid repetitive namings * @param Cake\ORM\TableRegistry $tableInstance passed * @param array $config of the config.ini * * @return array $labels with key/value storage of alias/name */ protected function _getTabLabels($tableInstance, $config = []) { $labels = []; $associationLabels = []; if (!empty($config['associationLabels'])) { $associationLabels = $tableInstance->associationLabels($config['associationLabels']); } $labelCounts = []; // Gather labels for all associations foreach ($tableInstance->associations() as $association) { $assocTableInstance = TableRegistry::get($association->table()); $icon = $this->_getTableIcon($assocTableInstance); $assocAlias = $association->alias(); // Initialize association label array with the icon if (empty($labels[$assocAlias])) { $labels[$assocAlias] = ['icon' => $icon]; } if (in_array($assocAlias, array_keys($associationLabels))) { // If label exists in config.ini, use it. $labels[$assocAlias]['label'] = $associationLabels[$assocAlias]; } else { // Otherwise use table alias or name as label $labels[$assocAlias]['label'] = Inflector::humanize($association->table()); if (method_exists($assocTableInstance, 'moduleAlias')) { $labels[$assocAlias]['label'] = Inflector::humanize($assocTableInstance->moduleAlias()); } } // Initialize counter for current label, if needed if (empty($labelCounts[$labels[$assocAlias]['label']])) { $labelCounts[$labels[$assocAlias]['label']] = 0; } // Bump up label counter $labelCounts[$labels[$assocAlias]['label']]++; } // Not that we have all the labels, check if we have any duplicate labels // and append the association field name to those that are not unique. // Also, while we are at it, construct the actual label string from the // icon, label, and field name. foreach ($labels as $assocAlias => $label) { $labels[$assocAlias] = $label['icon'] . $label['label']; if ($labelCounts[$label['label']] <= 1) { // If the label is unique, we have nothing else to do continue; } // Get the association field and clean it up, removing the association name // from the field. So, for 'primaryContactIdLeads', we'll do the following: // * Tableize: primary_contact_id_leads // * Humanize: Primary Contact Id Leads // * Remove association table: Primary Contact Id $fieldName = Inflector::humanize(Inflector::tableize($assocAlias)); $fieldName = str_replace($assocAlias, '', Inflector::humanize(Inflector::tableize($assocAlias))); $fieldName = trim(str_replace($label['label'], '', $fieldName)); // Field can be empty in case of, for example, many-to-many relationships. if (!empty($fieldName)) { $labels[$assocAlias] .= sprintf(" (%s)", $fieldName); } } return $labels; }
public function get_data() { $this->auth(); $this->layout = false; $this->render(false); $model_name = Inflector::camelize($this->request->data['model']); $Model = TableRegistry::get($model_name); $table = new Table(Inflector::tableize($this->request->data['model'])); $cols = $table->columns(); //die(var_dump($Model)); $order = []; if ($Model->hasField('sort')) { $order[$model_name . '.sort'] = 'ASC'; } if ($Model->hasField('name')) { $order[$model_name . '.name'] = 'ASC'; } if (isset($this->request->data['order_field']) && isset($this->request->data['order_dir'])) { $order = [$model_name . '.' . $this->request->data['order_field'] => $this->request->data['order_dir']]; } if (isset($this->request->data['belongsTo'])) { $conditions = []; foreach ($this->request->data['belongsTo'] as $key => $val) { if ($val === 'null') { $val = null; } $conditions[$key] = $val; } $result = $Model->find('all', ['conditions' => $conditions, 'order' => $order])->toArray(); } else { $result = $Model->find('all', ['order' => $order])->toArray(); } if ($result) { die(json_encode(["data" => $result, "status" => "success"])); } die(json_encode(["data" => [], "status" => "fail"])); }
/** * Get a model object for a class name. * * @param string $className Name of class you want model to be. * @param string $table Table name * @return \Cake\ORM\Table Table instance */ public function getTableObject($className) { if (TableRegistry::exists($className)) { return TableRegistry::get($className); } return TableRegistry::get($className, ['name' => $className, 'table' => Inflector::tableize($className), 'connection' => ConnectionManager::get($this->connection)]); }
/** * Assembles and writes a Fixture file * * @param string $model Name of model to bake. * @param string|null $useTable Name of table to use. * @return string Baked fixture content * @throws \RuntimeException */ public function bake($model, $useTable = null) { $table = $schema = $records = $import = $modelImport = null; if (!$useTable) { $useTable = Inflector::tableize($model); } elseif ($useTable !== Inflector::tableize($model)) { $table = $useTable; } $importBits = []; if (!empty($this->params['schema'])) { $modelImport = true; $importBits[] = "'table' => '{$useTable}'"; } if (!empty($importBits) && $this->connection !== 'default') { $importBits[] = "'connection' => '{$this->connection}'"; } if (!empty($importBits)) { $import = sprintf("[%s]", implode(', ', $importBits)); } $connection = ConnectionManager::get($this->connection); if (!method_exists($connection, 'schemaCollection')) { throw new \RuntimeException('Cannot generate fixtures for connections that do not implement schemaCollection()'); } $schemaCollection = $connection->schemaCollection(); try { $data = $schemaCollection->describe($useTable); } catch (Exception $e) { $useTable = Inflector::underscore($model); $table = $useTable; $data = $schemaCollection->describe($useTable); } if ($modelImport === null) { $schema = $this->_generateSchema($data); } if (empty($this->params['records'])) { $recordCount = 1; if (isset($this->params['count'])) { $recordCount = $this->params['count']; } $records = $this->_makeRecordString($this->_generateRecords($data, $recordCount)); } if (!empty($this->params['records'])) { $records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable)); } return $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import')); }
/** * Method that creates joined tables for Many to Many relationships. * * @param string $tableName current table name * @return array phinx table instances */ public function joins($tableName) { $result = []; $this->_setConfiguration($tableName); if (empty($this->_config['manyToMany']['modules'])) { return $result; } $manyToMany = explode(',', $this->_config['manyToMany']['modules']); foreach ($manyToMany as $module) { // skip manyToMany table creation if one of the tables does not exist if (!$this->hasTable(Inflector::tableize($module))) { continue; } $tables = []; $tables[] = $tableName; /* associated table name */ $moduleTable = TableRegistry::get($module)->table(); $tables[] = $moduleTable; /* sort them alphabetically for CakePHP naming convention */ sort($tables); $joinedTable = implode('_', $tables); /* skip if join table exists */ if ($this->hasTable($joinedTable)) { continue; } /* construct instance of the new table */ $table = $this->table($joinedTable); $table->addColumn('id', 'uuid', ['null' => false]); $table->addColumn(Inflector::singularize($tableName) . '_id', 'uuid', ['null' => false]); $table->addColumn(Inflector::singularize($moduleTable) . '_id', 'uuid', ['null' => false]); $table->addColumn('created', 'datetime'); $table->addColumn('modified', 'datetime'); $table->addPrimaryKey(['id']); $result[] = $table; } return $result; }
/** * Find belongsTo relations and add them to the associations list. * * @param \Cake\ORM\Table $model Database\Table instance of table being generated. * @param array $associations Array of in progress associations * @return array Associations with belongsTo added in. */ public function findBelongsTo($model, array $associations) { $schema = $model->schema(); foreach ($schema->columns() as $fieldName) { if (!preg_match('/^.*_id$/', $fieldName)) { continue; } if ($fieldName === 'parent_id') { $className = $this->plugin ? $this->plugin . '.' . $model->alias() : $model->alias(); $assoc = ['alias' => 'Parent' . $model->alias(), 'className' => $className, 'foreignKey' => $fieldName]; } else { $tmpModelName = $this->_modelNameFromKey($fieldName); if (!in_array(Inflector::tableize($tmpModelName), $this->_tables)) { $found = $this->findTableReferencedBy($schema, $fieldName); if ($found) { $tmpModelName = Inflector::camelize($found); } } $assoc = ['alias' => $tmpModelName, 'foreignKey' => $fieldName]; if ($schema->column($fieldName)['null'] === false) { $assoc['joinType'] = 'INNER'; } } if ($this->plugin && empty($assoc['className'])) { $assoc['className'] = $this->plugin . '.' . $assoc['alias']; } $associations['belongsTo'][] = $assoc; } return $associations; }
/** * Initialize the fixture. * * @return void * @throws \Cake\ORM\Exception\MissingTableClassException When importing from a table that does not exist. */ public function init() { if ($this->name === null) { list(, $class) = namespaceSplit(get_class($this)); preg_match('/^(.*)MethodFixture$/', $class, $matches); $method = $class; if (isset($matches[1])) { $method = $matches[1]; } $this->name = Inflector::tableize($method); } }