repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.processThumbnails
public function processThumbnails(array $config) { $thumbnailPaths = []; if (!isset($config['thumbnailSizes'])) { return $thumbnailPaths; } foreach ($config['thumbnailSizes'] as $prefix => $thumbnailConfig) { $method = 'gd'; if (!empty($config['thumbnailMethod'])) { $method = $config['thumbnailMethod']; } $this->ImageManager = new ImageManager(['driver' => $method]); $thumbnailPaths[] = $this->makeThumbnail($prefix, $thumbnailConfig); } return $thumbnailPaths; }
php
public function processThumbnails(array $config) { $thumbnailPaths = []; if (!isset($config['thumbnailSizes'])) { return $thumbnailPaths; } foreach ($config['thumbnailSizes'] as $prefix => $thumbnailConfig) { $method = 'gd'; if (!empty($config['thumbnailMethod'])) { $method = $config['thumbnailMethod']; } $this->ImageManager = new ImageManager(['driver' => $method]); $thumbnailPaths[] = $this->makeThumbnail($prefix, $thumbnailConfig); } return $thumbnailPaths; }
[ "public", "function", "processThumbnails", "(", "array", "$", "config", ")", "{", "$", "thumbnailPaths", "=", "[", "]", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'thumbnailSizes'", "]", ")", ")", "{", "return", "$", "thumbnailPaths", ";", ...
Take an upload fields configuration and create all the thumbnails @param array $config The upload fields configuration @return array
[ "Take", "an", "upload", "fields", "configuration", "and", "create", "all", "the", "thumbnails" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L51-L70
train
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.makeThumbnail
public function makeThumbnail($prefix, array $config) { $defaultConfig = [ 'jpeg_quality' => 100 ]; $config = array_merge($defaultConfig, $config); $width = !empty($config['w']) ? $config['w'] : null; $height = !empty($config['h']) ? $config['h'] : null; $image = $this->ImageManager->make($this->Path->fullPath()); if (!empty($config['orientate'])) { $image = $this->orientate($image); } if (!empty($config['crop'])) { $image = $this->thumbnailCrop($image, $width, $height); } elseif (!empty($config['fit'])) { $image = $this->thumbnailFit($image, $width, $height); } elseif (!empty($config['custom'])) { $image = $this->thumbnailCustom($image, $config['custom'], $config['params']); } else { $image = $this->thumbnailResize($image, $width, $height); } unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']); $image->save($this->Path->fullPath($prefix), $config['jpeg_quality']); return $this->Path->fullPath($prefix); }
php
public function makeThumbnail($prefix, array $config) { $defaultConfig = [ 'jpeg_quality' => 100 ]; $config = array_merge($defaultConfig, $config); $width = !empty($config['w']) ? $config['w'] : null; $height = !empty($config['h']) ? $config['h'] : null; $image = $this->ImageManager->make($this->Path->fullPath()); if (!empty($config['orientate'])) { $image = $this->orientate($image); } if (!empty($config['crop'])) { $image = $this->thumbnailCrop($image, $width, $height); } elseif (!empty($config['fit'])) { $image = $this->thumbnailFit($image, $width, $height); } elseif (!empty($config['custom'])) { $image = $this->thumbnailCustom($image, $config['custom'], $config['params']); } else { $image = $this->thumbnailResize($image, $width, $height); } unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']); $image->save($this->Path->fullPath($prefix), $config['jpeg_quality']); return $this->Path->fullPath($prefix); }
[ "public", "function", "makeThumbnail", "(", "$", "prefix", ",", "array", "$", "config", ")", "{", "$", "defaultConfig", "=", "[", "'jpeg_quality'", "=>", "100", "]", ";", "$", "config", "=", "array_merge", "(", "$", "defaultConfig", ",", "$", "config", "...
Generate and save the thumbnail @param string $prefix The thumbnail prefix @param array $config Array of thumbnail config @return string
[ "Generate", "and", "save", "the", "thumbnail" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L79-L110
train
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.thumbnailResize
protected function thumbnailResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); }
php
protected function thumbnailResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); }
[ "protected", "function", "thumbnailResize", "(", "Image", "$", "image", ",", "$", "width", ",", "$", "height", ")", "{", "return", "$", "image", "->", "resize", "(", "$", "width", ",", "$", "height", ",", "function", "(", "$", "constraint", ")", "{", ...
Resize current image @see http://image.intervention.io/api/resize @param \Intervention\Image\Image $image Image instance @param int $width Desired width in pixels @param int $height Desired height in pixels @return \Intervention\Image\Image
[ "Resize", "current", "image" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L155-L160
train
davidyell/CakePHP3-Proffer
src/Model/Validation/ProfferRules.php
ProfferRules.dimensions
public static function dimensions($value, array $dimensions) { $fileDimensions = getimagesize($value['tmp_name']); if ($fileDimensions === false) { return false; } $sourceWidth = $fileDimensions[0]; $sourceHeight = $fileDimensions[1]; foreach ($dimensions as $rule => $sizes) { if ($rule === 'min') { if (isset($sizes['w']) && $sourceWidth < $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight < $sizes['h']) { return false; } } elseif ($rule === 'max') { if (isset($sizes['w']) && $sourceWidth > $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight > $sizes['h']) { return false; } } } return true; }
php
public static function dimensions($value, array $dimensions) { $fileDimensions = getimagesize($value['tmp_name']); if ($fileDimensions === false) { return false; } $sourceWidth = $fileDimensions[0]; $sourceHeight = $fileDimensions[1]; foreach ($dimensions as $rule => $sizes) { if ($rule === 'min') { if (isset($sizes['w']) && $sourceWidth < $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight < $sizes['h']) { return false; } } elseif ($rule === 'max') { if (isset($sizes['w']) && $sourceWidth > $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight > $sizes['h']) { return false; } } } return true; }
[ "public", "static", "function", "dimensions", "(", "$", "value", ",", "array", "$", "dimensions", ")", "{", "$", "fileDimensions", "=", "getimagesize", "(", "$", "value", "[", "'tmp_name'", "]", ")", ";", "if", "(", "$", "fileDimensions", "===", "false", ...
Validate the dimensions of an image. If the file isn't an image then validation will fail @param array $value An array of the name and value of the field @param array $dimensions Array of rule dimensions for example ['dimensions', [ 'min' => ['w' => 100, 'h' => 100], 'max' => ['w' => 500, 'h' => 500] ]] would validate a minimum size of 100x100 pixels and a maximum of 500x500 pixels @return bool
[ "Validate", "the", "dimensions", "of", "an", "image", ".", "If", "the", "file", "isn", "t", "an", "image", "then", "validation", "will", "fail" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Validation/ProfferRules.php#L27-L57
train
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.getOptionParser
public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addSubcommand('generate', [ 'help' => __('Regenerate thumbnails for a specific table.'), 'parser' => [ 'description' => [__('Use this command to regenerate the thumbnails for a specific table.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'path-class' => [ 'short' => 'p', 'help' => __('Fully name spaced custom path class, you must use double backslash.') ], 'image-class' => [ 'short' => 'i', 'help' => __('Fully name spaced custom image transform class, you must use double backslash.') ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before generate.'), ], ] ] ]); $parser->addSubcommand('cleanup', [ 'help' => __('Clean up old images on the file system which are not linked in the database.'), 'parser' => [ 'description' => [__('This command will delete images which are not part of the model configuration.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'dry-run' => [ 'short' => 'd', 'help' => __('Do a dry run and don\'t delete any files.'), 'boolean' => true ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before cleanup.'), ], ] ], ]); return $parser; }
php
public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addSubcommand('generate', [ 'help' => __('Regenerate thumbnails for a specific table.'), 'parser' => [ 'description' => [__('Use this command to regenerate the thumbnails for a specific table.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'path-class' => [ 'short' => 'p', 'help' => __('Fully name spaced custom path class, you must use double backslash.') ], 'image-class' => [ 'short' => 'i', 'help' => __('Fully name spaced custom image transform class, you must use double backslash.') ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before generate.'), ], ] ] ]); $parser->addSubcommand('cleanup', [ 'help' => __('Clean up old images on the file system which are not linked in the database.'), 'parser' => [ 'description' => [__('This command will delete images which are not part of the model configuration.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'dry-run' => [ 'short' => 'd', 'help' => __('Do a dry run and don\'t delete any files.'), 'boolean' => true ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before cleanup.'), ], ] ], ]); return $parser; }
[ "public", "function", "getOptionParser", "(", ")", "{", "$", "parser", "=", "parent", "::", "getOptionParser", "(", ")", ";", "$", "parser", "->", "addSubcommand", "(", "'generate'", ",", "[", "'help'", "=>", "__", "(", "'Regenerate thumbnails for a specific tab...
Return the help options and validate arguments @return \Cake\Console\ConsoleOptionParser
[ "Return", "the", "help", "options", "and", "validate", "arguments" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L27-L73
train
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.main
public function main() { $this->out('Welcome to the Proffer shell.'); $this->out('This shell can be used to regenerate thumbnails and cleanup unlinked images.'); $this->hr(); $this->out($this->OptionParser->help()); }
php
public function main() { $this->out('Welcome to the Proffer shell.'); $this->out('This shell can be used to regenerate thumbnails and cleanup unlinked images.'); $this->hr(); $this->out($this->OptionParser->help()); }
[ "public", "function", "main", "(", ")", "{", "$", "this", "->", "out", "(", "'Welcome to the Proffer shell.'", ")", ";", "$", "this", "->", "out", "(", "'This shell can be used to regenerate thumbnails and cleanup unlinked images.'", ")", ";", "$", "this", "->", "hr...
Introduction to the shell @return void
[ "Introduction", "to", "the", "shell" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L80-L86
train
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.generate
public function generate($table) { $this->checkTable($table); $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { $records = $this->{$this->Table->alias()}->find() ->select([$this->Table->primaryKey(), $field, $settings['dir']]) ->where([ "$field IS NOT NULL", "$field != ''" ]); foreach ($records as $item) { if ($this->param('verbose')) { $this->out( __('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey())) ); } if (!empty($this->param('path-class'))) { $class = (string)$this->param('path-class'); $path = new $class($this->Table, $item, $field, $settings); } else { $path = new ProfferPath($this->Table, $item, $field, $settings); } if (!empty($this->param('image-class'))) { $class = (string)$this->param('image-class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); } $transform->processThumbnails($settings); if ($this->param('verbose')) { $this->out(__('Thumbnails regenerated for ' . $path->fullPath())); } else { $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field))); } } } $this->out($this->nl(0)); $this->out(__('<info>Completed</info>')); }
php
public function generate($table) { $this->checkTable($table); $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { $records = $this->{$this->Table->alias()}->find() ->select([$this->Table->primaryKey(), $field, $settings['dir']]) ->where([ "$field IS NOT NULL", "$field != ''" ]); foreach ($records as $item) { if ($this->param('verbose')) { $this->out( __('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey())) ); } if (!empty($this->param('path-class'))) { $class = (string)$this->param('path-class'); $path = new $class($this->Table, $item, $field, $settings); } else { $path = new ProfferPath($this->Table, $item, $field, $settings); } if (!empty($this->param('image-class'))) { $class = (string)$this->param('image-class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); } $transform->processThumbnails($settings); if ($this->param('verbose')) { $this->out(__('Thumbnails regenerated for ' . $path->fullPath())); } else { $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field))); } } } $this->out($this->nl(0)); $this->out(__('<info>Completed</info>')); }
[ "public", "function", "generate", "(", "$", "table", ")", "{", "$", "this", "->", "checkTable", "(", "$", "table", ")", ";", "$", "config", "=", "$", "this", "->", "Table", "->", "behaviors", "(", ")", "->", "Proffer", "->", "config", "(", ")", ";"...
Load a table, get it's config and then regenerate the thumbnails for that tables upload fields. @param string $table The name of the table @return void
[ "Load", "a", "table", "get", "it", "s", "config", "and", "then", "regenerate", "the", "thumbnails", "for", "that", "tables", "upload", "fields", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L94-L141
train
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.checkTable
protected function checkTable($table) { try { $this->Table = $this->loadModel($table); } catch (Exception $e) { $this->out(__('<error>' . $e->getMessage() . '</error>')); $this->_stop(); } if (get_class($this->Table) === 'AppModel') { $this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>')); $this->_stop(); } if (!$this->Table->hasBehavior('Proffer')) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>" ); $this->out($out); $this->_stop(); } $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { if (!$this->Table->hasField($field)) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>" ); $this->out($out); $this->_stop(); } if (!$this->Table->hasField($settings['dir'])) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>" ); $this->out($out); $this->_stop(); } } if ($this->param('remove-behaviors')) { $removeBehaviors = explode(',', (string)$this->param('remove-behaviors')); foreach ($removeBehaviors as $removeBehavior) { $this->Table->removeBehavior($removeBehavior); } } }
php
protected function checkTable($table) { try { $this->Table = $this->loadModel($table); } catch (Exception $e) { $this->out(__('<error>' . $e->getMessage() . '</error>')); $this->_stop(); } if (get_class($this->Table) === 'AppModel') { $this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>')); $this->_stop(); } if (!$this->Table->hasBehavior('Proffer')) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>" ); $this->out($out); $this->_stop(); } $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { if (!$this->Table->hasField($field)) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>" ); $this->out($out); $this->_stop(); } if (!$this->Table->hasField($settings['dir'])) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>" ); $this->out($out); $this->_stop(); } } if ($this->param('remove-behaviors')) { $removeBehaviors = explode(',', (string)$this->param('remove-behaviors')); foreach ($removeBehaviors as $removeBehavior) { $this->Table->removeBehavior($removeBehavior); } } }
[ "protected", "function", "checkTable", "(", "$", "table", ")", "{", "try", "{", "$", "this", "->", "Table", "=", "$", "this", "->", "loadModel", "(", "$", "table", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "...
Do some checks on the table which has been passed to make sure that it has what we need @param string $table The table @return void
[ "Do", "some", "checks", "on", "the", "table", "which", "has", "been", "passed", "to", "make", "sure", "that", "it", "has", "what", "we", "need" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L264-L313
train
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.setFilename
public function setFilename($filename) { if (is_array($filename) && isset($filename['name'])) { $this->filename = $filename['name']; } else { $this->filename = $filename; } }
php
public function setFilename($filename) { if (is_array($filename) && isset($filename['name'])) { $this->filename = $filename['name']; } else { $this->filename = $filename; } }
[ "public", "function", "setFilename", "(", "$", "filename", ")", "{", "if", "(", "is_array", "(", "$", "filename", ")", "&&", "isset", "(", "$", "filename", "[", "'name'", "]", ")", ")", "{", "$", "this", "->", "filename", "=", "$", "filename", "[", ...
Set the filename or pull it from the upload array @param string|array $filename The name of the actual file including it's extension @return void
[ "Set", "the", "filename", "or", "pull", "it", "from", "the", "upload", "array" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L158-L165
train
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.setPrefixes
public function setPrefixes(array $thumbnailSizes) { foreach ($thumbnailSizes as $prefix => $dimensions) { array_push($this->prefixes, $prefix); } }
php
public function setPrefixes(array $thumbnailSizes) { foreach ($thumbnailSizes as $prefix => $dimensions) { array_push($this->prefixes, $prefix); } }
[ "public", "function", "setPrefixes", "(", "array", "$", "thumbnailSizes", ")", "{", "foreach", "(", "$", "thumbnailSizes", "as", "$", "prefix", "=>", "$", "dimensions", ")", "{", "array_push", "(", "$", "this", "->", "prefixes", ",", "$", "prefix", ")", ...
Take the configured thumbnail sizes and store the prefixes @param array $thumbnailSizes The 'thumbnailSizes' dimension of the behaviour configuration array @return void
[ "Take", "the", "configured", "thumbnail", "sizes", "and", "store", "the", "prefixes" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L183-L188
train
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.fullPath
public function fullPath($prefix = null) { if ($prefix) { return $this->getFolder() . $prefix . '_' . $this->getFilename(); } return $this->getFolder() . $this->getFilename(); }
php
public function fullPath($prefix = null) { if ($prefix) { return $this->getFolder() . $prefix . '_' . $this->getFilename(); } return $this->getFolder() . $this->getFilename(); }
[ "public", "function", "fullPath", "(", "$", "prefix", "=", "null", ")", "{", "if", "(", "$", "prefix", ")", "{", "return", "$", "this", "->", "getFolder", "(", ")", ".", "$", "prefix", ".", "'_'", ".", "$", "this", "->", "getFilename", "(", ")", ...
Return the complete absolute path to an upload. If it's an image with thumbnails you can pass the prefix to get the path to the prefixed thumbnail file. @param string $prefix Thumbnail prefix @return string
[ "Return", "the", "complete", "absolute", "path", "to", "an", "upload", ".", "If", "it", "s", "an", "image", "with", "thumbnails", "you", "can", "pass", "the", "prefix", "to", "get", "the", "path", "to", "the", "prefixed", "thumbnail", "file", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L212-L219
train
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.getFolder
public function getFolder() { $table = $this->getTable(); $table = (!empty($table)) ? $table . DS : null; $seed = $this->getSeed(); $seed = (!empty($seed)) ? $seed . DS : null; return $this->getRoot() . DS . $table . $this->getField() . DS . $seed; }
php
public function getFolder() { $table = $this->getTable(); $table = (!empty($table)) ? $table . DS : null; $seed = $this->getSeed(); $seed = (!empty($seed)) ? $seed . DS : null; return $this->getRoot() . DS . $table . $this->getField() . DS . $seed; }
[ "public", "function", "getFolder", "(", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "table", "=", "(", "!", "empty", "(", "$", "table", ")", ")", "?", "$", "table", ".", "DS", ":", "null", ";", "$", "seed", ...
Return the absolute path to the containing parent folder where all the files will be uploaded @return string
[ "Return", "the", "absolute", "path", "to", "the", "containing", "parent", "folder", "where", "all", "the", "files", "will", "be", "uploaded" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L226-L235
train
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.deleteFiles
public function deleteFiles($folder, $rmdir = false) { array_map('unlink', glob($folder . DS . '*')); if ($rmdir) { rmdir($folder); } }
php
public function deleteFiles($folder, $rmdir = false) { array_map('unlink', glob($folder . DS . '*')); if ($rmdir) { rmdir($folder); } }
[ "public", "function", "deleteFiles", "(", "$", "folder", ",", "$", "rmdir", "=", "false", ")", "{", "array_map", "(", "'unlink'", ",", "glob", "(", "$", "folder", ".", "DS", ".", "'*'", ")", ")", ";", "if", "(", "$", "rmdir", ")", "{", "rmdir", "...
Clear out a folder and optionally delete it @param string $folder Absolute path to the folder @param bool $rmdir If you want to remove the folder as well @return void
[ "Clear", "out", "a", "folder", "and", "optionally", "delete", "it" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L258-L264
train
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.process
protected function process($field, array $settings, EntityInterface $entity, ProfferPathInterface $path = null) { $path = $this->createPath($entity, $field, $settings, $path); if (is_array($entity->get($field)) && count(array_filter(array_keys($entity->get($field)), 'is_string')) > 0) { $uploadList = [$entity->get($field)]; } else { $uploadList = [ [ 'name' => $entity->get('name'), 'type' => $entity->get('type'), 'tmp_name' => $entity->get('tmp_name'), 'error' => $entity->get('error'), 'size' => $entity->get('size'), ] ]; } foreach ($uploadList as $upload) { if ($this->moveUploadedFile($upload['tmp_name'], $path->fullPath())) { $entity->set($field, $path->getFilename()); $entity->set($settings['dir'], $path->getSeed()); $this->createThumbnails($entity, $settings, $path); } else { throw new CannotUploadFileException("File `{$upload['name']}` could not be copied."); } } unset($path); }
php
protected function process($field, array $settings, EntityInterface $entity, ProfferPathInterface $path = null) { $path = $this->createPath($entity, $field, $settings, $path); if (is_array($entity->get($field)) && count(array_filter(array_keys($entity->get($field)), 'is_string')) > 0) { $uploadList = [$entity->get($field)]; } else { $uploadList = [ [ 'name' => $entity->get('name'), 'type' => $entity->get('type'), 'tmp_name' => $entity->get('tmp_name'), 'error' => $entity->get('error'), 'size' => $entity->get('size'), ] ]; } foreach ($uploadList as $upload) { if ($this->moveUploadedFile($upload['tmp_name'], $path->fullPath())) { $entity->set($field, $path->getFilename()); $entity->set($settings['dir'], $path->getSeed()); $this->createThumbnails($entity, $settings, $path); } else { throw new CannotUploadFileException("File `{$upload['name']}` could not be copied."); } } unset($path); }
[ "protected", "function", "process", "(", "$", "field", ",", "array", "$", "settings", ",", "EntityInterface", "$", "entity", ",", "ProfferPathInterface", "$", "path", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "createPath", "(", "$", "en...
Process any uploaded files, generate paths, move the files and kick off thumbnail generation if it's an image @param string $field The upload field name @param array $settings Array of upload settings for the field @param \Cake\Datasource\EntityInterface $entity The current entity to process @param \Proffer\Lib\ProfferPathInterface|null $path Inject an instance of ProfferPath @throws \Exception If the file cannot be renamed / moved to the correct path @return void
[ "Process", "any", "uploaded", "files", "generate", "paths", "move", "the", "files", "and", "kick", "off", "thumbnail", "generation", "if", "it", "s", "an", "image" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L116-L146
train
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.createPath
protected function createPath(EntityInterface $entity, $field, array $settings, ProfferPathInterface $path = null) { if (!empty($settings['pathClass'])) { $path = new $settings['pathClass']($this->_table, $entity, $field, $settings); if (!$path instanceof ProfferPathInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ProfferPathInterface."); } } elseif (!isset($path)) { $path = new ProfferPath($this->_table, $entity, $field, $settings); } $event = new Event('Proffer.afterPath', $entity, ['path' => $path]); $this->_table->getEventManager()->dispatch($event); if (!empty($event->result)) { $path = $event->result; } $path->createPathFolder(); return $path; }
php
protected function createPath(EntityInterface $entity, $field, array $settings, ProfferPathInterface $path = null) { if (!empty($settings['pathClass'])) { $path = new $settings['pathClass']($this->_table, $entity, $field, $settings); if (!$path instanceof ProfferPathInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ProfferPathInterface."); } } elseif (!isset($path)) { $path = new ProfferPath($this->_table, $entity, $field, $settings); } $event = new Event('Proffer.afterPath', $entity, ['path' => $path]); $this->_table->getEventManager()->dispatch($event); if (!empty($event->result)) { $path = $event->result; } $path->createPathFolder(); return $path; }
[ "protected", "function", "createPath", "(", "EntityInterface", "$", "entity", ",", "$", "field", ",", "array", "$", "settings", ",", "ProfferPathInterface", "$", "path", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "settings", "[", "'pathClass...
Load a path class instance and create the path for the uploads to be moved into @param \Cake\Datasource\EntityInterface $entity Instance of the entity @param string $field The upload field name @param array $settings Array of upload settings for the field @param \Proffer\Lib\ProfferPathInterface|null $path Inject an instance of ProfferPath @throws \App\Exception\InvalidClassException If the custom class doesn't implement the interface @return \Proffer\Lib\ProfferPathInterface
[ "Load", "a", "path", "class", "instance", "and", "create", "the", "path", "for", "the", "uploads", "to", "be", "moved", "into" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L160-L180
train
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.createThumbnails
protected function createThumbnails(EntityInterface $entity, array $settings, ProfferPathInterface $path) { if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) { $imagePaths = [$path->fullPath()]; if (!empty($settings['transformClass'])) { $imageTransform = new $settings['transformClass']($this->_table, $path); if (!$imageTransform instanceof ImageTransformInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ImageTransformInterface."); } } else { $imageTransform = new ImageTransform($this->_table, $path); } $thumbnailPaths = $imageTransform->processThumbnails($settings); $imagePaths = array_merge($imagePaths, $thumbnailPaths); $eventData = ['path' => $path, 'images' => $imagePaths]; $event = new Event('Proffer.afterCreateImage', $entity, $eventData); $this->_table->getEventManager()->dispatch($event); } }
php
protected function createThumbnails(EntityInterface $entity, array $settings, ProfferPathInterface $path) { if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) { $imagePaths = [$path->fullPath()]; if (!empty($settings['transformClass'])) { $imageTransform = new $settings['transformClass']($this->_table, $path); if (!$imageTransform instanceof ImageTransformInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ImageTransformInterface."); } } else { $imageTransform = new ImageTransform($this->_table, $path); } $thumbnailPaths = $imageTransform->processThumbnails($settings); $imagePaths = array_merge($imagePaths, $thumbnailPaths); $eventData = ['path' => $path, 'images' => $imagePaths]; $event = new Event('Proffer.afterCreateImage', $entity, $eventData); $this->_table->getEventManager()->dispatch($event); } }
[ "protected", "function", "createThumbnails", "(", "EntityInterface", "$", "entity", ",", "array", "$", "settings", ",", "ProfferPathInterface", "$", "path", ")", "{", "if", "(", "getimagesize", "(", "$", "path", "->", "fullPath", "(", ")", ")", "!==", "false...
Create a new image transform instance, and create any configured thumbnails; if the upload is an image and there are thumbnails configured. @param \Cake\Datasource\EntityInterface $entity Instance of the entity @param array $settings Array of upload field settings @param \Proffer\Lib\ProfferPathInterface $path Instance of the path class @throws \App\Exception\InvalidClassException If the transform class doesn't implement the interface @return void
[ "Create", "a", "new", "image", "transform", "instance", "and", "create", "any", "configured", "thumbnails", ";", "if", "the", "upload", "is", "an", "image", "and", "there", "are", "thumbnails", "configured", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L194-L215
train
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.moveUploadedFile
protected function moveUploadedFile($file, $destination) { if (is_uploaded_file($file)) { return move_uploaded_file($file, $destination); } return rename($file, $destination); }
php
protected function moveUploadedFile($file, $destination) { if (is_uploaded_file($file)) { return move_uploaded_file($file, $destination); } return rename($file, $destination); }
[ "protected", "function", "moveUploadedFile", "(", "$", "file", ",", "$", "destination", ")", "{", "if", "(", "is_uploaded_file", "(", "$", "file", ")", ")", "{", "return", "move_uploaded_file", "(", "$", "file", ",", "$", "destination", ")", ";", "}", "r...
Wrapper method for move_uploaded_file to facilitate testing and 'uploading' of local files This will check if the file has been uploaded or not before picking the correct method to move the file @param string $file Path to the uploaded file @param string $destination The destination file name @return bool
[ "Wrapper", "method", "for", "move_uploaded_file", "to", "facilitate", "testing", "and", "uploading", "of", "local", "files" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L262-L269
train
imbo/behat-api-extension
src/Context/Initializer/ApiClientAwareInitializer.php
ApiClientAwareInitializer.initializeContext
public function initializeContext(Context $context) { if ($context instanceof ApiClientAwareContext) { // Fetch base URI from the Guzzle client configuration, if it exists $baseUri = !empty($this->guzzleConfig['base_uri']) ? $this->guzzleConfig['base_uri'] : null; if ($baseUri && !$this->validateConnection($baseUri)) { throw new RuntimeException(sprintf('Can\'t connect to base_uri: "%s".', $baseUri)); } $context->setClient(new Client($this->guzzleConfig)); } }
php
public function initializeContext(Context $context) { if ($context instanceof ApiClientAwareContext) { // Fetch base URI from the Guzzle client configuration, if it exists $baseUri = !empty($this->guzzleConfig['base_uri']) ? $this->guzzleConfig['base_uri'] : null; if ($baseUri && !$this->validateConnection($baseUri)) { throw new RuntimeException(sprintf('Can\'t connect to base_uri: "%s".', $baseUri)); } $context->setClient(new Client($this->guzzleConfig)); } }
[ "public", "function", "initializeContext", "(", "Context", "$", "context", ")", "{", "if", "(", "$", "context", "instanceof", "ApiClientAwareContext", ")", "{", "// Fetch base URI from the Guzzle client configuration, if it exists", "$", "baseUri", "=", "!", "empty", "(...
Initialize the context Inject the Guzzle client if the context implements the ApiClientAwareContext interface @param Context $context
[ "Initialize", "the", "context" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/Initializer/ApiClientAwareInitializer.php#L39-L50
train
imbo/behat-api-extension
src/Context/Initializer/ApiClientAwareInitializer.php
ApiClientAwareInitializer.validateConnection
private function validateConnection($baseUri) { $parts = parse_url($baseUri); $host = $parts['host']; $port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'https' ? 443 : 80); set_error_handler(function () { return true; }); $resource = fsockopen($host, $port); restore_error_handler(); if ($resource === false) { // Can't connect return false; } // Connection successful, close connection fclose($resource); return true; }
php
private function validateConnection($baseUri) { $parts = parse_url($baseUri); $host = $parts['host']; $port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'https' ? 443 : 80); set_error_handler(function () { return true; }); $resource = fsockopen($host, $port); restore_error_handler(); if ($resource === false) { // Can't connect return false; } // Connection successful, close connection fclose($resource); return true; }
[ "private", "function", "validateConnection", "(", "$", "baseUri", ")", "{", "$", "parts", "=", "parse_url", "(", "$", "baseUri", ")", ";", "$", "host", "=", "$", "parts", "[", "'host'", "]", ";", "$", "port", "=", "isset", "(", "$", "parts", "[", "...
Validate a connection to the base URI @param string $baseUri @return boolean
[ "Validate", "a", "connection", "to", "the", "base", "URI" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/Initializer/ApiClientAwareInitializer.php#L58-L79
train
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.addFunction
public function addFunction($name, $callback) { if (!is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'Callback provided for function "%s" is not callable.', $name )); } $this->functions[$name] = $callback; return $this; }
php
public function addFunction($name, $callback) { if (!is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'Callback provided for function "%s" is not callable.', $name )); } $this->functions[$name] = $callback; return $this; }
[ "public", "function", "addFunction", "(", "$", "name", ",", "$", "callback", ")", "{", "if", "(", "!", "is_callable", "(", "$", "callback", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Callback provided for function \"%s\" is...
Add a custom matcher function If an existing function exists with the same name it will be replaced @param string $name The name of the function, for instance "length" @param callable $callback The piece of callback code @throws InvalidArgumentException Throws an exception if the callback is not callable @return self
[ "Add", "a", "custom", "matcher", "function" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L34-L45
train
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.getMatcherFunction
public function getMatcherFunction($name) { if (!isset($this->functions[$name])) { throw new InvalidArgumentException(sprintf( 'No matcher function registered for "%s".', $name )); } return $this->functions[$name]; }
php
public function getMatcherFunction($name) { if (!isset($this->functions[$name])) { throw new InvalidArgumentException(sprintf( 'No matcher function registered for "%s".', $name )); } return $this->functions[$name]; }
[ "public", "function", "getMatcherFunction", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "functions", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'No matcher functi...
Get a matcher function by name @param string $name The name of the matcher function @return mixed
[ "Get", "a", "matcher", "function", "by", "name" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L53-L62
train
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.compareValues
protected function compareValues($needleValue, $haystackValue) { $match = []; // List of available function names $functions = array_map(function($value) { return preg_quote($value, '/'); }, array_keys($this->functions)); // Dynamic pattern, based on the keys in the functions list $pattern = sprintf( '/^@(?<function>%s)\((?<params>.*?)\)$/', implode('|', $functions) ); if (is_string($needleValue) && $functions && preg_match($pattern, $needleValue, $match)) { // Custom function matching $function = $match['function']; $params = $match['params']; try { $this->functions[$function]($haystackValue, $params); return true; } catch (Exception $e) { throw new ArrayContainsComparatorException( sprintf( 'Function "%s" failed with error message: "%s".', $function, $e->getMessage() ), 0, $e, $needleValue, $haystackValue ); } } // Regular value matching return $needleValue === $haystackValue; }
php
protected function compareValues($needleValue, $haystackValue) { $match = []; // List of available function names $functions = array_map(function($value) { return preg_quote($value, '/'); }, array_keys($this->functions)); // Dynamic pattern, based on the keys in the functions list $pattern = sprintf( '/^@(?<function>%s)\((?<params>.*?)\)$/', implode('|', $functions) ); if (is_string($needleValue) && $functions && preg_match($pattern, $needleValue, $match)) { // Custom function matching $function = $match['function']; $params = $match['params']; try { $this->functions[$function]($haystackValue, $params); return true; } catch (Exception $e) { throw new ArrayContainsComparatorException( sprintf( 'Function "%s" failed with error message: "%s".', $function, $e->getMessage() ), 0, $e, $needleValue, $haystackValue ); } } // Regular value matching return $needleValue === $haystackValue; }
[ "protected", "function", "compareValues", "(", "$", "needleValue", ",", "$", "haystackValue", ")", "{", "$", "match", "=", "[", "]", ";", "// List of available function names", "$", "functions", "=", "array_map", "(", "function", "(", "$", "value", ")", "{", ...
Compare a value from a needle with a value from the haystack Based on the value of the needle, this method will perform a regular value comparison, or a custom function match. @param mixed $needleValue @param mixed $haystackValue @throws ArrayContainsComparatorException @return boolean
[ "Compare", "a", "value", "from", "a", "needle", "with", "a", "value", "from", "the", "haystack" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L174-L210
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.addMultipartFileToRequest
public function addMultipartFileToRequest($path, $partName) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } // Create the multipart entry in the request options if it does not already exist if (!isset($this->requestOptions['multipart'])) { $this->requestOptions['multipart'] = []; } // Add an entry to the multipart array $this->requestOptions['multipart'][] = [ 'name' => $partName, 'contents' => fopen($path, 'r'), 'filename' => basename($path), ]; return $this; }
php
public function addMultipartFileToRequest($path, $partName) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } // Create the multipart entry in the request options if it does not already exist if (!isset($this->requestOptions['multipart'])) { $this->requestOptions['multipart'] = []; } // Add an entry to the multipart array $this->requestOptions['multipart'][] = [ 'name' => $partName, 'contents' => fopen($path, 'r'), 'filename' => basename($path), ]; return $this; }
[ "public", "function", "addMultipartFileToRequest", "(", "$", "path", ",", "$", "partName", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'File does not exist: \"%s\"'",...
Attach a file to the request @param string $path Path to the image to add to the request @param string $partName Multipart entry name @throws InvalidArgumentException If the $path does not point to a file, an exception is thrown @return self @Given I attach :path to the request as :partName
[ "Attach", "a", "file", "to", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L107-L125
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestHeader
public function setRequestHeader($header, $value) { $this->request = $this->request->withHeader($header, $value); return $this; }
php
public function setRequestHeader($header, $value) { $this->request = $this->request->withHeader($header, $value); return $this; }
[ "public", "function", "setRequestHeader", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "request", "=", "$", "this", "->", "request", "->", "withHeader", "(", "$", "header", ",", "$", "value", ")", ";", "return", "$", "this", ";...
Set a HTTP request header If the header already exists it will be overwritten @param string $header The header name @param string $value The header value @return self @Given the :header request header is :value
[ "Set", "a", "HTTP", "request", "header" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L153-L157
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestFormParams
public function setRequestFormParams(TableNode $table) { if (!isset($this->requestOptions['form_params'])) { $this->requestOptions['form_params'] = []; } foreach ($table as $row) { $name = $row['name']; $value = $row['value']; if (isset($this->requestOptions['form_params'][$name]) && !is_array($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name] = [$this->requestOptions['form_params'][$name]]; } if (isset($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name][] = $value; } else { $this->requestOptions['form_params'][$name] = $value; } } return $this; }
php
public function setRequestFormParams(TableNode $table) { if (!isset($this->requestOptions['form_params'])) { $this->requestOptions['form_params'] = []; } foreach ($table as $row) { $name = $row['name']; $value = $row['value']; if (isset($this->requestOptions['form_params'][$name]) && !is_array($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name] = [$this->requestOptions['form_params'][$name]]; } if (isset($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name][] = $value; } else { $this->requestOptions['form_params'][$name] = $value; } } return $this; }
[ "public", "function", "setRequestFormParams", "(", "TableNode", "$", "table", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]", ")", ")", "{", "$", "this", "->", "requestOptions", "[", "'form_params'", ...
Set form parameters @param TableNode $table Table with name / value pairs @return self @Given the following form parameters are set:
[ "Set", "form", "parameters" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L184-L205
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestBody
public function setRequestBody($string) { if (!empty($this->requestOptions['multipart']) || !empty($this->requestOptions['form_params'])) { throw new InvalidArgumentException( 'It\'s not allowed to set a request body when using multipart/form-data or form parameters.' ); } $this->request = $this->request->withBody(Psr7\stream_for($string)); return $this; }
php
public function setRequestBody($string) { if (!empty($this->requestOptions['multipart']) || !empty($this->requestOptions['form_params'])) { throw new InvalidArgumentException( 'It\'s not allowed to set a request body when using multipart/form-data or form parameters.' ); } $this->request = $this->request->withBody(Psr7\stream_for($string)); return $this; }
[ "public", "function", "setRequestBody", "(", "$", "string", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'multipart'", "]", ")", "||", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]"...
Set the request body to a string @param resource|string|PyStringNode $string The content to set as the request body @throws InvalidArgumentException If form_params or multipart is used in the request options an exception will be thrown as these can't be combined. @return self @Given the request body is:
[ "Set", "the", "request", "body", "to", "a", "string" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L217-L227
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestBodyToFileResource
public function setRequestBodyToFileResource($path) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path)); } // Set the Content-Type request header and the request body return $this ->setRequestHeader('Content-Type', mime_content_type($path)) ->setRequestBody(fopen($path, 'r')); }
php
public function setRequestBodyToFileResource($path) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path)); } // Set the Content-Type request header and the request body return $this ->setRequestHeader('Content-Type', mime_content_type($path)) ->setRequestBody(fopen($path, 'r')); }
[ "public", "function", "setRequestBodyToFileResource", "(", "$", "path", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'File does not exist: \"%s\"'", ",", "$", "path", ...
Set the request body to a read-only resource pointing to a file This step will open a read-only resource to $path and attach it to the request body. If the file does not exist or is not readable the method will end up throwing an exception. The method will also set the Content-Type request header. mime_content_type() is used to get the mime type of the file. @param string $path Path to a file @throws InvalidArgumentException @return self @Given the request body contains :path
[ "Set", "the", "request", "body", "to", "a", "read", "-", "only", "resource", "pointing", "to", "a", "file" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L243-L256
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.addJwtToken
public function addJwtToken($name, $secret, PyStringNode $payload) { $jwtMatcher = $this->arrayContainsComparator->getMatcherFunction('jwt'); if (!($jwtMatcher instanceof JwtMatcher)) { throw new RuntimeException(sprintf( 'Matcher registered for the @jwt() matcher function must be an instance of %s', JwtMatcher::class )); } $jwtMatcher->addToken($name, $this->jsonDecode((string) $payload), $secret); return $this; }
php
public function addJwtToken($name, $secret, PyStringNode $payload) { $jwtMatcher = $this->arrayContainsComparator->getMatcherFunction('jwt'); if (!($jwtMatcher instanceof JwtMatcher)) { throw new RuntimeException(sprintf( 'Matcher registered for the @jwt() matcher function must be an instance of %s', JwtMatcher::class )); } $jwtMatcher->addToken($name, $this->jsonDecode((string) $payload), $secret); return $this; }
[ "public", "function", "addJwtToken", "(", "$", "name", ",", "$", "secret", ",", "PyStringNode", "$", "payload", ")", "{", "$", "jwtMatcher", "=", "$", "this", "->", "arrayContainsComparator", "->", "getMatcherFunction", "(", "'jwt'", ")", ";", "if", "(", "...
Add a JWT token to the matcher @param string $name String identifying the token @param string $secret The secret used to sign the token @param PyStringNode $payload The payload for the JWT @throws RuntimeException @return self @Given the response body contains a JWT identified by :name, signed with :secret:
[ "Add", "a", "JWT", "token", "to", "the", "matcher" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L269-L282
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.requestPath
public function requestPath($path, $method = null) { $this->setRequestPath($path); if (null === $method) { $this->setRequestMethod('GET', false); } else { $this->setRequestMethod($method); } return $this->sendRequest(); }
php
public function requestPath($path, $method = null) { $this->setRequestPath($path); if (null === $method) { $this->setRequestMethod('GET', false); } else { $this->setRequestMethod($method); } return $this->sendRequest(); }
[ "public", "function", "requestPath", "(", "$", "path", ",", "$", "method", "=", "null", ")", "{", "$", "this", "->", "setRequestPath", "(", "$", "path", ")", ";", "if", "(", "null", "===", "$", "method", ")", "{", "$", "this", "->", "setRequestMethod...
Request a path @param string $path The path to request @param string $method The HTTP method to use @return self @When I request :path @When I request :path using HTTP :method
[ "Request", "a", "path" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L294-L304
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseCodeIs
public function assertResponseCodeIs($code) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getStatusCode(), $expected = $this->validateResponseCode($code), sprintf('Expected response code %d, got %d.', $expected, $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseCodeIs($code) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getStatusCode(), $expected = $this->validateResponseCode($code), sprintf('Expected response code %d, got %d.', $expected, $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseCodeIs", "(", "$", "code", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getStatusCode", "(", ")",...
Assert the HTTP response code @param int $code The HTTP response code @throws AssertionFailedException @return void @Then the response code is :code
[ "Assert", "the", "HTTP", "response", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L315-L327
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseCodeIsNot
public function assertResponseCodeIsNot($code) { $this->requireResponse(); try { Assertion::notSame( $actual = $this->response->getStatusCode(), $this->validateResponseCode($code), sprintf('Did not expect response code %d.', $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseCodeIsNot($code) { $this->requireResponse(); try { Assertion::notSame( $actual = $this->response->getStatusCode(), $this->validateResponseCode($code), sprintf('Did not expect response code %d.', $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseCodeIsNot", "(", "$", "code", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getStatusCode", "(", ...
Assert the HTTP response code is not a specific code @param int $code The HTTP response code @throws AssertionFailedException @return void @Then the response code is not :code
[ "Assert", "the", "HTTP", "response", "code", "is", "not", "a", "specific", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L338-L350
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseIs
public function assertResponseReasonPhraseIs($phrase) { $this->requireResponse(); try { Assertion::same($phrase, $actual = $this->response->getReasonPhrase(), sprintf( 'Expected response reason phrase "%s", got "%s".', $phrase, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseIs($phrase) { $this->requireResponse(); try { Assertion::same($phrase, $actual = $this->response->getReasonPhrase(), sprintf( 'Expected response reason phrase "%s", got "%s".', $phrase, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseIs", "(", "$", "phrase", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "phrase", ",", "$", "actual", "=", "$", "this", "->", "response", "-...
Assert that the HTTP response reason phrase equals a given value @param string $phrase Expected HTTP response reason phrase @throws AssertionFailedException @return void @Then the response reason phrase is :phrase
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "equals", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L361-L373
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseIsNot
public function assertResponseReasonPhraseIsNot($phrase) { $this->requireResponse(); try { Assertion::notSame($phrase, $this->response->getReasonPhrase(), sprintf( 'Did not expect response reason phrase "%s".', $phrase )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseIsNot($phrase) { $this->requireResponse(); try { Assertion::notSame($phrase, $this->response->getReasonPhrase(), sprintf( 'Did not expect response reason phrase "%s".', $phrase )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseIsNot", "(", "$", "phrase", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "phrase", ",", "$", "this", "->", "response", "->", "getReasonPhra...
Assert that the HTTP response reason phrase does not equal a given value @param string $phrase Reason phrase that the HTTP response should not equal @throws AssertionFailedException @return void @Then the response reason phrase is not :phrase
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "does", "not", "equal", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L384-L395
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseMatches
public function assertResponseReasonPhraseMatches($pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getReasonPhrase(), $pattern, sprintf( 'Expected the response reason phrase to match the regular expression "%s", got "%s".', $pattern, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseMatches($pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getReasonPhrase(), $pattern, sprintf( 'Expected the response reason phrase to match the regular expression "%s", got "%s".', $pattern, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseMatches", "(", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "regex", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getReasonPhr...
Assert that the HTTP response reason phrase matches a regular expression @param string $pattern Regular expression pattern @throws AssertionFailedException @return void @Then the response reason phrase matches :expression
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "matches", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L406-L421
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineIs
public function assertResponseStatusLineIs($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::same($line, $actualStatusLine, sprintf( 'Expected response status line "%s", got "%s".', $line, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineIs($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::same($line, $actualStatusLine, sprintf( 'Expected response status line "%s", got "%s".', $line, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineIs", "(", "$", "line", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getStatusCode...
Assert that the HTTP response status line equals a given value @param string $line Expected HTTP response status line @throws AssertionFailedException @return void @Then the response status line is :line
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "equals", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L432-L450
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineIsNot
public function assertResponseStatusLineIsNot($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::notSame($line, $actualStatusLine, sprintf( 'Did not expect response status line "%s".', $line )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineIsNot($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::notSame($line, $actualStatusLine, sprintf( 'Did not expect response status line "%s".', $line )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineIsNot", "(", "$", "line", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getStatusC...
Assert that the HTTP response status line does not equal a given value @param string $line Value that the HTTP response status line must not equal @throws AssertionFailedException @return void @Then the response status line is not :line
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "does", "not", "equal", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L461-L478
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineMatches
public function assertResponseStatusLineMatches($pattern) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::regex( $actualStatusLine, $pattern, sprintf( 'Expected the response status line to match the regular expression "%s", got "%s".', $pattern, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineMatches($pattern) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::regex( $actualStatusLine, $pattern, sprintf( 'Expected the response status line to match the regular expression "%s", got "%s".', $pattern, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineMatches", "(", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getSt...
Assert that the HTTP response status line matches a regular expression @param string $pattern Regular expression pattern @throws AssertionFailedException @return void @Then the response status line matches :expression
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "matches", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L489-L510
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseIs
public function assertResponseIs($group) { $this->requireResponse(); $range = $this->getResponseCodeGroupRange($group); try { Assertion::range($code = $this->response->getStatusCode(), $range['min'], $range['max']); } catch (AssertionFailure $e) { throw new AssertionFailedException(sprintf( 'Expected response group "%s", got "%s" (response code: %d).', $group, $this->getResponseGroup($code), $code )); } }
php
public function assertResponseIs($group) { $this->requireResponse(); $range = $this->getResponseCodeGroupRange($group); try { Assertion::range($code = $this->response->getStatusCode(), $range['min'], $range['max']); } catch (AssertionFailure $e) { throw new AssertionFailedException(sprintf( 'Expected response group "%s", got "%s" (response code: %d).', $group, $this->getResponseGroup($code), $code )); } }
[ "public", "function", "assertResponseIs", "(", "$", "group", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "range", "=", "$", "this", "->", "getResponseCodeGroupRange", "(", "$", "group", ")", ";", "try", "{", "Assertion", "::", "ra...
Checks if the HTTP response code is in a group Allowed groups are: - informational - success - redirection - client error - server error @param string $group Name of the group that the response code should be in @throws AssertionFailedException @return void @Then the response is :group
[ "Checks", "if", "the", "HTTP", "response", "code", "is", "in", "a", "group" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L529-L543
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderExists
public function assertResponseHeaderExists($header) { $this->requireResponse(); try { Assertion::true( $this->response->hasHeader($header), sprintf('The "%s" response header does not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderExists($header) { $this->requireResponse(); try { Assertion::true( $this->response->hasHeader($header), sprintf('The "%s" response header does not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderExists", "(", "$", "header", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "true", "(", "$", "this", "->", "response", "->", "hasHeader", "(", "$", "header", ")", ...
Assert that a response header exists @param string $header Then name of the header @throws AssertionFailedException @return void @Then the :header response header exists
[ "Assert", "that", "a", "response", "header", "exists" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L586-L597
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderDoesNotExist
public function assertResponseHeaderDoesNotExist($header) { $this->requireResponse(); try { Assertion::false( $this->response->hasHeader($header), sprintf('The "%s" response header should not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderDoesNotExist($header) { $this->requireResponse(); try { Assertion::false( $this->response->hasHeader($header), sprintf('The "%s" response header should not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderDoesNotExist", "(", "$", "header", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "false", "(", "$", "this", "->", "response", "->", "hasHeader", "(", "$", "header", ...
Assert that a response header does not exist @param string $header Then name of the header @throws AssertionFailedException @return void @Then the :header response header does not exist
[ "Assert", "that", "a", "response", "header", "does", "not", "exist" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L608-L619
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderIs
public function assertResponseHeaderIs($header, $value) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getHeaderLine($header), $value, sprintf( 'Expected the "%s" response header to be "%s", got "%s".', $header, $value, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderIs($header, $value) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getHeaderLine($header), $value, sprintf( 'Expected the "%s" response header to be "%s", got "%s".', $header, $value, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderIs", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "...
Compare a response header value against a string @param string $header The name of the header @param string $value The value to compare with @throws AssertionFailedException @return void @Then the :header response header is :value
[ "Compare", "a", "response", "header", "value", "against", "a", "string" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L631-L648
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderIsNot
public function assertResponseHeaderIsNot($header, $value) { $this->requireResponse(); try { Assertion::notSame( $this->response->getHeaderLine($header), $value, sprintf( 'Did not expect the "%s" response header to be "%s".', $header, $value ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderIsNot($header, $value) { $this->requireResponse(); try { Assertion::notSame( $this->response->getHeaderLine($header), $value, sprintf( 'Did not expect the "%s" response header to be "%s".', $header, $value ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderIsNot", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "this", "->", "response", "->", "getHeaderLine", "(...
Assert that a response header is not a value @param string $header The name of the header @param string $value The value to compare with @throws AssertionFailedException @return void @Then the :header response header is not :value
[ "Assert", "that", "a", "response", "header", "is", "not", "a", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L660-L676
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderMatches
public function assertResponseHeaderMatches($header, $pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getHeaderLine($header), $pattern, sprintf( 'Expected the "%s" response header to match the regular expression "%s", got "%s".', $header, $pattern, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderMatches($header, $pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getHeaderLine($header), $pattern, sprintf( 'Expected the "%s" response header to match the regular expression "%s", got "%s".', $header, $pattern, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderMatches", "(", "$", "header", ",", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "regex", "(", "$", "actual", "=", "$", "this", "->", "response", "...
Match a response header value against a regular expression pattern @param string $header The name of the header @param string $pattern The regular expression pattern @throws AssertionFailedException @return void @Then the :header response header matches :pattern
[ "Match", "a", "response", "header", "value", "against", "a", "regular", "expression", "pattern" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L688-L705
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsAnEmptyJsonObject
public function assertResponseBodyIsAnEmptyJsonObject() { $this->requireResponse(); $body = $this->getResponseBody(); try { Assertion::isInstanceOf($body, 'stdClass', 'Expected response body to be a JSON object.'); Assertion::same('{}', $encoded = json_encode($body, JSON_PRETTY_PRINT), sprintf( 'Expected response body to be an empty JSON object, got "%s".', $encoded )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsAnEmptyJsonObject() { $this->requireResponse(); $body = $this->getResponseBody(); try { Assertion::isInstanceOf($body, 'stdClass', 'Expected response body to be a JSON object.'); Assertion::same('{}', $encoded = json_encode($body, JSON_PRETTY_PRINT), sprintf( 'Expected response body to be an empty JSON object, got "%s".', $encoded )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsAnEmptyJsonObject", "(", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "body", "=", "$", "this", "->", "getResponseBody", "(", ")", ";", "try", "{", "Assertion", "::", "isInstanceOf", "(", "$",...
Assert that the response body contains an empty JSON object @throws AssertionFailedException @return void @Then the response body is an empty JSON object
[ "Assert", "that", "the", "response", "body", "contains", "an", "empty", "JSON", "object" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L715-L728
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsAnEmptyJsonArray
public function assertResponseBodyIsAnEmptyJsonArray() { $this->requireResponse(); try { Assertion::same( [], $body = $this->getResponseBodyArray(), sprintf('Expected response body to be an empty JSON array, got "%s".', json_encode($body, JSON_PRETTY_PRINT)) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsAnEmptyJsonArray() { $this->requireResponse(); try { Assertion::same( [], $body = $this->getResponseBodyArray(), sprintf('Expected response body to be an empty JSON array, got "%s".', json_encode($body, JSON_PRETTY_PRINT)) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsAnEmptyJsonArray", "(", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "[", "]", ",", "$", "body", "=", "$", "this", "->", "getResponseBodyArray", "(", "...
Assert that the response body contains an empty JSON array @throws AssertionFailedException @return void @Then the response body is an empty JSON array
[ "Assert", "that", "the", "response", "body", "contains", "an", "empty", "JSON", "array" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L738-L750
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyJsonArrayLength
public function assertResponseBodyJsonArrayLength($length) { $this->requireResponse(); $length = (int) $length; try { Assertion::count( $body = $this->getResponseBodyArray(), $length, sprintf( 'Expected response body to be a JSON array with %d entr%s, got %d: "%s".', $length, $length === 1 ? 'y' : 'ies', count($body), json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyJsonArrayLength($length) { $this->requireResponse(); $length = (int) $length; try { Assertion::count( $body = $this->getResponseBodyArray(), $length, sprintf( 'Expected response body to be a JSON array with %d entr%s, got %d: "%s".', $length, $length === 1 ? 'y' : 'ies', count($body), json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyJsonArrayLength", "(", "$", "length", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "length", "=", "(", "int", ")", "$", "length", ";", "try", "{", "Assertion", "::", "count", "(", "$", "body...
Assert that the response body contains an array with a specific length @param int $length The length of the array @throws AssertionFailedException @return void @Then the response body is a JSON array of length :length
[ "Assert", "that", "the", "response", "body", "contains", "an", "array", "with", "a", "specific", "length" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L761-L780
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyJsonArrayMinLength
public function assertResponseBodyJsonArrayMinLength($length) { $this->requireResponse(); $length = (int) $length; $body = $this->getResponseBodyArray(); try { Assertion::min( $bodyLength = count($body), $length, sprintf( 'Expected response body to be a JSON array with at least %d entr%s, got %d: "%s".', $length, (int) $length === 1 ? 'y' : 'ies', $bodyLength, json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyJsonArrayMinLength($length) { $this->requireResponse(); $length = (int) $length; $body = $this->getResponseBodyArray(); try { Assertion::min( $bodyLength = count($body), $length, sprintf( 'Expected response body to be a JSON array with at least %d entr%s, got %d: "%s".', $length, (int) $length === 1 ? 'y' : 'ies', $bodyLength, json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyJsonArrayMinLength", "(", "$", "length", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "length", "=", "(", "int", ")", "$", "length", ";", "$", "body", "=", "$", "this", "->", "getResponseBodyA...
Assert that the response body contains an array with a length of at least a given length @param int $length The length to use in the assertion @throws AssertionFailedException @return void @Then the response body is a JSON array with a length of at least :length
[ "Assert", "that", "the", "response", "body", "contains", "an", "array", "with", "a", "length", "of", "at", "least", "a", "given", "length" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L791-L812
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIs
public function assertResponseBodyIs(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::same($body = (string) $this->response->getBody(), $content, sprintf( 'Expected response body "%s", got "%s".', $content, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIs(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::same($body = (string) $this->response->getBody(), $content, sprintf( 'Expected response body "%s", got "%s".', $content, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIs", "(", "PyStringNode", "$", "content", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "content", "=", "(", "string", ")", "$", "content", ";", "try", "{", "Assertion", "::", "same", "(", "$...
Assert that the response body matches some content @param PyStringNode $content The content to match the response body against @throws AssertionFailedException @return void @Then the response body is:
[ "Assert", "that", "the", "response", "body", "matches", "some", "content" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L856-L869
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsNot
public function assertResponseBodyIsNot(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::notSame((string) $this->response->getBody(), $content, sprintf( 'Did not expect response body to be "%s".', $content )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsNot(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::notSame((string) $this->response->getBody(), $content, sprintf( 'Did not expect response body to be "%s".', $content )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsNot", "(", "PyStringNode", "$", "content", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "content", "=", "(", "string", ")", "$", "content", ";", "try", "{", "Assertion", "::", "notSame", "("...
Assert that the response body does not match some content @param PyStringNode $content The content that the response body should not match @throws AssertionFailedException @return void @Then the response body is not:
[ "Assert", "that", "the", "response", "body", "does", "not", "match", "some", "content" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L880-L892
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyMatches
public function assertResponseBodyMatches(PyStringNode $pattern) { $this->requireResponse(); $pattern = (string) $pattern; try { Assertion::regex($body = (string) $this->response->getBody(), $pattern, sprintf( 'Expected response body to match regular expression "%s", got "%s".', $pattern, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyMatches(PyStringNode $pattern) { $this->requireResponse(); $pattern = (string) $pattern; try { Assertion::regex($body = (string) $this->response->getBody(), $pattern, sprintf( 'Expected response body to match regular expression "%s", got "%s".', $pattern, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyMatches", "(", "PyStringNode", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "pattern", "=", "(", "string", ")", "$", "pattern", ";", "try", "{", "Assertion", "::", "regex", "("...
Assert that the response body matches some content using a regular expression @param PyStringNode $pattern The regular expression pattern to use for the match @throws AssertionFailedException @return void @Then the response body matches:
[ "Assert", "that", "the", "response", "body", "matches", "some", "content", "using", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L903-L916
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.sendRequest
protected function sendRequest() { if (!empty($this->requestOptions['form_params']) && !$this->forceHttpMethod) { $this->setRequestMethod('POST'); } if (!empty($this->requestOptions['multipart']) && !empty($this->requestOptions['form_params'])) { // We have both multipart and form_params set in the request options. Take all // form_params and add them to the multipart part of the option array as it's not // allowed to have both. foreach ($this->requestOptions['form_params'] as $name => $contents) { if (is_array($contents)) { // The contents is an array, so use array notation for the part name and store // all values under this name $name .= '[]'; foreach ($contents as $content) { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $content, ]; } } else { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $contents ]; } } // Remove form_params from the options, otherwise Guzzle will throw an exception unset($this->requestOptions['form_params']); } try { $this->response = $this->client->send( $this->request, $this->requestOptions ); } catch (RequestException $e) { $this->response = $e->getResponse(); if (!$this->response) { throw $e; } } return $this; }
php
protected function sendRequest() { if (!empty($this->requestOptions['form_params']) && !$this->forceHttpMethod) { $this->setRequestMethod('POST'); } if (!empty($this->requestOptions['multipart']) && !empty($this->requestOptions['form_params'])) { // We have both multipart and form_params set in the request options. Take all // form_params and add them to the multipart part of the option array as it's not // allowed to have both. foreach ($this->requestOptions['form_params'] as $name => $contents) { if (is_array($contents)) { // The contents is an array, so use array notation for the part name and store // all values under this name $name .= '[]'; foreach ($contents as $content) { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $content, ]; } } else { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $contents ]; } } // Remove form_params from the options, otherwise Guzzle will throw an exception unset($this->requestOptions['form_params']); } try { $this->response = $this->client->send( $this->request, $this->requestOptions ); } catch (RequestException $e) { $this->response = $e->getResponse(); if (!$this->response) { throw $e; } } return $this; }
[ "protected", "function", "sendRequest", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]", ")", "&&", "!", "$", "this", "->", "forceHttpMethod", ")", "{", "$", "this", "->", "setRequestMethod", "(...
Send the current request and set the response instance @throws RequestException @return self
[ "Send", "the", "current", "request", "and", "set", "the", "response", "instance" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L952-L999
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.getResponseCodeGroupRange
protected function getResponseCodeGroupRange($group) { switch ($group) { case 'informational': $min = 100; $max = 199; break; case 'success': $min = 200; $max = 299; break; case 'redirection': $min = 300; $max = 399; break; case 'client error': $min = 400; $max = 499; break; case 'server error': $min = 500; $max = 599; break; default: throw new InvalidArgumentException(sprintf('Invalid response code group: %s', $group)); } return [ 'min' => $min, 'max' => $max, ]; }
php
protected function getResponseCodeGroupRange($group) { switch ($group) { case 'informational': $min = 100; $max = 199; break; case 'success': $min = 200; $max = 299; break; case 'redirection': $min = 300; $max = 399; break; case 'client error': $min = 400; $max = 499; break; case 'server error': $min = 500; $max = 599; break; default: throw new InvalidArgumentException(sprintf('Invalid response code group: %s', $group)); } return [ 'min' => $min, 'max' => $max, ]; }
[ "protected", "function", "getResponseCodeGroupRange", "(", "$", "group", ")", "{", "switch", "(", "$", "group", ")", "{", "case", "'informational'", ":", "$", "min", "=", "100", ";", "$", "max", "=", "199", ";", "break", ";", "case", "'success'", ":", ...
Get the min and max values for a response body group @param string $group The name of the group @throws InvalidArgumentException @return array An array with two keys, min and max, which represents the min and max values for $group
[ "Get", "the", "min", "and", "max", "values", "for", "a", "response", "body", "group" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1020-L1050
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.validateResponseCode
protected function validateResponseCode($code) { $code = (int) $code; try { Assertion::range($code, 100, 599, sprintf('Response code must be between 100 and 599, got %d.', $code)); } catch (AssertionFailure $e) { throw new InvalidArgumentException($e->getMessage()); } return $code; }
php
protected function validateResponseCode($code) { $code = (int) $code; try { Assertion::range($code, 100, 599, sprintf('Response code must be between 100 and 599, got %d.', $code)); } catch (AssertionFailure $e) { throw new InvalidArgumentException($e->getMessage()); } return $code; }
[ "protected", "function", "validateResponseCode", "(", "$", "code", ")", "{", "$", "code", "=", "(", "int", ")", "$", "code", ";", "try", "{", "Assertion", "::", "range", "(", "$", "code", ",", "100", ",", "599", ",", "sprintf", "(", "'Response code mus...
Validate a response code @param int $code @throws InvalidArgumentException @return int
[ "Validate", "a", "response", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1081-L1091
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestPath
protected function setRequestPath($path) { // Resolve the path with the base_uri set in the client $uri = Psr7\Uri::resolve($this->client->getConfig('base_uri'), Psr7\uri_for($path)); $this->request = $this->request->withUri($uri); return $this; }
php
protected function setRequestPath($path) { // Resolve the path with the base_uri set in the client $uri = Psr7\Uri::resolve($this->client->getConfig('base_uri'), Psr7\uri_for($path)); $this->request = $this->request->withUri($uri); return $this; }
[ "protected", "function", "setRequestPath", "(", "$", "path", ")", "{", "// Resolve the path with the base_uri set in the client", "$", "uri", "=", "Psr7", "\\", "Uri", "::", "resolve", "(", "$", "this", "->", "client", "->", "getConfig", "(", "'base_uri'", ")", ...
Update the path of the request @param string $path The path to request @return self
[ "Update", "the", "path", "of", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1099-L1105
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestMethod
protected function setRequestMethod($method, $force = true) { $this->request = $this->request->withMethod($method); $this->forceHttpMethod = $force; return $this; }
php
protected function setRequestMethod($method, $force = true) { $this->request = $this->request->withMethod($method); $this->forceHttpMethod = $force; return $this; }
[ "protected", "function", "setRequestMethod", "(", "$", "method", ",", "$", "force", "=", "true", ")", "{", "$", "this", "->", "request", "=", "$", "this", "->", "request", "->", "withMethod", "(", "$", "method", ")", ";", "$", "this", "->", "forceHttpM...
Update the HTTP method of the request @param string $method The HTTP method @param boolean $force Force the HTTP method. If set to false the method set CAN be overridden (this occurs for instance when adding form parameters to the request, and not specifying HTTP POST for the request) @return self
[ "Update", "the", "HTTP", "method", "of", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1116-L1121
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.getResponseBody
protected function getResponseBody() { $body = json_decode((string) $this->response->getBody()); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException('The response body does not contain valid JSON data.'); } else if (!is_array($body) && !($body instanceof stdClass)) { throw new InvalidArgumentException('The response body does not contain a valid JSON array / object.'); } return $body; }
php
protected function getResponseBody() { $body = json_decode((string) $this->response->getBody()); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException('The response body does not contain valid JSON data.'); } else if (!is_array($body) && !($body instanceof stdClass)) { throw new InvalidArgumentException('The response body does not contain a valid JSON array / object.'); } return $body; }
[ "protected", "function", "getResponseBody", "(", ")", "{", "$", "body", "=", "json_decode", "(", "(", "string", ")", "$", "this", "->", "response", "->", "getBody", "(", ")", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")"...
Get the JSON-encoded array or stdClass from the response body @throws InvalidArgumentException @return array|stdClass
[ "Get", "the", "JSON", "-", "encoded", "array", "or", "stdClass", "from", "the", "response", "body" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1129-L1139
train
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.jsonDecode
protected function jsonDecode($value, $errorMessage = null) { $decoded = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException( $errorMessage ?: 'The supplied parameter is not a valid JSON object.' ); } return $decoded; }
php
protected function jsonDecode($value, $errorMessage = null) { $decoded = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException( $errorMessage ?: 'The supplied parameter is not a valid JSON object.' ); } return $decoded; }
[ "protected", "function", "jsonDecode", "(", "$", "value", ",", "$", "errorMessage", "=", "null", ")", "{", "$", "decoded", "=", "json_decode", "(", "$", "value", ",", "true", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")"...
Convert some variable to a JSON-array @param string $value The value to decode @param string $errorMessage Optional error message @throws InvalidArgumentException @return array
[ "Convert", "some", "variable", "to", "a", "JSON", "-", "array" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1163-L1173
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.prepareScenario
public function prepareScenario(BeforeScenarioScope $scope) { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-api-extension' . DIRECTORY_SEPARATOR . microtime(true); mkdir($dir . '/features/bootstrap', 0777, true); // Locate the php binary if (($bin = (new PhpExecutableFinder())->find()) === false) { throw new RuntimeException('Unable to find the PHP executable.'); } $this->workingDir = $dir; $this->phpBin = $bin; $this->process = new Process(null); }
php
public function prepareScenario(BeforeScenarioScope $scope) { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-api-extension' . DIRECTORY_SEPARATOR . microtime(true); mkdir($dir . '/features/bootstrap', 0777, true); // Locate the php binary if (($bin = (new PhpExecutableFinder())->find()) === false) { throw new RuntimeException('Unable to find the PHP executable.'); } $this->workingDir = $dir; $this->phpBin = $bin; $this->process = new Process(null); }
[ "public", "function", "prepareScenario", "(", "BeforeScenarioScope", "$", "scope", ")", "{", "$", "dir", "=", "sys_get_temp_dir", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'behat-api-extension'", ".", "DIRECTORY_SEPARATOR", ".", "microtime", "(", "true", ")", ";...
Prepare a scenario @param BeforeScenarioScope $scope @throws RuntimeException @BeforeScenario
[ "Prepare", "a", "scenario" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L64-L76
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.createFile
public function createFile($filename, PyStringNode $content, $readable = true) { $filename = rtrim($this->workingDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($filename, DIRECTORY_SEPARATOR); $path = dirname($filename); $content = str_replace("'''", '"""', (string) $content); if (!is_dir($path)) { mkdir($path, 0777, true); } file_put_contents($filename, $content); if (!$readable) { chmod($filename, 0000); } }
php
public function createFile($filename, PyStringNode $content, $readable = true) { $filename = rtrim($this->workingDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($filename, DIRECTORY_SEPARATOR); $path = dirname($filename); $content = str_replace("'''", '"""', (string) $content); if (!is_dir($path)) { mkdir($path, 0777, true); } file_put_contents($filename, $content); if (!$readable) { chmod($filename, 0000); } }
[ "public", "function", "createFile", "(", "$", "filename", ",", "PyStringNode", "$", "content", ",", "$", "readable", "=", "true", ")", "{", "$", "filename", "=", "rtrim", "(", "$", "this", "->", "workingDir", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTOR...
Creates a file with specified name and content in the current working dir @param string $filename Name of the file relative to the working dir @param PyStringNode $content Content of the file @param boolean $readable Whether or not the created file is readable @Given a file named :filename with:
[ "Creates", "a", "file", "with", "specified", "name", "and", "content", "in", "the", "current", "working", "dir" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L87-L101
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.assertCommandResultWithOutput
public function assertCommandResultWithOutput($result, PyStringNode $output) { $this->assertCommandResult($result); $this->assertCommandOutputMatches($output); }
php
public function assertCommandResultWithOutput($result, PyStringNode $output) { $this->assertCommandResult($result); $this->assertCommandOutputMatches($output); }
[ "public", "function", "assertCommandResultWithOutput", "(", "$", "result", ",", "PyStringNode", "$", "output", ")", "{", "$", "this", "->", "assertCommandResult", "(", "$", "result", ")", ";", "$", "this", "->", "assertCommandOutputMatches", "(", "$", "output", ...
Checks whether the command failed or passed, with output @param string $result @param PyStringNode $output @Then /^it should (fail|pass) with:$/
[ "Checks", "whether", "the", "command", "failed", "or", "passed", "with", "output" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L146-L149
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.assertCommandOutputMatches
public function assertCommandOutputMatches(PyStringNode $content) { Assertion::contains( $this->getOutput(), str_replace("'''", '"""', (string) $content), sprintf('Command output does not match. Actual output: %s', $this->getOutput()) ); }
php
public function assertCommandOutputMatches(PyStringNode $content) { Assertion::contains( $this->getOutput(), str_replace("'''", '"""', (string) $content), sprintf('Command output does not match. Actual output: %s', $this->getOutput()) ); }
[ "public", "function", "assertCommandOutputMatches", "(", "PyStringNode", "$", "content", ")", "{", "Assertion", "::", "contains", "(", "$", "this", "->", "getOutput", "(", ")", ",", "str_replace", "(", "\"'''\"", ",", "'\"\"\"'", ",", "(", "string", ")", "$"...
Assert command output contains a string @param PyStringNode $output @Then the output should contain:
[ "Assert", "command", "output", "contains", "a", "string" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L158-L164
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.assertCommandResult
public function assertCommandResult($result) { $exitCode = $this->getExitCode(); // Escape % as the callback will pass this value to sprintf() if the assertion fails, and // sprintf might complain about too few arguments as the output might contain stuff like %s // or %d. $output = str_replace('%', '%%', $this->getOutput()); if ($result === 'fail') { $callback = 'notEq'; $errorMessage = sprintf( 'Invalid exit code, did not expect 0. Command output: %s', $output ); } else { $callback = 'eq'; $errorMessage = sprintf( 'Expected exit code 0, got %d. Command output: %s', $exitCode, $output ); } Assertion::$callback(0, $exitCode, $errorMessage); }
php
public function assertCommandResult($result) { $exitCode = $this->getExitCode(); // Escape % as the callback will pass this value to sprintf() if the assertion fails, and // sprintf might complain about too few arguments as the output might contain stuff like %s // or %d. $output = str_replace('%', '%%', $this->getOutput()); if ($result === 'fail') { $callback = 'notEq'; $errorMessage = sprintf( 'Invalid exit code, did not expect 0. Command output: %s', $output ); } else { $callback = 'eq'; $errorMessage = sprintf( 'Expected exit code 0, got %d. Command output: %s', $exitCode, $output ); } Assertion::$callback(0, $exitCode, $errorMessage); }
[ "public", "function", "assertCommandResult", "(", "$", "result", ")", "{", "$", "exitCode", "=", "$", "this", "->", "getExitCode", "(", ")", ";", "// Escape % as the callback will pass this value to sprintf() if the assertion fails, and", "// sprintf might complain about too fe...
Checks whether the command failed or passed @param string $result @Then /^it should (fail|pass)$/
[ "Checks", "whether", "the", "command", "failed", "or", "passed" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L172-L196
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.getOutput
private function getOutput() { $output = $this->process->getErrorOutput() . $this->process->getOutput(); return trim(preg_replace('/ +$/m', '', $output)); }
php
private function getOutput() { $output = $this->process->getErrorOutput() . $this->process->getOutput(); return trim(preg_replace('/ +$/m', '', $output)); }
[ "private", "function", "getOutput", "(", ")", "{", "$", "output", "=", "$", "this", "->", "process", "->", "getErrorOutput", "(", ")", ".", "$", "this", "->", "process", "->", "getOutput", "(", ")", ";", "return", "trim", "(", "preg_replace", "(", "'/ ...
Get output from the process @return string
[ "Get", "output", "from", "the", "process" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L212-L216
train
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.rmdir
private static function rmdir($path) { foreach (glob($path . '/*') as $file) { if (is_dir($file)) { self::rmdir($file); } else { unlink($file); } } // Remove the remaining directory rmdir($path); }
php
private static function rmdir($path) { foreach (glob($path . '/*') as $file) { if (is_dir($file)) { self::rmdir($file); } else { unlink($file); } } // Remove the remaining directory rmdir($path); }
[ "private", "static", "function", "rmdir", "(", "$", "path", ")", "{", "foreach", "(", "glob", "(", "$", "path", ".", "'/*'", ")", "as", "$", "file", ")", "{", "if", "(", "is_dir", "(", "$", "file", ")", ")", "{", "self", "::", "rmdir", "(", "$"...
Recursively delete a directory @param string $path Path to a file or a directory
[ "Recursively", "delete", "a", "directory" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L223-L234
train
imbo/behat-api-extension
src/ArrayContainsComparator/Matcher/JWT.php
JWT.addToken
public function addToken($name, array $payload, $secret) { $this->jwtTokens[$name] = [ 'payload' => $payload, 'secret' => $secret, ]; return $this; }
php
public function addToken($name, array $payload, $secret) { $this->jwtTokens[$name] = [ 'payload' => $payload, 'secret' => $secret, ]; return $this; }
[ "public", "function", "addToken", "(", "$", "name", ",", "array", "$", "payload", ",", "$", "secret", ")", "{", "$", "this", "->", "jwtTokens", "[", "$", "name", "]", "=", "[", "'payload'", "=>", "$", "payload", ",", "'secret'", "=>", "$", "secret", ...
Add a JWT token that can be matched @param string $name String identifying the token @param array $payload The payload @param string $secret The secret used to sign the token @return self
[ "Add", "a", "JWT", "token", "that", "can", "be", "matched" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator/Matcher/JWT.php#L56-L63
train
wordplate/framework
src/PluginLoader.php
PluginLoader.load
public function load(): void { // Load WordPress's action and filter helper functions. require_once ABSPATH.'wp-includes/plugin.php'; add_filter('pre_option_active_plugins', [$this, 'preOptionActivePlugins']); add_filter('show_advanced_plugins', [$this, 'showAdvancedPlugins'], 0, 2); add_filter('option_active_plugins', [$this, 'optionActivePlugins'], PHP_INT_MAX); add_filter('pre_update_option_active_plugins', [$this, 'preUpdateOptionActivePlugins']); }
php
public function load(): void { // Load WordPress's action and filter helper functions. require_once ABSPATH.'wp-includes/plugin.php'; add_filter('pre_option_active_plugins', [$this, 'preOptionActivePlugins']); add_filter('show_advanced_plugins', [$this, 'showAdvancedPlugins'], 0, 2); add_filter('option_active_plugins', [$this, 'optionActivePlugins'], PHP_INT_MAX); add_filter('pre_update_option_active_plugins', [$this, 'preUpdateOptionActivePlugins']); }
[ "public", "function", "load", "(", ")", ":", "void", "{", "// Load WordPress's action and filter helper functions.", "require_once", "ABSPATH", ".", "'wp-includes/plugin.php'", ";", "add_filter", "(", "'pre_option_active_plugins'", ",", "[", "$", "this", ",", "'preOptionA...
Run the plugin loader. @return void
[ "Run", "the", "plugin", "loader", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L48-L57
train
wordplate/framework
src/PluginLoader.php
PluginLoader.showAdvancedPlugins
public function showAdvancedPlugins(bool $show, string $type) { if (!$this->isPluginsScreen() || $type !== 'mustuse' || !current_user_can('activate_plugins')) { return $show; } $GLOBALS['plugins']['mustuse'] = $this->getPlugins(); }
php
public function showAdvancedPlugins(bool $show, string $type) { if (!$this->isPluginsScreen() || $type !== 'mustuse' || !current_user_can('activate_plugins')) { return $show; } $GLOBALS['plugins']['mustuse'] = $this->getPlugins(); }
[ "public", "function", "showAdvancedPlugins", "(", "bool", "$", "show", ",", "string", "$", "type", ")", "{", "if", "(", "!", "$", "this", "->", "isPluginsScreen", "(", ")", "||", "$", "type", "!==", "'mustuse'", "||", "!", "current_user_can", "(", "'acti...
Show must-use plugins on the plugins page. @param bool $show @param string $type @return void
[ "Show", "must", "-", "use", "plugins", "on", "the", "plugins", "page", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L67-L74
train
wordplate/framework
src/PluginLoader.php
PluginLoader.preOptionActivePlugins
public function preOptionActivePlugins($plugins) { remove_filter('pre_option_active_plugins', [$this, 'preOptionActivePlugins']); if ( !defined('WP_PLUGIN_DIR') || !defined('WPMU_PLUGIN_DIR') || !is_blog_installed() ) { return false; } $this->validatePlugins(); $haveUnactivatedPlugins = false; foreach (array_keys($this->getPlugins()) as $plugin) { if ($this->isPluginActive($plugin)) { require_once WPMU_PLUGIN_DIR.'/'.$plugin; } else { $haveUnactivatedPlugins = true; } } if ($haveUnactivatedPlugins) { add_action('wp_loaded', [$this, 'activatePlugins']); } return $plugins; }
php
public function preOptionActivePlugins($plugins) { remove_filter('pre_option_active_plugins', [$this, 'preOptionActivePlugins']); if ( !defined('WP_PLUGIN_DIR') || !defined('WPMU_PLUGIN_DIR') || !is_blog_installed() ) { return false; } $this->validatePlugins(); $haveUnactivatedPlugins = false; foreach (array_keys($this->getPlugins()) as $plugin) { if ($this->isPluginActive($plugin)) { require_once WPMU_PLUGIN_DIR.'/'.$plugin; } else { $haveUnactivatedPlugins = true; } } if ($haveUnactivatedPlugins) { add_action('wp_loaded', [$this, 'activatePlugins']); } return $plugins; }
[ "public", "function", "preOptionActivePlugins", "(", "$", "plugins", ")", "{", "remove_filter", "(", "'pre_option_active_plugins'", ",", "[", "$", "this", ",", "'preOptionActivePlugins'", "]", ")", ";", "if", "(", "!", "defined", "(", "'WP_PLUGIN_DIR'", ")", "||...
Active plugins including must-use plugins. @param mixed $plugins @return mixed
[ "Active", "plugins", "including", "must", "-", "use", "plugins", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L83-L111
train
wordplate/framework
src/PluginLoader.php
PluginLoader.optionActivePlugins
public function optionActivePlugins($plugins): array { if ($this->isPluginsScreen()) { return $plugins; } foreach (array_keys($this->getPlugins()) as $plugin) { $plugins = array_diff($plugins, [$plugin]); if ($this->isPluginActive($plugin)) { // Remove plugin from array, if exists $plugins = array_diff($plugins, [$plugin]); // Add plugin with relative url to WPMU_PLUGIN_DIR $plugins[] = $this->getRelativePath().$plugin; } } return array_unique($plugins); }
php
public function optionActivePlugins($plugins): array { if ($this->isPluginsScreen()) { return $plugins; } foreach (array_keys($this->getPlugins()) as $plugin) { $plugins = array_diff($plugins, [$plugin]); if ($this->isPluginActive($plugin)) { // Remove plugin from array, if exists $plugins = array_diff($plugins, [$plugin]); // Add plugin with relative url to WPMU_PLUGIN_DIR $plugins[] = $this->getRelativePath().$plugin; } } return array_unique($plugins); }
[ "public", "function", "optionActivePlugins", "(", "$", "plugins", ")", ":", "array", "{", "if", "(", "$", "this", "->", "isPluginsScreen", "(", ")", ")", "{", "return", "$", "plugins", ";", "}", "foreach", "(", "array_keys", "(", "$", "this", "->", "ge...
Add plugins to active plugins, this makes is_plugin_active work. @param array $plugins @return array
[ "Add", "plugins", "to", "active", "plugins", "this", "makes", "is_plugin_active", "work", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L120-L138
train
wordplate/framework
src/PluginLoader.php
PluginLoader.activatePlugins
public function activatePlugins(): void { foreach (array_keys($this->getPlugins()) as $plugin) { if (!$this->isPluginActive($plugin)) { $this->activatePlugin($plugin); } } }
php
public function activatePlugins(): void { foreach (array_keys($this->getPlugins()) as $plugin) { if (!$this->isPluginActive($plugin)) { $this->activatePlugin($plugin); } } }
[ "public", "function", "activatePlugins", "(", ")", ":", "void", "{", "foreach", "(", "array_keys", "(", "$", "this", "->", "getPlugins", "(", ")", ")", "as", "$", "plugin", ")", "{", "if", "(", "!", "$", "this", "->", "isPluginActive", "(", "$", "plu...
Active plugins not activated. @return void
[ "Active", "plugins", "not", "activated", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L159-L166
train
wordplate/framework
src/PluginLoader.php
PluginLoader.getPlugins
protected function getPlugins(): array { if ($this->plugins) { return $this->plugins; } // Load WordPress's plugin helper functions. require_once ABSPATH.'wp-admin/includes/plugin.php'; $plugins = array_diff_key( get_plugins('/'.$this->getRelativePath()), get_mu_plugins() ); $this->plugins = array_unique($plugins, SORT_REGULAR); return $this->plugins; }
php
protected function getPlugins(): array { if ($this->plugins) { return $this->plugins; } // Load WordPress's plugin helper functions. require_once ABSPATH.'wp-admin/includes/plugin.php'; $plugins = array_diff_key( get_plugins('/'.$this->getRelativePath()), get_mu_plugins() ); $this->plugins = array_unique($plugins, SORT_REGULAR); return $this->plugins; }
[ "protected", "function", "getPlugins", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "plugins", ")", "{", "return", "$", "this", "->", "plugins", ";", "}", "// Load WordPress's plugin helper functions.", "require_once", "ABSPATH", ".", "'wp-admin/in...
Get the plugins and must-use plugins. @return array
[ "Get", "the", "plugins", "and", "must", "-", "use", "plugins", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L173-L190
train
wordplate/framework
src/PluginLoader.php
PluginLoader.getActivePlugins
protected function getActivePlugins(): array { if ($this->activePlugins) { return $this->activePlugins; } $this->activePlugins = (array) get_option('active_mu_plugins', []); return $this->activePlugins; }
php
protected function getActivePlugins(): array { if ($this->activePlugins) { return $this->activePlugins; } $this->activePlugins = (array) get_option('active_mu_plugins', []); return $this->activePlugins; }
[ "protected", "function", "getActivePlugins", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "activePlugins", ")", "{", "return", "$", "this", "->", "activePlugins", ";", "}", "$", "this", "->", "activePlugins", "=", "(", "array", ")", "get_op...
Get the active must-use plugins. @return array
[ "Get", "the", "active", "must", "-", "use", "plugins", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L197-L206
train
wordplate/framework
src/PluginLoader.php
PluginLoader.setActivePlugins
protected function setActivePlugins(array $plugins): void { $plugins = array_unique($plugins, SORT_REGULAR); update_option('active_mu_plugins', $plugins); $this->activePlugins = $plugins; }
php
protected function setActivePlugins(array $plugins): void { $plugins = array_unique($plugins, SORT_REGULAR); update_option('active_mu_plugins', $plugins); $this->activePlugins = $plugins; }
[ "protected", "function", "setActivePlugins", "(", "array", "$", "plugins", ")", ":", "void", "{", "$", "plugins", "=", "array_unique", "(", "$", "plugins", ",", "SORT_REGULAR", ")", ";", "update_option", "(", "'active_mu_plugins'", ",", "$", "plugins", ")", ...
Set the active must-use plugins. @param array $plugins @return void
[ "Set", "the", "active", "must", "-", "use", "plugins", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L215-L222
train
wordplate/framework
src/PluginLoader.php
PluginLoader.activatePlugin
protected function activatePlugin(string $plugin): void { require_once WPMU_PLUGIN_DIR.'/'.$plugin; do_action('activate_'.$plugin); $plugins = $this->getActivePlugins(); $plugins[] = $plugin; $this->setActivePlugins($plugins); }
php
protected function activatePlugin(string $plugin): void { require_once WPMU_PLUGIN_DIR.'/'.$plugin; do_action('activate_'.$plugin); $plugins = $this->getActivePlugins(); $plugins[] = $plugin; $this->setActivePlugins($plugins); }
[ "protected", "function", "activatePlugin", "(", "string", "$", "plugin", ")", ":", "void", "{", "require_once", "WPMU_PLUGIN_DIR", ".", "'/'", ".", "$", "plugin", ";", "do_action", "(", "'activate_'", ".", "$", "plugin", ")", ";", "$", "plugins", "=", "$",...
Activate plugin by their name. @param string $plugin @return void
[ "Activate", "plugin", "by", "their", "name", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L243-L253
train
wordplate/framework
src/PluginLoader.php
PluginLoader.validatePlugins
protected function validatePlugins(): void { $plugins = array_filter($this->getActivePlugins(), function ($plugin) { return file_exists(WPMU_PLUGIN_DIR.'/'.$plugin); }); if (array_diff($plugins, $this->getActivePlugins())) { $this->setActivePlugins($plugins); } }
php
protected function validatePlugins(): void { $plugins = array_filter($this->getActivePlugins(), function ($plugin) { return file_exists(WPMU_PLUGIN_DIR.'/'.$plugin); }); if (array_diff($plugins, $this->getActivePlugins())) { $this->setActivePlugins($plugins); } }
[ "protected", "function", "validatePlugins", "(", ")", ":", "void", "{", "$", "plugins", "=", "array_filter", "(", "$", "this", "->", "getActivePlugins", "(", ")", ",", "function", "(", "$", "plugin", ")", "{", "return", "file_exists", "(", "WPMU_PLUGIN_DIR",...
Validate active plugins and deactivate invalid plugins. @return void
[ "Validate", "active", "plugins", "and", "deactivate", "invalid", "plugins", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/PluginLoader.php#L260-L269
train
wordplate/framework
src/Application.php
Application.run
public function run() { // For developers: WordPress debugging mode. $debug = env('WP_DEBUG', false); define('WP_DEBUG', $debug); define('WP_DEBUG_LOG', env('WP_DEBUG_LOG', false)); define('WP_DEBUG_DISPLAY', env('WP_DEBUG_DISPLAY', $debug)); define('SCRIPT_DEBUG', env('SCRIPT_DEBUG', $debug)); // The database configuration with database name, username, password, // hostname charset and database collae type. define('DB_NAME', env('DB_NAME')); define('DB_USER', env('DB_USER')); define('DB_PASSWORD', env('DB_PASSWORD')); define('DB_HOST', env('DB_HOST')); define('DB_CHARSET', env('DB_CHARSET', 'utf8mb4')); define('DB_COLLATE', env('DB_COLLATE', 'utf8mb4_unicode_ci')); // Set the unique authentication keys and salts. define('AUTH_KEY', env('AUTH_KEY')); define('SECURE_AUTH_KEY', env('SECURE_AUTH_KEY')); define('LOGGED_IN_KEY', env('LOGGED_IN_KEY')); define('NONCE_KEY', env('NONCE_KEY')); define('AUTH_SALT', env('AUTH_SALT')); define('SECURE_AUTH_SALT', env('SECURE_AUTH_SALT')); define('LOGGED_IN_SALT', env('LOGGED_IN_SALT')); define('NONCE_SALT', env('NONCE_SALT')); // Set the home url to the current domain. $request = Request::createFromGlobals(); define('WP_HOME', env('WP_URL', $request->getSchemeAndHttpHost())); // Set the WordPress directory path. define('WP_SITEURL', env('WP_SITEURL', sprintf('%s/%s', WP_HOME, env('WP_DIR', 'wordpress')))); // Set the WordPress content directory path. define('WP_CONTENT_DIR', env('WP_CONTENT_DIR', $this->getPublicPath())); define('WP_CONTENT_URL', env('WP_CONTENT_URL', WP_HOME)); // Set the trash to less days to optimize WordPress. define('EMPTY_TRASH_DAYS', env('EMPTY_TRASH_DAYS', 7)); // Set the default WordPress theme. define('WP_DEFAULT_THEME', env('WP_THEME', 'wordplate')); // Constant to configure core updates. define('WP_AUTO_UPDATE_CORE', env('WP_AUTO_UPDATE_CORE', 'minor')); // Specify the number of post revisions. define('WP_POST_REVISIONS', env('WP_POST_REVISIONS', 2)); // Cleanup WordPress image edits. define('IMAGE_EDIT_OVERWRITE', env('IMAGE_EDIT_OVERWRITE', true)); // Prevent file edititing from the dashboard. define('DISALLOW_FILE_EDIT', env('DISALLOW_FILE_EDIT', true)); // Set the absolute path to the WordPress directory. if (!defined('ABSPATH')) { define('ABSPATH', sprintf('%s/%s/', $this->getPublicPath(), env('WP_DIR', 'wordpress'))); } // Load the must-use plugins. $pluginLoader = new PluginLoader(); $pluginLoader->load(); }
php
public function run() { // For developers: WordPress debugging mode. $debug = env('WP_DEBUG', false); define('WP_DEBUG', $debug); define('WP_DEBUG_LOG', env('WP_DEBUG_LOG', false)); define('WP_DEBUG_DISPLAY', env('WP_DEBUG_DISPLAY', $debug)); define('SCRIPT_DEBUG', env('SCRIPT_DEBUG', $debug)); // The database configuration with database name, username, password, // hostname charset and database collae type. define('DB_NAME', env('DB_NAME')); define('DB_USER', env('DB_USER')); define('DB_PASSWORD', env('DB_PASSWORD')); define('DB_HOST', env('DB_HOST')); define('DB_CHARSET', env('DB_CHARSET', 'utf8mb4')); define('DB_COLLATE', env('DB_COLLATE', 'utf8mb4_unicode_ci')); // Set the unique authentication keys and salts. define('AUTH_KEY', env('AUTH_KEY')); define('SECURE_AUTH_KEY', env('SECURE_AUTH_KEY')); define('LOGGED_IN_KEY', env('LOGGED_IN_KEY')); define('NONCE_KEY', env('NONCE_KEY')); define('AUTH_SALT', env('AUTH_SALT')); define('SECURE_AUTH_SALT', env('SECURE_AUTH_SALT')); define('LOGGED_IN_SALT', env('LOGGED_IN_SALT')); define('NONCE_SALT', env('NONCE_SALT')); // Set the home url to the current domain. $request = Request::createFromGlobals(); define('WP_HOME', env('WP_URL', $request->getSchemeAndHttpHost())); // Set the WordPress directory path. define('WP_SITEURL', env('WP_SITEURL', sprintf('%s/%s', WP_HOME, env('WP_DIR', 'wordpress')))); // Set the WordPress content directory path. define('WP_CONTENT_DIR', env('WP_CONTENT_DIR', $this->getPublicPath())); define('WP_CONTENT_URL', env('WP_CONTENT_URL', WP_HOME)); // Set the trash to less days to optimize WordPress. define('EMPTY_TRASH_DAYS', env('EMPTY_TRASH_DAYS', 7)); // Set the default WordPress theme. define('WP_DEFAULT_THEME', env('WP_THEME', 'wordplate')); // Constant to configure core updates. define('WP_AUTO_UPDATE_CORE', env('WP_AUTO_UPDATE_CORE', 'minor')); // Specify the number of post revisions. define('WP_POST_REVISIONS', env('WP_POST_REVISIONS', 2)); // Cleanup WordPress image edits. define('IMAGE_EDIT_OVERWRITE', env('IMAGE_EDIT_OVERWRITE', true)); // Prevent file edititing from the dashboard. define('DISALLOW_FILE_EDIT', env('DISALLOW_FILE_EDIT', true)); // Set the absolute path to the WordPress directory. if (!defined('ABSPATH')) { define('ABSPATH', sprintf('%s/%s/', $this->getPublicPath(), env('WP_DIR', 'wordpress'))); } // Load the must-use plugins. $pluginLoader = new PluginLoader(); $pluginLoader->load(); }
[ "public", "function", "run", "(", ")", "{", "// For developers: WordPress debugging mode.", "$", "debug", "=", "env", "(", "'WP_DEBUG'", ",", "false", ")", ";", "define", "(", "'WP_DEBUG'", ",", "$", "debug", ")", ";", "define", "(", "'WP_DEBUG_LOG'", ",", "...
Star the application engine. @return void
[ "Star", "the", "application", "engine", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/Application.php#L61-L126
train
wordplate/framework
src/Application.php
Application.getPublicPath
public function getPublicPath(): string { if (is_null($this->publicPath)) { return $this->basePath.DIRECTORY_SEPARATOR.'public'; } return $this->publicPath; }
php
public function getPublicPath(): string { if (is_null($this->publicPath)) { return $this->basePath.DIRECTORY_SEPARATOR.'public'; } return $this->publicPath; }
[ "public", "function", "getPublicPath", "(", ")", ":", "string", "{", "if", "(", "is_null", "(", "$", "this", "->", "publicPath", ")", ")", "{", "return", "$", "this", "->", "basePath", ".", "DIRECTORY_SEPARATOR", ".", "'public'", ";", "}", "return", "$",...
Get the public web directory path. @return string
[ "Get", "the", "public", "web", "directory", "path", "." ]
2760174306e74fa728551a1ce0938e3d75ccbf90
https://github.com/wordplate/framework/blob/2760174306e74fa728551a1ce0938e3d75ccbf90/src/Application.php#L143-L150
train
Artem-Schander/L5Modular
src/Console/ModuleMakeCommand.php
ModuleMakeCommand.handle
public function handle() { $app = app(); $this->version = (int) str_replace('.', '', $app->version()); // check if module exists if ($this->files->exists(app_path().'/Modules/'.studly_case($this->getNameInput()))) { return $this->error($this->type.' already exists!'); } // Create Controller $this->generate('controller'); // Create Model $this->generate('model'); // Create Views folder $this->generate('view'); //Flag for no translation if (! $this->option('no-translation')) { // Create Translations folder $this->generate('translation'); } if ($this->version < 530) { // Create Routes file $this->generate('routes'); } else { // Create WEB Routes file $this->generate('web'); // Create API Routes file $this->generate('api'); } // Create Helper file $this->generate('helper'); if (! $this->option('no-migration')) { // without hacky studly_case function // foo-bar results in foo-bar and not in foo_bar $table = str_plural(snake_case(studly_case($this->getNameInput()))); $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]); } $this->info($this->type.' created successfully.'); }
php
public function handle() { $app = app(); $this->version = (int) str_replace('.', '', $app->version()); // check if module exists if ($this->files->exists(app_path().'/Modules/'.studly_case($this->getNameInput()))) { return $this->error($this->type.' already exists!'); } // Create Controller $this->generate('controller'); // Create Model $this->generate('model'); // Create Views folder $this->generate('view'); //Flag for no translation if (! $this->option('no-translation')) { // Create Translations folder $this->generate('translation'); } if ($this->version < 530) { // Create Routes file $this->generate('routes'); } else { // Create WEB Routes file $this->generate('web'); // Create API Routes file $this->generate('api'); } // Create Helper file $this->generate('helper'); if (! $this->option('no-migration')) { // without hacky studly_case function // foo-bar results in foo-bar and not in foo_bar $table = str_plural(snake_case(studly_case($this->getNameInput()))); $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]); } $this->info($this->type.' created successfully.'); }
[ "public", "function", "handle", "(", ")", "{", "$", "app", "=", "app", "(", ")", ";", "$", "this", "->", "version", "=", "(", "int", ")", "str_replace", "(", "'.'", ",", "''", ",", "$", "app", "->", "version", "(", ")", ")", ";", "// check if mod...
Execute the console command >= L5.5. @return void
[ "Execute", "the", "console", "command", ">", "=", "L5", ".", "5", "." ]
5cf09c427e392131a730533d0a600b6ffbf8dc4e
https://github.com/Artem-Schander/L5Modular/blob/5cf09c427e392131a730533d0a600b6ffbf8dc4e/src/Console/ModuleMakeCommand.php#L53-L104
train
Artem-Schander/L5Modular
src/Console/ModuleMakeCommand.php
ModuleMakeCommand.replaceName
protected function replaceName(&$stub, $name) { $stub = str_replace('DummyTitle', $name, $stub); $stub = str_replace('DummyUCtitle', ucfirst(studly_case($name)), $stub); return $this; }
php
protected function replaceName(&$stub, $name) { $stub = str_replace('DummyTitle', $name, $stub); $stub = str_replace('DummyUCtitle', ucfirst(studly_case($name)), $stub); return $this; }
[ "protected", "function", "replaceName", "(", "&", "$", "stub", ",", "$", "name", ")", "{", "$", "stub", "=", "str_replace", "(", "'DummyTitle'", ",", "$", "name", ",", "$", "stub", ")", ";", "$", "stub", "=", "str_replace", "(", "'DummyUCtitle'", ",", ...
Replace the name for the given stub. @param string $stub @param string $name @return string
[ "Replace", "the", "name", "for", "the", "given", "stub", "." ]
5cf09c427e392131a730533d0a600b6ffbf8dc4e
https://github.com/Artem-Schander/L5Modular/blob/5cf09c427e392131a730533d0a600b6ffbf8dc4e/src/Console/ModuleMakeCommand.php#L198-L203
train
mikestecker/craft-videoembedder
src/services/VideoEmbedderService.php
VideoEmbedderService.getVideoId
public function getVideoId($url) { // looks like there are, now let's only do this for YouTube and Vimeo if($this->getInfo($url)->type == 'video' && ($this->isYouTube($url) || $this->isVimeo($url))) { if ($this->isYouTube($url)) { return $this->getYouTubeId($url); } else if ($this->isVimeo($url)) { return $this->getVimeoId($url); } } else { // return empty string return ''; } }
php
public function getVideoId($url) { // looks like there are, now let's only do this for YouTube and Vimeo if($this->getInfo($url)->type == 'video' && ($this->isYouTube($url) || $this->isVimeo($url))) { if ($this->isYouTube($url)) { return $this->getYouTubeId($url); } else if ($this->isVimeo($url)) { return $this->getVimeoId($url); } } else { // return empty string return ''; } }
[ "public", "function", "getVideoId", "(", "$", "url", ")", "{", "// looks like there are, now let's only do this for YouTube and Vimeo", "if", "(", "$", "this", "->", "getInfo", "(", "$", "url", ")", "->", "type", "==", "'video'", "&&", "(", "$", "this", "->", ...
Take a url and returns only the video ID @param string $url @return string
[ "Take", "a", "url", "and", "returns", "only", "the", "video", "ID" ]
03045545633952647190ed07b5b115e645931d57
https://github.com/mikestecker/craft-videoembedder/blob/03045545633952647190ed07b5b115e645931d57/src/services/VideoEmbedderService.php#L261-L280
train
pcrov/JsonReader
src/Parser/Lexer.php
Lexer.scanCodepoint
private function scanCodepoint(): string { $buffer = &$this->buffer; $offset = &$this->offset; $codepoint = $buffer[$offset++]; $ord = \ord($codepoint); if (!($ord >> 7)) { return $codepoint; } if (!(($ord >> 5) ^ 0b110)) { $expect = 1; } elseif (!(($ord >> 4) ^ 0b1110)) { $expect = 2; } elseif (!(($ord >> 3) ^ 0b11110)) { $expect = 3; } else { $expect = 0; // This'll throw in just a moment. } $continuationBytes = ""; do { $temp = \substr($buffer, $offset, $expect); $deltaLength = \strlen($temp); $expect -= $deltaLength; $continuationBytes .= $temp; } while ($expect > 0 && $this->refillBuffer()); $offset += $deltaLength; for ( $i = 0, $continuationBytesLength = \strlen($continuationBytes); $i < $continuationBytesLength; $i++ ) { $byte = $continuationBytes[$i]; if ((\ord($byte) >> 6) ^ 0b10) { break; } $codepoint .= $byte; } $chr = \IntlChar::chr($codepoint); if ($chr === null) { throw new ParseException($this->getIllFormedUtf8ExceptionMessage($codepoint)); } return $chr; }
php
private function scanCodepoint(): string { $buffer = &$this->buffer; $offset = &$this->offset; $codepoint = $buffer[$offset++]; $ord = \ord($codepoint); if (!($ord >> 7)) { return $codepoint; } if (!(($ord >> 5) ^ 0b110)) { $expect = 1; } elseif (!(($ord >> 4) ^ 0b1110)) { $expect = 2; } elseif (!(($ord >> 3) ^ 0b11110)) { $expect = 3; } else { $expect = 0; // This'll throw in just a moment. } $continuationBytes = ""; do { $temp = \substr($buffer, $offset, $expect); $deltaLength = \strlen($temp); $expect -= $deltaLength; $continuationBytes .= $temp; } while ($expect > 0 && $this->refillBuffer()); $offset += $deltaLength; for ( $i = 0, $continuationBytesLength = \strlen($continuationBytes); $i < $continuationBytesLength; $i++ ) { $byte = $continuationBytes[$i]; if ((\ord($byte) >> 6) ^ 0b10) { break; } $codepoint .= $byte; } $chr = \IntlChar::chr($codepoint); if ($chr === null) { throw new ParseException($this->getIllFormedUtf8ExceptionMessage($codepoint)); } return $chr; }
[ "private", "function", "scanCodepoint", "(", ")", ":", "string", "{", "$", "buffer", "=", "&", "$", "this", "->", "buffer", ";", "$", "offset", "=", "&", "$", "this", "->", "offset", ";", "$", "codepoint", "=", "$", "buffer", "[", "$", "offset", "+...
Scans a single UTF-8 encoded Unicode codepoint, which can be up to four bytes long. 0xxx xxxx Single-byte codepoint. 110x xxxx First of a two-byte codepoint. 1110 xxxx First of three. 1111 0xxx First of four. 10xx xxxx A continuation of any of the three preceding. @see https://en.wikipedia.org/wiki/UTF-8#Description @see http://www.unicode.org/versions/Unicode9.0.0/ch03.pdf#page=54 @throws ParseException on ill-formed UTF-8.
[ "Scans", "a", "single", "UTF", "-", "8", "encoded", "Unicode", "codepoint", "which", "can", "be", "up", "to", "four", "bytes", "long", "." ]
83ff905fbea18c74bd438c6aa85cb3500763bfdb
https://github.com/pcrov/JsonReader/blob/83ff905fbea18c74bd438c6aa85cb3500763bfdb/src/Parser/Lexer.php#L367-L420
train
pcrov/JsonReader
src/Parser/Lexer.php
Lexer.scanEscapedUnicodeSequence
private function scanEscapedUnicodeSequence(): string { static $hexChars = "0123456789ABCDEFabcdef"; static $length = 4; $sequence = $this->scanWhile($hexChars, $length); if (\strlen($sequence) < $length) { throw new ParseException($this->getExceptionMessage()); } return $sequence; }
php
private function scanEscapedUnicodeSequence(): string { static $hexChars = "0123456789ABCDEFabcdef"; static $length = 4; $sequence = $this->scanWhile($hexChars, $length); if (\strlen($sequence) < $length) { throw new ParseException($this->getExceptionMessage()); } return $sequence; }
[ "private", "function", "scanEscapedUnicodeSequence", "(", ")", ":", "string", "{", "static", "$", "hexChars", "=", "\"0123456789ABCDEFabcdef\"", ";", "static", "$", "length", "=", "4", ";", "$", "sequence", "=", "$", "this", "->", "scanWhile", "(", "$", "hex...
Scans four hexadecimal characters. @throws ParseException
[ "Scans", "four", "hexadecimal", "characters", "." ]
83ff905fbea18c74bd438c6aa85cb3500763bfdb
https://github.com/pcrov/JsonReader/blob/83ff905fbea18c74bd438c6aa85cb3500763bfdb/src/Parser/Lexer.php#L466-L478
train
damirka/yii2-jwt
src/UserTrait.php
UserTrait.getJWT
public function getJWT() { // Collect all the data $secret = static::getSecretKey(); $currentTime = time(); $request = Yii::$app->request; $hostInfo = ''; // There is also a \yii\console\Request that doesn't have this property if ($request instanceof WebRequest) { $hostInfo = $request->hostInfo; } // Merge token with presets not to miss any params in custom // configuration $token = array_merge([ 'iss' => $hostInfo, 'aud' => $hostInfo, 'iat' => $currentTime, 'nbf' => $currentTime ], static::getHeaderToken()); // Set up id $token['jti'] = $this->getJTI(); return JWT::encode($token, $secret, static::getAlgo()); }
php
public function getJWT() { // Collect all the data $secret = static::getSecretKey(); $currentTime = time(); $request = Yii::$app->request; $hostInfo = ''; // There is also a \yii\console\Request that doesn't have this property if ($request instanceof WebRequest) { $hostInfo = $request->hostInfo; } // Merge token with presets not to miss any params in custom // configuration $token = array_merge([ 'iss' => $hostInfo, 'aud' => $hostInfo, 'iat' => $currentTime, 'nbf' => $currentTime ], static::getHeaderToken()); // Set up id $token['jti'] = $this->getJTI(); return JWT::encode($token, $secret, static::getAlgo()); }
[ "public", "function", "getJWT", "(", ")", "{", "// Collect all the data", "$", "secret", "=", "static", "::", "getSecretKey", "(", ")", ";", "$", "currentTime", "=", "time", "(", ")", ";", "$", "request", "=", "Yii", "::", "$", "app", "->", "request", ...
Encodes model data to create custom JWT with model.id set in it @return string encoded JWT
[ "Encodes", "model", "data", "to", "create", "custom", "JWT", "with", "model", ".", "id", "set", "in", "it" ]
3598863189aaec7cb93329fd11104fdfe2a6baa1
https://github.com/damirka/yii2-jwt/blob/3598863189aaec7cb93329fd11104fdfe2a6baa1/src/UserTrait.php#L110-L136
train
Superbalist/php-pubsub
src/Utils.php
Utils.unserializeMessagePayload
public static function unserializeMessagePayload($payload) { $message = json_decode($payload, true); if (json_last_error() === JSON_ERROR_NONE) { return $message; } return $payload; }
php
public static function unserializeMessagePayload($payload) { $message = json_decode($payload, true); if (json_last_error() === JSON_ERROR_NONE) { return $message; } return $payload; }
[ "public", "static", "function", "unserializeMessagePayload", "(", "$", "payload", ")", "{", "$", "message", "=", "json_decode", "(", "$", "payload", ",", "true", ")", ";", "if", "(", "json_last_error", "(", ")", "===", "JSON_ERROR_NONE", ")", "{", "return", ...
Unserialize the message payload. @param string $payload @return mixed
[ "Unserialize", "the", "message", "payload", "." ]
b2dcae00364c505266650eefb2a1374683e59cb3
https://github.com/Superbalist/php-pubsub/blob/b2dcae00364c505266650eefb2a1374683e59cb3/src/Utils.php#L26-L34
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Util.php
Util.getJoomlaVersion
public static function getJoomlaVersion($base) { $key = md5($base); if (!isset(self::$_versions[$key])) { $canonical = function($version) { if (isset($version->RELEASE)) { return 'v' . $version->RELEASE . '.' . $version->DEV_LEVEL; } // Joomla 3.5 and up uses constants instead of properties in JVersion $className = get_class($version); if (defined("$className::RELEASE")) { return $version::RELEASE . '.' . $version::DEV_LEVEL; } return 'unknown'; }; $files = array( 'joomla-cms' => '/libraries/cms/version/version.php', 'joomla-cms-new' => '/libraries/src/Version.php', // 3.8+ 'joomlatools-platform' => '/lib/libraries/cms/version/version.php', 'joomla-1.5' => '/libraries/joomla/version.php' ); $code = false; $application = false; foreach ($files as $type => $file) { $path = $base . $file; if (file_exists($path)) { $code = $path; $application = $type; break; } } if ($code !== false) { if (!defined('JPATH_PLATFORM')) { define('JPATH_PLATFORM', self::buildTargetPath('/libraries', $base)); } if (!defined('_JEXEC')) { define('_JEXEC', 1); } $identifier = uniqid(); $source = file_get_contents($code); $source = preg_replace('/<\?php/', '', $source, 1); $pattern = $application == 'joomla-cms-new' ? '/class Version/i' : '/class JVersion/i'; $replacement = $application == 'joomla-cms-new' ? 'class Version' . $identifier : 'class JVersion' . $identifier; $source = preg_replace($pattern, $replacement, $source); eval($source); $class = $application == 'joomla-cms-new' ? '\\Joomla\\CMS\\Version'.$identifier : 'JVersion'.$identifier; $version = new $class(); self::$_versions[$key] = (object) array('release' => $canonical($version), 'type' => $application); } else self::$_versions[$key] = false; } if (!self::$_versions[$key] && self::isKodekitPlatform($base)) { self::$_versions[$key] = (object) array('type' => 'kodekit-platform', 'release' => 'n/a'); } return self::$_versions[$key]; }
php
public static function getJoomlaVersion($base) { $key = md5($base); if (!isset(self::$_versions[$key])) { $canonical = function($version) { if (isset($version->RELEASE)) { return 'v' . $version->RELEASE . '.' . $version->DEV_LEVEL; } // Joomla 3.5 and up uses constants instead of properties in JVersion $className = get_class($version); if (defined("$className::RELEASE")) { return $version::RELEASE . '.' . $version::DEV_LEVEL; } return 'unknown'; }; $files = array( 'joomla-cms' => '/libraries/cms/version/version.php', 'joomla-cms-new' => '/libraries/src/Version.php', // 3.8+ 'joomlatools-platform' => '/lib/libraries/cms/version/version.php', 'joomla-1.5' => '/libraries/joomla/version.php' ); $code = false; $application = false; foreach ($files as $type => $file) { $path = $base . $file; if (file_exists($path)) { $code = $path; $application = $type; break; } } if ($code !== false) { if (!defined('JPATH_PLATFORM')) { define('JPATH_PLATFORM', self::buildTargetPath('/libraries', $base)); } if (!defined('_JEXEC')) { define('_JEXEC', 1); } $identifier = uniqid(); $source = file_get_contents($code); $source = preg_replace('/<\?php/', '', $source, 1); $pattern = $application == 'joomla-cms-new' ? '/class Version/i' : '/class JVersion/i'; $replacement = $application == 'joomla-cms-new' ? 'class Version' . $identifier : 'class JVersion' . $identifier; $source = preg_replace($pattern, $replacement, $source); eval($source); $class = $application == 'joomla-cms-new' ? '\\Joomla\\CMS\\Version'.$identifier : 'JVersion'.$identifier; $version = new $class(); self::$_versions[$key] = (object) array('release' => $canonical($version), 'type' => $application); } else self::$_versions[$key] = false; } if (!self::$_versions[$key] && self::isKodekitPlatform($base)) { self::$_versions[$key] = (object) array('type' => 'kodekit-platform', 'release' => 'n/a'); } return self::$_versions[$key]; }
[ "public", "static", "function", "getJoomlaVersion", "(", "$", "base", ")", "{", "$", "key", "=", "md5", "(", "$", "base", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "_versions", "[", "$", "key", "]", ")", ")", "{", "$", "canonical...
Retrieve the Joomla version. Returns an object with properties type and release. Returns FALSE if unable to find correct version. @param string $base Base path for the Joomla installation @return stdclass|boolean
[ "Retrieve", "the", "Joomla", "version", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Util.php#L23-L100
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Util.php
Util.buildTargetPath
public static function buildTargetPath($path, $base = '') { if (!empty($base) && substr($base, -1) == '/') { $base = substr($base, 0, -1); } $path = str_replace($base, '', $path); if (substr($path, 0, 1) != '/') { $path = '/'.$path; } if (self::isPlatform($base)) { $paths = array( '/administrator/manifests' => '/config/manifests/', '/administrator' => '/app/administrator', '/components' => '/app/site/components', '/modules' => '/app/site/modules', '/language' => '/app/site/language', '/media' => '/web/media', '/plugins' => '/lib/plugins', '/libraries' => '/lib/libraries', '/images' => '/web/images', '/configuration.php' => '/config/configuration.php' ); foreach ($paths as $original => $replacement) { if (substr($path, 0, strlen($original)) == $original) { $path = $replacement . substr($path, strlen($original)); break; } } } return $base.$path; }
php
public static function buildTargetPath($path, $base = '') { if (!empty($base) && substr($base, -1) == '/') { $base = substr($base, 0, -1); } $path = str_replace($base, '', $path); if (substr($path, 0, 1) != '/') { $path = '/'.$path; } if (self::isPlatform($base)) { $paths = array( '/administrator/manifests' => '/config/manifests/', '/administrator' => '/app/administrator', '/components' => '/app/site/components', '/modules' => '/app/site/modules', '/language' => '/app/site/language', '/media' => '/web/media', '/plugins' => '/lib/plugins', '/libraries' => '/lib/libraries', '/images' => '/web/images', '/configuration.php' => '/config/configuration.php' ); foreach ($paths as $original => $replacement) { if (substr($path, 0, strlen($original)) == $original) { $path = $replacement . substr($path, strlen($original)); break; } } } return $base.$path; }
[ "public", "static", "function", "buildTargetPath", "(", "$", "path", ",", "$", "base", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "base", ")", "&&", "substr", "(", "$", "base", ",", "-", "1", ")", "==", "'/'", ")", "{", "$", "base"...
Builds the full path for a given path inside a Joomla project. If base is a Joomla Platform installation, the path will be translated into the correct path in platform. Example: /administrator/components/com_xyz becomes /app/administrator/components/com_xyz in platform. @param string $path The original relative path to the file/directory @param string $base The root directory of the Joomla installation @return string Target path
[ "Builds", "the", "full", "path", "for", "a", "given", "path", "inside", "a", "Joomla", "project", ".", "If", "base", "is", "a", "Joomla", "Platform", "installation", "the", "path", "will", "be", "translated", "into", "the", "correct", "path", "in", "platfo...
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Util.php#L159-L197
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Util.php
Util.isJoomlatoolsBox
public static function isJoomlatoolsBox() { if (php_uname('n') === 'joomlatools') { return true; } // Support boxes that do not have the correct hostname set $user = exec('whoami'); if (trim($user) == 'vagrant' && file_exists('/home/vagrant/scripts/dashboard/index.php')) { if (file_exists('/etc/varnish/default.vcl')) { return true; } } return false; }
php
public static function isJoomlatoolsBox() { if (php_uname('n') === 'joomlatools') { return true; } // Support boxes that do not have the correct hostname set $user = exec('whoami'); if (trim($user) == 'vagrant' && file_exists('/home/vagrant/scripts/dashboard/index.php')) { if (file_exists('/etc/varnish/default.vcl')) { return true; } } return false; }
[ "public", "static", "function", "isJoomlatoolsBox", "(", ")", "{", "if", "(", "php_uname", "(", "'n'", ")", "===", "'joomlatools'", ")", "{", "return", "true", ";", "}", "// Support boxes that do not have the correct hostname set", "$", "user", "=", "exec", "(", ...
Determine if we are running from inside the Joomlatools Box environment. Only boxes >= 1.4.0 can be recognized. @return boolean true|false
[ "Determine", "if", "we", "are", "running", "from", "inside", "the", "Joomlatools", "Box", "environment", ".", "Only", "boxes", ">", "=", "1", ".", "4", ".", "0", "can", "be", "recognized", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Util.php#L205-L221
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Util.php
Util.getTemplatePath
public static function getTemplatePath() { $path = \Phar::running(); if (!empty($path)) { return $path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . '.files'; } $root = dirname(dirname(dirname(dirname(__DIR__)))); return realpath($root .DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . '.files'); }
php
public static function getTemplatePath() { $path = \Phar::running(); if (!empty($path)) { return $path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . '.files'; } $root = dirname(dirname(dirname(dirname(__DIR__)))); return realpath($root .DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . '.files'); }
[ "public", "static", "function", "getTemplatePath", "(", ")", "{", "$", "path", "=", "\\", "Phar", "::", "running", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "path", ")", ")", "{", "return", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'bin'...
Get template directory path @return string
[ "Get", "template", "directory", "path" ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Util.php#L244-L255
train
dmkit/phalcon-jwt-auth
src/Phalcon/Auth/Middleware/Micro.php
Micro.setEventChecker
protected function setEventChecker() { $diName = self::$diName; $eventsManager = $this->app->getEventsManager() ?? new EventsManager(); $eventsManager->attach( "micro:beforeExecuteRoute", function (Event $event, $app) use($diName) { $auth = $app[$diName]; // check if it has CORS support if ($auth->isIgnoreOptionsMethod() && $app['request']->getMethod() == 'OPTIONS') { return true; } if($auth->isIgnoreUri()) { /** * Let's try to parse if there's a token * but we don't want to get an invalid token */ if( !$auth->check() && $this->getMessages()[0] != 'missing token') { return $auth->unauthorized(); } return true; } if($auth->check()) { return true; } return $auth->unauthorized(); } ); $this->app->setEventsManager($eventsManager); }
php
protected function setEventChecker() { $diName = self::$diName; $eventsManager = $this->app->getEventsManager() ?? new EventsManager(); $eventsManager->attach( "micro:beforeExecuteRoute", function (Event $event, $app) use($diName) { $auth = $app[$diName]; // check if it has CORS support if ($auth->isIgnoreOptionsMethod() && $app['request']->getMethod() == 'OPTIONS') { return true; } if($auth->isIgnoreUri()) { /** * Let's try to parse if there's a token * but we don't want to get an invalid token */ if( !$auth->check() && $this->getMessages()[0] != 'missing token') { return $auth->unauthorized(); } return true; } if($auth->check()) { return true; } return $auth->unauthorized(); } ); $this->app->setEventsManager($eventsManager); }
[ "protected", "function", "setEventChecker", "(", ")", "{", "$", "diName", "=", "self", "::", "$", "diName", ";", "$", "eventsManager", "=", "$", "this", "->", "app", "->", "getEventsManager", "(", ")", "??", "new", "EventsManager", "(", ")", ";", "$", ...
Sets event authentication.
[ "Sets", "event", "authentication", "." ]
1f4db19a7da8924832e482e4cc37471c5e61b8c2
https://github.com/dmkit/phalcon-jwt-auth/blob/1f4db19a7da8924832e482e4cc37471c5e61b8c2/src/Phalcon/Auth/Middleware/Micro.php#L136-L173
train
dmkit/phalcon-jwt-auth
src/Phalcon/Auth/Middleware/Micro.php
Micro.isIgnoreUri
public function isIgnoreUri() { if(!$this->ignoreUri) { return false; } // access request object $request = $this->app['request']; // url $uri = $request->getURI(); // http method $method = $request->getMethod(); return $this->hasMatchIgnoreUri($uri, $method); }
php
public function isIgnoreUri() { if(!$this->ignoreUri) { return false; } // access request object $request = $this->app['request']; // url $uri = $request->getURI(); // http method $method = $request->getMethod(); return $this->hasMatchIgnoreUri($uri, $method); }
[ "public", "function", "isIgnoreUri", "(", ")", "{", "if", "(", "!", "$", "this", "->", "ignoreUri", ")", "{", "return", "false", ";", "}", "// access request object", "$", "request", "=", "$", "this", "->", "app", "[", "'request'", "]", ";", "// url", ...
Checks if the URI and HTTP METHOD can bypass the authentication. @return bool
[ "Checks", "if", "the", "URI", "and", "HTTP", "METHOD", "can", "bypass", "the", "authentication", "." ]
1f4db19a7da8924832e482e4cc37471c5e61b8c2
https://github.com/dmkit/phalcon-jwt-auth/blob/1f4db19a7da8924832e482e4cc37471c5e61b8c2/src/Phalcon/Auth/Middleware/Micro.php#L210-L226
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Application.php
Application.getPluginPath
public function getPluginPath() { if (empty($this->_plugin_path)) { $this->_plugin_path = $this->getConsoleHome() . '/plugins'; } return $this->_plugin_path; }
php
public function getPluginPath() { if (empty($this->_plugin_path)) { $this->_plugin_path = $this->getConsoleHome() . '/plugins'; } return $this->_plugin_path; }
[ "public", "function", "getPluginPath", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_plugin_path", ")", ")", "{", "$", "this", "->", "_plugin_path", "=", "$", "this", "->", "getConsoleHome", "(", ")", ".", "'/plugins'", ";", "}", "return...
Get the plugin path @return string Path to the plugins directory
[ "Get", "the", "plugin", "path" ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Application.php#L100-L107
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Application.php
Application.getPlugins
public function getPlugins() { if (!$this->_plugins) { $manifest = $this->getPluginPath() . '/composer.json'; if (!file_exists($manifest)) { return array(); } $contents = file_get_contents($manifest); if ($contents === false) { return array(); } $data = json_decode($contents); if (!isset($data->require)) { return array(); } $this->_plugins = array(); foreach ($data->require as $package => $version) { $file = $this->getPluginPath() . '/vendor/' . $package . '/composer.json'; if (file_exists($file)) { $json = file_get_contents($file); $manifest = json_decode($json); if (is_null($manifest)) { continue; } if (isset($manifest->type) && $manifest->type == 'joomlatools-console-plugin') { $this->_plugins[$package] = $version; } } } } return $this->_plugins; }
php
public function getPlugins() { if (!$this->_plugins) { $manifest = $this->getPluginPath() . '/composer.json'; if (!file_exists($manifest)) { return array(); } $contents = file_get_contents($manifest); if ($contents === false) { return array(); } $data = json_decode($contents); if (!isset($data->require)) { return array(); } $this->_plugins = array(); foreach ($data->require as $package => $version) { $file = $this->getPluginPath() . '/vendor/' . $package . '/composer.json'; if (file_exists($file)) { $json = file_get_contents($file); $manifest = json_decode($json); if (is_null($manifest)) { continue; } if (isset($manifest->type) && $manifest->type == 'joomlatools-console-plugin') { $this->_plugins[$package] = $version; } } } } return $this->_plugins; }
[ "public", "function", "getPlugins", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_plugins", ")", "{", "$", "manifest", "=", "$", "this", "->", "getPluginPath", "(", ")", ".", "'/composer.json'", ";", "if", "(", "!", "file_exists", "(", "$", "ma...
Get the list of installed plugin packages. @return array Array of package names as key and their version as value
[ "Get", "the", "list", "of", "installed", "plugin", "packages", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Application.php#L165-L210
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Application.php
Application._loadPlugins
protected function _loadPlugins() { $autoloader = $this->getPluginPath() . '/vendor/autoload.php'; if (file_exists($autoloader)) { require_once $autoloader; } $plugins = $this->getPlugins(); $classes = array(); foreach ($plugins as $package => $version) { $path = $this->getPluginPath() . '/vendor/' . $package; $directories = glob($path.'/*/Console/Command', GLOB_ONLYDIR); foreach ($directories as $directory) { $vendor = substr($directory, strlen($path) + 1, strlen('/Console/Command') * -1); $iterator = new \DirectoryIterator($directory); foreach ($iterator as $file) { if ($file->getExtension() == 'php') { $classes[] = sprintf('%s\Console\Command\%s', $vendor, $file->getBasename('.php')); } } } } foreach ($classes as $class) { if (class_exists($class)) { $command = new $class(); if (!$command instanceof \Symfony\Component\Console\Command\Command) { continue; } $name = $command->getName(); if(!$this->has($name)) { $this->add($command); } else $this->_output->writeln("<fg=yellow;options=bold>Notice:</fg=yellow;options=bold> The '$class' command wants to register the '$name' command but it already exists, ignoring."); } } }
php
protected function _loadPlugins() { $autoloader = $this->getPluginPath() . '/vendor/autoload.php'; if (file_exists($autoloader)) { require_once $autoloader; } $plugins = $this->getPlugins(); $classes = array(); foreach ($plugins as $package => $version) { $path = $this->getPluginPath() . '/vendor/' . $package; $directories = glob($path.'/*/Console/Command', GLOB_ONLYDIR); foreach ($directories as $directory) { $vendor = substr($directory, strlen($path) + 1, strlen('/Console/Command') * -1); $iterator = new \DirectoryIterator($directory); foreach ($iterator as $file) { if ($file->getExtension() == 'php') { $classes[] = sprintf('%s\Console\Command\%s', $vendor, $file->getBasename('.php')); } } } } foreach ($classes as $class) { if (class_exists($class)) { $command = new $class(); if (!$command instanceof \Symfony\Component\Console\Command\Command) { continue; } $name = $command->getName(); if(!$this->has($name)) { $this->add($command); } else $this->_output->writeln("<fg=yellow;options=bold>Notice:</fg=yellow;options=bold> The '$class' command wants to register the '$name' command but it already exists, ignoring."); } } }
[ "protected", "function", "_loadPlugins", "(", ")", "{", "$", "autoloader", "=", "$", "this", "->", "getPluginPath", "(", ")", ".", "'/vendor/autoload.php'", ";", "if", "(", "file_exists", "(", "$", "autoloader", ")", ")", "{", "require_once", "$", "autoloade...
Loads plugins into the application.
[ "Loads", "plugins", "into", "the", "application", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Application.php#L244-L292
train
dmkit/phalcon-jwt-auth
src/Phalcon/Auth/Auth.php
Auth.check
public function check(TokenGetter $parser, string $key) : bool { $token = $parser->parse(); if(!$token) { $this->appendMessage('missing token'); return false; } $payload = $this->decode($token, $key); if(!$payload || empty($payload)) { return false; } $this->payload = $payload; // if any of the callback return false, this will immediately return false foreach($this->_onCheckCb as $callback) { if( $callback($this) === false ) { return false; } } return true; }
php
public function check(TokenGetter $parser, string $key) : bool { $token = $parser->parse(); if(!$token) { $this->appendMessage('missing token'); return false; } $payload = $this->decode($token, $key); if(!$payload || empty($payload)) { return false; } $this->payload = $payload; // if any of the callback return false, this will immediately return false foreach($this->_onCheckCb as $callback) { if( $callback($this) === false ) { return false; } } return true; }
[ "public", "function", "check", "(", "TokenGetter", "$", "parser", ",", "string", "$", "key", ")", ":", "bool", "{", "$", "token", "=", "$", "parser", "->", "parse", "(", ")", ";", "if", "(", "!", "$", "token", ")", "{", "$", "this", "->", "append...
Checks and validates JWT. Calls the oncheck callbacks and pass self as parameter. @param Dmkit\Phalcon\Auth\TokenGetter\AdapterInterface $parser @param string $key @return bool
[ "Checks", "and", "validates", "JWT", ".", "Calls", "the", "oncheck", "callbacks", "and", "pass", "self", "as", "parameter", "." ]
1f4db19a7da8924832e482e4cc37471c5e61b8c2
https://github.com/dmkit/phalcon-jwt-auth/blob/1f4db19a7da8924832e482e4cc37471c5e61b8c2/src/Phalcon/Auth/Auth.php#L50-L74
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Application.php
Application.hasExtension
public function hasExtension($element, $type = 'component') { $db = JFactory::getDbo(); $sql = "SELECT `extension_id`, `state` FROM `#__extensions`" ." WHERE `element` = ".$db->quote($element)." AND `type` = ".$db->quote($type); $extension = $db->setQuery($sql)->loadObject(); return ($extension && $extension->state != -1); }
php
public function hasExtension($element, $type = 'component') { $db = JFactory::getDbo(); $sql = "SELECT `extension_id`, `state` FROM `#__extensions`" ." WHERE `element` = ".$db->quote($element)." AND `type` = ".$db->quote($type); $extension = $db->setQuery($sql)->loadObject(); return ($extension && $extension->state != -1); }
[ "public", "function", "hasExtension", "(", "$", "element", ",", "$", "type", "=", "'component'", ")", "{", "$", "db", "=", "JFactory", "::", "getDbo", "(", ")", ";", "$", "sql", "=", "\"SELECT `extension_id`, `state` FROM `#__extensions`\"", ".", "\" WHERE `elem...
Checks if this Joomla installation has a certain element installed. @param string $element The name of the element @param string $type The type of extension @return bool
[ "Checks", "if", "this", "Joomla", "installation", "has", "a", "certain", "element", "installed", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Application.php#L138-L147
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Application.php
Application.getName
public function getName() { $name = ''; switch ($this->_clientId) { case Bootstrapper::SITE: $name = 'site'; break; case Bootstrapper::ADMIN: $name = 'administrator'; break; default: $name = 'cli'; break; } return $name; }
php
public function getName() { $name = ''; switch ($this->_clientId) { case Bootstrapper::SITE: $name = 'site'; break; case Bootstrapper::ADMIN: $name = 'administrator'; break; default: $name = 'cli'; break; } return $name; }
[ "public", "function", "getName", "(", ")", "{", "$", "name", "=", "''", ";", "switch", "(", "$", "this", "->", "_clientId", ")", "{", "case", "Bootstrapper", "::", "SITE", ":", "$", "name", "=", "'site'", ";", "break", ";", "case", "Bootstrapper", ":...
Get the current application name. @return string
[ "Get", "the", "current", "application", "name", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Application.php#L257-L275
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Application.php
Application.fetchConfigurationData
protected function fetchConfigurationData($file = '', $class = 'JConfig') { $config = parent::fetchConfigurationData($file, $class); // Inject the root user configuration if(isset($this->_options['root_user'])) { $root_user = isset($this->_options['root_user']) ? $this->_options['root_user'] : 'root'; if (is_array($config)) { $config['root_user'] = $root_user; } elseif (is_object($config)) { $config->root_user = $root_user; } } return $config; }
php
protected function fetchConfigurationData($file = '', $class = 'JConfig') { $config = parent::fetchConfigurationData($file, $class); // Inject the root user configuration if(isset($this->_options['root_user'])) { $root_user = isset($this->_options['root_user']) ? $this->_options['root_user'] : 'root'; if (is_array($config)) { $config['root_user'] = $root_user; } elseif (is_object($config)) { $config->root_user = $root_user; } } return $config; }
[ "protected", "function", "fetchConfigurationData", "(", "$", "file", "=", "''", ",", "$", "class", "=", "'JConfig'", ")", "{", "$", "config", "=", "parent", "::", "fetchConfigurationData", "(", "$", "file", ",", "$", "class", ")", ";", "// Inject the root us...
Method to load a PHP configuration class file based on convention and return the instantiated data object. You will extend this method in child classes to provide configuration data from whatever data source is relevant for your specific application. Additionally injects the root_user into the configuration. @param string $file The path and filename of the configuration file. If not provided, configuration.php in JPATH_BASE will be used. @param string $class The class name to instantiate. @return mixed Either an array or object to be loaded into the configuration object. @since 11.1
[ "Method", "to", "load", "a", "PHP", "configuration", "class", "file", "based", "on", "convention", "and", "return", "the", "instantiated", "data", "object", ".", "You", "will", "extend", "this", "method", "in", "child", "classes", "to", "provide", "configurati...
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Application.php#L365-L383
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Application.php
Application._startSession
protected function _startSession() { $name = md5($this->getCfg('secret') . get_class($this)); $lifetime = $this->getCfg('lifetime') * 60 ; $handler = $this->getCfg('session_handler', 'none'); $options = array( 'name' => $name, 'expire' => $lifetime ); $session = JSession::getInstance($handler, $options); $session->initialise($this->input, $this->dispatcher); if ($session->getState() == 'expired') { $session->restart(); } else { $session->start(); } return $session; }
php
protected function _startSession() { $name = md5($this->getCfg('secret') . get_class($this)); $lifetime = $this->getCfg('lifetime') * 60 ; $handler = $this->getCfg('session_handler', 'none'); $options = array( 'name' => $name, 'expire' => $lifetime ); $session = JSession::getInstance($handler, $options); $session->initialise($this->input, $this->dispatcher); if ($session->getState() == 'expired') { $session->restart(); } else { $session->start(); } return $session; }
[ "protected", "function", "_startSession", "(", ")", "{", "$", "name", "=", "md5", "(", "$", "this", "->", "getCfg", "(", "'secret'", ")", ".", "get_class", "(", "$", "this", ")", ")", ";", "$", "lifetime", "=", "$", "this", "->", "getCfg", "(", "'l...
Creates a new Joomla session. @return JSession
[ "Creates", "a", "new", "Joomla", "session", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Application.php#L390-L411
train
joomlatools/joomlatools-console
src/Joomlatools/Console/Joomla/Application.php
Application.getMenu
public function getMenu($name = null, $options = array()) { if (!isset($name)) { $app = JFactory::getApplication(); $name = $app->getName(); } try { if (!class_exists('JMenu' . ucfirst($name))) { jimport('cms.menu.'.strtolower($name)); } $menu = JMenu::getInstance($name, $options); } catch (Exception $e) { return null; } return $menu; }
php
public function getMenu($name = null, $options = array()) { if (!isset($name)) { $app = JFactory::getApplication(); $name = $app->getName(); } try { if (!class_exists('JMenu' . ucfirst($name))) { jimport('cms.menu.'.strtolower($name)); } $menu = JMenu::getInstance($name, $options); } catch (Exception $e) { return null; } return $menu; }
[ "public", "function", "getMenu", "(", "$", "name", "=", "null", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "name", ")", ")", "{", "$", "app", "=", "JFactory", "::", "getApplication", "(", ")", ";", ...
Returns the application JMenu object. @param string $name The name of the application/client. @param array $options An optional associative array of configuration settings. @return JMenu
[ "Returns", "the", "application", "JMenu", "object", "." ]
2911032c1dba27dcedc0b802717fe9ade6301239
https://github.com/joomlatools/joomlatools-console/blob/2911032c1dba27dcedc0b802717fe9ade6301239/src/Joomlatools/Console/Joomla/Application.php#L534-L555
train
dmkit/phalcon-jwt-auth
src/Phalcon/Auth/TokenGetter/Handler/Header.php
Header.parse
public function parse() : string { $raw_token = $this->_Request->getHeader($this->key); if(!$raw_token) { return ''; } return trim( str_ireplace($this->prefix, '', $raw_token)); }
php
public function parse() : string { $raw_token = $this->_Request->getHeader($this->key); if(!$raw_token) { return ''; } return trim( str_ireplace($this->prefix, '', $raw_token)); }
[ "public", "function", "parse", "(", ")", ":", "string", "{", "$", "raw_token", "=", "$", "this", "->", "_Request", "->", "getHeader", "(", "$", "this", "->", "key", ")", ";", "if", "(", "!", "$", "raw_token", ")", "{", "return", "''", ";", "}", "...
Gets the token from the headers @return string
[ "Gets", "the", "token", "from", "the", "headers" ]
1f4db19a7da8924832e482e4cc37471c5e61b8c2
https://github.com/dmkit/phalcon-jwt-auth/blob/1f4db19a7da8924832e482e4cc37471c5e61b8c2/src/Phalcon/Auth/TokenGetter/Handler/Header.php#L24-L33
train