repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
ProjectDescriptorBuilder.filterAndValidateEachDescriptor
private function filterAndValidateEachDescriptor($descriptor) { $descriptors = new Collection(); foreach ($descriptor as $key => $item) { $item = $this->filterAndValidateDescriptor($item); if (!$item) { continue; } $descriptors[$key] = $item; } return $descriptors; }
php
private function filterAndValidateEachDescriptor($descriptor) { $descriptors = new Collection(); foreach ($descriptor as $key => $item) { $item = $this->filterAndValidateDescriptor($item); if (!$item) { continue; } $descriptors[$key] = $item; } return $descriptors; }
[ "private", "function", "filterAndValidateEachDescriptor", "(", "$", "descriptor", ")", "{", "$", "descriptors", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "descriptor", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "item", "=", "$", "this", "->", "filterAndValidateDescriptor", "(", "$", "item", ")", ";", "if", "(", "!", "$", "item", ")", "{", "continue", ";", "}", "$", "descriptors", "[", "$", "key", "]", "=", "$", "item", ";", "}", "return", "$", "descriptors", ";", "}" ]
Filters each descriptor, validates them, stores the validation results and returns a collection of transmuted objects. @param DescriptorAbstract[] $descriptor @return Collection
[ "Filters", "each", "descriptor", "validates", "them", "stores", "the", "validation", "results", "and", "returns", "a", "collection", "of", "transmuted", "objects", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php#L213-L226
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
ProjectDescriptorBuilder.filterAndValidateDescriptor
protected function filterAndValidateDescriptor($descriptor) { if (!$descriptor instanceof Filterable) { return $descriptor; } // filter the descriptor; this may result in the descriptor being removed! $descriptor = $this->filter($descriptor); if (!$descriptor) { return null; } // Validate the descriptor and store any errors $descriptor->setErrors($this->validate($descriptor)); return $descriptor; }
php
protected function filterAndValidateDescriptor($descriptor) { if (!$descriptor instanceof Filterable) { return $descriptor; } // filter the descriptor; this may result in the descriptor being removed! $descriptor = $this->filter($descriptor); if (!$descriptor) { return null; } // Validate the descriptor and store any errors $descriptor->setErrors($this->validate($descriptor)); return $descriptor; }
[ "protected", "function", "filterAndValidateDescriptor", "(", "$", "descriptor", ")", "{", "if", "(", "!", "$", "descriptor", "instanceof", "Filterable", ")", "{", "return", "$", "descriptor", ";", "}", "// filter the descriptor; this may result in the descriptor being removed!", "$", "descriptor", "=", "$", "this", "->", "filter", "(", "$", "descriptor", ")", ";", "if", "(", "!", "$", "descriptor", ")", "{", "return", "null", ";", "}", "// Validate the descriptor and store any errors", "$", "descriptor", "->", "setErrors", "(", "$", "this", "->", "validate", "(", "$", "descriptor", ")", ")", ";", "return", "$", "descriptor", ";", "}" ]
Filters a descriptor, validates it, stores the validation results and returns the transmuted object or null if it is supposed to be removed. @param DescriptorAbstract $descriptor @return DescriptorAbstract|null
[ "Filters", "a", "descriptor", "validates", "it", "stores", "the", "validation", "results", "and", "returns", "the", "transmuted", "object", "or", "null", "if", "it", "is", "supposed", "to", "be", "removed", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php#L236-L252
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
ProjectDescriptorBuilder.mapCodeToSeverity
protected function mapCodeToSeverity($code) { if (is_int($code) && $this->translator->translate('VAL:ERRLVL-'.$code)) { $severity = $this->translator->translate('VAL:ERRLVL-'.$code); } else { $severity = LogLevel::ERROR; } return $severity; }
php
protected function mapCodeToSeverity($code) { if (is_int($code) && $this->translator->translate('VAL:ERRLVL-'.$code)) { $severity = $this->translator->translate('VAL:ERRLVL-'.$code); } else { $severity = LogLevel::ERROR; } return $severity; }
[ "protected", "function", "mapCodeToSeverity", "(", "$", "code", ")", "{", "if", "(", "is_int", "(", "$", "code", ")", "&&", "$", "this", "->", "translator", "->", "translate", "(", "'VAL:ERRLVL-'", ".", "$", "code", ")", ")", "{", "$", "severity", "=", "$", "this", "->", "translator", "->", "translate", "(", "'VAL:ERRLVL-'", ".", "$", "code", ")", ";", "}", "else", "{", "$", "severity", "=", "LogLevel", "::", "ERROR", ";", "}", "return", "$", "severity", ";", "}" ]
Map error code to severity. @param int $code @return string
[ "Map", "error", "code", "to", "severity", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php#L261-L270
ComposePress/core
src/Abstracts/Plugin.php
Plugin.get_plugin_info
public function get_plugin_info( $field = null ) { $info = get_plugin_data( $this->plugin_file ); if ( null !== $field && isset( $info[ $field ] ) ) { return $info[ $field ]; } return $info; }
php
public function get_plugin_info( $field = null ) { $info = get_plugin_data( $this->plugin_file ); if ( null !== $field && isset( $info[ $field ] ) ) { return $info[ $field ]; } return $info; }
[ "public", "function", "get_plugin_info", "(", "$", "field", "=", "null", ")", "{", "$", "info", "=", "get_plugin_data", "(", "$", "this", "->", "plugin_file", ")", ";", "if", "(", "null", "!==", "$", "field", "&&", "isset", "(", "$", "info", "[", "$", "field", "]", ")", ")", "{", "return", "$", "info", "[", "$", "field", "]", ";", "}", "return", "$", "info", ";", "}" ]
@param string $field @return string|array
[ "@param", "string", "$field" ]
train
https://github.com/ComposePress/core/blob/f403f81d06a1e43017cb23c19c980fe3ef3bb6f7/src/Abstracts/Plugin.php#L182-L189
ComposePress/core
src/Abstracts/Plugin.php
Plugin.get_asset_url
public function get_asset_url( $file ) { if ( $this->get_wp_filesystem()->is_file( $file ) ) { $file = str_replace( plugin_dir_path( $this->plugin_file ), '', $file ); } return plugins_url( $file, $this->plugin_file ); }
php
public function get_asset_url( $file ) { if ( $this->get_wp_filesystem()->is_file( $file ) ) { $file = str_replace( plugin_dir_path( $this->plugin_file ), '', $file ); } return plugins_url( $file, $this->plugin_file ); }
[ "public", "function", "get_asset_url", "(", "$", "file", ")", "{", "if", "(", "$", "this", "->", "get_wp_filesystem", "(", ")", "->", "is_file", "(", "$", "file", ")", ")", "{", "$", "file", "=", "str_replace", "(", "plugin_dir_path", "(", "$", "this", "->", "plugin_file", ")", ",", "''", ",", "$", "file", ")", ";", "}", "return", "plugins_url", "(", "$", "file", ",", "$", "this", "->", "plugin_file", ")", ";", "}" ]
@param $file @return string
[ "@param", "$file" ]
train
https://github.com/ComposePress/core/blob/f403f81d06a1e43017cb23c19c980fe3ef3bb6f7/src/Abstracts/Plugin.php#L203-L209
DataDo/data
src/main/php/DataDo/Data/DefaultNamingConvention.php
DefaultNamingConvention.propertyToColumnName
public function propertyToColumnName($property) { $name = $property->getName(); $columnName = $this->removeCamelCasing($name); return $columnName; }
php
public function propertyToColumnName($property) { $name = $property->getName(); $columnName = $this->removeCamelCasing($name); return $columnName; }
[ "public", "function", "propertyToColumnName", "(", "$", "property", ")", "{", "$", "name", "=", "$", "property", "->", "getName", "(", ")", ";", "$", "columnName", "=", "$", "this", "->", "removeCamelCasing", "(", "$", "name", ")", ";", "return", "$", "columnName", ";", "}" ]
{$@inheritdoc}
[ "{", "$" ]
train
https://github.com/DataDo/data/blob/555b02a27755032fcd53e165b0674e81a68067c0/src/main/php/DataDo/Data/DefaultNamingConvention.php#L25-L30
ekuiter/feature-php
FeaturePhp/Model/ConfigurationRenderer.php
ConfigurationRenderer._render
public function _render($textOnly) { $str = ""; if ($textOnly) $str .= "\nModel Analysis\n==============\n"; else $str .= "<h2>Model Analysis</h2>"; $str .= $this->analyzeModel($this->configuration->getModel(), $textOnly); if ($textOnly) $str .= "\nConfiguration Analysis\n======================\n"; else $str .= "</td><td valign='top'><h2>Configuration Analysis</h2>"; $str .= $this->analyzeConfiguration($this->configuration, $textOnly); return $str; }
php
public function _render($textOnly) { $str = ""; if ($textOnly) $str .= "\nModel Analysis\n==============\n"; else $str .= "<h2>Model Analysis</h2>"; $str .= $this->analyzeModel($this->configuration->getModel(), $textOnly); if ($textOnly) $str .= "\nConfiguration Analysis\n======================\n"; else $str .= "</td><td valign='top'><h2>Configuration Analysis</h2>"; $str .= $this->analyzeConfiguration($this->configuration, $textOnly); return $str; }
[ "public", "function", "_render", "(", "$", "textOnly", ")", "{", "$", "str", "=", "\"\"", ";", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"\\nModel Analysis\\n==============\\n\"", ";", "else", "$", "str", ".=", "\"<h2>Model Analysis</h2>\"", ";", "$", "str", ".=", "$", "this", "->", "analyzeModel", "(", "$", "this", "->", "configuration", "->", "getModel", "(", ")", ",", "$", "textOnly", ")", ";", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"\\nConfiguration Analysis\\n======================\\n\"", ";", "else", "$", "str", ".=", "\"</td><td valign='top'><h2>Configuration Analysis</h2>\"", ";", "$", "str", ".=", "$", "this", "->", "analyzeConfiguration", "(", "$", "this", "->", "configuration", ",", "$", "textOnly", ")", ";", "return", "$", "str", ";", "}" ]
Returns the model and configuration analysis. @param bool $textOnly whether to render text or HTML @return string
[ "Returns", "the", "model", "and", "configuration", "analysis", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/ConfigurationRenderer.php#L43-L56
ekuiter/feature-php
FeaturePhp/Model/ConfigurationRenderer.php
ConfigurationRenderer.analyzeModel
private function analyzeModel($model, $textOnly) { $featureNum = count($model->getFeatures()); $rootFeatureName = $model->getRootFeature()->getName(); $constraintNum = count($model->getConstraintSolver()->getConstraints()); $ruleNum = count($model->getXmlModel()->getRules()); $str = ""; $maxLen = fphp\Helper\_String::getMaxLength($model->getFeatures(), "getName"); if ($textOnly) $str .= "The given feature model with the root feature " . "$this->accentColor$rootFeatureName$this->defaultColor has the following $featureNum features:\n\n"; else { $str .= "<div>"; $str .= "<p>The given feature model with the root feature <span class='feature'>$rootFeatureName</span> " . "has the following $featureNum features:</p>"; $str .= "<ul>"; } foreach ($model->getFeatures() as $feature) { $description = $feature->getDescription(); if ($this->productLine) $class = $this->productLine->getArtifact($feature)->isGenerated() ? "" : "unimplemented"; else $class = ""; if ($textOnly) { $color = $class === "unimplemented" ? "" : $this->accentColor; $str .= sprintf("%s%-{$maxLen}s$this->defaultColor %s\n", $color, $feature->getName(), fphp\Helper\_String::truncate($description)); } else $str .= "<li><span class='feature $class'>" . $feature->getName() . ($description ? "</span><br /><span style='font-size: 0.8em'>" . str_replace("\n", "<br />", $description) . "</span>" : "") . "</li>"; } if ($textOnly) $str .= "\nThere are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).\n"; else { $str .= "</ul>"; $str .= "<p>There are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).</p>"; $str .= "</div>"; } return $str; }
php
private function analyzeModel($model, $textOnly) { $featureNum = count($model->getFeatures()); $rootFeatureName = $model->getRootFeature()->getName(); $constraintNum = count($model->getConstraintSolver()->getConstraints()); $ruleNum = count($model->getXmlModel()->getRules()); $str = ""; $maxLen = fphp\Helper\_String::getMaxLength($model->getFeatures(), "getName"); if ($textOnly) $str .= "The given feature model with the root feature " . "$this->accentColor$rootFeatureName$this->defaultColor has the following $featureNum features:\n\n"; else { $str .= "<div>"; $str .= "<p>The given feature model with the root feature <span class='feature'>$rootFeatureName</span> " . "has the following $featureNum features:</p>"; $str .= "<ul>"; } foreach ($model->getFeatures() as $feature) { $description = $feature->getDescription(); if ($this->productLine) $class = $this->productLine->getArtifact($feature)->isGenerated() ? "" : "unimplemented"; else $class = ""; if ($textOnly) { $color = $class === "unimplemented" ? "" : $this->accentColor; $str .= sprintf("%s%-{$maxLen}s$this->defaultColor %s\n", $color, $feature->getName(), fphp\Helper\_String::truncate($description)); } else $str .= "<li><span class='feature $class'>" . $feature->getName() . ($description ? "</span><br /><span style='font-size: 0.8em'>" . str_replace("\n", "<br />", $description) . "</span>" : "") . "</li>"; } if ($textOnly) $str .= "\nThere are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).\n"; else { $str .= "</ul>"; $str .= "<p>There are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).</p>"; $str .= "</div>"; } return $str; }
[ "private", "function", "analyzeModel", "(", "$", "model", ",", "$", "textOnly", ")", "{", "$", "featureNum", "=", "count", "(", "$", "model", "->", "getFeatures", "(", ")", ")", ";", "$", "rootFeatureName", "=", "$", "model", "->", "getRootFeature", "(", ")", "->", "getName", "(", ")", ";", "$", "constraintNum", "=", "count", "(", "$", "model", "->", "getConstraintSolver", "(", ")", "->", "getConstraints", "(", ")", ")", ";", "$", "ruleNum", "=", "count", "(", "$", "model", "->", "getXmlModel", "(", ")", "->", "getRules", "(", ")", ")", ";", "$", "str", "=", "\"\"", ";", "$", "maxLen", "=", "fphp", "\\", "Helper", "\\", "_String", "::", "getMaxLength", "(", "$", "model", "->", "getFeatures", "(", ")", ",", "\"getName\"", ")", ";", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"The given feature model with the root feature \"", ".", "\"$this->accentColor$rootFeatureName$this->defaultColor has the following $featureNum features:\\n\\n\"", ";", "else", "{", "$", "str", ".=", "\"<div>\"", ";", "$", "str", ".=", "\"<p>The given feature model with the root feature <span class='feature'>$rootFeatureName</span> \"", ".", "\"has the following $featureNum features:</p>\"", ";", "$", "str", ".=", "\"<ul>\"", ";", "}", "foreach", "(", "$", "model", "->", "getFeatures", "(", ")", "as", "$", "feature", ")", "{", "$", "description", "=", "$", "feature", "->", "getDescription", "(", ")", ";", "if", "(", "$", "this", "->", "productLine", ")", "$", "class", "=", "$", "this", "->", "productLine", "->", "getArtifact", "(", "$", "feature", ")", "->", "isGenerated", "(", ")", "?", "\"\"", ":", "\"unimplemented\"", ";", "else", "$", "class", "=", "\"\"", ";", "if", "(", "$", "textOnly", ")", "{", "$", "color", "=", "$", "class", "===", "\"unimplemented\"", "?", "\"\"", ":", "$", "this", "->", "accentColor", ";", "$", "str", ".=", "sprintf", "(", "\"%s%-{$maxLen}s$this->defaultColor %s\\n\"", ",", "$", "color", ",", "$", "feature", "->", "getName", "(", ")", ",", "fphp", "\\", "Helper", "\\", "_String", "::", "truncate", "(", "$", "description", ")", ")", ";", "}", "else", "$", "str", ".=", "\"<li><span class='feature $class'>\"", ".", "$", "feature", "->", "getName", "(", ")", ".", "(", "$", "description", "?", "\"</span><br /><span style='font-size: 0.8em'>\"", ".", "str_replace", "(", "\"\\n\"", ",", "\"<br />\"", ",", "$", "description", ")", ".", "\"</span>\"", ":", "\"\"", ")", ".", "\"</li>\"", ";", "}", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"\\nThere are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).\\n\"", ";", "else", "{", "$", "str", ".=", "\"</ul>\"", ";", "$", "str", ".=", "\"<p>There are $constraintNum feature constraints ($ruleNum of them cross-tree constraints).</p>\"", ";", "$", "str", ".=", "\"</div>\"", ";", "}", "return", "$", "str", ";", "}" ]
Returns a model analysis. @param Model $model @param bool $textOnly whether to render text or HTML @return string
[ "Returns", "a", "model", "analysis", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/ConfigurationRenderer.php#L64-L110
ekuiter/feature-php
FeaturePhp/Model/ConfigurationRenderer.php
ConfigurationRenderer.analyzeConfiguration
private function analyzeConfiguration($configuration, $textOnly) { $validity = $configuration->isValid() ? "valid" : "invalid"; $str = ""; $selectedColor = "\033[1;32m"; $deselectedColor = "\033[1;31m"; if ($textOnly) $str .= "The given configuration has the following feature selection:\n\n"; else { $str .= "<div style='font-family: monospace'>"; $str .= "<p>The given configuration has the following feature selection:</p>"; $str .= "<ul>"; } foreach ($configuration->getModel()->getFeatures() as $feature) { $isSelected = Feature::has($configuration->getSelectedFeatures(), $feature); $mark = $isSelected ? "x" : "&nbsp;"; $class = $isSelected ? "selected" : "deselected"; if ($textOnly) $str .= "[" . ($isSelected ? "x" : " ") . "] " . ($isSelected ? $selectedColor : $deselectedColor) . $feature->getName() . "$this->defaultColor\n"; else $str .= "<li>[$mark] <span class='feature $class'>" . $feature->getName() . "</span></li>"; } if ($textOnly) $str .= "\nThis configuration is $validity.\n"; else { $str .= "</ul>"; $str .= "<p>This configuration is $validity.</p>"; $str .= "</div>"; } return $str; }
php
private function analyzeConfiguration($configuration, $textOnly) { $validity = $configuration->isValid() ? "valid" : "invalid"; $str = ""; $selectedColor = "\033[1;32m"; $deselectedColor = "\033[1;31m"; if ($textOnly) $str .= "The given configuration has the following feature selection:\n\n"; else { $str .= "<div style='font-family: monospace'>"; $str .= "<p>The given configuration has the following feature selection:</p>"; $str .= "<ul>"; } foreach ($configuration->getModel()->getFeatures() as $feature) { $isSelected = Feature::has($configuration->getSelectedFeatures(), $feature); $mark = $isSelected ? "x" : "&nbsp;"; $class = $isSelected ? "selected" : "deselected"; if ($textOnly) $str .= "[" . ($isSelected ? "x" : " ") . "] " . ($isSelected ? $selectedColor : $deselectedColor) . $feature->getName() . "$this->defaultColor\n"; else $str .= "<li>[$mark] <span class='feature $class'>" . $feature->getName() . "</span></li>"; } if ($textOnly) $str .= "\nThis configuration is $validity.\n"; else { $str .= "</ul>"; $str .= "<p>This configuration is $validity.</p>"; $str .= "</div>"; } return $str; }
[ "private", "function", "analyzeConfiguration", "(", "$", "configuration", ",", "$", "textOnly", ")", "{", "$", "validity", "=", "$", "configuration", "->", "isValid", "(", ")", "?", "\"valid\"", ":", "\"invalid\"", ";", "$", "str", "=", "\"\"", ";", "$", "selectedColor", "=", "\"\\033[1;32m\"", ";", "$", "deselectedColor", "=", "\"\\033[1;31m\"", ";", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"The given configuration has the following feature selection:\\n\\n\"", ";", "else", "{", "$", "str", ".=", "\"<div style='font-family: monospace'>\"", ";", "$", "str", ".=", "\"<p>The given configuration has the following feature selection:</p>\"", ";", "$", "str", ".=", "\"<ul>\"", ";", "}", "foreach", "(", "$", "configuration", "->", "getModel", "(", ")", "->", "getFeatures", "(", ")", "as", "$", "feature", ")", "{", "$", "isSelected", "=", "Feature", "::", "has", "(", "$", "configuration", "->", "getSelectedFeatures", "(", ")", ",", "$", "feature", ")", ";", "$", "mark", "=", "$", "isSelected", "?", "\"x\"", ":", "\"&nbsp;\"", ";", "$", "class", "=", "$", "isSelected", "?", "\"selected\"", ":", "\"deselected\"", ";", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"[\"", ".", "(", "$", "isSelected", "?", "\"x\"", ":", "\" \"", ")", ".", "\"] \"", ".", "(", "$", "isSelected", "?", "$", "selectedColor", ":", "$", "deselectedColor", ")", ".", "$", "feature", "->", "getName", "(", ")", ".", "\"$this->defaultColor\\n\"", ";", "else", "$", "str", ".=", "\"<li>[$mark] <span class='feature $class'>\"", ".", "$", "feature", "->", "getName", "(", ")", ".", "\"</span></li>\"", ";", "}", "if", "(", "$", "textOnly", ")", "$", "str", ".=", "\"\\nThis configuration is $validity.\\n\"", ";", "else", "{", "$", "str", ".=", "\"</ul>\"", ";", "$", "str", ".=", "\"<p>This configuration is $validity.</p>\"", ";", "$", "str", ".=", "\"</div>\"", ";", "}", "return", "$", "str", ";", "}" ]
Returns a configuration analysis. @param Configuration $configuration @param bool $textOnly whether to render text or HTML @return string
[ "Returns", "a", "configuration", "analysis", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/ConfigurationRenderer.php#L118-L153
tourze/flow
src/Flow.php
Flow.start
public function start() { foreach ($this->layers as $layer) { // 数组格式,可以传参 if (is_array($layer)) { } // 如果是字符串 if (is_string($layer)) { $layer = new $layer; } if ($layer instanceof LayerInterface && $layer instanceof HandlerInterface) { // 传递当前请求流 $layer->setFlow($this); // 执行请求 $this->_previousLayerResult = $layer->handle(); } } }
php
public function start() { foreach ($this->layers as $layer) { // 数组格式,可以传参 if (is_array($layer)) { } // 如果是字符串 if (is_string($layer)) { $layer = new $layer; } if ($layer instanceof LayerInterface && $layer instanceof HandlerInterface) { // 传递当前请求流 $layer->setFlow($this); // 执行请求 $this->_previousLayerResult = $layer->handle(); } } }
[ "public", "function", "start", "(", ")", "{", "foreach", "(", "$", "this", "->", "layers", "as", "$", "layer", ")", "{", "// 数组格式,可以传参", "if", "(", "is_array", "(", "$", "layer", ")", ")", "{", "}", "// 如果是字符串", "if", "(", "is_string", "(", "$", "layer", ")", ")", "{", "$", "layer", "=", "new", "$", "layer", ";", "}", "if", "(", "$", "layer", "instanceof", "LayerInterface", "&&", "$", "layer", "instanceof", "HandlerInterface", ")", "{", "// 传递当前请求流", "$", "layer", "->", "setFlow", "(", "$", "this", ")", ";", "// 执行请求", "$", "this", "->", "_previousLayerResult", "=", "$", "layer", "->", "handle", "(", ")", ";", "}", "}", "}" ]
开始流程
[ "开始流程" ]
train
https://github.com/tourze/flow/blob/2256f9458e4ef1dbeeffc3659aaf06ed9c895133/src/Flow.php#L58-L81
tourze/flow
src/Flow.php
Flow.addLayer
public function addLayer($layers) { if ( ! is_array($layers)) { $layers = [$layers]; } foreach ($layers as $layer) { if ( ! in_array($layer, $this->layers)) { $this->layers[] = $layer; } } }
php
public function addLayer($layers) { if ( ! is_array($layers)) { $layers = [$layers]; } foreach ($layers as $layer) { if ( ! in_array($layer, $this->layers)) { $this->layers[] = $layer; } } }
[ "public", "function", "addLayer", "(", "$", "layers", ")", "{", "if", "(", "!", "is_array", "(", "$", "layers", ")", ")", "{", "$", "layers", "=", "[", "$", "layers", "]", ";", "}", "foreach", "(", "$", "layers", "as", "$", "layer", ")", "{", "if", "(", "!", "in_array", "(", "$", "layer", ",", "$", "this", "->", "layers", ")", ")", "{", "$", "this", "->", "layers", "[", "]", "=", "$", "layer", ";", "}", "}", "}" ]
增加执行请求层 @param $layers
[ "增加执行请求层" ]
train
https://github.com/tourze/flow/blob/2256f9458e4ef1dbeeffc3659aaf06ed9c895133/src/Flow.php#L110-L123
petrica/php-statsd-system
Config/Definition/ConfigDefinition.php
ConfigDefinition.getConfigTreeBuilder
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('gauges'); $rootNode ->useAttributeAsKey('path') ->prototype('array') ->children() ->scalarNode('class') ->isRequired() ->cannotBeEmpty() ->end() ->variableNode('arguments')->end() ->end(); return $treeBuilder; }
php
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('gauges'); $rootNode ->useAttributeAsKey('path') ->prototype('array') ->children() ->scalarNode('class') ->isRequired() ->cannotBeEmpty() ->end() ->variableNode('arguments')->end() ->end(); return $treeBuilder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "rootNode", "=", "$", "treeBuilder", "->", "root", "(", "'gauges'", ")", ";", "$", "rootNode", "->", "useAttributeAsKey", "(", "'path'", ")", "->", "prototype", "(", "'array'", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'class'", ")", "->", "isRequired", "(", ")", "->", "cannotBeEmpty", "(", ")", "->", "end", "(", ")", "->", "variableNode", "(", "'arguments'", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "return", "$", "treeBuilder", ";", "}" ]
Provides configuration mapping @return TreeBuilder
[ "Provides", "configuration", "mapping" ]
train
https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Config/Definition/ConfigDefinition.php#L24-L40
stk2k/net-driver
src/Http/ResponseHeaders.php
ResponseHeaders.parse
public function parse() { $this->parsed = []; $status_line = isset($this->headers[0]) ? trim($this->headers[0]) : null; if ( $status_line ){ $parts = explode(' ', $status_line, 3); $protocol_and_version = isset($parts[0]) ? $parts[0] : ''; $this->status_code = isset($parts[1]) ? intval($parts[1]) : 0; $this->reason_phrase = isset($parts[2]) ? $parts[2] : ''; $p = strpos($protocol_and_version, '/'); $this->protocol = ($p !== false) ? substr($protocol_and_version,0,$p) : $protocol_and_version; $this->protocol_version = ($p !== false) ? substr($protocol_and_version,$p+1) : ''; } foreach( $this->headers as $h ){ if ( preg_match( '@Content-Encoding:\s+([\w/+]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_ENCODING] = isset($matches[1]) ? strtolower($matches[1]) : null; } if ( preg_match( '@Content-Type:\s*([\w/+-\/]+);\s*charset=\s*([\w/+\-]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_TYPE] = isset($matches[1]) ? strtolower($matches[1]) : null; $this->parsed[EnumHttpHeader::CHARSET] = isset($matches[2]) ? strtolower($matches[2]) : null; } if ( preg_match( '@Content-Type:\s*([\w/+-\/]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_TYPE] = isset($matches[1]) ? strtolower($matches[1]) : null; } if ( preg_match( '@Host:\s+([\w/:+]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::HOST] = isset($matches[1]) ? strtolower($matches[1]) : null; } } }
php
public function parse() { $this->parsed = []; $status_line = isset($this->headers[0]) ? trim($this->headers[0]) : null; if ( $status_line ){ $parts = explode(' ', $status_line, 3); $protocol_and_version = isset($parts[0]) ? $parts[0] : ''; $this->status_code = isset($parts[1]) ? intval($parts[1]) : 0; $this->reason_phrase = isset($parts[2]) ? $parts[2] : ''; $p = strpos($protocol_and_version, '/'); $this->protocol = ($p !== false) ? substr($protocol_and_version,0,$p) : $protocol_and_version; $this->protocol_version = ($p !== false) ? substr($protocol_and_version,$p+1) : ''; } foreach( $this->headers as $h ){ if ( preg_match( '@Content-Encoding:\s+([\w/+]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_ENCODING] = isset($matches[1]) ? strtolower($matches[1]) : null; } if ( preg_match( '@Content-Type:\s*([\w/+-\/]+);\s*charset=\s*([\w/+\-]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_TYPE] = isset($matches[1]) ? strtolower($matches[1]) : null; $this->parsed[EnumHttpHeader::CHARSET] = isset($matches[2]) ? strtolower($matches[2]) : null; } if ( preg_match( '@Content-Type:\s*([\w/+-\/]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::CONTENT_TYPE] = isset($matches[1]) ? strtolower($matches[1]) : null; } if ( preg_match( '@Host:\s+([\w/:+]+)@i', $h, $matches ) ){ $this->parsed[EnumHttpHeader::HOST] = isset($matches[1]) ? strtolower($matches[1]) : null; } } }
[ "public", "function", "parse", "(", ")", "{", "$", "this", "->", "parsed", "=", "[", "]", ";", "$", "status_line", "=", "isset", "(", "$", "this", "->", "headers", "[", "0", "]", ")", "?", "trim", "(", "$", "this", "->", "headers", "[", "0", "]", ")", ":", "null", ";", "if", "(", "$", "status_line", ")", "{", "$", "parts", "=", "explode", "(", "' '", ",", "$", "status_line", ",", "3", ")", ";", "$", "protocol_and_version", "=", "isset", "(", "$", "parts", "[", "0", "]", ")", "?", "$", "parts", "[", "0", "]", ":", "''", ";", "$", "this", "->", "status_code", "=", "isset", "(", "$", "parts", "[", "1", "]", ")", "?", "intval", "(", "$", "parts", "[", "1", "]", ")", ":", "0", ";", "$", "this", "->", "reason_phrase", "=", "isset", "(", "$", "parts", "[", "2", "]", ")", "?", "$", "parts", "[", "2", "]", ":", "''", ";", "$", "p", "=", "strpos", "(", "$", "protocol_and_version", ",", "'/'", ")", ";", "$", "this", "->", "protocol", "=", "(", "$", "p", "!==", "false", ")", "?", "substr", "(", "$", "protocol_and_version", ",", "0", ",", "$", "p", ")", ":", "$", "protocol_and_version", ";", "$", "this", "->", "protocol_version", "=", "(", "$", "p", "!==", "false", ")", "?", "substr", "(", "$", "protocol_and_version", ",", "$", "p", "+", "1", ")", ":", "''", ";", "}", "foreach", "(", "$", "this", "->", "headers", "as", "$", "h", ")", "{", "if", "(", "preg_match", "(", "'@Content-Encoding:\\s+([\\w/+]+)@i'", ",", "$", "h", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "parsed", "[", "EnumHttpHeader", "::", "CONTENT_ENCODING", "]", "=", "isset", "(", "$", "matches", "[", "1", "]", ")", "?", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ":", "null", ";", "}", "if", "(", "preg_match", "(", "'@Content-Type:\\s*([\\w/+-\\/]+);\\s*charset=\\s*([\\w/+\\-]+)@i'", ",", "$", "h", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "parsed", "[", "EnumHttpHeader", "::", "CONTENT_TYPE", "]", "=", "isset", "(", "$", "matches", "[", "1", "]", ")", "?", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ":", "null", ";", "$", "this", "->", "parsed", "[", "EnumHttpHeader", "::", "CHARSET", "]", "=", "isset", "(", "$", "matches", "[", "2", "]", ")", "?", "strtolower", "(", "$", "matches", "[", "2", "]", ")", ":", "null", ";", "}", "if", "(", "preg_match", "(", "'@Content-Type:\\s*([\\w/+-\\/]+)@i'", ",", "$", "h", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "parsed", "[", "EnumHttpHeader", "::", "CONTENT_TYPE", "]", "=", "isset", "(", "$", "matches", "[", "1", "]", ")", "?", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ":", "null", ";", "}", "if", "(", "preg_match", "(", "'@Host:\\s+([\\w/:+]+)@i'", ",", "$", "h", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "parsed", "[", "EnumHttpHeader", "::", "HOST", "]", "=", "isset", "(", "$", "matches", "[", "1", "]", ")", "?", "strtolower", "(", "$", "matches", "[", "1", "]", ")", ":", "null", ";", "}", "}", "}" ]
Parse headers
[ "Parse", "headers" ]
train
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Http/ResponseHeaders.php#L92-L124
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.execute
public function execute(ProjectDescriptor $project) { $this->setObjectAliasesList($project->getIndexes()->elements->getAll()); $this->substitute($project); }
php
public function execute(ProjectDescriptor $project) { $this->setObjectAliasesList($project->getIndexes()->elements->getAll()); $this->substitute($project); }
[ "public", "function", "execute", "(", "ProjectDescriptor", "$", "project", ")", "{", "$", "this", "->", "setObjectAliasesList", "(", "$", "project", "->", "getIndexes", "(", ")", "->", "elements", "->", "getAll", "(", ")", ")", ";", "$", "this", "->", "substitute", "(", "$", "project", ")", ";", "}" ]
Executes the linker. @param ProjectDescriptor $project Representation of the Object Graph that can be manipulated. @return void
[ "Executes", "the", "linker", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L82-L86
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.substitute
public function substitute($item, $container = null) { $result = null; if (is_string($item)) { $result = $this->findAlias($item, $container); } elseif (is_array($item) || ($item instanceof \Traversable && ! $item instanceof ProjectInterface)) { $isModified = false; foreach ($item as $key => $element) { $isModified = true; $element = $this->substitute($element, $container); if ($element !== null) { $item[$key] = $element; } } if ($isModified) { $result = $item; } } elseif (is_object($item) && $item instanceof UnknownTypeDescriptor) { $alias = $this->findAlias($item->getName()); $result = $alias ?: $item; } elseif (is_object($item)) { $hash = spl_object_hash($item); if (isset($this->processedObjects[$hash])) { // if analyzed; just return return null; } $newContainer = ($this->isDescriptorContainer($item)) ? $item : $container; $this->processedObjects[$hash] = true; $objectClassName = get_class($item); $fieldNames = isset($this->substitutions[$objectClassName]) ? $this->substitutions[$objectClassName] : array(); foreach ($fieldNames as $fieldName) { $fieldValue = $this->findFieldValue($item, $fieldName); $response = $this->substitute($fieldValue, $newContainer); // if the returned response is not an object it must be grafted on the calling object if ($response !== null) { $setter = 'set'.ucfirst($fieldName); $item->$setter($response); } } } return $result; }
php
public function substitute($item, $container = null) { $result = null; if (is_string($item)) { $result = $this->findAlias($item, $container); } elseif (is_array($item) || ($item instanceof \Traversable && ! $item instanceof ProjectInterface)) { $isModified = false; foreach ($item as $key => $element) { $isModified = true; $element = $this->substitute($element, $container); if ($element !== null) { $item[$key] = $element; } } if ($isModified) { $result = $item; } } elseif (is_object($item) && $item instanceof UnknownTypeDescriptor) { $alias = $this->findAlias($item->getName()); $result = $alias ?: $item; } elseif (is_object($item)) { $hash = spl_object_hash($item); if (isset($this->processedObjects[$hash])) { // if analyzed; just return return null; } $newContainer = ($this->isDescriptorContainer($item)) ? $item : $container; $this->processedObjects[$hash] = true; $objectClassName = get_class($item); $fieldNames = isset($this->substitutions[$objectClassName]) ? $this->substitutions[$objectClassName] : array(); foreach ($fieldNames as $fieldName) { $fieldValue = $this->findFieldValue($item, $fieldName); $response = $this->substitute($fieldValue, $newContainer); // if the returned response is not an object it must be grafted on the calling object if ($response !== null) { $setter = 'set'.ucfirst($fieldName); $item->$setter($response); } } } return $result; }
[ "public", "function", "substitute", "(", "$", "item", ",", "$", "container", "=", "null", ")", "{", "$", "result", "=", "null", ";", "if", "(", "is_string", "(", "$", "item", ")", ")", "{", "$", "result", "=", "$", "this", "->", "findAlias", "(", "$", "item", ",", "$", "container", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "item", ")", "||", "(", "$", "item", "instanceof", "\\", "Traversable", "&&", "!", "$", "item", "instanceof", "ProjectInterface", ")", ")", "{", "$", "isModified", "=", "false", ";", "foreach", "(", "$", "item", "as", "$", "key", "=>", "$", "element", ")", "{", "$", "isModified", "=", "true", ";", "$", "element", "=", "$", "this", "->", "substitute", "(", "$", "element", ",", "$", "container", ")", ";", "if", "(", "$", "element", "!==", "null", ")", "{", "$", "item", "[", "$", "key", "]", "=", "$", "element", ";", "}", "}", "if", "(", "$", "isModified", ")", "{", "$", "result", "=", "$", "item", ";", "}", "}", "elseif", "(", "is_object", "(", "$", "item", ")", "&&", "$", "item", "instanceof", "UnknownTypeDescriptor", ")", "{", "$", "alias", "=", "$", "this", "->", "findAlias", "(", "$", "item", "->", "getName", "(", ")", ")", ";", "$", "result", "=", "$", "alias", "?", ":", "$", "item", ";", "}", "elseif", "(", "is_object", "(", "$", "item", ")", ")", "{", "$", "hash", "=", "spl_object_hash", "(", "$", "item", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "processedObjects", "[", "$", "hash", "]", ")", ")", "{", "// if analyzed; just return", "return", "null", ";", "}", "$", "newContainer", "=", "(", "$", "this", "->", "isDescriptorContainer", "(", "$", "item", ")", ")", "?", "$", "item", ":", "$", "container", ";", "$", "this", "->", "processedObjects", "[", "$", "hash", "]", "=", "true", ";", "$", "objectClassName", "=", "get_class", "(", "$", "item", ")", ";", "$", "fieldNames", "=", "isset", "(", "$", "this", "->", "substitutions", "[", "$", "objectClassName", "]", ")", "?", "$", "this", "->", "substitutions", "[", "$", "objectClassName", "]", ":", "array", "(", ")", ";", "foreach", "(", "$", "fieldNames", "as", "$", "fieldName", ")", "{", "$", "fieldValue", "=", "$", "this", "->", "findFieldValue", "(", "$", "item", ",", "$", "fieldName", ")", ";", "$", "response", "=", "$", "this", "->", "substitute", "(", "$", "fieldValue", ",", "$", "newContainer", ")", ";", "// if the returned response is not an object it must be grafted on the calling object", "if", "(", "$", "response", "!==", "null", ")", "{", "$", "setter", "=", "'set'", ".", "ucfirst", "(", "$", "fieldName", ")", ";", "$", "item", "->", "$", "setter", "(", "$", "response", ")", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Substitutes the given item or its children's FQCN with an object alias. This method may do either of the following depending on the item's type String If the given item is a string then this method will attempt to find an appropriate Class, Interface or TraitDescriptor object and return that. See {@see findAlias()} for more information on the normalization of these strings. Array or Traversable Iterate through each item, pass each key's contents to a new call to substitute and replace the key's contents if the contents is not an object (objects automatically update and saves performance). Object Determines all eligible substitutions using the substitutions property, construct a getter and retrieve the field's contents. Pass these contents to a new call of substitute and use a setter to replace the field's contents if anything other than null is returned. This method will return null if no substitution was possible and all of the above should not update the parent item when null is passed. @param string|object|\Traversable|array $item @param DescriptorAbstract|null $container A descriptor that acts as container for all elements underneath or null if there is no current container. @return null|string|DescriptorAbstract
[ "Substitutes", "the", "given", "item", "or", "its", "children", "s", "FQCN", "with", "an", "object", "alias", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L138-L189
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.findAlias
public function findAlias($fqsen, $container = null) { $fqsen = $this->replacePseudoTypes($fqsen, $container); if ($this->isContextMarkerInFqsen($fqsen) && $container instanceof DescriptorAbstract) { // first exchange `@context::element` for `\My\Class::element` and if it exists, return that $classMember = $this->fetchElementByFqsen($this->getTypeWithClassAsContext($fqsen, $container)); if ($classMember) { return $classMember; } // otherwise exchange `@context::element` for `\My\element` and if it exists, return that $namespaceContext = $this->getTypeWithNamespaceAsContext($fqsen, $container); $namespaceMember = $this->fetchElementByFqsen($namespaceContext); if ($namespaceMember) { return $namespaceMember; } // Otherwise we assume it is an undocumented class/interface/trait and return `\My\element` so // that the name containing the marker may be replaced by the class reference as string return $namespaceContext; } return $this->fetchElementByFqsen($fqsen); }
php
public function findAlias($fqsen, $container = null) { $fqsen = $this->replacePseudoTypes($fqsen, $container); if ($this->isContextMarkerInFqsen($fqsen) && $container instanceof DescriptorAbstract) { // first exchange `@context::element` for `\My\Class::element` and if it exists, return that $classMember = $this->fetchElementByFqsen($this->getTypeWithClassAsContext($fqsen, $container)); if ($classMember) { return $classMember; } // otherwise exchange `@context::element` for `\My\element` and if it exists, return that $namespaceContext = $this->getTypeWithNamespaceAsContext($fqsen, $container); $namespaceMember = $this->fetchElementByFqsen($namespaceContext); if ($namespaceMember) { return $namespaceMember; } // Otherwise we assume it is an undocumented class/interface/trait and return `\My\element` so // that the name containing the marker may be replaced by the class reference as string return $namespaceContext; } return $this->fetchElementByFqsen($fqsen); }
[ "public", "function", "findAlias", "(", "$", "fqsen", ",", "$", "container", "=", "null", ")", "{", "$", "fqsen", "=", "$", "this", "->", "replacePseudoTypes", "(", "$", "fqsen", ",", "$", "container", ")", ";", "if", "(", "$", "this", "->", "isContextMarkerInFqsen", "(", "$", "fqsen", ")", "&&", "$", "container", "instanceof", "DescriptorAbstract", ")", "{", "// first exchange `@context::element` for `\\My\\Class::element` and if it exists, return that", "$", "classMember", "=", "$", "this", "->", "fetchElementByFqsen", "(", "$", "this", "->", "getTypeWithClassAsContext", "(", "$", "fqsen", ",", "$", "container", ")", ")", ";", "if", "(", "$", "classMember", ")", "{", "return", "$", "classMember", ";", "}", "// otherwise exchange `@context::element` for `\\My\\element` and if it exists, return that", "$", "namespaceContext", "=", "$", "this", "->", "getTypeWithNamespaceAsContext", "(", "$", "fqsen", ",", "$", "container", ")", ";", "$", "namespaceMember", "=", "$", "this", "->", "fetchElementByFqsen", "(", "$", "namespaceContext", ")", ";", "if", "(", "$", "namespaceMember", ")", "{", "return", "$", "namespaceMember", ";", "}", "// Otherwise we assume it is an undocumented class/interface/trait and return `\\My\\element` so", "// that the name containing the marker may be replaced by the class reference as string", "return", "$", "namespaceContext", ";", "}", "return", "$", "this", "->", "fetchElementByFqsen", "(", "$", "fqsen", ")", ";", "}" ]
Attempts to find a Descriptor object alias with the FQSEN of the element it represents. This method will try to fetch an element after normalizing the provided FQSEN. The FQSEN may contain references (bindings) that can only be resolved during linking (such as `self`) or it may contain a context marker {@see CONTEXT_MARKER}. If there is a context marker then this method will see if a child of the given container exists that matches the element following the marker. If such a child does not exist in the current container then the namespace is queried if a child exists there that matches. For example: Given the Fqsen `@context::myFunction()` and the lastContainer `\My\Class` will this method first check to see if `\My\Class::myFunction()` exists; if it doesn't it will then check if `\My\myFunction()` exists. If neither element exists then this method assumes it is an undocumented class/trait/interface and change the given FQSEN by returning the namespaced element name (thus in the example above that would be `\My\myFunction()`). The calling method {@see substitute()} will then replace the value of the field containing the context marker with this normalized string. @param string $fqsen @param DescriptorAbstract|null $container @return DescriptorAbstract|string|null
[ "Attempts", "to", "find", "a", "Descriptor", "object", "alias", "with", "the", "FQSEN", "of", "the", "element", "it", "represents", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L217-L241
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.isDescriptorContainer
protected function isDescriptorContainer($item) { return $item instanceof FileDescriptor || $item instanceof NamespaceDescriptor || $item instanceof ClassDescriptor || $item instanceof TraitDescriptor || $item instanceof InterfaceDescriptor; }
php
protected function isDescriptorContainer($item) { return $item instanceof FileDescriptor || $item instanceof NamespaceDescriptor || $item instanceof ClassDescriptor || $item instanceof TraitDescriptor || $item instanceof InterfaceDescriptor; }
[ "protected", "function", "isDescriptorContainer", "(", "$", "item", ")", "{", "return", "$", "item", "instanceof", "FileDescriptor", "||", "$", "item", "instanceof", "NamespaceDescriptor", "||", "$", "item", "instanceof", "ClassDescriptor", "||", "$", "item", "instanceof", "TraitDescriptor", "||", "$", "item", "instanceof", "InterfaceDescriptor", ";", "}" ]
Returns true if the given Descriptor is a container type. @param DescriptorAbstract|mixed $item @return bool
[ "Returns", "true", "if", "the", "given", "Descriptor", "is", "a", "container", "type", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L265-L272
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.replacePseudoTypes
protected function replacePseudoTypes($fqsen, $container) { $pseudoTypes = array('self', '$this'); foreach ($pseudoTypes as $pseudoType) { if ((strpos($fqsen, $pseudoType . '::') === 0 || $fqsen === $pseudoType) && $container) { $fqsen = $container->getFullyQualifiedStructuralElementName() . substr($fqsen, strlen($pseudoType)); } } return $fqsen; }
php
protected function replacePseudoTypes($fqsen, $container) { $pseudoTypes = array('self', '$this'); foreach ($pseudoTypes as $pseudoType) { if ((strpos($fqsen, $pseudoType . '::') === 0 || $fqsen === $pseudoType) && $container) { $fqsen = $container->getFullyQualifiedStructuralElementName() . substr($fqsen, strlen($pseudoType)); } } return $fqsen; }
[ "protected", "function", "replacePseudoTypes", "(", "$", "fqsen", ",", "$", "container", ")", "{", "$", "pseudoTypes", "=", "array", "(", "'self'", ",", "'$this'", ")", ";", "foreach", "(", "$", "pseudoTypes", "as", "$", "pseudoType", ")", "{", "if", "(", "(", "strpos", "(", "$", "fqsen", ",", "$", "pseudoType", ".", "'::'", ")", "===", "0", "||", "$", "fqsen", "===", "$", "pseudoType", ")", "&&", "$", "container", ")", "{", "$", "fqsen", "=", "$", "container", "->", "getFullyQualifiedStructuralElementName", "(", ")", ".", "substr", "(", "$", "fqsen", ",", "strlen", "(", "$", "pseudoType", ")", ")", ";", "}", "}", "return", "$", "fqsen", ";", "}" ]
Replaces pseudo-types, such as `self`, into a normalized version based on the last container that was encountered. @param string $fqsen @param DescriptorAbstract|null $container @return string
[ "Replaces", "pseudo", "-", "types", "such", "as", "self", "into", "a", "normalized", "version", "based", "on", "the", "last", "container", "that", "was", "encountered", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L283-L294
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Linker/Linker.php
Linker.fetchElementByFqsen
protected function fetchElementByFqsen($fqsen) { return isset($this->elementList[$fqsen]) ? $this->elementList[$fqsen] : null; }
php
protected function fetchElementByFqsen($fqsen) { return isset($this->elementList[$fqsen]) ? $this->elementList[$fqsen] : null; }
[ "protected", "function", "fetchElementByFqsen", "(", "$", "fqsen", ")", "{", "return", "isset", "(", "$", "this", "->", "elementList", "[", "$", "fqsen", "]", ")", "?", "$", "this", "->", "elementList", "[", "$", "fqsen", "]", ":", "null", ";", "}" ]
Attempts to find an element with the given Fqsen in the list of elements for this project and returns null if it cannot find it. @param string $fqsen @return DescriptorAbstract|null
[ "Attempts", "to", "find", "an", "element", "with", "the", "given", "Fqsen", "in", "the", "list", "of", "elements", "for", "this", "project", "and", "returns", "null", "if", "it", "cannot", "find", "it", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Linker/Linker.php#L356-L359
Danack/GithubArtaxService
lib/GithubService/Operation/createOrGetAuthorization.php
createOrGetAuthorization.createRequest
public function createRequest() { $request = new \Amp\Artax\Request(); $url = null; $request->setMethod('PUT'); $jsonParams = []; if (array_key_exists('Accept', $this->parameters) == true) { $value = $this->getFilteredParameter('Accept'); $request->setHeader('Accept', $value); } $value = $this->getFilteredParameter('userAgent'); $request->setHeader('User-Agent', $value); $value = $this->getFilteredParameter('Authorization'); $request->setHeader('Authorization', $value); if (array_key_exists('otp', $this->parameters) == true) { $value = $this->getFilteredParameter('otp'); $request->setHeader('X-GitHub-OTP', $value); } $value = $this->getFilteredParameter('scopes'); $jsonParams['scopes'] = $value; $value = $this->getFilteredParameter('note'); $jsonParams['note'] = $value; $value = $this->getFilteredParameter('note_url'); $jsonParams['note_url'] = $value; $value = $this->getFilteredParameter('client_id'); $queryParameters['client_id'] = $value; $value = $this->getFilteredParameter('client_secret'); $jsonParams['client_secret'] = $value; $value = $this->getFilteredParameter('fingerprint'); $jsonParams['fingerprint'] = $value; //Parameters are parsed and set, lets prepare the request if (count($jsonParams)) { $jsonBody = json_encode($jsonParams); $request->setHeader("Content-Type", "application/json"); $request->setBody($jsonBody); } if ($url == null) { $url = "https://api.github.com/authorizations/clients/{client_id}"; } $uriTemplate = new \ArtaxServiceBuilder\Service\UriTemplate\UriTemplate(); $url = $uriTemplate->expand($url, $this->parameters); $request->setUri($url); return $request; }
php
public function createRequest() { $request = new \Amp\Artax\Request(); $url = null; $request->setMethod('PUT'); $jsonParams = []; if (array_key_exists('Accept', $this->parameters) == true) { $value = $this->getFilteredParameter('Accept'); $request->setHeader('Accept', $value); } $value = $this->getFilteredParameter('userAgent'); $request->setHeader('User-Agent', $value); $value = $this->getFilteredParameter('Authorization'); $request->setHeader('Authorization', $value); if (array_key_exists('otp', $this->parameters) == true) { $value = $this->getFilteredParameter('otp'); $request->setHeader('X-GitHub-OTP', $value); } $value = $this->getFilteredParameter('scopes'); $jsonParams['scopes'] = $value; $value = $this->getFilteredParameter('note'); $jsonParams['note'] = $value; $value = $this->getFilteredParameter('note_url'); $jsonParams['note_url'] = $value; $value = $this->getFilteredParameter('client_id'); $queryParameters['client_id'] = $value; $value = $this->getFilteredParameter('client_secret'); $jsonParams['client_secret'] = $value; $value = $this->getFilteredParameter('fingerprint'); $jsonParams['fingerprint'] = $value; //Parameters are parsed and set, lets prepare the request if (count($jsonParams)) { $jsonBody = json_encode($jsonParams); $request->setHeader("Content-Type", "application/json"); $request->setBody($jsonBody); } if ($url == null) { $url = "https://api.github.com/authorizations/clients/{client_id}"; } $uriTemplate = new \ArtaxServiceBuilder\Service\UriTemplate\UriTemplate(); $url = $uriTemplate->expand($url, $this->parameters); $request->setUri($url); return $request; }
[ "public", "function", "createRequest", "(", ")", "{", "$", "request", "=", "new", "\\", "Amp", "\\", "Artax", "\\", "Request", "(", ")", ";", "$", "url", "=", "null", ";", "$", "request", "->", "setMethod", "(", "'PUT'", ")", ";", "$", "jsonParams", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'Accept'", ",", "$", "this", "->", "parameters", ")", "==", "true", ")", "{", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'Accept'", ")", ";", "$", "request", "->", "setHeader", "(", "'Accept'", ",", "$", "value", ")", ";", "}", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'userAgent'", ")", ";", "$", "request", "->", "setHeader", "(", "'User-Agent'", ",", "$", "value", ")", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'Authorization'", ")", ";", "$", "request", "->", "setHeader", "(", "'Authorization'", ",", "$", "value", ")", ";", "if", "(", "array_key_exists", "(", "'otp'", ",", "$", "this", "->", "parameters", ")", "==", "true", ")", "{", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'otp'", ")", ";", "$", "request", "->", "setHeader", "(", "'X-GitHub-OTP'", ",", "$", "value", ")", ";", "}", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'scopes'", ")", ";", "$", "jsonParams", "[", "'scopes'", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'note'", ")", ";", "$", "jsonParams", "[", "'note'", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'note_url'", ")", ";", "$", "jsonParams", "[", "'note_url'", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'client_id'", ")", ";", "$", "queryParameters", "[", "'client_id'", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'client_secret'", ")", ";", "$", "jsonParams", "[", "'client_secret'", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "getFilteredParameter", "(", "'fingerprint'", ")", ";", "$", "jsonParams", "[", "'fingerprint'", "]", "=", "$", "value", ";", "//Parameters are parsed and set, lets prepare the request", "if", "(", "count", "(", "$", "jsonParams", ")", ")", "{", "$", "jsonBody", "=", "json_encode", "(", "$", "jsonParams", ")", ";", "$", "request", "->", "setHeader", "(", "\"Content-Type\"", ",", "\"application/json\"", ")", ";", "$", "request", "->", "setBody", "(", "$", "jsonBody", ")", ";", "}", "if", "(", "$", "url", "==", "null", ")", "{", "$", "url", "=", "\"https://api.github.com/authorizations/clients/{client_id}\"", ";", "}", "$", "uriTemplate", "=", "new", "\\", "ArtaxServiceBuilder", "\\", "Service", "\\", "UriTemplate", "\\", "UriTemplate", "(", ")", ";", "$", "url", "=", "$", "uriTemplate", "->", "expand", "(", "$", "url", ",", "$", "this", "->", "parameters", ")", ";", "$", "request", "->", "setUri", "(", "$", "url", ")", ";", "return", "$", "request", ";", "}" ]
Create an Amp\Artax\Request object from the operation. @return \Amp\Artax\Request
[ "Create", "an", "Amp", "\\", "Artax", "\\", "Request", "object", "from", "the", "operation", "." ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/createOrGetAuthorization.php#L260-L306
Danack/GithubArtaxService
lib/GithubService/Operation/createOrGetAuthorization.php
createOrGetAuthorization.call
public function call() { $request = $this->createRequest(); $response = $this->api->execute($request, $this); $this->response = $response; if ($this->shouldResponseBeProcessed($response)) { $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; } return $response; }
php
public function call() { $request = $this->createRequest(); $response = $this->api->execute($request, $this); $this->response = $response; if ($this->shouldResponseBeProcessed($response)) { $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; } return $response; }
[ "public", "function", "call", "(", ")", "{", "$", "request", "=", "$", "this", "->", "createRequest", "(", ")", ";", "$", "response", "=", "$", "this", "->", "api", "->", "execute", "(", "$", "request", ",", "$", "this", ")", ";", "$", "this", "->", "response", "=", "$", "response", ";", "if", "(", "$", "this", "->", "shouldResponseBeProcessed", "(", "$", "response", ")", ")", "{", "$", "instance", "=", "\\", "GithubService", "\\", "Model", "\\", "OauthAccess", "::", "createFromResponse", "(", "$", "response", ",", "$", "this", ")", ";", "return", "$", "instance", ";", "}", "return", "$", "response", ";", "}" ]
Create and execute the operation, then return the processed response. @return mixed|\GithubService\Model\OauthAccess
[ "Create", "and", "execute", "the", "operation", "then", "return", "the", "processed", "response", "." ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/createOrGetAuthorization.php#L326-L337
Danack/GithubArtaxService
lib/GithubService/Operation/createOrGetAuthorization.php
createOrGetAuthorization.dispatch
public function dispatch(\Amp\Artax\Request $request) { $response = $this->api->execute($request, $this); $this->response = $response; $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; }
php
public function dispatch(\Amp\Artax\Request $request) { $response = $this->api->execute($request, $this); $this->response = $response; $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; }
[ "public", "function", "dispatch", "(", "\\", "Amp", "\\", "Artax", "\\", "Request", "$", "request", ")", "{", "$", "response", "=", "$", "this", "->", "api", "->", "execute", "(", "$", "request", ",", "$", "this", ")", ";", "$", "this", "->", "response", "=", "$", "response", ";", "$", "instance", "=", "\\", "GithubService", "\\", "Model", "\\", "OauthAccess", "::", "createFromResponse", "(", "$", "response", ",", "$", "this", ")", ";", "return", "$", "instance", ";", "}" ]
Dispatch the request for this operation and process the response. Allows you to modify the request before it is sent. @return \GithubService\Model\OauthAccess @param \Amp\Artax\Request $request The request to be processed
[ "Dispatch", "the", "request", "for", "this", "operation", "and", "process", "the", "response", ".", "Allows", "you", "to", "modify", "the", "request", "before", "it", "is", "sent", "." ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/createOrGetAuthorization.php#L367-L373
Danack/GithubArtaxService
lib/GithubService/Operation/createOrGetAuthorization.php
createOrGetAuthorization.processResponse
public function processResponse(\Amp\Artax\Response $response) { $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; }
php
public function processResponse(\Amp\Artax\Response $response) { $instance = \GithubService\Model\OauthAccess::createFromResponse($response, $this); return $instance; }
[ "public", "function", "processResponse", "(", "\\", "Amp", "\\", "Artax", "\\", "Response", "$", "response", ")", "{", "$", "instance", "=", "\\", "GithubService", "\\", "Model", "\\", "OauthAccess", "::", "createFromResponse", "(", "$", "response", ",", "$", "this", ")", ";", "return", "$", "instance", ";", "}" ]
Dispatch the request for this operation and process the response. Allows you to modify the request before it is sent. @return \GithubService\Model\OauthAccess @param \Amp\Artax\Response $response The HTTP response.
[ "Dispatch", "the", "request", "for", "this", "operation", "and", "process", "the", "response", ".", "Allows", "you", "to", "modify", "the", "request", "before", "it", "is", "sent", "." ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/createOrGetAuthorization.php#L394-L398
hametuha/wpametu
src/WPametu/UI/Widget.php
Widget.widget
public function widget($args, $instance){ $content = $this->widget_content($instance); if( $content ){ echo $args['before_widget']; if( isset($instance['title']) && !empty($instance['title']) ){ echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } echo $content; echo $args['after_widget']; } }
php
public function widget($args, $instance){ $content = $this->widget_content($instance); if( $content ){ echo $args['before_widget']; if( isset($instance['title']) && !empty($instance['title']) ){ echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } echo $content; echo $args['after_widget']; } }
[ "public", "function", "widget", "(", "$", "args", ",", "$", "instance", ")", "{", "$", "content", "=", "$", "this", "->", "widget_content", "(", "$", "instance", ")", ";", "if", "(", "$", "content", ")", "{", "echo", "$", "args", "[", "'before_widget'", "]", ";", "if", "(", "isset", "(", "$", "instance", "[", "'title'", "]", ")", "&&", "!", "empty", "(", "$", "instance", "[", "'title'", "]", ")", ")", "{", "echo", "$", "args", "[", "'before_title'", "]", ";", "echo", "$", "instance", "[", "'title'", "]", ";", "echo", "$", "args", "[", "'after_title'", "]", ";", "}", "echo", "$", "content", ";", "echo", "$", "args", "[", "'after_widget'", "]", ";", "}", "}" ]
Show widget content @param array $args @param array $instance
[ "Show", "widget", "content" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Widget.php#L82-L94
hametuha/wpametu
src/WPametu/UI/Widget.php
Widget.replace
protected function replace($content, $instance){ foreach( $this->placeholders as $key => $desc ){ $fill = $this->fill($key, $instance); if( $fill && false !== strpos($content, '%'.$key.'%') ){ $content = str_replace("%{$key}%", $fill, $content); } } return $content; }
php
protected function replace($content, $instance){ foreach( $this->placeholders as $key => $desc ){ $fill = $this->fill($key, $instance); if( $fill && false !== strpos($content, '%'.$key.'%') ){ $content = str_replace("%{$key}%", $fill, $content); } } return $content; }
[ "protected", "function", "replace", "(", "$", "content", ",", "$", "instance", ")", "{", "foreach", "(", "$", "this", "->", "placeholders", "as", "$", "key", "=>", "$", "desc", ")", "{", "$", "fill", "=", "$", "this", "->", "fill", "(", "$", "key", ",", "$", "instance", ")", ";", "if", "(", "$", "fill", "&&", "false", "!==", "strpos", "(", "$", "content", ",", "'%'", ".", "$", "key", ".", "'%'", ")", ")", "{", "$", "content", "=", "str_replace", "(", "\"%{$key}%\"", ",", "$", "fill", ",", "$", "content", ")", ";", "}", "}", "return", "$", "content", ";", "}" ]
Replace content @param string $content @param array $instance Widget's setting @return string
[ "Replace", "content" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Widget.php#L111-L119
hametuha/wpametu
src/WPametu/UI/Widget.php
Widget.get_placeholders
protected function get_placeholders(){ return [ 'title' => $this->__('Post title'), 'url' => $this->__('Permalink'), 'excerpt' => $this->__('Excerpt'), 'date' => $this->__('Published'), 'modified' => $this->__('Last modified'), 'author' => $this->__('Author name'), 'category' => $this->__('Category'), 'tag' => $this->__('Post tag'), ]; }
php
protected function get_placeholders(){ return [ 'title' => $this->__('Post title'), 'url' => $this->__('Permalink'), 'excerpt' => $this->__('Excerpt'), 'date' => $this->__('Published'), 'modified' => $this->__('Last modified'), 'author' => $this->__('Author name'), 'category' => $this->__('Category'), 'tag' => $this->__('Post tag'), ]; }
[ "protected", "function", "get_placeholders", "(", ")", "{", "return", "[", "'title'", "=>", "$", "this", "->", "__", "(", "'Post title'", ")", ",", "'url'", "=>", "$", "this", "->", "__", "(", "'Permalink'", ")", ",", "'excerpt'", "=>", "$", "this", "->", "__", "(", "'Excerpt'", ")", ",", "'date'", "=>", "$", "this", "->", "__", "(", "'Published'", ")", ",", "'modified'", "=>", "$", "this", "->", "__", "(", "'Last modified'", ")", ",", "'author'", "=>", "$", "this", "->", "__", "(", "'Author name'", ")", ",", "'category'", "=>", "$", "this", "->", "__", "(", "'Category'", ")", ",", "'tag'", "=>", "$", "this", "->", "__", "(", "'Post tag'", ")", ",", "]", ";", "}" ]
Set placeholder @return array
[ "Set", "placeholder" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Widget.php#L126-L137
hametuha/wpametu
src/WPametu/UI/Widget.php
Widget.fill
protected function fill($placeholder, $instance){ switch( $placeholder ){ case 'title': return get_the_title(); break; case 'url': return get_permalink(); break; case 'excerpt': return get_the_excerpt(); break; case 'date': return get_the_date(); break; case 'modified': return get_the_modified_date(); break; case 'author': return get_the_author(); break; default: return false; break; } }
php
protected function fill($placeholder, $instance){ switch( $placeholder ){ case 'title': return get_the_title(); break; case 'url': return get_permalink(); break; case 'excerpt': return get_the_excerpt(); break; case 'date': return get_the_date(); break; case 'modified': return get_the_modified_date(); break; case 'author': return get_the_author(); break; default: return false; break; } }
[ "protected", "function", "fill", "(", "$", "placeholder", ",", "$", "instance", ")", "{", "switch", "(", "$", "placeholder", ")", "{", "case", "'title'", ":", "return", "get_the_title", "(", ")", ";", "break", ";", "case", "'url'", ":", "return", "get_permalink", "(", ")", ";", "break", ";", "case", "'excerpt'", ":", "return", "get_the_excerpt", "(", ")", ";", "break", ";", "case", "'date'", ":", "return", "get_the_date", "(", ")", ";", "break", ";", "case", "'modified'", ":", "return", "get_the_modified_date", "(", ")", ";", "break", ";", "case", "'author'", ":", "return", "get_the_author", "(", ")", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get placeholder's content @param string $placeholder @param array $instance Widget's setting @return bool|string
[ "Get", "placeholder", "s", "content" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Widget.php#L146-L170
caffeinated/beverage
src/Traits/DotArrayAccess.php
DotArrayAccess.offsetSet
public function offsetSet($offset, $value = null) { if (is_array($offset)) { foreach ($offset as $innerKey => $innerValue) { array_set($this->{$this->getArrayAccessor()}, $innerKey, $innerValue); } } else { array_set($this->{$this->getArrayAccessor()}, $offset, $value); } return $this; }
php
public function offsetSet($offset, $value = null) { if (is_array($offset)) { foreach ($offset as $innerKey => $innerValue) { array_set($this->{$this->getArrayAccessor()}, $innerKey, $innerValue); } } else { array_set($this->{$this->getArrayAccessor()}, $offset, $value); } return $this; }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "offset", ")", ")", "{", "foreach", "(", "$", "offset", "as", "$", "innerKey", "=>", "$", "innerValue", ")", "{", "array_set", "(", "$", "this", "->", "{", "$", "this", "->", "getArrayAccessor", "(", ")", "}", ",", "$", "innerKey", ",", "$", "innerValue", ")", ";", "}", "}", "else", "{", "array_set", "(", "$", "this", "->", "{", "$", "this", "->", "getArrayAccessor", "(", ")", "}", ",", "$", "offset", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the item at a given offset. @param $offset @param mixed $value @return $this @internal param mixed $key
[ "Set", "the", "item", "at", "a", "given", "offset", "." ]
train
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/DotArrayAccess.php#L56-L67
miguelibero/meinhof
src/Meinhof/Action/SetupSiteAction.php
SetupSiteAction.take
public function take() { $params = array_merge(array( 'author' => null, 'categories' => null ), $this->input->getOptions()); $params = $this->fixAuthorSetupParameters($params); $params = $this->fixCategoriesSetupParameters($params); $this->writeOutputLine("writing site configuration...", 2); $this->store->write($params); $this->writeOutputLine("done", 2); }
php
public function take() { $params = array_merge(array( 'author' => null, 'categories' => null ), $this->input->getOptions()); $params = $this->fixAuthorSetupParameters($params); $params = $this->fixCategoriesSetupParameters($params); $this->writeOutputLine("writing site configuration...", 2); $this->store->write($params); $this->writeOutputLine("done", 2); }
[ "public", "function", "take", "(", ")", "{", "$", "params", "=", "array_merge", "(", "array", "(", "'author'", "=>", "null", ",", "'categories'", "=>", "null", ")", ",", "$", "this", "->", "input", "->", "getOptions", "(", ")", ")", ";", "$", "params", "=", "$", "this", "->", "fixAuthorSetupParameters", "(", "$", "params", ")", ";", "$", "params", "=", "$", "this", "->", "fixCategoriesSetupParameters", "(", "$", "params", ")", ";", "$", "this", "->", "writeOutputLine", "(", "\"writing site configuration...\"", ",", "2", ")", ";", "$", "this", "->", "store", "->", "write", "(", "$", "params", ")", ";", "$", "this", "->", "writeOutputLine", "(", "\"done\"", ",", "2", ")", ";", "}" ]
Creates the site structure.
[ "Creates", "the", "site", "structure", "." ]
train
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/Action/SetupSiteAction.php#L44-L59
miguelibero/meinhof
src/Meinhof/Action/SetupSiteAction.php
SetupSiteAction.fixAuthorSetupParameters
protected function fixAuthorSetupParameters(array $params) { if (!isset($params['author'])) { $params['author'] = null; } if (preg_match('/(.*) <(.+)>/', $params['author'], $m)) { $params['author'] = $m[1]; $params['author-email'] = $m[2]; } else { $params['author-email'] = null; } return $params; }
php
protected function fixAuthorSetupParameters(array $params) { if (!isset($params['author'])) { $params['author'] = null; } if (preg_match('/(.*) <(.+)>/', $params['author'], $m)) { $params['author'] = $m[1]; $params['author-email'] = $m[2]; } else { $params['author-email'] = null; } return $params; }
[ "protected", "function", "fixAuthorSetupParameters", "(", "array", "$", "params", ")", "{", "if", "(", "!", "isset", "(", "$", "params", "[", "'author'", "]", ")", ")", "{", "$", "params", "[", "'author'", "]", "=", "null", ";", "}", "if", "(", "preg_match", "(", "'/(.*) <(.+)>/'", ",", "$", "params", "[", "'author'", "]", ",", "$", "m", ")", ")", "{", "$", "params", "[", "'author'", "]", "=", "$", "m", "[", "1", "]", ";", "$", "params", "[", "'author-email'", "]", "=", "$", "m", "[", "2", "]", ";", "}", "else", "{", "$", "params", "[", "'author-email'", "]", "=", "null", ";", "}", "return", "$", "params", ";", "}" ]
Fixes the author setup parameter. In the setup you can specify an author as `Author Name <[email protected]>`. This function separates this into two different keys, `author` and `author_email`. @param array $params setup parameter array @return array fixed setup parameter array
[ "Fixes", "the", "author", "setup", "parameter", "." ]
train
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/Action/SetupSiteAction.php#L71-L84
libreworks/caridea-validate
src/Builder.php
Builder.field
public function field(string $field, ...$rules): self { $this->validators[$field] = $this->parser->parse($rules); return $this; }
php
public function field(string $field, ...$rules): self { $this->validators[$field] = $this->parser->parse($rules); return $this; }
[ "public", "function", "field", "(", "string", "$", "field", ",", "...", "$", "rules", ")", ":", "self", "{", "$", "this", "->", "validators", "[", "$", "field", "]", "=", "$", "this", "->", "parser", "->", "parse", "(", "$", "rules", ")", ";", "return", "$", "this", ";", "}" ]
Adds one or more rules to this builder. @param string $field The field to validate @param string|object|array $rules Either a string name, an associative array, or an object with name → arguments @return $this provides a fluent interface
[ "Adds", "one", "or", "more", "rules", "to", "this", "builder", "." ]
train
https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Builder.php#L58-L62
libreworks/caridea-validate
src/Builder.php
Builder.build
public function build($ruleset = null): Validator { $validators = array_merge([], $this->validators); if (is_object($ruleset) || (is_array($ruleset) && Parser::isAssociative($ruleset))) { foreach ($ruleset as $field => $rules) { $validators[$field] = $this->parser->parse($rules); } } return new Validator($validators); }
php
public function build($ruleset = null): Validator { $validators = array_merge([], $this->validators); if (is_object($ruleset) || (is_array($ruleset) && Parser::isAssociative($ruleset))) { foreach ($ruleset as $field => $rules) { $validators[$field] = $this->parser->parse($rules); } } return new Validator($validators); }
[ "public", "function", "build", "(", "$", "ruleset", "=", "null", ")", ":", "Validator", "{", "$", "validators", "=", "array_merge", "(", "[", "]", ",", "$", "this", "->", "validators", ")", ";", "if", "(", "is_object", "(", "$", "ruleset", ")", "||", "(", "is_array", "(", "$", "ruleset", ")", "&&", "Parser", "::", "isAssociative", "(", "$", "ruleset", ")", ")", ")", "{", "foreach", "(", "$", "ruleset", "as", "$", "field", "=>", "$", "rules", ")", "{", "$", "validators", "[", "$", "field", "]", "=", "$", "this", "->", "parser", "->", "parse", "(", "$", "rules", ")", ";", "}", "}", "return", "new", "Validator", "(", "$", "validators", ")", ";", "}" ]
Builds a validator for the provided ruleset. ```javascript // rules.json { name: 'required', email: ['required', 'email'], drinks: { one_of: [['coffee', 'tea']] }, phone: {max_length: 10} } ``` ```php $ruleset = json_decode(file_get_contents('rules.json')); $builder = new \Caridea\Validate\Builder(); $validator = $builder->build($ruleset); ``` @param object|array $ruleset Object or associative array (as returned from `json_decode`) with ruleset, or `null` to use defined rules. @return \Caridea\Validate\Validator the built validator
[ "Builds", "a", "validator", "for", "the", "provided", "ruleset", "." ]
train
https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Builder.php#L86-L95
cmsgears/module-community
admin/controllers/base/group/PostController.php
PostController.init
public function init() { parent::init(); // Views $this->setViewPath( '@cmsgears/module-community/admin/views/group/post' ); // Permission $this->crudPermission = CmnGlobal::PERM_GROUP_ADMIN; // Config $this->type = CoreGlobal::TYPE_DEFAULT; $this->templateType = CmnGlobal::TYPE_GROUP_POST; // Services $this->modelService = Yii::$app->factory->get( 'groupPostService' ); $this->parentService = Yii::$app->factory->get( 'groupService' ); $this->templateService = Yii::$app->factory->get( 'templateService' ); }
php
public function init() { parent::init(); // Views $this->setViewPath( '@cmsgears/module-community/admin/views/group/post' ); // Permission $this->crudPermission = CmnGlobal::PERM_GROUP_ADMIN; // Config $this->type = CoreGlobal::TYPE_DEFAULT; $this->templateType = CmnGlobal::TYPE_GROUP_POST; // Services $this->modelService = Yii::$app->factory->get( 'groupPostService' ); $this->parentService = Yii::$app->factory->get( 'groupService' ); $this->templateService = Yii::$app->factory->get( 'templateService' ); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "// Views", "$", "this", "->", "setViewPath", "(", "'@cmsgears/module-community/admin/views/group/post'", ")", ";", "// Permission", "$", "this", "->", "crudPermission", "=", "CmnGlobal", "::", "PERM_GROUP_ADMIN", ";", "// Config", "$", "this", "->", "type", "=", "CoreGlobal", "::", "TYPE_DEFAULT", ";", "$", "this", "->", "templateType", "=", "CmnGlobal", "::", "TYPE_GROUP_POST", ";", "// Services", "$", "this", "->", "modelService", "=", "Yii", "::", "$", "app", "->", "factory", "->", "get", "(", "'groupPostService'", ")", ";", "$", "this", "->", "parentService", "=", "Yii", "::", "$", "app", "->", "factory", "->", "get", "(", "'groupService'", ")", ";", "$", "this", "->", "templateService", "=", "Yii", "::", "$", "app", "->", "factory", "->", "get", "(", "'templateService'", ")", ";", "}" ]
Constructor and Initialisation ------------------------------
[ "Constructor", "and", "Initialisation", "------------------------------" ]
train
https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/admin/controllers/base/group/PostController.php#L53-L74
gplcart/cli
controllers/commands/Shipping.php
Shipping.cmdGetShipping
public function cmdGetShipping() { $result = $this->getListShipping(); $this->outputFormat($result); $this->outputFormatTableShipping($result); $this->output(); }
php
public function cmdGetShipping() { $result = $this->getListShipping(); $this->outputFormat($result); $this->outputFormatTableShipping($result); $this->output(); }
[ "public", "function", "cmdGetShipping", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListShipping", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTableShipping", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "shipping-get" command
[ "Callback", "for", "shipping", "-", "get", "command" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Shipping.php#L40-L46
gplcart/cli
controllers/commands/Shipping.php
Shipping.getListShipping
protected function getListShipping() { $id = $this->getParam(0); if (!isset($id)) { $list = $this->shipping->getList(); $this->limitArray($list); return $list; } $method = $this->shipping->get($id); if (empty($method)) { $this->errorAndExit($this->text('Unexpected result')); } return array($method); }
php
protected function getListShipping() { $id = $this->getParam(0); if (!isset($id)) { $list = $this->shipping->getList(); $this->limitArray($list); return $list; } $method = $this->shipping->get($id); if (empty($method)) { $this->errorAndExit($this->text('Unexpected result')); } return array($method); }
[ "protected", "function", "getListShipping", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "if", "(", "!", "isset", "(", "$", "id", ")", ")", "{", "$", "list", "=", "$", "this", "->", "shipping", "->", "getList", "(", ")", ";", "$", "this", "->", "limitArray", "(", "$", "list", ")", ";", "return", "$", "list", ";", "}", "$", "method", "=", "$", "this", "->", "shipping", "->", "get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "method", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "return", "array", "(", "$", "method", ")", ";", "}" ]
Returns an array of shipping methods @return array
[ "Returns", "an", "array", "of", "shipping", "methods" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Shipping.php#L52-L69
perryflynn/PerrysLambda
src/PerrysLambda/Converter/ListConverter.php
ListConverter.setArraySource
public function setArraySource(array $data=null) { if($data===null) { $this->iterator = null; } else { $this->iterator = new \ArrayIterator($data); } }
php
public function setArraySource(array $data=null) { if($data===null) { $this->iterator = null; } else { $this->iterator = new \ArrayIterator($data); } }
[ "public", "function", "setArraySource", "(", "array", "$", "data", "=", "null", ")", "{", "if", "(", "$", "data", "===", "null", ")", "{", "$", "this", "->", "iterator", "=", "null", ";", "}", "else", "{", "$", "this", "->", "iterator", "=", "new", "\\", "ArrayIterator", "(", "$", "data", ")", ";", "}", "}" ]
Array as import source @param array $data
[ "Array", "as", "import", "source" ]
train
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/Converter/ListConverter.php#L110-L120
perryflynn/PerrysLambda
src/PerrysLambda/Converter/ListConverter.php
ListConverter.setIteratorSource
public function setIteratorSource(\Iterator $iterator=null, $start=0, $end=-1) { $this->iteratorstartindex = (int)$start; $this->iteratorendindex = (int)$end; $this->iterator = $iterator; }
php
public function setIteratorSource(\Iterator $iterator=null, $start=0, $end=-1) { $this->iteratorstartindex = (int)$start; $this->iteratorendindex = (int)$end; $this->iterator = $iterator; }
[ "public", "function", "setIteratorSource", "(", "\\", "Iterator", "$", "iterator", "=", "null", ",", "$", "start", "=", "0", ",", "$", "end", "=", "-", "1", ")", "{", "$", "this", "->", "iteratorstartindex", "=", "(", "int", ")", "$", "start", ";", "$", "this", "->", "iteratorendindex", "=", "(", "int", ")", "$", "end", ";", "$", "this", "->", "iterator", "=", "$", "iterator", ";", "}" ]
Iterator as import source @param \Iterator $iterator @param int $start @param int $end
[ "Iterator", "as", "import", "source" ]
train
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/Converter/ListConverter.php#L136-L141
perryflynn/PerrysLambda
src/PerrysLambda/Converter/ListConverter.php
ListConverter.importInto
public function importInto(ArrayBase $collection) { if($this->iterator instanceof \Iterator) { $i = 0; foreach($this->iterator as $key => $row) { if($this->iteratorendindex>=0 && $i>$this->iteratorendindex) { break; } elseif($i>=$this->iteratorstartindex) { $tempkey = $key; $tempvalue = $row; /* if($this->isItemConverterExist()) { $this->getItemConverter()->deserializeAll($tempvalue, $tempkey); } */ if($tempvalue!==null && $tempkey!==null) { $collection->set($tempkey, $tempvalue);//, true); } } $i++; } } }
php
public function importInto(ArrayBase $collection) { if($this->iterator instanceof \Iterator) { $i = 0; foreach($this->iterator as $key => $row) { if($this->iteratorendindex>=0 && $i>$this->iteratorendindex) { break; } elseif($i>=$this->iteratorstartindex) { $tempkey = $key; $tempvalue = $row; /* if($this->isItemConverterExist()) { $this->getItemConverter()->deserializeAll($tempvalue, $tempkey); } */ if($tempvalue!==null && $tempkey!==null) { $collection->set($tempkey, $tempvalue);//, true); } } $i++; } } }
[ "public", "function", "importInto", "(", "ArrayBase", "$", "collection", ")", "{", "if", "(", "$", "this", "->", "iterator", "instanceof", "\\", "Iterator", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "this", "->", "iterator", "as", "$", "key", "=>", "$", "row", ")", "{", "if", "(", "$", "this", "->", "iteratorendindex", ">=", "0", "&&", "$", "i", ">", "$", "this", "->", "iteratorendindex", ")", "{", "break", ";", "}", "elseif", "(", "$", "i", ">=", "$", "this", "->", "iteratorstartindex", ")", "{", "$", "tempkey", "=", "$", "key", ";", "$", "tempvalue", "=", "$", "row", ";", "/*\n if($this->isItemConverterExist())\n {\n $this->getItemConverter()->deserializeAll($tempvalue, $tempkey);\n }\n */", "if", "(", "$", "tempvalue", "!==", "null", "&&", "$", "tempkey", "!==", "null", ")", "{", "$", "collection", "->", "set", "(", "$", "tempkey", ",", "$", "tempvalue", ")", ";", "//, true);", "}", "}", "$", "i", "++", ";", "}", "}", "}" ]
Import into ArrayBase @param ArrayBase $collection
[ "Import", "into", "ArrayBase" ]
train
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/Converter/ListConverter.php#L147-L178
perryflynn/PerrysLambda
src/PerrysLambda/Converter/ListConverter.php
ListConverter.newInstance
public function newInstance() { $class = get_called_class(); $instance = new $class(); $instance->setSerializer($this->getSerializer()); $instance->setItemConverter($this->getItemConverter()->newInstance()); return $instance; }
php
public function newInstance() { $class = get_called_class(); $instance = new $class(); $instance->setSerializer($this->getSerializer()); $instance->setItemConverter($this->getItemConverter()->newInstance()); return $instance; }
[ "public", "function", "newInstance", "(", ")", "{", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "instance", "=", "new", "$", "class", "(", ")", ";", "$", "instance", "->", "setSerializer", "(", "$", "this", "->", "getSerializer", "(", ")", ")", ";", "$", "instance", "->", "setItemConverter", "(", "$", "this", "->", "getItemConverter", "(", ")", "->", "newInstance", "(", ")", ")", ";", "return", "$", "instance", ";", "}" ]
Creates a new instance of this class @return \PerrysLambda\Converter\ListConverter
[ "Creates", "a", "new", "instance", "of", "this", "class" ]
train
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/Converter/ListConverter.php#L184-L191
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Framework/Loader/LoaderTrait.php
LoaderTrait.setUp
public function setUp( $entityClass, array $entityProperties, $collectionClass, RepositoryInterface $entityRepository = null ) { @trigger_error(__METHOD__.'() is deprecated and will be removed in 2.0. Please use configureMetadata() instead.', E_USER_DEPRECATED); if ($entityRepository) { @trigger_error('Repository injection throught '.__METHOD__.'() is deprecated and will be removed in 2.0. Please inject it by constructor.', E_USER_DEPRECATED); $this->entityRepository = $entityRepository; } return $this->configureMetadata($entityClass, $entityProperties, $collectionClass); }
php
public function setUp( $entityClass, array $entityProperties, $collectionClass, RepositoryInterface $entityRepository = null ) { @trigger_error(__METHOD__.'() is deprecated and will be removed in 2.0. Please use configureMetadata() instead.', E_USER_DEPRECATED); if ($entityRepository) { @trigger_error('Repository injection throught '.__METHOD__.'() is deprecated and will be removed in 2.0. Please inject it by constructor.', E_USER_DEPRECATED); $this->entityRepository = $entityRepository; } return $this->configureMetadata($entityClass, $entityProperties, $collectionClass); }
[ "public", "function", "setUp", "(", "$", "entityClass", ",", "array", "$", "entityProperties", ",", "$", "collectionClass", ",", "RepositoryInterface", "$", "entityRepository", "=", "null", ")", "{", "@", "trigger_error", "(", "__METHOD__", ".", "'() is deprecated and will be removed in 2.0. Please use configureMetadata() instead.'", ",", "E_USER_DEPRECATED", ")", ";", "if", "(", "$", "entityRepository", ")", "{", "@", "trigger_error", "(", "'Repository injection throught '", ".", "__METHOD__", ".", "'() is deprecated and will be removed in 2.0. Please inject it by constructor.'", ",", "E_USER_DEPRECATED", ")", ";", "$", "this", "->", "entityRepository", "=", "$", "entityRepository", ";", "}", "return", "$", "this", "->", "configureMetadata", "(", "$", "entityClass", ",", "$", "entityProperties", ",", "$", "collectionClass", ")", ";", "}" ]
setUp method. @param string $entityClass @param array $entityProperties @param string $collectionClass @param RepositoryInterface $entityRepository
[ "setUp", "method", "." ]
train
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/LoaderTrait.php#L53-L68
mwyatt/core
src/Cache.php
Cache.create
public function create($fileName, $data) { $path = $this->getPathBase($fileName); if (file_exists($path)) { return; } $data = serialize($data); return file_put_contents($path, $data); }
php
public function create($fileName, $data) { $path = $this->getPathBase($fileName); if (file_exists($path)) { return; } $data = serialize($data); return file_put_contents($path, $data); }
[ "public", "function", "create", "(", "$", "fileName", ",", "$", "data", ")", "{", "$", "path", "=", "$", "this", "->", "getPathBase", "(", "$", "fileName", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "data", "=", "serialize", "(", "$", "data", ")", ";", "return", "file_put_contents", "(", "$", "path", ",", "$", "data", ")", ";", "}" ]
serialises and creates cache file if required if the file already exists, skip this @param string $key example-file-name @param array $data @return bool
[ "serialises", "and", "creates", "cache", "file", "if", "required", "if", "the", "file", "already", "exists", "skip", "this" ]
train
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Cache.php#L76-L87
mwyatt/core
src/Cache.php
Cache.read
public function read($fileName) { $path = $this->getPathBase($fileName); if (!file_exists($path)) { return; } $data = file_get_contents($path); return $this->data = unserialize($data); }
php
public function read($fileName) { $path = $this->getPathBase($fileName); if (!file_exists($path)) { return; } $data = file_get_contents($path); return $this->data = unserialize($data); }
[ "public", "function", "read", "(", "$", "fileName", ")", "{", "$", "path", "=", "$", "this", "->", "getPathBase", "(", "$", "fileName", ")", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "data", "=", "file_get_contents", "(", "$", "path", ")", ";", "return", "$", "this", "->", "data", "=", "unserialize", "(", "$", "data", ")", ";", "}" ]
reads in the cached file, if it exists unserialises and stores in data property @param string $key example-file-name @return bool
[ "reads", "in", "the", "cached", "file", "if", "it", "exists", "unserialises", "and", "stores", "in", "data", "property" ]
train
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Cache.php#L96-L106
mwyatt/core
src/Cache.php
Cache.delete
public function delete($fileName) { $path = $this->getPathBase($fileName); if (!file_exists($path)) { return; } return unlink($path); }
php
public function delete($fileName) { $path = $this->getPathBase($fileName); if (!file_exists($path)) { return; } return unlink($path); }
[ "public", "function", "delete", "(", "$", "fileName", ")", "{", "$", "path", "=", "$", "this", "->", "getPathBase", "(", "$", "fileName", ")", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "return", ";", "}", "return", "unlink", "(", "$", "path", ")", ";", "}" ]
removes the file from the cache @param string $key @return bool
[ "removes", "the", "file", "from", "the", "cache" ]
train
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Cache.php#L114-L123
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.getModel
public function getModel() { if(null === $this->model) { $mainService = $this->getServiceLocator()->get('neobazaar.service.main'); $this->model = $mainService->getDocumentEntityRepository(); } return $this->model; }
php
public function getModel() { if(null === $this->model) { $mainService = $this->getServiceLocator()->get('neobazaar.service.main'); $this->model = $mainService->getDocumentEntityRepository(); } return $this->model; }
[ "public", "function", "getModel", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "model", ")", "{", "$", "mainService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'neobazaar.service.main'", ")", ";", "$", "this", "->", "model", "=", "$", "mainService", "->", "getDocumentEntityRepository", "(", ")", ";", "}", "return", "$", "this", "->", "model", ";", "}" ]
Get the model
[ "Get", "the", "model" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L78-L85
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.checkOptions
public function checkOptions(MvcEvent $e) { $matches = $e->getRouteMatch(); $response = $e->getResponse(); $request = $e->getRequest(); $method = $request->getMethod(); // test if we matched an individual resource, and then test // if we allow the particular request method if ($matches->getParam('id', false)) { if (!in_array($method, $this->allowedResourceMethods)) { $response->setStatusCode(405); return $response; } return; } // We matched a collection; test if we allow the particular request // method if (!in_array($method, $this->allowedCollectionMethods)) { $response->setStatusCode(405); return $response; } }
php
public function checkOptions(MvcEvent $e) { $matches = $e->getRouteMatch(); $response = $e->getResponse(); $request = $e->getRequest(); $method = $request->getMethod(); // test if we matched an individual resource, and then test // if we allow the particular request method if ($matches->getParam('id', false)) { if (!in_array($method, $this->allowedResourceMethods)) { $response->setStatusCode(405); return $response; } return; } // We matched a collection; test if we allow the particular request // method if (!in_array($method, $this->allowedCollectionMethods)) { $response->setStatusCode(405); return $response; } }
[ "public", "function", "checkOptions", "(", "MvcEvent", "$", "e", ")", "{", "$", "matches", "=", "$", "e", "->", "getRouteMatch", "(", ")", ";", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "$", "request", "=", "$", "e", "->", "getRequest", "(", ")", ";", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "// test if we matched an individual resource, and then test", "// if we allow the particular request method", "if", "(", "$", "matches", "->", "getParam", "(", "'id'", ",", "false", ")", ")", "{", "if", "(", "!", "in_array", "(", "$", "method", ",", "$", "this", "->", "allowedResourceMethods", ")", ")", "{", "$", "response", "->", "setStatusCode", "(", "405", ")", ";", "return", "$", "response", ";", "}", "return", ";", "}", "// We matched a collection; test if we allow the particular request ", "// method", "if", "(", "!", "in_array", "(", "$", "method", ",", "$", "this", "->", "allowedCollectionMethods", ")", ")", "{", "$", "response", "->", "setStatusCode", "(", "405", ")", ";", "return", "$", "response", ";", "}", "}" ]
Checks that is an allowed method @param Zend\Mvc\MvcEvent $e @return void|Zend\Http\Response
[ "Checks", "that", "is", "an", "allowed", "method" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L104-L127
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.injectLinkHeader
public function injectLinkHeader(MvcEvent $e) { $response = $e->getResponse(); $headers = $response->getHeaders(); // $headers->addHeaderLine('Link', sprintf( // '<%s>; rel="describedby"', // $this->url()->fromRoute('static-classified-service') // )); $headers->addHeaderLine('Access-Control-Allow-Origin', '*'); $headers->addHeaderLine('Access-Control-Allow-Methods', 'POST PUT DELETE GET'); }
php
public function injectLinkHeader(MvcEvent $e) { $response = $e->getResponse(); $headers = $response->getHeaders(); // $headers->addHeaderLine('Link', sprintf( // '<%s>; rel="describedby"', // $this->url()->fromRoute('static-classified-service') // )); $headers->addHeaderLine('Access-Control-Allow-Origin', '*'); $headers->addHeaderLine('Access-Control-Allow-Methods', 'POST PUT DELETE GET'); }
[ "public", "function", "injectLinkHeader", "(", "MvcEvent", "$", "e", ")", "{", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "// \t$headers->addHeaderLine('Link', sprintf(", "// \t\t\t'<%s>; rel=\"describedby\"',", "// \t\t\t$this->url()->fromRoute('static-classified-service')", "// \t));", "$", "headers", "->", "addHeaderLine", "(", "'Access-Control-Allow-Origin'", ",", "'*'", ")", ";", "$", "headers", "->", "addHeaderLine", "(", "'Access-Control-Allow-Methods'", ",", "'POST PUT DELETE GET'", ")", ";", "}" ]
Inject documentation link header to the response @param Zend\Mvc\MvcEvent $e @return void
[ "Inject", "documentation", "link", "header", "to", "the", "response" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L135-L146
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.getList
public function getList() { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); // 1) getting params $page = (int) $this->params()->fromQuery("page", 1); $category = $this->params()->fromQuery("category", "usato"); $purpose = $this->params()->fromQuery("purpose", "compravendita"); $location = $this->params()->fromQuery("location", "italia"); $limit = 30; $offset = ($page * $limit) - $limit; $returnSelect = true; // 2) Discard useless params and prepare them to be passed to the model $params = $this->requestToSearchParams($this->params()->fromQuery()); $params = is_array($params) ? $params + compact('returnSelect', 'offset', 'limit') : array(); if(empty($params)) { return new JsonModel(array()); } // 3) get only for current user? $onlyCurrentUser = (bool) $this->params()->fromQuery("current", false); $k = 0; foreach($params['field'] as $f) { if('current' == $f || 'user' == $f) { unset($params['field'][$k]); unset($params['value'][$k]); } $k++; } if($onlyCurrentUser) { if($this->zfcUserAuthentication()->hasIdentity()) { $identity = $this->zfcUserAuthentication()->getIdentity(); // $params['field'][] = 'user'; // $params['value'][] = sha1('neo' . $identity->getUserId() . 'bazaar'); $params['field'][] = 'account'; $params['value'][] = sha1('neo' . $identity->getUserId() . 'bazaar'); } else { // Questo è necessario per non far restituire la lista completa se l'utente non è connesso $params['field'][] = 'account'; $params['value'][] = sha1('usernotconnected'); } } // 4) all classifieds? This should be requested only by the admin, will not use sphinx if((bool) $this->params()->fromQuery("full", false)) { if($this->zfcUserAuthentication()->hasIdentity()) { $params = $this->params()->fromQuery(); $identity = $this->zfcUserAuthentication()->getIdentity(); $userModel = $this->getServiceLocator()->get('user.model.user'); $userModel->init($identity, $this->getServiceLocator()); if(!$userModel->getIsAdmin()) { return new JsonModel(array()); } $paginator = $this->getServiceLocator()->get('document.paginator.classifiedFull'); $paginator->build($params); $data = array(); foreach($paginator as $post) { $file = $this->getServiceLocator()->get('document.model.classifiedAdminListing'); $data[] = $file->init($post); } $routeName = 'DocumentAdminClassified/page'; $routeParams = array('page' => $this->params()->fromQuery("page", 1)); $queryParams = array('full' => 1, 'user' => $this->params()->fromQuery("user")); $data = $this->getModel()->getPaginationData($this->getServiceLocator(), $paginator, $data, $routeName, $routeParams, $queryParams); return new JsonModel($data); } } // 5) Pass param to the model and get the data $data = $this->getModel()->getList($params, $this->getServiceLocator()); return new JsonModel($data); }
php
public function getList() { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); // 1) getting params $page = (int) $this->params()->fromQuery("page", 1); $category = $this->params()->fromQuery("category", "usato"); $purpose = $this->params()->fromQuery("purpose", "compravendita"); $location = $this->params()->fromQuery("location", "italia"); $limit = 30; $offset = ($page * $limit) - $limit; $returnSelect = true; // 2) Discard useless params and prepare them to be passed to the model $params = $this->requestToSearchParams($this->params()->fromQuery()); $params = is_array($params) ? $params + compact('returnSelect', 'offset', 'limit') : array(); if(empty($params)) { return new JsonModel(array()); } // 3) get only for current user? $onlyCurrentUser = (bool) $this->params()->fromQuery("current", false); $k = 0; foreach($params['field'] as $f) { if('current' == $f || 'user' == $f) { unset($params['field'][$k]); unset($params['value'][$k]); } $k++; } if($onlyCurrentUser) { if($this->zfcUserAuthentication()->hasIdentity()) { $identity = $this->zfcUserAuthentication()->getIdentity(); // $params['field'][] = 'user'; // $params['value'][] = sha1('neo' . $identity->getUserId() . 'bazaar'); $params['field'][] = 'account'; $params['value'][] = sha1('neo' . $identity->getUserId() . 'bazaar'); } else { // Questo è necessario per non far restituire la lista completa se l'utente non è connesso $params['field'][] = 'account'; $params['value'][] = sha1('usernotconnected'); } } // 4) all classifieds? This should be requested only by the admin, will not use sphinx if((bool) $this->params()->fromQuery("full", false)) { if($this->zfcUserAuthentication()->hasIdentity()) { $params = $this->params()->fromQuery(); $identity = $this->zfcUserAuthentication()->getIdentity(); $userModel = $this->getServiceLocator()->get('user.model.user'); $userModel->init($identity, $this->getServiceLocator()); if(!$userModel->getIsAdmin()) { return new JsonModel(array()); } $paginator = $this->getServiceLocator()->get('document.paginator.classifiedFull'); $paginator->build($params); $data = array(); foreach($paginator as $post) { $file = $this->getServiceLocator()->get('document.model.classifiedAdminListing'); $data[] = $file->init($post); } $routeName = 'DocumentAdminClassified/page'; $routeParams = array('page' => $this->params()->fromQuery("page", 1)); $queryParams = array('full' => 1, 'user' => $this->params()->fromQuery("user")); $data = $this->getModel()->getPaginationData($this->getServiceLocator(), $paginator, $data, $routeName, $routeParams, $queryParams); return new JsonModel($data); } } // 5) Pass param to the model and get the data $data = $this->getModel()->getList($params, $this->getServiceLocator()); return new JsonModel($data); }
[ "public", "function", "getList", "(", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_200", ")", ";", "// 1) getting params", "$", "page", "=", "(", "int", ")", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"page\"", ",", "1", ")", ";", "$", "category", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"category\"", ",", "\"usato\"", ")", ";", "$", "purpose", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"purpose\"", ",", "\"compravendita\"", ")", ";", "$", "location", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"location\"", ",", "\"italia\"", ")", ";", "$", "limit", "=", "30", ";", "$", "offset", "=", "(", "$", "page", "*", "$", "limit", ")", "-", "$", "limit", ";", "$", "returnSelect", "=", "true", ";", "// 2) Discard useless params and prepare them to be passed to the model", "$", "params", "=", "$", "this", "->", "requestToSearchParams", "(", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", ")", ")", ";", "$", "params", "=", "is_array", "(", "$", "params", ")", "?", "$", "params", "+", "compact", "(", "'returnSelect'", ",", "'offset'", ",", "'limit'", ")", ":", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "return", "new", "JsonModel", "(", "array", "(", ")", ")", ";", "}", "// 3) get only for current user?", "$", "onlyCurrentUser", "=", "(", "bool", ")", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"current\"", ",", "false", ")", ";", "$", "k", "=", "0", ";", "foreach", "(", "$", "params", "[", "'field'", "]", "as", "$", "f", ")", "{", "if", "(", "'current'", "==", "$", "f", "||", "'user'", "==", "$", "f", ")", "{", "unset", "(", "$", "params", "[", "'field'", "]", "[", "$", "k", "]", ")", ";", "unset", "(", "$", "params", "[", "'value'", "]", "[", "$", "k", "]", ")", ";", "}", "$", "k", "++", ";", "}", "if", "(", "$", "onlyCurrentUser", ")", "{", "if", "(", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "hasIdentity", "(", ")", ")", "{", "$", "identity", "=", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "getIdentity", "(", ")", ";", "// \t\t\t\t$params['field'][] = 'user';", "// \t\t\t\t$params['value'][] = sha1('neo' . $identity->getUserId() . 'bazaar');", "$", "params", "[", "'field'", "]", "[", "]", "=", "'account'", ";", "$", "params", "[", "'value'", "]", "[", "]", "=", "sha1", "(", "'neo'", ".", "$", "identity", "->", "getUserId", "(", ")", ".", "'bazaar'", ")", ";", "}", "else", "{", "// Questo è necessario per non far restituire la lista completa se l'utente non è connesso", "$", "params", "[", "'field'", "]", "[", "]", "=", "'account'", ";", "$", "params", "[", "'value'", "]", "[", "]", "=", "sha1", "(", "'usernotconnected'", ")", ";", "}", "}", "// 4) all classifieds? This should be requested only by the admin, will not use sphinx", "if", "(", "(", "bool", ")", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"full\"", ",", "false", ")", ")", "{", "if", "(", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "hasIdentity", "(", ")", ")", "{", "$", "params", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", ")", ";", "$", "identity", "=", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "getIdentity", "(", ")", ";", "$", "userModel", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'user.model.user'", ")", ";", "$", "userModel", "->", "init", "(", "$", "identity", ",", "$", "this", "->", "getServiceLocator", "(", ")", ")", ";", "if", "(", "!", "$", "userModel", "->", "getIsAdmin", "(", ")", ")", "{", "return", "new", "JsonModel", "(", "array", "(", ")", ")", ";", "}", "$", "paginator", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.paginator.classifiedFull'", ")", ";", "$", "paginator", "->", "build", "(", "$", "params", ")", ";", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "paginator", "as", "$", "post", ")", "{", "$", "file", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.model.classifiedAdminListing'", ")", ";", "$", "data", "[", "]", "=", "$", "file", "->", "init", "(", "$", "post", ")", ";", "}", "$", "routeName", "=", "'DocumentAdminClassified/page'", ";", "$", "routeParams", "=", "array", "(", "'page'", "=>", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"page\"", ",", "1", ")", ")", ";", "$", "queryParams", "=", "array", "(", "'full'", "=>", "1", ",", "'user'", "=>", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "\"user\"", ")", ")", ";", "$", "data", "=", "$", "this", "->", "getModel", "(", ")", "->", "getPaginationData", "(", "$", "this", "->", "getServiceLocator", "(", ")", ",", "$", "paginator", ",", "$", "data", ",", "$", "routeName", ",", "$", "routeParams", ",", "$", "queryParams", ")", ";", "return", "new", "JsonModel", "(", "$", "data", ")", ";", "}", "}", "// 5) Pass param to the model and get the data", "$", "data", "=", "$", "this", "->", "getModel", "(", ")", "->", "getList", "(", "$", "params", ",", "$", "this", "->", "getServiceLocator", "(", ")", ")", ";", "return", "new", "JsonModel", "(", "$", "data", ")", ";", "}" ]
Respond to HTTP GET method without :id @see \Zend\Mvc\Controller\AbstractRestfulController::getList()
[ "Respond", "to", "HTTP", "GET", "method", "without", ":", "id" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L152-L231
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.get
public function get($id) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); try { $data = $classifiedService->get($id); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $data = new \StdClass(); } return new JsonModel(array( 'data' => $data )); }
php
public function get($id) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); try { $data = $classifiedService->get($id); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $data = new \StdClass(); } return new JsonModel(array( 'data' => $data )); }
[ "public", "function", "get", "(", "$", "id", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_200", ")", ";", "$", "classifiedService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.service.classified'", ")", ";", "try", "{", "$", "data", "=", "$", "classifiedService", "->", "get", "(", "$", "id", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "data", "=", "new", "\\", "StdClass", "(", ")", ";", "}", "return", "new", "JsonModel", "(", "array", "(", "'data'", "=>", "$", "data", ")", ")", ";", "}" ]
Respond to HTTP GET method with :id @see \Zend\Mvc\Controller\AbstractRestfulController::get()
[ "Respond", "to", "HTTP", "GET", "method", "with", ":", "id" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L237-L255
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.create
public function create($data) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_201); $request = $this->getRequest(); $content = $request->getContent(); $content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array(); $post = array_merge_recursive( $request->getPost()->toArray(), $content ); // Inject user data if connected checking if it is not the admin // write better this part, peraphs in some service or using doctrine $main = $this->getServiceLocator()->get('neobazaar.service.main'); $userRepository = $main->getUserEntityRepository(); if($this->zfcUserAuthentication()->hasIdentity()) { $identity = $this->zfcUserAuthentication()->getIdentity(); $userModel = new UserModel($identity, $this->getServiceLocator()); $classifiedId = isset($post['document']) && isset($post['document']['id']) ? $post['document']['id'] : null; // Set identity values in any case!! $post['user'] = array ( 'email' => $identity->getEmail(), 'name' => $identity->getName(), 'id' => $userRepository->getEncryptedId($identity->getUserId()) ); // admin that want to edit other user classified, // set the correct user to the data. if($userModel->isAdmin && null !== $classifiedId) { // must check if the classified owner is the admin $documentRepository = $main->getDocumentEntityRepository(); $classified = $documentRepository->findByEncryptedId($classifiedId, 'documentId'); if(null !== $classified) { if($classified->getUser()->getUserId() == $identity->getUserId()) { $name = $identity->getName(); $post['user'] = array( 'email' => $identity->getEmail(), 'name' => strlen($name) > 2 ? $name : 'xx', 'id' => $userRepository->getEncryptedId($identity->getUserId()) ); } else { $user = $userRepository->find($classified->getUser()->getUserId()); $name = $user->getName(); $post['user'] = array( 'email' => $user->getEmail(), 'name' => strlen($name) > 2 ? $name : 'xx', 'id' => $userRepository->getEncryptedId($user->getUserId()) ); } } } } try { $classifiedService = $this->getServiceLocator()->get('document.service.classified'); $document = $classifiedService->save($post); $data = array( 'status' => 'success', 'message' => $document->getDocumentId() ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $data = @unserialize($e->getMessage()); if(!is_array($data)) { $data = array( 'status' => 'danger', 'message' => $e->getMessage() ); } } return new JsonModel($data); }
php
public function create($data) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_201); $request = $this->getRequest(); $content = $request->getContent(); $content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array(); $post = array_merge_recursive( $request->getPost()->toArray(), $content ); // Inject user data if connected checking if it is not the admin // write better this part, peraphs in some service or using doctrine $main = $this->getServiceLocator()->get('neobazaar.service.main'); $userRepository = $main->getUserEntityRepository(); if($this->zfcUserAuthentication()->hasIdentity()) { $identity = $this->zfcUserAuthentication()->getIdentity(); $userModel = new UserModel($identity, $this->getServiceLocator()); $classifiedId = isset($post['document']) && isset($post['document']['id']) ? $post['document']['id'] : null; // Set identity values in any case!! $post['user'] = array ( 'email' => $identity->getEmail(), 'name' => $identity->getName(), 'id' => $userRepository->getEncryptedId($identity->getUserId()) ); // admin that want to edit other user classified, // set the correct user to the data. if($userModel->isAdmin && null !== $classifiedId) { // must check if the classified owner is the admin $documentRepository = $main->getDocumentEntityRepository(); $classified = $documentRepository->findByEncryptedId($classifiedId, 'documentId'); if(null !== $classified) { if($classified->getUser()->getUserId() == $identity->getUserId()) { $name = $identity->getName(); $post['user'] = array( 'email' => $identity->getEmail(), 'name' => strlen($name) > 2 ? $name : 'xx', 'id' => $userRepository->getEncryptedId($identity->getUserId()) ); } else { $user = $userRepository->find($classified->getUser()->getUserId()); $name = $user->getName(); $post['user'] = array( 'email' => $user->getEmail(), 'name' => strlen($name) > 2 ? $name : 'xx', 'id' => $userRepository->getEncryptedId($user->getUserId()) ); } } } } try { $classifiedService = $this->getServiceLocator()->get('document.service.classified'); $document = $classifiedService->save($post); $data = array( 'status' => 'success', 'message' => $document->getDocumentId() ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $data = @unserialize($e->getMessage()); if(!is_array($data)) { $data = array( 'status' => 'danger', 'message' => $e->getMessage() ); } } return new JsonModel($data); }
[ "public", "function", "create", "(", "$", "data", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_201", ")", ";", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "content", "=", "$", "request", "->", "getContent", "(", ")", ";", "$", "content", "=", "!", "empty", "(", "$", "content", ")", "?", "Json", "::", "decode", "(", "$", "content", ",", "Json", "::", "TYPE_ARRAY", ")", ":", "array", "(", ")", ";", "$", "post", "=", "array_merge_recursive", "(", "$", "request", "->", "getPost", "(", ")", "->", "toArray", "(", ")", ",", "$", "content", ")", ";", "// Inject user data if connected checking if it is not the admin", "// write better this part, peraphs in some service or using doctrine", "$", "main", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'neobazaar.service.main'", ")", ";", "$", "userRepository", "=", "$", "main", "->", "getUserEntityRepository", "(", ")", ";", "if", "(", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "hasIdentity", "(", ")", ")", "{", "$", "identity", "=", "$", "this", "->", "zfcUserAuthentication", "(", ")", "->", "getIdentity", "(", ")", ";", "$", "userModel", "=", "new", "UserModel", "(", "$", "identity", ",", "$", "this", "->", "getServiceLocator", "(", ")", ")", ";", "$", "classifiedId", "=", "isset", "(", "$", "post", "[", "'document'", "]", ")", "&&", "isset", "(", "$", "post", "[", "'document'", "]", "[", "'id'", "]", ")", "?", "$", "post", "[", "'document'", "]", "[", "'id'", "]", ":", "null", ";", "// Set identity values in any case!!", "$", "post", "[", "'user'", "]", "=", "array", "(", "'email'", "=>", "$", "identity", "->", "getEmail", "(", ")", ",", "'name'", "=>", "$", "identity", "->", "getName", "(", ")", ",", "'id'", "=>", "$", "userRepository", "->", "getEncryptedId", "(", "$", "identity", "->", "getUserId", "(", ")", ")", ")", ";", "// admin that want to edit other user classified, ", "// set the correct user to the data.", "if", "(", "$", "userModel", "->", "isAdmin", "&&", "null", "!==", "$", "classifiedId", ")", "{", "// must check if the classified owner is the admin", "$", "documentRepository", "=", "$", "main", "->", "getDocumentEntityRepository", "(", ")", ";", "$", "classified", "=", "$", "documentRepository", "->", "findByEncryptedId", "(", "$", "classifiedId", ",", "'documentId'", ")", ";", "if", "(", "null", "!==", "$", "classified", ")", "{", "if", "(", "$", "classified", "->", "getUser", "(", ")", "->", "getUserId", "(", ")", "==", "$", "identity", "->", "getUserId", "(", ")", ")", "{", "$", "name", "=", "$", "identity", "->", "getName", "(", ")", ";", "$", "post", "[", "'user'", "]", "=", "array", "(", "'email'", "=>", "$", "identity", "->", "getEmail", "(", ")", ",", "'name'", "=>", "strlen", "(", "$", "name", ")", ">", "2", "?", "$", "name", ":", "'xx'", ",", "'id'", "=>", "$", "userRepository", "->", "getEncryptedId", "(", "$", "identity", "->", "getUserId", "(", ")", ")", ")", ";", "}", "else", "{", "$", "user", "=", "$", "userRepository", "->", "find", "(", "$", "classified", "->", "getUser", "(", ")", "->", "getUserId", "(", ")", ")", ";", "$", "name", "=", "$", "user", "->", "getName", "(", ")", ";", "$", "post", "[", "'user'", "]", "=", "array", "(", "'email'", "=>", "$", "user", "->", "getEmail", "(", ")", ",", "'name'", "=>", "strlen", "(", "$", "name", ")", ">", "2", "?", "$", "name", ":", "'xx'", ",", "'id'", "=>", "$", "userRepository", "->", "getEncryptedId", "(", "$", "user", "->", "getUserId", "(", ")", ")", ")", ";", "}", "}", "}", "}", "try", "{", "$", "classifiedService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.service.classified'", ")", ";", "$", "document", "=", "$", "classifiedService", "->", "save", "(", "$", "post", ")", ";", "$", "data", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "$", "document", "->", "getDocumentId", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "data", "=", "@", "unserialize", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "array", "(", "'status'", "=>", "'danger'", ",", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "new", "JsonModel", "(", "$", "data", ")", ";", "}" ]
Respond to HTTP POST method with data, without :id @see \Zend\Mvc\Controller\AbstractRestfulController::create()
[ "Respond", "to", "HTTP", "POST", "method", "with", "data", "without", ":", "id" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L261-L341
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.update
public function update($id, $data) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_201); $returnData = ''; $action = strtolower($this->params()->fromQuery('action')); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); switch($action) { case 'activation': try { $classifiedService->activate($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio attivato con successo. Ti ricordiamo che potrebbero essere necessarie alcune ore prima di poter visualizzare l\'annuncio.' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; case 'disableenable': try { $classifiedService->enableDisable($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio modificato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; case 'touch': try { $classifiedService->touch($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio aggiornato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; } return new JsonModel($returnData); }
php
public function update($id, $data) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_201); $returnData = ''; $action = strtolower($this->params()->fromQuery('action')); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); switch($action) { case 'activation': try { $classifiedService->activate($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio attivato con successo. Ti ricordiamo che potrebbero essere necessarie alcune ore prima di poter visualizzare l\'annuncio.' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; case 'disableenable': try { $classifiedService->enableDisable($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio modificato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; case 'touch': try { $classifiedService->touch($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio aggiornato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; } return new JsonModel($returnData); }
[ "public", "function", "update", "(", "$", "id", ",", "$", "data", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_201", ")", ";", "$", "returnData", "=", "''", ";", "$", "action", "=", "strtolower", "(", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "'action'", ")", ")", ";", "$", "classifiedService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.service.classified'", ")", ";", "switch", "(", "$", "action", ")", "{", "case", "'activation'", ":", "try", "{", "$", "classifiedService", "->", "activate", "(", "$", "id", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "'Annuncio attivato con successo. Ti ricordiamo che potrebbero essere \n\t\t\t\t\t\t\tnecessarie alcune ore prima di poter visualizzare l\\'annuncio.'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'danger'", ",", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "break", ";", "case", "'disableenable'", ":", "try", "{", "$", "classifiedService", "->", "enableDisable", "(", "$", "id", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "'Annuncio modificato con successo'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'danger'", ",", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "break", ";", "case", "'touch'", ":", "try", "{", "$", "classifiedService", "->", "touch", "(", "$", "id", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "'Annuncio aggiornato con successo'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'danger'", ",", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "break", ";", "}", "return", "new", "JsonModel", "(", "$", "returnData", ")", ";", "}" ]
Respond to HTTP PUT method with data, with :id Utilizzao per attivazione/disattivazione annuncio @see \Zend\Mvc\Controller\AbstractRestfulController::update()
[ "Respond", "to", "HTTP", "PUT", "method", "with", "data", "with", ":", "id", "Utilizzao", "per", "attivazione", "/", "disattivazione", "annuncio" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L348-L410
kaiohken1982/NeobazaarDocumentModule
src/Document/Controller/ClassifiedController.php
ClassifiedController.delete
public function delete($id) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); $request = $this->getRequest(); $content = $request->getContent(); $content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array(); $post = array_merge_recursive( $request->getPost()->toArray(), $content ); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); $returnData = ''; $action = strtolower($id); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); switch($action) { case 'bulk': $ids = $this->params()->fromQuery('ids', array()); $ids = !is_array($ids) ? explode(",", $ids) : $ids; $success = 0; $error = 0; foreach($ids as $id) { try { $classifiedService->delete($id); $success++; } catch(\Exception $e) { $error++; }; } $returnData = array( 'status' => 'success', 'message' => 'Annunci eliminati con successo (' . $success . '/' . $error . ')' ); break; default: try { $classifiedService->delete($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio eliminato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; } return new JsonModel($returnData); }
php
public function delete($id) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_200); $request = $this->getRequest(); $content = $request->getContent(); $content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array(); $post = array_merge_recursive( $request->getPost()->toArray(), $content ); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); $returnData = ''; $action = strtolower($id); $classifiedService = $this->getServiceLocator()->get('document.service.classified'); switch($action) { case 'bulk': $ids = $this->params()->fromQuery('ids', array()); $ids = !is_array($ids) ? explode(",", $ids) : $ids; $success = 0; $error = 0; foreach($ids as $id) { try { $classifiedService->delete($id); $success++; } catch(\Exception $e) { $error++; }; } $returnData = array( 'status' => 'success', 'message' => 'Annunci eliminati con successo (' . $success . '/' . $error . ')' ); break; default: try { $classifiedService->delete($id); $returnData = array( 'status' => 'success', 'message' => 'Annuncio eliminato con successo' ); } catch(\Exception $e) { $this->getResponse() ->setStatusCode(Response::STATUS_CODE_500); $returnData = array( 'status' => 'danger', 'message' => $e->getMessage() ); } break; } return new JsonModel($returnData); }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_200", ")", ";", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "content", "=", "$", "request", "->", "getContent", "(", ")", ";", "$", "content", "=", "!", "empty", "(", "$", "content", ")", "?", "Json", "::", "decode", "(", "$", "content", ",", "Json", "::", "TYPE_ARRAY", ")", ":", "array", "(", ")", ";", "$", "post", "=", "array_merge_recursive", "(", "$", "request", "->", "getPost", "(", ")", "->", "toArray", "(", ")", ",", "$", "content", ")", ";", "$", "classifiedService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.service.classified'", ")", ";", "$", "returnData", "=", "''", ";", "$", "action", "=", "strtolower", "(", "$", "id", ")", ";", "$", "classifiedService", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'document.service.classified'", ")", ";", "switch", "(", "$", "action", ")", "{", "case", "'bulk'", ":", "$", "ids", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "'ids'", ",", "array", "(", ")", ")", ";", "$", "ids", "=", "!", "is_array", "(", "$", "ids", ")", "?", "explode", "(", "\",\"", ",", "$", "ids", ")", ":", "$", "ids", ";", "$", "success", "=", "0", ";", "$", "error", "=", "0", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "try", "{", "$", "classifiedService", "->", "delete", "(", "$", "id", ")", ";", "$", "success", "++", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "error", "++", ";", "}", ";", "}", "$", "returnData", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "'Annunci eliminati con successo ('", ".", "$", "success", ".", "'/'", ".", "$", "error", ".", "')'", ")", ";", "break", ";", "default", ":", "try", "{", "$", "classifiedService", "->", "delete", "(", "$", "id", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'success'", ",", "'message'", "=>", "'Annuncio eliminato con successo'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "Response", "::", "STATUS_CODE_500", ")", ";", "$", "returnData", "=", "array", "(", "'status'", "=>", "'danger'", ",", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "break", ";", "}", "return", "new", "JsonModel", "(", "$", "returnData", ")", ";", "}" ]
Respond to HTTP DELETE method with :id @see \Zend\Mvc\Controller\AbstractRestfulController::delete()
[ "Respond", "to", "HTTP", "DELETE", "method", "with", ":", "id" ]
train
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Controller/ClassifiedController.php#L416-L473
AnonymPHP/Anonym-Database
Traits/Builder.php
Builder.buildQuery
private function buildQuery($pattern, $args) { if (count($args['parameters']) > 0) { $string = $pattern[0]; } else { $string = $pattern[1]; } if (preg_match_all("/:(\w+)/", $string, $match)) { $match = $match[0]; $values = array_values($args); return str_replace($match, $values, $string); } }
php
private function buildQuery($pattern, $args) { if (count($args['parameters']) > 0) { $string = $pattern[0]; } else { $string = $pattern[1]; } if (preg_match_all("/:(\w+)/", $string, $match)) { $match = $match[0]; $values = array_values($args); return str_replace($match, $values, $string); } }
[ "private", "function", "buildQuery", "(", "$", "pattern", ",", "$", "args", ")", "{", "if", "(", "count", "(", "$", "args", "[", "'parameters'", "]", ")", ">", "0", ")", "{", "$", "string", "=", "$", "pattern", "[", "0", "]", ";", "}", "else", "{", "$", "string", "=", "$", "pattern", "[", "1", "]", ";", "}", "if", "(", "preg_match_all", "(", "\"/:(\\w+)/\"", ",", "$", "string", ",", "$", "match", ")", ")", "{", "$", "match", "=", "$", "match", "[", "0", "]", ";", "$", "values", "=", "array_values", "(", "$", "args", ")", ";", "return", "str_replace", "(", "$", "match", ",", "$", "values", ",", "$", "string", ")", ";", "}", "}" ]
create the a sql query @param array $pattern @param array $args @return mixed
[ "create", "the", "a", "sql", "query" ]
train
https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Traits/Builder.php#L19-L36
Blipfoto/php-sdk
src/Blipfoto/Api/Client.php
Client.endpoint
public function endpoint() { $endpoint = $this->getset('endpoint', func_get_args()); return $this->validateEndpoint($endpoint ?: self::URI_API); }
php
public function endpoint() { $endpoint = $this->getset('endpoint', func_get_args()); return $this->validateEndpoint($endpoint ?: self::URI_API); }
[ "public", "function", "endpoint", "(", ")", "{", "$", "endpoint", "=", "$", "this", "->", "getset", "(", "'endpoint'", ",", "func_get_args", "(", ")", ")", ";", "return", "$", "this", "->", "validateEndpoint", "(", "$", "endpoint", "?", ":", "self", "::", "URI_API", ")", ";", "}" ]
Get and optionally set the endpoint. @param string $endpoint (optional) @return string
[ "Get", "and", "optionally", "set", "the", "endpoint", "." ]
train
https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Client.php#L104-L107
Blipfoto/php-sdk
src/Blipfoto/Api/Client.php
Client.authorizationEndpoint
public function authorizationEndpoint() { $endpoint = $this->getset('authorization_endpoint', func_get_args()); return $this->validateEndpoint($endpoint ?: self::URI_AUTHORIZE); }
php
public function authorizationEndpoint() { $endpoint = $this->getset('authorization_endpoint', func_get_args()); return $this->validateEndpoint($endpoint ?: self::URI_AUTHORIZE); }
[ "public", "function", "authorizationEndpoint", "(", ")", "{", "$", "endpoint", "=", "$", "this", "->", "getset", "(", "'authorization_endpoint'", ",", "func_get_args", "(", ")", ")", ";", "return", "$", "this", "->", "validateEndpoint", "(", "$", "endpoint", "?", ":", "self", "::", "URI_AUTHORIZE", ")", ";", "}" ]
Get and optionally set the authorization endpoint. @param string $authorization_endpoint (optional) @return string
[ "Get", "and", "optionally", "set", "the", "authorization", "endpoint", "." ]
train
https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Client.php#L115-L118
Blipfoto/php-sdk
src/Blipfoto/Api/Client.php
Client.run
protected function run($method, $args) { $request = $this->request(); $request->method($method); $request->resource(array_shift($args)); if (count($args)) { $request->params(array_shift($args)); } if (count($args)) { $request->files(array_shift($args)); } return $request->send(); }
php
protected function run($method, $args) { $request = $this->request(); $request->method($method); $request->resource(array_shift($args)); if (count($args)) { $request->params(array_shift($args)); } if (count($args)) { $request->files(array_shift($args)); } return $request->send(); }
[ "protected", "function", "run", "(", "$", "method", ",", "$", "args", ")", "{", "$", "request", "=", "$", "this", "->", "request", "(", ")", ";", "$", "request", "->", "method", "(", "$", "method", ")", ";", "$", "request", "->", "resource", "(", "array_shift", "(", "$", "args", ")", ")", ";", "if", "(", "count", "(", "$", "args", ")", ")", "{", "$", "request", "->", "params", "(", "array_shift", "(", "$", "args", ")", ")", ";", "}", "if", "(", "count", "(", "$", "args", ")", ")", "{", "$", "request", "->", "files", "(", "array_shift", "(", "$", "args", ")", ")", ";", "}", "return", "$", "request", "->", "send", "(", ")", ";", "}" ]
Convenience method for sending a request and returning a response. @return Response @throws OAuthException|ApiResponseException
[ "Convenience", "method", "for", "sending", "a", "request", "and", "returning", "a", "response", "." ]
train
https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Client.php#L173-L184
lanfisis/deflection
src/Deflection/Element/Classes.php
Classes.isAbstract
public function isAbstract($status = null) { $this->is_abstract = $status !== null ? $status : $this->is_abstract; return $this->is_abstract ; }
php
public function isAbstract($status = null) { $this->is_abstract = $status !== null ? $status : $this->is_abstract; return $this->is_abstract ; }
[ "public", "function", "isAbstract", "(", "$", "status", "=", "null", ")", "{", "$", "this", "->", "is_abstract", "=", "$", "status", "!==", "null", "?", "$", "status", ":", "$", "this", "->", "is_abstract", ";", "return", "$", "this", "->", "is_abstract", ";", "}" ]
Is an abstract class @return \Deflection\Element\Classes
[ "Is", "an", "abstract", "class" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Classes.php#L70-L74
lanfisis/deflection
src/Deflection/Element/Classes.php
Classes.addUse
public function addUse($class, $alias = null) { $as = $alias == null ? (int)(count($this->uses) + 1) : $alias; $this->uses[$as] = (string)$class; return $this; }
php
public function addUse($class, $alias = null) { $as = $alias == null ? (int)(count($this->uses) + 1) : $alias; $this->uses[$as] = (string)$class; return $this; }
[ "public", "function", "addUse", "(", "$", "class", ",", "$", "alias", "=", "null", ")", "{", "$", "as", "=", "$", "alias", "==", "null", "?", "(", "int", ")", "(", "count", "(", "$", "this", "->", "uses", ")", "+", "1", ")", ":", "$", "alias", ";", "$", "this", "->", "uses", "[", "$", "as", "]", "=", "(", "string", ")", "$", "class", ";", "return", "$", "this", ";", "}" ]
Add use @param string $class Class name @param string|null $alias Use alias @return \Deflection\Element\Classes
[ "Add", "use" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Classes.php#L164-L169
lanfisis/deflection
src/Deflection/Element/Classes.php
Classes.addParam
public function addParam(\Deflection\Element\Param $param) { $element = $param->getElement(); $this->params = array_merge($this->params, array(''), $element); return $this; }
php
public function addParam(\Deflection\Element\Param $param) { $element = $param->getElement(); $this->params = array_merge($this->params, array(''), $element); return $this; }
[ "public", "function", "addParam", "(", "\\", "Deflection", "\\", "Element", "\\", "Param", "$", "param", ")", "{", "$", "element", "=", "$", "param", "->", "getElement", "(", ")", ";", "$", "this", "->", "params", "=", "array_merge", "(", "$", "this", "->", "params", ",", "array", "(", "''", ")", ",", "$", "element", ")", ";", "return", "$", "this", ";", "}" ]
Add function to structure @param \Deflection\Element\Param $param Param @return \Deflection\Element\Classes
[ "Add", "function", "to", "structure" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Classes.php#L188-L193
lanfisis/deflection
src/Deflection/Element/Classes.php
Classes.addFunction
public function addFunction(\Deflection\Element\Functions $function) { $element = $function->getElement(); $this->functions = array_merge($this->functions, array(''), $element); return $this; }
php
public function addFunction(\Deflection\Element\Functions $function) { $element = $function->getElement(); $this->functions = array_merge($this->functions, array(''), $element); return $this; }
[ "public", "function", "addFunction", "(", "\\", "Deflection", "\\", "Element", "\\", "Functions", "$", "function", ")", "{", "$", "element", "=", "$", "function", "->", "getElement", "(", ")", ";", "$", "this", "->", "functions", "=", "array_merge", "(", "$", "this", "->", "functions", ",", "array", "(", "''", ")", ",", "$", "element", ")", ";", "return", "$", "this", ";", "}" ]
Add param to structure @param \Deflection\Element\Functions $function Function @return \Deflection\Element\Classes
[ "Add", "param", "to", "structure" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Classes.php#L212-L217
lanfisis/deflection
src/Deflection/Element/Classes.php
Classes.getElement
public function getElement() { if ($this->getDocblock()) { $this->setLines($this->getDocblock()->getElement()); $this->addBlankLine(); } if ($this->getNamespace()) { $this->addLine('namespace '.$this->getNamespace().';'); $this->addBlankLine(); } if (count($this->getUse()) > 0) { foreach ($this->getUse() as $alias => $class) { $line = 'use '.$class; if (is_string($alias)) { $line .= ' as '.$alias; } $this->addLine($line.';'); } $this->addBlankLine(); } if ($this->getName()) { $this->addLine( ($this->isAbstract() ? 'abstract ' : '').'class '.$this->getName() ); } if ($this->getExtends()) { $this->addLine(array('extends '.$this->getExtends())); } if (count($this->getImplements()) > 0) { $this->addLine(array('implements '.implode(', ', $this->getImplements()))); } $this->startBlock(); $this->addLine($this->getParams()); $this->addLine($this->getFunctions()); $this->endBlock(); return $this->getLines(); }
php
public function getElement() { if ($this->getDocblock()) { $this->setLines($this->getDocblock()->getElement()); $this->addBlankLine(); } if ($this->getNamespace()) { $this->addLine('namespace '.$this->getNamespace().';'); $this->addBlankLine(); } if (count($this->getUse()) > 0) { foreach ($this->getUse() as $alias => $class) { $line = 'use '.$class; if (is_string($alias)) { $line .= ' as '.$alias; } $this->addLine($line.';'); } $this->addBlankLine(); } if ($this->getName()) { $this->addLine( ($this->isAbstract() ? 'abstract ' : '').'class '.$this->getName() ); } if ($this->getExtends()) { $this->addLine(array('extends '.$this->getExtends())); } if (count($this->getImplements()) > 0) { $this->addLine(array('implements '.implode(', ', $this->getImplements()))); } $this->startBlock(); $this->addLine($this->getParams()); $this->addLine($this->getFunctions()); $this->endBlock(); return $this->getLines(); }
[ "public", "function", "getElement", "(", ")", "{", "if", "(", "$", "this", "->", "getDocblock", "(", ")", ")", "{", "$", "this", "->", "setLines", "(", "$", "this", "->", "getDocblock", "(", ")", "->", "getElement", "(", ")", ")", ";", "$", "this", "->", "addBlankLine", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getNamespace", "(", ")", ")", "{", "$", "this", "->", "addLine", "(", "'namespace '", ".", "$", "this", "->", "getNamespace", "(", ")", ".", "';'", ")", ";", "$", "this", "->", "addBlankLine", "(", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "getUse", "(", ")", ")", ">", "0", ")", "{", "foreach", "(", "$", "this", "->", "getUse", "(", ")", "as", "$", "alias", "=>", "$", "class", ")", "{", "$", "line", "=", "'use '", ".", "$", "class", ";", "if", "(", "is_string", "(", "$", "alias", ")", ")", "{", "$", "line", ".=", "' as '", ".", "$", "alias", ";", "}", "$", "this", "->", "addLine", "(", "$", "line", ".", "';'", ")", ";", "}", "$", "this", "->", "addBlankLine", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getName", "(", ")", ")", "{", "$", "this", "->", "addLine", "(", "(", "$", "this", "->", "isAbstract", "(", ")", "?", "'abstract '", ":", "''", ")", ".", "'class '", ".", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getExtends", "(", ")", ")", "{", "$", "this", "->", "addLine", "(", "array", "(", "'extends '", ".", "$", "this", "->", "getExtends", "(", ")", ")", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "getImplements", "(", ")", ")", ">", "0", ")", "{", "$", "this", "->", "addLine", "(", "array", "(", "'implements '", ".", "implode", "(", "', '", ",", "$", "this", "->", "getImplements", "(", ")", ")", ")", ")", ";", "}", "$", "this", "->", "startBlock", "(", ")", ";", "$", "this", "->", "addLine", "(", "$", "this", "->", "getParams", "(", ")", ")", ";", "$", "this", "->", "addLine", "(", "$", "this", "->", "getFunctions", "(", ")", ")", ";", "$", "this", "->", "endBlock", "(", ")", ";", "return", "$", "this", "->", "getLines", "(", ")", ";", "}" ]
Generate docblock @return array
[ "Generate", "docblock" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Element/Classes.php#L234-L270
lasallecms/lasallecms-l5-lasallecmsapi-pkg
database/migrations/2016_01_25_190724_create_failed_jobs_table.php
CreateFailedJobsTable.up
public function up() { Schema::create('failed_jobs', function (Blueprint $table) { $table->increments('id'); $table->text('connection'); $table->text('queue'); $table->longText('payload'); $table->timestamp('failed_at'); }); }
php
public function up() { Schema::create('failed_jobs', function (Blueprint $table) { $table->increments('id'); $table->text('connection'); $table->text('queue'); $table->longText('payload'); $table->timestamp('failed_at'); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "'failed_jobs'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "'id'", ")", ";", "$", "table", "->", "text", "(", "'connection'", ")", ";", "$", "table", "->", "text", "(", "'queue'", ")", ";", "$", "table", "->", "longText", "(", "'payload'", ")", ";", "$", "table", "->", "timestamp", "(", "'failed_at'", ")", ";", "}", ")", ";", "}" ]
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/database/migrations/2016_01_25_190724_create_failed_jobs_table.php#L48-L57
miaoxing/user
src/Controller/Users.php
Users.createAction
public function createAction($req) { // 1. 调用注册接口 $user = wei()->user(); $ret = $user->register($req); if ($ret['code'] !== 1) { return $this->ret($ret); } // 2. 登录用户 $loginRet = wei()->curUser->loginById($user['id']); if ($loginRet['code'] !== 1) { return $loginRet; } return $this->ret($ret); }
php
public function createAction($req) { // 1. 调用注册接口 $user = wei()->user(); $ret = $user->register($req); if ($ret['code'] !== 1) { return $this->ret($ret); } // 2. 登录用户 $loginRet = wei()->curUser->loginById($user['id']); if ($loginRet['code'] !== 1) { return $loginRet; } return $this->ret($ret); }
[ "public", "function", "createAction", "(", "$", "req", ")", "{", "// 1. 调用注册接口", "$", "user", "=", "wei", "(", ")", "->", "user", "(", ")", ";", "$", "ret", "=", "$", "user", "->", "register", "(", "$", "req", ")", ";", "if", "(", "$", "ret", "[", "'code'", "]", "!==", "1", ")", "{", "return", "$", "this", "->", "ret", "(", "$", "ret", ")", ";", "}", "// 2. 登录用户", "$", "loginRet", "=", "wei", "(", ")", "->", "curUser", "->", "loginById", "(", "$", "user", "[", "'id'", "]", ")", ";", "if", "(", "$", "loginRet", "[", "'code'", "]", "!==", "1", ")", "{", "return", "$", "loginRet", ";", "}", "return", "$", "this", "->", "ret", "(", "$", "ret", ")", ";", "}" ]
用户注册 @param $req @return \Wei\Response
[ "用户注册" ]
train
https://github.com/miaoxing/user/blob/d94e52f64a0151ba7202c857b373394ad09e06ce/src/Controller/Users.php#L95-L111
miaoxing/user
src/Controller/Users.php
Users.editAction
public function editAction($req) { $user = $this->curUser; $enableMobileVerify = $this->setting('user.enableMobileVerify', false); $isMobileVerified = $user->isMobileVerified(); // 如果认证了手机号码,又没启用认证功能,就不显示手机号 $hideMobile = $isMobileVerified && !$enableMobileVerify; $this->page->setTitle('个人信息'); return get_defined_vars(); }
php
public function editAction($req) { $user = $this->curUser; $enableMobileVerify = $this->setting('user.enableMobileVerify', false); $isMobileVerified = $user->isMobileVerified(); // 如果认证了手机号码,又没启用认证功能,就不显示手机号 $hideMobile = $isMobileVerified && !$enableMobileVerify; $this->page->setTitle('个人信息'); return get_defined_vars(); }
[ "public", "function", "editAction", "(", "$", "req", ")", "{", "$", "user", "=", "$", "this", "->", "curUser", ";", "$", "enableMobileVerify", "=", "$", "this", "->", "setting", "(", "'user.enableMobileVerify'", ",", "false", ")", ";", "$", "isMobileVerified", "=", "$", "user", "->", "isMobileVerified", "(", ")", ";", "// 如果认证了手机号码,又没启用认证功能,就不显示手机号", "$", "hideMobile", "=", "$", "isMobileVerified", "&&", "!", "$", "enableMobileVerify", ";", "$", "this", "->", "page", "->", "setTitle", "(", "'个人信息');", "", "", "return", "get_defined_vars", "(", ")", ";", "}" ]
个人信息页面 @return array
[ "个人信息页面" ]
train
https://github.com/miaoxing/user/blob/d94e52f64a0151ba7202c857b373394ad09e06ce/src/Controller/Users.php#L118-L131
miaoxing/user
src/Controller/Users.php
Users.loginAction
public function loginAction(Request $req) { if ($req->isPost()) { if (wei()->setting('user.enableLoginCaptcha')) { $ret = wei()->captcha->check($req['captcha']); if ($ret['code'] !== 1) { $ret['captchaErr'] = true; return $this->ret($ret); } } $ret = $this->curUser->login($req); return $this->ret($ret); } else { if (!$this->setting('user.enableLogin', true)) { return $this->err($this->setting('user.disableLoginTips', '登录功能未启用')); } $this->page->setTitle('登录'); return get_defined_vars(); } }
php
public function loginAction(Request $req) { if ($req->isPost()) { if (wei()->setting('user.enableLoginCaptcha')) { $ret = wei()->captcha->check($req['captcha']); if ($ret['code'] !== 1) { $ret['captchaErr'] = true; return $this->ret($ret); } } $ret = $this->curUser->login($req); return $this->ret($ret); } else { if (!$this->setting('user.enableLogin', true)) { return $this->err($this->setting('user.disableLoginTips', '登录功能未启用')); } $this->page->setTitle('登录'); return get_defined_vars(); } }
[ "public", "function", "loginAction", "(", "Request", "$", "req", ")", "{", "if", "(", "$", "req", "->", "isPost", "(", ")", ")", "{", "if", "(", "wei", "(", ")", "->", "setting", "(", "'user.enableLoginCaptcha'", ")", ")", "{", "$", "ret", "=", "wei", "(", ")", "->", "captcha", "->", "check", "(", "$", "req", "[", "'captcha'", "]", ")", ";", "if", "(", "$", "ret", "[", "'code'", "]", "!==", "1", ")", "{", "$", "ret", "[", "'captchaErr'", "]", "=", "true", ";", "return", "$", "this", "->", "ret", "(", "$", "ret", ")", ";", "}", "}", "$", "ret", "=", "$", "this", "->", "curUser", "->", "login", "(", "$", "req", ")", ";", "return", "$", "this", "->", "ret", "(", "$", "ret", ")", ";", "}", "else", "{", "if", "(", "!", "$", "this", "->", "setting", "(", "'user.enableLogin'", ",", "true", ")", ")", "{", "return", "$", "this", "->", "err", "(", "$", "this", "->", "setting", "(", "'user.disableLoginTips'", ",", "'登录功能未启用'));", "", "", "", "}", "$", "this", "->", "page", "->", "setTitle", "(", "'登录');", "", "", "return", "get_defined_vars", "(", ")", ";", "}", "}" ]
用户登录 @param Request $req @return array|\Wei\Response
[ "用户登录" ]
train
https://github.com/miaoxing/user/blob/d94e52f64a0151ba7202c857b373394ad09e06ce/src/Controller/Users.php#L152-L175
miaoxing/user
src/Controller/Users.php
Users.logoutAction
public function logoutAction($req) { wei()->curUser->logout(); $next = $req('next', $this->request->getReferer()); return $this->response->redirect($next); }
php
public function logoutAction($req) { wei()->curUser->logout(); $next = $req('next', $this->request->getReferer()); return $this->response->redirect($next); }
[ "public", "function", "logoutAction", "(", "$", "req", ")", "{", "wei", "(", ")", "->", "curUser", "->", "logout", "(", ")", ";", "$", "next", "=", "$", "req", "(", "'next'", ",", "$", "this", "->", "request", "->", "getReferer", "(", ")", ")", ";", "return", "$", "this", "->", "response", "->", "redirect", "(", "$", "next", ")", ";", "}" ]
用户退出登录 @param $req @return \Wei\Response
[ "用户退出登录" ]
train
https://github.com/miaoxing/user/blob/d94e52f64a0151ba7202c857b373394ad09e06ce/src/Controller/Users.php#L183-L190
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.isAllowed
public function isAllowed($role, $resource) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } if(false === is_string($resource)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR); } if(true === isset($this -> permissions[$role][$resource])) { return $this -> permissions[$role][$resource]; } return false; }
php
public function isAllowed($role, $resource) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } if(false === is_string($resource)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR); } if(true === isset($this -> permissions[$role][$resource])) { return $this -> permissions[$role][$resource]; } return false; }
[ "public", "function", "isAllowed", "(", "$", "role", ",", "$", "resource", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "role", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "role", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "is_string", "(", "$", "resource", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "resource", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "true", "===", "isset", "(", "$", "this", "->", "permissions", "[", "$", "role", "]", "[", "$", "resource", "]", ")", ")", "{", "return", "$", "this", "->", "permissions", "[", "$", "role", "]", "[", "$", "resource", "]", ";", "}", "return", "false", ";", "}" ]
Returns if a role is allowed access to the resource @param string $role @param string $resource @return boolean
[ "Returns", "if", "a", "role", "is", "allowed", "access", "to", "the", "resource" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L29-L44
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.inherit
public function inherit($roles, $inherits) { if(true === is_string($roles)) { $roles = [$roles]; } if(true === is_string($inherits)) { $inherits = [$inherits]; } if(false === is_array($roles)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR); } if(false === is_array($inherits)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($inherits)), E_USER_ERROR); } foreach($inherits as $inherit) { if(true === isset($this -> permissions[$inherit])) { foreach($this -> permissions[$inherit] as $resource => $allowed) { foreach($roles as $role) { $this -> fill($role, $resource, $allowed); } } } } return $this; }
php
public function inherit($roles, $inherits) { if(true === is_string($roles)) { $roles = [$roles]; } if(true === is_string($inherits)) { $inherits = [$inherits]; } if(false === is_array($roles)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR); } if(false === is_array($inherits)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($inherits)), E_USER_ERROR); } foreach($inherits as $inherit) { if(true === isset($this -> permissions[$inherit])) { foreach($this -> permissions[$inherit] as $resource => $allowed) { foreach($roles as $role) { $this -> fill($role, $resource, $allowed); } } } } return $this; }
[ "public", "function", "inherit", "(", "$", "roles", ",", "$", "inherits", ")", "{", "if", "(", "true", "===", "is_string", "(", "$", "roles", ")", ")", "{", "$", "roles", "=", "[", "$", "roles", "]", ";", "}", "if", "(", "true", "===", "is_string", "(", "$", "inherits", ")", ")", "{", "$", "inherits", "=", "[", "$", "inherits", "]", ";", "}", "if", "(", "false", "===", "is_array", "(", "$", "roles", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string or array, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "roles", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "is_array", "(", "$", "inherits", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be of the type string or array, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "inherits", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "foreach", "(", "$", "inherits", "as", "$", "inherit", ")", "{", "if", "(", "true", "===", "isset", "(", "$", "this", "->", "permissions", "[", "$", "inherit", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "permissions", "[", "$", "inherit", "]", "as", "$", "resource", "=>", "$", "allowed", ")", "{", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "$", "this", "->", "fill", "(", "$", "role", ",", "$", "resource", ",", "$", "allowed", ")", ";", "}", "}", "}", "}", "return", "$", "this", ";", "}" ]
Let a single or multiple roles inherit the resources of other single or multiple roles @param string|array $roles @param string|array $inherits @return sFire\Permissions\ACL
[ "Let", "a", "single", "or", "multiple", "roles", "inherit", "the", "resources", "of", "other", "single", "or", "multiple", "roles" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L86-L119
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.getRoles
public function getRoles() { $roles = []; foreach($this -> permissions as $role => $permissions) { $roles[$role] = $this -> getRole($role); } return $roles; }
php
public function getRoles() { $roles = []; foreach($this -> permissions as $role => $permissions) { $roles[$role] = $this -> getRole($role); } return $roles; }
[ "public", "function", "getRoles", "(", ")", "{", "$", "roles", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "permissions", "as", "$", "role", "=>", "$", "permissions", ")", "{", "$", "roles", "[", "$", "role", "]", "=", "$", "this", "->", "getRole", "(", "$", "role", ")", ";", "}", "return", "$", "roles", ";", "}" ]
Returns all the roles as an array @return array
[ "Returns", "all", "the", "roles", "as", "an", "array" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L126-L135
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.getRole
public function getRole($role) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } foreach($this -> permissions as $type => $resources) { if($role === $type) { $p = new Resources(); $p -> setResources($resources); return $p; } } return null; }
php
public function getRole($role) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } foreach($this -> permissions as $type => $resources) { if($role === $type) { $p = new Resources(); $p -> setResources($resources); return $p; } } return null; }
[ "public", "function", "getRole", "(", "$", "role", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "role", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "role", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "foreach", "(", "$", "this", "->", "permissions", "as", "$", "type", "=>", "$", "resources", ")", "{", "if", "(", "$", "role", "===", "$", "type", ")", "{", "$", "p", "=", "new", "Resources", "(", ")", ";", "$", "p", "->", "setResources", "(", "$", "resources", ")", ";", "return", "$", "p", ";", "}", "}", "return", "null", ";", "}" ]
Returns the roles in array @return array
[ "Returns", "the", "roles", "in", "array" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L142-L160
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.getResources
public function getResources($match = null) { if(null !== $match && false === is_string($match)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($match)), E_USER_ERROR); } $permissions = []; $match = null === $match ? '.*?' : $match; foreach($this -> permissions as $permission) { foreach($permission as $type => $value) { if(preg_match(sprintf('#%s#', str_replace('#', '\#', $match)), $type)) { $permissions[] = $type; } } } return array_unique($permissions); }
php
public function getResources($match = null) { if(null !== $match && false === is_string($match)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($match)), E_USER_ERROR); } $permissions = []; $match = null === $match ? '.*?' : $match; foreach($this -> permissions as $permission) { foreach($permission as $type => $value) { if(preg_match(sprintf('#%s#', str_replace('#', '\#', $match)), $type)) { $permissions[] = $type; } } } return array_unique($permissions); }
[ "public", "function", "getResources", "(", "$", "match", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "match", "&&", "false", "===", "is_string", "(", "$", "match", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "match", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "permissions", "=", "[", "]", ";", "$", "match", "=", "null", "===", "$", "match", "?", "'.*?'", ":", "$", "match", ";", "foreach", "(", "$", "this", "->", "permissions", "as", "$", "permission", ")", "{", "foreach", "(", "$", "permission", "as", "$", "type", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "sprintf", "(", "'#%s#'", ",", "str_replace", "(", "'#'", ",", "'\\#'", ",", "$", "match", ")", ")", ",", "$", "type", ")", ")", "{", "$", "permissions", "[", "]", "=", "$", "type", ";", "}", "}", "}", "return", "array_unique", "(", "$", "permissions", ")", ";", "}" ]
Returns all the resourses in array @param string|null $match @return array
[ "Returns", "all", "the", "resourses", "in", "array" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L168-L188
Kris-Kuiper/sFire-Framework
src/Permissions/ACL.php
ACL.fill
private function fill($roles, $resources, $allow) { if(true === is_string($roles)) { $roles = [$roles]; } if(true === is_string($resources)) { $resources = [$resources]; } if(false === is_array($roles)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR); } if(false === is_array($resources)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR); } if(false === is_bool($allow)) { return trigger_error(sprintf('Argument 3 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($allow)), E_USER_ERROR); } foreach($roles as $role) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } if(false === isset($this -> permissions[$role])) { $this -> permissions[$role] = []; } foreach($resources as $resource) { if(false === is_string($resource)) { return trigger_error(sprintf('Argument 2 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR); } $this -> permissions[$role][$resource] = $allow; } } return $this; }
php
private function fill($roles, $resources, $allow) { if(true === is_string($roles)) { $roles = [$roles]; } if(true === is_string($resources)) { $resources = [$resources]; } if(false === is_array($roles)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($roles)), E_USER_ERROR); } if(false === is_array($resources)) { return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($resources)), E_USER_ERROR); } if(false === is_bool($allow)) { return trigger_error(sprintf('Argument 3 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($allow)), E_USER_ERROR); } foreach($roles as $role) { if(false === is_string($role)) { return trigger_error(sprintf('Argument 1 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($role)), E_USER_ERROR); } if(false === isset($this -> permissions[$role])) { $this -> permissions[$role] = []; } foreach($resources as $resource) { if(false === is_string($resource)) { return trigger_error(sprintf('Argument 2 passed to %s() must contain only strings, "%s" given', __METHOD__, gettype($resource)), E_USER_ERROR); } $this -> permissions[$role][$resource] = $allow; } } return $this; }
[ "private", "function", "fill", "(", "$", "roles", ",", "$", "resources", ",", "$", "allow", ")", "{", "if", "(", "true", "===", "is_string", "(", "$", "roles", ")", ")", "{", "$", "roles", "=", "[", "$", "roles", "]", ";", "}", "if", "(", "true", "===", "is_string", "(", "$", "resources", ")", ")", "{", "$", "resources", "=", "[", "$", "resources", "]", ";", "}", "if", "(", "false", "===", "is_array", "(", "$", "roles", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string or array, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "roles", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "is_array", "(", "$", "resources", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must be of the type string or array, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "resources", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "is_bool", "(", "$", "allow", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 3 passed to %s() must be of the type boolean, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "allow", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "role", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must contain only strings, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "role", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "isset", "(", "$", "this", "->", "permissions", "[", "$", "role", "]", ")", ")", "{", "$", "this", "->", "permissions", "[", "$", "role", "]", "=", "[", "]", ";", "}", "foreach", "(", "$", "resources", "as", "$", "resource", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "resource", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 2 passed to %s() must contain only strings, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "resource", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "permissions", "[", "$", "role", "]", "[", "$", "resource", "]", "=", "$", "allow", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add a new permission entry @param string|array $roles @param string|array $resources @param boolean $allow @return sFire\Permissions\ACL
[ "Add", "a", "new", "permission", "entry" ]
train
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Permissions/ACL.php#L198-L241
Wedeto/IO
src/File.php
File.touch
public function touch() { // Check permissions $path = $this->getFullPath(); if (file_exists($path)) { if (!is_writable($path)) Path::makeWritable($path); } touch($path); Path::setPermissions($path); }
php
public function touch() { // Check permissions $path = $this->getFullPath(); if (file_exists($path)) { if (!is_writable($path)) Path::makeWritable($path); } touch($path); Path::setPermissions($path); }
[ "public", "function", "touch", "(", ")", "{", "// Check permissions", "$", "path", "=", "$", "this", "->", "getFullPath", "(", ")", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "if", "(", "!", "is_writable", "(", "$", "path", ")", ")", "Path", "::", "makeWritable", "(", "$", "path", ")", ";", "}", "touch", "(", "$", "path", ")", ";", "Path", "::", "setPermissions", "(", "$", "path", ")", ";", "}" ]
Touch the file, updating its permissions
[ "Touch", "the", "file", "updating", "its", "permissions" ]
train
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L47-L59
Wedeto/IO
src/File.php
File.getMime
public function getMime() { if (!$this->mime) { $type = FileType::getFromFile($this->getFullPath()); $this->mime = $type->getMimeType(); } return $this->mime; }
php
public function getMime() { if (!$this->mime) { $type = FileType::getFromFile($this->getFullPath()); $this->mime = $type->getMimeType(); } return $this->mime; }
[ "public", "function", "getMime", "(", ")", "{", "if", "(", "!", "$", "this", "->", "mime", ")", "{", "$", "type", "=", "FileType", "::", "getFromFile", "(", "$", "this", "->", "getFullPath", "(", ")", ")", ";", "$", "this", "->", "mime", "=", "$", "type", "->", "getMimeType", "(", ")", ";", "}", "return", "$", "this", "->", "mime", ";", "}" ]
Return the appropriate mime type for the file
[ "Return", "the", "appropriate", "mime", "type", "for", "the", "file" ]
train
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L84-L92
Wedeto/IO
src/File.php
File.open
public function open(string $mode) { $read = strpbrk($mode, "r+") !== false; $write = strpbrk($mode, "waxc+") !== false; $x = strpbrk($mode, "x") !== false; $path = $this->getFullPath(); $fh = @fopen($path, $mode); if (is_resource($fh)) return $fh; if ($x && file_exists($path)) throw new IOException("File already exists: " . $path); if ($write && !is_writable($path)) throw new IOException("File is not writable: " . $path); if ($read && !is_readable($path)) throw new IOException("File is not readable: " . $path); throw new IOException("Invalid mode for opening file: " . $mode); }
php
public function open(string $mode) { $read = strpbrk($mode, "r+") !== false; $write = strpbrk($mode, "waxc+") !== false; $x = strpbrk($mode, "x") !== false; $path = $this->getFullPath(); $fh = @fopen($path, $mode); if (is_resource($fh)) return $fh; if ($x && file_exists($path)) throw new IOException("File already exists: " . $path); if ($write && !is_writable($path)) throw new IOException("File is not writable: " . $path); if ($read && !is_readable($path)) throw new IOException("File is not readable: " . $path); throw new IOException("Invalid mode for opening file: " . $mode); }
[ "public", "function", "open", "(", "string", "$", "mode", ")", "{", "$", "read", "=", "strpbrk", "(", "$", "mode", ",", "\"r+\"", ")", "!==", "false", ";", "$", "write", "=", "strpbrk", "(", "$", "mode", ",", "\"waxc+\"", ")", "!==", "false", ";", "$", "x", "=", "strpbrk", "(", "$", "mode", ",", "\"x\"", ")", "!==", "false", ";", "$", "path", "=", "$", "this", "->", "getFullPath", "(", ")", ";", "$", "fh", "=", "@", "fopen", "(", "$", "path", ",", "$", "mode", ")", ";", "if", "(", "is_resource", "(", "$", "fh", ")", ")", "return", "$", "fh", ";", "if", "(", "$", "x", "&&", "file_exists", "(", "$", "path", ")", ")", "throw", "new", "IOException", "(", "\"File already exists: \"", ".", "$", "path", ")", ";", "if", "(", "$", "write", "&&", "!", "is_writable", "(", "$", "path", ")", ")", "throw", "new", "IOException", "(", "\"File is not writable: \"", ".", "$", "path", ")", ";", "if", "(", "$", "read", "&&", "!", "is_readable", "(", "$", "path", ")", ")", "throw", "new", "IOException", "(", "\"File is not readable: \"", ".", "$", "path", ")", ";", "throw", "new", "IOException", "(", "\"Invalid mode for opening file: \"", ".", "$", "mode", ")", ";", "}" ]
Open the file for reading or writing, throwing informative exceptions when it fails. @param string $mode The file opening mode @return resource The opened file resource @throws IOException When opening the file failed. @seealso fopen
[ "Open", "the", "file", "for", "reading", "or", "writing", "throwing", "informative", "exceptions", "when", "it", "fails", "." ]
train
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/File.php#L154-L173
Dhii/placeholder-template-abstract
src/TokenStartAwareTrait.php
TokenStartAwareTrait._setTokenStart
protected function _setTokenStart($delimiter) { if (!is_null($delimiter)) { $delimiter = $this->_normalizeTokenDelimiter($delimiter); } $this->tokenStart = $delimiter; }
php
protected function _setTokenStart($delimiter) { if (!is_null($delimiter)) { $delimiter = $this->_normalizeTokenDelimiter($delimiter); } $this->tokenStart = $delimiter; }
[ "protected", "function", "_setTokenStart", "(", "$", "delimiter", ")", "{", "if", "(", "!", "is_null", "(", "$", "delimiter", ")", ")", "{", "$", "delimiter", "=", "$", "this", "->", "_normalizeTokenDelimiter", "(", "$", "delimiter", ")", ";", "}", "$", "this", "->", "tokenStart", "=", "$", "delimiter", ";", "}" ]
Assigns the token start delimiter. @since [*next-version*] @param Stringable|string|int|float|bool|null $delimiter The delimiter that marks the start of a token. @throws InvalidArgumentException If the delimiter is invalid.
[ "Assigns", "the", "token", "start", "delimiter", "." ]
train
https://github.com/Dhii/placeholder-template-abstract/blob/bfa7cea3b1e078b19bcf59d9a3da63b8c12ed03b/src/TokenStartAwareTrait.php#L43-L50
miaoxing/plugin
src/Service/App.php
App.getNamespaceFromWechatAppId
protected function getNamespaceFromWechatAppId($namespace) { if (substr($namespace, 0, 2) != 'wx') { return false; } wei()->logger->debug('Got wechat appId', ['appId' => $namespace]); $appId = wei()->wechatAccount()->select('appId')->fetchColumn(['applicationId' => $namespace]); if (!$appId) { return false; } $namespace = wei()->appRecord()->select('name')->fetchColumn(['id' => $appId]); wei()->logger->debug('Convert wechat appId to namespace', ['namespace' => $namespace]); return $namespace; }
php
protected function getNamespaceFromWechatAppId($namespace) { if (substr($namespace, 0, 2) != 'wx') { return false; } wei()->logger->debug('Got wechat appId', ['appId' => $namespace]); $appId = wei()->wechatAccount()->select('appId')->fetchColumn(['applicationId' => $namespace]); if (!$appId) { return false; } $namespace = wei()->appRecord()->select('name')->fetchColumn(['id' => $appId]); wei()->logger->debug('Convert wechat appId to namespace', ['namespace' => $namespace]); return $namespace; }
[ "protected", "function", "getNamespaceFromWechatAppId", "(", "$", "namespace", ")", "{", "if", "(", "substr", "(", "$", "namespace", ",", "0", ",", "2", ")", "!=", "'wx'", ")", "{", "return", "false", ";", "}", "wei", "(", ")", "->", "logger", "->", "debug", "(", "'Got wechat appId'", ",", "[", "'appId'", "=>", "$", "namespace", "]", ")", ";", "$", "appId", "=", "wei", "(", ")", "->", "wechatAccount", "(", ")", "->", "select", "(", "'appId'", ")", "->", "fetchColumn", "(", "[", "'applicationId'", "=>", "$", "namespace", "]", ")", ";", "if", "(", "!", "$", "appId", ")", "{", "return", "false", ";", "}", "$", "namespace", "=", "wei", "(", ")", "->", "appRecord", "(", ")", "->", "select", "(", "'name'", ")", "->", "fetchColumn", "(", "[", "'id'", "=>", "$", "appId", "]", ")", ";", "wei", "(", ")", "->", "logger", "->", "debug", "(", "'Convert wechat appId to namespace'", ",", "[", "'namespace'", "=>", "$", "namespace", "]", ")", ";", "return", "$", "namespace", ";", "}" ]
通过微信AppID获取应用的名称 @param string $namespace @return string|false
[ "通过微信AppID获取应用的名称" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L164-L181
miaoxing/plugin
src/Service/App.php
App.getDefaultTemplate
public function getDefaultTemplate($controller = null, $action = null) { $file = lcfirst($controller ?: $this->controller) . '/' . ($action ?: $this->action) . $this->view->getExtension(); $plugin = $this->getPlugin(); return $plugin ? '@' . $plugin . '/' . $file : $file; }
php
public function getDefaultTemplate($controller = null, $action = null) { $file = lcfirst($controller ?: $this->controller) . '/' . ($action ?: $this->action) . $this->view->getExtension(); $plugin = $this->getPlugin(); return $plugin ? '@' . $plugin . '/' . $file : $file; }
[ "public", "function", "getDefaultTemplate", "(", "$", "controller", "=", "null", ",", "$", "action", "=", "null", ")", "{", "$", "file", "=", "lcfirst", "(", "$", "controller", "?", ":", "$", "this", "->", "controller", ")", ".", "'/'", ".", "(", "$", "action", "?", ":", "$", "this", "->", "action", ")", ".", "$", "this", "->", "view", "->", "getExtension", "(", ")", ";", "$", "plugin", "=", "$", "this", "->", "getPlugin", "(", ")", ";", "return", "$", "plugin", "?", "'@'", ".", "$", "plugin", ".", "'/'", ".", "$", "file", ":", "$", "file", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L197-L205
miaoxing/plugin
src/Service/App.php
App.getPlugin
public function getPlugin() { if (!$this->plugin) { $classes = array_reverse($this->getControllerClasses($this->controller)); foreach ($classes as $class) { // 认为第二部分是插件名称 list(, $plugin) = explode('\\', $class, 3); $this->plugin = $this->str->dash($plugin); break; } } return $this->plugin; }
php
public function getPlugin() { if (!$this->plugin) { $classes = array_reverse($this->getControllerClasses($this->controller)); foreach ($classes as $class) { // 认为第二部分是插件名称 list(, $plugin) = explode('\\', $class, 3); $this->plugin = $this->str->dash($plugin); break; } } return $this->plugin; }
[ "public", "function", "getPlugin", "(", ")", "{", "if", "(", "!", "$", "this", "->", "plugin", ")", "{", "$", "classes", "=", "array_reverse", "(", "$", "this", "->", "getControllerClasses", "(", "$", "this", "->", "controller", ")", ")", ";", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "// 认为第二部分是插件名称", "list", "(", ",", "$", "plugin", ")", "=", "explode", "(", "'\\\\'", ",", "$", "class", ",", "3", ")", ";", "$", "this", "->", "plugin", "=", "$", "this", "->", "str", "->", "dash", "(", "$", "plugin", ")", ";", "break", ";", "}", "}", "return", "$", "this", "->", "plugin", ";", "}" ]
获取当前运行的插件名称 @return string
[ "获取当前运行的插件名称" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L234-L248
miaoxing/plugin
src/Service/App.php
App.getRecord
public function getRecord() { $this->record || $this->record = wei()->appRecord() ->tags(false) ->setCacheKey('appName:' . $this->namespace) ->cache(86400) ->find(['name' => $this->namespace]); return $this->record; }
php
public function getRecord() { $this->record || $this->record = wei()->appRecord() ->tags(false) ->setCacheKey('appName:' . $this->namespace) ->cache(86400) ->find(['name' => $this->namespace]); return $this->record; }
[ "public", "function", "getRecord", "(", ")", "{", "$", "this", "->", "record", "||", "$", "this", "->", "record", "=", "wei", "(", ")", "->", "appRecord", "(", ")", "->", "tags", "(", "false", ")", "->", "setCacheKey", "(", "'appName:'", ".", "$", "this", "->", "namespace", ")", "->", "cache", "(", "86400", ")", "->", "find", "(", "[", "'name'", "=>", "$", "this", "->", "namespace", "]", ")", ";", "return", "$", "this", "->", "record", ";", "}" ]
获取App数据表对象 @return \Miaoxing\Plugin\Service\AppRecord
[ "获取App数据表对象" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L255-L264
miaoxing/plugin
src/Service/App.php
App.getId
public function getId() { if (isset($this->ids[$this->namespace])) { return $this->ids[$this->namespace]; } else { return (int) $this->getRecord()->get('id'); } }
php
public function getId() { if (isset($this->ids[$this->namespace])) { return $this->ids[$this->namespace]; } else { return (int) $this->getRecord()->get('id'); } }
[ "public", "function", "getId", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "ids", "[", "$", "this", "->", "namespace", "]", ")", ")", "{", "return", "$", "this", "->", "ids", "[", "$", "this", "->", "namespace", "]", ";", "}", "else", "{", "return", "(", "int", ")", "$", "this", "->", "getRecord", "(", ")", "->", "get", "(", "'id'", ")", ";", "}", "}" ]
Record: 获取当前项目的编号 @return int @throws \Exception
[ "Record", ":", "获取当前项目的编号" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L272-L279
miaoxing/plugin
src/Service/App.php
App.getDbName
public function getDbName($id) { if (!$this->dbNames[$id]) { $record = wei()->appRecord()->findById($id); $this->dbNames[$id] = $record['name']; } return $this->dbNames[$id]; }
php
public function getDbName($id) { if (!$this->dbNames[$id]) { $record = wei()->appRecord()->findById($id); $this->dbNames[$id] = $record['name']; } return $this->dbNames[$id]; }
[ "public", "function", "getDbName", "(", "$", "id", ")", "{", "if", "(", "!", "$", "this", "->", "dbNames", "[", "$", "id", "]", ")", "{", "$", "record", "=", "wei", "(", ")", "->", "appRecord", "(", ")", "->", "findById", "(", "$", "id", ")", ";", "$", "this", "->", "dbNames", "[", "$", "id", "]", "=", "$", "record", "[", "'name'", "]", ";", "}", "return", "$", "this", "->", "dbNames", "[", "$", "id", "]", ";", "}" ]
Repo: 根据应用ID获取应用数据库名称 @param int $id @return string
[ "Repo", ":", "根据应用ID获取应用数据库名称" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L287-L295
miaoxing/plugin
src/Service/App.php
App.handleResponse
public function handleResponse($response) { if ($this->isRet($response)) { return $this->handleRet($response); } elseif (is_array($response)) { $template = $this->getDefaultTemplate(); $file = $this->view->resolveFile($template) ? $template : $this->defaultViewFile; $content = $this->view->render($file, $response); return $this->response->setContent($content); } else { return parent::handleResponse($response); } }
php
public function handleResponse($response) { if ($this->isRet($response)) { return $this->handleRet($response); } elseif (is_array($response)) { $template = $this->getDefaultTemplate(); $file = $this->view->resolveFile($template) ? $template : $this->defaultViewFile; $content = $this->view->render($file, $response); return $this->response->setContent($content); } else { return parent::handleResponse($response); } }
[ "public", "function", "handleResponse", "(", "$", "response", ")", "{", "if", "(", "$", "this", "->", "isRet", "(", "$", "response", ")", ")", "{", "return", "$", "this", "->", "handleRet", "(", "$", "response", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "response", ")", ")", "{", "$", "template", "=", "$", "this", "->", "getDefaultTemplate", "(", ")", ";", "$", "file", "=", "$", "this", "->", "view", "->", "resolveFile", "(", "$", "template", ")", "?", "$", "template", ":", "$", "this", "->", "defaultViewFile", ";", "$", "content", "=", "$", "this", "->", "view", "->", "render", "(", "$", "file", ",", "$", "response", ")", ";", "return", "$", "this", "->", "response", "->", "setContent", "(", "$", "content", ")", ";", "}", "else", "{", "return", "parent", "::", "handleResponse", "(", "$", "response", ")", ";", "}", "}" ]
重写handleResponse,支持Ret结构 @param mixed $response @return Response @throws \Exception
[ "重写handleResponse", "支持Ret结构" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L314-L326
miaoxing/plugin
src/Service/App.php
App.handleRet
protected function handleRet(array $ret) { if ($this->request->acceptJson() || php_sapi_name() == 'cli' || $this->isApi()) { return $this->response->json($ret); } else { $type = isset($ret['retType']) ? $ret['retType'] : ($ret['code'] === 1 ? 'success' : 'warning'); $content = $this->view->render('@plugin/ret/ret.php', $ret + ['type' => $type]); return $this->response->setContent($content); } }
php
protected function handleRet(array $ret) { if ($this->request->acceptJson() || php_sapi_name() == 'cli' || $this->isApi()) { return $this->response->json($ret); } else { $type = isset($ret['retType']) ? $ret['retType'] : ($ret['code'] === 1 ? 'success' : 'warning'); $content = $this->view->render('@plugin/ret/ret.php', $ret + ['type' => $type]); return $this->response->setContent($content); } }
[ "protected", "function", "handleRet", "(", "array", "$", "ret", ")", "{", "if", "(", "$", "this", "->", "request", "->", "acceptJson", "(", ")", "||", "php_sapi_name", "(", ")", "==", "'cli'", "||", "$", "this", "->", "isApi", "(", ")", ")", "{", "return", "$", "this", "->", "response", "->", "json", "(", "$", "ret", ")", ";", "}", "else", "{", "$", "type", "=", "isset", "(", "$", "ret", "[", "'retType'", "]", ")", "?", "$", "ret", "[", "'retType'", "]", ":", "(", "$", "ret", "[", "'code'", "]", "===", "1", "?", "'success'", ":", "'warning'", ")", ";", "$", "content", "=", "$", "this", "->", "view", "->", "render", "(", "'@plugin/ret/ret.php'", ",", "$", "ret", "+", "[", "'type'", "=>", "$", "type", "]", ")", ";", "return", "$", "this", "->", "response", "->", "setContent", "(", "$", "content", ")", ";", "}", "}" ]
转换Ret结构为response @param array $ret @return Response @throws \Exception
[ "转换Ret结构为response" ]
train
https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/App.php#L335-L345
spryker/price-product-merchant-relationship-data-import
src/Spryker/Zed/PriceProductMerchantRelationshipDataImport/Business/Model/PriceProductMerchantRelationshipWriterStep.php
PriceProductMerchantRelationshipWriterStep.execute
public function execute(DataSetInterface $dataSet): void { $priceProductMerchantRelationshipEntity = $this->findExistingPriceProductStoreEntity($dataSet); $idPriceProductStore = $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT_STORE]; if ($priceProductMerchantRelationshipEntity && $priceProductMerchantRelationshipEntity->getFkPriceProductStore() === $idPriceProductStore) { return; } if (!$priceProductMerchantRelationshipEntity) { $priceProductMerchantRelationshipEntity = (new SpyPriceProductMerchantRelationship()) ->setFkMerchantRelationship($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_MERCHANT_RELATIONSHIP]); if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT])) { $priceProductMerchantRelationshipEntity->setFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]); } else { $priceProductMerchantRelationshipEntity->setFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]); } } $priceProductMerchantRelationshipEntity->setFkPriceProductStore($idPriceProductStore); $eventName = $priceProductMerchantRelationshipEntity->isNew() ? PriceProductMerchantRelationshipDataImportConstants::ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_CREATE : PriceProductMerchantRelationshipDataImportConstants::ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_UPDATE; $priceProductMerchantRelationshipEntity->save(); $this->addPublishEvents( $eventName, (int)$priceProductMerchantRelationshipEntity->getPrimaryKey() ); }
php
public function execute(DataSetInterface $dataSet): void { $priceProductMerchantRelationshipEntity = $this->findExistingPriceProductStoreEntity($dataSet); $idPriceProductStore = $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT_STORE]; if ($priceProductMerchantRelationshipEntity && $priceProductMerchantRelationshipEntity->getFkPriceProductStore() === $idPriceProductStore) { return; } if (!$priceProductMerchantRelationshipEntity) { $priceProductMerchantRelationshipEntity = (new SpyPriceProductMerchantRelationship()) ->setFkMerchantRelationship($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_MERCHANT_RELATIONSHIP]); if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT])) { $priceProductMerchantRelationshipEntity->setFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]); } else { $priceProductMerchantRelationshipEntity->setFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]); } } $priceProductMerchantRelationshipEntity->setFkPriceProductStore($idPriceProductStore); $eventName = $priceProductMerchantRelationshipEntity->isNew() ? PriceProductMerchantRelationshipDataImportConstants::ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_CREATE : PriceProductMerchantRelationshipDataImportConstants::ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_UPDATE; $priceProductMerchantRelationshipEntity->save(); $this->addPublishEvents( $eventName, (int)$priceProductMerchantRelationshipEntity->getPrimaryKey() ); }
[ "public", "function", "execute", "(", "DataSetInterface", "$", "dataSet", ")", ":", "void", "{", "$", "priceProductMerchantRelationshipEntity", "=", "$", "this", "->", "findExistingPriceProductStoreEntity", "(", "$", "dataSet", ")", ";", "$", "idPriceProductStore", "=", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRICE_PRODUCT_STORE", "]", ";", "if", "(", "$", "priceProductMerchantRelationshipEntity", "&&", "$", "priceProductMerchantRelationshipEntity", "->", "getFkPriceProductStore", "(", ")", "===", "$", "idPriceProductStore", ")", "{", "return", ";", "}", "if", "(", "!", "$", "priceProductMerchantRelationshipEntity", ")", "{", "$", "priceProductMerchantRelationshipEntity", "=", "(", "new", "SpyPriceProductMerchantRelationship", "(", ")", ")", "->", "setFkMerchantRelationship", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_MERCHANT_RELATIONSHIP", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_ABSTRACT", "]", ")", ")", "{", "$", "priceProductMerchantRelationshipEntity", "->", "setFkProductAbstract", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_ABSTRACT", "]", ")", ";", "}", "else", "{", "$", "priceProductMerchantRelationshipEntity", "->", "setFkProduct", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_CONCRETE", "]", ")", ";", "}", "}", "$", "priceProductMerchantRelationshipEntity", "->", "setFkPriceProductStore", "(", "$", "idPriceProductStore", ")", ";", "$", "eventName", "=", "$", "priceProductMerchantRelationshipEntity", "->", "isNew", "(", ")", "?", "PriceProductMerchantRelationshipDataImportConstants", "::", "ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_CREATE", ":", "PriceProductMerchantRelationshipDataImportConstants", "::", "ENTITY_SPY_PRICE_PRODUCT_MERCHANT_RELATIONSHIP_UPDATE", ";", "$", "priceProductMerchantRelationshipEntity", "->", "save", "(", ")", ";", "$", "this", "->", "addPublishEvents", "(", "$", "eventName", ",", "(", "int", ")", "$", "priceProductMerchantRelationshipEntity", "->", "getPrimaryKey", "(", ")", ")", ";", "}" ]
@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet @return void
[ "@param", "\\", "Spryker", "\\", "Zed", "\\", "DataImport", "\\", "Business", "\\", "Model", "\\", "DataSet", "\\", "DataSetInterface", "$dataSet" ]
train
https://github.com/spryker/price-product-merchant-relationship-data-import/blob/2b96c8a449920daa286e60ce6f98bde0989c7683/src/Spryker/Zed/PriceProductMerchantRelationshipDataImport/Business/Model/PriceProductMerchantRelationshipWriterStep.php#L25-L58
spryker/price-product-merchant-relationship-data-import
src/Spryker/Zed/PriceProductMerchantRelationshipDataImport/Business/Model/PriceProductMerchantRelationshipWriterStep.php
PriceProductMerchantRelationshipWriterStep.findExistingPriceProductStoreEntity
protected function findExistingPriceProductStoreEntity(DataSetInterface $dataSet): ?SpyPriceProductMerchantRelationship { $query = SpyPriceProductMerchantRelationshipQuery::create() ->usePriceProductStoreQuery() ->filterByFkStore($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_STORE]) ->filterByFkCurrency($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_CURRENCY]) ->filterByFkPriceProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT]) ->endUse() ->filterByFkMerchantRelationship($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_MERCHANT_RELATIONSHIP]); if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT])) { $query->filterByFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]); } else { $query->filterByFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]); } return $query->findOne(); }
php
protected function findExistingPriceProductStoreEntity(DataSetInterface $dataSet): ?SpyPriceProductMerchantRelationship { $query = SpyPriceProductMerchantRelationshipQuery::create() ->usePriceProductStoreQuery() ->filterByFkStore($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_STORE]) ->filterByFkCurrency($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_CURRENCY]) ->filterByFkPriceProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT]) ->endUse() ->filterByFkMerchantRelationship($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_MERCHANT_RELATIONSHIP]); if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT])) { $query->filterByFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]); } else { $query->filterByFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]); } return $query->findOne(); }
[ "protected", "function", "findExistingPriceProductStoreEntity", "(", "DataSetInterface", "$", "dataSet", ")", ":", "?", "SpyPriceProductMerchantRelationship", "{", "$", "query", "=", "SpyPriceProductMerchantRelationshipQuery", "::", "create", "(", ")", "->", "usePriceProductStoreQuery", "(", ")", "->", "filterByFkStore", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_STORE", "]", ")", "->", "filterByFkCurrency", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_CURRENCY", "]", ")", "->", "filterByFkPriceProduct", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRICE_PRODUCT", "]", ")", "->", "endUse", "(", ")", "->", "filterByFkMerchantRelationship", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_MERCHANT_RELATIONSHIP", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_ABSTRACT", "]", ")", ")", "{", "$", "query", "->", "filterByFkProductAbstract", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_ABSTRACT", "]", ")", ";", "}", "else", "{", "$", "query", "->", "filterByFkProduct", "(", "$", "dataSet", "[", "PriceProductMerchantRelationshipDataSetInterface", "::", "ID_PRODUCT_CONCRETE", "]", ")", ";", "}", "return", "$", "query", "->", "findOne", "(", ")", ";", "}" ]
@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet @return \Orm\Zed\PriceProductMerchantRelationship\Persistence\SpyPriceProductMerchantRelationship|null
[ "@param", "\\", "Spryker", "\\", "Zed", "\\", "DataImport", "\\", "Business", "\\", "Model", "\\", "DataSet", "\\", "DataSetInterface", "$dataSet" ]
train
https://github.com/spryker/price-product-merchant-relationship-data-import/blob/2b96c8a449920daa286e60ce6f98bde0989c7683/src/Spryker/Zed/PriceProductMerchantRelationshipDataImport/Business/Model/PriceProductMerchantRelationshipWriterStep.php#L65-L82
fiiSoft/fiisoft-console
src/Tools/Console/AbstractCommand.php
AbstractCommand.createPidFile
final protected function createPidFile($pidfilesPath, $pidfilePrefix) { if (!$this->openPidFile($pidfilesPath, $pidfilePrefix, $pidFile)) { $this->output->writeln('Unable to create pid file '.$pidFile); $this->output->writeln('Please be sure pid file can be created in this location.'); $this->output->writeln('Command stopped!'); exit(1); } return $pidFile; }
php
final protected function createPidFile($pidfilesPath, $pidfilePrefix) { if (!$this->openPidFile($pidfilesPath, $pidfilePrefix, $pidFile)) { $this->output->writeln('Unable to create pid file '.$pidFile); $this->output->writeln('Please be sure pid file can be created in this location.'); $this->output->writeln('Command stopped!'); exit(1); } return $pidFile; }
[ "final", "protected", "function", "createPidFile", "(", "$", "pidfilesPath", ",", "$", "pidfilePrefix", ")", "{", "if", "(", "!", "$", "this", "->", "openPidFile", "(", "$", "pidfilesPath", ",", "$", "pidfilePrefix", ",", "$", "pidFile", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "'Unable to create pid file '", ".", "$", "pidFile", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "'Please be sure pid file can be created in this location.'", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "'Command stopped!'", ")", ";", "exit", "(", "1", ")", ";", "}", "return", "$", "pidFile", ";", "}" ]
Create pid file (ind default directory). If pid file cannot be created, stop execution with exit code 1. @param string $pidfilesPath path to directory where pid file will be created @param string $pidfilePrefix prefix for name of pid file @return string path to created pid file
[ "Create", "pid", "file", "(", "ind", "default", "directory", ")", ".", "If", "pid", "file", "cannot", "be", "created", "stop", "execution", "with", "exit", "code", "1", "." ]
train
https://github.com/fiiSoft/fiisoft-console/blob/50e1be6e26429bed5b5b932dc21605ca09161a49/src/Tools/Console/AbstractCommand.php#L95-L105
Wedeto/Log
src/Writer/ExternalLogWriter.php
ExternalLogWriter.write
public function write(string $level, string $message, array $context) { $this->logger->log($level, $message, $context); }
php
public function write(string $level, string $message, array $context) { $this->logger->log($level, $message, $context); }
[ "public", "function", "write", "(", "string", "$", "level", ",", "string", "$", "message", ",", "array", "$", "context", ")", "{", "$", "this", "->", "logger", "->", "log", "(", "$", "level", ",", "$", "message", ",", "$", "context", ")", ";", "}" ]
Write a log message. @param string $level The LogLevel @param string $message The message to write @param array $context The context variables
[ "Write", "a", "log", "message", "." ]
train
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Writer/ExternalLogWriter.php#L64-L67
lanfisis/deflection
src/Deflection/Transformer.php
Transformer.arrayToClassElement
public function arrayToClassElement($definition) { $class = new Classes(); if (isset($definition['docblock'])) { $docblock = $this->arrayToDocblockElement($definition['docblock']); $class->setDocbloc($docblock); } if (isset($definition['namespace'])) { $class->setNamespace($definition['namespace']); } if (isset($definition['name'])) { $class->setName($definition['name']); } if (isset($definition['extends'])) { $class->setExtends($definition['extends']); } if (isset($definition['implements'])) { foreach ($definition['implements'] as $interface) { $class->addImplements($interface); } } if (isset($definition['uses'])) { foreach ($definition['uses'] as $alias => $use) { $alias = is_string($alias) ? $alias : null; $class->addUse($use, $alias); } } if (isset($definition['functions'])) { foreach ($definition['functions'] as $definition) { $function = $this->arrayToFunctionElement($definition); $class->addFunction($function); } } return $class; }
php
public function arrayToClassElement($definition) { $class = new Classes(); if (isset($definition['docblock'])) { $docblock = $this->arrayToDocblockElement($definition['docblock']); $class->setDocbloc($docblock); } if (isset($definition['namespace'])) { $class->setNamespace($definition['namespace']); } if (isset($definition['name'])) { $class->setName($definition['name']); } if (isset($definition['extends'])) { $class->setExtends($definition['extends']); } if (isset($definition['implements'])) { foreach ($definition['implements'] as $interface) { $class->addImplements($interface); } } if (isset($definition['uses'])) { foreach ($definition['uses'] as $alias => $use) { $alias = is_string($alias) ? $alias : null; $class->addUse($use, $alias); } } if (isset($definition['functions'])) { foreach ($definition['functions'] as $definition) { $function = $this->arrayToFunctionElement($definition); $class->addFunction($function); } } return $class; }
[ "public", "function", "arrayToClassElement", "(", "$", "definition", ")", "{", "$", "class", "=", "new", "Classes", "(", ")", ";", "if", "(", "isset", "(", "$", "definition", "[", "'docblock'", "]", ")", ")", "{", "$", "docblock", "=", "$", "this", "->", "arrayToDocblockElement", "(", "$", "definition", "[", "'docblock'", "]", ")", ";", "$", "class", "->", "setDocbloc", "(", "$", "docblock", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'namespace'", "]", ")", ")", "{", "$", "class", "->", "setNamespace", "(", "$", "definition", "[", "'namespace'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'name'", "]", ")", ")", "{", "$", "class", "->", "setName", "(", "$", "definition", "[", "'name'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'extends'", "]", ")", ")", "{", "$", "class", "->", "setExtends", "(", "$", "definition", "[", "'extends'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'implements'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'implements'", "]", "as", "$", "interface", ")", "{", "$", "class", "->", "addImplements", "(", "$", "interface", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "definition", "[", "'uses'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'uses'", "]", "as", "$", "alias", "=>", "$", "use", ")", "{", "$", "alias", "=", "is_string", "(", "$", "alias", ")", "?", "$", "alias", ":", "null", ";", "$", "class", "->", "addUse", "(", "$", "use", ",", "$", "alias", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "definition", "[", "'functions'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'functions'", "]", "as", "$", "definition", ")", "{", "$", "function", "=", "$", "this", "->", "arrayToFunctionElement", "(", "$", "definition", ")", ";", "$", "class", "->", "addFunction", "(", "$", "function", ")", ";", "}", "}", "return", "$", "class", ";", "}" ]
Transform an array to a class element object @param array $definition Class definitoion @return Deflection\Element\Classes
[ "Transform", "an", "array", "to", "a", "class", "element", "object" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L26-L60
lanfisis/deflection
src/Deflection/Transformer.php
Transformer.arrayToDocblockElement
public function arrayToDocblockElement(array $definition) { $docblock = new Docblock(); if (isset($definition['description'])) { $docblock->setDescription($definition['description']); } if (isset($definition['params'])) { foreach ($definition['params'] as $param => $infos) { $type = isset($infos['type']) ? $infos['type']: ''; $description = isset($infos['description']) ? $infos['description'] : ''; $docblock->addVar($param, $type, $description); } } if (isset($definition['return'])) { $docblock->addParam('return', $definition['return']); } if (isset($definition['infos'])) { foreach ($definition['infos'] as $name => $value) { $docblock->addParam($name, $value); } } return $docblock; }
php
public function arrayToDocblockElement(array $definition) { $docblock = new Docblock(); if (isset($definition['description'])) { $docblock->setDescription($definition['description']); } if (isset($definition['params'])) { foreach ($definition['params'] as $param => $infos) { $type = isset($infos['type']) ? $infos['type']: ''; $description = isset($infos['description']) ? $infos['description'] : ''; $docblock->addVar($param, $type, $description); } } if (isset($definition['return'])) { $docblock->addParam('return', $definition['return']); } if (isset($definition['infos'])) { foreach ($definition['infos'] as $name => $value) { $docblock->addParam($name, $value); } } return $docblock; }
[ "public", "function", "arrayToDocblockElement", "(", "array", "$", "definition", ")", "{", "$", "docblock", "=", "new", "Docblock", "(", ")", ";", "if", "(", "isset", "(", "$", "definition", "[", "'description'", "]", ")", ")", "{", "$", "docblock", "->", "setDescription", "(", "$", "definition", "[", "'description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'params'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'params'", "]", "as", "$", "param", "=>", "$", "infos", ")", "{", "$", "type", "=", "isset", "(", "$", "infos", "[", "'type'", "]", ")", "?", "$", "infos", "[", "'type'", "]", ":", "''", ";", "$", "description", "=", "isset", "(", "$", "infos", "[", "'description'", "]", ")", "?", "$", "infos", "[", "'description'", "]", ":", "''", ";", "$", "docblock", "->", "addVar", "(", "$", "param", ",", "$", "type", ",", "$", "description", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "definition", "[", "'return'", "]", ")", ")", "{", "$", "docblock", "->", "addParam", "(", "'return'", ",", "$", "definition", "[", "'return'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'infos'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'infos'", "]", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "docblock", "->", "addParam", "(", "$", "name", ",", "$", "value", ")", ";", "}", "}", "return", "$", "docblock", ";", "}" ]
Returns well formated header with descriptions, param, return, ... @param array $definition Header definition @return Deflection\Element\Docblock
[ "Returns", "well", "formated", "header", "with", "descriptions", "param", "return", "..." ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L69-L91
lanfisis/deflection
src/Deflection/Transformer.php
Transformer.arrayToFunctionElement
public function arrayToFunctionElement(array $definition) { $function = new Functions; if (isset($definition['docblock'])) { $docblock = $this->arrayToDocblockElement($definition['docblock']); $function->setDocbloc($docblock); } if (isset($definition['public'])) { $function->isPublic(true); } if (isset($definition['name'])) { $function->setName($definition['name']); } if (isset($definition['params'])) { foreach ($definition['params'] as $name => $type) { $function->addParam($name, $type); } } if (isset($definition['content'])) { $function->setContent($definition['content']); } return $function; }
php
public function arrayToFunctionElement(array $definition) { $function = new Functions; if (isset($definition['docblock'])) { $docblock = $this->arrayToDocblockElement($definition['docblock']); $function->setDocbloc($docblock); } if (isset($definition['public'])) { $function->isPublic(true); } if (isset($definition['name'])) { $function->setName($definition['name']); } if (isset($definition['params'])) { foreach ($definition['params'] as $name => $type) { $function->addParam($name, $type); } } if (isset($definition['content'])) { $function->setContent($definition['content']); } return $function; }
[ "public", "function", "arrayToFunctionElement", "(", "array", "$", "definition", ")", "{", "$", "function", "=", "new", "Functions", ";", "if", "(", "isset", "(", "$", "definition", "[", "'docblock'", "]", ")", ")", "{", "$", "docblock", "=", "$", "this", "->", "arrayToDocblockElement", "(", "$", "definition", "[", "'docblock'", "]", ")", ";", "$", "function", "->", "setDocbloc", "(", "$", "docblock", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'public'", "]", ")", ")", "{", "$", "function", "->", "isPublic", "(", "true", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'name'", "]", ")", ")", "{", "$", "function", "->", "setName", "(", "$", "definition", "[", "'name'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "definition", "[", "'params'", "]", ")", ")", "{", "foreach", "(", "$", "definition", "[", "'params'", "]", "as", "$", "name", "=>", "$", "type", ")", "{", "$", "function", "->", "addParam", "(", "$", "name", ",", "$", "type", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "definition", "[", "'content'", "]", ")", ")", "{", "$", "function", "->", "setContent", "(", "$", "definition", "[", "'content'", "]", ")", ";", "}", "return", "$", "function", ";", "}" ]
Returns well formated function declaration @param array $definition Functions definition @return Deflection\Element\Functions
[ "Returns", "well", "formated", "function", "declaration" ]
train
https://github.com/lanfisis/deflection/blob/31deaf7f085d6456d8a323e7ac3cc9914fbe49a9/src/Deflection/Transformer.php#L100-L122
intpro/scalar
src/Service/DbCleaner.php
DbCleaner.strategy
private function strategy(callable $action) { $report = false; $tables = [ 'string' => StringModel::class, 'text' => TextModel::class, 'bool' => BoolModel::class, 'float' => FloatModel::class, 'int' => IntModel::class, 'timestamp' => TimestampModel::class]; foreach($tables as $type_name => $modelClass) { $wehave = $modelClass::all(); foreach($wehave as $model) { $entity_name = $model->entity_name; $name = $model->name; if(!$this->taxonomy->exist($entity_name)) { $action(1, $type_name, $model); $report = true; } else { $ownerType = $this->taxonomy->getType($entity_name); if($ownerType->getRank() === TypeRank::OWN) { $action(2, $type_name, $model); $report = true; } elseif(!$ownerType->ownExist($name)) { $action(3, $type_name, $model); $report = true; } elseif($ownerType->getFieldType($name) !== $this->taxonomy->getType($type_name)) { $action(4, $type_name, $model); $report = true; } } } } return $report; }
php
private function strategy(callable $action) { $report = false; $tables = [ 'string' => StringModel::class, 'text' => TextModel::class, 'bool' => BoolModel::class, 'float' => FloatModel::class, 'int' => IntModel::class, 'timestamp' => TimestampModel::class]; foreach($tables as $type_name => $modelClass) { $wehave = $modelClass::all(); foreach($wehave as $model) { $entity_name = $model->entity_name; $name = $model->name; if(!$this->taxonomy->exist($entity_name)) { $action(1, $type_name, $model); $report = true; } else { $ownerType = $this->taxonomy->getType($entity_name); if($ownerType->getRank() === TypeRank::OWN) { $action(2, $type_name, $model); $report = true; } elseif(!$ownerType->ownExist($name)) { $action(3, $type_name, $model); $report = true; } elseif($ownerType->getFieldType($name) !== $this->taxonomy->getType($type_name)) { $action(4, $type_name, $model); $report = true; } } } } return $report; }
[ "private", "function", "strategy", "(", "callable", "$", "action", ")", "{", "$", "report", "=", "false", ";", "$", "tables", "=", "[", "'string'", "=>", "StringModel", "::", "class", ",", "'text'", "=>", "TextModel", "::", "class", ",", "'bool'", "=>", "BoolModel", "::", "class", ",", "'float'", "=>", "FloatModel", "::", "class", ",", "'int'", "=>", "IntModel", "::", "class", ",", "'timestamp'", "=>", "TimestampModel", "::", "class", "]", ";", "foreach", "(", "$", "tables", "as", "$", "type_name", "=>", "$", "modelClass", ")", "{", "$", "wehave", "=", "$", "modelClass", "::", "all", "(", ")", ";", "foreach", "(", "$", "wehave", "as", "$", "model", ")", "{", "$", "entity_name", "=", "$", "model", "->", "entity_name", ";", "$", "name", "=", "$", "model", "->", "name", ";", "if", "(", "!", "$", "this", "->", "taxonomy", "->", "exist", "(", "$", "entity_name", ")", ")", "{", "$", "action", "(", "1", ",", "$", "type_name", ",", "$", "model", ")", ";", "$", "report", "=", "true", ";", "}", "else", "{", "$", "ownerType", "=", "$", "this", "->", "taxonomy", "->", "getType", "(", "$", "entity_name", ")", ";", "if", "(", "$", "ownerType", "->", "getRank", "(", ")", "===", "TypeRank", "::", "OWN", ")", "{", "$", "action", "(", "2", ",", "$", "type_name", ",", "$", "model", ")", ";", "$", "report", "=", "true", ";", "}", "elseif", "(", "!", "$", "ownerType", "->", "ownExist", "(", "$", "name", ")", ")", "{", "$", "action", "(", "3", ",", "$", "type_name", ",", "$", "model", ")", ";", "$", "report", "=", "true", ";", "}", "elseif", "(", "$", "ownerType", "->", "getFieldType", "(", "$", "name", ")", "!==", "$", "this", "->", "taxonomy", "->", "getType", "(", "$", "type_name", ")", ")", "{", "$", "action", "(", "4", ",", "$", "type_name", ",", "$", "model", ")", ";", "$", "report", "=", "true", ";", "}", "}", "}", "}", "return", "$", "report", ";", "}" ]
@param callable $action @return bool
[ "@param", "callable", "$action" ]
train
https://github.com/intpro/scalar/blob/de2d8c6e39efc9edf479447d8b2ed265aebe0a8d/src/Service/DbCleaner.php#L32-L82
rzajac/phptools
src/Helper/Err.php
Err.errToException
public static function errToException($turnOn = true) { if (!$turnOn) { return set_error_handler(null); } /* * Error handler * * @param int $errno * @param string $errStr * @param string $errFile * @param int $errLine * * @throws ErrorException */ $handler = function ($errno, $errStr, $errFile, $errLine) { // This error code is not included in error_reporting if (!(error_reporting() & $errno)) { return; } throw new ErrorException($errStr, 0, $errno, $errFile, $errLine); }; return set_error_handler($handler); }
php
public static function errToException($turnOn = true) { if (!$turnOn) { return set_error_handler(null); } /* * Error handler * * @param int $errno * @param string $errStr * @param string $errFile * @param int $errLine * * @throws ErrorException */ $handler = function ($errno, $errStr, $errFile, $errLine) { // This error code is not included in error_reporting if (!(error_reporting() & $errno)) { return; } throw new ErrorException($errStr, 0, $errno, $errFile, $errLine); }; return set_error_handler($handler); }
[ "public", "static", "function", "errToException", "(", "$", "turnOn", "=", "true", ")", "{", "if", "(", "!", "$", "turnOn", ")", "{", "return", "set_error_handler", "(", "null", ")", ";", "}", "/*\n * Error handler\n *\n * @param int $errno\n * @param string $errStr\n * @param string $errFile\n * @param int $errLine\n *\n * @throws ErrorException\n */", "$", "handler", "=", "function", "(", "$", "errno", ",", "$", "errStr", ",", "$", "errFile", ",", "$", "errLine", ")", "{", "// This error code is not included in error_reporting", "if", "(", "!", "(", "error_reporting", "(", ")", "&", "$", "errno", ")", ")", "{", "return", ";", "}", "throw", "new", "ErrorException", "(", "$", "errStr", ",", "0", ",", "$", "errno", ",", "$", "errFile", ",", "$", "errLine", ")", ";", "}", ";", "return", "set_error_handler", "(", "$", "handler", ")", ";", "}" ]
Change errors to exceptions. @see http://php.net/manual/en/class.errorexception.php @param bool $turnOn Set to false to turn off user defined error exception handling and set the default one. @return mixed
[ "Change", "errors", "to", "exceptions", "." ]
train
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Err.php#L38-L63
peridot-php/peridot-scope
src/Scope.php
Scope.&
public function &__get($name) { list($result, $found) = $this->peridotScanChildren($this, function ($childScope, &$accumulator) use ($name) { if (property_exists($childScope, $name)) { $accumulator = [$childScope->$name, true, $childScope]; } }); if (!$found) { throw new DomainException("Scope property $name not found"); } return $result; }
php
public function &__get($name) { list($result, $found) = $this->peridotScanChildren($this, function ($childScope, &$accumulator) use ($name) { if (property_exists($childScope, $name)) { $accumulator = [$childScope->$name, true, $childScope]; } }); if (!$found) { throw new DomainException("Scope property $name not found"); } return $result; }
[ "public", "function", "&", "__get", "(", "$", "name", ")", "{", "list", "(", "$", "result", ",", "$", "found", ")", "=", "$", "this", "->", "peridotScanChildren", "(", "$", "this", ",", "function", "(", "$", "childScope", ",", "&", "$", "accumulator", ")", "use", "(", "$", "name", ")", "{", "if", "(", "property_exists", "(", "$", "childScope", ",", "$", "name", ")", ")", "{", "$", "accumulator", "=", "[", "$", "childScope", "->", "$", "name", ",", "true", ",", "$", "childScope", "]", ";", "}", "}", ")", ";", "if", "(", "!", "$", "found", ")", "{", "throw", "new", "DomainException", "(", "\"Scope property $name not found\"", ")", ";", "}", "return", "$", "result", ";", "}" ]
Lookup properties on child scopes. @param $name @return mixed @throws DomainException
[ "Lookup", "properties", "on", "child", "scopes", "." ]
train
https://github.com/peridot-php/peridot-scope/blob/baabb128c805f84279c1506435120314ac09d9ff/src/Scope.php#L106-L117
peridot-php/peridot-scope
src/Scope.php
Scope.peridotScanChildren
protected function peridotScanChildren(Scope $scope, callable $fn, &$accumulator = []) { if (! empty($accumulator)) { return $accumulator; } $children = $scope->peridotGetChildScopes(); foreach ($children as $childScope) { $fn($childScope, $accumulator); $this->peridotScanChildren($childScope, $fn, $accumulator); } if (empty($accumulator)) { return [null, false]; } return $accumulator; }
php
protected function peridotScanChildren(Scope $scope, callable $fn, &$accumulator = []) { if (! empty($accumulator)) { return $accumulator; } $children = $scope->peridotGetChildScopes(); foreach ($children as $childScope) { $fn($childScope, $accumulator); $this->peridotScanChildren($childScope, $fn, $accumulator); } if (empty($accumulator)) { return [null, false]; } return $accumulator; }
[ "protected", "function", "peridotScanChildren", "(", "Scope", "$", "scope", ",", "callable", "$", "fn", ",", "&", "$", "accumulator", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "accumulator", ")", ")", "{", "return", "$", "accumulator", ";", "}", "$", "children", "=", "$", "scope", "->", "peridotGetChildScopes", "(", ")", ";", "foreach", "(", "$", "children", "as", "$", "childScope", ")", "{", "$", "fn", "(", "$", "childScope", ",", "$", "accumulator", ")", ";", "$", "this", "->", "peridotScanChildren", "(", "$", "childScope", ",", "$", "fn", ",", "$", "accumulator", ")", ";", "}", "if", "(", "empty", "(", "$", "accumulator", ")", ")", "{", "return", "[", "null", ",", "false", "]", ";", "}", "return", "$", "accumulator", ";", "}" ]
Scan child scopes and execute a function against each one passing an accumulator reference along. @param Scope $scope @param callable $fn @param array $accumulator @return array
[ "Scan", "child", "scopes", "and", "execute", "a", "function", "against", "each", "one", "passing", "an", "accumulator", "reference", "along", "." ]
train
https://github.com/peridot-php/peridot-scope/blob/baabb128c805f84279c1506435120314ac09d9ff/src/Scope.php#L128-L145
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.prepareContainer
public static function prepareContainer($id) { // use array key exists so non existing column will researched if(array_key_exists('id', self::$container)) { return static::$container[$id]; } $model = ColumnsetModel::findByPk($id); if($model === null) { static::$container[$id] = null; return null; } $sizes = deserialize($model->sizes, true); $container = array(); foreach($sizes as $size) { $key = 'columnset_' . $size; $columns = deserialize($model->{$key}, true); foreach($columns as $index => $column) { if(isset($container[$index][0])) { $container[$index][0] .= ' ' . self::prepareSize($size, deserialize($column, true)); } else { $container[$index][0] .= self::prepareSize($size, deserialize($column, true)); } } } static::$container[$id] = $container; return $container; }
php
public static function prepareContainer($id) { // use array key exists so non existing column will researched if(array_key_exists('id', self::$container)) { return static::$container[$id]; } $model = ColumnsetModel::findByPk($id); if($model === null) { static::$container[$id] = null; return null; } $sizes = deserialize($model->sizes, true); $container = array(); foreach($sizes as $size) { $key = 'columnset_' . $size; $columns = deserialize($model->{$key}, true); foreach($columns as $index => $column) { if(isset($container[$index][0])) { $container[$index][0] .= ' ' . self::prepareSize($size, deserialize($column, true)); } else { $container[$index][0] .= self::prepareSize($size, deserialize($column, true)); } } } static::$container[$id] = $container; return $container; }
[ "public", "static", "function", "prepareContainer", "(", "$", "id", ")", "{", "// use array key exists so non existing column will researched", "if", "(", "array_key_exists", "(", "'id'", ",", "self", "::", "$", "container", ")", ")", "{", "return", "static", "::", "$", "container", "[", "$", "id", "]", ";", "}", "$", "model", "=", "ColumnsetModel", "::", "findByPk", "(", "$", "id", ")", ";", "if", "(", "$", "model", "===", "null", ")", "{", "static", "::", "$", "container", "[", "$", "id", "]", "=", "null", ";", "return", "null", ";", "}", "$", "sizes", "=", "deserialize", "(", "$", "model", "->", "sizes", ",", "true", ")", ";", "$", "container", "=", "array", "(", ")", ";", "foreach", "(", "$", "sizes", "as", "$", "size", ")", "{", "$", "key", "=", "'columnset_'", ".", "$", "size", ";", "$", "columns", "=", "deserialize", "(", "$", "model", "->", "{", "$", "key", "}", ",", "true", ")", ";", "foreach", "(", "$", "columns", "as", "$", "index", "=>", "$", "column", ")", "{", "if", "(", "isset", "(", "$", "container", "[", "$", "index", "]", "[", "0", "]", ")", ")", "{", "$", "container", "[", "$", "index", "]", "[", "0", "]", ".=", "' '", ".", "self", "::", "prepareSize", "(", "$", "size", ",", "deserialize", "(", "$", "column", ",", "true", ")", ")", ";", "}", "else", "{", "$", "container", "[", "$", "index", "]", "[", "0", "]", ".=", "self", "::", "prepareSize", "(", "$", "size", ",", "deserialize", "(", "$", "column", ",", "true", ")", ")", ";", "}", "}", "}", "static", "::", "$", "container", "[", "$", "id", "]", "=", "$", "container", ";", "return", "$", "container", ";", "}" ]
prepare the container which sub columns expects @param int $id id of the columnset @return array
[ "prepare", "the", "container", "which", "sub", "columns", "expects" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L39-L75
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.prepareSize
protected static function prepareSize($size, array $definition) { $css = sprintf('col-%s-%s', $size, $definition['width']); if($definition['offset']) { $css .= sprintf(' col-%s-offset-%s', $size, $definition['offset']); } if($definition['order']) { $css .= sprintf(' col-%s-%s', $size, $definition['order']); } return $css; }
php
protected static function prepareSize($size, array $definition) { $css = sprintf('col-%s-%s', $size, $definition['width']); if($definition['offset']) { $css .= sprintf(' col-%s-offset-%s', $size, $definition['offset']); } if($definition['order']) { $css .= sprintf(' col-%s-%s', $size, $definition['order']); } return $css; }
[ "protected", "static", "function", "prepareSize", "(", "$", "size", ",", "array", "$", "definition", ")", "{", "$", "css", "=", "sprintf", "(", "'col-%s-%s'", ",", "$", "size", ",", "$", "definition", "[", "'width'", "]", ")", ";", "if", "(", "$", "definition", "[", "'offset'", "]", ")", "{", "$", "css", ".=", "sprintf", "(", "' col-%s-offset-%s'", ",", "$", "size", ",", "$", "definition", "[", "'offset'", "]", ")", ";", "}", "if", "(", "$", "definition", "[", "'order'", "]", ")", "{", "$", "css", ".=", "sprintf", "(", "' col-%s-%s'", ",", "$", "size", ",", "$", "definition", "[", "'order'", "]", ")", ";", "}", "return", "$", "css", ";", "}" ]
generates the css class defnition for one column @param string $size the selected size @param array $definition the column definition @return string
[ "generates", "the", "css", "class", "defnition", "for", "one", "column" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L85-L98
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.appendColumnsetIdToPalette
public function appendColumnsetIdToPalette($dc) { if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') { return; } if($dc->table == 'tl_content') { $model = \ContentModel::findByPK($dc->id); if($model->sc_type > 0) { \MetaPalettes::appendFields($dc->table, 'colsetStart', 'colset', array('columnset_id')); } } else { $model = \ModuleModel::findByPk($dc->id); if($model->sc_type > 0) { if($model->sc_type > 0) { $GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace( 'sc_type,', 'sc_type,columnset_id,', $GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] ); } } } }
php
public function appendColumnsetIdToPalette($dc) { if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') { return; } if($dc->table == 'tl_content') { $model = \ContentModel::findByPK($dc->id); if($model->sc_type > 0) { \MetaPalettes::appendFields($dc->table, 'colsetStart', 'colset', array('columnset_id')); } } else { $model = \ModuleModel::findByPk($dc->id); if($model->sc_type > 0) { if($model->sc_type > 0) { $GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace( 'sc_type,', 'sc_type,columnset_id,', $GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] ); } } } }
[ "public", "function", "appendColumnsetIdToPalette", "(", "$", "dc", ")", "{", "if", "(", "$", "GLOBALS", "[", "'TL_CONFIG'", "]", "[", "'subcolumns'", "]", "!=", "'bootstrap_customizable'", ")", "{", "return", ";", "}", "if", "(", "$", "dc", "->", "table", "==", "'tl_content'", ")", "{", "$", "model", "=", "\\", "ContentModel", "::", "findByPK", "(", "$", "dc", "->", "id", ")", ";", "if", "(", "$", "model", "->", "sc_type", ">", "0", ")", "{", "\\", "MetaPalettes", "::", "appendFields", "(", "$", "dc", "->", "table", ",", "'colsetStart'", ",", "'colset'", ",", "array", "(", "'columnset_id'", ")", ")", ";", "}", "}", "else", "{", "$", "model", "=", "\\", "ModuleModel", "::", "findByPk", "(", "$", "dc", "->", "id", ")", ";", "if", "(", "$", "model", "->", "sc_type", ">", "0", ")", "{", "if", "(", "$", "model", "->", "sc_type", ">", "0", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_module'", "]", "[", "'palettes'", "]", "[", "'subcolumns'", "]", "=", "str_replace", "(", "'sc_type,'", ",", "'sc_type,columnset_id,'", ",", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_module'", "]", "[", "'palettes'", "]", "[", "'subcolumns'", "]", ")", ";", "}", "}", "}", "}" ]
add column set field to the colsetStart content element. We need to do it dynamically because subcolumns creates its palette dynamically @param $dc
[ "add", "column", "set", "field", "to", "the", "colsetStart", "content", "element", ".", "We", "need", "to", "do", "it", "dynamically", "because", "subcolumns", "creates", "its", "palette", "dynamically" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L107-L133
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.appendColumnSizesToPalette
public function appendColumnSizesToPalette($dc) { $model = ColumnsetModel::findByPk($dc->id); $sizes = array_merge(deserialize($model->sizes, true)); foreach($sizes as $size) { $field = 'columnset_' . $size; \MetaPalettes::appendFields('tl_columnset', 'columnset', array($field)); } }
php
public function appendColumnSizesToPalette($dc) { $model = ColumnsetModel::findByPk($dc->id); $sizes = array_merge(deserialize($model->sizes, true)); foreach($sizes as $size) { $field = 'columnset_' . $size; \MetaPalettes::appendFields('tl_columnset', 'columnset', array($field)); } }
[ "public", "function", "appendColumnSizesToPalette", "(", "$", "dc", ")", "{", "$", "model", "=", "ColumnsetModel", "::", "findByPk", "(", "$", "dc", "->", "id", ")", ";", "$", "sizes", "=", "array_merge", "(", "deserialize", "(", "$", "model", "->", "sizes", ",", "true", ")", ")", ";", "foreach", "(", "$", "sizes", "as", "$", "size", ")", "{", "$", "field", "=", "'columnset_'", ".", "$", "size", ";", "\\", "MetaPalettes", "::", "appendFields", "(", "'tl_columnset'", ",", "'columnset'", ",", "array", "(", "$", "field", ")", ")", ";", "}", "}" ]
Append column sizes fields dynamically to the palettes. Not using @param $dc
[ "Append", "column", "sizes", "fields", "dynamically", "to", "the", "palettes", ".", "Not", "using" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L140-L151
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.createColumns
public function createColumns($value, $mcw) { $columns = (int) $mcw->activeRecord->columns; $value = deserialize($value, true); $count = count($value); // initialize columns if($count == 0) { for($i= 0; $i < $columns; $i++) { $value[$i]['width'] = floor(12/$columns); } } // reduce columns if necessary elseif($count > $columns) { $count = count($value) - $columns; for($i=0; $i < $count; $i++) { array_pop($value); } } // make sure that column numbers has not changed else { for($i= 0; $i < ($columns - $count); $i++) { $value[$i+$count]['width'] = floor(12/$columns); } } return $value; }
php
public function createColumns($value, $mcw) { $columns = (int) $mcw->activeRecord->columns; $value = deserialize($value, true); $count = count($value); // initialize columns if($count == 0) { for($i= 0; $i < $columns; $i++) { $value[$i]['width'] = floor(12/$columns); } } // reduce columns if necessary elseif($count > $columns) { $count = count($value) - $columns; for($i=0; $i < $count; $i++) { array_pop($value); } } // make sure that column numbers has not changed else { for($i= 0; $i < ($columns - $count); $i++) { $value[$i+$count]['width'] = floor(12/$columns); } } return $value; }
[ "public", "function", "createColumns", "(", "$", "value", ",", "$", "mcw", ")", "{", "$", "columns", "=", "(", "int", ")", "$", "mcw", "->", "activeRecord", "->", "columns", ";", "$", "value", "=", "deserialize", "(", "$", "value", ",", "true", ")", ";", "$", "count", "=", "count", "(", "$", "value", ")", ";", "// initialize columns", "if", "(", "$", "count", "==", "0", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "columns", ";", "$", "i", "++", ")", "{", "$", "value", "[", "$", "i", "]", "[", "'width'", "]", "=", "floor", "(", "12", "/", "$", "columns", ")", ";", "}", "}", "// reduce columns if necessary", "elseif", "(", "$", "count", ">", "$", "columns", ")", "{", "$", "count", "=", "count", "(", "$", "value", ")", "-", "$", "columns", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "array_pop", "(", "$", "value", ")", ";", "}", "}", "// make sure that column numbers has not changed", "else", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "(", "$", "columns", "-", "$", "count", ")", ";", "$", "i", "++", ")", "{", "$", "value", "[", "$", "i", "+", "$", "count", "]", "[", "'width'", "]", "=", "floor", "(", "12", "/", "$", "columns", ")", ";", "}", "}", "return", "$", "value", ";", "}" ]
create a MCW row for each column @param string $value deseriazable value, for getting an array @param $mcw multi column wizard or DC_Table @return mixed
[ "create", "a", "MCW", "row", "for", "each", "column" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L161-L190
netzmacht-archive/subcolumns_bootstrap_customizable
src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php
ColumnSet.getAllTypes
public function getAllTypes($dc) { if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') { $sc = new \tl_content_sc(); return $sc->getAllTypes(); } $this->import('Database'); $collection = $this->Database->execute('SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns'); $types = array(); while($collection->next()) { $types[] = $collection->columns; } return $types; }
php
public function getAllTypes($dc) { if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') { $sc = new \tl_content_sc(); return $sc->getAllTypes(); } $this->import('Database'); $collection = $this->Database->execute('SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns'); $types = array(); while($collection->next()) { $types[] = $collection->columns; } return $types; }
[ "public", "function", "getAllTypes", "(", "$", "dc", ")", "{", "if", "(", "$", "GLOBALS", "[", "'TL_CONFIG'", "]", "[", "'subcolumns'", "]", "!=", "'bootstrap_customizable'", ")", "{", "$", "sc", "=", "new", "\\", "tl_content_sc", "(", ")", ";", "return", "$", "sc", "->", "getAllTypes", "(", ")", ";", "}", "$", "this", "->", "import", "(", "'Database'", ")", ";", "$", "collection", "=", "$", "this", "->", "Database", "->", "execute", "(", "'SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns'", ")", ";", "$", "types", "=", "array", "(", ")", ";", "while", "(", "$", "collection", "->", "next", "(", ")", ")", "{", "$", "types", "[", "]", "=", "$", "collection", "->", "columns", ";", "}", "return", "$", "types", ";", "}" ]
replace subcolumns getAllTypes method, to load all created columnsets. There is a fallback provided if not bootstra_customizable is used @param DC_Table $dc @return array
[ "replace", "subcolumns", "getAllTypes", "method", "to", "load", "all", "created", "columnsets", ".", "There", "is", "a", "fallback", "provided", "if", "not", "bootstra_customizable", "is", "used" ]
train
https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L200-L217