repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
QoboLtd/cakephp-csv-migrations
src/Shell/ImportShell.php
ImportShell._findRelatedRecord
protected function _findRelatedRecord(Table $table, string $field, string $value) : string { $csvField = FieldUtility::getCsvField($table, $field); if (null !== $csvField && 'related' === $csvField->getType()) { $relatedTable = (string)$csvField->getLimit(); $value = $this->_findRelatedRecord( TableRegistry::get($relatedTable), TableRegistry::get($relatedTable)->getDisplayField(), $value ); } foreach ($table->associations() as $association) { if ($association->getForeignKey() !== $field) { continue; } $targetTable = $association->getTarget(); $primaryKey = $targetTable->getPrimaryKey(); if (! is_string($primaryKey)) { throw new UnsupportedPrimaryKeyException(); } // combine lookup fields with primary key and display field $lookupFields = array_merge( FieldUtility::getLookup($targetTable), [$primaryKey, $targetTable->getDisplayField()] ); // remove virtual/non-existing fields $lookupFields = array_intersect($lookupFields, $targetTable->getSchema()->columns()); // alias lookup fields foreach ($lookupFields as $k => $v) { $lookupFields[$k] = $targetTable->aliasField($v); } // populate lookup field values $lookupValues = array_fill(0, count($lookupFields), $value); $query = $targetTable->find('all') ->enableHydration(true) ->select([$targetTable->aliasField($primaryKey)]) ->where(['OR' => array_combine($lookupFields, $lookupValues)]); try { $entity = $query->firstOrFail(); } catch (RecordNotFoundException $e) { continue; } Assert::isInstanceOf($entity, EntityInterface::class); return $entity->get($primaryKey); } return $value; }
php
protected function _findRelatedRecord(Table $table, string $field, string $value) : string { $csvField = FieldUtility::getCsvField($table, $field); if (null !== $csvField && 'related' === $csvField->getType()) { $relatedTable = (string)$csvField->getLimit(); $value = $this->_findRelatedRecord( TableRegistry::get($relatedTable), TableRegistry::get($relatedTable)->getDisplayField(), $value ); } foreach ($table->associations() as $association) { if ($association->getForeignKey() !== $field) { continue; } $targetTable = $association->getTarget(); $primaryKey = $targetTable->getPrimaryKey(); if (! is_string($primaryKey)) { throw new UnsupportedPrimaryKeyException(); } // combine lookup fields with primary key and display field $lookupFields = array_merge( FieldUtility::getLookup($targetTable), [$primaryKey, $targetTable->getDisplayField()] ); // remove virtual/non-existing fields $lookupFields = array_intersect($lookupFields, $targetTable->getSchema()->columns()); // alias lookup fields foreach ($lookupFields as $k => $v) { $lookupFields[$k] = $targetTable->aliasField($v); } // populate lookup field values $lookupValues = array_fill(0, count($lookupFields), $value); $query = $targetTable->find('all') ->enableHydration(true) ->select([$targetTable->aliasField($primaryKey)]) ->where(['OR' => array_combine($lookupFields, $lookupValues)]); try { $entity = $query->firstOrFail(); } catch (RecordNotFoundException $e) { continue; } Assert::isInstanceOf($entity, EntityInterface::class); return $entity->get($primaryKey); } return $value; }
[ "protected", "function", "_findRelatedRecord", "(", "Table", "$", "table", ",", "string", "$", "field", ",", "string", "$", "value", ")", ":", "string", "{", "$", "csvField", "=", "FieldUtility", "::", "getCsvField", "(", "$", "table", ",", "$", "field", ")", ";", "if", "(", "null", "!==", "$", "csvField", "&&", "'related'", "===", "$", "csvField", "->", "getType", "(", ")", ")", "{", "$", "relatedTable", "=", "(", "string", ")", "$", "csvField", "->", "getLimit", "(", ")", ";", "$", "value", "=", "$", "this", "->", "_findRelatedRecord", "(", "TableRegistry", "::", "get", "(", "$", "relatedTable", ")", ",", "TableRegistry", "::", "get", "(", "$", "relatedTable", ")", "->", "getDisplayField", "(", ")", ",", "$", "value", ")", ";", "}", "foreach", "(", "$", "table", "->", "associations", "(", ")", "as", "$", "association", ")", "{", "if", "(", "$", "association", "->", "getForeignKey", "(", ")", "!==", "$", "field", ")", "{", "continue", ";", "}", "$", "targetTable", "=", "$", "association", "->", "getTarget", "(", ")", ";", "$", "primaryKey", "=", "$", "targetTable", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "primaryKey", ")", ")", "{", "throw", "new", "UnsupportedPrimaryKeyException", "(", ")", ";", "}", "// combine lookup fields with primary key and display field", "$", "lookupFields", "=", "array_merge", "(", "FieldUtility", "::", "getLookup", "(", "$", "targetTable", ")", ",", "[", "$", "primaryKey", ",", "$", "targetTable", "->", "getDisplayField", "(", ")", "]", ")", ";", "// remove virtual/non-existing fields", "$", "lookupFields", "=", "array_intersect", "(", "$", "lookupFields", ",", "$", "targetTable", "->", "getSchema", "(", ")", "->", "columns", "(", ")", ")", ";", "// alias lookup fields", "foreach", "(", "$", "lookupFields", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "lookupFields", "[", "$", "k", "]", "=", "$", "targetTable", "->", "aliasField", "(", "$", "v", ")", ";", "}", "// populate lookup field values", "$", "lookupValues", "=", "array_fill", "(", "0", ",", "count", "(", "$", "lookupFields", ")", ",", "$", "value", ")", ";", "$", "query", "=", "$", "targetTable", "->", "find", "(", "'all'", ")", "->", "enableHydration", "(", "true", ")", "->", "select", "(", "[", "$", "targetTable", "->", "aliasField", "(", "$", "primaryKey", ")", "]", ")", "->", "where", "(", "[", "'OR'", "=>", "array_combine", "(", "$", "lookupFields", ",", "$", "lookupValues", ")", "]", ")", ";", "try", "{", "$", "entity", "=", "$", "query", "->", "firstOrFail", "(", ")", ";", "}", "catch", "(", "RecordNotFoundException", "$", "e", ")", "{", "continue", ";", "}", "Assert", "::", "isInstanceOf", "(", "$", "entity", ",", "EntityInterface", "::", "class", ")", ";", "return", "$", "entity", "->", "get", "(", "$", "primaryKey", ")", ";", "}", "return", "$", "value", ";", "}" ]
Fetch related record id if found, otherwise return initial value. @param \Cake\ORM\Table $table Table instance @param string $field Field name @param string $value Field value @return string
[ "Fetch", "related", "record", "id", "if", "found", "otherwise", "return", "initial", "value", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ImportShell.php#L473-L531
train
QoboLtd/cakephp-csv-migrations
src/Shell/ImportShell.php
ImportShell._findListValue
protected function _findListValue(RepositoryInterface $table, string $listName, string $value) : string { $options = FieldUtility::getList(sprintf('%s.%s', $table->getAlias(), $listName), true); // check against list options values foreach ($options as $val => $params) { if ($val !== $value) { continue; } return $val; } // check against list options labels foreach ($options as $val => $params) { if ($params['label'] !== $value) { continue; } return $val; } return $value; }
php
protected function _findListValue(RepositoryInterface $table, string $listName, string $value) : string { $options = FieldUtility::getList(sprintf('%s.%s', $table->getAlias(), $listName), true); // check against list options values foreach ($options as $val => $params) { if ($val !== $value) { continue; } return $val; } // check against list options labels foreach ($options as $val => $params) { if ($params['label'] !== $value) { continue; } return $val; } return $value; }
[ "protected", "function", "_findListValue", "(", "RepositoryInterface", "$", "table", ",", "string", "$", "listName", ",", "string", "$", "value", ")", ":", "string", "{", "$", "options", "=", "FieldUtility", "::", "getList", "(", "sprintf", "(", "'%s.%s'", ",", "$", "table", "->", "getAlias", "(", ")", ",", "$", "listName", ")", ",", "true", ")", ";", "// check against list options values", "foreach", "(", "$", "options", "as", "$", "val", "=>", "$", "params", ")", "{", "if", "(", "$", "val", "!==", "$", "value", ")", "{", "continue", ";", "}", "return", "$", "val", ";", "}", "// check against list options labels", "foreach", "(", "$", "options", "as", "$", "val", "=>", "$", "params", ")", "{", "if", "(", "$", "params", "[", "'label'", "]", "!==", "$", "value", ")", "{", "continue", ";", "}", "return", "$", "val", ";", "}", "return", "$", "value", ";", "}" ]
Fetch list value. First will try to find if the row value matches one of the list options. @param \Cake\Datasource\RepositoryInterface $table Table instance @param string $listName List name @param string $value Field value @return string
[ "Fetch", "list", "value", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ImportShell.php#L544-L567
train
QoboLtd/cakephp-csv-migrations
src/Shell/ImportShell.php
ImportShell._importFail
protected function _importFail(ImportResult $entity, array $errors) : bool { $table = TableRegistry::get('CsvMigrations.ImportResults'); Assert::isInstanceOf($table, ImportResultsTable::class); $entity->set('status', $table::STATUS_FAIL); $message = sprintf($table::STATUS_FAIL_MESSAGE, json_encode($errors)); $entity->set('status_message', $message); return (bool)$table->save($entity); }
php
protected function _importFail(ImportResult $entity, array $errors) : bool { $table = TableRegistry::get('CsvMigrations.ImportResults'); Assert::isInstanceOf($table, ImportResultsTable::class); $entity->set('status', $table::STATUS_FAIL); $message = sprintf($table::STATUS_FAIL_MESSAGE, json_encode($errors)); $entity->set('status_message', $message); return (bool)$table->save($entity); }
[ "protected", "function", "_importFail", "(", "ImportResult", "$", "entity", ",", "array", "$", "errors", ")", ":", "bool", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "'CsvMigrations.ImportResults'", ")", ";", "Assert", "::", "isInstanceOf", "(", "$", "table", ",", "ImportResultsTable", "::", "class", ")", ";", "$", "entity", "->", "set", "(", "'status'", ",", "$", "table", "::", "STATUS_FAIL", ")", ";", "$", "message", "=", "sprintf", "(", "$", "table", "::", "STATUS_FAIL_MESSAGE", ",", "json_encode", "(", "$", "errors", ")", ")", ";", "$", "entity", "->", "set", "(", "'status_message'", ",", "$", "message", ")", ";", "return", "(", "bool", ")", "$", "table", "->", "save", "(", "$", "entity", ")", ";", "}" ]
Mark import result as failed. @param \CsvMigrations\Model\Entity\ImportResult $entity ImportResult entity @param mixed[] $errors Fail errors @return bool
[ "Mark", "import", "result", "as", "failed", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ImportShell.php#L576-L586
train
QoboLtd/cakephp-csv-migrations
src/Shell/ImportShell.php
ImportShell._importSuccess
protected function _importSuccess(ImportResult $importResult, EntityInterface $entity) : bool { $table = TableRegistry::get('CsvMigrations.ImportResults'); Assert::isInstanceOf($table, ImportResultsTable::class); $importResult->set('model_id', $entity->get('id')); $importResult->set('status', $table::STATUS_SUCCESS); $importResult->set('status_message', $table::STATUS_SUCCESS_MESSAGE); return (bool)$table->save($importResult); }
php
protected function _importSuccess(ImportResult $importResult, EntityInterface $entity) : bool { $table = TableRegistry::get('CsvMigrations.ImportResults'); Assert::isInstanceOf($table, ImportResultsTable::class); $importResult->set('model_id', $entity->get('id')); $importResult->set('status', $table::STATUS_SUCCESS); $importResult->set('status_message', $table::STATUS_SUCCESS_MESSAGE); return (bool)$table->save($importResult); }
[ "protected", "function", "_importSuccess", "(", "ImportResult", "$", "importResult", ",", "EntityInterface", "$", "entity", ")", ":", "bool", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "'CsvMigrations.ImportResults'", ")", ";", "Assert", "::", "isInstanceOf", "(", "$", "table", ",", "ImportResultsTable", "::", "class", ")", ";", "$", "importResult", "->", "set", "(", "'model_id'", ",", "$", "entity", "->", "get", "(", "'id'", ")", ")", ";", "$", "importResult", "->", "set", "(", "'status'", ",", "$", "table", "::", "STATUS_SUCCESS", ")", ";", "$", "importResult", "->", "set", "(", "'status_message'", ",", "$", "table", "::", "STATUS_SUCCESS_MESSAGE", ")", ";", "return", "(", "bool", ")", "$", "table", "->", "save", "(", "$", "importResult", ")", ";", "}" ]
Mark import result as successful. @param \CsvMigrations\Model\Entity\ImportResult $importResult ImportResult entity @param \Cake\Datasource\EntityInterface $entity Newly created Entity @return bool
[ "Mark", "import", "result", "as", "successful", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ImportShell.php#L595-L605
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/DbField.php
DbField.fromCsvField
public static function fromCsvField(CsvField $csvField) : DbField { return new self( $csvField->getName(), $csvField->getType(), $csvField->getLimit(), $csvField->getRequired(), $csvField->getNonSearchable(), $csvField->getUnique() ); }
php
public static function fromCsvField(CsvField $csvField) : DbField { return new self( $csvField->getName(), $csvField->getType(), $csvField->getLimit(), $csvField->getRequired(), $csvField->getNonSearchable(), $csvField->getUnique() ); }
[ "public", "static", "function", "fromCsvField", "(", "CsvField", "$", "csvField", ")", ":", "DbField", "{", "return", "new", "self", "(", "$", "csvField", "->", "getName", "(", ")", ",", "$", "csvField", "->", "getType", "(", ")", ",", "$", "csvField", "->", "getLimit", "(", ")", ",", "$", "csvField", "->", "getRequired", "(", ")", ",", "$", "csvField", "->", "getNonSearchable", "(", ")", ",", "$", "csvField", "->", "getUnique", "(", ")", ")", ";", "}" ]
Construct a new instance from CsvField @param \CsvMigrations\FieldHandlers\CsvField $csvField CsvField instance @return \CsvMigrations\FieldHandlers\DbField
[ "Construct", "a", "new", "instance", "from", "CsvField" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/DbField.php#L102-L112
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/DbField.php
DbField.setDefaultOptions
protected function setDefaultOptions() : void { $type = $this->getType(); if (! empty($this->defaultOptions[$type])) { $this->options = $this->defaultOptions[$type]; } }
php
protected function setDefaultOptions() : void { $type = $this->getType(); if (! empty($this->defaultOptions[$type])) { $this->options = $this->defaultOptions[$type]; } }
[ "protected", "function", "setDefaultOptions", "(", ")", ":", "void", "{", "$", "type", "=", "$", "this", "->", "getType", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "defaultOptions", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "options", "=", "$", "this", "->", "defaultOptions", "[", "$", "type", "]", ";", "}", "}" ]
Populate options with defaults @return void
[ "Populate", "options", "with", "defaults" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/DbField.php#L119-L125
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/DbField.php
DbField.setType
protected function setType(string $type) : void { if (empty($type)) { throw new InvalidArgumentException(__CLASS__ . ': Empty field type is not allowed'); } if (! in_array($type, array_keys($this->defaultOptions))) { throw new InvalidArgumentException(__CLASS__ . ': Unsupported field type: ' . $type); } $this->type = $type; }
php
protected function setType(string $type) : void { if (empty($type)) { throw new InvalidArgumentException(__CLASS__ . ': Empty field type is not allowed'); } if (! in_array($type, array_keys($this->defaultOptions))) { throw new InvalidArgumentException(__CLASS__ . ': Unsupported field type: ' . $type); } $this->type = $type; }
[ "protected", "function", "setType", "(", "string", "$", "type", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "type", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "__CLASS__", ".", "': Empty field type is not allowed'", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "type", ",", "array_keys", "(", "$", "this", "->", "defaultOptions", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "__CLASS__", ".", "': Unsupported field type: '", ".", "$", "type", ")", ";", "}", "$", "this", "->", "type", "=", "$", "type", ";", "}" ]
Field type setter. @param string $type field type @return void
[ "Field", "type", "setter", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/DbField.php#L179-L190
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/DbField.php
DbField.getLimit
public function getLimit() { $result = null; if (isset($this->options['limit'])) { $result = $this->options['limit']; } return $result; }
php
public function getLimit() { $result = null; if (isset($this->options['limit'])) { $result = $this->options['limit']; } return $result; }
[ "public", "function", "getLimit", "(", ")", "{", "$", "result", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'limit'", "]", ")", ")", "{", "$", "result", "=", "$", "this", "->", "options", "[", "'limit'", "]", ";", "}", "return", "$", "result", ";", "}" ]
Field limit getter. @return int|string|null
[ "Field", "limit", "getter", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/DbField.php#L220-L228
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getModulesWithoutRelations
public function getModulesWithoutRelations(array $modules) : array { $result = []; foreach ($modules as $moduleName => $module) { if (isset($module['relations']) && is_array($module['relations']) && ! empty($module['relations'])) { continue; } $result[] = $moduleName; } return $result; }
php
public function getModulesWithoutRelations(array $modules) : array { $result = []; foreach ($modules as $moduleName => $module) { if (isset($module['relations']) && is_array($module['relations']) && ! empty($module['relations'])) { continue; } $result[] = $moduleName; } return $result; }
[ "public", "function", "getModulesWithoutRelations", "(", "array", "$", "modules", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "modules", "as", "$", "moduleName", "=>", "$", "module", ")", "{", "if", "(", "isset", "(", "$", "module", "[", "'relations'", "]", ")", "&&", "is_array", "(", "$", "module", "[", "'relations'", "]", ")", "&&", "!", "empty", "(", "$", "module", "[", "'relations'", "]", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "moduleName", ";", "}", "return", "$", "result", ";", "}" ]
Return a list of module names that do not have relations. @param mixed[] $modules modules. @return mixed[]
[ "Return", "a", "list", "of", "module", "names", "that", "do", "not", "have", "relations", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L125-L136
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getCSVModuleAttr
protected function getCSVModuleAttr(string $moduleName) : array { if (empty($this->modules[$moduleName])) { return []; } return $this->modules[$moduleName]; }
php
protected function getCSVModuleAttr(string $moduleName) : array { if (empty($this->modules[$moduleName])) { return []; } return $this->modules[$moduleName]; }
[ "protected", "function", "getCSVModuleAttr", "(", "string", "$", "moduleName", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "modules", "[", "$", "moduleName", "]", ")", ")", "{", "return", "[", "]", ";", "}", "return", "$", "this", "->", "modules", "[", "$", "moduleName", "]", ";", "}" ]
Get all the csv module's properties @param string $moduleName module name. @return mixed[]
[ "Get", "all", "the", "csv", "module", "s", "properties" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L144-L151
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getFieldValueBasedOnType
protected function getFieldValueBasedOnType(string $type, string $moduleName = '', string $listName = '') { $faker = Factory::create(); $value = null; switch ($type) { case 'uuid': $value = $faker->unique()->uuid; break; case 'url': $value = $faker->url; break; case 'time': $value = $faker->unique()->time('HH:mm'); break; case 'string': $value = $faker->unique()->text(20); break; case 'text': $value = $faker->unique()->paragraph(); break; case 'phone': $value = $faker->unique()->phoneNumber; break; case 'decimal': $value = $faker->unique()->randomFloat(); break; case 'integer': $value = $faker->unique()->numberBetween(); break; case 'email': $value = $faker->unique()->email; break; case 'datetime': case 'reminder': $value = $faker->unique()->dateTime('yyyy-MM-dd HH:mm:ss'); break; case 'date': $value = $faker->unique()->date('yyyy-MM-dd'); break; case 'boolean': $value = $faker->unique()->boolean(); break; default: if (strpos($type, 'list') !== false || strpos($type, 'money') !== false || strpos($type, 'metric') !== false) { //get list values if (empty($listName)) { $listName = $this->getStringEnclosedInParenthesis($type); } $list = $this->getListData($moduleName, $listName); if (empty($list) || count($list) == 0) { $value = null; break; } $value = $faker->randomElement($list); } if (strpos($type, 'related') !== false) { //get list values $moduleName = $this->getStringEnclosedInParenthesis($type); $list = $this->getModuleIds($moduleName); if (empty($list) || count($list) == 0) { $value = null; break; } $value = $faker->randomElement($list); } } return $value; }
php
protected function getFieldValueBasedOnType(string $type, string $moduleName = '', string $listName = '') { $faker = Factory::create(); $value = null; switch ($type) { case 'uuid': $value = $faker->unique()->uuid; break; case 'url': $value = $faker->url; break; case 'time': $value = $faker->unique()->time('HH:mm'); break; case 'string': $value = $faker->unique()->text(20); break; case 'text': $value = $faker->unique()->paragraph(); break; case 'phone': $value = $faker->unique()->phoneNumber; break; case 'decimal': $value = $faker->unique()->randomFloat(); break; case 'integer': $value = $faker->unique()->numberBetween(); break; case 'email': $value = $faker->unique()->email; break; case 'datetime': case 'reminder': $value = $faker->unique()->dateTime('yyyy-MM-dd HH:mm:ss'); break; case 'date': $value = $faker->unique()->date('yyyy-MM-dd'); break; case 'boolean': $value = $faker->unique()->boolean(); break; default: if (strpos($type, 'list') !== false || strpos($type, 'money') !== false || strpos($type, 'metric') !== false) { //get list values if (empty($listName)) { $listName = $this->getStringEnclosedInParenthesis($type); } $list = $this->getListData($moduleName, $listName); if (empty($list) || count($list) == 0) { $value = null; break; } $value = $faker->randomElement($list); } if (strpos($type, 'related') !== false) { //get list values $moduleName = $this->getStringEnclosedInParenthesis($type); $list = $this->getModuleIds($moduleName); if (empty($list) || count($list) == 0) { $value = null; break; } $value = $faker->randomElement($list); } } return $value; }
[ "protected", "function", "getFieldValueBasedOnType", "(", "string", "$", "type", ",", "string", "$", "moduleName", "=", "''", ",", "string", "$", "listName", "=", "''", ")", "{", "$", "faker", "=", "Factory", "::", "create", "(", ")", ";", "$", "value", "=", "null", ";", "switch", "(", "$", "type", ")", "{", "case", "'uuid'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "uuid", ";", "break", ";", "case", "'url'", ":", "$", "value", "=", "$", "faker", "->", "url", ";", "break", ";", "case", "'time'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "time", "(", "'HH:mm'", ")", ";", "break", ";", "case", "'string'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "text", "(", "20", ")", ";", "break", ";", "case", "'text'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "paragraph", "(", ")", ";", "break", ";", "case", "'phone'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "phoneNumber", ";", "break", ";", "case", "'decimal'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "randomFloat", "(", ")", ";", "break", ";", "case", "'integer'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "numberBetween", "(", ")", ";", "break", ";", "case", "'email'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "email", ";", "break", ";", "case", "'datetime'", ":", "case", "'reminder'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "dateTime", "(", "'yyyy-MM-dd HH:mm:ss'", ")", ";", "break", ";", "case", "'date'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "date", "(", "'yyyy-MM-dd'", ")", ";", "break", ";", "case", "'boolean'", ":", "$", "value", "=", "$", "faker", "->", "unique", "(", ")", "->", "boolean", "(", ")", ";", "break", ";", "default", ":", "if", "(", "strpos", "(", "$", "type", ",", "'list'", ")", "!==", "false", "||", "strpos", "(", "$", "type", ",", "'money'", ")", "!==", "false", "||", "strpos", "(", "$", "type", ",", "'metric'", ")", "!==", "false", ")", "{", "//get list values", "if", "(", "empty", "(", "$", "listName", ")", ")", "{", "$", "listName", "=", "$", "this", "->", "getStringEnclosedInParenthesis", "(", "$", "type", ")", ";", "}", "$", "list", "=", "$", "this", "->", "getListData", "(", "$", "moduleName", ",", "$", "listName", ")", ";", "if", "(", "empty", "(", "$", "list", ")", "||", "count", "(", "$", "list", ")", "==", "0", ")", "{", "$", "value", "=", "null", ";", "break", ";", "}", "$", "value", "=", "$", "faker", "->", "randomElement", "(", "$", "list", ")", ";", "}", "if", "(", "strpos", "(", "$", "type", ",", "'related'", ")", "!==", "false", ")", "{", "//get list values", "$", "moduleName", "=", "$", "this", "->", "getStringEnclosedInParenthesis", "(", "$", "type", ")", ";", "$", "list", "=", "$", "this", "->", "getModuleIds", "(", "$", "moduleName", ")", ";", "if", "(", "empty", "(", "$", "list", ")", "||", "count", "(", "$", "list", ")", "==", "0", ")", "{", "$", "value", "=", "null", ";", "break", ";", "}", "$", "value", "=", "$", "faker", "->", "randomElement", "(", "$", "list", ")", ";", "}", "}", "return", "$", "value", ";", "}" ]
Get field value based on type. @param string $type type. @param string $moduleName module name. @param string $listName listName. @return mixed
[ "Get", "field", "value", "based", "on", "type", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L161-L231
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getCombinedFieldValueBasedOnType
protected function getCombinedFieldValueBasedOnType(string $type, string $moduleName, string $fieldName) : array { $values = []; if (strpos($type, 'money') !== false) { $values[$fieldName . '_amount'] = $this->getFieldValueBasedOnType('decimal', $moduleName); $values[$fieldName . '_currency'] = $this->getFieldValueBasedOnType($type, $moduleName); } if (strpos($type, 'metric') !== false) { $values[$fieldName . '_amount'] = $this->getFieldValueBasedOnType('decimal', $moduleName); $values[$fieldName . '_unit'] = $this->getFieldValueBasedOnType($type, $moduleName); } return $values; }
php
protected function getCombinedFieldValueBasedOnType(string $type, string $moduleName, string $fieldName) : array { $values = []; if (strpos($type, 'money') !== false) { $values[$fieldName . '_amount'] = $this->getFieldValueBasedOnType('decimal', $moduleName); $values[$fieldName . '_currency'] = $this->getFieldValueBasedOnType($type, $moduleName); } if (strpos($type, 'metric') !== false) { $values[$fieldName . '_amount'] = $this->getFieldValueBasedOnType('decimal', $moduleName); $values[$fieldName . '_unit'] = $this->getFieldValueBasedOnType($type, $moduleName); } return $values; }
[ "protected", "function", "getCombinedFieldValueBasedOnType", "(", "string", "$", "type", ",", "string", "$", "moduleName", ",", "string", "$", "fieldName", ")", ":", "array", "{", "$", "values", "=", "[", "]", ";", "if", "(", "strpos", "(", "$", "type", ",", "'money'", ")", "!==", "false", ")", "{", "$", "values", "[", "$", "fieldName", ".", "'_amount'", "]", "=", "$", "this", "->", "getFieldValueBasedOnType", "(", "'decimal'", ",", "$", "moduleName", ")", ";", "$", "values", "[", "$", "fieldName", ".", "'_currency'", "]", "=", "$", "this", "->", "getFieldValueBasedOnType", "(", "$", "type", ",", "$", "moduleName", ")", ";", "}", "if", "(", "strpos", "(", "$", "type", ",", "'metric'", ")", "!==", "false", ")", "{", "$", "values", "[", "$", "fieldName", ".", "'_amount'", "]", "=", "$", "this", "->", "getFieldValueBasedOnType", "(", "'decimal'", ",", "$", "moduleName", ")", ";", "$", "values", "[", "$", "fieldName", ".", "'_unit'", "]", "=", "$", "this", "->", "getFieldValueBasedOnType", "(", "$", "type", ",", "$", "moduleName", ")", ";", "}", "return", "$", "values", ";", "}" ]
if the type is money,metric will return the multifield values based on the type. @param string $type type. @param string $moduleName moduleName. @param string $fieldName fieldName. @return mixed[]
[ "if", "the", "type", "is", "money", "metric", "will", "return", "the", "multifield", "values", "based", "on", "the", "type", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L241-L255
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getModuleIds
protected function getModuleIds(string $moduleName) : array { $table = TableRegistry::get($moduleName); $query = $table->find() ->limit(100) ->select($table->getPrimaryKey()); $result = []; foreach ($query->all() as $entity) { $result[] = $entity->get($table->getPrimaryKey()); } return $result; }
php
protected function getModuleIds(string $moduleName) : array { $table = TableRegistry::get($moduleName); $query = $table->find() ->limit(100) ->select($table->getPrimaryKey()); $result = []; foreach ($query->all() as $entity) { $result[] = $entity->get($table->getPrimaryKey()); } return $result; }
[ "protected", "function", "getModuleIds", "(", "string", "$", "moduleName", ")", ":", "array", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "$", "moduleName", ")", ";", "$", "query", "=", "$", "table", "->", "find", "(", ")", "->", "limit", "(", "100", ")", "->", "select", "(", "$", "table", "->", "getPrimaryKey", "(", ")", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "query", "->", "all", "(", ")", "as", "$", "entity", ")", "{", "$", "result", "[", "]", "=", "$", "entity", "->", "get", "(", "$", "table", "->", "getPrimaryKey", "(", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get Module ids in an array. @param string $moduleName module name @return string[]
[ "Get", "Module", "ids", "in", "an", "array", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L263-L276
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.checkModuleRelations
protected function checkModuleRelations(array $modules) : array { $modulesWithRelations = []; foreach ($modules as $name => $module) { $module['relations'] = []; foreach ($module as $field) { if (empty($field['type'])) { continue; } if (strpos($field['type'], 'related') !== false) { //get related module $type = $this->getStringEnclosedInParenthesis($field['type']); $module['relations'][] = $type; } } $modulesWithRelations[$name] = $module; } return $modulesWithRelations; }
php
protected function checkModuleRelations(array $modules) : array { $modulesWithRelations = []; foreach ($modules as $name => $module) { $module['relations'] = []; foreach ($module as $field) { if (empty($field['type'])) { continue; } if (strpos($field['type'], 'related') !== false) { //get related module $type = $this->getStringEnclosedInParenthesis($field['type']); $module['relations'][] = $type; } } $modulesWithRelations[$name] = $module; } return $modulesWithRelations; }
[ "protected", "function", "checkModuleRelations", "(", "array", "$", "modules", ")", ":", "array", "{", "$", "modulesWithRelations", "=", "[", "]", ";", "foreach", "(", "$", "modules", "as", "$", "name", "=>", "$", "module", ")", "{", "$", "module", "[", "'relations'", "]", "=", "[", "]", ";", "foreach", "(", "$", "module", "as", "$", "field", ")", "{", "if", "(", "empty", "(", "$", "field", "[", "'type'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "strpos", "(", "$", "field", "[", "'type'", "]", ",", "'related'", ")", "!==", "false", ")", "{", "//get related module", "$", "type", "=", "$", "this", "->", "getStringEnclosedInParenthesis", "(", "$", "field", "[", "'type'", "]", ")", ";", "$", "module", "[", "'relations'", "]", "[", "]", "=", "$", "type", ";", "}", "}", "$", "modulesWithRelations", "[", "$", "name", "]", "=", "$", "module", ";", "}", "return", "$", "modulesWithRelations", ";", "}" ]
Check module relations. @param mixed[] $modules modules @return mixed[]
[ "Check", "module", "relations", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L315-L335
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.getModuleCsvData
protected function getModuleCsvData(array $modules) : array { $csvFiles = []; foreach ($modules as $module) { $mc = new ModuleConfig(ConfigType::MIGRATION(), $module); $config = json_encode($mc->parse()); if (false === $config) { continue; } $config = json_decode($config, true); if (empty($config)) { continue; } if (! isset($csvFiles[$module])) { $csvFiles[$module] = []; } $csvFiles[$module] = $config; } return $csvFiles; }
php
protected function getModuleCsvData(array $modules) : array { $csvFiles = []; foreach ($modules as $module) { $mc = new ModuleConfig(ConfigType::MIGRATION(), $module); $config = json_encode($mc->parse()); if (false === $config) { continue; } $config = json_decode($config, true); if (empty($config)) { continue; } if (! isset($csvFiles[$module])) { $csvFiles[$module] = []; } $csvFiles[$module] = $config; } return $csvFiles; }
[ "protected", "function", "getModuleCsvData", "(", "array", "$", "modules", ")", ":", "array", "{", "$", "csvFiles", "=", "[", "]", ";", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "$", "mc", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "module", ")", ";", "$", "config", "=", "json_encode", "(", "$", "mc", "->", "parse", "(", ")", ")", ";", "if", "(", "false", "===", "$", "config", ")", "{", "continue", ";", "}", "$", "config", "=", "json_decode", "(", "$", "config", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "csvFiles", "[", "$", "module", "]", ")", ")", "{", "$", "csvFiles", "[", "$", "module", "]", "=", "[", "]", ";", "}", "$", "csvFiles", "[", "$", "module", "]", "=", "$", "config", ";", "}", "return", "$", "csvFiles", ";", "}" ]
Get module csv data. @param string[] $modules modules @return mixed[]
[ "Get", "module", "csv", "data", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L354-L379
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.populateDataInModule
protected function populateDataInModule(string $moduleName) : void { if ('' === $moduleName) { return; } if (in_array($moduleName, $this->skipModules)) { return; } $module = $this->getCSVModuleAttr($moduleName); if (empty($module)) { return; } $table = TableRegistry::get($moduleName); for ($count = 0; $count < $this->numberOfRecords; $count++) { $entity = $table->newEntity(); $data = []; foreach ($module as $fieldName => $fieldData) { if (empty($fieldData['type'])) { continue; } if ($this->isCombinedField($fieldData['type'])) { $fields = $this->getCombinedFieldValueBasedOnType($fieldData['type'], '', (string)$fieldName); foreach ($fields as $field => $value) { $data[$field] = $value; } continue; } $fieldValue = $this->getFieldValueBasedOnType($fieldData['type']); if (empty($fieldValue)) { continue; } $data[$fieldName] = $fieldValue; } $entity = $table->patchEntity($entity, $data); if ($table->save($entity)) { $id = $entity->id; } } $this->modulesPolpulatedWithData[] = $moduleName; $this->out($moduleName); }
php
protected function populateDataInModule(string $moduleName) : void { if ('' === $moduleName) { return; } if (in_array($moduleName, $this->skipModules)) { return; } $module = $this->getCSVModuleAttr($moduleName); if (empty($module)) { return; } $table = TableRegistry::get($moduleName); for ($count = 0; $count < $this->numberOfRecords; $count++) { $entity = $table->newEntity(); $data = []; foreach ($module as $fieldName => $fieldData) { if (empty($fieldData['type'])) { continue; } if ($this->isCombinedField($fieldData['type'])) { $fields = $this->getCombinedFieldValueBasedOnType($fieldData['type'], '', (string)$fieldName); foreach ($fields as $field => $value) { $data[$field] = $value; } continue; } $fieldValue = $this->getFieldValueBasedOnType($fieldData['type']); if (empty($fieldValue)) { continue; } $data[$fieldName] = $fieldValue; } $entity = $table->patchEntity($entity, $data); if ($table->save($entity)) { $id = $entity->id; } } $this->modulesPolpulatedWithData[] = $moduleName; $this->out($moduleName); }
[ "protected", "function", "populateDataInModule", "(", "string", "$", "moduleName", ")", ":", "void", "{", "if", "(", "''", "===", "$", "moduleName", ")", "{", "return", ";", "}", "if", "(", "in_array", "(", "$", "moduleName", ",", "$", "this", "->", "skipModules", ")", ")", "{", "return", ";", "}", "$", "module", "=", "$", "this", "->", "getCSVModuleAttr", "(", "$", "moduleName", ")", ";", "if", "(", "empty", "(", "$", "module", ")", ")", "{", "return", ";", "}", "$", "table", "=", "TableRegistry", "::", "get", "(", "$", "moduleName", ")", ";", "for", "(", "$", "count", "=", "0", ";", "$", "count", "<", "$", "this", "->", "numberOfRecords", ";", "$", "count", "++", ")", "{", "$", "entity", "=", "$", "table", "->", "newEntity", "(", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "module", "as", "$", "fieldName", "=>", "$", "fieldData", ")", "{", "if", "(", "empty", "(", "$", "fieldData", "[", "'type'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "this", "->", "isCombinedField", "(", "$", "fieldData", "[", "'type'", "]", ")", ")", "{", "$", "fields", "=", "$", "this", "->", "getCombinedFieldValueBasedOnType", "(", "$", "fieldData", "[", "'type'", "]", ",", "''", ",", "(", "string", ")", "$", "fieldName", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "data", "[", "$", "field", "]", "=", "$", "value", ";", "}", "continue", ";", "}", "$", "fieldValue", "=", "$", "this", "->", "getFieldValueBasedOnType", "(", "$", "fieldData", "[", "'type'", "]", ")", ";", "if", "(", "empty", "(", "$", "fieldValue", ")", ")", "{", "continue", ";", "}", "$", "data", "[", "$", "fieldName", "]", "=", "$", "fieldValue", ";", "}", "$", "entity", "=", "$", "table", "->", "patchEntity", "(", "$", "entity", ",", "$", "data", ")", ";", "if", "(", "$", "table", "->", "save", "(", "$", "entity", ")", ")", "{", "$", "id", "=", "$", "entity", "->", "id", ";", "}", "}", "$", "this", "->", "modulesPolpulatedWithData", "[", "]", "=", "$", "moduleName", ";", "$", "this", "->", "out", "(", "$", "moduleName", ")", ";", "}" ]
Insert data into module. @param string $moduleName module name. @return void
[ "Insert", "data", "into", "module", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L387-L435
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.isCombinedField
public function isCombinedField(string $type) : bool { $result = false; if (strpos($type, 'money') !== false || strpos($type, 'metric') !== false) { $result = true; } return $result; }
php
public function isCombinedField(string $type) : bool { $result = false; if (strpos($type, 'money') !== false || strpos($type, 'metric') !== false) { $result = true; } return $result; }
[ "public", "function", "isCombinedField", "(", "string", "$", "type", ")", ":", "bool", "{", "$", "result", "=", "false", ";", "if", "(", "strpos", "(", "$", "type", ",", "'money'", ")", "!==", "false", "||", "strpos", "(", "$", "type", ",", "'metric'", ")", "!==", "false", ")", "{", "$", "result", "=", "true", ";", "}", "return", "$", "result", ";", "}" ]
Checks if the type is money or metric. @param string $type type. @return bool
[ "Checks", "if", "the", "type", "is", "money", "or", "metric", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L443-L452
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.createRelationIndex
protected function createRelationIndex(array $modules) : array { $index = []; foreach ($modules as $moduleName => $module) { if (! isset($module['relations'])) { $index[$moduleName] = []; continue; } if (! is_array($module['relations'])) { $index[$moduleName] = []; continue; } foreach ($module['relations'] as $relatedModule) { if (!empty($index[$relatedModule][$moduleName])) { continue; } $index[$relatedModule][] = $moduleName; } } return $index; }
php
protected function createRelationIndex(array $modules) : array { $index = []; foreach ($modules as $moduleName => $module) { if (! isset($module['relations'])) { $index[$moduleName] = []; continue; } if (! is_array($module['relations'])) { $index[$moduleName] = []; continue; } foreach ($module['relations'] as $relatedModule) { if (!empty($index[$relatedModule][$moduleName])) { continue; } $index[$relatedModule][] = $moduleName; } } return $index; }
[ "protected", "function", "createRelationIndex", "(", "array", "$", "modules", ")", ":", "array", "{", "$", "index", "=", "[", "]", ";", "foreach", "(", "$", "modules", "as", "$", "moduleName", "=>", "$", "module", ")", "{", "if", "(", "!", "isset", "(", "$", "module", "[", "'relations'", "]", ")", ")", "{", "$", "index", "[", "$", "moduleName", "]", "=", "[", "]", ";", "continue", ";", "}", "if", "(", "!", "is_array", "(", "$", "module", "[", "'relations'", "]", ")", ")", "{", "$", "index", "[", "$", "moduleName", "]", "=", "[", "]", ";", "continue", ";", "}", "foreach", "(", "$", "module", "[", "'relations'", "]", "as", "$", "relatedModule", ")", "{", "if", "(", "!", "empty", "(", "$", "index", "[", "$", "relatedModule", "]", "[", "$", "moduleName", "]", ")", ")", "{", "continue", ";", "}", "$", "index", "[", "$", "relatedModule", "]", "[", "]", "=", "$", "moduleName", ";", "}", "}", "return", "$", "index", ";", "}" ]
Create relation index between modules. @param mixed[] $modules modules. @return mixed[]
[ "Create", "relation", "index", "between", "modules", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L460-L484
train
QoboLtd/cakephp-csv-migrations
src/Shell/SeedShell.php
SeedShell.checkHierarchyForModule
protected function checkHierarchyForModule(string $moduleName, array $index) : void { if ('' === $moduleName) { return; } //In case the module tried to fill from a previous loop that is still in the stack return. //this way we prevent infinit loops when 2 or more modules are referenced by themselves or by each other in a way that they produce circles. if (in_array($moduleName, $this->stack)) { return; } //add the current module in the stack. $this->stack[] = $moduleName; //In case the module is already filled with data. if (in_array($moduleName, $this->modulesPolpulatedWithData)) { return; } //checking the case that the module do not has any relations. if (! empty($index[$moduleName]) && is_array($index[$moduleName])) { foreach ($index[$moduleName] as $relatedModule) { $this->checkHierarchyForModule($relatedModule, $index); } } $this->populateDataInModule($moduleName); //remove the current module from the stack. unset($this->stack[$moduleName]); }
php
protected function checkHierarchyForModule(string $moduleName, array $index) : void { if ('' === $moduleName) { return; } //In case the module tried to fill from a previous loop that is still in the stack return. //this way we prevent infinit loops when 2 or more modules are referenced by themselves or by each other in a way that they produce circles. if (in_array($moduleName, $this->stack)) { return; } //add the current module in the stack. $this->stack[] = $moduleName; //In case the module is already filled with data. if (in_array($moduleName, $this->modulesPolpulatedWithData)) { return; } //checking the case that the module do not has any relations. if (! empty($index[$moduleName]) && is_array($index[$moduleName])) { foreach ($index[$moduleName] as $relatedModule) { $this->checkHierarchyForModule($relatedModule, $index); } } $this->populateDataInModule($moduleName); //remove the current module from the stack. unset($this->stack[$moduleName]); }
[ "protected", "function", "checkHierarchyForModule", "(", "string", "$", "moduleName", ",", "array", "$", "index", ")", ":", "void", "{", "if", "(", "''", "===", "$", "moduleName", ")", "{", "return", ";", "}", "//In case the module tried to fill from a previous loop that is still in the stack return.", "//this way we prevent infinit loops when 2 or more modules are referenced by themselves or by each other in a way that they produce circles.", "if", "(", "in_array", "(", "$", "moduleName", ",", "$", "this", "->", "stack", ")", ")", "{", "return", ";", "}", "//add the current module in the stack.", "$", "this", "->", "stack", "[", "]", "=", "$", "moduleName", ";", "//In case the module is already filled with data.", "if", "(", "in_array", "(", "$", "moduleName", ",", "$", "this", "->", "modulesPolpulatedWithData", ")", ")", "{", "return", ";", "}", "//checking the case that the module do not has any relations.", "if", "(", "!", "empty", "(", "$", "index", "[", "$", "moduleName", "]", ")", "&&", "is_array", "(", "$", "index", "[", "$", "moduleName", "]", ")", ")", "{", "foreach", "(", "$", "index", "[", "$", "moduleName", "]", "as", "$", "relatedModule", ")", "{", "$", "this", "->", "checkHierarchyForModule", "(", "$", "relatedModule", ",", "$", "index", ")", ";", "}", "}", "$", "this", "->", "populateDataInModule", "(", "$", "moduleName", ")", ";", "//remove the current module from the stack.", "unset", "(", "$", "this", "->", "stack", "[", "$", "moduleName", "]", ")", ";", "}" ]
Check the hierarchy for each module recursively and populate data. @param string $moduleName module name. @param mixed[] $index index. @return void
[ "Check", "the", "hierarchy", "for", "each", "module", "recursively", "and", "populate", "data", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/SeedShell.php#L506-L536
train
QoboLtd/cakephp-csv-migrations
src/Shell/ValidateShell.php
ValidateShell.getOptionParser
public function getOptionParser() { $parser = new ConsoleOptionParser('console'); $parser->setDescription('Validate modules configuration'); $parser->addArgument('modules', [ 'help' => 'Comma-separated list of modules to validate. All will be checked if omitted.', ]); $parser->addOption('no-warnings', [ 'short' => 'n', 'help' => 'Skip warnings (display only errors)', 'default' => false, 'boolean' => true, ]); return $parser; }
php
public function getOptionParser() { $parser = new ConsoleOptionParser('console'); $parser->setDescription('Validate modules configuration'); $parser->addArgument('modules', [ 'help' => 'Comma-separated list of modules to validate. All will be checked if omitted.', ]); $parser->addOption('no-warnings', [ 'short' => 'n', 'help' => 'Skip warnings (display only errors)', 'default' => false, 'boolean' => true, ]); return $parser; }
[ "public", "function", "getOptionParser", "(", ")", "{", "$", "parser", "=", "new", "ConsoleOptionParser", "(", "'console'", ")", ";", "$", "parser", "->", "setDescription", "(", "'Validate modules configuration'", ")", ";", "$", "parser", "->", "addArgument", "(", "'modules'", ",", "[", "'help'", "=>", "'Comma-separated list of modules to validate. All will be checked if omitted.'", ",", "]", ")", ";", "$", "parser", "->", "addOption", "(", "'no-warnings'", ",", "[", "'short'", "=>", "'n'", ",", "'help'", "=>", "'Skip warnings (display only errors)'", ",", "'default'", "=>", "false", ",", "'boolean'", "=>", "true", ",", "]", ")", ";", "return", "$", "parser", ";", "}" ]
Set shell description and command line options @return ConsoleOptionParser
[ "Set", "shell", "description", "and", "command", "line", "options" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ValidateShell.php#L38-L53
train
QoboLtd/cakephp-csv-migrations
src/Shell/ValidateShell.php
ValidateShell.main
public function main(string $modules = '') { $this->info('Checking modules configuration'); $this->hr(); $this->modules = Utility::getModules(); $this->skipWarnings = (bool)$this->param('no-warnings'); if (empty($this->modules)) { $this->warn('Did not find any modules'); exit(); } $modules = '' === $modules ? $this->modules : explode(',', $modules); $errorsCount = $this->validateModules($modules); if ($errorsCount > 0) { $this->abort("Errors found: $errorsCount. Validation failed!"); } $this->success('No errors found. Validation passed!'); }
php
public function main(string $modules = '') { $this->info('Checking modules configuration'); $this->hr(); $this->modules = Utility::getModules(); $this->skipWarnings = (bool)$this->param('no-warnings'); if (empty($this->modules)) { $this->warn('Did not find any modules'); exit(); } $modules = '' === $modules ? $this->modules : explode(',', $modules); $errorsCount = $this->validateModules($modules); if ($errorsCount > 0) { $this->abort("Errors found: $errorsCount. Validation failed!"); } $this->success('No errors found. Validation passed!'); }
[ "public", "function", "main", "(", "string", "$", "modules", "=", "''", ")", "{", "$", "this", "->", "info", "(", "'Checking modules configuration'", ")", ";", "$", "this", "->", "hr", "(", ")", ";", "$", "this", "->", "modules", "=", "Utility", "::", "getModules", "(", ")", ";", "$", "this", "->", "skipWarnings", "=", "(", "bool", ")", "$", "this", "->", "param", "(", "'no-warnings'", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "modules", ")", ")", "{", "$", "this", "->", "warn", "(", "'Did not find any modules'", ")", ";", "exit", "(", ")", ";", "}", "$", "modules", "=", "''", "===", "$", "modules", "?", "$", "this", "->", "modules", ":", "explode", "(", "','", ",", "$", "modules", ")", ";", "$", "errorsCount", "=", "$", "this", "->", "validateModules", "(", "$", "modules", ")", ";", "if", "(", "$", "errorsCount", ">", "0", ")", "{", "$", "this", "->", "abort", "(", "\"Errors found: $errorsCount. Validation failed!\"", ")", ";", "}", "$", "this", "->", "success", "(", "'No errors found. Validation passed!'", ")", ";", "}" ]
Main method for shell execution @param string $modules Comma-separated list of module names to validate @return bool|int|void
[ "Main", "method", "for", "shell", "execution" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ValidateShell.php#L61-L80
train
QoboLtd/cakephp-csv-migrations
src/Shell/ValidateShell.php
ValidateShell.validateModules
protected function validateModules(array $modules) : int { $result = 0; foreach ($modules as $module) { $this->info("Checking module $module", 2); $moduleResult = $this->runModuleChecks($module); $result += count($moduleResult['errors']); if (!$this->skipWarnings) { $this->printMessages('warn', $moduleResult['warnings']); } $this->printMessages('err', $moduleResult['errors']); $this->hr(); } return $result; }
php
protected function validateModules(array $modules) : int { $result = 0; foreach ($modules as $module) { $this->info("Checking module $module", 2); $moduleResult = $this->runModuleChecks($module); $result += count($moduleResult['errors']); if (!$this->skipWarnings) { $this->printMessages('warn', $moduleResult['warnings']); } $this->printMessages('err', $moduleResult['errors']); $this->hr(); } return $result; }
[ "protected", "function", "validateModules", "(", "array", "$", "modules", ")", ":", "int", "{", "$", "result", "=", "0", ";", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "$", "this", "->", "info", "(", "\"Checking module $module\"", ",", "2", ")", ";", "$", "moduleResult", "=", "$", "this", "->", "runModuleChecks", "(", "$", "module", ")", ";", "$", "result", "+=", "count", "(", "$", "moduleResult", "[", "'errors'", "]", ")", ";", "if", "(", "!", "$", "this", "->", "skipWarnings", ")", "{", "$", "this", "->", "printMessages", "(", "'warn'", ",", "$", "moduleResult", "[", "'warnings'", "]", ")", ";", "}", "$", "this", "->", "printMessages", "(", "'err'", ",", "$", "moduleResult", "[", "'errors'", "]", ")", ";", "$", "this", "->", "hr", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Validate a given list of modules @param string[] $modules List of module names to validate @return int Count of errors found
[ "Validate", "a", "given", "list", "of", "modules" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ValidateShell.php#L88-L107
train
QoboLtd/cakephp-csv-migrations
src/Shell/ValidateShell.php
ValidateShell.runModuleChecks
protected function runModuleChecks(string $module) : array { $result = [ 'errors' => [], 'warnings' => [], ]; if (!in_array($module, $this->modules)) { $result['errors'][] = "$module is not a known module"; return $result; } $checks = Check::getList($module); if (empty($checks)) { $result['warnings'][] = "No checks configured for module [$module]"; return $result; } foreach ($checks as $check => $options) { $this->out(" - Running $check ... ", 0); try { $check = Check::getInstance((string)$check); $checkResult = $check->run($module, $options); } catch (InvalidArgumentException $e) { $result['errors'][] = $e->getMessage(); $this->printCheckStatus(1); continue; } $result['errors'] = array_merge($result['errors'], $check->getErrors()); $result['warnings'] = array_merge($result['warnings'], $check->getWarnings()); $this->printCheckStatus($checkResult); } return $result; }
php
protected function runModuleChecks(string $module) : array { $result = [ 'errors' => [], 'warnings' => [], ]; if (!in_array($module, $this->modules)) { $result['errors'][] = "$module is not a known module"; return $result; } $checks = Check::getList($module); if (empty($checks)) { $result['warnings'][] = "No checks configured for module [$module]"; return $result; } foreach ($checks as $check => $options) { $this->out(" - Running $check ... ", 0); try { $check = Check::getInstance((string)$check); $checkResult = $check->run($module, $options); } catch (InvalidArgumentException $e) { $result['errors'][] = $e->getMessage(); $this->printCheckStatus(1); continue; } $result['errors'] = array_merge($result['errors'], $check->getErrors()); $result['warnings'] = array_merge($result['warnings'], $check->getWarnings()); $this->printCheckStatus($checkResult); } return $result; }
[ "protected", "function", "runModuleChecks", "(", "string", "$", "module", ")", ":", "array", "{", "$", "result", "=", "[", "'errors'", "=>", "[", "]", ",", "'warnings'", "=>", "[", "]", ",", "]", ";", "if", "(", "!", "in_array", "(", "$", "module", ",", "$", "this", "->", "modules", ")", ")", "{", "$", "result", "[", "'errors'", "]", "[", "]", "=", "\"$module is not a known module\"", ";", "return", "$", "result", ";", "}", "$", "checks", "=", "Check", "::", "getList", "(", "$", "module", ")", ";", "if", "(", "empty", "(", "$", "checks", ")", ")", "{", "$", "result", "[", "'warnings'", "]", "[", "]", "=", "\"No checks configured for module [$module]\"", ";", "return", "$", "result", ";", "}", "foreach", "(", "$", "checks", "as", "$", "check", "=>", "$", "options", ")", "{", "$", "this", "->", "out", "(", "\" - Running $check ... \"", ",", "0", ")", ";", "try", "{", "$", "check", "=", "Check", "::", "getInstance", "(", "(", "string", ")", "$", "check", ")", ";", "$", "checkResult", "=", "$", "check", "->", "run", "(", "$", "module", ",", "$", "options", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "result", "[", "'errors'", "]", "[", "]", "=", "$", "e", "->", "getMessage", "(", ")", ";", "$", "this", "->", "printCheckStatus", "(", "1", ")", ";", "continue", ";", "}", "$", "result", "[", "'errors'", "]", "=", "array_merge", "(", "$", "result", "[", "'errors'", "]", ",", "$", "check", "->", "getErrors", "(", ")", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "array_merge", "(", "$", "result", "[", "'warnings'", "]", ",", "$", "check", "->", "getWarnings", "(", ")", ")", ";", "$", "this", "->", "printCheckStatus", "(", "$", "checkResult", ")", ";", "}", "return", "$", "result", ";", "}" ]
Run validation checks for a given module @param string $module Module name @return mixed[] Array with errors and warnings
[ "Run", "validation", "checks", "for", "a", "given", "module" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ValidateShell.php#L115-L155
train
QoboLtd/cakephp-csv-migrations
src/Shell/ValidateShell.php
ValidateShell.printMessages
protected function printMessages(string $type, array $messages = []) : void { $this->out(''); $plural = Inflector::pluralize($type); if (empty($messages)) { $this->success("No $plural found in module."); return; } // Minimize output to only unique messages $messages = array_unique($messages); $plural = ucfirst($plural); $this->{$type}("$plural (" . count($messages) . "):"); // Remove ROOT path for shorter output $messages = preg_replace('#' . ROOT . DS . '#', '', $messages); if (null === $messages) { return; } // Prefix all messages as list items $messages = preg_replace('/^/', ' - ', $messages); if (null === $messages) { return; } $this->{$type}($messages); }
php
protected function printMessages(string $type, array $messages = []) : void { $this->out(''); $plural = Inflector::pluralize($type); if (empty($messages)) { $this->success("No $plural found in module."); return; } // Minimize output to only unique messages $messages = array_unique($messages); $plural = ucfirst($plural); $this->{$type}("$plural (" . count($messages) . "):"); // Remove ROOT path for shorter output $messages = preg_replace('#' . ROOT . DS . '#', '', $messages); if (null === $messages) { return; } // Prefix all messages as list items $messages = preg_replace('/^/', ' - ', $messages); if (null === $messages) { return; } $this->{$type}($messages); }
[ "protected", "function", "printMessages", "(", "string", "$", "type", ",", "array", "$", "messages", "=", "[", "]", ")", ":", "void", "{", "$", "this", "->", "out", "(", "''", ")", ";", "$", "plural", "=", "Inflector", "::", "pluralize", "(", "$", "type", ")", ";", "if", "(", "empty", "(", "$", "messages", ")", ")", "{", "$", "this", "->", "success", "(", "\"No $plural found in module.\"", ")", ";", "return", ";", "}", "// Minimize output to only unique messages", "$", "messages", "=", "array_unique", "(", "$", "messages", ")", ";", "$", "plural", "=", "ucfirst", "(", "$", "plural", ")", ";", "$", "this", "->", "{", "$", "type", "}", "(", "\"$plural (\"", ".", "count", "(", "$", "messages", ")", ".", "\"):\"", ")", ";", "// Remove ROOT path for shorter output", "$", "messages", "=", "preg_replace", "(", "'#'", ".", "ROOT", ".", "DS", ".", "'#'", ",", "''", ",", "$", "messages", ")", ";", "if", "(", "null", "===", "$", "messages", ")", "{", "return", ";", "}", "// Prefix all messages as list items", "$", "messages", "=", "preg_replace", "(", "'/^/'", ",", "' - '", ",", "$", "messages", ")", ";", "if", "(", "null", "===", "$", "messages", ")", "{", "return", ";", "}", "$", "this", "->", "{", "$", "type", "}", "(", "$", "messages", ")", ";", "}" ]
Print messages of a given type @param string $type Type of messages (info, error, warning, etc) @param string[] $messages Array of messages to report @return void
[ "Print", "messages", "of", "a", "given", "type" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/ValidateShell.php#L184-L214
train
QoboLtd/cakephp-csv-migrations
src/Controller/Traits/ImportTrait.php
ImportTrait.importDownload
public function importDownload(string $id, string $type = 'original') : Response { $table = TableRegistry::get('CsvMigrations.Imports'); $entity = $table->get($id); Assert::isInstanceOf($entity, Import::class); $path = $entity->get('filename'); if ('processed' === $type) { $path = ImportUtility::getProcessedFile($entity); } return $this->response->withFile($path, ['download' => true]); }
php
public function importDownload(string $id, string $type = 'original') : Response { $table = TableRegistry::get('CsvMigrations.Imports'); $entity = $table->get($id); Assert::isInstanceOf($entity, Import::class); $path = $entity->get('filename'); if ('processed' === $type) { $path = ImportUtility::getProcessedFile($entity); } return $this->response->withFile($path, ['download' => true]); }
[ "public", "function", "importDownload", "(", "string", "$", "id", ",", "string", "$", "type", "=", "'original'", ")", ":", "Response", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "'CsvMigrations.Imports'", ")", ";", "$", "entity", "=", "$", "table", "->", "get", "(", "$", "id", ")", ";", "Assert", "::", "isInstanceOf", "(", "$", "entity", ",", "Import", "::", "class", ")", ";", "$", "path", "=", "$", "entity", "->", "get", "(", "'filename'", ")", ";", "if", "(", "'processed'", "===", "$", "type", ")", "{", "$", "path", "=", "ImportUtility", "::", "getProcessedFile", "(", "$", "entity", ")", ";", "}", "return", "$", "this", "->", "response", "->", "withFile", "(", "$", "path", ",", "[", "'download'", "=>", "true", "]", ")", ";", "}" ]
Import download action. @param string $id Import id @param string $type Export Type (supported values: 'original', 'processed') @return \Cake\Http\Response
[ "Import", "download", "action", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Controller/Traits/ImportTrait.php#L123-L135
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/Provider/RenderValue/CurrencyRenderer.php
CurrencyRenderer.getIcon
public static function getIcon(string $key, string $value): string { $currenciesList = Configure::readOrFail('Currencies.list'); //Check if the key exist in currencies list else return just the value if (!array_key_exists($key, $currenciesList)) { return $value; } return sprintf(static::ICON_HTML, $currenciesList[$key]['description'], $currenciesList[$key]['symbol'], $value); }
php
public static function getIcon(string $key, string $value): string { $currenciesList = Configure::readOrFail('Currencies.list'); //Check if the key exist in currencies list else return just the value if (!array_key_exists($key, $currenciesList)) { return $value; } return sprintf(static::ICON_HTML, $currenciesList[$key]['description'], $currenciesList[$key]['symbol'], $value); }
[ "public", "static", "function", "getIcon", "(", "string", "$", "key", ",", "string", "$", "value", ")", ":", "string", "{", "$", "currenciesList", "=", "Configure", "::", "readOrFail", "(", "'Currencies.list'", ")", ";", "//Check if the key exist in currencies list else return just the value", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "currenciesList", ")", ")", "{", "return", "$", "value", ";", "}", "return", "sprintf", "(", "static", "::", "ICON_HTML", ",", "$", "currenciesList", "[", "$", "key", "]", "[", "'description'", "]", ",", "$", "currenciesList", "[", "$", "key", "]", "[", "'symbol'", "]", ",", "$", "value", ")", ";", "}" ]
Get Icon html @param string $key The key @param string $value The value @return string The icon.
[ "Get", "Icon", "html" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/Provider/RenderValue/CurrencyRenderer.php#L56-L65
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isValidList
public static function isValidList(string $list, string $module = '') : bool { if (strpos($list, '.') !== false) { list($module, $list) = explode('.', $list, 2); } $listItems = null; try { $mc = new ModuleConfig(ConfigType::LISTS(), $module, $list, ['cacheSkip' => true]); $config = $mc->parse(); $listItems = property_exists($config, 'items') ? $config->items : null; } catch (InvalidArgumentException $e) { return false; } if (null === $listItems) { return false; } return true; }
php
public static function isValidList(string $list, string $module = '') : bool { if (strpos($list, '.') !== false) { list($module, $list) = explode('.', $list, 2); } $listItems = null; try { $mc = new ModuleConfig(ConfigType::LISTS(), $module, $list, ['cacheSkip' => true]); $config = $mc->parse(); $listItems = property_exists($config, 'items') ? $config->items : null; } catch (InvalidArgumentException $e) { return false; } if (null === $listItems) { return false; } return true; }
[ "public", "static", "function", "isValidList", "(", "string", "$", "list", ",", "string", "$", "module", "=", "''", ")", ":", "bool", "{", "if", "(", "strpos", "(", "$", "list", ",", "'.'", ")", "!==", "false", ")", "{", "list", "(", "$", "module", ",", "$", "list", ")", "=", "explode", "(", "'.'", ",", "$", "list", ",", "2", ")", ";", "}", "$", "listItems", "=", "null", ";", "try", "{", "$", "mc", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "LISTS", "(", ")", ",", "$", "module", ",", "$", "list", ",", "[", "'cacheSkip'", "=>", "true", "]", ")", ";", "$", "config", "=", "$", "mc", "->", "parse", "(", ")", ";", "$", "listItems", "=", "property_exists", "(", "$", "config", ",", "'items'", ")", "?", "$", "config", "->", "items", ":", "null", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "return", "false", ";", "}", "if", "(", "null", "===", "$", "listItems", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if the given list is valid Lists with no items are assumed to be invalid. @param string $list List name to check @param string $module Module name to check the list in @return bool True if valid, false otherwise
[ "Check", "if", "the", "given", "list", "is", "valid" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L67-L87
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isRealModuleField
public static function isRealModuleField(string $module, string $field) : bool { $fields = self::getRealModuleFields($module); // If we couldn't get the migration, we cannot verify if the // field is real or not. To avoid unnecessary fails, we // assume that it's real. if (empty($fields)) { return true; } return in_array($field, $fields); }
php
public static function isRealModuleField(string $module, string $field) : bool { $fields = self::getRealModuleFields($module); // If we couldn't get the migration, we cannot verify if the // field is real or not. To avoid unnecessary fails, we // assume that it's real. if (empty($fields)) { return true; } return in_array($field, $fields); }
[ "public", "static", "function", "isRealModuleField", "(", "string", "$", "module", ",", "string", "$", "field", ")", ":", "bool", "{", "$", "fields", "=", "self", "::", "getRealModuleFields", "(", "$", "module", ")", ";", "// If we couldn't get the migration, we cannot verify if the", "// field is real or not. To avoid unnecessary fails, we", "// assume that it's real.", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "true", ";", "}", "return", "in_array", "(", "$", "field", ",", "$", "fields", ")", ";", "}" ]
Check if the field is defined in the module migration If the migration file does not exist or is not parseable, it is assumed the field is real. Presence and validity of the migration file is checked elsewhere. @param string $module Module to check in @param string $field Field to check @return bool True if field is real, false otherwise
[ "Check", "if", "the", "field", "is", "defined", "in", "the", "module", "migration" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L101-L113
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.getRealModuleFields
public static function getRealModuleFields(string $module, bool $validate = true) : array { $moduleFields = []; $mc = new ModuleConfig(ConfigType::MIGRATION(), $module, null, ['cacheSkip' => true]); $mc->setParser(new Parser($mc->createSchema(), ['validate' => $validate])); $moduleFields = Convert::objectToArray($mc->parse()); $fields = Hash::extract($moduleFields, '{*}.name'); return (array)$fields; }
php
public static function getRealModuleFields(string $module, bool $validate = true) : array { $moduleFields = []; $mc = new ModuleConfig(ConfigType::MIGRATION(), $module, null, ['cacheSkip' => true]); $mc->setParser(new Parser($mc->createSchema(), ['validate' => $validate])); $moduleFields = Convert::objectToArray($mc->parse()); $fields = Hash::extract($moduleFields, '{*}.name'); return (array)$fields; }
[ "public", "static", "function", "getRealModuleFields", "(", "string", "$", "module", ",", "bool", "$", "validate", "=", "true", ")", ":", "array", "{", "$", "moduleFields", "=", "[", "]", ";", "$", "mc", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "module", ",", "null", ",", "[", "'cacheSkip'", "=>", "true", "]", ")", ";", "$", "mc", "->", "setParser", "(", "new", "Parser", "(", "$", "mc", "->", "createSchema", "(", ")", ",", "[", "'validate'", "=>", "$", "validate", "]", ")", ")", ";", "$", "moduleFields", "=", "Convert", "::", "objectToArray", "(", "$", "mc", "->", "parse", "(", ")", ")", ";", "$", "fields", "=", "Hash", "::", "extract", "(", "$", "moduleFields", ",", "'{*}.name'", ")", ";", "return", "(", "array", ")", "$", "fields", ";", "}" ]
Returns a list of fields defined in `migration.json`. @param string $module Module name. @param bool $validate Should the data be validated against the schema. @return string[] List of fields.
[ "Returns", "a", "list", "of", "fields", "defined", "in", "migration", ".", "json", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L122-L132
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isRealRelationField
public static function isRealRelationField(string $module, string $field) : bool { $fields = self::getRealRelationFields($module); if (empty($fields)) { return false; } return in_array($field, $fields); }
php
public static function isRealRelationField(string $module, string $field) : bool { $fields = self::getRealRelationFields($module); if (empty($fields)) { return false; } return in_array($field, $fields); }
[ "public", "static", "function", "isRealRelationField", "(", "string", "$", "module", ",", "string", "$", "field", ")", ":", "bool", "{", "$", "fields", "=", "self", "::", "getRealRelationFields", "(", "$", "module", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "field", ",", "$", "fields", ")", ";", "}" ]
Check if the field is defined in the relation fields list @param string $module Module to check in @param string $field Field to check @return bool True if field is real, false otherwise
[ "Check", "if", "the", "field", "is", "defined", "in", "the", "relation", "fields", "list" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L141-L150
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.getRealRelationFields
public static function getRealRelationFields(string $module) : array { $relation = []; $table = TableRegistry::getTableLocator()->get($module); foreach ($table->associations() as $association) { $relation[] = $association->getName(); } return $relation; }
php
public static function getRealRelationFields(string $module) : array { $relation = []; $table = TableRegistry::getTableLocator()->get($module); foreach ($table->associations() as $association) { $relation[] = $association->getName(); } return $relation; }
[ "public", "static", "function", "getRealRelationFields", "(", "string", "$", "module", ")", ":", "array", "{", "$", "relation", "=", "[", "]", ";", "$", "table", "=", "TableRegistry", "::", "getTableLocator", "(", ")", "->", "get", "(", "$", "module", ")", ";", "foreach", "(", "$", "table", "->", "associations", "(", ")", "as", "$", "association", ")", "{", "$", "relation", "[", "]", "=", "$", "association", "->", "getName", "(", ")", ";", "}", "return", "$", "relation", ";", "}" ]
Returns a list of relation fields. @param string $module Module name. @return string[] List of relation fields.
[ "Returns", "a", "list", "of", "relation", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L158-L168
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.getVirtualModuleFields
public static function getVirtualModuleFields(string $module, bool $validate = true) : array { $fields = []; $mc = new ModuleConfig(ConfigType::MODULE(), $module, null, ['cacheSkip' => true]); $mc->setParser(new Parser($mc->createSchema(), ['validate' => $validate])); $virtualFields = Convert::objectToArray($mc->parse()); if (isset($virtualFields['virtualFields'])) { $fields = $virtualFields['virtualFields']; } return $fields; }
php
public static function getVirtualModuleFields(string $module, bool $validate = true) : array { $fields = []; $mc = new ModuleConfig(ConfigType::MODULE(), $module, null, ['cacheSkip' => true]); $mc->setParser(new Parser($mc->createSchema(), ['validate' => $validate])); $virtualFields = Convert::objectToArray($mc->parse()); if (isset($virtualFields['virtualFields'])) { $fields = $virtualFields['virtualFields']; } return $fields; }
[ "public", "static", "function", "getVirtualModuleFields", "(", "string", "$", "module", ",", "bool", "$", "validate", "=", "true", ")", ":", "array", "{", "$", "fields", "=", "[", "]", ";", "$", "mc", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "module", ",", "null", ",", "[", "'cacheSkip'", "=>", "true", "]", ")", ";", "$", "mc", "->", "setParser", "(", "new", "Parser", "(", "$", "mc", "->", "createSchema", "(", ")", ",", "[", "'validate'", "=>", "$", "validate", "]", ")", ")", ";", "$", "virtualFields", "=", "Convert", "::", "objectToArray", "(", "$", "mc", "->", "parse", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "virtualFields", "[", "'virtualFields'", "]", ")", ")", "{", "$", "fields", "=", "$", "virtualFields", "[", "'virtualFields'", "]", ";", "}", "return", "$", "fields", ";", "}" ]
Returns a list of virtual fields in `config.json`. @param string $module Module name. @param bool $validate Should the data be validated against the schema. @return string[] list of virtual fields.
[ "Returns", "a", "list", "of", "virtual", "fields", "in", "config", ".", "json", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L177-L190
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isVirtualModuleField
public static function isVirtualModuleField(string $module, string $field) : bool { $config = self::getVirtualModuleFields($module); if (empty($config) || !is_array($config)) { return false; } return in_array($field, array_keys($config)); }
php
public static function isVirtualModuleField(string $module, string $field) : bool { $config = self::getVirtualModuleFields($module); if (empty($config) || !is_array($config)) { return false; } return in_array($field, array_keys($config)); }
[ "public", "static", "function", "isVirtualModuleField", "(", "string", "$", "module", ",", "string", "$", "field", ")", ":", "bool", "{", "$", "config", "=", "self", "::", "getVirtualModuleFields", "(", "$", "module", ")", ";", "if", "(", "empty", "(", "$", "config", ")", "||", "!", "is_array", "(", "$", "config", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "field", ",", "array_keys", "(", "$", "config", ")", ")", ";", "}" ]
Check if the field is defined in the module's virtual fields The validity of the virtual field definition is checked elsewhere. Here we only verify that the field exists in the `[virtualFields]` section definition. @param string $module Module to check in @param string $field Field to check @return bool True if field is real, false otherwise
[ "Check", "if", "the", "field", "is", "defined", "in", "the", "module", "s", "virtual", "fields" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L203-L212
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isValidModuleField
public static function isValidModuleField(string $module, string $field) : bool { return static::isRealModuleField($module, $field) || static::isVirtualModuleField($module, $field) || static::isRealRelationField($module, $field); }
php
public static function isValidModuleField(string $module, string $field) : bool { return static::isRealModuleField($module, $field) || static::isVirtualModuleField($module, $field) || static::isRealRelationField($module, $field); }
[ "public", "static", "function", "isValidModuleField", "(", "string", "$", "module", ",", "string", "$", "field", ")", ":", "bool", "{", "return", "static", "::", "isRealModuleField", "(", "$", "module", ",", "$", "field", ")", "||", "static", "::", "isVirtualModuleField", "(", "$", "module", ",", "$", "field", ")", "||", "static", "::", "isRealRelationField", "(", "$", "module", ",", "$", "field", ")", ";", "}" ]
Check if the given field is valid for given module If valid fields are not available from the migration we will assume that the field is valid. @param string $module Module to check in @param string $field Field to check @return bool True if field is valid, false otherwise
[ "Check", "if", "the", "given", "field", "is", "valid", "for", "given", "module" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L224-L227
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Utility.php
Utility.isValidFieldType
public static function isValidFieldType(string $type) : bool { try { $config = ConfigFactory::getByType($type, 'dummy_field'); } catch (InvalidArgumentException $e) { return false; } return true; }
php
public static function isValidFieldType(string $type) : bool { try { $config = ConfigFactory::getByType($type, 'dummy_field'); } catch (InvalidArgumentException $e) { return false; } return true; }
[ "public", "static", "function", "isValidFieldType", "(", "string", "$", "type", ")", ":", "bool", "{", "try", "{", "$", "config", "=", "ConfigFactory", "::", "getByType", "(", "$", "type", ",", "'dummy_field'", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if the field type is valid Migration field type needs a field handler configuration. @param string $type Field type @return bool True if valid, false otherwise
[ "Check", "if", "the", "field", "type", "is", "valid" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Utility.php#L237-L246
train
QoboLtd/cakephp-csv-migrations
src/Shell/Task/CsvRelationTask.php
CsvRelationTask.selection
private function selection(string $path) : array { $modules = $this->getModules($path); if (empty($modules)) { $this->abort('Aborting, system modules not found.'); } $result[] = $this->in('Please select first related module:', $modules); $result[] = $this->in('Please select second related module:', $modules); while ('y' === $this->in('Would you like to select more modules?', ['y', 'n'])) { $result[] = $this->in('Please select another related module:', $modules); } return $result; }
php
private function selection(string $path) : array { $modules = $this->getModules($path); if (empty($modules)) { $this->abort('Aborting, system modules not found.'); } $result[] = $this->in('Please select first related module:', $modules); $result[] = $this->in('Please select second related module:', $modules); while ('y' === $this->in('Would you like to select more modules?', ['y', 'n'])) { $result[] = $this->in('Please select another related module:', $modules); } return $result; }
[ "private", "function", "selection", "(", "string", "$", "path", ")", ":", "array", "{", "$", "modules", "=", "$", "this", "->", "getModules", "(", "$", "path", ")", ";", "if", "(", "empty", "(", "$", "modules", ")", ")", "{", "$", "this", "->", "abort", "(", "'Aborting, system modules not found.'", ")", ";", "}", "$", "result", "[", "]", "=", "$", "this", "->", "in", "(", "'Please select first related module:'", ",", "$", "modules", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "in", "(", "'Please select second related module:'", ",", "$", "modules", ")", ";", "while", "(", "'y'", "===", "$", "this", "->", "in", "(", "'Would you like to select more modules?'", ",", "[", "'y'", ",", "'n'", "]", ")", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "in", "(", "'Please select another related module:'", ",", "$", "modules", ")", ";", "}", "return", "$", "result", ";", "}" ]
Interactive shell for modules selection. @param string $path Modules root path @return string[]
[ "Interactive", "shell", "for", "modules", "selection", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/Task/CsvRelationTask.php#L82-L96
train
QoboLtd/cakephp-csv-migrations
src/Shell/Task/CsvRelationTask.php
CsvRelationTask.isModule
private function isModule(string $module) : bool { $config = (new ModuleConfig(ConfigType::MIGRATION(), $module, null, ['cacheSkip' => true]))->parse(); $config = json_encode($config); if (false === $config) { return false; } $config = json_decode($config, true); if (empty($config)) { return false; } $config = (new ModuleConfig(ConfigType::MODULE(), $module, null, ['cacheSkip' => true]))->parse(); if (! property_exists($config, 'table')) { return false; } if (! property_exists($config->table, 'type')) { return false; } if ('module' !== $config->table->type) { return false; } return true; }
php
private function isModule(string $module) : bool { $config = (new ModuleConfig(ConfigType::MIGRATION(), $module, null, ['cacheSkip' => true]))->parse(); $config = json_encode($config); if (false === $config) { return false; } $config = json_decode($config, true); if (empty($config)) { return false; } $config = (new ModuleConfig(ConfigType::MODULE(), $module, null, ['cacheSkip' => true]))->parse(); if (! property_exists($config, 'table')) { return false; } if (! property_exists($config->table, 'type')) { return false; } if ('module' !== $config->table->type) { return false; } return true; }
[ "private", "function", "isModule", "(", "string", "$", "module", ")", ":", "bool", "{", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "module", ",", "null", ",", "[", "'cacheSkip'", "=>", "true", "]", ")", ")", "->", "parse", "(", ")", ";", "$", "config", "=", "json_encode", "(", "$", "config", ")", ";", "if", "(", "false", "===", "$", "config", ")", "{", "return", "false", ";", "}", "$", "config", "=", "json_decode", "(", "$", "config", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "return", "false", ";", "}", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "module", ",", "null", ",", "[", "'cacheSkip'", "=>", "true", "]", ")", ")", "->", "parse", "(", ")", ";", "if", "(", "!", "property_exists", "(", "$", "config", ",", "'table'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "property_exists", "(", "$", "config", "->", "table", ",", "'type'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "'module'", "!==", "$", "config", "->", "table", "->", "type", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks module validity. @param string $module Module name @return bool
[ "Checks", "module", "validity", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/Task/CsvRelationTask.php#L124-L149
train
QoboLtd/cakephp-csv-migrations
src/Shell/Task/CsvRelationTask.php
CsvRelationTask.normalize
private function normalize(array $selection) : array { $result = []; foreach ($selection as $module) { $result[] = $this->_camelize(strtolower(trim($module))); } $result = array_unique($result); asort($result); return $result; }
php
private function normalize(array $selection) : array { $result = []; foreach ($selection as $module) { $result[] = $this->_camelize(strtolower(trim($module))); } $result = array_unique($result); asort($result); return $result; }
[ "private", "function", "normalize", "(", "array", "$", "selection", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "selection", "as", "$", "module", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "_camelize", "(", "strtolower", "(", "trim", "(", "$", "module", ")", ")", ")", ";", "}", "$", "result", "=", "array_unique", "(", "$", "result", ")", ";", "asort", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Interactive input normalization. @param string[] $selection User input @return string[]
[ "Interactive", "input", "normalization", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/Task/CsvRelationTask.php#L157-L168
train
QoboLtd/cakephp-csv-migrations
src/Shell/Task/CsvRelationTask.php
CsvRelationTask.validate
private function validate(string $name, string $path) : void { if (! ctype_alpha($name)) { $this->abort(sprintf('Invalid Relation name provided: %s', $name)); } if (in_array($name, Utility::findDirs($path))) { $this->abort(sprintf('Relation %s already exists', $name)); } }
php
private function validate(string $name, string $path) : void { if (! ctype_alpha($name)) { $this->abort(sprintf('Invalid Relation name provided: %s', $name)); } if (in_array($name, Utility::findDirs($path))) { $this->abort(sprintf('Relation %s already exists', $name)); } }
[ "private", "function", "validate", "(", "string", "$", "name", ",", "string", "$", "path", ")", ":", "void", "{", "if", "(", "!", "ctype_alpha", "(", "$", "name", ")", ")", "{", "$", "this", "->", "abort", "(", "sprintf", "(", "'Invalid Relation name provided: %s'", ",", "$", "name", ")", ")", ";", "}", "if", "(", "in_array", "(", "$", "name", ",", "Utility", "::", "findDirs", "(", "$", "path", ")", ")", ")", "{", "$", "this", "->", "abort", "(", "sprintf", "(", "'Relation %s already exists'", ",", "$", "name", ")", ")", ";", "}", "}" ]
Validates relation name parameter. @param string $name Module name @param string $path Modules root path @return void
[ "Validates", "relation", "name", "parameter", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/Task/CsvRelationTask.php#L177-L186
train
QoboLtd/cakephp-csv-migrations
src/Shell/Task/CsvRelationTask.php
CsvRelationTask.bakeModuleConfig
private function bakeModuleConfig(array $selection, string $path) : bool { reset($selection); $this->BakeTemplate->set(['display_field' => $this->_modelKey(current($selection))]); return $this->createFile( $path . implode('', $selection) . DS . 'config' . DS . 'config.dist.json', $this->BakeTemplate->generate('CsvMigrations.Relation/config/config') ); }
php
private function bakeModuleConfig(array $selection, string $path) : bool { reset($selection); $this->BakeTemplate->set(['display_field' => $this->_modelKey(current($selection))]); return $this->createFile( $path . implode('', $selection) . DS . 'config' . DS . 'config.dist.json', $this->BakeTemplate->generate('CsvMigrations.Relation/config/config') ); }
[ "private", "function", "bakeModuleConfig", "(", "array", "$", "selection", ",", "string", "$", "path", ")", ":", "bool", "{", "reset", "(", "$", "selection", ")", ";", "$", "this", "->", "BakeTemplate", "->", "set", "(", "[", "'display_field'", "=>", "$", "this", "->", "_modelKey", "(", "current", "(", "$", "selection", ")", ")", "]", ")", ";", "return", "$", "this", "->", "createFile", "(", "$", "path", ".", "implode", "(", "''", ",", "$", "selection", ")", ".", "DS", ".", "'config'", ".", "DS", ".", "'config.dist.json'", ",", "$", "this", "->", "BakeTemplate", "->", "generate", "(", "'CsvMigrations.Relation/config/config'", ")", ")", ";", "}" ]
Bake Relation configuration files. @param string[] $selection Modules selection @param string $path Modules root path @return bool
[ "Bake", "Relation", "configuration", "files", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Shell/Task/CsvRelationTask.php#L195-L204
train
QoboLtd/cakephp-csv-migrations
src/Event/Model/ModelAfterSaveListener.php
ModelAfterSaveListener.getRemindersToModules
protected function getRemindersToModules(RepositoryInterface $table) : array { $config = (new ModuleConfig(ConfigType::MODULE(), $table->getRegistryAlias()))->parseToArray(); if (empty($config['table']['allow_reminders'])) { return []; } return $config['table']['allow_reminders']; }
php
protected function getRemindersToModules(RepositoryInterface $table) : array { $config = (new ModuleConfig(ConfigType::MODULE(), $table->getRegistryAlias()))->parseToArray(); if (empty($config['table']['allow_reminders'])) { return []; } return $config['table']['allow_reminders']; }
[ "protected", "function", "getRemindersToModules", "(", "RepositoryInterface", "$", "table", ")", ":", "array", "{", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "table", "->", "getRegistryAlias", "(", ")", ")", ")", "->", "parseToArray", "(", ")", ";", "if", "(", "empty", "(", "$", "config", "[", "'table'", "]", "[", "'allow_reminders'", "]", ")", ")", "{", "return", "[", "]", ";", "}", "return", "$", "config", "[", "'table'", "]", "[", "'allow_reminders'", "]", ";", "}" ]
Get a list of reminder modules Check if the given table has reminders configured, and if so, return the list of modules to which reminders should be sent (Users, Contacts, etc). @param \Cake\Datasource\RepositoryInterface $table Table to check @return string[] List of modules
[ "Get", "a", "list", "of", "reminder", "modules" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Event/Model/ModelAfterSaveListener.php#L183-L191
train
QoboLtd/cakephp-csv-migrations
src/Event/Model/ModelAfterSaveListener.php
ModelAfterSaveListener.getReminderField
protected function getReminderField(RepositoryInterface $table) : string { $config = (new ModuleConfig(ConfigType::MIGRATION(), $table->getRegistryAlias()))->parse(); $fields = array_filter((array)$config, function ($field) { if ('reminder' === $field->type) { return $field; } }); if (empty($fields)) { return ''; } // FIXME: What should happen when there is more than 1 reminder field on the table? reset($fields); return current($fields)->name; }
php
protected function getReminderField(RepositoryInterface $table) : string { $config = (new ModuleConfig(ConfigType::MIGRATION(), $table->getRegistryAlias()))->parse(); $fields = array_filter((array)$config, function ($field) { if ('reminder' === $field->type) { return $field; } }); if (empty($fields)) { return ''; } // FIXME: What should happen when there is more than 1 reminder field on the table? reset($fields); return current($fields)->name; }
[ "protected", "function", "getReminderField", "(", "RepositoryInterface", "$", "table", ")", ":", "string", "{", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "table", "->", "getRegistryAlias", "(", ")", ")", ")", "->", "parse", "(", ")", ";", "$", "fields", "=", "array_filter", "(", "(", "array", ")", "$", "config", ",", "function", "(", "$", "field", ")", "{", "if", "(", "'reminder'", "===", "$", "field", "->", "type", ")", "{", "return", "$", "field", ";", "}", "}", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "''", ";", "}", "// FIXME: What should happen when there is more than 1 reminder field on the table?", "reset", "(", "$", "fields", ")", ";", "return", "current", "(", "$", "fields", ")", "->", "name", ";", "}" ]
Get the fist reminder field of the given table NOTE: It is not very common to have more than one reminder field per table, but it is not impossible. We need to figure out what should happen. Possible scenarios: * Forbid more than one field with validation. * Send reminder only to the first/non-empty. * Send separate reminder for each. * Have more flexible configuration rules. @param \Cake\Datasource\RepositoryInterface $table Table to use @return string First reminder field name
[ "Get", "the", "fist", "reminder", "field", "of", "the", "given", "table" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Event/Model/ModelAfterSaveListener.php#L209-L227
train
QoboLtd/cakephp-csv-migrations
src/Event/Model/ModelAfterSaveListener.php
ModelAfterSaveListener.getAttendeesFields
protected function getAttendeesFields(Table $table, array $modules) : array { $associations = []; foreach ($table->associations() as $association) { if (in_array(Inflector::humanize($association->getTarget()->getTable()), $modules)) { $associations[] = $association; } } if (empty($associations)) { return []; } $result = []; foreach ($associations as $association) { $foreignKey = $association->getForeignKey(); if (!is_string($foreignKey)) { throw new UnsupportedForeignKeyException(); } if (in_array($foreignKey, $this->skipAttendeesIn)) { continue; } $result[] = $foreignKey; } return $result; }
php
protected function getAttendeesFields(Table $table, array $modules) : array { $associations = []; foreach ($table->associations() as $association) { if (in_array(Inflector::humanize($association->getTarget()->getTable()), $modules)) { $associations[] = $association; } } if (empty($associations)) { return []; } $result = []; foreach ($associations as $association) { $foreignKey = $association->getForeignKey(); if (!is_string($foreignKey)) { throw new UnsupportedForeignKeyException(); } if (in_array($foreignKey, $this->skipAttendeesIn)) { continue; } $result[] = $foreignKey; } return $result; }
[ "protected", "function", "getAttendeesFields", "(", "Table", "$", "table", ",", "array", "$", "modules", ")", ":", "array", "{", "$", "associations", "=", "[", "]", ";", "foreach", "(", "$", "table", "->", "associations", "(", ")", "as", "$", "association", ")", "{", "if", "(", "in_array", "(", "Inflector", "::", "humanize", "(", "$", "association", "->", "getTarget", "(", ")", "->", "getTable", "(", ")", ")", ",", "$", "modules", ")", ")", "{", "$", "associations", "[", "]", "=", "$", "association", ";", "}", "}", "if", "(", "empty", "(", "$", "associations", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "associations", "as", "$", "association", ")", "{", "$", "foreignKey", "=", "$", "association", "->", "getForeignKey", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "foreignKey", ")", ")", "{", "throw", "new", "UnsupportedForeignKeyException", "(", ")", ";", "}", "if", "(", "in_array", "(", "$", "foreignKey", ",", "$", "this", "->", "skipAttendeesIn", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "foreignKey", ";", "}", "return", "$", "result", ";", "}" ]
Retrieve attendees fields from current Table's associations. @param \Cake\ORM\Table $table Table instance @param string[] $modules Reminder to modules @return string[]
[ "Retrieve", "attendees", "fields", "from", "current", "Table", "s", "associations", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Event/Model/ModelAfterSaveListener.php#L236-L262
train
QoboLtd/cakephp-csv-migrations
src/Event/Model/ModelAfterSaveListener.php
ModelAfterSaveListener.isRequiredModified
protected function isRequiredModified(EntityInterface $entity, array $requiredFields) : bool { foreach ($requiredFields as $field) { if ($entity->isDirty($field)) { return true; } } return false; }
php
protected function isRequiredModified(EntityInterface $entity, array $requiredFields) : bool { foreach ($requiredFields as $field) { if ($entity->isDirty($field)) { return true; } } return false; }
[ "protected", "function", "isRequiredModified", "(", "EntityInterface", "$", "entity", ",", "array", "$", "requiredFields", ")", ":", "bool", "{", "foreach", "(", "$", "requiredFields", "as", "$", "field", ")", "{", "if", "(", "$", "entity", "->", "isDirty", "(", "$", "field", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check that required entity fields are modified Entities are modified all the time and we don't always want to send a notification about these changes. Instead, here we check that particular fields were modified (usually the reminder datetime field or the attendees of the event). @param \Cake\Datasource\EntityInterface $entity Entity instance @param string[] $requiredFields Required fields list @return bool
[ "Check", "that", "required", "entity", "fields", "are", "modified" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Event/Model/ModelAfterSaveListener.php#L276-L285
train
QoboLtd/cakephp-csv-migrations
src/Event/Model/ModelAfterSaveListener.php
ModelAfterSaveListener.getEventOptions
protected function getEventOptions(CsvTable $table, EntityInterface $entity, string $startField) : array { // Event start and end times $eventTimes = $this->getEventTime($entity, $startField); $mailer = new IcEmail($table, $entity); $result = [ 'id' => $entity->get('id'), 'sequence' => $entity->isNew() ? 0 : time(), 'summary' => $mailer->getEventSubject(), 'description' => $mailer->getEventContent(), 'location' => (string)$entity->get('location'), 'startTime' => $eventTimes['start'], 'endTime' => $eventTimes['end'], ]; return $result; }
php
protected function getEventOptions(CsvTable $table, EntityInterface $entity, string $startField) : array { // Event start and end times $eventTimes = $this->getEventTime($entity, $startField); $mailer = new IcEmail($table, $entity); $result = [ 'id' => $entity->get('id'), 'sequence' => $entity->isNew() ? 0 : time(), 'summary' => $mailer->getEventSubject(), 'description' => $mailer->getEventContent(), 'location' => (string)$entity->get('location'), 'startTime' => $eventTimes['start'], 'endTime' => $eventTimes['end'], ]; return $result; }
[ "protected", "function", "getEventOptions", "(", "CsvTable", "$", "table", ",", "EntityInterface", "$", "entity", ",", "string", "$", "startField", ")", ":", "array", "{", "// Event start and end times", "$", "eventTimes", "=", "$", "this", "->", "getEventTime", "(", "$", "entity", ",", "$", "startField", ")", ";", "$", "mailer", "=", "new", "IcEmail", "(", "$", "table", ",", "$", "entity", ")", ";", "$", "result", "=", "[", "'id'", "=>", "$", "entity", "->", "get", "(", "'id'", ")", ",", "'sequence'", "=>", "$", "entity", "->", "isNew", "(", ")", "?", "0", ":", "time", "(", ")", ",", "'summary'", "=>", "$", "mailer", "->", "getEventSubject", "(", ")", ",", "'description'", "=>", "$", "mailer", "->", "getEventContent", "(", ")", ",", "'location'", "=>", "(", "string", ")", "$", "entity", "->", "get", "(", "'location'", ")", ",", "'startTime'", "=>", "$", "eventTimes", "[", "'start'", "]", ",", "'endTime'", "=>", "$", "eventTimes", "[", "'end'", "]", ",", "]", ";", "return", "$", "result", ";", "}" ]
Get options for the new event @param \CsvMigrations\Table $table Table instance @param \Cake\Datasource\EntityInterface $entity Entity instance @param string $startField Entity field to use for event start time @return mixed[]
[ "Get", "options", "for", "the", "new", "event" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Event/Model/ModelAfterSaveListener.php#L380-L398
train
QoboLtd/cakephp-csv-migrations
src/Aggregator/AbstractAggregator.php
AbstractAggregator.validate
public function validate() : bool { $table = $this->getConfig()->getTable(); foreach ([$this->config->getField(), $this->config->getDisplayField()] as $field) { if ($table->getSchema()->hasColumn($field)) { continue; } $this->errors[] = sprintf('Unknown column "%s" for table "%s"', $field, $table->getAlias()); } return empty($this->errors); }
php
public function validate() : bool { $table = $this->getConfig()->getTable(); foreach ([$this->config->getField(), $this->config->getDisplayField()] as $field) { if ($table->getSchema()->hasColumn($field)) { continue; } $this->errors[] = sprintf('Unknown column "%s" for table "%s"', $field, $table->getAlias()); } return empty($this->errors); }
[ "public", "function", "validate", "(", ")", ":", "bool", "{", "$", "table", "=", "$", "this", "->", "getConfig", "(", ")", "->", "getTable", "(", ")", ";", "foreach", "(", "[", "$", "this", "->", "config", "->", "getField", "(", ")", ",", "$", "this", "->", "config", "->", "getDisplayField", "(", ")", "]", "as", "$", "field", ")", "{", "if", "(", "$", "table", "->", "getSchema", "(", ")", "->", "hasColumn", "(", "$", "field", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'Unknown column \"%s\" for table \"%s\"'", ",", "$", "field", ",", "$", "table", "->", "getAlias", "(", ")", ")", ";", "}", "return", "empty", "(", "$", "this", "->", "errors", ")", ";", "}" ]
Validator method. Checks for column existance. @return bool
[ "Validator", "method", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Aggregator/AbstractAggregator.php#L46-L58
train
QoboLtd/cakephp-csv-migrations
src/Utility/DTZone.php
DTZone.toDateTime
public static function toDateTime($value, DateTimeZone $dtz) : DateTime { // TODO : Figure out where to move. Can vary for different source objects $format = 'Y-m-d H:i:s'; if (is_string($value)) { $val = strtotime($value); if (false === $val) { throw new InvalidArgumentException(sprintf('Unsupported datetime string provided: %s', $value)); } return new DateTime(date($format, $val), $dtz); } if ($value instanceof Time) { $value = $value->format($format); return new DateTime($value, $dtz); } if ($value instanceof DateTime) { return $value; } throw new InvalidArgumentException("Type [" . gettype($value) . "] is not supported for date/time"); }
php
public static function toDateTime($value, DateTimeZone $dtz) : DateTime { // TODO : Figure out where to move. Can vary for different source objects $format = 'Y-m-d H:i:s'; if (is_string($value)) { $val = strtotime($value); if (false === $val) { throw new InvalidArgumentException(sprintf('Unsupported datetime string provided: %s', $value)); } return new DateTime(date($format, $val), $dtz); } if ($value instanceof Time) { $value = $value->format($format); return new DateTime($value, $dtz); } if ($value instanceof DateTime) { return $value; } throw new InvalidArgumentException("Type [" . gettype($value) . "] is not supported for date/time"); }
[ "public", "static", "function", "toDateTime", "(", "$", "value", ",", "DateTimeZone", "$", "dtz", ")", ":", "DateTime", "{", "// TODO : Figure out where to move. Can vary for different source objects", "$", "format", "=", "'Y-m-d H:i:s'", ";", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "val", "=", "strtotime", "(", "$", "value", ")", ";", "if", "(", "false", "===", "$", "val", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Unsupported datetime string provided: %s'", ",", "$", "value", ")", ")", ";", "}", "return", "new", "DateTime", "(", "date", "(", "$", "format", ",", "$", "val", ")", ",", "$", "dtz", ")", ";", "}", "if", "(", "$", "value", "instanceof", "Time", ")", "{", "$", "value", "=", "$", "value", "->", "format", "(", "$", "format", ")", ";", "return", "new", "DateTime", "(", "$", "value", ",", "$", "dtz", ")", ";", "}", "if", "(", "$", "value", "instanceof", "DateTime", ")", "{", "return", "$", "value", ";", "}", "throw", "new", "InvalidArgumentException", "(", "\"Type [\"", ".", "gettype", "(", "$", "value", ")", ".", "\"] is not supported for date/time\"", ")", ";", "}" ]
Convert a given value to DateTime instance @throws \InvalidArgumentException when cannot convert to \DateTime @param mixed $value Value to convert (string, Time, DateTime, etc) @param \DateTimeZone $dtz DateTimeZone instance @return \DateTime
[ "Convert", "a", "given", "value", "to", "DateTime", "instance" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/DTZone.php#L51-L76
train
QoboLtd/cakephp-csv-migrations
src/Utility/DTZone.php
DTZone.offsetToUtc
public static function offsetToUtc(DateTime $value) : DateTime { $result = $value; $dtz = $value->getTimezone(); if ($dtz->getName() === 'UTC') { return $result; } $epoch = time(); $transitions = $dtz->getTransitions($epoch, $epoch); $offset = $transitions[0]['offset']; $result = $result->modify("-$offset seconds"); return $result; }
php
public static function offsetToUtc(DateTime $value) : DateTime { $result = $value; $dtz = $value->getTimezone(); if ($dtz->getName() === 'UTC') { return $result; } $epoch = time(); $transitions = $dtz->getTransitions($epoch, $epoch); $offset = $transitions[0]['offset']; $result = $result->modify("-$offset seconds"); return $result; }
[ "public", "static", "function", "offsetToUtc", "(", "DateTime", "$", "value", ")", ":", "DateTime", "{", "$", "result", "=", "$", "value", ";", "$", "dtz", "=", "$", "value", "->", "getTimezone", "(", ")", ";", "if", "(", "$", "dtz", "->", "getName", "(", ")", "===", "'UTC'", ")", "{", "return", "$", "result", ";", "}", "$", "epoch", "=", "time", "(", ")", ";", "$", "transitions", "=", "$", "dtz", "->", "getTransitions", "(", "$", "epoch", ",", "$", "epoch", ")", ";", "$", "offset", "=", "$", "transitions", "[", "0", "]", "[", "'offset'", "]", ";", "$", "result", "=", "$", "result", "->", "modify", "(", "\"-$offset seconds\"", ")", ";", "return", "$", "result", ";", "}" ]
Offset DateTime value to UTC NOTE: This is a temporary work around until we fix our handling of the application timezones. Database values should always be stored in UTC no matter what. Otherwise, you will be riding a bike which is on fire, while you are on fire, and everything around you is on fire. See Redmine ticket #4336 for details. @param \DateTime $value DateTime value to offset @return \DateTime
[ "Offset", "DateTime", "value", "to", "UTC" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/DTZone.php#L90-L106
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/CsvField.php
CsvField._extractType
protected function _extractType(string $type) : string { if (preg_match(static::PATTERN_TYPE, $type, $matches)) { if (! empty($matches[1])) { return $matches[1]; } } return $type; }
php
protected function _extractType(string $type) : string { if (preg_match(static::PATTERN_TYPE, $type, $matches)) { if (! empty($matches[1])) { return $matches[1]; } } return $type; }
[ "protected", "function", "_extractType", "(", "string", "$", "type", ")", ":", "string", "{", "if", "(", "preg_match", "(", "static", "::", "PATTERN_TYPE", ",", "$", "type", ",", "$", "matches", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "$", "matches", "[", "1", "]", ";", "}", "}", "return", "$", "type", ";", "}" ]
Extract field type from type value Field type can be either simple or combined with limit. For example: * Simple: uuid, string, date. * Combined: string(100), list(Foo). In case of a simple type, it is returned as is. For the combined typed, the limit is stripped out and a simple type only is returned. @param string $type field type @return string field type
[ "Extract", "field", "type", "from", "type", "value" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/CsvField.php#L192-L201
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/CsvField.php
CsvField._extractLimit
protected function _extractLimit(string $type) { if (preg_match(static::PATTERN_TYPE, $type, $matches)) { if (! empty($matches[2])) { return $matches[2]; } } return static::DEFAULT_FIELD_LIMIT; }
php
protected function _extractLimit(string $type) { if (preg_match(static::PATTERN_TYPE, $type, $matches)) { if (! empty($matches[2])) { return $matches[2]; } } return static::DEFAULT_FIELD_LIMIT; }
[ "protected", "function", "_extractLimit", "(", "string", "$", "type", ")", "{", "if", "(", "preg_match", "(", "static", "::", "PATTERN_TYPE", ",", "$", "type", ",", "$", "matches", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "return", "$", "matches", "[", "2", "]", ";", "}", "}", "return", "static", "::", "DEFAULT_FIELD_LIMIT", ";", "}" ]
Extract field limit from type value Field type can be either simple or combined with limit. For example: * Simple: uuid, string, date. * Combined: string(100), list(Foo). In case of a simple type, the default limit is returned. For the combined typed, the type is stripped out and a limit only is returned. @param string $type field type @return mixed field limit
[ "Extract", "field", "limit", "from", "type", "value" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/CsvField.php#L219-L228
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/CsvField.php
CsvField.setName
public function setName(string $name) : void { if (empty($name)) { throw new InvalidArgumentException('Empty field name is not allowed'); } $this->_name = $name; }
php
public function setName(string $name) : void { if (empty($name)) { throw new InvalidArgumentException('Empty field name is not allowed'); } $this->_name = $name; }
[ "public", "function", "setName", "(", "string", "$", "name", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Empty field name is not allowed'", ")", ";", "}", "$", "this", "->", "_name", "=", "$", "name", ";", "}" ]
Set field name @throws \InvalidArgumentException when name is empty @param string $name field name @return void
[ "Set", "field", "name" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/CsvField.php#L237-L244
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/CsvField.php
CsvField.setType
public function setType(string $type) : void { if (empty($type)) { throw new InvalidArgumentException('Empty field type is not allowed: ' . $this->getName()); } $this->_type = $this->_extractType($type); }
php
public function setType(string $type) : void { if (empty($type)) { throw new InvalidArgumentException('Empty field type is not allowed: ' . $this->getName()); } $this->_type = $this->_extractType($type); }
[ "public", "function", "setType", "(", "string", "$", "type", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "type", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Empty field type is not allowed: '", ".", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "_type", "=", "$", "this", "->", "_extractType", "(", "$", "type", ")", ";", "}" ]
Set field type @throws \InvalidArgumentException when type is empty @param string $type field type @return void
[ "Set", "field", "type" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/CsvField.php#L263-L270
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/CsvField.php
CsvField.setLimit
public function setLimit($limit) : void { if ($limit === null) { $this->_limit = $limit; return; } if (is_int($limit) || is_numeric($limit)) { $limit = abs(intval($limit)); $this->_limit = $limit === 0 ? null : $limit; return; } if (empty($limit)) { throw new InvalidArgumentException('Empty field type is not allowed: ' . $this->getName()); } $this->_limit = $this->_extractLimit($limit); }
php
public function setLimit($limit) : void { if ($limit === null) { $this->_limit = $limit; return; } if (is_int($limit) || is_numeric($limit)) { $limit = abs(intval($limit)); $this->_limit = $limit === 0 ? null : $limit; return; } if (empty($limit)) { throw new InvalidArgumentException('Empty field type is not allowed: ' . $this->getName()); } $this->_limit = $this->_extractLimit($limit); }
[ "public", "function", "setLimit", "(", "$", "limit", ")", ":", "void", "{", "if", "(", "$", "limit", "===", "null", ")", "{", "$", "this", "->", "_limit", "=", "$", "limit", ";", "return", ";", "}", "if", "(", "is_int", "(", "$", "limit", ")", "||", "is_numeric", "(", "$", "limit", ")", ")", "{", "$", "limit", "=", "abs", "(", "intval", "(", "$", "limit", ")", ")", ";", "$", "this", "->", "_limit", "=", "$", "limit", "===", "0", "?", "null", ":", "$", "limit", ";", "return", ";", "}", "if", "(", "empty", "(", "$", "limit", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Empty field type is not allowed: '", ".", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "_limit", "=", "$", "this", "->", "_extractLimit", "(", "$", "limit", ")", ";", "}" ]
Set field limit Type is set as is if it is null or integer. If it passses is_numeric() then it's cast to integer. In all other cases, it is assumed that the limit is a string defining field type, and limit needs to be extracted. @param int|string|null $limit field limit @return void
[ "Set", "field", "limit" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/CsvField.php#L294-L314
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/Config/Config.php
Config.getProvider
public function getProvider(string $name) : string { $providers = $this->getProviders(); if (!in_array($name, array_keys($providers))) { throw new InvalidArgumentException("Provider for [$name] is not configured"); } return $providers[$name]; }
php
public function getProvider(string $name) : string { $providers = $this->getProviders(); if (!in_array($name, array_keys($providers))) { throw new InvalidArgumentException("Provider for [$name] is not configured"); } return $providers[$name]; }
[ "public", "function", "getProvider", "(", "string", "$", "name", ")", ":", "string", "{", "$", "providers", "=", "$", "this", "->", "getProviders", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "name", ",", "array_keys", "(", "$", "providers", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Provider for [$name] is not configured\"", ")", ";", "}", "return", "$", "providers", "[", "$", "name", "]", ";", "}" ]
Get provider by name @throws \InvalidArgumentException for invalid provider @param string $name Name of the provider to get @return string
[ "Get", "provider", "by", "name" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/Config/Config.php#L227-L235
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php
AbstractSearchOptions.getSearchOperators
protected function getSearchOperators($data = null, array $options = []) : array { $result = $this->config->getProvider('searchOperators'); $result = new $result($this->config); $result = $result->provide($data, $options); return $result; }
php
protected function getSearchOperators($data = null, array $options = []) : array { $result = $this->config->getProvider('searchOperators'); $result = new $result($this->config); $result = $result->provide($data, $options); return $result; }
[ "protected", "function", "getSearchOperators", "(", "$", "data", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "result", "=", "$", "this", "->", "config", "->", "getProvider", "(", "'searchOperators'", ")", ";", "$", "result", "=", "new", "$", "result", "(", "$", "this", "->", "config", ")", ";", "$", "result", "=", "$", "result", "->", "provide", "(", "$", "data", ",", "$", "options", ")", ";", "return", "$", "result", ";", "}" ]
Helper method to get search operators @param mixed $data Data to use for provision @param mixed[] $options Options to use for provision @return mixed[]
[ "Helper", "method", "to", "get", "search", "operators" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php#L30-L37
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php
AbstractSearchOptions.getDefaultOptions
protected function getDefaultOptions($data = null, array $options = []) : array { $result = [ 'type' => $options['fieldDefinitions']->getType(), 'label' => $options['label'], 'operators' => $this->getSearchOperators($data, $options), 'input' => [ 'content' => '', ], ]; return $result; }
php
protected function getDefaultOptions($data = null, array $options = []) : array { $result = [ 'type' => $options['fieldDefinitions']->getType(), 'label' => $options['label'], 'operators' => $this->getSearchOperators($data, $options), 'input' => [ 'content' => '', ], ]; return $result; }
[ "protected", "function", "getDefaultOptions", "(", "$", "data", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "result", "=", "[", "'type'", "=>", "$", "options", "[", "'fieldDefinitions'", "]", "->", "getType", "(", ")", ",", "'label'", "=>", "$", "options", "[", "'label'", "]", ",", "'operators'", "=>", "$", "this", "->", "getSearchOperators", "(", "$", "data", ",", "$", "options", ")", ",", "'input'", "=>", "[", "'content'", "=>", "''", ",", "]", ",", "]", ";", "return", "$", "result", ";", "}" ]
Get default search options @param mixed $data Data to use for provision @param mixed[] $options Options to use for provision @return mixed[]
[ "Get", "default", "search", "options" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php#L46-L58
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php
AbstractSearchOptions.getBasicTemplate
protected function getBasicTemplate(string $type) : string { $view = $this->config->getView(); $result = $view->Form->control('{{name}}', [ 'value' => '{{value}}', 'type' => $type, 'label' => false ]); return $result; }
php
protected function getBasicTemplate(string $type) : string { $view = $this->config->getView(); $result = $view->Form->control('{{name}}', [ 'value' => '{{value}}', 'type' => $type, 'label' => false ]); return $result; }
[ "protected", "function", "getBasicTemplate", "(", "string", "$", "type", ")", ":", "string", "{", "$", "view", "=", "$", "this", "->", "config", "->", "getView", "(", ")", ";", "$", "result", "=", "$", "view", "->", "Form", "->", "control", "(", "'{{name}}'", ",", "[", "'value'", "=>", "'{{value}}'", ",", "'type'", "=>", "$", "type", ",", "'label'", "=>", "false", "]", ")", ";", "return", "$", "result", ";", "}" ]
Get basic template for a given type @param string $type Form input type @return string
[ "Get", "basic", "template", "for", "a", "given", "type" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/Provider/SearchOptions/AbstractSearchOptions.php#L66-L76
train
QoboLtd/cakephp-csv-migrations
src/Model/Table/DblistsTable.php
DblistsTable.getOptions
public function getOptions(string $listName) : array { try { $entity = $this->find('all') ->enableHydration(true) ->where(['name' => $listName]) ->firstOrFail(); } catch (RecordNotFoundException $e) { return []; } $treeOptions = [ 'keyPath' => 'value', 'valuePath' => 'name', 'spacer' => ' - ' ]; Assert::isInstanceOf($entity, EntityInterface::class); return $this->DblistItems->find('treeList', $treeOptions) ->where(['dblist_id' => $entity->get('id')]) ->toArray(); }
php
public function getOptions(string $listName) : array { try { $entity = $this->find('all') ->enableHydration(true) ->where(['name' => $listName]) ->firstOrFail(); } catch (RecordNotFoundException $e) { return []; } $treeOptions = [ 'keyPath' => 'value', 'valuePath' => 'name', 'spacer' => ' - ' ]; Assert::isInstanceOf($entity, EntityInterface::class); return $this->DblistItems->find('treeList', $treeOptions) ->where(['dblist_id' => $entity->get('id')]) ->toArray(); }
[ "public", "function", "getOptions", "(", "string", "$", "listName", ")", ":", "array", "{", "try", "{", "$", "entity", "=", "$", "this", "->", "find", "(", "'all'", ")", "->", "enableHydration", "(", "true", ")", "->", "where", "(", "[", "'name'", "=>", "$", "listName", "]", ")", "->", "firstOrFail", "(", ")", ";", "}", "catch", "(", "RecordNotFoundException", "$", "e", ")", "{", "return", "[", "]", ";", "}", "$", "treeOptions", "=", "[", "'keyPath'", "=>", "'value'", ",", "'valuePath'", "=>", "'name'", ",", "'spacer'", "=>", "' - '", "]", ";", "Assert", "::", "isInstanceOf", "(", "$", "entity", ",", "EntityInterface", "::", "class", ")", ";", "return", "$", "this", "->", "DblistItems", "->", "find", "(", "'treeList'", ",", "$", "treeOptions", ")", "->", "where", "(", "[", "'dblist_id'", "=>", "$", "entity", "->", "get", "(", "'id'", ")", "]", ")", "->", "toArray", "(", ")", ";", "}" ]
Reusable query options. It can be used for retreving the options of the select field(list). Options: - name: List name (required) @param string $listName List name to retrieve options from @return mixed[] Options for the select option field
[ "Reusable", "query", "options", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Model/Table/DblistsTable.php#L115-L137
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Check/ConfigCheck.php
ConfigCheck.checkParent
protected function checkParent(string $module, array $options = [], array $config = []) : void { if (empty($config['parent'])) { return; } if (!empty($config['parent']['redirect'])) { //if redirect = parent, we force the user to mention the relation and module if (in_array($config['parent']['redirect'], ['parent'])) { if (empty($config['parent']['module'])) { $this->errors[] = $module . " config [parent] requires 'module' value when redirect = parent."; } if (empty($config['parent']['relation'])) { $this->errors[] = $module . " config [parent] requires 'relation' when redirect = parent."; } } } }
php
protected function checkParent(string $module, array $options = [], array $config = []) : void { if (empty($config['parent'])) { return; } if (!empty($config['parent']['redirect'])) { //if redirect = parent, we force the user to mention the relation and module if (in_array($config['parent']['redirect'], ['parent'])) { if (empty($config['parent']['module'])) { $this->errors[] = $module . " config [parent] requires 'module' value when redirect = parent."; } if (empty($config['parent']['relation'])) { $this->errors[] = $module . " config [parent] requires 'relation' when redirect = parent."; } } } }
[ "protected", "function", "checkParent", "(", "string", "$", "module", ",", "array", "$", "options", "=", "[", "]", ",", "array", "$", "config", "=", "[", "]", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "config", "[", "'parent'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'parent'", "]", "[", "'redirect'", "]", ")", ")", "{", "//if redirect = parent, we force the user to mention the relation and module", "if", "(", "in_array", "(", "$", "config", "[", "'parent'", "]", "[", "'redirect'", "]", ",", "[", "'parent'", "]", ")", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'parent'", "]", "[", "'module'", "]", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "module", ".", "\" config [parent] requires 'module' value when redirect = parent.\"", ";", "}", "if", "(", "empty", "(", "$", "config", "[", "'parent'", "]", "[", "'relation'", "]", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "module", ".", "\" config [parent] requires 'relation' when redirect = parent.\"", ";", "}", "}", "}", "}" ]
Check parent section of the configuration @param string $module Module name @param mixed[] $options Check options @param mixed[] $config Configuration @return void
[ "Check", "parent", "section", "of", "the", "configuration" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Check/ConfigCheck.php#L152-L170
train
QoboLtd/cakephp-csv-migrations
src/Aggregator/AggregateResult.php
AggregateResult.get
public static function get(AggregatorInterface $aggregator) { $config = $aggregator->getConfig(); $query = $config->getTable()->find('all'); $query = $aggregator->applyConditions($query); $query = static::join($aggregator, $query); $entity = $query->first(); if (null === $entity) { return ''; } return $aggregator->getResult($entity); }
php
public static function get(AggregatorInterface $aggregator) { $config = $aggregator->getConfig(); $query = $config->getTable()->find('all'); $query = $aggregator->applyConditions($query); $query = static::join($aggregator, $query); $entity = $query->first(); if (null === $entity) { return ''; } return $aggregator->getResult($entity); }
[ "public", "static", "function", "get", "(", "AggregatorInterface", "$", "aggregator", ")", "{", "$", "config", "=", "$", "aggregator", "->", "getConfig", "(", ")", ";", "$", "query", "=", "$", "config", "->", "getTable", "(", ")", "->", "find", "(", "'all'", ")", ";", "$", "query", "=", "$", "aggregator", "->", "applyConditions", "(", "$", "query", ")", ";", "$", "query", "=", "static", "::", "join", "(", "$", "aggregator", ",", "$", "query", ")", ";", "$", "entity", "=", "$", "query", "->", "first", "(", ")", ";", "if", "(", "null", "===", "$", "entity", ")", "{", "return", "''", ";", "}", "return", "$", "aggregator", "->", "getResult", "(", "$", "entity", ")", ";", "}" ]
Aggregator execution method. @param \CsvMigrations\Aggregator\AggregatorInterface $aggregator Aggregator instance @return mixed
[ "Aggregator", "execution", "method", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Aggregator/AggregateResult.php#L19-L33
train
QoboLtd/cakephp-csv-migrations
src/Aggregator/AggregateResult.php
AggregateResult.join
private static function join(AggregatorInterface $aggregator, QueryInterface $query) : QueryInterface { $config = $aggregator->getConfig(); if (! $config->joinMode()) { return $query; } Assert::isInstanceOf($query, Query::class); $association = static::findAssociation($aggregator); // limit to record's associated data $query->innerJoinWith($association->getName(), function ($q) use ($association, $config) { $table = $config->getJoinTable(); $primaryKey = $table->getPrimaryKey(); if (! is_string($primaryKey)) { Log::error('Failed to apply inner join for aggregated field value: primary key must be a string', [ 'source_table' => $config->getTable()->getAlias(), 'target_table' => $table->getAlias(), 'primar_key' => $table->getPrimaryKey(), 'association' => $association->getName() ]); return $q; } $entity = $config->getEntity(); return $q->where([ $association->getTarget()->aliasField($primaryKey) => $entity->get($primaryKey) ]); }); return $query; }
php
private static function join(AggregatorInterface $aggregator, QueryInterface $query) : QueryInterface { $config = $aggregator->getConfig(); if (! $config->joinMode()) { return $query; } Assert::isInstanceOf($query, Query::class); $association = static::findAssociation($aggregator); // limit to record's associated data $query->innerJoinWith($association->getName(), function ($q) use ($association, $config) { $table = $config->getJoinTable(); $primaryKey = $table->getPrimaryKey(); if (! is_string($primaryKey)) { Log::error('Failed to apply inner join for aggregated field value: primary key must be a string', [ 'source_table' => $config->getTable()->getAlias(), 'target_table' => $table->getAlias(), 'primar_key' => $table->getPrimaryKey(), 'association' => $association->getName() ]); return $q; } $entity = $config->getEntity(); return $q->where([ $association->getTarget()->aliasField($primaryKey) => $entity->get($primaryKey) ]); }); return $query; }
[ "private", "static", "function", "join", "(", "AggregatorInterface", "$", "aggregator", ",", "QueryInterface", "$", "query", ")", ":", "QueryInterface", "{", "$", "config", "=", "$", "aggregator", "->", "getConfig", "(", ")", ";", "if", "(", "!", "$", "config", "->", "joinMode", "(", ")", ")", "{", "return", "$", "query", ";", "}", "Assert", "::", "isInstanceOf", "(", "$", "query", ",", "Query", "::", "class", ")", ";", "$", "association", "=", "static", "::", "findAssociation", "(", "$", "aggregator", ")", ";", "// limit to record's associated data", "$", "query", "->", "innerJoinWith", "(", "$", "association", "->", "getName", "(", ")", ",", "function", "(", "$", "q", ")", "use", "(", "$", "association", ",", "$", "config", ")", "{", "$", "table", "=", "$", "config", "->", "getJoinTable", "(", ")", ";", "$", "primaryKey", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "primaryKey", ")", ")", "{", "Log", "::", "error", "(", "'Failed to apply inner join for aggregated field value: primary key must be a string'", ",", "[", "'source_table'", "=>", "$", "config", "->", "getTable", "(", ")", "->", "getAlias", "(", ")", ",", "'target_table'", "=>", "$", "table", "->", "getAlias", "(", ")", ",", "'primar_key'", "=>", "$", "table", "->", "getPrimaryKey", "(", ")", ",", "'association'", "=>", "$", "association", "->", "getName", "(", ")", "]", ")", ";", "return", "$", "q", ";", "}", "$", "entity", "=", "$", "config", "->", "getEntity", "(", ")", ";", "return", "$", "q", "->", "where", "(", "[", "$", "association", "->", "getTarget", "(", ")", "->", "aliasField", "(", "$", "primaryKey", ")", "=>", "$", "entity", "->", "get", "(", "$", "primaryKey", ")", "]", ")", ";", "}", ")", ";", "return", "$", "query", ";", "}" ]
Aggregator query is joined whenever the entity instance is set, meaning that the results will be limited to the entity's associated records. @param \CsvMigrations\Aggregator\AggregatorInterface $aggregator Aggregator instance @param \Cake\Datasource\QueryInterface $query Query object @return \Cake\Datasource\QueryInterface
[ "Aggregator", "query", "is", "joined", "whenever", "the", "entity", "instance", "is", "set", "meaning", "that", "the", "results", "will", "be", "limited", "to", "the", "entity", "s", "associated", "records", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Aggregator/AggregateResult.php#L43-L77
train
QoboLtd/cakephp-csv-migrations
src/Aggregator/AggregateResult.php
AggregateResult.findAssociation
private static function findAssociation(AggregatorInterface $aggregator) : Association { $config = $aggregator->getConfig(); $table = $config->getTable(); $joinTable = $config->getJoinTable(); foreach ($table->associations() as $association) { // skip unsupported associations if (! in_array($association->type(), ['manyToMany', 'manyToOne'])) { continue; } if ($association->className() !== $joinTable->getAlias()) { continue; } return $association; } throw new RuntimeException(sprintf( 'Table "%s" has no association with "%s"', get_class($config->getTable()), $joinTable->getAlias() )); }
php
private static function findAssociation(AggregatorInterface $aggregator) : Association { $config = $aggregator->getConfig(); $table = $config->getTable(); $joinTable = $config->getJoinTable(); foreach ($table->associations() as $association) { // skip unsupported associations if (! in_array($association->type(), ['manyToMany', 'manyToOne'])) { continue; } if ($association->className() !== $joinTable->getAlias()) { continue; } return $association; } throw new RuntimeException(sprintf( 'Table "%s" has no association with "%s"', get_class($config->getTable()), $joinTable->getAlias() )); }
[ "private", "static", "function", "findAssociation", "(", "AggregatorInterface", "$", "aggregator", ")", ":", "Association", "{", "$", "config", "=", "$", "aggregator", "->", "getConfig", "(", ")", ";", "$", "table", "=", "$", "config", "->", "getTable", "(", ")", ";", "$", "joinTable", "=", "$", "config", "->", "getJoinTable", "(", ")", ";", "foreach", "(", "$", "table", "->", "associations", "(", ")", "as", "$", "association", ")", "{", "// skip unsupported associations", "if", "(", "!", "in_array", "(", "$", "association", "->", "type", "(", ")", ",", "[", "'manyToMany'", ",", "'manyToOne'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "association", "->", "className", "(", ")", "!==", "$", "joinTable", "->", "getAlias", "(", ")", ")", "{", "continue", ";", "}", "return", "$", "association", ";", "}", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Table \"%s\" has no association with \"%s\"'", ",", "get_class", "(", "$", "config", "->", "getTable", "(", ")", ")", ",", "$", "joinTable", "->", "getAlias", "(", ")", ")", ")", ";", "}" ]
Association instance finder. This is from the target table's side, since the aggregation is applied on its column. @param \CsvMigrations\Aggregator\AggregatorInterface $aggregator Aggregator instance @return \Cake\ORM\Association @throws \RuntimeException When association is not found between source and target tables.
[ "Association", "instance", "finder", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Aggregator/AggregateResult.php#L88-L112
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.setName
public function setName(string $name = '') : void { if (empty($name)) { throw new RuntimeException('Panel name not found therefore the object cannot be created'); } $this->name = $name; }
php
public function setName(string $name = '') : void { if (empty($name)) { throw new RuntimeException('Panel name not found therefore the object cannot be created'); } $this->name = $name; }
[ "public", "function", "setName", "(", "string", "$", "name", "=", "''", ")", ":", "void", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Panel name not found therefore the object cannot be created'", ")", ";", "}", "$", "this", "->", "name", "=", "$", "name", ";", "}" ]
Setter of panel name. @param string $name Panel name @return void
[ "Setter", "of", "panel", "name", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L84-L90
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.getExpression
public function getExpression(bool $clean = false) : string { return $clean ? str_replace(self::EXP_TOKEN, '', $this->expression) : // clean up expression from placeholder tokens. $this->expression; }
php
public function getExpression(bool $clean = false) : string { return $clean ? str_replace(self::EXP_TOKEN, '', $this->expression) : // clean up expression from placeholder tokens. $this->expression; }
[ "public", "function", "getExpression", "(", "bool", "$", "clean", "=", "false", ")", ":", "string", "{", "return", "$", "clean", "?", "str_replace", "(", "self", "::", "EXP_TOKEN", ",", "''", ",", "$", "this", "->", "expression", ")", ":", "// clean up expression from placeholder tokens.", "$", "this", "->", "expression", ";", "}" ]
Getter of expression @param bool $clean Flag for removing the expression tokens @return string expression
[ "Getter", "of", "expression" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L98-L103
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.setExpression
public function setExpression(array $config) : void { $panels = Hash::get($config, self::PANELS); $exp = Hash::get($panels, $this->getName()); $this->expression = $exp; }
php
public function setExpression(array $config) : void { $panels = Hash::get($config, self::PANELS); $exp = Hash::get($panels, $this->getName()); $this->expression = $exp; }
[ "public", "function", "setExpression", "(", "array", "$", "config", ")", ":", "void", "{", "$", "panels", "=", "Hash", "::", "get", "(", "$", "config", ",", "self", "::", "PANELS", ")", ";", "$", "exp", "=", "Hash", "::", "get", "(", "$", "panels", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "expression", "=", "$", "exp", ";", "}" ]
Setter of expression. @param mixed[] $config Table's config @return void
[ "Setter", "of", "expression", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L111-L116
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.setFields
public function setFields() : void { preg_match_all('#' . self::EXP_TOKEN . '(.*?)' . self::EXP_TOKEN . '#', $this->getExpression(), $matches); if (empty($matches[1])) { throw new InvalidArgumentException("No tokens found in expression"); } $this->fields = $matches[1]; }
php
public function setFields() : void { preg_match_all('#' . self::EXP_TOKEN . '(.*?)' . self::EXP_TOKEN . '#', $this->getExpression(), $matches); if (empty($matches[1])) { throw new InvalidArgumentException("No tokens found in expression"); } $this->fields = $matches[1]; }
[ "public", "function", "setFields", "(", ")", ":", "void", "{", "preg_match_all", "(", "'#'", ".", "self", "::", "EXP_TOKEN", ".", "'(.*?)'", ".", "self", "::", "EXP_TOKEN", ".", "'#'", ",", "$", "this", "->", "getExpression", "(", ")", ",", "$", "matches", ")", ";", "if", "(", "empty", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"No tokens found in expression\"", ")", ";", "}", "$", "this", "->", "fields", "=", "$", "matches", "[", "1", "]", ";", "}" ]
Setter of fields. @throws InvalidArgumentException @return void
[ "Setter", "of", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L134-L141
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.getFieldValues
public function getFieldValues(array $data) : array { $result = []; foreach ($this->getFields() as $field) { $result[$field] = array_key_exists($field, $data) ? $data[$field] : null; } return $result; }
php
public function getFieldValues(array $data) : array { $result = []; foreach ($this->getFields() as $field) { $result[$field] = array_key_exists($field, $data) ? $data[$field] : null; } return $result; }
[ "public", "function", "getFieldValues", "(", "array", "$", "data", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getFields", "(", ")", "as", "$", "field", ")", "{", "$", "result", "[", "$", "field", "]", "=", "array_key_exists", "(", "$", "field", ",", "$", "data", ")", "?", "$", "data", "[", "$", "field", "]", ":", "null", ";", "}", "return", "$", "result", ";", "}" ]
Returns field values from the given entity. @param mixed[] $data to get the values for placeholders @return mixed[] Associative array, Keys: placeholders Values: values
[ "Returns", "field", "values", "from", "the", "given", "entity", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L149-L157
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.evalExpression
public function evalExpression(array $data) : bool { $language = new ExpressionLanguage(); $values = $this->getFieldValues($data); $eval = $language->evaluate($this->getExpression(true), $values); return $eval; }
php
public function evalExpression(array $data) : bool { $language = new ExpressionLanguage(); $values = $this->getFieldValues($data); $eval = $language->evaluate($this->getExpression(true), $values); return $eval; }
[ "public", "function", "evalExpression", "(", "array", "$", "data", ")", ":", "bool", "{", "$", "language", "=", "new", "ExpressionLanguage", "(", ")", ";", "$", "values", "=", "$", "this", "->", "getFieldValues", "(", "$", "data", ")", ";", "$", "eval", "=", "$", "language", "->", "evaluate", "(", "$", "this", "->", "getExpression", "(", "true", ")", ",", "$", "values", ")", ";", "return", "$", "eval", ";", "}" ]
Evaluate the expression. @param mixed[] $data to get the values for placeholders @return bool True if it matches, false otherwise.
[ "Evaluate", "the", "expression", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L165-L172
train
QoboLtd/cakephp-csv-migrations
src/Utility/Panel.php
Panel.getPanelNames
public static function getPanelNames(array $config) : array { if (empty($config[self::PANELS])) { return []; } return array_keys($config[self::PANELS]); }
php
public static function getPanelNames(array $config) : array { if (empty($config[self::PANELS])) { return []; } return array_keys($config[self::PANELS]); }
[ "public", "static", "function", "getPanelNames", "(", "array", "$", "config", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "config", "[", "self", "::", "PANELS", "]", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_keys", "(", "$", "config", "[", "self", "::", "PANELS", "]", ")", ";", "}" ]
Returns panel names. @param mixed[] $config Table's config @return mixed[]
[ "Returns", "panel", "names", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Panel.php#L180-L187
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getLookup
public static function getLookup(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MODULE(), $moduleName); $parsed = $config->parse(); if (! property_exists($parsed, 'table')) { return []; } if (! property_exists($parsed->table, 'lookup_fields')) { return []; } return $parsed->table->lookup_fields; }
php
public static function getLookup(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MODULE(), $moduleName); $parsed = $config->parse(); if (! property_exists($parsed, 'table')) { return []; } if (! property_exists($parsed->table, 'lookup_fields')) { return []; } return $parsed->table->lookup_fields; }
[ "public", "static", "function", "getLookup", "(", "RepositoryInterface", "$", "table", ")", ":", "array", "{", "$", "moduleName", "=", "App", "::", "shortName", "(", "get_class", "(", "$", "table", ")", ",", "'Model/Table'", ",", "'Table'", ")", ";", "$", "config", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "moduleName", ")", ";", "$", "parsed", "=", "$", "config", "->", "parse", "(", ")", ";", "if", "(", "!", "property_exists", "(", "$", "parsed", ",", "'table'", ")", ")", "{", "return", "[", "]", ";", "}", "if", "(", "!", "property_exists", "(", "$", "parsed", "->", "table", ",", "'lookup_fields'", ")", ")", "{", "return", "[", "]", ";", "}", "return", "$", "parsed", "->", "table", "->", "lookup_fields", ";", "}" ]
Get Table's lookup fields. @param \Cake\Datasource\RepositoryInterface $table Table instance @return string[]
[ "Get", "Table", "s", "lookup", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L29-L45
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getCsv
public static function getCsv(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MIGRATION(), $moduleName); $parsed = json_encode($config->parse()); if (false === $parsed) { return []; } $parsed = json_decode($parsed, true); if (empty($parsed)) { return []; } $result = []; foreach ($parsed as $field => $params) { $result[$field] = new CsvField($params); } return $result; }
php
public static function getCsv(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MIGRATION(), $moduleName); $parsed = json_encode($config->parse()); if (false === $parsed) { return []; } $parsed = json_decode($parsed, true); if (empty($parsed)) { return []; } $result = []; foreach ($parsed as $field => $params) { $result[$field] = new CsvField($params); } return $result; }
[ "public", "static", "function", "getCsv", "(", "RepositoryInterface", "$", "table", ")", ":", "array", "{", "$", "moduleName", "=", "App", "::", "shortName", "(", "get_class", "(", "$", "table", ")", ",", "'Model/Table'", ",", "'Table'", ")", ";", "$", "config", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "moduleName", ")", ";", "$", "parsed", "=", "json_encode", "(", "$", "config", "->", "parse", "(", ")", ")", ";", "if", "(", "false", "===", "$", "parsed", ")", "{", "return", "[", "]", ";", "}", "$", "parsed", "=", "json_decode", "(", "$", "parsed", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "parsed", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "parsed", "as", "$", "field", "=>", "$", "params", ")", "{", "$", "result", "[", "$", "field", "]", "=", "new", "CsvField", "(", "$", "params", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get Table's csv fields. @param \Cake\Datasource\RepositoryInterface $table Table instance @return mixed[]
[ "Get", "Table", "s", "csv", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L53-L75
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getCsvField
public static function getCsvField(RepositoryInterface $table, string $field) : ?CsvField { if ('' === $field) { return null; } $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MIGRATION(), $moduleName); $parsed = $config->parse(); if (! property_exists($parsed, $field)) { return null; } $parsed = json_encode($parsed->{$field}); if (false === $parsed) { return null; } return new CsvField(json_decode($parsed, true)); }
php
public static function getCsvField(RepositoryInterface $table, string $field) : ?CsvField { if ('' === $field) { return null; } $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = new ModuleConfig(ConfigType::MIGRATION(), $moduleName); $parsed = $config->parse(); if (! property_exists($parsed, $field)) { return null; } $parsed = json_encode($parsed->{$field}); if (false === $parsed) { return null; } return new CsvField(json_decode($parsed, true)); }
[ "public", "static", "function", "getCsvField", "(", "RepositoryInterface", "$", "table", ",", "string", "$", "field", ")", ":", "?", "CsvField", "{", "if", "(", "''", "===", "$", "field", ")", "{", "return", "null", ";", "}", "$", "moduleName", "=", "App", "::", "shortName", "(", "get_class", "(", "$", "table", ")", ",", "'Model/Table'", ",", "'Table'", ")", ";", "$", "config", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "MIGRATION", "(", ")", ",", "$", "moduleName", ")", ";", "$", "parsed", "=", "$", "config", "->", "parse", "(", ")", ";", "if", "(", "!", "property_exists", "(", "$", "parsed", ",", "$", "field", ")", ")", "{", "return", "null", ";", "}", "$", "parsed", "=", "json_encode", "(", "$", "parsed", "->", "{", "$", "field", "}", ")", ";", "if", "(", "false", "===", "$", "parsed", ")", "{", "return", "null", ";", "}", "return", "new", "CsvField", "(", "json_decode", "(", "$", "parsed", ",", "true", ")", ")", ";", "}" ]
CSV field instance getter. @param \Cake\Datasource\RepositoryInterface $table Table instance @param string $field Field name @return \CsvMigrations\FieldHandlers\CsvField|null
[ "CSV", "field", "instance", "getter", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L84-L105
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getVirtual
public static function getVirtual(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = (new ModuleConfig(ConfigType::MODULE(), $moduleName))->parse(); return property_exists($config, 'virtualFields') ? (array)$config->virtualFields : []; }
php
public static function getVirtual(RepositoryInterface $table) : array { $moduleName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = (new ModuleConfig(ConfigType::MODULE(), $moduleName))->parse(); return property_exists($config, 'virtualFields') ? (array)$config->virtualFields : []; }
[ "public", "static", "function", "getVirtual", "(", "RepositoryInterface", "$", "table", ")", ":", "array", "{", "$", "moduleName", "=", "App", "::", "shortName", "(", "get_class", "(", "$", "table", ")", ",", "'Model/Table'", ",", "'Table'", ")", ";", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "moduleName", ")", ")", "->", "parse", "(", ")", ";", "return", "property_exists", "(", "$", "config", ",", "'virtualFields'", ")", "?", "(", "array", ")", "$", "config", "->", "virtualFields", ":", "[", "]", ";", "}" ]
Module virtual fields getter. @param \Cake\Datasource\RepositoryInterface $table Table instance @return string[]
[ "Module", "virtual", "fields", "getter", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L113-L120
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getCsvView
public static function getCsvView(RepositoryInterface $table, string $action, bool $includeModel = false, bool $panels = false) : array { $tableName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = (new ModuleConfig(ConfigType::VIEW(), $tableName, $action))->parse(); if (! isset($config->items)) { return []; } $result = $config->items; if ($panels) { $result = static::arrangePanels($result); } if ($includeModel) { $result = static::setFieldPluginAndModel($tableName, $result); } return $result; }
php
public static function getCsvView(RepositoryInterface $table, string $action, bool $includeModel = false, bool $panels = false) : array { $tableName = App::shortName(get_class($table), 'Model/Table', 'Table'); $config = (new ModuleConfig(ConfigType::VIEW(), $tableName, $action))->parse(); if (! isset($config->items)) { return []; } $result = $config->items; if ($panels) { $result = static::arrangePanels($result); } if ($includeModel) { $result = static::setFieldPluginAndModel($tableName, $result); } return $result; }
[ "public", "static", "function", "getCsvView", "(", "RepositoryInterface", "$", "table", ",", "string", "$", "action", ",", "bool", "$", "includeModel", "=", "false", ",", "bool", "$", "panels", "=", "false", ")", ":", "array", "{", "$", "tableName", "=", "App", "::", "shortName", "(", "get_class", "(", "$", "table", ")", ",", "'Model/Table'", ",", "'Table'", ")", ";", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "VIEW", "(", ")", ",", "$", "tableName", ",", "$", "action", ")", ")", "->", "parse", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "->", "items", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "$", "config", "->", "items", ";", "if", "(", "$", "panels", ")", "{", "$", "result", "=", "static", "::", "arrangePanels", "(", "$", "result", ")", ";", "}", "if", "(", "$", "includeModel", ")", "{", "$", "result", "=", "static", "::", "setFieldPluginAndModel", "(", "$", "tableName", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get View's csv fields. @param \Cake\Datasource\RepositoryInterface $table Table instance @param string $action Controller action @param bool $includeModel Include model flag @param bool $panels Arrange panels flag @return mixed[]
[ "Get", "View", "s", "csv", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L131-L152
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.getList
public static function getList(string $listName, bool $flat = false) : array { $moduleName = ''; if (false !== strpos($listName, '.')) { list($moduleName, $listName) = explode('.', $listName, 2); } $config = new ModuleConfig(ConfigType::LISTS(), $moduleName, $listName, ['flatten' => $flat]); try { $config = json_encode($config->parse()); $config = false !== $config ? json_decode($config, true) : []; $items = isset($config['items']) ? $config['items'] : []; } catch (InvalidArgumentException $e) { return []; } return $items; }
php
public static function getList(string $listName, bool $flat = false) : array { $moduleName = ''; if (false !== strpos($listName, '.')) { list($moduleName, $listName) = explode('.', $listName, 2); } $config = new ModuleConfig(ConfigType::LISTS(), $moduleName, $listName, ['flatten' => $flat]); try { $config = json_encode($config->parse()); $config = false !== $config ? json_decode($config, true) : []; $items = isset($config['items']) ? $config['items'] : []; } catch (InvalidArgumentException $e) { return []; } return $items; }
[ "public", "static", "function", "getList", "(", "string", "$", "listName", ",", "bool", "$", "flat", "=", "false", ")", ":", "array", "{", "$", "moduleName", "=", "''", ";", "if", "(", "false", "!==", "strpos", "(", "$", "listName", ",", "'.'", ")", ")", "{", "list", "(", "$", "moduleName", ",", "$", "listName", ")", "=", "explode", "(", "'.'", ",", "$", "listName", ",", "2", ")", ";", "}", "$", "config", "=", "new", "ModuleConfig", "(", "ConfigType", "::", "LISTS", "(", ")", ",", "$", "moduleName", ",", "$", "listName", ",", "[", "'flatten'", "=>", "$", "flat", "]", ")", ";", "try", "{", "$", "config", "=", "json_encode", "(", "$", "config", "->", "parse", "(", ")", ")", ";", "$", "config", "=", "false", "!==", "$", "config", "?", "json_decode", "(", "$", "config", ",", "true", ")", ":", "[", "]", ";", "$", "items", "=", "isset", "(", "$", "config", "[", "'items'", "]", ")", "?", "$", "config", "[", "'items'", "]", ":", "[", "]", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "return", "[", "]", ";", "}", "return", "$", "items", ";", "}" ]
Get list's options. @param string $listName List name @param bool $flat Fatten list flag @return mixed[]
[ "Get", "list", "s", "options", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L161-L178
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.arrangePanels
protected static function arrangePanels(array $fields) : array { $result = []; foreach ($fields as $row) { $panelName = array_shift($row); $result[$panelName][] = $row; } return $result; }
php
protected static function arrangePanels(array $fields) : array { $result = []; foreach ($fields as $row) { $panelName = array_shift($row); $result[$panelName][] = $row; } return $result; }
[ "protected", "static", "function", "arrangePanels", "(", "array", "$", "fields", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "row", ")", "{", "$", "panelName", "=", "array_shift", "(", "$", "row", ")", ";", "$", "result", "[", "$", "panelName", "]", "[", "]", "=", "$", "row", ";", "}", "return", "$", "result", ";", "}" ]
Method that arranges csv fields into panels. @param mixed[] $fields csv fields @return mixed[]
[ "Method", "that", "arranges", "csv", "fields", "into", "panels", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L186-L196
train
QoboLtd/cakephp-csv-migrations
src/Utility/Field.php
Field.setFieldPluginAndModel
protected static function setFieldPluginAndModel(string $tableName, array $fields) : array { list($plugin, $model) = pluginSplit($tableName); $callback = function (&$value, $key) use ($plugin, $model) { $value = ['plugin' => $plugin, 'model' => $model, 'name' => $value]; return $value; }; array_walk_recursive($fields, $callback); return $fields; }
php
protected static function setFieldPluginAndModel(string $tableName, array $fields) : array { list($plugin, $model) = pluginSplit($tableName); $callback = function (&$value, $key) use ($plugin, $model) { $value = ['plugin' => $plugin, 'model' => $model, 'name' => $value]; return $value; }; array_walk_recursive($fields, $callback); return $fields; }
[ "protected", "static", "function", "setFieldPluginAndModel", "(", "string", "$", "tableName", ",", "array", "$", "fields", ")", ":", "array", "{", "list", "(", "$", "plugin", ",", "$", "model", ")", "=", "pluginSplit", "(", "$", "tableName", ")", ";", "$", "callback", "=", "function", "(", "&", "$", "value", ",", "$", "key", ")", "use", "(", "$", "plugin", ",", "$", "model", ")", "{", "$", "value", "=", "[", "'plugin'", "=>", "$", "plugin", ",", "'model'", "=>", "$", "model", ",", "'name'", "=>", "$", "value", "]", ";", "return", "$", "value", ";", "}", ";", "array_walk_recursive", "(", "$", "fields", ",", "$", "callback", ")", ";", "return", "$", "fields", ";", "}" ]
Add plugin and model name for each of the csv fields. @param string $tableName Table name @param string[] $fields View csv fields @return mixed[]
[ "Add", "plugin", "and", "model", "name", "for", "each", "of", "the", "csv", "fields", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Field.php#L205-L218
train
QoboLtd/cakephp-csv-migrations
src/Model/Table/ImportResultsTable.php
ImportResultsTable.findImported
public function findImported(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_SUCCESS ]); return $query; }
php
public function findImported(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_SUCCESS ]); return $query; }
[ "public", "function", "findImported", "(", "QueryInterface", "$", "query", ",", "array", "$", "options", ")", ":", "QueryInterface", "{", "$", "query", "->", "where", "(", "[", "'import_id'", "=>", "$", "options", "[", "'import'", "]", "->", "id", ",", "'status'", "=>", "static", "::", "STATUS_SUCCESS", "]", ")", ";", "return", "$", "query", ";", "}" ]
Find import results by import id and success status. @param \Cake\Datasource\QueryInterface $query Query object @param mixed[] $options Additional options @return \Cake\Datasource\QueryInterface
[ "Find", "import", "results", "by", "import", "id", "and", "success", "status", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Model/Table/ImportResultsTable.php#L147-L155
train
QoboLtd/cakephp-csv-migrations
src/Model/Table/ImportResultsTable.php
ImportResultsTable.findPending
public function findPending(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_PENDING ]); return $query; }
php
public function findPending(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_PENDING ]); return $query; }
[ "public", "function", "findPending", "(", "QueryInterface", "$", "query", ",", "array", "$", "options", ")", ":", "QueryInterface", "{", "$", "query", "->", "where", "(", "[", "'import_id'", "=>", "$", "options", "[", "'import'", "]", "->", "id", ",", "'status'", "=>", "static", "::", "STATUS_PENDING", "]", ")", ";", "return", "$", "query", ";", "}" ]
Find import results by import id and pending status. @param \Cake\Datasource\QueryInterface $query Query object @param mixed[] $options Additional options @return \Cake\Datasource\QueryInterface
[ "Find", "import", "results", "by", "import", "id", "and", "pending", "status", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Model/Table/ImportResultsTable.php#L164-L172
train
QoboLtd/cakephp-csv-migrations
src/Model/Table/ImportResultsTable.php
ImportResultsTable.findFailed
public function findFailed(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_FAIL ]); return $query; }
php
public function findFailed(QueryInterface $query, array $options) : QueryInterface { $query->where([ 'import_id' => $options['import']->id, 'status' => static::STATUS_FAIL ]); return $query; }
[ "public", "function", "findFailed", "(", "QueryInterface", "$", "query", ",", "array", "$", "options", ")", ":", "QueryInterface", "{", "$", "query", "->", "where", "(", "[", "'import_id'", "=>", "$", "options", "[", "'import'", "]", "->", "id", ",", "'status'", "=>", "static", "::", "STATUS_FAIL", "]", ")", ";", "return", "$", "query", ";", "}" ]
Find import results by import id and fail status. @param \Cake\Datasource\QueryInterface $query Query object @param mixed[] $options Additional options @return \Cake\Datasource\QueryInterface
[ "Find", "import", "results", "by", "import", "id", "and", "fail", "status", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Model/Table/ImportResultsTable.php#L181-L189
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Check/ViewsCheck.php
ViewsCheck.validateEmbedded
protected function validateEmbedded(string $embeddedValue, string $module, string $view): void { // extract embedded module and field list($embeddedModule, $embeddedModuleField) = false !== strpos($embeddedValue, '.') ? explode('.', $embeddedValue) : [null, $embeddedValue]; if (empty($embeddedModule)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column without a module', $module, $view ); } if (! empty($embeddedModule) && ! Utility::isValidModule($embeddedModule)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column with unknown module "%s"', $module, $view, $embeddedModule ); } if (empty($embeddedModuleField)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column without a module field', $module, $view ); } if (! empty($embeddedModuleField) && ! Utility::isValidModuleField($module, $embeddedModuleField)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column with unknown field "%s" of module "%s"', $module, $view, $embeddedModuleField, $embeddedModule ); } }
php
protected function validateEmbedded(string $embeddedValue, string $module, string $view): void { // extract embedded module and field list($embeddedModule, $embeddedModuleField) = false !== strpos($embeddedValue, '.') ? explode('.', $embeddedValue) : [null, $embeddedValue]; if (empty($embeddedModule)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column without a module', $module, $view ); } if (! empty($embeddedModule) && ! Utility::isValidModule($embeddedModule)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column with unknown module "%s"', $module, $view, $embeddedModule ); } if (empty($embeddedModuleField)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column without a module field', $module, $view ); } if (! empty($embeddedModuleField) && ! Utility::isValidModuleField($module, $embeddedModuleField)) { $this->errors[] = sprintf( '%s module [%s] view reference EMBEDDED column with unknown field "%s" of module "%s"', $module, $view, $embeddedModuleField, $embeddedModule ); } }
[ "protected", "function", "validateEmbedded", "(", "string", "$", "embeddedValue", ",", "string", "$", "module", ",", "string", "$", "view", ")", ":", "void", "{", "// extract embedded module and field", "list", "(", "$", "embeddedModule", ",", "$", "embeddedModuleField", ")", "=", "false", "!==", "strpos", "(", "$", "embeddedValue", ",", "'.'", ")", "?", "explode", "(", "'.'", ",", "$", "embeddedValue", ")", ":", "[", "null", ",", "$", "embeddedValue", "]", ";", "if", "(", "empty", "(", "$", "embeddedModule", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'%s module [%s] view reference EMBEDDED column without a module'", ",", "$", "module", ",", "$", "view", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "embeddedModule", ")", "&&", "!", "Utility", "::", "isValidModule", "(", "$", "embeddedModule", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'%s module [%s] view reference EMBEDDED column with unknown module \"%s\"'", ",", "$", "module", ",", "$", "view", ",", "$", "embeddedModule", ")", ";", "}", "if", "(", "empty", "(", "$", "embeddedModuleField", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'%s module [%s] view reference EMBEDDED column without a module field'", ",", "$", "module", ",", "$", "view", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "embeddedModuleField", ")", "&&", "!", "Utility", "::", "isValidModuleField", "(", "$", "module", ",", "$", "embeddedModuleField", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'%s module [%s] view reference EMBEDDED column with unknown field \"%s\" of module \"%s\"'", ",", "$", "module", ",", "$", "view", ",", "$", "embeddedModuleField", ",", "$", "embeddedModule", ")", ";", "}", "}" ]
Validates values enclosed in EMBEDDED @param string $embeddedValue Value enclosed by EMBEDDED(...) @param string $module Module's name @param string $view View's name @return void
[ "Validates", "values", "enclosed", "in", "EMBEDDED" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Check/ViewsCheck.php#L141-L182
train
QoboLtd/cakephp-csv-migrations
src/Utility/Validate/Check/ViewsCheck.php
ViewsCheck.validateAssociation
protected function validateAssociation(string $associationValue, string $module, string $view): void { $table = TableRegistry::getTableLocator()->get($module); if (!$table->hasAssociation($associationValue)) { $this->errors[] = sprintf( '%s module [%s] view reference ASSOCIATION column with unknown association "%s"', $module, $view, $associationValue ); } }
php
protected function validateAssociation(string $associationValue, string $module, string $view): void { $table = TableRegistry::getTableLocator()->get($module); if (!$table->hasAssociation($associationValue)) { $this->errors[] = sprintf( '%s module [%s] view reference ASSOCIATION column with unknown association "%s"', $module, $view, $associationValue ); } }
[ "protected", "function", "validateAssociation", "(", "string", "$", "associationValue", ",", "string", "$", "module", ",", "string", "$", "view", ")", ":", "void", "{", "$", "table", "=", "TableRegistry", "::", "getTableLocator", "(", ")", "->", "get", "(", "$", "module", ")", ";", "if", "(", "!", "$", "table", "->", "hasAssociation", "(", "$", "associationValue", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "sprintf", "(", "'%s module [%s] view reference ASSOCIATION column with unknown association \"%s\"'", ",", "$", "module", ",", "$", "view", ",", "$", "associationValue", ")", ";", "}", "}" ]
Validates values enclosed in ASSOCIATION @param string $associationValue Value enclosed by ASSOCIATION(...) @param string $module Module's name @param string $view View's name @return void
[ "Validates", "values", "enclosed", "in", "ASSOCIATION" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/Utility/Validate/Check/ViewsCheck.php#L192-L203
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getRelatedParentProperties
protected function _getRelatedParentProperties(array $relatedProperties) : array { if (empty($relatedProperties['entity']) || empty($relatedProperties['controller']) || empty($relatedProperties['config']['parent']['module']) ) { return []; } $foreignKey = $this->_getForeignKey( TableRegistry::get($relatedProperties['config']['parent']['module']), empty($relatedProperties['plugin']) ? $relatedProperties['controller'] : sprintf('%s.%s', $relatedProperties['plugin'], $relatedProperties['controller']) ); if ('' === $foreignKey) { return []; } if (empty($relatedProperties['entity']->get($foreignKey))) { return []; } $result = $this->_getRelatedProperties( $relatedProperties['config']['parent']['module'], $relatedProperties['entity']->get($foreignKey) ); if (null === $result['entity']) { return []; } return $result; }
php
protected function _getRelatedParentProperties(array $relatedProperties) : array { if (empty($relatedProperties['entity']) || empty($relatedProperties['controller']) || empty($relatedProperties['config']['parent']['module']) ) { return []; } $foreignKey = $this->_getForeignKey( TableRegistry::get($relatedProperties['config']['parent']['module']), empty($relatedProperties['plugin']) ? $relatedProperties['controller'] : sprintf('%s.%s', $relatedProperties['plugin'], $relatedProperties['controller']) ); if ('' === $foreignKey) { return []; } if (empty($relatedProperties['entity']->get($foreignKey))) { return []; } $result = $this->_getRelatedProperties( $relatedProperties['config']['parent']['module'], $relatedProperties['entity']->get($foreignKey) ); if (null === $result['entity']) { return []; } return $result; }
[ "protected", "function", "_getRelatedParentProperties", "(", "array", "$", "relatedProperties", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "relatedProperties", "[", "'entity'", "]", ")", "||", "empty", "(", "$", "relatedProperties", "[", "'controller'", "]", ")", "||", "empty", "(", "$", "relatedProperties", "[", "'config'", "]", "[", "'parent'", "]", "[", "'module'", "]", ")", ")", "{", "return", "[", "]", ";", "}", "$", "foreignKey", "=", "$", "this", "->", "_getForeignKey", "(", "TableRegistry", "::", "get", "(", "$", "relatedProperties", "[", "'config'", "]", "[", "'parent'", "]", "[", "'module'", "]", ")", ",", "empty", "(", "$", "relatedProperties", "[", "'plugin'", "]", ")", "?", "$", "relatedProperties", "[", "'controller'", "]", ":", "sprintf", "(", "'%s.%s'", ",", "$", "relatedProperties", "[", "'plugin'", "]", ",", "$", "relatedProperties", "[", "'controller'", "]", ")", ")", ";", "if", "(", "''", "===", "$", "foreignKey", ")", "{", "return", "[", "]", ";", "}", "if", "(", "empty", "(", "$", "relatedProperties", "[", "'entity'", "]", "->", "get", "(", "$", "foreignKey", ")", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "$", "this", "->", "_getRelatedProperties", "(", "$", "relatedProperties", "[", "'config'", "]", "[", "'parent'", "]", "[", "'module'", "]", ",", "$", "relatedProperties", "[", "'entity'", "]", "->", "get", "(", "$", "foreignKey", ")", ")", ";", "if", "(", "null", "===", "$", "result", "[", "'entity'", "]", ")", "{", "return", "[", "]", ";", "}", "return", "$", "result", ";", "}" ]
Get related model's parent model properties. @param mixed[] $relatedProperties related model properties @return mixed[] $result containing parent properties
[ "Get", "related", "model", "s", "parent", "model", "properties", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L41-L75
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getRelatedProperties
protected function _getRelatedProperties(string $tableName, string $data) : array { $table = TableRegistry::get($tableName); $config = (new ModuleConfig(ConfigType::MODULE(), $tableName))->parseToArray(); $displayField = $table->getDisplayField(); $displayFieldValue = ''; try { $entity = $this->_getAssociatedRecord($table, $data); // get related table's display field value by rendering it through field handler factory $value = (new FieldHandlerFactory())->renderValue( $table, $displayField, $entity->get($displayField), ['renderAs' => Setting::RENDER_PLAIN_VALUE_RELATED()] ); $displayFieldValue = '' === $value ? 'N/A' : $value; } catch (RecordNotFoundException $e) { // @todo rethrow the exception $entity = null; } $result = [ 'id' => $data, 'config' => $config, 'displayField' => $displayField, 'entity' => $entity, 'dispFieldVal' => $displayFieldValue ]; // get plugin and controller names list($result['plugin'], $result['controller']) = pluginSplit($table->getAlias()); return $result; }
php
protected function _getRelatedProperties(string $tableName, string $data) : array { $table = TableRegistry::get($tableName); $config = (new ModuleConfig(ConfigType::MODULE(), $tableName))->parseToArray(); $displayField = $table->getDisplayField(); $displayFieldValue = ''; try { $entity = $this->_getAssociatedRecord($table, $data); // get related table's display field value by rendering it through field handler factory $value = (new FieldHandlerFactory())->renderValue( $table, $displayField, $entity->get($displayField), ['renderAs' => Setting::RENDER_PLAIN_VALUE_RELATED()] ); $displayFieldValue = '' === $value ? 'N/A' : $value; } catch (RecordNotFoundException $e) { // @todo rethrow the exception $entity = null; } $result = [ 'id' => $data, 'config' => $config, 'displayField' => $displayField, 'entity' => $entity, 'dispFieldVal' => $displayFieldValue ]; // get plugin and controller names list($result['plugin'], $result['controller']) = pluginSplit($table->getAlias()); return $result; }
[ "protected", "function", "_getRelatedProperties", "(", "string", "$", "tableName", ",", "string", "$", "data", ")", ":", "array", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "$", "tableName", ")", ";", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "tableName", ")", ")", "->", "parseToArray", "(", ")", ";", "$", "displayField", "=", "$", "table", "->", "getDisplayField", "(", ")", ";", "$", "displayFieldValue", "=", "''", ";", "try", "{", "$", "entity", "=", "$", "this", "->", "_getAssociatedRecord", "(", "$", "table", ",", "$", "data", ")", ";", "// get related table's display field value by rendering it through field handler factory", "$", "value", "=", "(", "new", "FieldHandlerFactory", "(", ")", ")", "->", "renderValue", "(", "$", "table", ",", "$", "displayField", ",", "$", "entity", "->", "get", "(", "$", "displayField", ")", ",", "[", "'renderAs'", "=>", "Setting", "::", "RENDER_PLAIN_VALUE_RELATED", "(", ")", "]", ")", ";", "$", "displayFieldValue", "=", "''", "===", "$", "value", "?", "'N/A'", ":", "$", "value", ";", "}", "catch", "(", "RecordNotFoundException", "$", "e", ")", "{", "// @todo rethrow the exception", "$", "entity", "=", "null", ";", "}", "$", "result", "=", "[", "'id'", "=>", "$", "data", ",", "'config'", "=>", "$", "config", ",", "'displayField'", "=>", "$", "displayField", ",", "'entity'", "=>", "$", "entity", ",", "'dispFieldVal'", "=>", "$", "displayFieldValue", "]", ";", "// get plugin and controller names", "list", "(", "$", "result", "[", "'plugin'", "]", ",", "$", "result", "[", "'controller'", "]", ")", "=", "pluginSplit", "(", "$", "table", "->", "getAlias", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
Get related model's properties. @param string $tableName Related table name @param string $data query parameter value @return mixed[]
[ "Get", "related", "model", "s", "properties", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L84-L121
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getForeignKey
protected function _getForeignKey(Table $table, string $modelName) : string { foreach ($table->associations() as $association) { if ($modelName !== $association->className()) { continue; } $primaryKey = $association->getForeignKey(); if (! is_string($primaryKey)) { throw new RuntimeException('Primary key must be a string'); } return $primaryKey; } return ''; }
php
protected function _getForeignKey(Table $table, string $modelName) : string { foreach ($table->associations() as $association) { if ($modelName !== $association->className()) { continue; } $primaryKey = $association->getForeignKey(); if (! is_string($primaryKey)) { throw new RuntimeException('Primary key must be a string'); } return $primaryKey; } return ''; }
[ "protected", "function", "_getForeignKey", "(", "Table", "$", "table", ",", "string", "$", "modelName", ")", ":", "string", "{", "foreach", "(", "$", "table", "->", "associations", "(", ")", "as", "$", "association", ")", "{", "if", "(", "$", "modelName", "!==", "$", "association", "->", "className", "(", ")", ")", "{", "continue", ";", "}", "$", "primaryKey", "=", "$", "association", "->", "getForeignKey", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "primaryKey", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Primary key must be a string'", ")", ";", "}", "return", "$", "primaryKey", ";", "}", "return", "''", ";", "}" ]
Get parent model association's foreign key. @param \Cake\ORM\Table $table Table instance @param string $modelName Model name @return string
[ "Get", "parent", "model", "association", "s", "foreign", "key", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L130-L146
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getAssociatedRecord
protected function _getAssociatedRecord(Table $table, string $value) : EntityInterface { $primaryKey = $table->getPrimaryKey(); if (! is_string($primaryKey)) { throw new UnsupportedPrimaryKeyException(); } // try to fetch with trashed if finder method exists, otherwise fallback to find all $finderMethod = $table->hasBehavior('Trash') ? 'withTrashed' : 'all'; $entity = $table->find($finderMethod, ['conditions' => [$table->aliasField($primaryKey) => $value]]) ->enableHydration(true) ->firstOrFail(); Assert::isInstanceOf($entity, EntityInterface::class); return $entity; }
php
protected function _getAssociatedRecord(Table $table, string $value) : EntityInterface { $primaryKey = $table->getPrimaryKey(); if (! is_string($primaryKey)) { throw new UnsupportedPrimaryKeyException(); } // try to fetch with trashed if finder method exists, otherwise fallback to find all $finderMethod = $table->hasBehavior('Trash') ? 'withTrashed' : 'all'; $entity = $table->find($finderMethod, ['conditions' => [$table->aliasField($primaryKey) => $value]]) ->enableHydration(true) ->firstOrFail(); Assert::isInstanceOf($entity, EntityInterface::class); return $entity; }
[ "protected", "function", "_getAssociatedRecord", "(", "Table", "$", "table", ",", "string", "$", "value", ")", ":", "EntityInterface", "{", "$", "primaryKey", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "primaryKey", ")", ")", "{", "throw", "new", "UnsupportedPrimaryKeyException", "(", ")", ";", "}", "// try to fetch with trashed if finder method exists, otherwise fallback to find all", "$", "finderMethod", "=", "$", "table", "->", "hasBehavior", "(", "'Trash'", ")", "?", "'withTrashed'", ":", "'all'", ";", "$", "entity", "=", "$", "table", "->", "find", "(", "$", "finderMethod", ",", "[", "'conditions'", "=>", "[", "$", "table", "->", "aliasField", "(", "$", "primaryKey", ")", "=>", "$", "value", "]", "]", ")", "->", "enableHydration", "(", "true", ")", "->", "firstOrFail", "(", ")", ";", "Assert", "::", "isInstanceOf", "(", "$", "entity", ",", "EntityInterface", "::", "class", ")", ";", "return", "$", "entity", ";", "}" ]
Retrieve and return associated record Entity, by primary key value. If the record has been trashed - query will return NULL. @param \Cake\ORM\Table $table Table instance @param string $value Primary key value @return \Cake\Datasource\EntityInterface
[ "Retrieve", "and", "return", "associated", "record", "Entity", "by", "primary", "key", "value", ".", "If", "the", "record", "has", "been", "trashed", "-", "query", "will", "return", "NULL", "." ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L156-L172
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getInputHelp
protected function _getInputHelp(array $properties) : string { $config = (new ModuleConfig(ConfigType::MODULE(), $properties['controller']))->parseToArray(); $typeaheadFields = !empty($config['table']['typeahead_fields']) ? $config['table']['typeahead_fields'] : []; // if no typeahead fields, use display field if (empty($typeaheadFields)) { $typeaheadFields = [$properties['displayField']]; } $virtualFields = !empty($config['virtualFields']) ? $config['virtualFields'] : []; // extract virtual fields, if any $result = []; foreach ($typeaheadFields as $typeaheadField) { $fields = isset($virtualFields[$typeaheadField]) ? (array)$virtualFields[$typeaheadField] : [$typeaheadField]; $result = array_merge($result, $fields); } return implode(', or ', array_map(function ($value) { return Inflector::humanize($value); }, $result)); }
php
protected function _getInputHelp(array $properties) : string { $config = (new ModuleConfig(ConfigType::MODULE(), $properties['controller']))->parseToArray(); $typeaheadFields = !empty($config['table']['typeahead_fields']) ? $config['table']['typeahead_fields'] : []; // if no typeahead fields, use display field if (empty($typeaheadFields)) { $typeaheadFields = [$properties['displayField']]; } $virtualFields = !empty($config['virtualFields']) ? $config['virtualFields'] : []; // extract virtual fields, if any $result = []; foreach ($typeaheadFields as $typeaheadField) { $fields = isset($virtualFields[$typeaheadField]) ? (array)$virtualFields[$typeaheadField] : [$typeaheadField]; $result = array_merge($result, $fields); } return implode(', or ', array_map(function ($value) { return Inflector::humanize($value); }, $result)); }
[ "protected", "function", "_getInputHelp", "(", "array", "$", "properties", ")", ":", "string", "{", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "properties", "[", "'controller'", "]", ")", ")", "->", "parseToArray", "(", ")", ";", "$", "typeaheadFields", "=", "!", "empty", "(", "$", "config", "[", "'table'", "]", "[", "'typeahead_fields'", "]", ")", "?", "$", "config", "[", "'table'", "]", "[", "'typeahead_fields'", "]", ":", "[", "]", ";", "// if no typeahead fields, use display field", "if", "(", "empty", "(", "$", "typeaheadFields", ")", ")", "{", "$", "typeaheadFields", "=", "[", "$", "properties", "[", "'displayField'", "]", "]", ";", "}", "$", "virtualFields", "=", "!", "empty", "(", "$", "config", "[", "'virtualFields'", "]", ")", "?", "$", "config", "[", "'virtualFields'", "]", ":", "[", "]", ";", "// extract virtual fields, if any", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "typeaheadFields", "as", "$", "typeaheadField", ")", "{", "$", "fields", "=", "isset", "(", "$", "virtualFields", "[", "$", "typeaheadField", "]", ")", "?", "(", "array", ")", "$", "virtualFields", "[", "$", "typeaheadField", "]", ":", "[", "$", "typeaheadField", "]", ";", "$", "result", "=", "array_merge", "(", "$", "result", ",", "$", "fields", ")", ";", "}", "return", "implode", "(", "', or '", ",", "array_map", "(", "function", "(", "$", "value", ")", "{", "return", "Inflector", "::", "humanize", "(", "$", "value", ")", ";", "}", ",", "$", "result", ")", ")", ";", "}" ]
Generate input help string Can be used as a value for placeholder or title attributes. @param mixed[] $properties Input properties @return string
[ "Generate", "input", "help", "string" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L182-L206
train
QoboLtd/cakephp-csv-migrations
src/FieldHandlers/RelatedFieldTrait.php
RelatedFieldTrait._getInputIcon
protected function _getInputIcon(array $properties) : string { $config = (new ModuleConfig(ConfigType::MODULE(), $properties['controller']))->parseToArray(); if (! isset($config['table'])) { return Configure::read('CsvMigrations.default_icon'); } if (! isset($config['table']['icon'])) { return Configure::read('CsvMigrations.default_icon'); } return $config['table']['icon']; }
php
protected function _getInputIcon(array $properties) : string { $config = (new ModuleConfig(ConfigType::MODULE(), $properties['controller']))->parseToArray(); if (! isset($config['table'])) { return Configure::read('CsvMigrations.default_icon'); } if (! isset($config['table']['icon'])) { return Configure::read('CsvMigrations.default_icon'); } return $config['table']['icon']; }
[ "protected", "function", "_getInputIcon", "(", "array", "$", "properties", ")", ":", "string", "{", "$", "config", "=", "(", "new", "ModuleConfig", "(", "ConfigType", "::", "MODULE", "(", ")", ",", "$", "properties", "[", "'controller'", "]", ")", ")", "->", "parseToArray", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'table'", "]", ")", ")", "{", "return", "Configure", "::", "read", "(", "'CsvMigrations.default_icon'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "config", "[", "'table'", "]", "[", "'icon'", "]", ")", ")", "{", "return", "Configure", "::", "read", "(", "'CsvMigrations.default_icon'", ")", ";", "}", "return", "$", "config", "[", "'table'", "]", "[", "'icon'", "]", ";", "}" ]
Get input field associated icon @param mixed[] $properties Input properties @return string
[ "Get", "input", "field", "associated", "icon" ]
49300070cdd9b829670a3c40f747c535c8e539b3
https://github.com/QoboLtd/cakephp-csv-migrations/blob/49300070cdd9b829670a3c40f747c535c8e539b3/src/FieldHandlers/RelatedFieldTrait.php#L214-L227
train
keboola/syrup
src/Keboola/Syrup/Service/StorageApi/Limits.php
Limits.getParallelLimit
public static function getParallelLimit($tokenData) { if (!empty($tokenData['owner']['limits'][self::PARALLEL_LIMIT_NAME]['value'])) { return (int) $tokenData['owner']['limits'][self::PARALLEL_LIMIT_NAME]['value']; } return null; }
php
public static function getParallelLimit($tokenData) { if (!empty($tokenData['owner']['limits'][self::PARALLEL_LIMIT_NAME]['value'])) { return (int) $tokenData['owner']['limits'][self::PARALLEL_LIMIT_NAME]['value']; } return null; }
[ "public", "static", "function", "getParallelLimit", "(", "$", "tokenData", ")", "{", "if", "(", "!", "empty", "(", "$", "tokenData", "[", "'owner'", "]", "[", "'limits'", "]", "[", "self", "::", "PARALLEL_LIMIT_NAME", "]", "[", "'value'", "]", ")", ")", "{", "return", "(", "int", ")", "$", "tokenData", "[", "'owner'", "]", "[", "'limits'", "]", "[", "self", "::", "PARALLEL_LIMIT_NAME", "]", "[", "'value'", "]", ";", "}", "return", "null", ";", "}" ]
Parallel jobs limit of KBC project, null if unlimited @param $tokenData @return int|null
[ "Parallel", "jobs", "limit", "of", "KBC", "project", "null", "if", "unlimited" ]
83c0704dff3cd0c2e44e88076caadc010d32cd0e
https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Service/StorageApi/Limits.php#L45-L52
train
keboola/syrup
src/Keboola/Syrup/Controller/BaseController.php
BaseController.getPostJson
protected function getPostJson(Request $request, $assoc = true) { $return = array(); $body = $request->getContent(); if (!empty($body) && !is_null($body) && $body != 'null') { $return = json_decode($body, $assoc); if (json_last_error() != JSON_ERROR_NONE) { throw new UserException("Bad JSON format of request body: " . json_last_error_msg()); } } return $return; }
php
protected function getPostJson(Request $request, $assoc = true) { $return = array(); $body = $request->getContent(); if (!empty($body) && !is_null($body) && $body != 'null') { $return = json_decode($body, $assoc); if (json_last_error() != JSON_ERROR_NONE) { throw new UserException("Bad JSON format of request body: " . json_last_error_msg()); } } return $return; }
[ "protected", "function", "getPostJson", "(", "Request", "$", "request", ",", "$", "assoc", "=", "true", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "body", "=", "$", "request", "->", "getContent", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "body", ")", "&&", "!", "is_null", "(", "$", "body", ")", "&&", "$", "body", "!=", "'null'", ")", "{", "$", "return", "=", "json_decode", "(", "$", "body", ",", "$", "assoc", ")", ";", "if", "(", "json_last_error", "(", ")", "!=", "JSON_ERROR_NONE", ")", "{", "throw", "new", "UserException", "(", "\"Bad JSON format of request body: \"", ".", "json_last_error_msg", "(", ")", ")", ";", "}", "}", "return", "$", "return", ";", "}" ]
Extracts POST data in JSON from request @param Request $request @param bool $assoc @return array|mixed
[ "Extracts", "POST", "data", "in", "JSON", "from", "request" ]
83c0704dff3cd0c2e44e88076caadc010d32cd0e
https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Controller/BaseController.php#L69-L82
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.autoload
public function autoload( $class ) { $parent = explode( '\\', get_class( $this ) ); $class_array = explode( '\\', $class ); $intersect = array_intersect_assoc( $parent, $class_array ); $intersect_depth = count( $intersect ); $autoload_match_depth = static::$autoload_ns_match_depth; // Confirm $class is in same namespace as this autoloader. if ( $intersect_depth >= $autoload_match_depth ) { $file = $this->get_file_name_from_class( $class ); if ( 'classmap' === static::$autoload_type && is_array( $this->autoload_dir ) ) { foreach ( $this->autoload_dir as $dir ) { $this->load_file( $this->installed_dir . $dir . $file ); } } else { $this->load_file( $this->installed_dir . $file ); } } }
php
public function autoload( $class ) { $parent = explode( '\\', get_class( $this ) ); $class_array = explode( '\\', $class ); $intersect = array_intersect_assoc( $parent, $class_array ); $intersect_depth = count( $intersect ); $autoload_match_depth = static::$autoload_ns_match_depth; // Confirm $class is in same namespace as this autoloader. if ( $intersect_depth >= $autoload_match_depth ) { $file = $this->get_file_name_from_class( $class ); if ( 'classmap' === static::$autoload_type && is_array( $this->autoload_dir ) ) { foreach ( $this->autoload_dir as $dir ) { $this->load_file( $this->installed_dir . $dir . $file ); } } else { $this->load_file( $this->installed_dir . $file ); } } }
[ "public", "function", "autoload", "(", "$", "class", ")", "{", "$", "parent", "=", "explode", "(", "'\\\\'", ",", "get_class", "(", "$", "this", ")", ")", ";", "$", "class_array", "=", "explode", "(", "'\\\\'", ",", "$", "class", ")", ";", "$", "intersect", "=", "array_intersect_assoc", "(", "$", "parent", ",", "$", "class_array", ")", ";", "$", "intersect_depth", "=", "count", "(", "$", "intersect", ")", ";", "$", "autoload_match_depth", "=", "static", "::", "$", "autoload_ns_match_depth", ";", "// Confirm $class is in same namespace as this autoloader.", "if", "(", "$", "intersect_depth", ">=", "$", "autoload_match_depth", ")", "{", "$", "file", "=", "$", "this", "->", "get_file_name_from_class", "(", "$", "class", ")", ";", "if", "(", "'classmap'", "===", "static", "::", "$", "autoload_type", "&&", "is_array", "(", "$", "this", "->", "autoload_dir", ")", ")", "{", "foreach", "(", "$", "this", "->", "autoload_dir", "as", "$", "dir", ")", "{", "$", "this", "->", "load_file", "(", "$", "this", "->", "installed_dir", ".", "$", "dir", ".", "$", "file", ")", ";", "}", "}", "else", "{", "$", "this", "->", "load_file", "(", "$", "this", "->", "installed_dir", ".", "$", "file", ")", ";", "}", "}", "}" ]
Auto-load classes on demand to reduce memory consumption. Classes must have a namespace so as to resolve performance issues around auto-loading classes unrelated to current plugin. @param string $class The name of the class object.
[ "Auto", "-", "load", "classes", "on", "demand", "to", "reduce", "memory", "consumption", ".", "Classes", "must", "have", "a", "namespace", "so", "as", "to", "resolve", "performance", "issues", "around", "auto", "-", "loading", "classes", "unrelated", "to", "current", "plugin", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L225-L243
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.configure_defaults
protected function configure_defaults() { $this->modules = new \stdClass(); $this->modules->count = 0; $this->installed_dir = static::dirname( static::$current_file, 1 ); $this->plugin_basedir = static::dirname( static::$current_file, 2 ); $assumed_plugin_name = basename( $this->plugin_basedir ); $this->plugin_file = $this->plugin_basedir . '/' . $assumed_plugin_name . '.php'; $this->wp_plugin_slug = $assumed_plugin_name . '/' . $assumed_plugin_name . '.php'; if ( is_callable( 'is_plugin_active_for_network' ) ) { $this->is_network_active = is_plugin_active_for_network( $this->wp_plugin_slug ); } if ( file_exists( $this->plugin_file ) ) { $this->installed_url = plugins_url( '/', $this->plugin_file ); // Ensure get_plugin_data is available. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $this->plugin_data = get_plugin_data( $this->plugin_file, $markup = true, $translate = true ); if ( is_array( $this->plugin_data ) && isset( $this->plugin_data['Version'] ) ) { $this->version = $this->plugin_data['Version']; } } else { $this->installed_url = plugins_url( '/', static::$current_file ); } // Setup network url and fallback in case siteurl is not defined. if ( ! defined( 'WP_NETWORKURL' ) && is_multisite() ) { define( 'WP_NETWORKURL', network_site_url() ); } elseif ( ! defined( 'WP_NETWORKURL' ) ) { define( 'WP_NETWORKURL', get_site_url() ); } $this->network_url = WP_NETWORKURL; }
php
protected function configure_defaults() { $this->modules = new \stdClass(); $this->modules->count = 0; $this->installed_dir = static::dirname( static::$current_file, 1 ); $this->plugin_basedir = static::dirname( static::$current_file, 2 ); $assumed_plugin_name = basename( $this->plugin_basedir ); $this->plugin_file = $this->plugin_basedir . '/' . $assumed_plugin_name . '.php'; $this->wp_plugin_slug = $assumed_plugin_name . '/' . $assumed_plugin_name . '.php'; if ( is_callable( 'is_plugin_active_for_network' ) ) { $this->is_network_active = is_plugin_active_for_network( $this->wp_plugin_slug ); } if ( file_exists( $this->plugin_file ) ) { $this->installed_url = plugins_url( '/', $this->plugin_file ); // Ensure get_plugin_data is available. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $this->plugin_data = get_plugin_data( $this->plugin_file, $markup = true, $translate = true ); if ( is_array( $this->plugin_data ) && isset( $this->plugin_data['Version'] ) ) { $this->version = $this->plugin_data['Version']; } } else { $this->installed_url = plugins_url( '/', static::$current_file ); } // Setup network url and fallback in case siteurl is not defined. if ( ! defined( 'WP_NETWORKURL' ) && is_multisite() ) { define( 'WP_NETWORKURL', network_site_url() ); } elseif ( ! defined( 'WP_NETWORKURL' ) ) { define( 'WP_NETWORKURL', get_site_url() ); } $this->network_url = WP_NETWORKURL; }
[ "protected", "function", "configure_defaults", "(", ")", "{", "$", "this", "->", "modules", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "this", "->", "modules", "->", "count", "=", "0", ";", "$", "this", "->", "installed_dir", "=", "static", "::", "dirname", "(", "static", "::", "$", "current_file", ",", "1", ")", ";", "$", "this", "->", "plugin_basedir", "=", "static", "::", "dirname", "(", "static", "::", "$", "current_file", ",", "2", ")", ";", "$", "assumed_plugin_name", "=", "basename", "(", "$", "this", "->", "plugin_basedir", ")", ";", "$", "this", "->", "plugin_file", "=", "$", "this", "->", "plugin_basedir", ".", "'/'", ".", "$", "assumed_plugin_name", ".", "'.php'", ";", "$", "this", "->", "wp_plugin_slug", "=", "$", "assumed_plugin_name", ".", "'/'", ".", "$", "assumed_plugin_name", ".", "'.php'", ";", "if", "(", "is_callable", "(", "'is_plugin_active_for_network'", ")", ")", "{", "$", "this", "->", "is_network_active", "=", "is_plugin_active_for_network", "(", "$", "this", "->", "wp_plugin_slug", ")", ";", "}", "if", "(", "file_exists", "(", "$", "this", "->", "plugin_file", ")", ")", "{", "$", "this", "->", "installed_url", "=", "plugins_url", "(", "'/'", ",", "$", "this", "->", "plugin_file", ")", ";", "// Ensure get_plugin_data is available.", "require_once", "(", "ABSPATH", ".", "'wp-admin/includes/plugin.php'", ")", ";", "$", "this", "->", "plugin_data", "=", "get_plugin_data", "(", "$", "this", "->", "plugin_file", ",", "$", "markup", "=", "true", ",", "$", "translate", "=", "true", ")", ";", "if", "(", "is_array", "(", "$", "this", "->", "plugin_data", ")", "&&", "isset", "(", "$", "this", "->", "plugin_data", "[", "'Version'", "]", ")", ")", "{", "$", "this", "->", "version", "=", "$", "this", "->", "plugin_data", "[", "'Version'", "]", ";", "}", "}", "else", "{", "$", "this", "->", "installed_url", "=", "plugins_url", "(", "'/'", ",", "static", "::", "$", "current_file", ")", ";", "}", "// Setup network url and fallback in case siteurl is not defined.", "if", "(", "!", "defined", "(", "'WP_NETWORKURL'", ")", "&&", "is_multisite", "(", ")", ")", "{", "define", "(", "'WP_NETWORKURL'", ",", "network_site_url", "(", ")", ")", ";", "}", "elseif", "(", "!", "defined", "(", "'WP_NETWORKURL'", ")", ")", "{", "define", "(", "'WP_NETWORKURL'", ",", "get_site_url", "(", ")", ")", ";", "}", "$", "this", "->", "network_url", "=", "WP_NETWORKURL", ";", "}" ]
Setup plugins global params.
[ "Setup", "plugins", "global", "params", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L248-L279
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.filepath_to_classname
public static function filepath_to_classname( $file, $installed_dir, $namespace ) { /** * Convert path and filename into namespace and class */ $path_info = str_ireplace( $installed_dir, '', $file ); $path_info = pathinfo( $path_info ); $converted_dir = str_replace( '/', '\\', $path_info['dirname'] ); $converted_dir = ucwords( $converted_dir, '_\\' ); $filename_search = [ static::$filename_prefix, '-' ]; $filename_replace = [ '', '_' ]; $class = str_ireplace( $filename_search, $filename_replace, $path_info['filename'] ); $class_name = $namespace . $converted_dir . '\\' . ucwords( $class, '_' ); return $class_name; }
php
public static function filepath_to_classname( $file, $installed_dir, $namespace ) { /** * Convert path and filename into namespace and class */ $path_info = str_ireplace( $installed_dir, '', $file ); $path_info = pathinfo( $path_info ); $converted_dir = str_replace( '/', '\\', $path_info['dirname'] ); $converted_dir = ucwords( $converted_dir, '_\\' ); $filename_search = [ static::$filename_prefix, '-' ]; $filename_replace = [ '', '_' ]; $class = str_ireplace( $filename_search, $filename_replace, $path_info['filename'] ); $class_name = $namespace . $converted_dir . '\\' . ucwords( $class, '_' ); return $class_name; }
[ "public", "static", "function", "filepath_to_classname", "(", "$", "file", ",", "$", "installed_dir", ",", "$", "namespace", ")", "{", "/**\n\t\t * Convert path and filename into namespace and class\n\t\t */", "$", "path_info", "=", "str_ireplace", "(", "$", "installed_dir", ",", "''", ",", "$", "file", ")", ";", "$", "path_info", "=", "pathinfo", "(", "$", "path_info", ")", ";", "$", "converted_dir", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "path_info", "[", "'dirname'", "]", ")", ";", "$", "converted_dir", "=", "ucwords", "(", "$", "converted_dir", ",", "'_\\\\'", ")", ";", "$", "filename_search", "=", "[", "static", "::", "$", "filename_prefix", ",", "'-'", "]", ";", "$", "filename_replace", "=", "[", "''", ",", "'_'", "]", ";", "$", "class", "=", "str_ireplace", "(", "$", "filename_search", ",", "$", "filename_replace", ",", "$", "path_info", "[", "'filename'", "]", ")", ";", "$", "class_name", "=", "$", "namespace", ".", "$", "converted_dir", ".", "'\\\\'", ".", "ucwords", "(", "$", "class", ",", "'_'", ")", ";", "return", "$", "class_name", ";", "}" ]
Utility function to get class name from filename if you follow this abstract plugin's naming standards @param string $file Absolute path to file. @param string $installed_dir Absolute path to plugin folder. @param string $namespace Namespace of calling class, if any. @return string $class_name Name of Class to load based on file path.
[ "Utility", "function", "to", "get", "class", "name", "from", "filename", "if", "you", "follow", "this", "abstract", "plugin", "s", "naming", "standards" ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L321-L335
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.get
public static function get() { global $wp_plugins; $plugin_name = strtolower( get_called_class() ); if ( isset( $wp_plugins ) && isset( $wp_plugins->$plugin_name ) ) { return $wp_plugins->$plugin_name; } else { return false; } }
php
public static function get() { global $wp_plugins; $plugin_name = strtolower( get_called_class() ); if ( isset( $wp_plugins ) && isset( $wp_plugins->$plugin_name ) ) { return $wp_plugins->$plugin_name; } else { return false; } }
[ "public", "static", "function", "get", "(", ")", "{", "global", "$", "wp_plugins", ";", "$", "plugin_name", "=", "strtolower", "(", "get_called_class", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "wp_plugins", ")", "&&", "isset", "(", "$", "wp_plugins", "->", "$", "plugin_name", ")", ")", "{", "return", "$", "wp_plugins", "->", "$", "plugin_name", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Used to get the instance of the class as an unforced singleton model @return bool|Abstract_Plugin|mixed $instance
[ "Used", "to", "get", "the", "instance", "of", "the", "class", "as", "an", "unforced", "singleton", "model" ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L342-L350
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.get_file_name_from_class
private function get_file_name_from_class( $class ) { if ( 'classmap' === static::$autoload_type ) { $filtered_class_name = explode( '\\', $class ); $class_filename = end( $filtered_class_name ); $class_filename = str_replace( '_', '-', $class_filename ); return static::$filename_prefix . $class_filename . '.php'; } else { return $this->psr4_get_file_name_from_class( $class ); } }
php
private function get_file_name_from_class( $class ) { if ( 'classmap' === static::$autoload_type ) { $filtered_class_name = explode( '\\', $class ); $class_filename = end( $filtered_class_name ); $class_filename = str_replace( '_', '-', $class_filename ); return static::$filename_prefix . $class_filename . '.php'; } else { return $this->psr4_get_file_name_from_class( $class ); } }
[ "private", "function", "get_file_name_from_class", "(", "$", "class", ")", "{", "if", "(", "'classmap'", "===", "static", "::", "$", "autoload_type", ")", "{", "$", "filtered_class_name", "=", "explode", "(", "'\\\\'", ",", "$", "class", ")", ";", "$", "class_filename", "=", "end", "(", "$", "filtered_class_name", ")", ";", "$", "class_filename", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "class_filename", ")", ";", "return", "static", "::", "$", "filename_prefix", ".", "$", "class_filename", ".", "'.php'", ";", "}", "else", "{", "return", "$", "this", "->", "psr4_get_file_name_from_class", "(", "$", "class", ")", ";", "}", "}" ]
Take a class name and turn it into a file name. @param string $class Raw class name. @return string
[ "Take", "a", "class", "name", "and", "turn", "it", "into", "a", "file", "name", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L359-L370
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.load_file
private function load_file( $path ) { if ( $path && is_readable( $path ) ) { include_once( $path ); $success = true; } return ! ( empty( $success ) ) ? true : false; }
php
private function load_file( $path ) { if ( $path && is_readable( $path ) ) { include_once( $path ); $success = true; } return ! ( empty( $success ) ) ? true : false; }
[ "private", "function", "load_file", "(", "$", "path", ")", "{", "if", "(", "$", "path", "&&", "is_readable", "(", "$", "path", ")", ")", "{", "include_once", "(", "$", "path", ")", ";", "$", "success", "=", "true", ";", "}", "return", "!", "(", "empty", "(", "$", "success", ")", ")", "?", "true", ":", "false", ";", "}" ]
Include a class file. @param string $path Server path to file for inclusion. @return bool successful or not
[ "Include", "a", "class", "file", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L399-L406
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.psr4_get_file_name_from_class
private function psr4_get_file_name_from_class( $class ) { $class = strtolower( $class ); if ( stristr( $class, '\\' ) ) { // If the first item is == the collection name, trim it off. $class = str_ireplace( static::$autoload_class_prefix, '', $class ); // Maybe fix formatting underscores to dashes and double to single slashes. $class = str_replace( [ '_', '\\' ], [ '-', '/' ], $class ); $class = explode( '/', $class ); $file_name = &$class[ count( $class ) - 1 ]; $file_name = static::$filename_prefix . $file_name . '.php'; $file_path = join( DIRECTORY_SEPARATOR, $class ); return $file_path; } else { return static::$filename_prefix . str_replace( '_', '-', $class ) . '.php'; } }
php
private function psr4_get_file_name_from_class( $class ) { $class = strtolower( $class ); if ( stristr( $class, '\\' ) ) { // If the first item is == the collection name, trim it off. $class = str_ireplace( static::$autoload_class_prefix, '', $class ); // Maybe fix formatting underscores to dashes and double to single slashes. $class = str_replace( [ '_', '\\' ], [ '-', '/' ], $class ); $class = explode( '/', $class ); $file_name = &$class[ count( $class ) - 1 ]; $file_name = static::$filename_prefix . $file_name . '.php'; $file_path = join( DIRECTORY_SEPARATOR, $class ); return $file_path; } else { return static::$filename_prefix . str_replace( '_', '-', $class ) . '.php'; } }
[ "private", "function", "psr4_get_file_name_from_class", "(", "$", "class", ")", "{", "$", "class", "=", "strtolower", "(", "$", "class", ")", ";", "if", "(", "stristr", "(", "$", "class", ",", "'\\\\'", ")", ")", "{", "// If the first item is == the collection name, trim it off.", "$", "class", "=", "str_ireplace", "(", "static", "::", "$", "autoload_class_prefix", ",", "''", ",", "$", "class", ")", ";", "// Maybe fix formatting underscores to dashes and double to single slashes.", "$", "class", "=", "str_replace", "(", "[", "'_'", ",", "'\\\\'", "]", ",", "[", "'-'", ",", "'/'", "]", ",", "$", "class", ")", ";", "$", "class", "=", "explode", "(", "'/'", ",", "$", "class", ")", ";", "$", "file_name", "=", "&", "$", "class", "[", "count", "(", "$", "class", ")", "-", "1", "]", ";", "$", "file_name", "=", "static", "::", "$", "filename_prefix", ".", "$", "file_name", ".", "'.php'", ";", "$", "file_path", "=", "join", "(", "DIRECTORY_SEPARATOR", ",", "$", "class", ")", ";", "return", "$", "file_path", ";", "}", "else", "{", "return", "static", "::", "$", "filename_prefix", ".", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "class", ")", ".", "'.php'", ";", "}", "}" ]
Take a namespaced class name and turn it into a file name. @param string $class The name of the class to load. @return string
[ "Take", "a", "namespaced", "class", "name", "and", "turn", "it", "into", "a", "file", "name", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L415-L433
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.run
public static function run( $file ) { // Logic required for WordPress VIP plugins to load during themes function file initialization. if ( did_action( 'plugins_loaded' ) ) { add_action( 'init', [ get_called_class(), 'load' ], 1 ); } else { add_action( 'plugins_loaded', [ get_called_class(), 'load' ] ); } // Installation and un-installation hooks. register_activation_hook( $file, [ get_called_class(), 'activate' ] ); register_deactivation_hook( $file, [ get_called_class(), 'deactivate' ] ); register_uninstall_hook( $file, [ get_called_class(), 'uninstall' ] ); }
php
public static function run( $file ) { // Logic required for WordPress VIP plugins to load during themes function file initialization. if ( did_action( 'plugins_loaded' ) ) { add_action( 'init', [ get_called_class(), 'load' ], 1 ); } else { add_action( 'plugins_loaded', [ get_called_class(), 'load' ] ); } // Installation and un-installation hooks. register_activation_hook( $file, [ get_called_class(), 'activate' ] ); register_deactivation_hook( $file, [ get_called_class(), 'deactivate' ] ); register_uninstall_hook( $file, [ get_called_class(), 'uninstall' ] ); }
[ "public", "static", "function", "run", "(", "$", "file", ")", "{", "// Logic required for WordPress VIP plugins to load during themes function file initialization.", "if", "(", "did_action", "(", "'plugins_loaded'", ")", ")", "{", "add_action", "(", "'init'", ",", "[", "get_called_class", "(", ")", ",", "'load'", "]", ",", "1", ")", ";", "}", "else", "{", "add_action", "(", "'plugins_loaded'", ",", "[", "get_called_class", "(", ")", ",", "'load'", "]", ")", ";", "}", "// Installation and un-installation hooks.", "register_activation_hook", "(", "$", "file", ",", "[", "get_called_class", "(", ")", ",", "'activate'", "]", ")", ";", "register_deactivation_hook", "(", "$", "file", ",", "[", "get_called_class", "(", ")", ",", "'deactivate'", "]", ")", ";", "register_uninstall_hook", "(", "$", "file", ",", "[", "get_called_class", "(", ")", ",", "'uninstall'", "]", ")", ";", "}" ]
Setup special hooks that don't run after plugins_loaded action @param string $file File location on the server, passed in and used to build other paths.
[ "Setup", "special", "hooks", "that", "don", "t", "run", "after", "plugins_loaded", "action" ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L440-L451
train
WordPress-Phoenix/abstract-plugin-base
src/abstract-plugin.php
Abstract_Plugin.set
private static function set( $instance = false ) { // Make sure the plugin hasn't already been instantiated before. global $wp_plugins; if ( ! isset( $wp_plugins ) ) { $wp_plugins = new \stdClass(); } // Get the fully qualified parent class name and instantiate an instance of it. $called_class = get_called_class(); $plugin_name = strtolower( $called_class ); if ( empty( $instance ) || ! is_a( $instance, $called_class ) ) { $wp_plugins->$plugin_name = new $called_class(); } else { $wp_plugins->$plugin_name = $instance; } }
php
private static function set( $instance = false ) { // Make sure the plugin hasn't already been instantiated before. global $wp_plugins; if ( ! isset( $wp_plugins ) ) { $wp_plugins = new \stdClass(); } // Get the fully qualified parent class name and instantiate an instance of it. $called_class = get_called_class(); $plugin_name = strtolower( $called_class ); if ( empty( $instance ) || ! is_a( $instance, $called_class ) ) { $wp_plugins->$plugin_name = new $called_class(); } else { $wp_plugins->$plugin_name = $instance; } }
[ "private", "static", "function", "set", "(", "$", "instance", "=", "false", ")", "{", "// Make sure the plugin hasn't already been instantiated before.", "global", "$", "wp_plugins", ";", "if", "(", "!", "isset", "(", "$", "wp_plugins", ")", ")", "{", "$", "wp_plugins", "=", "new", "\\", "stdClass", "(", ")", ";", "}", "// Get the fully qualified parent class name and instantiate an instance of it.", "$", "called_class", "=", "get_called_class", "(", ")", ";", "$", "plugin_name", "=", "strtolower", "(", "$", "called_class", ")", ";", "if", "(", "empty", "(", "$", "instance", ")", "||", "!", "is_a", "(", "$", "instance", ",", "$", "called_class", ")", ")", "{", "$", "wp_plugins", "->", "$", "plugin_name", "=", "new", "$", "called_class", "(", ")", ";", "}", "else", "{", "$", "wp_plugins", "->", "$", "plugin_name", "=", "$", "instance", ";", "}", "}" ]
Used to setup the instance of the class and place in wp_plugins collection. @param bool|Abstract_Plugin|mixed $instance Contains object representing the plugin.
[ "Used", "to", "setup", "the", "instance", "of", "the", "class", "and", "place", "in", "wp_plugins", "collection", "." ]
8c08aa240836e310ce014d7b29a53d922d0c31fe
https://github.com/WordPress-Phoenix/abstract-plugin-base/blob/8c08aa240836e310ce014d7b29a53d922d0c31fe/src/abstract-plugin.php#L465-L479
train
keboola/syrup
src/Keboola/Syrup/Elasticsearch/ComponentIndex.php
ComponentIndex.getMapping
public function getMapping() { $params['index'] = $this->getLastIndexName(); $params['type'] = 'jobs'; return $this->client->indices()->getMapping($params); }
php
public function getMapping() { $params['index'] = $this->getLastIndexName(); $params['type'] = 'jobs'; return $this->client->indices()->getMapping($params); }
[ "public", "function", "getMapping", "(", ")", "{", "$", "params", "[", "'index'", "]", "=", "$", "this", "->", "getLastIndexName", "(", ")", ";", "$", "params", "[", "'type'", "]", "=", "'jobs'", ";", "return", "$", "this", "->", "client", "->", "indices", "(", ")", "->", "getMapping", "(", "$", "params", ")", ";", "}" ]
Return mapping from latest index @return array mapping resource
[ "Return", "mapping", "from", "latest", "index" ]
83c0704dff3cd0c2e44e88076caadc010d32cd0e
https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Elasticsearch/ComponentIndex.php#L60-L66
train