repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.replacePatternParameterWithPlaceholder
protected function replacePatternParameterWithPlaceholder( $matches, &$parameters ) { $name = $matches['name']; $optional = ! empty( $matches['optional'] ); $replacement = '/(?P<' . $name . '>' . $this->parameter_pattern . ')'; if ( $optional ) { $replacement = '(?:' . $replacement . ')?'; } $hash = sha1( implode( '_', [ count( $parameters ), $replacement, uniqid( 'wpemerge_', true ), ] ) ); $placeholder = '___placeholder_' . $hash . '___'; $parameters[ $placeholder ] = $replacement; return $placeholder; }
php
protected function replacePatternParameterWithPlaceholder( $matches, &$parameters ) { $name = $matches['name']; $optional = ! empty( $matches['optional'] ); $replacement = '/(?P<' . $name . '>' . $this->parameter_pattern . ')'; if ( $optional ) { $replacement = '(?:' . $replacement . ')?'; } $hash = sha1( implode( '_', [ count( $parameters ), $replacement, uniqid( 'wpemerge_', true ), ] ) ); $placeholder = '___placeholder_' . $hash . '___'; $parameters[ $placeholder ] = $replacement; return $placeholder; }
[ "protected", "function", "replacePatternParameterWithPlaceholder", "(", "$", "matches", ",", "&", "$", "parameters", ")", "{", "$", "name", "=", "$", "matches", "[", "'name'", "]", ";", "$", "optional", "=", "!", "empty", "(", "$", "matches", "[", "'option...
Validation pattern replace callback. @param array $matches @param array $parameters @return string
[ "Validation", "pattern", "replace", "callback", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L208-L227
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.getValidationPattern
public function getValidationPattern( $url, $wrap = true ) { $parameters = []; // Replace all parameters with placeholders $validation_pattern = preg_replace_callback( $this->url_pattern, function ( $matches ) use ( &$parameters ) { return $this->replacePatternParameterWithPlaceholder( $matches, $parameters ); }, $url ); // Quote the remaining string so that it does not get evaluated as a pattern. $validation_pattern = preg_quote( $validation_pattern, '~' ); // Replace the placeholders with the real parameter patterns. $validation_pattern = str_replace( array_keys( $parameters ), array_values( $parameters ), $validation_pattern ); // Match the entire url; make trailing slash optional. $validation_pattern = '^' . $validation_pattern . '?$'; if ( $wrap ) { $validation_pattern = '~' . $validation_pattern . '~'; } return $validation_pattern; }
php
public function getValidationPattern( $url, $wrap = true ) { $parameters = []; // Replace all parameters with placeholders $validation_pattern = preg_replace_callback( $this->url_pattern, function ( $matches ) use ( &$parameters ) { return $this->replacePatternParameterWithPlaceholder( $matches, $parameters ); }, $url ); // Quote the remaining string so that it does not get evaluated as a pattern. $validation_pattern = preg_quote( $validation_pattern, '~' ); // Replace the placeholders with the real parameter patterns. $validation_pattern = str_replace( array_keys( $parameters ), array_values( $parameters ), $validation_pattern ); // Match the entire url; make trailing slash optional. $validation_pattern = '^' . $validation_pattern . '?$'; if ( $wrap ) { $validation_pattern = '~' . $validation_pattern . '~'; } return $validation_pattern; }
[ "public", "function", "getValidationPattern", "(", "$", "url", ",", "$", "wrap", "=", "true", ")", "{", "$", "parameters", "=", "[", "]", ";", "// Replace all parameters with placeholders", "$", "validation_pattern", "=", "preg_replace_callback", "(", "$", "this",...
Get pattern to test whether normal urls match the parameter-based one. @param string $url @param boolean $wrap @return string
[ "Get", "pattern", "to", "test", "whether", "normal", "urls", "match", "the", "parameter", "-", "based", "one", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L236-L262
htmlburger/wpemerge
src/View/ViewServiceProvider.php
ViewServiceProvider.register
public function register( $container ) { /** @var $container \Pimple\Container */ $this->extendConfig( $container, 'views', '' ); $container[ WPEMERGE_VIEW_SERVICE_KEY ] = function () { return new ViewService(); }; $container[ WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ] = function ( $c ) { return new PhpViewEngine( $c[ WPEMERGE_CONFIG_KEY ]['views'] ); }; $container[ WPEMERGE_VIEW_ENGINE_KEY ] = $container->raw( WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ); Application::alias( 'View', \WPEmerge\Facades\View::class ); Application::alias( 'ViewEngine', \WPEmerge\Facades\ViewEngine::class ); }
php
public function register( $container ) { /** @var $container \Pimple\Container */ $this->extendConfig( $container, 'views', '' ); $container[ WPEMERGE_VIEW_SERVICE_KEY ] = function () { return new ViewService(); }; $container[ WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ] = function ( $c ) { return new PhpViewEngine( $c[ WPEMERGE_CONFIG_KEY ]['views'] ); }; $container[ WPEMERGE_VIEW_ENGINE_KEY ] = $container->raw( WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ); Application::alias( 'View', \WPEmerge\Facades\View::class ); Application::alias( 'ViewEngine', \WPEmerge\Facades\ViewEngine::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "/** @var $container \\Pimple\\Container */", "$", "this", "->", "extendConfig", "(", "$", "container", ",", "'views'", ",", "''", ")", ";", "$", "container", "[", "WPEMERGE_VIEW_SERVICE_KEY", "]",...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/ViewServiceProvider.php#L27-L43
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.canonical
public function canonical( $view ) { $root = realpath( MixedType::normalizePath( get_template_directory() ) ) . DIRECTORY_SEPARATOR; $match_root = '/^' . preg_quote( $root, '/' ) . '/'; return preg_replace( $match_root, '', $this->resolveFilepath( $view ) ); }
php
public function canonical( $view ) { $root = realpath( MixedType::normalizePath( get_template_directory() ) ) . DIRECTORY_SEPARATOR; $match_root = '/^' . preg_quote( $root, '/' ) . '/'; return preg_replace( $match_root, '', $this->resolveFilepath( $view ) ); }
[ "public", "function", "canonical", "(", "$", "view", ")", "{", "$", "root", "=", "realpath", "(", "MixedType", "::", "normalizePath", "(", "get_template_directory", "(", ")", ")", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "match_root", "=", "'/^'", ".", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L67-L71
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.make
public function make( $views ) { foreach ( $views as $view ) { if ( $this->exists( $view ) ) { $filepath = $this->resolveFilepath( $view ); return $this->makeView( $view, $filepath ); } } throw new ViewNotFoundException( 'View not found for "' . implode( ', ', $views ) . '"' ); }
php
public function make( $views ) { foreach ( $views as $view ) { if ( $this->exists( $view ) ) { $filepath = $this->resolveFilepath( $view ); return $this->makeView( $view, $filepath ); } } throw new ViewNotFoundException( 'View not found for "' . implode( ', ', $views ) . '"' ); }
[ "public", "function", "make", "(", "$", "views", ")", "{", "foreach", "(", "$", "views", "as", "$", "view", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "view", ")", ")", "{", "$", "filepath", "=", "$", "this", "->", "resolveFilepa...
{@inheritDoc} @throws ViewNotFoundException
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L77-L86
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.makeView
protected function makeView( $name, $filepath ) { $view = (new PhpView()) ->setName( $name ) ->setFilepath( $filepath ); $layout = $this->getViewLayout( $view ); if ( $layout !== null ) { $view->setLayout( $layout ); } return $view; }
php
protected function makeView( $name, $filepath ) { $view = (new PhpView()) ->setName( $name ) ->setFilepath( $filepath ); $layout = $this->getViewLayout( $view ); if ( $layout !== null ) { $view->setLayout( $layout ); } return $view; }
[ "protected", "function", "makeView", "(", "$", "name", ",", "$", "filepath", ")", "{", "$", "view", "=", "(", "new", "PhpView", "(", ")", ")", "->", "setName", "(", "$", "name", ")", "->", "setFilepath", "(", "$", "filepath", ")", ";", "$", "layout...
Create a view instance. @param string $name @param string $filepath @return ViewInterface @throws ViewNotFoundException
[ "Create", "a", "view", "instance", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L96-L108
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.getViewLayout
protected function getViewLayout( PhpView $view ) { $layout_headers = array_filter( get_file_data( $view->getFilepath(), ['App Layout'] ) ); if ( empty( $layout_headers ) ) { return null; } $layout_file = trim( $layout_headers[0] ); if ( ! $this->exists( $layout_file ) ) { throw new ViewNotFoundException( 'View layout not found for "' . $layout_file . '"' ); } return $this->makeView( $this->canonical( $layout_file ), $this->resolveFilepath( $layout_file ) ); }
php
protected function getViewLayout( PhpView $view ) { $layout_headers = array_filter( get_file_data( $view->getFilepath(), ['App Layout'] ) ); if ( empty( $layout_headers ) ) { return null; } $layout_file = trim( $layout_headers[0] ); if ( ! $this->exists( $layout_file ) ) { throw new ViewNotFoundException( 'View layout not found for "' . $layout_file . '"' ); } return $this->makeView( $this->canonical( $layout_file ), $this->resolveFilepath( $layout_file ) ); }
[ "protected", "function", "getViewLayout", "(", "PhpView", "$", "view", ")", "{", "$", "layout_headers", "=", "array_filter", "(", "get_file_data", "(", "$", "view", "->", "getFilepath", "(", ")", ",", "[", "'App Layout'", "]", ")", ")", ";", "if", "(", "...
Create a view instance for the given view's layout header, if any. @param PhpView $view @return ViewInterface @throws ViewNotFoundException
[ "Create", "a", "view", "instance", "for", "the", "given", "view", "s", "layout", "header", "if", "any", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L117-L134
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.resolveFilepath
protected function resolveFilepath( $view ) { $view = $this->resolveRelativeFilepath( $view ); $file = $this->resolveFromCustomFilepath( $view ); if ( ! $file ) { $file = $this->resolveFromThemeFilepath( $view ); } if ( ! $file ) { $file = $this->resolveFromAbsoluteFilepath( $view ); } if ( $file ) { $file = realpath( $file ); } return $file; }
php
protected function resolveFilepath( $view ) { $view = $this->resolveRelativeFilepath( $view ); $file = $this->resolveFromCustomFilepath( $view ); if ( ! $file ) { $file = $this->resolveFromThemeFilepath( $view ); } if ( ! $file ) { $file = $this->resolveFromAbsoluteFilepath( $view ); } if ( $file ) { $file = realpath( $file ); } return $file; }
[ "protected", "function", "resolveFilepath", "(", "$", "view", ")", "{", "$", "view", "=", "$", "this", "->", "resolveRelativeFilepath", "(", "$", "view", ")", ";", "$", "file", "=", "$", "this", "->", "resolveFromCustomFilepath", "(", "$", "view", ")", "...
Resolve a view name to an absolute filepath. @param string $view @return string
[ "Resolve", "a", "view", "name", "to", "an", "absolute", "filepath", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L142-L159
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.resolveRelativeFilepath
protected function resolveRelativeFilepath( $view ) { $normalized_view = MixedType::normalizePath( $view ); $paths = [ STYLESHEETPATH, TEMPLATEPATH ]; foreach ( $paths as $path ) { $path = MixedType::addTrailingSlash( $path ); if ( substr( $normalized_view, 0, strlen( $path ) ) === $path ) { return substr( $normalized_view, strlen( $path ) ); } } // Bail if we've failed to convert the view to a relative path. return $view; }
php
protected function resolveRelativeFilepath( $view ) { $normalized_view = MixedType::normalizePath( $view ); $paths = [ STYLESHEETPATH, TEMPLATEPATH ]; foreach ( $paths as $path ) { $path = MixedType::addTrailingSlash( $path ); if ( substr( $normalized_view, 0, strlen( $path ) ) === $path ) { return substr( $normalized_view, strlen( $path ) ); } } // Bail if we've failed to convert the view to a relative path. return $view; }
[ "protected", "function", "resolveRelativeFilepath", "(", "$", "view", ")", "{", "$", "normalized_view", "=", "MixedType", "::", "normalizePath", "(", "$", "view", ")", ";", "$", "paths", "=", "[", "STYLESHEETPATH", ",", "TEMPLATEPATH", "]", ";", "foreach", "...
Resolve an absolute view to a relative one, if possible. @param string $view @return string
[ "Resolve", "an", "absolute", "view", "to", "a", "relative", "one", "if", "possible", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L167-L181
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.resolveFromCustomFilepath
protected function resolveFromCustomFilepath( $view ) { $directory = $this->getDirectory(); if ( $directory === '' ) { return ''; } // Normalize to ensure there are no doubled separators. $file = MixedType::normalizePath( $directory . DIRECTORY_SEPARATOR . $view ); if ( ! file_exists( $file ) ) { // Try adding a .php extension. $file .= '.php'; }; return file_exists( $file ) ? $file : ''; }
php
protected function resolveFromCustomFilepath( $view ) { $directory = $this->getDirectory(); if ( $directory === '' ) { return ''; } // Normalize to ensure there are no doubled separators. $file = MixedType::normalizePath( $directory . DIRECTORY_SEPARATOR . $view ); if ( ! file_exists( $file ) ) { // Try adding a .php extension. $file .= '.php'; }; return file_exists( $file ) ? $file : ''; }
[ "protected", "function", "resolveFromCustomFilepath", "(", "$", "view", ")", "{", "$", "directory", "=", "$", "this", "->", "getDirectory", "(", ")", ";", "if", "(", "$", "directory", "===", "''", ")", "{", "return", "''", ";", "}", "// Normalize to ensure...
Resolve a view if it exists in the custom views directory. @param string $view @return string
[ "Resolve", "a", "view", "if", "it", "exists", "in", "the", "custom", "views", "directory", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L189-L205
htmlburger/wpemerge
src/View/PhpViewEngine.php
PhpViewEngine.resolveFromThemeFilepath
protected function resolveFromThemeFilepath( $view ) { $file = locate_template( $view, false ); if ( ! $file ) { // Try adding a .php extension. $file = locate_template( $view . '.php', false ); } return $file; }
php
protected function resolveFromThemeFilepath( $view ) { $file = locate_template( $view, false ); if ( ! $file ) { // Try adding a .php extension. $file = locate_template( $view . '.php', false ); } return $file; }
[ "protected", "function", "resolveFromThemeFilepath", "(", "$", "view", ")", "{", "$", "file", "=", "locate_template", "(", "$", "view", ",", "false", ")", ";", "if", "(", "!", "$", "file", ")", "{", "// Try adding a .php extension.", "$", "file", "=", "loc...
Resolve a view if it exists in the current theme. @param string $view @return string
[ "Resolve", "a", "view", "if", "it", "exists", "in", "the", "current", "theme", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpViewEngine.php#L213-L222
htmlburger/wpemerge
src/Routing/Conditions/PostSlugCondition.php
PostSlugCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { $post = get_post(); return ( is_singular() && $post && $this->post_slug === $post->post_name ); }
php
public function isSatisfied( RequestInterface $request ) { $post = get_post(); return ( is_singular() && $post && $this->post_slug === $post->post_name ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "$", "post", "=", "get_post", "(", ")", ";", "return", "(", "is_singular", "(", ")", "&&", "$", "post", "&&", "$", "this", "->", "post_slug", "===", "$", "post", "-...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/PostSlugCondition.php#L40-L43
htmlburger/wpemerge
src/Input/OldInput.php
OldInput.get
public function get( $key, $default = null ) { return Arr::get( $this->flash->get( $this->flash_key, [] ), $key, $default ); }
php
public function get( $key, $default = null ) { return Arr::get( $this->flash->get( $this->flash_key, [] ), $key, $default ); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "return", "Arr", "::", "get", "(", "$", "this", "->", "flash", "->", "get", "(", "$", "this", "->", "flash_key", ",", "[", "]", ")", ",", "$", "key", ",",...
Get request value for key from the previous request. @param string $key @param mixed $default @return mixed
[ "Get", "request", "value", "for", "key", "from", "the", "previous", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Input/OldInput.php#L61-L63
htmlburger/wpemerge
src/Routing/Conditions/PostStatusCondition.php
PostStatusCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { $post = get_post(); return ( is_singular() && $post && $this->post_status === $post->post_status ); }
php
public function isSatisfied( RequestInterface $request ) { $post = get_post(); return ( is_singular() && $post && $this->post_status === $post->post_status ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "$", "post", "=", "get_post", "(", ")", ";", "return", "(", "is_singular", "(", ")", "&&", "$", "post", "&&", "$", "this", "->", "post_status", "===", "$", "post", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/PostStatusCondition.php#L40-L43
htmlburger/wpemerge
src/View/PhpView.php
PhpView.toString
public function toString() { if ( empty( $this->getName() ) ) { throw new ViewException( 'View must have a name.' ); } if ( empty( $this->getFilepath() ) ) { throw new ViewException( 'View must have a filepath.' ); } $clone = clone $this; static::$layout_content_stack[] = $clone->compose(); if ( $this->getLayout() !== null ) { return $this->getLayout()->toString(); } return static::getLayoutContent(); }
php
public function toString() { if ( empty( $this->getName() ) ) { throw new ViewException( 'View must have a name.' ); } if ( empty( $this->getFilepath() ) ) { throw new ViewException( 'View must have a filepath.' ); } $clone = clone $this; static::$layout_content_stack[] = $clone->compose(); if ( $this->getLayout() !== null ) { return $this->getLayout()->toString(); } return static::getLayoutContent(); }
[ "public", "function", "toString", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "getName", "(", ")", ")", ")", "{", "throw", "new", "ViewException", "(", "'View must have a name.'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "-...
{@inheritDoc} @throws ViewException
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpView.php#L99-L116
htmlburger/wpemerge
src/View/PhpView.php
PhpView.compose
protected function compose() { $context = $this->getContext(); $this->with( ['global' => View::getGlobals()] ); View::compose( $this ); $this->with( $context ); return $this; }
php
protected function compose() { $context = $this->getContext(); $this->with( ['global' => View::getGlobals()] ); View::compose( $this ); $this->with( $context ); return $this; }
[ "protected", "function", "compose", "(", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "this", "->", "with", "(", "[", "'global'", "=>", "View", "::", "getGlobals", "(", ")", "]", ")", ";", "View", "::", "compo...
Compose the context. @return static $this
[ "Compose", "the", "context", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpView.php#L123-L129
htmlburger/wpemerge
src/View/PhpView.php
PhpView.render
protected function render() { $__context = $this->getContext(); ob_start(); extract( $__context, EXTR_OVERWRITE ); /** @noinspection PhpIncludeInspection */ include $this->getFilepath(); return ob_get_clean(); }
php
protected function render() { $__context = $this->getContext(); ob_start(); extract( $__context, EXTR_OVERWRITE ); /** @noinspection PhpIncludeInspection */ include $this->getFilepath(); return ob_get_clean(); }
[ "protected", "function", "render", "(", ")", "{", "$", "__context", "=", "$", "this", "->", "getContext", "(", ")", ";", "ob_start", "(", ")", ";", "extract", "(", "$", "__context", ",", "EXTR_OVERWRITE", ")", ";", "/** @noinspection PhpIncludeInspection */", ...
Render the view to a string. @return string
[ "Render", "the", "view", "to", "a", "string", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/PhpView.php#L136-L143
htmlburger/wpemerge
src/View/ViewService.php
ViewService.addGlobals
public function addGlobals( $globals ) { foreach ( $globals as $key => $value ) { $this->addGlobal( $key, $value ); } }
php
public function addGlobals( $globals ) { foreach ( $globals as $key => $value ) { $this->addGlobal( $key, $value ); } }
[ "public", "function", "addGlobals", "(", "$", "globals", ")", "{", "foreach", "(", "$", "globals", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "addGlobal", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Set an array of global variables. @param array $globals @return void
[ "Set", "an", "array", "of", "global", "variables", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/ViewService.php#L61-L65
htmlburger/wpemerge
src/View/ViewService.php
ViewService.getComposersForView
public function getComposersForView( $view ) { $view = ViewEngine::canonical( $view ); $composers = []; foreach ( $this->composers as $composer ) { if ( in_array( $view, $composer['views'], true ) ) { $composers[] = $composer['composer']; } } return $composers; }
php
public function getComposersForView( $view ) { $view = ViewEngine::canonical( $view ); $composers = []; foreach ( $this->composers as $composer ) { if ( in_array( $view, $composer['views'], true ) ) { $composers[] = $composer['composer']; } } return $composers; }
[ "public", "function", "getComposersForView", "(", "$", "view", ")", "{", "$", "view", "=", "ViewEngine", "::", "canonical", "(", "$", "view", ")", ";", "$", "composers", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "composers", "as", "$", "...
Get view composer. @param string $view @return array<Handler>
[ "Get", "view", "composer", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/ViewService.php#L73-L85
htmlburger/wpemerge
src/View/ViewService.php
ViewService.addComposer
public function addComposer( $views, $composer ) { $views = array_map( function ( $view ) { return ViewEngine::canonical( $view ); }, MixedType::toArray( $views ) ); $handler = new Handler( $composer, 'compose', '\\App\\ViewComposers\\' ); $this->composers[] = [ 'views' => $views, 'composer' => $handler, ]; }
php
public function addComposer( $views, $composer ) { $views = array_map( function ( $view ) { return ViewEngine::canonical( $view ); }, MixedType::toArray( $views ) ); $handler = new Handler( $composer, 'compose', '\\App\\ViewComposers\\' ); $this->composers[] = [ 'views' => $views, 'composer' => $handler, ]; }
[ "public", "function", "addComposer", "(", "$", "views", ",", "$", "composer", ")", "{", "$", "views", "=", "array_map", "(", "function", "(", "$", "view", ")", "{", "return", "ViewEngine", "::", "canonical", "(", "$", "view", ")", ";", "}", ",", "Mix...
Add view composer. @param string|array<string> $views @param string|Closure $composer @return void
[ "Add", "view", "composer", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/ViewService.php#L94-L105
htmlburger/wpemerge
src/View/ViewService.php
ViewService.compose
public function compose( ViewInterface $view ) { $composers = $this->getComposersForView( $view->getName() ); foreach ( $composers as $composer ) { $composer->execute( $view ); } }
php
public function compose( ViewInterface $view ) { $composers = $this->getComposersForView( $view->getName() ); foreach ( $composers as $composer ) { $composer->execute( $view ); } }
[ "public", "function", "compose", "(", "ViewInterface", "$", "view", ")", "{", "$", "composers", "=", "$", "this", "->", "getComposersForView", "(", "$", "view", "->", "getName", "(", ")", ")", ";", "foreach", "(", "$", "composers", "as", "$", "composer",...
Get the composed context for a view. Passes all arguments to the composer. @param ViewInterface $view @return void
[ "Get", "the", "composed", "context", "for", "a", "view", ".", "Passes", "all", "arguments", "to", "the", "composer", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/ViewService.php#L114-L120
htmlburger/wpemerge
src/Flash/Flash.php
Flash.setStore
public function setStore( &$store ) { if ( ! $this->isValidStore( $store ) ) { return; } $this->store = &$store; if ( ! isset( $this->store[ $this->store_key ] ) ) { $this->store[ $this->store_key ] = [ static::CURRENT_KEY => [], static::NEXT_KEY => [], ]; } $this->flashed = $store[ $this->store_key ]; }
php
public function setStore( &$store ) { if ( ! $this->isValidStore( $store ) ) { return; } $this->store = &$store; if ( ! isset( $this->store[ $this->store_key ] ) ) { $this->store[ $this->store_key ] = [ static::CURRENT_KEY => [], static::NEXT_KEY => [], ]; } $this->flashed = $store[ $this->store_key ]; }
[ "public", "function", "setStore", "(", "&", "$", "store", ")", "{", "if", "(", "!", "$", "this", "->", "isValidStore", "(", "$", "store", ")", ")", "{", "return", ";", "}", "$", "this", "->", "store", "=", "&", "$", "store", ";", "if", "(", "!"...
Set the store for flash messages. @param array|\ArrayAccess $store @return void
[ "Set", "the", "store", "for", "flash", "messages", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/Flash.php#L99-L114
htmlburger/wpemerge
src/Flash/Flash.php
Flash.getFromRequest
protected function getFromRequest( $request_key, $key = null, $default = [] ) { $this->validateStore(); if ( $key === null ) { return Arr::get( $this->flashed, $request_key, $default ); } return Arr::get( $this->flashed[ $request_key ], $key, $default ); }
php
protected function getFromRequest( $request_key, $key = null, $default = [] ) { $this->validateStore(); if ( $key === null ) { return Arr::get( $this->flashed, $request_key, $default ); } return Arr::get( $this->flashed[ $request_key ], $key, $default ); }
[ "protected", "function", "getFromRequest", "(", "$", "request_key", ",", "$", "key", "=", "null", ",", "$", "default", "=", "[", "]", ")", "{", "$", "this", "->", "validateStore", "(", ")", ";", "if", "(", "$", "key", "===", "null", ")", "{", "retu...
Get the entire store or the values for a key for a request. @param string $request_key @param string|null $key @param mixed $default @return mixed
[ "Get", "the", "entire", "store", "or", "the", "values", "for", "a", "key", "for", "a", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/Flash.php#L133-L141
htmlburger/wpemerge
src/Flash/Flash.php
Flash.addToRequest
protected function addToRequest( $request_key, $key, $new_items ) { $this->validateStore(); $new_items = MixedType::toArray( $new_items ); $items = MixedType::toArray( $this->get( $key, [] ) ); $this->flashed[ $request_key ][ $key ] = array_merge( $items, $new_items ); }
php
protected function addToRequest( $request_key, $key, $new_items ) { $this->validateStore(); $new_items = MixedType::toArray( $new_items ); $items = MixedType::toArray( $this->get( $key, [] ) ); $this->flashed[ $request_key ][ $key ] = array_merge( $items, $new_items ); }
[ "protected", "function", "addToRequest", "(", "$", "request_key", ",", "$", "key", ",", "$", "new_items", ")", "{", "$", "this", "->", "validateStore", "(", ")", ";", "$", "new_items", "=", "MixedType", "::", "toArray", "(", "$", "new_items", ")", ";", ...
Add values for a key for a request. @param string $request_key @param string $key @param mixed $new_items @return void
[ "Add", "values", "for", "a", "key", "for", "a", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/Flash.php#L151-L157
htmlburger/wpemerge
src/Flash/Flash.php
Flash.clearFromRequest
protected function clearFromRequest( $request_key, $key = null ) { $this->validateStore(); $keys = $key === null ? array_keys( $this->flashed[ $request_key ] ) : [$key]; foreach ( $keys as $k ) { unset( $this->flashed[ $request_key ][ $k ] ); } }
php
protected function clearFromRequest( $request_key, $key = null ) { $this->validateStore(); $keys = $key === null ? array_keys( $this->flashed[ $request_key ] ) : [$key]; foreach ( $keys as $k ) { unset( $this->flashed[ $request_key ][ $k ] ); } }
[ "protected", "function", "clearFromRequest", "(", "$", "request_key", ",", "$", "key", "=", "null", ")", "{", "$", "this", "->", "validateStore", "(", ")", ";", "$", "keys", "=", "$", "key", "===", "null", "?", "array_keys", "(", "$", "this", "->", "...
Remove all values or values for a key from a request. @param string $request_key @param string|null $key @return void
[ "Remove", "all", "values", "or", "values", "for", "a", "key", "from", "a", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/Flash.php#L166-L173
htmlburger/wpemerge
src/Flash/Flash.php
Flash.shift
public function shift() { $this->validateStore(); $this->flashed[ static::CURRENT_KEY ] = $this->flashed[ static::NEXT_KEY ]; $this->flashed[ static::NEXT_KEY ] = []; }
php
public function shift() { $this->validateStore(); $this->flashed[ static::CURRENT_KEY ] = $this->flashed[ static::NEXT_KEY ]; $this->flashed[ static::NEXT_KEY ] = []; }
[ "public", "function", "shift", "(", ")", "{", "$", "this", "->", "validateStore", "(", ")", ";", "$", "this", "->", "flashed", "[", "static", "::", "CURRENT_KEY", "]", "=", "$", "this", "->", "flashed", "[", "static", "::", "NEXT_KEY", "]", ";", "$",...
Shift current store and replace it with next store. @return void
[ "Shift", "current", "store", "and", "replace", "it", "with", "next", "store", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/Flash.php#L244-L249
htmlburger/wpemerge
src/Helpers/MixedType.php
MixedType.value
public static function value( $entity, $arguments = [], $method = '__invoke', $instantiator = 'static::instantiate' ) { if ( is_callable( $entity ) ) { return call_user_func_array( $entity, $arguments ); } if ( is_object( $entity ) ) { return call_user_func_array( [$entity, $method], $arguments ); } if ( static::isClass( $entity ) ) { return call_user_func_array( [call_user_func( $instantiator, $entity ), $method], $arguments ); } return $entity; }
php
public static function value( $entity, $arguments = [], $method = '__invoke', $instantiator = 'static::instantiate' ) { if ( is_callable( $entity ) ) { return call_user_func_array( $entity, $arguments ); } if ( is_object( $entity ) ) { return call_user_func_array( [$entity, $method], $arguments ); } if ( static::isClass( $entity ) ) { return call_user_func_array( [call_user_func( $instantiator, $entity ), $method], $arguments ); } return $entity; }
[ "public", "static", "function", "value", "(", "$", "entity", ",", "$", "arguments", "=", "[", "]", ",", "$", "method", "=", "'__invoke'", ",", "$", "instantiator", "=", "'static::instantiate'", ")", "{", "if", "(", "is_callable", "(", "$", "entity", ")",...
Executes a value depending on what type it is and returns the result Callable: call; return result Instance: call method; return result Class: instantiate; call method; return result Other: return value without taking any action @noinspection PhpDocSignatureInspection @param mixed $entity @param array $arguments @param string $method @param callable $instantiator @return mixed
[ "Executes", "a", "value", "depending", "on", "what", "type", "it", "is", "and", "returns", "the", "result", "Callable", ":", "call", ";", "return", "result", "Instance", ":", "call", "method", ";", "return", "result", "Class", ":", "instantiate", ";", "cal...
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/MixedType.php#L41-L60
htmlburger/wpemerge
src/Helpers/MixedType.php
MixedType.addTrailingSlash
public static function addTrailingSlash( $path, $slash = DIRECTORY_SEPARATOR ) { $path = static::normalizePath( $path, $slash ); $path = preg_replace( '~' . preg_quote( $slash, '~' ) . '*$~', $slash, $path ); return $path; }
php
public static function addTrailingSlash( $path, $slash = DIRECTORY_SEPARATOR ) { $path = static::normalizePath( $path, $slash ); $path = preg_replace( '~' . preg_quote( $slash, '~' ) . '*$~', $slash, $path ); return $path; }
[ "public", "static", "function", "addTrailingSlash", "(", "$", "path", ",", "$", "slash", "=", "DIRECTORY_SEPARATOR", ")", "{", "$", "path", "=", "static", "::", "normalizePath", "(", "$", "path", ",", "$", "slash", ")", ";", "$", "path", "=", "preg_repla...
Ensure path has a trailing slash. @param string $path @param string $slash @return string
[ "Ensure", "path", "has", "a", "trailing", "slash", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/MixedType.php#L101-L105
htmlburger/wpemerge
src/Helpers/MixedType.php
MixedType.removeTrailingSlash
public static function removeTrailingSlash( $path, $slash = DIRECTORY_SEPARATOR ) { $path = static::normalizePath( $path, $slash ); $path = preg_replace( '~' . preg_quote( $slash, '~' ) . '+$~', '', $path ); return $path; }
php
public static function removeTrailingSlash( $path, $slash = DIRECTORY_SEPARATOR ) { $path = static::normalizePath( $path, $slash ); $path = preg_replace( '~' . preg_quote( $slash, '~' ) . '+$~', '', $path ); return $path; }
[ "public", "static", "function", "removeTrailingSlash", "(", "$", "path", ",", "$", "slash", "=", "DIRECTORY_SEPARATOR", ")", "{", "$", "path", "=", "static", "::", "normalizePath", "(", "$", "path", ",", "$", "slash", ")", ";", "$", "path", "=", "preg_re...
Ensure path does not have a trailing slash. @param string $path @param string $slash @return string
[ "Ensure", "path", "does", "not", "have", "a", "trailing", "slash", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/MixedType.php#L114-L118
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.respond
public function respond( ResponseInterface $response ) { if ( ! headers_sent() ) { $this->sendHeaders( $response ); } $this->sendBody( $response ); }
php
public function respond( ResponseInterface $response ) { if ( ! headers_sent() ) { $this->sendHeaders( $response ); } $this->sendBody( $response ); }
[ "public", "function", "respond", "(", "ResponseInterface", "$", "response", ")", "{", "if", "(", "!", "headers_sent", "(", ")", ")", "{", "$", "this", "->", "sendHeaders", "(", "$", "response", ")", ";", "}", "$", "this", "->", "sendBody", "(", "$", ...
Send output based on a response object. @credit heavily modified version of slimphp/slim - Slim/App.php @codeCoverageIgnore @param ResponseInterface $response @return void
[ "Send", "output", "based", "on", "a", "response", "object", ".", "@credit", "heavily", "modified", "version", "of", "slimphp", "/", "slim", "-", "Slim", "/", "App", ".", "php" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L49-L54
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.sendHeaders
public function sendHeaders( ResponseInterface $response ) { // Status header( sprintf( 'HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase() ) ); // Headers foreach ( $response->getHeaders() as $name => $values ) { foreach ( $values as $value ) { header( sprintf( '%s: %s', $name, $value ), false ); } } }
php
public function sendHeaders( ResponseInterface $response ) { // Status header( sprintf( 'HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase() ) ); // Headers foreach ( $response->getHeaders() as $name => $values ) { foreach ( $values as $value ) { header( sprintf( '%s: %s', $name, $value ), false ); } } }
[ "public", "function", "sendHeaders", "(", "ResponseInterface", "$", "response", ")", "{", "// Status", "header", "(", "sprintf", "(", "'HTTP/%s %s %s'", ",", "$", "response", "->", "getProtocolVersion", "(", ")", ",", "$", "response", "->", "getStatusCode", "(",...
Send a request's headers to the client. @codeCoverageIgnore @param ResponseInterface $response @return void
[ "Send", "a", "request", "s", "headers", "to", "the", "client", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L63-L78
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.getBody
protected function getBody( ResponseInterface $response ) { $body = $response->getBody(); if ( $body->isSeekable() ) { $body->rewind(); } return $body; }
php
protected function getBody( ResponseInterface $response ) { $body = $response->getBody(); if ( $body->isSeekable() ) { $body->rewind(); } return $body; }
[ "protected", "function", "getBody", "(", "ResponseInterface", "$", "response", ")", "{", "$", "body", "=", "$", "response", "->", "getBody", "(", ")", ";", "if", "(", "$", "body", "->", "isSeekable", "(", ")", ")", "{", "$", "body", "->", "rewind", "...
Get a response's body stream so it is ready to be read. @codeCoverageIgnore @param ResponseInterface $response @return StreamInterface
[ "Get", "a", "response", "s", "body", "stream", "so", "it", "is", "ready", "to", "be", "read", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L87-L93
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.getBodyContentLength
protected function getBodyContentLength( ResponseInterface $response ) { $content_length = $response->getHeaderLine( 'Content-Length' ); if ( ! $content_length ) { $body = $this->getBody( $response ); $content_length = $body->getSize(); } if ( ! is_numeric( $content_length ) ) { $content_length = 0; } return (integer) $content_length; }
php
protected function getBodyContentLength( ResponseInterface $response ) { $content_length = $response->getHeaderLine( 'Content-Length' ); if ( ! $content_length ) { $body = $this->getBody( $response ); $content_length = $body->getSize(); } if ( ! is_numeric( $content_length ) ) { $content_length = 0; } return (integer) $content_length; }
[ "protected", "function", "getBodyContentLength", "(", "ResponseInterface", "$", "response", ")", "{", "$", "content_length", "=", "$", "response", "->", "getHeaderLine", "(", "'Content-Length'", ")", ";", "if", "(", "!", "$", "content_length", ")", "{", "$", "...
Get a response's body's content length. @codeCoverageIgnore @param ResponseInterface $response @return integer
[ "Get", "a", "response", "s", "body", "s", "content", "length", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L102-L115
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.sendBody
public function sendBody( ResponseInterface $response, $chunk_size = 4096 ) { $body = $this->getBody( $response ); $content_length = $this->getBodyContentLength( $response ); if ( $content_length > 0 ) { $this->sendBodyWithLength( $body, $content_length, $chunk_size ); } else { $this->sendBodyWithoutLength( $body, $chunk_size ); } }
php
public function sendBody( ResponseInterface $response, $chunk_size = 4096 ) { $body = $this->getBody( $response ); $content_length = $this->getBodyContentLength( $response ); if ( $content_length > 0 ) { $this->sendBodyWithLength( $body, $content_length, $chunk_size ); } else { $this->sendBodyWithoutLength( $body, $chunk_size ); } }
[ "public", "function", "sendBody", "(", "ResponseInterface", "$", "response", ",", "$", "chunk_size", "=", "4096", ")", "{", "$", "body", "=", "$", "this", "->", "getBody", "(", "$", "response", ")", ";", "$", "content_length", "=", "$", "this", "->", "...
Send a request's body to the client. @codeCoverageIgnore @param ResponseInterface $response @param integer $chunk_size @return void
[ "Send", "a", "request", "s", "body", "to", "the", "client", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L125-L134
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.sendBodyWithoutLength
protected function sendBodyWithoutLength( StreamInterface $body, $chunk_size ) { while ( ! $body->eof() ) { echo $body->read( $chunk_size ); if ( connection_status() !== CONNECTION_NORMAL ) { break; } } }
php
protected function sendBodyWithoutLength( StreamInterface $body, $chunk_size ) { while ( ! $body->eof() ) { echo $body->read( $chunk_size ); if ( connection_status() !== CONNECTION_NORMAL ) { break; } } }
[ "protected", "function", "sendBodyWithoutLength", "(", "StreamInterface", "$", "body", ",", "$", "chunk_size", ")", "{", "while", "(", "!", "$", "body", "->", "eof", "(", ")", ")", "{", "echo", "$", "body", "->", "read", "(", "$", "chunk_size", ")", ";...
Send a body with an unknown length to the client. @codeCoverageIgnore @param StreamInterface $body @param integer $chunk_size @return void
[ "Send", "a", "body", "with", "an", "unknown", "length", "to", "the", "client", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L144-L152
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.sendBodyWithLength
protected function sendBodyWithLength( StreamInterface $body, $length, $chunk_size ) { $content_left = $length; while ( $content_left > 0 ) { $read = min( $chunk_size, $content_left ); if ( $read <= 0 ) { break; } echo $body->read( $read ); $content_left -= $read; if ( connection_status() !== CONNECTION_NORMAL ) { break; } } }
php
protected function sendBodyWithLength( StreamInterface $body, $length, $chunk_size ) { $content_left = $length; while ( $content_left > 0 ) { $read = min( $chunk_size, $content_left ); if ( $read <= 0 ) { break; } echo $body->read( $read ); $content_left -= $read; if ( connection_status() !== CONNECTION_NORMAL ) { break; } } }
[ "protected", "function", "sendBodyWithLength", "(", "StreamInterface", "$", "body", ",", "$", "length", ",", "$", "chunk_size", ")", "{", "$", "content_left", "=", "$", "length", ";", "while", "(", "$", "content_left", ">", "0", ")", "{", "$", "read", "=...
Send a body with a known length to the client. @codeCoverageIgnore @param StreamInterface $body @param integer $length @param integer $chunk_size @return void
[ "Send", "a", "body", "with", "a", "known", "length", "to", "the", "client", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L163-L181
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.output
public function output( $output ) { $response = $this->response(); $response = $response->withBody( Psr7\stream_for( $output ) ); return $response; }
php
public function output( $output ) { $response = $this->response(); $response = $response->withBody( Psr7\stream_for( $output ) ); return $response; }
[ "public", "function", "output", "(", "$", "output", ")", "{", "$", "response", "=", "$", "this", "->", "response", "(", ")", ";", "$", "response", "=", "$", "response", "->", "withBody", "(", "Psr7", "\\", "stream_for", "(", "$", "output", ")", ")", ...
Get a cloned response with the passed string as the body. @param string $output @return ResponseInterface
[ "Get", "a", "cloned", "response", "with", "the", "passed", "string", "as", "the", "body", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L198-L202
htmlburger/wpemerge
src/Responses/ResponseService.php
ResponseService.json
public function json( $data ) { $response = $this->response(); $response = $response->withHeader( 'Content-Type', 'application/json' ); $response = $response->withBody( Psr7\stream_for( wp_json_encode( $data ) ) ); return $response; }
php
public function json( $data ) { $response = $this->response(); $response = $response->withHeader( 'Content-Type', 'application/json' ); $response = $response->withBody( Psr7\stream_for( wp_json_encode( $data ) ) ); return $response; }
[ "public", "function", "json", "(", "$", "data", ")", "{", "$", "response", "=", "$", "this", "->", "response", "(", ")", ";", "$", "response", "=", "$", "response", "->", "withHeader", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "$", "r...
Get a cloned response, json encoding the passed data as the body. @param mixed $data @return ResponseInterface
[ "Get", "a", "cloned", "response", "json", "encoding", "the", "passed", "data", "as", "the", "body", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponseService.php#L210-L215
htmlburger/wpemerge
src/View/NameProxyViewEngine.php
NameProxyViewEngine.exists
public function exists( $view ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->exists( $view ); }
php
public function exists( $view ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->exists( $view ); }
[ "public", "function", "exists", "(", "$", "view", ")", "{", "$", "engine_key", "=", "$", "this", "->", "getBindingForFile", "(", "$", "view", ")", ";", "$", "engine", "=", "Application", "::", "resolve", "(", "$", "engine_key", ")", ";", "return", "$",...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/NameProxyViewEngine.php#L49-L53
htmlburger/wpemerge
src/View/NameProxyViewEngine.php
NameProxyViewEngine.canonical
public function canonical( $view ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->canonical( $view ); }
php
public function canonical( $view ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->canonical( $view ); }
[ "public", "function", "canonical", "(", "$", "view", ")", "{", "$", "engine_key", "=", "$", "this", "->", "getBindingForFile", "(", "$", "view", ")", ";", "$", "engine", "=", "Application", "::", "resolve", "(", "$", "engine_key", ")", ";", "return", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/NameProxyViewEngine.php#L58-L62
htmlburger/wpemerge
src/View/NameProxyViewEngine.php
NameProxyViewEngine.make
public function make( $views ) { foreach ( $views as $view ) { if ( $this->exists( $view ) ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->make( [$view] ); } } throw new ViewNotFoundException( 'View not found for "' . implode( ', ', $views ) . '"' ); }
php
public function make( $views ) { foreach ( $views as $view ) { if ( $this->exists( $view ) ) { $engine_key = $this->getBindingForFile( $view ); $engine = Application::resolve( $engine_key ); return $engine->make( [$view] ); } } throw new ViewNotFoundException( 'View not found for "' . implode( ', ', $views ) . '"' ); }
[ "public", "function", "make", "(", "$", "views", ")", "{", "foreach", "(", "$", "views", "as", "$", "view", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "view", ")", ")", "{", "$", "engine_key", "=", "$", "this", "->", "getBindingF...
{@inheritDoc} @throws ViewNotFoundException
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/NameProxyViewEngine.php#L68-L78
htmlburger/wpemerge
src/View/NameProxyViewEngine.php
NameProxyViewEngine.getBindingForFile
public function getBindingForFile( $file ) { $engine_key = $this->default; foreach ( $this->bindings as $suffix => $engine ) { if ( substr( $file, -strlen( $suffix ) ) === $suffix ) { $engine_key = $engine; break; } } return $engine_key; }
php
public function getBindingForFile( $file ) { $engine_key = $this->default; foreach ( $this->bindings as $suffix => $engine ) { if ( substr( $file, -strlen( $suffix ) ) === $suffix ) { $engine_key = $engine; break; } } return $engine_key; }
[ "public", "function", "getBindingForFile", "(", "$", "file", ")", "{", "$", "engine_key", "=", "$", "this", "->", "default", ";", "foreach", "(", "$", "this", "->", "bindings", "as", "$", "suffix", "=>", "$", "engine", ")", "{", "if", "(", "substr", ...
Get the engine key binding for a specific file @param string $file @return string
[ "Get", "the", "engine", "key", "binding", "for", "a", "specific", "file" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/NameProxyViewEngine.php#L104-L115
htmlburger/wpemerge
src/Responses/RedirectResponse.php
RedirectResponse.back
public function back( $fallback = '', $status = 302 ) { $url = $this->request->headers( 'Referer' ); if ( empty( $url ) ) { $url = $fallback; } if ( empty( $url ) ) { $url = $this->request->getUrl(); } return $this->to( $url, $status ); }
php
public function back( $fallback = '', $status = 302 ) { $url = $this->request->headers( 'Referer' ); if ( empty( $url ) ) { $url = $fallback; } if ( empty( $url ) ) { $url = $this->request->getUrl(); } return $this->to( $url, $status ); }
[ "public", "function", "back", "(", "$", "fallback", "=", "''", ",", "$", "status", "=", "302", ")", "{", "$", "url", "=", "$", "this", "->", "request", "->", "headers", "(", "'Referer'", ")", ";", "if", "(", "empty", "(", "$", "url", ")", ")", ...
Get a response redirecting back to the referrer or a fallback. @param string $fallback @param integer $status @return \Psr\Http\Message\ResponseInterface
[ "Get", "a", "response", "redirecting", "back", "to", "the", "referrer", "or", "a", "fallback", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/RedirectResponse.php#L57-L69
htmlburger/wpemerge
src/Application/Application.php
Application.bootstrap
public function bootstrap( $config = [], $run = true ) { $this->renderConfigurationExceptions( function () use ( $config, $run ) { if ( $this->isBootstrapped() ) { throw new ConfigurationException( static::class . ' already bootstrapped.' ); } $container = $this->getContainer(); $this->loadConfig( $container, $config ); $this->loadServiceProviders( $container ); $this->loadRoutes( Arr::get( $config, 'routes.web', '' ), Arr::get( $config, 'routes.admin', '' ), Arr::get( $config, 'routes.ajax', '' ) ); $this->bootstrapped = true; if ( $run ) { $kernel = $this->resolve( WPEMERGE_WORDPRESS_HTTP_KERNEL_KEY ); $kernel->bootstrap(); } } ); }
php
public function bootstrap( $config = [], $run = true ) { $this->renderConfigurationExceptions( function () use ( $config, $run ) { if ( $this->isBootstrapped() ) { throw new ConfigurationException( static::class . ' already bootstrapped.' ); } $container = $this->getContainer(); $this->loadConfig( $container, $config ); $this->loadServiceProviders( $container ); $this->loadRoutes( Arr::get( $config, 'routes.web', '' ), Arr::get( $config, 'routes.admin', '' ), Arr::get( $config, 'routes.ajax', '' ) ); $this->bootstrapped = true; if ( $run ) { $kernel = $this->resolve( WPEMERGE_WORDPRESS_HTTP_KERNEL_KEY ); $kernel->bootstrap(); } } ); }
[ "public", "function", "bootstrap", "(", "$", "config", "=", "[", "]", ",", "$", "run", "=", "true", ")", "{", "$", "this", "->", "renderConfigurationExceptions", "(", "function", "(", ")", "use", "(", "$", "config", ",", "$", "run", ")", "{", "if", ...
Bootstrap the application. WordPress' 'after_setup_theme' action is a good place to call this. @param array $config @param boolean $run @return void
[ "Bootstrap", "the", "application", ".", "WordPress", "after_setup_theme", "action", "is", "a", "good", "place", "to", "call", "this", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L140-L162
htmlburger/wpemerge
src/Application/Application.php
Application.loadConfig
protected function loadConfig( Container $container, $config ) { $container[ WPEMERGE_CONFIG_KEY ] = array_merge( $container[ WPEMERGE_CONFIG_KEY ], $config ); }
php
protected function loadConfig( Container $container, $config ) { $container[ WPEMERGE_CONFIG_KEY ] = array_merge( $container[ WPEMERGE_CONFIG_KEY ], $config ); }
[ "protected", "function", "loadConfig", "(", "Container", "$", "container", ",", "$", "config", ")", "{", "$", "container", "[", "WPEMERGE_CONFIG_KEY", "]", "=", "array_merge", "(", "$", "container", "[", "WPEMERGE_CONFIG_KEY", "]", ",", "$", "config", ")", "...
Load config into the service container. @codeCoverageIgnore @param Container $container @param array $config @return void
[ "Load", "config", "into", "the", "service", "container", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L172-L177
htmlburger/wpemerge
src/Application/Application.php
Application.loadServiceProviders
protected function loadServiceProviders( Container $container ) { $container[ WPEMERGE_SERVICE_PROVIDERS_KEY ] = array_merge( $this->service_providers, $container[ WPEMERGE_CONFIG_KEY ]['providers'] ); $service_providers = array_map( function ( $service_provider ) { if ( ! is_subclass_of( $service_provider, ServiceProviderInterface::class ) ) { throw new ConfigurationException( 'The following class does not implement ' . 'ServiceProviderInterface: ' . $service_provider ); } return new $service_provider(); }, $container[ WPEMERGE_SERVICE_PROVIDERS_KEY ] ); $this->registerServiceProviders( $service_providers, $container ); $this->bootstrapServiceProviders( $service_providers, $container ); }
php
protected function loadServiceProviders( Container $container ) { $container[ WPEMERGE_SERVICE_PROVIDERS_KEY ] = array_merge( $this->service_providers, $container[ WPEMERGE_CONFIG_KEY ]['providers'] ); $service_providers = array_map( function ( $service_provider ) { if ( ! is_subclass_of( $service_provider, ServiceProviderInterface::class ) ) { throw new ConfigurationException( 'The following class does not implement ' . 'ServiceProviderInterface: ' . $service_provider ); } return new $service_provider(); }, $container[ WPEMERGE_SERVICE_PROVIDERS_KEY ] ); $this->registerServiceProviders( $service_providers, $container ); $this->bootstrapServiceProviders( $service_providers, $container ); }
[ "protected", "function", "loadServiceProviders", "(", "Container", "$", "container", ")", "{", "$", "container", "[", "WPEMERGE_SERVICE_PROVIDERS_KEY", "]", "=", "array_merge", "(", "$", "this", "->", "service_providers", ",", "$", "container", "[", "WPEMERGE_CONFIG...
Register and bootstrap all service providers. @codeCoverageIgnore @param Container $container @return void
[ "Register", "and", "bootstrap", "all", "service", "providers", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L186-L205
htmlburger/wpemerge
src/Application/Application.php
Application.registerServiceProviders
protected function registerServiceProviders( $service_providers, Container $container ) { foreach ( $service_providers as $provider ) { $provider->register( $container ); } }
php
protected function registerServiceProviders( $service_providers, Container $container ) { foreach ( $service_providers as $provider ) { $provider->register( $container ); } }
[ "protected", "function", "registerServiceProviders", "(", "$", "service_providers", ",", "Container", "$", "container", ")", "{", "foreach", "(", "$", "service_providers", "as", "$", "provider", ")", "{", "$", "provider", "->", "register", "(", "$", "container",...
Register all service providers. @param array<\WPEmerge\ServiceProviders\ServiceProviderInterface> $service_providers @param Container $container @return void
[ "Register", "all", "service", "providers", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L214-L218
htmlburger/wpemerge
src/Application/Application.php
Application.bootstrapServiceProviders
protected function bootstrapServiceProviders( $service_providers, Container $container ) { foreach ( $service_providers as $provider ) { $provider->bootstrap( $container ); } }
php
protected function bootstrapServiceProviders( $service_providers, Container $container ) { foreach ( $service_providers as $provider ) { $provider->bootstrap( $container ); } }
[ "protected", "function", "bootstrapServiceProviders", "(", "$", "service_providers", ",", "Container", "$", "container", ")", "{", "foreach", "(", "$", "service_providers", "as", "$", "provider", ")", "{", "$", "provider", "->", "bootstrap", "(", "$", "container...
Bootstrap all service providers. @param array<\WPEmerge\ServiceProviders\ServiceProviderInterface> $service_providers @param Container $container @return void
[ "Bootstrap", "all", "service", "providers", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L227-L231
htmlburger/wpemerge
src/Application/Application.php
Application.loadRoutes
protected function loadRoutes( $web = '', $admin = '', $ajax = '' ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { $this->loadRoutesFile( $ajax, [ 'namespace' => '\\App\\Controllers\\Ajax\\', 'middleware' => ['ajax'], ] ); return; } if ( is_admin() ) { $this->loadRoutesFile( $admin, [ 'namespace' => '\\App\\Controllers\\Admin\\', 'middleware' => ['admin'], ] ); return; } $this->loadRoutesFile( $web, [ 'namespace' => '\\App\\Controllers\\Web\\', 'handler' => '\\WPEmerge\\Controllers\\WordPressController@handle', 'middleware' => ['web'], ] ); }
php
protected function loadRoutes( $web = '', $admin = '', $ajax = '' ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { $this->loadRoutesFile( $ajax, [ 'namespace' => '\\App\\Controllers\\Ajax\\', 'middleware' => ['ajax'], ] ); return; } if ( is_admin() ) { $this->loadRoutesFile( $admin, [ 'namespace' => '\\App\\Controllers\\Admin\\', 'middleware' => ['admin'], ] ); return; } $this->loadRoutesFile( $web, [ 'namespace' => '\\App\\Controllers\\Web\\', 'handler' => '\\WPEmerge\\Controllers\\WordPressController@handle', 'middleware' => ['web'], ] ); }
[ "protected", "function", "loadRoutes", "(", "$", "web", "=", "''", ",", "$", "admin", "=", "''", ",", "$", "ajax", "=", "''", ")", "{", "if", "(", "defined", "(", "'DOING_AJAX'", ")", "&&", "DOING_AJAX", ")", "{", "$", "this", "->", "loadRoutesFile",...
Load route definition files depending on the current request. @codeCoverageIgnore @param string $web @param string $admin @param string $ajax @return void
[ "Load", "route", "definition", "files", "depending", "on", "the", "current", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L242-L264
htmlburger/wpemerge
src/Application/Application.php
Application.loadRoutesFile
protected function loadRoutesFile( $file, $attributes ) { if ( empty( $file ) ) { return; } Route::attributes( $attributes )->group( $file ); }
php
protected function loadRoutesFile( $file, $attributes ) { if ( empty( $file ) ) { return; } Route::attributes( $attributes )->group( $file ); }
[ "protected", "function", "loadRoutesFile", "(", "$", "file", ",", "$", "attributes", ")", "{", "if", "(", "empty", "(", "$", "file", ")", ")", "{", "return", ";", "}", "Route", "::", "attributes", "(", "$", "attributes", ")", "->", "group", "(", "$",...
Load a route definition file, applying attributes to all routes defined within. @codeCoverageIgnore @param string $file @param array<string, mixed> $attributes @return void
[ "Load", "a", "route", "definition", "file", "applying", "attributes", "to", "all", "routes", "defined", "within", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L274-L280
htmlburger/wpemerge
src/Application/Application.php
Application.resolve
public function resolve( $key ) { $this->verifyBootstrap(); if ( ! isset( $this->getContainer()[ $key ] ) ) { return null; } return $this->getContainer()[ $key ]; }
php
public function resolve( $key ) { $this->verifyBootstrap(); if ( ! isset( $this->getContainer()[ $key ] ) ) { return null; } return $this->getContainer()[ $key ]; }
[ "public", "function", "resolve", "(", "$", "key", ")", "{", "$", "this", "->", "verifyBootstrap", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "getContainer", "(", ")", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";"...
Resolve a dependency from the IoC container. @param string $key @return mixed|null
[ "Resolve", "a", "dependency", "from", "the", "IoC", "container", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L299-L307
htmlburger/wpemerge
src/Application/Application.php
Application.instantiate
public function instantiate( $class ) { $this->verifyBootstrap(); $instance = $this->resolve( $class ); if ( $instance === null ) { if ( ! class_exists( $class ) ) { throw new ClassNotFoundException( 'Class not found: ' . $class ); } $instance = new $class(); } return $instance; }
php
public function instantiate( $class ) { $this->verifyBootstrap(); $instance = $this->resolve( $class ); if ( $instance === null ) { if ( ! class_exists( $class ) ) { throw new ClassNotFoundException( 'Class not found: ' . $class ); } $instance = new $class(); } return $instance; }
[ "public", "function", "instantiate", "(", "$", "class", ")", "{", "$", "this", "->", "verifyBootstrap", "(", ")", ";", "$", "instance", "=", "$", "this", "->", "resolve", "(", "$", "class", ")", ";", "if", "(", "$", "instance", "===", "null", ")", ...
Create and return a class instance. @throws ClassNotFoundException @param string $class @return object
[ "Create", "and", "return", "a", "class", "instance", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L316-L330
htmlburger/wpemerge
src/Application/Application.php
Application.renderConfigurationExceptions
protected function renderConfigurationExceptions( Closure $action ) { try { $action(); } catch ( ConfigurationException $exception ) { if ( ! $this->render_configuration_exceptions ) { throw $exception; } $request = Request::fromGlobals(); $handler = $this->resolve( WPEMERGE_EXCEPTIONS_CONFIGURATION_ERROR_HANDLER_KEY ); add_filter( 'wpemerge.pretty_errors.apply_admin_styles', '__return_false' ); Response::respond( $handler->getResponse( $request, $exception ) ); wp_die(); } }
php
protected function renderConfigurationExceptions( Closure $action ) { try { $action(); } catch ( ConfigurationException $exception ) { if ( ! $this->render_configuration_exceptions ) { throw $exception; } $request = Request::fromGlobals(); $handler = $this->resolve( WPEMERGE_EXCEPTIONS_CONFIGURATION_ERROR_HANDLER_KEY ); add_filter( 'wpemerge.pretty_errors.apply_admin_styles', '__return_false' ); Response::respond( $handler->getResponse( $request, $exception ) ); wp_die(); } }
[ "protected", "function", "renderConfigurationExceptions", "(", "Closure", "$", "action", ")", "{", "try", "{", "$", "action", "(", ")", ";", "}", "catch", "(", "ConfigurationException", "$", "exception", ")", "{", "if", "(", "!", "$", "this", "->", "render...
Catch any configuration exceptions and short-circuit to an error page. @codeCoverageIgnore @param Closure $action @return void
[ "Catch", "any", "configuration", "exceptions", "and", "short", "-", "circuit", "to", "an", "error", "page", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Application/Application.php#L339-L354
htmlburger/wpemerge
src/Routing/Route.php
Route.isSatisfied
public function isSatisfied( RequestInterface $request ) { if ( ! in_array( $request->getMethod(), $this->methods ) ) { return false; } return $this->condition->isSatisfied( $request ); }
php
public function isSatisfied( RequestInterface $request ) { if ( ! in_array( $request->getMethod(), $this->methods ) ) { return false; } return $this->condition->isSatisfied( $request ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "!", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "$", "this", "->", "methods", ")", ")", "{", "return", "false", ";", "}", "return...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Route.php#L76-L82
htmlburger/wpemerge
src/Routing/Route.php
Route.decorate
public function decorate( $attributes ) { $middleware = Arr::get( $attributes, 'middleware', [] ); $query = Arr::get( $attributes, 'query', null ); $this->middleware( $middleware ); if ( $query !== null) { $this->setQueryFilter( $query ); } }
php
public function decorate( $attributes ) { $middleware = Arr::get( $attributes, 'middleware', [] ); $query = Arr::get( $attributes, 'query', null ); $this->middleware( $middleware ); if ( $query !== null) { $this->setQueryFilter( $query ); } }
[ "public", "function", "decorate", "(", "$", "attributes", ")", "{", "$", "middleware", "=", "Arr", "::", "get", "(", "$", "attributes", ",", "'middleware'", ",", "[", "]", ")", ";", "$", "query", "=", "Arr", "::", "get", "(", "$", "attributes", ",", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Route.php#L94-L103
htmlburger/wpemerge
src/Routing/Route.php
Route.handle
public function handle( RequestInterface $request, $arguments = [] ) { $arguments = array_merge( [$request], $arguments, array_values( $this->condition->getArguments( $request ) ) ); return call_user_func_array( [$this->getHandler(), 'execute'], $arguments ); }
php
public function handle( RequestInterface $request, $arguments = [] ) { $arguments = array_merge( [$request], $arguments, array_values( $this->condition->getArguments( $request ) ) ); return call_user_func_array( [$this->getHandler(), 'execute'], $arguments ); }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "$", "arguments", "=", "[", "]", ")", "{", "$", "arguments", "=", "array_merge", "(", "[", "$", "request", "]", ",", "$", "arguments", ",", "array_values", "(", "$", "this", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Route.php#L108-L116
htmlburger/wpemerge
src/Controllers/WordPressController.php
WordPressController.handle
public function handle( RequestInterface $request, $view = '' ) { if ( is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { throw new ConfigurationException( 'Attempted to run the default WordPress controller on an ' . 'admin or AJAX page. Did you miss to specify a custom handler for ' . 'a route or accidentally used Route::all() during admin ' . 'requests?' ); } if ( empty( $view ) ) { throw new ConfigurationException( 'No view loaded for default WordPress controller. ' . 'Did you miss to specify a custom handler for an ajax or admin route?' ); } return Response::view( $view ) ->toResponse() ->withStatus( http_response_code() ); }
php
public function handle( RequestInterface $request, $view = '' ) { if ( is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { throw new ConfigurationException( 'Attempted to run the default WordPress controller on an ' . 'admin or AJAX page. Did you miss to specify a custom handler for ' . 'a route or accidentally used Route::all() during admin ' . 'requests?' ); } if ( empty( $view ) ) { throw new ConfigurationException( 'No view loaded for default WordPress controller. ' . 'Did you miss to specify a custom handler for an ajax or admin route?' ); } return Response::view( $view ) ->toResponse() ->withStatus( http_response_code() ); }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "$", "view", "=", "''", ")", "{", "if", "(", "is_admin", "(", ")", "||", "(", "defined", "(", "'DOING_AJAX'", ")", "&&", "DOING_AJAX", ")", ")", "{", "throw", "new", "Configu...
Default WordPress handler. @param RequestInterface $request @param string $view @return \Psr\Http\Message\ResponseInterface
[ "Default", "WordPress", "handler", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Controllers/WordPressController.php#L30-L50
htmlburger/wpemerge
src/Requests/Request.php
Request.getMethod
public function getMethod() { $method = (string) $this->server( 'REQUEST_METHOD', 'GET' ); $header_override = (string) $this->headers( 'X-HTTP-METHOD-OVERRIDE' ); if ( $method === 'POST' && $header_override ) { $method = strtoupper( $header_override ); } $body_override = (string) $this->post( '_method' ); if ( $method === 'POST' && $body_override ) { $method = strtoupper( $body_override ); } return strtoupper( $method ); }
php
public function getMethod() { $method = (string) $this->server( 'REQUEST_METHOD', 'GET' ); $header_override = (string) $this->headers( 'X-HTTP-METHOD-OVERRIDE' ); if ( $method === 'POST' && $header_override ) { $method = strtoupper( $header_override ); } $body_override = (string) $this->post( '_method' ); if ( $method === 'POST' && $body_override ) { $method = strtoupper( $body_override ); } return strtoupper( $method ); }
[ "public", "function", "getMethod", "(", ")", "{", "$", "method", "=", "(", "string", ")", "$", "this", "->", "server", "(", "'REQUEST_METHOD'", ",", "'GET'", ")", ";", "$", "header_override", "=", "(", "string", ")", "$", "this", "->", "headers", "(", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Requests/Request.php#L97-L111
htmlburger/wpemerge
src/Requests/Request.php
Request.getUrl
public function getUrl() { $https = $this->server( 'HTTPS' ); $protocol = $https ? 'https' : 'http'; $host = (string) $this->server( 'HTTP_HOST', '' ); $uri = (string) $this->server( 'REQUEST_URI', '' ); $uri = Url::addLeadingSlash( $uri ); return $protocol . '://' . $host . $uri; }
php
public function getUrl() { $https = $this->server( 'HTTPS' ); $protocol = $https ? 'https' : 'http'; $host = (string) $this->server( 'HTTP_HOST', '' ); $uri = (string) $this->server( 'REQUEST_URI', '' ); $uri = Url::addLeadingSlash( $uri ); return $protocol . '://' . $host . $uri; }
[ "public", "function", "getUrl", "(", ")", "{", "$", "https", "=", "$", "this", "->", "server", "(", "'HTTPS'", ")", ";", "$", "protocol", "=", "$", "https", "?", "'https'", ":", "'http'", ";", "$", "host", "=", "(", "string", ")", "$", "this", "-...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Requests/Request.php#L179-L188
htmlburger/wpemerge
src/Requests/Request.php
Request.input
protected function input( $source, $key = '', $default = null ) { $source = isset( $this->{$source} ) && is_array( $this->{$source} ) ? $this->{$source} : []; if ( empty( $key ) ) { return $source; } return Arr::get( $source, $key, $default ); }
php
protected function input( $source, $key = '', $default = null ) { $source = isset( $this->{$source} ) && is_array( $this->{$source} ) ? $this->{$source} : []; if ( empty( $key ) ) { return $source; } return Arr::get( $source, $key, $default ); }
[ "protected", "function", "input", "(", "$", "source", ",", "$", "key", "=", "''", ",", "$", "default", "=", "null", ")", "{", "$", "source", "=", "isset", "(", "$", "this", "->", "{", "$", "source", "}", ")", "&&", "is_array", "(", "$", "this", ...
Get all values or a single one from an input type. @param string $source @param string $key @param mixed $default @return mixed
[ "Get", "all", "values", "or", "a", "single", "one", "from", "an", "input", "type", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Requests/Request.php#L198-L206
htmlburger/wpemerge
src/Helpers/Handler.php
Handler.parse
protected function parse( $raw_handler, $default_method, $namespace ) { if ( $raw_handler instanceof Closure ) { return $raw_handler; } return $this->parseFromString( $raw_handler, $default_method, $namespace ); }
php
protected function parse( $raw_handler, $default_method, $namespace ) { if ( $raw_handler instanceof Closure ) { return $raw_handler; } return $this->parseFromString( $raw_handler, $default_method, $namespace ); }
[ "protected", "function", "parse", "(", "$", "raw_handler", ",", "$", "default_method", ",", "$", "namespace", ")", "{", "if", "(", "$", "raw_handler", "instanceof", "Closure", ")", "{", "return", "$", "raw_handler", ";", "}", "return", "$", "this", "->", ...
Parse a raw handler to a Closure or a [class, method] array @param string|Closure $raw_handler @param string $default_method @param string $namespace @return array|Closure|null
[ "Parse", "a", "raw", "handler", "to", "a", "Closure", "or", "a", "[", "class", "method", "]", "array" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/Handler.php#L53-L59
htmlburger/wpemerge
src/Helpers/Handler.php
Handler.parseFromString
protected function parseFromString( $raw_handler, $default_method, $namespace ) { list( $class, $method ) = array_pad( preg_split( '/@|::/', $raw_handler, 2 ), 2, '' ); if ( empty( $method ) ) { $method = $default_method; } if ( ! empty( $class ) && ! empty( $method ) ) { return [ 'class' => $class, 'method' => $method, 'namespace' => $namespace, ]; } return null; }
php
protected function parseFromString( $raw_handler, $default_method, $namespace ) { list( $class, $method ) = array_pad( preg_split( '/@|::/', $raw_handler, 2 ), 2, '' ); if ( empty( $method ) ) { $method = $default_method; } if ( ! empty( $class ) && ! empty( $method ) ) { return [ 'class' => $class, 'method' => $method, 'namespace' => $namespace, ]; } return null; }
[ "protected", "function", "parseFromString", "(", "$", "raw_handler", ",", "$", "default_method", ",", "$", "namespace", ")", "{", "list", "(", "$", "class", ",", "$", "method", ")", "=", "array_pad", "(", "preg_split", "(", "'/@|::/'", ",", "$", "raw_handl...
Parse a raw string handler to a [class, method] array @param string $raw_handler @param string $default_method @param string $namespace @return array|null
[ "Parse", "a", "raw", "string", "handler", "to", "a", "[", "class", "method", "]", "array" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/Handler.php#L69-L85
htmlburger/wpemerge
src/Helpers/Handler.php
Handler.execute
public function execute() { $arguments = func_get_args(); if ( $this->handler instanceof Closure ) { return call_user_func_array( $this->handler, $arguments ); } $namespace = $this->handler['namespace']; $class = $this->handler['class']; $method = $this->handler['method']; try { $instance = Application::instantiate( $class ); } catch ( ClassNotFoundException $e ) { try { $instance = Application::instantiate( $namespace . $class ); } catch ( ClassNotFoundException $e ) { throw new ClassNotFoundException( 'Class not found - tried: ' . $class . ', ' . $namespace . $class ); } } return call_user_func_array( [$instance, $method], $arguments ); }
php
public function execute() { $arguments = func_get_args(); if ( $this->handler instanceof Closure ) { return call_user_func_array( $this->handler, $arguments ); } $namespace = $this->handler['namespace']; $class = $this->handler['class']; $method = $this->handler['method']; try { $instance = Application::instantiate( $class ); } catch ( ClassNotFoundException $e ) { try { $instance = Application::instantiate( $namespace . $class ); } catch ( ClassNotFoundException $e ) { throw new ClassNotFoundException( 'Class not found - tried: ' . $class . ', ' . $namespace . $class ); } } return call_user_func_array( [$instance, $method], $arguments ); }
[ "public", "function", "execute", "(", ")", "{", "$", "arguments", "=", "func_get_args", "(", ")", ";", "if", "(", "$", "this", "->", "handler", "instanceof", "Closure", ")", "{", "return", "call_user_func_array", "(", "$", "this", "->", "handler", ",", "...
Execute the parsed handler with any provided arguments and return the result @param mixed ,...$arguments @return mixed
[ "Execute", "the", "parsed", "handler", "with", "any", "provided", "arguments", "and", "return", "the", "result" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/Handler.php#L102-L124
htmlburger/wpemerge
src/Exceptions/ErrorHandler.php
ErrorHandler.toResponse
protected function toResponse( $exception ) { // @codeCoverageIgnoreStart if ( $exception instanceof InvalidCsrfTokenException ) { wp_nonce_ays( '' ); } // @codeCoverageIgnoreEnd if ( $exception instanceof NotFoundException ) { return Response::error( 404 ); } return false; }
php
protected function toResponse( $exception ) { // @codeCoverageIgnoreStart if ( $exception instanceof InvalidCsrfTokenException ) { wp_nonce_ays( '' ); } // @codeCoverageIgnoreEnd if ( $exception instanceof NotFoundException ) { return Response::error( 404 ); } return false; }
[ "protected", "function", "toResponse", "(", "$", "exception", ")", "{", "// @codeCoverageIgnoreStart", "if", "(", "$", "exception", "instanceof", "InvalidCsrfTokenException", ")", "{", "wp_nonce_ays", "(", "''", ")", ";", "}", "// @codeCoverageIgnoreEnd", "if", "(",...
Convert an exception to a ResponseInterface instance if possible. @param PhpException $exception @return ResponseInterface|false
[ "Convert", "an", "exception", "to", "a", "ResponseInterface", "instance", "if", "possible", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Exceptions/ErrorHandler.php#L74-L86
htmlburger/wpemerge
src/Exceptions/ErrorHandler.php
ErrorHandler.toDebugResponse
protected function toDebugResponse( RequestInterface $request, PhpException $exception ) { if ( $request->isAjax() ) { return Response::json( [ 'message' => $exception->getMessage(), 'exception' => get_class( $exception ), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => array_map( function ( $trace ) { return Arr::except( $trace, ['args'] ); }, $exception->getTrace() ), ] )->withStatus( 500 ); } if ( $this->whoops !== null ) { return $this->toPrettyErrorResponse( $exception ); } throw $exception; }
php
protected function toDebugResponse( RequestInterface $request, PhpException $exception ) { if ( $request->isAjax() ) { return Response::json( [ 'message' => $exception->getMessage(), 'exception' => get_class( $exception ), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => array_map( function ( $trace ) { return Arr::except( $trace, ['args'] ); }, $exception->getTrace() ), ] )->withStatus( 500 ); } if ( $this->whoops !== null ) { return $this->toPrettyErrorResponse( $exception ); } throw $exception; }
[ "protected", "function", "toDebugResponse", "(", "RequestInterface", "$", "request", ",", "PhpException", "$", "exception", ")", "{", "if", "(", "$", "request", "->", "isAjax", "(", ")", ")", "{", "return", "Response", "::", "json", "(", "[", "'message'", ...
Convert an exception to a debug ResponseInterface instance if possible. @throws PhpException @param RequestInterface $request @param PhpException $exception @return ResponseInterface
[ "Convert", "an", "exception", "to", "a", "debug", "ResponseInterface", "instance", "if", "possible", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Exceptions/ErrorHandler.php#L96-L114
htmlburger/wpemerge
src/Exceptions/ErrorHandler.php
ErrorHandler.toPrettyErrorResponse
protected function toPrettyErrorResponse( $exception ) { $method = RunInterface::EXCEPTION_HANDLER; ob_start(); $this->whoops->$method( $exception ); $response = ob_get_clean(); return Response::output( $response )->withStatus( 500 ); }
php
protected function toPrettyErrorResponse( $exception ) { $method = RunInterface::EXCEPTION_HANDLER; ob_start(); $this->whoops->$method( $exception ); $response = ob_get_clean(); return Response::output( $response )->withStatus( 500 ); }
[ "protected", "function", "toPrettyErrorResponse", "(", "$", "exception", ")", "{", "$", "method", "=", "RunInterface", "::", "EXCEPTION_HANDLER", ";", "ob_start", "(", ")", ";", "$", "this", "->", "whoops", "->", "$", "method", "(", "$", "exception", ")", ...
Convert an exception to a pretty error response. @codeCoverageIgnore @param PhpException $exception @return ResponseInterface
[ "Convert", "an", "exception", "to", "a", "pretty", "error", "response", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Exceptions/ErrorHandler.php#L123-L129
htmlburger/wpemerge
src/Exceptions/ErrorHandler.php
ErrorHandler.getResponse
public function getResponse( RequestInterface $request, PhpException $exception ) { $response = $this->toResponse( $exception ); if ( $response !== false ) { return $response; } if ( ! $this->debug ) { return Response::error( 500 ); } return $this->toDebugResponse( $request, $exception ); }
php
public function getResponse( RequestInterface $request, PhpException $exception ) { $response = $this->toResponse( $exception ); if ( $response !== false ) { return $response; } if ( ! $this->debug ) { return Response::error( 500 ); } return $this->toDebugResponse( $request, $exception ); }
[ "public", "function", "getResponse", "(", "RequestInterface", "$", "request", ",", "PhpException", "$", "exception", ")", "{", "$", "response", "=", "$", "this", "->", "toResponse", "(", "$", "exception", ")", ";", "if", "(", "$", "response", "!==", "false...
{@inheritDoc} @throws PhpException
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Exceptions/ErrorHandler.php#L135-L147
reactphp/dns
src/Config/HostsFile.php
HostsFile.getDefaultPath
public static function getDefaultPath() { // use static path for all Unix-based systems if (DIRECTORY_SEPARATOR !== '\\') { return '/etc/hosts'; } // Windows actually stores the path in the registry under // \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath $path = '%SystemRoot%\\system32\drivers\etc\hosts'; $base = getenv('SystemRoot'); if ($base === false) { $base = 'C:\\Windows'; } return str_replace('%SystemRoot%', $base, $path); }
php
public static function getDefaultPath() { // use static path for all Unix-based systems if (DIRECTORY_SEPARATOR !== '\\') { return '/etc/hosts'; } // Windows actually stores the path in the registry under // \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath $path = '%SystemRoot%\\system32\drivers\etc\hosts'; $base = getenv('SystemRoot'); if ($base === false) { $base = 'C:\\Windows'; } return str_replace('%SystemRoot%', $base, $path); }
[ "public", "static", "function", "getDefaultPath", "(", ")", "{", "// use static path for all Unix-based systems", "if", "(", "DIRECTORY_SEPARATOR", "!==", "'\\\\'", ")", "{", "return", "'/etc/hosts'", ";", "}", "// Windows actually stores the path in the registry under", "// ...
Returns the default path for the hosts file on this system @return string @codeCoverageIgnore
[ "Returns", "the", "default", "path", "for", "the", "hosts", "file", "on", "this", "system" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/HostsFile.php#L30-L47
reactphp/dns
src/Config/HostsFile.php
HostsFile.loadFromPathBlocking
public static function loadFromPathBlocking($path = null) { if ($path === null) { $path = self::getDefaultPath(); } $contents = @file_get_contents($path); if ($contents === false) { throw new RuntimeException('Unable to load hosts file "' . $path . '"'); } return new self($contents); }
php
public static function loadFromPathBlocking($path = null) { if ($path === null) { $path = self::getDefaultPath(); } $contents = @file_get_contents($path); if ($contents === false) { throw new RuntimeException('Unable to load hosts file "' . $path . '"'); } return new self($contents); }
[ "public", "static", "function", "loadFromPathBlocking", "(", "$", "path", "=", "null", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "$", "path", "=", "self", "::", "getDefaultPath", "(", ")", ";", "}", "$", "contents", "=", "@", "file_g...
Loads a hosts file (from the given path or default location) Note that this method blocks while loading the given path and should thus be used with care! While this should be relatively fast for normal hosts file, this may be an issue if this file is located on a slow device or contains an excessive number of entries. In particular, this method should only be executed before the loop starts, not while it is running. @param ?string $path (optional) path to hosts file or null=load default location @return self @throws RuntimeException if the path can not be loaded (does not exist)
[ "Loads", "a", "hosts", "file", "(", "from", "the", "given", "path", "or", "default", "location", ")" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/HostsFile.php#L62-L74
reactphp/dns
src/Config/HostsFile.php
HostsFile.getIpsForHost
public function getIpsForHost($name) { $name = strtolower($name); $ips = array(); foreach (preg_split('/\r?\n/', $this->contents) as $line) { $parts = preg_split('/\s+/', $line); $ip = array_shift($parts); if ($parts && array_search($name, $parts) !== false) { // remove IPv6 zone ID (`fe80::1%lo0` => `fe80:1`) if (strpos($ip, ':') !== false && ($pos = strpos($ip, '%')) !== false) { $ip = substr($ip, 0, $pos); } if (@inet_pton($ip) !== false) { $ips[] = $ip; } } } return $ips; }
php
public function getIpsForHost($name) { $name = strtolower($name); $ips = array(); foreach (preg_split('/\r?\n/', $this->contents) as $line) { $parts = preg_split('/\s+/', $line); $ip = array_shift($parts); if ($parts && array_search($name, $parts) !== false) { // remove IPv6 zone ID (`fe80::1%lo0` => `fe80:1`) if (strpos($ip, ':') !== false && ($pos = strpos($ip, '%')) !== false) { $ip = substr($ip, 0, $pos); } if (@inet_pton($ip) !== false) { $ips[] = $ip; } } } return $ips; }
[ "public", "function", "getIpsForHost", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "$", "ips", "=", "array", "(", ")", ";", "foreach", "(", "preg_split", "(", "'/\\r?\\n/'", ",", "$", "this", "->", "content...
Returns all IPs for the given hostname @param string $name @return string[]
[ "Returns", "all", "IPs", "for", "the", "given", "hostname" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/HostsFile.php#L95-L116
reactphp/dns
src/Config/HostsFile.php
HostsFile.getHostsForIp
public function getHostsForIp($ip) { // check binary representation of IP to avoid string case and short notation $ip = @inet_pton($ip); if ($ip === false) { return array(); } $names = array(); foreach (preg_split('/\r?\n/', $this->contents) as $line) { $parts = preg_split('/\s+/', $line, null, PREG_SPLIT_NO_EMPTY); $addr = array_shift($parts); // remove IPv6 zone ID (`fe80::1%lo0` => `fe80:1`) if (strpos($addr, ':') !== false && ($pos = strpos($addr, '%')) !== false) { $addr = substr($addr, 0, $pos); } if (@inet_pton($addr) === $ip) { foreach ($parts as $part) { $names[] = $part; } } } return $names; }
php
public function getHostsForIp($ip) { // check binary representation of IP to avoid string case and short notation $ip = @inet_pton($ip); if ($ip === false) { return array(); } $names = array(); foreach (preg_split('/\r?\n/', $this->contents) as $line) { $parts = preg_split('/\s+/', $line, null, PREG_SPLIT_NO_EMPTY); $addr = array_shift($parts); // remove IPv6 zone ID (`fe80::1%lo0` => `fe80:1`) if (strpos($addr, ':') !== false && ($pos = strpos($addr, '%')) !== false) { $addr = substr($addr, 0, $pos); } if (@inet_pton($addr) === $ip) { foreach ($parts as $part) { $names[] = $part; } } } return $names; }
[ "public", "function", "getHostsForIp", "(", "$", "ip", ")", "{", "// check binary representation of IP to avoid string case and short notation", "$", "ip", "=", "@", "inet_pton", "(", "$", "ip", ")", ";", "if", "(", "$", "ip", "===", "false", ")", "{", "return",...
Returns all hostnames for the given IPv4 or IPv6 address @param string $ip @return string[]
[ "Returns", "all", "hostnames", "for", "the", "given", "IPv4", "or", "IPv6", "address" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/HostsFile.php#L124-L150
reactphp/dns
src/Config/Config.php
Config.loadResolvConfBlocking
public static function loadResolvConfBlocking($path = null) { if ($path === null) { $path = '/etc/resolv.conf'; } $contents = @file_get_contents($path); if ($contents === false) { throw new RuntimeException('Unable to load resolv.conf file "' . $path . '"'); } preg_match_all('/^nameserver\s+(\S+)\s*$/m', $contents, $matches); $config = new self(); $config->nameservers = $matches[1]; return $config; }
php
public static function loadResolvConfBlocking($path = null) { if ($path === null) { $path = '/etc/resolv.conf'; } $contents = @file_get_contents($path); if ($contents === false) { throw new RuntimeException('Unable to load resolv.conf file "' . $path . '"'); } preg_match_all('/^nameserver\s+(\S+)\s*$/m', $contents, $matches); $config = new self(); $config->nameservers = $matches[1]; return $config; }
[ "public", "static", "function", "loadResolvConfBlocking", "(", "$", "path", "=", "null", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "$", "path", "=", "'/etc/resolv.conf'", ";", "}", "$", "contents", "=", "@", "file_get_contents", "(", "$"...
Loads a resolv.conf file (from the given path or default location) Note that this method blocks while loading the given path and should thus be used with care! While this should be relatively fast for normal resolv.conf files, this may be an issue if this file is located on a slow device or contains an excessive number of entries. In particular, this method should only be executed before the loop starts, not while it is running. Note that this method will throw if the given file can not be loaded, such as if it is not readable or does not exist. In particular, this file is not available on Windows. Currently, this will only parse valid "nameserver X" lines from the given file contents. Lines can be commented out with "#" and ";" and invalid lines will be ignored without complaining. See also `man resolv.conf` for more details. Note that the previous section implies that this may return an empty `Config` object if no valid "nameserver X" lines can be found. See also `man resolv.conf` which suggests that the DNS server on the localhost should be used in this case. This is left up to higher level consumers of this API. @param ?string $path (optional) path to resolv.conf file or null=load default location @return self @throws RuntimeException if the path can not be loaded (does not exist)
[ "Loads", "a", "resolv", ".", "conf", "file", "(", "from", "the", "given", "path", "or", "default", "location", ")" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/Config.php#L74-L91
reactphp/dns
src/Config/Config.php
Config.loadWmicBlocking
public static function loadWmicBlocking($command = null) { $contents = shell_exec($command === null ? 'wmic NICCONFIG get "DNSServerSearchOrder" /format:CSV' : $command); preg_match_all('/(?<=[{;,"])([\da-f.:]{4,})(?=[};,"])/i', $contents, $matches); $config = new self(); $config->nameservers = $matches[1]; return $config; }
php
public static function loadWmicBlocking($command = null) { $contents = shell_exec($command === null ? 'wmic NICCONFIG get "DNSServerSearchOrder" /format:CSV' : $command); preg_match_all('/(?<=[{;,"])([\da-f.:]{4,})(?=[};,"])/i', $contents, $matches); $config = new self(); $config->nameservers = $matches[1]; return $config; }
[ "public", "static", "function", "loadWmicBlocking", "(", "$", "command", "=", "null", ")", "{", "$", "contents", "=", "shell_exec", "(", "$", "command", "===", "null", "?", "'wmic NICCONFIG get \"DNSServerSearchOrder\" /format:CSV'", ":", "$", "command", ")", ";",...
Loads the DNS configurations from Windows's WMIC (from the given command or default command) Note that this method blocks while loading the given command and should thus be used with care! While this should be relatively fast for normal WMIC commands, it remains unknown if this may block under certain circumstances. In particular, this method should only be executed before the loop starts, not while it is running. Note that this method will only try to execute the given command try to parse its output, irrespective of whether this command exists. In particular, this command is only available on Windows. Currently, this will only parse valid nameserver entries from the command output and will ignore all other output without complaining. Note that the previous section implies that this may return an empty `Config` object if no valid nameserver entries can be found. @param ?string $command (advanced) should not be given (NULL) unless you know what you're doing @return self @link https://ss64.com/nt/wmic.html
[ "Loads", "the", "DNS", "configurations", "from", "Windows", "s", "WMIC", "(", "from", "the", "given", "command", "or", "default", "command", ")" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Config/Config.php#L115-L124
reactphp/dns
src/Protocol/Parser.php
Parser.parseMessage
public function parseMessage($data) { $message = new Message(); if ($this->parse($data, $message) !== $message) { throw new InvalidArgumentException('Unable to parse binary message'); } return $message; }
php
public function parseMessage($data) { $message = new Message(); if ($this->parse($data, $message) !== $message) { throw new InvalidArgumentException('Unable to parse binary message'); } return $message; }
[ "public", "function", "parseMessage", "(", "$", "data", ")", "{", "$", "message", "=", "new", "Message", "(", ")", ";", "if", "(", "$", "this", "->", "parse", "(", "$", "data", ",", "$", "message", ")", "!==", "$", "message", ")", "{", "throw", "...
Parses the given raw binary message into a Message object @param string $data @throws InvalidArgumentException @return Message
[ "Parses", "the", "given", "raw", "binary", "message", "into", "a", "Message", "object" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Protocol/Parser.php#L23-L31
reactphp/dns
src/Protocol/Parser.php
Parser.parseAnswer
public function parseAnswer(Message $message) { $record = $this->parseRecord($message); if ($record === null) { return null; } $message->answers[] = $record; if ($message->header->get('anCount') != count($message->answers)) { return $this->parseAnswer($message); } return $message; }
php
public function parseAnswer(Message $message) { $record = $this->parseRecord($message); if ($record === null) { return null; } $message->answers[] = $record; if ($message->header->get('anCount') != count($message->answers)) { return $this->parseAnswer($message); } return $message; }
[ "public", "function", "parseAnswer", "(", "Message", "$", "message", ")", "{", "$", "record", "=", "$", "this", "->", "parseRecord", "(", "$", "message", ")", ";", "if", "(", "$", "record", "===", "null", ")", "{", "return", "null", ";", "}", "$", ...
recursively parse all answers from the message data into message answer records @param Message $message @return ?Message returns the updated message on success or null if the data is invalid/incomplete @deprecated unused, exists for BC only @codeCoverageIgnore
[ "recursively", "parse", "all", "answers", "from", "the", "message", "data", "into", "message", "answer", "records" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Protocol/Parser.php#L157-L171
reactphp/dns
src/Query/RecordCache.php
RecordCache.lookup
public function lookup(Query $query) { $id = $this->serializeQueryToIdentity($query); $expiredAt = $this->expiredAt; return $this->cache ->get($id) ->then(function ($value) use ($query, $expiredAt) { // cache 0.5+ resolves with null on cache miss, return explicit cache miss here if ($value === null) { return Promise\reject(); } /* @var $recordBag RecordBag */ $recordBag = unserialize($value); // reject this cache hit if the query was started before the time we expired the cache? // todo: this is a legacy left over, this value is never actually set, so this never applies. // todo: this should probably validate the cache time instead. if (null !== $expiredAt && $expiredAt <= $query->currentTime) { return Promise\reject(); } return $recordBag->all(); }); }
php
public function lookup(Query $query) { $id = $this->serializeQueryToIdentity($query); $expiredAt = $this->expiredAt; return $this->cache ->get($id) ->then(function ($value) use ($query, $expiredAt) { // cache 0.5+ resolves with null on cache miss, return explicit cache miss here if ($value === null) { return Promise\reject(); } /* @var $recordBag RecordBag */ $recordBag = unserialize($value); // reject this cache hit if the query was started before the time we expired the cache? // todo: this is a legacy left over, this value is never actually set, so this never applies. // todo: this should probably validate the cache time instead. if (null !== $expiredAt && $expiredAt <= $query->currentTime) { return Promise\reject(); } return $recordBag->all(); }); }
[ "public", "function", "lookup", "(", "Query", "$", "query", ")", "{", "$", "id", "=", "$", "this", "->", "serializeQueryToIdentity", "(", "$", "query", ")", ";", "$", "expiredAt", "=", "$", "this", "->", "expiredAt", ";", "return", "$", "this", "->", ...
Looks up the cache if there's a cached answer for the given query @param Query $query @return PromiseInterface Promise<Record[],mixed> resolves with array of Record objects on sucess or rejects with mixed values when query is not cached already.
[ "Looks", "up", "the", "cache", "if", "there", "s", "a", "cached", "answer", "for", "the", "given", "query" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Query/RecordCache.php#L31-L57
reactphp/dns
src/Query/RecordCache.php
RecordCache.storeResponseMessage
public function storeResponseMessage($currentTime, Message $message) { foreach ($message->answers as $record) { $this->storeRecord($currentTime, $record); } }
php
public function storeResponseMessage($currentTime, Message $message) { foreach ($message->answers as $record) { $this->storeRecord($currentTime, $record); } }
[ "public", "function", "storeResponseMessage", "(", "$", "currentTime", ",", "Message", "$", "message", ")", "{", "foreach", "(", "$", "message", "->", "answers", "as", "$", "record", ")", "{", "$", "this", "->", "storeRecord", "(", "$", "currentTime", ",",...
Stores all records from this response message in the cache @param int $currentTime @param Message $message @uses self::storeRecord()
[ "Stores", "all", "records", "from", "this", "response", "message", "in", "the", "cache" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Query/RecordCache.php#L66-L71
reactphp/dns
src/Query/RecordCache.php
RecordCache.storeRecord
public function storeRecord($currentTime, Record $record) { $id = $this->serializeRecordToIdentity($record); $cache = $this->cache; $this->cache ->get($id) ->then( function ($value) { if ($value === null) { // cache 0.5+ cache miss resolves with null, return empty bag here return new RecordBag(); } // reuse existing bag on cache hit to append new record to it return unserialize($value); }, function ($e) { // legacy cache < 0.5 cache miss rejects promise, return empty bag here return new RecordBag(); } ) ->then(function (RecordBag $recordBag) use ($id, $currentTime, $record, $cache) { // add a record to the existing (possibly empty) record bag and save to cache $recordBag->set($currentTime, $record); $cache->set($id, serialize($recordBag)); }); }
php
public function storeRecord($currentTime, Record $record) { $id = $this->serializeRecordToIdentity($record); $cache = $this->cache; $this->cache ->get($id) ->then( function ($value) { if ($value === null) { // cache 0.5+ cache miss resolves with null, return empty bag here return new RecordBag(); } // reuse existing bag on cache hit to append new record to it return unserialize($value); }, function ($e) { // legacy cache < 0.5 cache miss rejects promise, return empty bag here return new RecordBag(); } ) ->then(function (RecordBag $recordBag) use ($id, $currentTime, $record, $cache) { // add a record to the existing (possibly empty) record bag and save to cache $recordBag->set($currentTime, $record); $cache->set($id, serialize($recordBag)); }); }
[ "public", "function", "storeRecord", "(", "$", "currentTime", ",", "Record", "$", "record", ")", "{", "$", "id", "=", "$", "this", "->", "serializeRecordToIdentity", "(", "$", "record", ")", ";", "$", "cache", "=", "$", "this", "->", "cache", ";", "$",...
Stores a single record from a response message in the cache @param int $currentTime @param Record $record
[ "Stores", "a", "single", "record", "from", "a", "response", "message", "in", "the", "cache" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Query/RecordCache.php#L79-L107
reactphp/dns
src/Resolver/Resolver.php
Resolver.resolve
public function resolve($domain) { return $this->resolveAll($domain, Message::TYPE_A)->then(function (array $ips) { return $ips[array_rand($ips)]; }); }
php
public function resolve($domain) { return $this->resolveAll($domain, Message::TYPE_A)->then(function (array $ips) { return $ips[array_rand($ips)]; }); }
[ "public", "function", "resolve", "(", "$", "domain", ")", "{", "return", "$", "this", "->", "resolveAll", "(", "$", "domain", ",", "Message", "::", "TYPE_A", ")", "->", "then", "(", "function", "(", "array", "$", "ips", ")", "{", "return", "$", "ips"...
Resolves the given $domain name to a single IPv4 address (type `A` query). ```php $resolver->resolve('reactphp.org')->then(function ($ip) { echo 'IP for reactphp.org is ' . $ip . PHP_EOL; }); ``` This is one of the main methods in this package. It sends a DNS query for the given $domain name to your DNS server and returns a single IP address on success. If the DNS server sends a DNS response message that contains more than one IP address for this query, it will randomly pick one of the IP addresses from the response. If you want the full list of IP addresses or want to send a different type of query, you should use the [`resolveAll()`](#resolveall) method instead. If the DNS server sends a DNS response message that indicates an error code, this method will reject with a `RecordNotFoundException`. Its message and code can be used to check for the response code. If the DNS communication fails and the server does not respond with a valid response message, this message will reject with an `Exception`. Pending DNS queries can be cancelled by cancelling its pending promise like so: ```php $promise = $resolver->resolve('reactphp.org'); $promise->cancel(); ``` @param string $domain @return PromiseInterface Returns a promise which resolves with a single IP address on success or rejects with an Exception on error.
[ "Resolves", "the", "given", "$domain", "name", "to", "a", "single", "IPv4", "address", "(", "type", "A", "query", ")", "." ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Resolver/Resolver.php#L60-L65
reactphp/dns
src/Resolver/Resolver.php
Resolver.resolveAll
public function resolveAll($domain, $type) { $query = new Query($domain, $type, Message::CLASS_IN); $that = $this; return $this->executor->query( $this->nameserver, $query )->then(function (Message $response) use ($query, $that) { return $that->extractValues($query, $response); }); }
php
public function resolveAll($domain, $type) { $query = new Query($domain, $type, Message::CLASS_IN); $that = $this; return $this->executor->query( $this->nameserver, $query )->then(function (Message $response) use ($query, $that) { return $that->extractValues($query, $response); }); }
[ "public", "function", "resolveAll", "(", "$", "domain", ",", "$", "type", ")", "{", "$", "query", "=", "new", "Query", "(", "$", "domain", ",", "$", "type", ",", "Message", "::", "CLASS_IN", ")", ";", "$", "that", "=", "$", "this", ";", "return", ...
Resolves all record values for the given $domain name and query $type. ```php $resolver->resolveAll('reactphp.org', Message::TYPE_A)->then(function ($ips) { echo 'IPv4 addresses for reactphp.org ' . implode(', ', $ips) . PHP_EOL; }); $resolver->resolveAll('reactphp.org', Message::TYPE_AAAA)->then(function ($ips) { echo 'IPv6 addresses for reactphp.org ' . implode(', ', $ips) . PHP_EOL; }); ``` This is one of the main methods in this package. It sends a DNS query for the given $domain name to your DNS server and returns a list with all record values on success. If the DNS server sends a DNS response message that contains one or more records for this query, it will return a list with all record values from the response. You can use the `Message::TYPE_*` constants to control which type of query will be sent. Note that this method always returns a list of record values, but each record value type depends on the query type. For example, it returns the IPv4 addresses for type `A` queries, the IPv6 addresses for type `AAAA` queries, the hostname for type `NS`, `CNAME` and `PTR` queries and structured data for other queries. See also the `Record` documentation for more details. If the DNS server sends a DNS response message that indicates an error code, this method will reject with a `RecordNotFoundException`. Its message and code can be used to check for the response code. If the DNS communication fails and the server does not respond with a valid response message, this message will reject with an `Exception`. Pending DNS queries can be cancelled by cancelling its pending promise like so: ```php $promise = $resolver->resolveAll('reactphp.org', Message::TYPE_AAAA); $promise->cancel(); ``` @param string $domain @return PromiseInterface Returns a promise which resolves with all record values on success or rejects with an Exception on error.
[ "Resolves", "all", "record", "values", "for", "the", "given", "$domain", "name", "and", "query", "$type", "." ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Resolver/Resolver.php#L113-L124
reactphp/dns
src/Resolver/Resolver.php
Resolver.extractValues
public function extractValues(Query $query, Message $response) { // reject if response code indicates this is an error response message $code = $response->getResponseCode(); if ($code !== Message::RCODE_OK) { switch ($code) { case Message::RCODE_FORMAT_ERROR: $message = 'Format Error'; break; case Message::RCODE_SERVER_FAILURE: $message = 'Server Failure'; break; case Message::RCODE_NAME_ERROR: $message = 'Non-Existent Domain / NXDOMAIN'; break; case Message::RCODE_NOT_IMPLEMENTED: $message = 'Not Implemented'; break; case Message::RCODE_REFUSED: $message = 'Refused'; break; default: $message = 'Unknown error response code ' . $code; } throw new RecordNotFoundException( 'DNS query for ' . $query->name . ' returned an error response (' . $message . ')', $code ); } $answers = $response->answers; $addresses = $this->valuesByNameAndType($answers, $query->name, $query->type); // reject if we did not receive a valid answer (domain is valid, but no record for this type could be found) if (0 === count($addresses)) { throw new RecordNotFoundException( 'DNS query for ' . $query->name . ' did not return a valid answer (NOERROR / NODATA)' ); } return array_values($addresses); }
php
public function extractValues(Query $query, Message $response) { // reject if response code indicates this is an error response message $code = $response->getResponseCode(); if ($code !== Message::RCODE_OK) { switch ($code) { case Message::RCODE_FORMAT_ERROR: $message = 'Format Error'; break; case Message::RCODE_SERVER_FAILURE: $message = 'Server Failure'; break; case Message::RCODE_NAME_ERROR: $message = 'Non-Existent Domain / NXDOMAIN'; break; case Message::RCODE_NOT_IMPLEMENTED: $message = 'Not Implemented'; break; case Message::RCODE_REFUSED: $message = 'Refused'; break; default: $message = 'Unknown error response code ' . $code; } throw new RecordNotFoundException( 'DNS query for ' . $query->name . ' returned an error response (' . $message . ')', $code ); } $answers = $response->answers; $addresses = $this->valuesByNameAndType($answers, $query->name, $query->type); // reject if we did not receive a valid answer (domain is valid, but no record for this type could be found) if (0 === count($addresses)) { throw new RecordNotFoundException( 'DNS query for ' . $query->name . ' did not return a valid answer (NOERROR / NODATA)' ); } return array_values($addresses); }
[ "public", "function", "extractValues", "(", "Query", "$", "query", ",", "Message", "$", "response", ")", "{", "// reject if response code indicates this is an error response message", "$", "code", "=", "$", "response", "->", "getResponseCode", "(", ")", ";", "if", "...
[Internal] extract all resource record values from response for this query @param Query $query @param Message $response @return array @throws RecordNotFoundException when response indicates an error or contains no data @internal
[ "[", "Internal", "]", "extract", "all", "resource", "record", "values", "from", "response", "for", "this", "query" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Resolver/Resolver.php#L145-L186
reactphp/dns
src/Resolver/Factory.php
Factory.decorateHostsFileExecutor
private function decorateHostsFileExecutor(ExecutorInterface $executor) { try { $executor = new HostsFileExecutor( HostsFile::loadFromPathBlocking(), $executor ); } catch (\RuntimeException $e) { // ignore this file if it can not be loaded } // Windows does not store localhost in hosts file by default but handles this internally // To compensate for this, we explicitly use hard-coded defaults for localhost if (DIRECTORY_SEPARATOR === '\\') { $executor = new HostsFileExecutor( new HostsFile("127.0.0.1 localhost\n::1 localhost"), $executor ); } return $executor; }
php
private function decorateHostsFileExecutor(ExecutorInterface $executor) { try { $executor = new HostsFileExecutor( HostsFile::loadFromPathBlocking(), $executor ); } catch (\RuntimeException $e) { // ignore this file if it can not be loaded } // Windows does not store localhost in hosts file by default but handles this internally // To compensate for this, we explicitly use hard-coded defaults for localhost if (DIRECTORY_SEPARATOR === '\\') { $executor = new HostsFileExecutor( new HostsFile("127.0.0.1 localhost\n::1 localhost"), $executor ); } return $executor; }
[ "private", "function", "decorateHostsFileExecutor", "(", "ExecutorInterface", "$", "executor", ")", "{", "try", "{", "$", "executor", "=", "new", "HostsFileExecutor", "(", "HostsFile", "::", "loadFromPathBlocking", "(", ")", ",", "$", "executor", ")", ";", "}", ...
Tries to load the hosts file and decorates the given executor on success @param ExecutorInterface $executor @return ExecutorInterface @codeCoverageIgnore
[ "Tries", "to", "load", "the", "hosts", "file", "and", "decorates", "the", "given", "executor", "on", "success" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Resolver/Factory.php#L47-L68
reactphp/dns
src/Model/Message.php
Message.createRequestForQuery
public static function createRequestForQuery(Query $query) { $request = new Message(); $request->header->set('id', self::generateId()); $request->header->set('rd', 1); $request->questions[] = (array) $query; $request->prepare(); return $request; }
php
public static function createRequestForQuery(Query $query) { $request = new Message(); $request->header->set('id', self::generateId()); $request->header->set('rd', 1); $request->questions[] = (array) $query; $request->prepare(); return $request; }
[ "public", "static", "function", "createRequestForQuery", "(", "Query", "$", "query", ")", "{", "$", "request", "=", "new", "Message", "(", ")", ";", "$", "request", "->", "header", "->", "set", "(", "'id'", ",", "self", "::", "generateId", "(", ")", ")...
Creates a new request message for the given query @param Query $query @return self
[ "Creates", "a", "new", "request", "message", "for", "the", "given", "query" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Model/Message.php#L39-L48
reactphp/dns
src/Model/Message.php
Message.createResponseWithAnswersForQuery
public static function createResponseWithAnswersForQuery(Query $query, array $answers) { $response = new Message(); $response->header->set('id', self::generateId()); $response->header->set('qr', 1); $response->header->set('opcode', Message::OPCODE_QUERY); $response->header->set('rd', 1); $response->header->set('rcode', Message::RCODE_OK); $response->questions[] = (array) $query; foreach ($answers as $record) { $response->answers[] = $record; } $response->prepare(); return $response; }
php
public static function createResponseWithAnswersForQuery(Query $query, array $answers) { $response = new Message(); $response->header->set('id', self::generateId()); $response->header->set('qr', 1); $response->header->set('opcode', Message::OPCODE_QUERY); $response->header->set('rd', 1); $response->header->set('rcode', Message::RCODE_OK); $response->questions[] = (array) $query; foreach ($answers as $record) { $response->answers[] = $record; } $response->prepare(); return $response; }
[ "public", "static", "function", "createResponseWithAnswersForQuery", "(", "Query", "$", "query", ",", "array", "$", "answers", ")", "{", "$", "response", "=", "new", "Message", "(", ")", ";", "$", "response", "->", "header", "->", "set", "(", "'id'", ",", ...
Creates a new response message for the given query with the given answer records @param Query $query @param Record[] $answers @return self
[ "Creates", "a", "new", "response", "message", "for", "the", "given", "query", "with", "the", "given", "answer", "records" ]
train
https://github.com/reactphp/dns/blob/2192705bad836cbde13a407d749a95891eca509f/src/Model/Message.php#L57-L75
spiral/framework
src/Module/Publisher.php
Publisher.publish
public function publish( string $filename, string $destination, string $mergeMode = self::FOLLOW, int $mode = FilesInterface::READONLY ) { if (!$this->files->isFile($filename)) { throw new PublishException("Given '{$filename}' is not valid file"); } if ($this->files->exists($destination)) { if ($this->files->md5($destination) == $this->files->md5($filename)) { //Nothing to do return; } if ($mergeMode == self::FOLLOW) { return; } } $this->ensureDirectory(dirname($destination), $mode); echo 1; $this->files->copy($filename, $destination); $this->files->setPermissions($destination, $mode); clearstatcache(); }
php
public function publish( string $filename, string $destination, string $mergeMode = self::FOLLOW, int $mode = FilesInterface::READONLY ) { if (!$this->files->isFile($filename)) { throw new PublishException("Given '{$filename}' is not valid file"); } if ($this->files->exists($destination)) { if ($this->files->md5($destination) == $this->files->md5($filename)) { //Nothing to do return; } if ($mergeMode == self::FOLLOW) { return; } } $this->ensureDirectory(dirname($destination), $mode); echo 1; $this->files->copy($filename, $destination); $this->files->setPermissions($destination, $mode); clearstatcache(); }
[ "public", "function", "publish", "(", "string", "$", "filename", ",", "string", "$", "destination", ",", "string", "$", "mergeMode", "=", "self", "::", "FOLLOW", ",", "int", "$", "mode", "=", "FilesInterface", "::", "READONLY", ")", "{", "if", "(", "!", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Module/Publisher.php#L42-L69
spiral/framework
src/Module/Publisher.php
Publisher.publishDirectory
public function publishDirectory( string $directory, string $destination, string $mergeMode = self::REPLACE, int $mode = FilesInterface::READONLY ) { if (!$this->files->isDirectory($directory)) { throw new PublishException("Given '{$directory}' is not valid directory"); } $finder = new Finder(); $finder->files()->in($directory); /** * @var SplFileInfo $file */ foreach ($finder->getIterator() as $file) { $this->publish( (string)$file, $destination . '/' . $file->getRelativePathname(), $mergeMode, $mode ); } }
php
public function publishDirectory( string $directory, string $destination, string $mergeMode = self::REPLACE, int $mode = FilesInterface::READONLY ) { if (!$this->files->isDirectory($directory)) { throw new PublishException("Given '{$directory}' is not valid directory"); } $finder = new Finder(); $finder->files()->in($directory); /** * @var SplFileInfo $file */ foreach ($finder->getIterator() as $file) { $this->publish( (string)$file, $destination . '/' . $file->getRelativePathname(), $mergeMode, $mode ); } }
[ "public", "function", "publishDirectory", "(", "string", "$", "directory", ",", "string", "$", "destination", ",", "string", "$", "mergeMode", "=", "self", "::", "REPLACE", ",", "int", "$", "mode", "=", "FilesInterface", "::", "READONLY", ")", "{", "if", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Module/Publisher.php#L74-L98
spiral/framework
src/Module/Publisher.php
Publisher.ensureDirectory
public function ensureDirectory(string $directory, int $mode = FilesInterface::READONLY) { $this->files->ensureDirectory($directory, $mode); }
php
public function ensureDirectory(string $directory, int $mode = FilesInterface::READONLY) { $this->files->ensureDirectory($directory, $mode); }
[ "public", "function", "ensureDirectory", "(", "string", "$", "directory", ",", "int", "$", "mode", "=", "FilesInterface", "::", "READONLY", ")", "{", "$", "this", "->", "files", "->", "ensureDirectory", "(", "$", "directory", ",", "$", "mode", ")", ";", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Module/Publisher.php#L103-L106
spiral/framework
src/Http/PaginationFactory.php
PaginationFactory.createPaginator
public function createPaginator(string $parameter, int $limit = 25): PaginatorInterface { if (!$this->container->has(ServerRequestInterface::class)) { throw new ScopeException("Unable to create paginator, no request scope found"); } /** * @var array $query */ $query = $this->container->get(ServerRequestInterface::class)->getQueryParams(); //Getting page number $page = 0; if (!empty($query[$parameter]) && is_scalar($query[$parameter])) { $page = (int)$query[$parameter]; } return $this->factory->make(Paginator::class, compact('limit', 'parameter'))->withPage($page); }
php
public function createPaginator(string $parameter, int $limit = 25): PaginatorInterface { if (!$this->container->has(ServerRequestInterface::class)) { throw new ScopeException("Unable to create paginator, no request scope found"); } /** * @var array $query */ $query = $this->container->get(ServerRequestInterface::class)->getQueryParams(); //Getting page number $page = 0; if (!empty($query[$parameter]) && is_scalar($query[$parameter])) { $page = (int)$query[$parameter]; } return $this->factory->make(Paginator::class, compact('limit', 'parameter'))->withPage($page); }
[ "public", "function", "createPaginator", "(", "string", "$", "parameter", ",", "int", "$", "limit", "=", "25", ")", ":", "PaginatorInterface", "{", "if", "(", "!", "$", "this", "->", "container", "->", "has", "(", "ServerRequestInterface", "::", "class", "...
{@inheritdoc} @throws ScopeException When no request are available.
[ "{", "@inheritdoc", "}" ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Http/PaginationFactory.php#L45-L62
spiral/framework
src/Command/Migrate/MigrateCommand.php
MigrateCommand.perform
public function perform() { if (!$this->verifyConfigured() || !$this->verifyEnvironment()) { return; } $found = false; $count = $this->option('one') ? 1 : PHP_INT_MAX; while ($count > 0 && ($migration = $this->migrator->run())) { $found = true; $count--; $this->sprintf( "<info>Migration <comment>%s</comment> was successfully executed.</info>", $migration->getState()->getName() ); } if (!$found) { $this->writeln("<fg=red>No outstanding migrations were found.</fg=red>"); } }
php
public function perform() { if (!$this->verifyConfigured() || !$this->verifyEnvironment()) { return; } $found = false; $count = $this->option('one') ? 1 : PHP_INT_MAX; while ($count > 0 && ($migration = $this->migrator->run())) { $found = true; $count--; $this->sprintf( "<info>Migration <comment>%s</comment> was successfully executed.</info>", $migration->getState()->getName() ); } if (!$found) { $this->writeln("<fg=red>No outstanding migrations were found.</fg=red>"); } }
[ "public", "function", "perform", "(", ")", "{", "if", "(", "!", "$", "this", "->", "verifyConfigured", "(", ")", "||", "!", "$", "this", "->", "verifyEnvironment", "(", ")", ")", "{", "return", ";", "}", "$", "found", "=", "false", ";", "$", "count...
Execute one or multiple migrations.
[ "Execute", "one", "or", "multiple", "migrations", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Command/Migrate/MigrateCommand.php#L25-L47
spiral/framework
src/Command/Migrate/StatusCommand.php
StatusCommand.perform
public function perform(FilesInterface $files) { if (!$this->verifyConfigured()) { return; } if (empty($this->migrator->getMigrations())) { $this->writeln("<comment>No migrations were found.</comment>"); return; } $table = $this->table(['Migration', 'Filename', 'Created at', 'Executed at']); foreach ($this->migrator->getMigrations() as $migration) { $filename = (new \ReflectionClass($migration))->getFileName(); $state = $migration->getState(); $table->addRow([ $state->getName(), '<comment>' . $files->relativePath($filename, $this->config->getDirectory()) . '</comment>', $state->getTimeCreated()->format('Y-m-d H:i:s'), $state->getStatus() == State::STATUS_PENDING ? self::PENDING : '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>' ]); } $table->render(); }
php
public function perform(FilesInterface $files) { if (!$this->verifyConfigured()) { return; } if (empty($this->migrator->getMigrations())) { $this->writeln("<comment>No migrations were found.</comment>"); return; } $table = $this->table(['Migration', 'Filename', 'Created at', 'Executed at']); foreach ($this->migrator->getMigrations() as $migration) { $filename = (new \ReflectionClass($migration))->getFileName(); $state = $migration->getState(); $table->addRow([ $state->getName(), '<comment>' . $files->relativePath($filename, $this->config->getDirectory()) . '</comment>', $state->getTimeCreated()->format('Y-m-d H:i:s'), $state->getStatus() == State::STATUS_PENDING ? self::PENDING : '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>' ]); } $table->render(); }
[ "public", "function", "perform", "(", "FilesInterface", "$", "files", ")", "{", "if", "(", "!", "$", "this", "->", "verifyConfigured", "(", ")", ")", "{", "return", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "migrator", "->", "getMigrations"...
@param FilesInterface $files @throws \ReflectionException
[ "@param", "FilesInterface", "$files" ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Command/Migrate/StatusCommand.php#L29-L60
spiral/framework
src/Core/Kernel.php
Kernel.mapDirectories
protected function mapDirectories(array $directories): array { if (!isset($directories['root'])) { throw new BootException("Missing required directory `root`."); } if (!isset($directories['app'])) { $directories['app'] = $directories['root'] . '/app/'; } return array_merge([ // public root 'public' => $directories['root'] . '/public/', // vendor libraries 'vendor' => $directories['root'] . '/vendor/', // data directories 'runtime' => $directories['root'] . '/runtime/', 'cache' => $directories['root'] . '/runtime/cache/', // application directories 'config' => $directories['app'] . '/config/', 'resources' => $directories['app'] . '/resources/', ], $directories); }
php
protected function mapDirectories(array $directories): array { if (!isset($directories['root'])) { throw new BootException("Missing required directory `root`."); } if (!isset($directories['app'])) { $directories['app'] = $directories['root'] . '/app/'; } return array_merge([ // public root 'public' => $directories['root'] . '/public/', // vendor libraries 'vendor' => $directories['root'] . '/vendor/', // data directories 'runtime' => $directories['root'] . '/runtime/', 'cache' => $directories['root'] . '/runtime/cache/', // application directories 'config' => $directories['app'] . '/config/', 'resources' => $directories['app'] . '/resources/', ], $directories); }
[ "protected", "function", "mapDirectories", "(", "array", "$", "directories", ")", ":", "array", "{", "if", "(", "!", "isset", "(", "$", "directories", "[", "'root'", "]", ")", ")", "{", "throw", "new", "BootException", "(", "\"Missing required directory `root`...
Normalizes directory list and adds all required aliases. @param array $directories @return array
[ "Normalizes", "directory", "list", "and", "adds", "all", "required", "aliases", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Core/Kernel.php#L66-L91
spiral/framework
src/Command/Migrate/AbstractCommand.php
AbstractCommand.verifyEnvironment
protected function verifyEnvironment(): bool { if ($this->option('force') || $this->config->isSafe()) { //Safe to run return true; } $this->writeln("<fg=red>Confirmation is required to run migrations!</fg=red>"); if (!$this->askConfirmation()) { $this->writeln("<comment>Cancelling operation...</comment>"); return false; } return true; }
php
protected function verifyEnvironment(): bool { if ($this->option('force') || $this->config->isSafe()) { //Safe to run return true; } $this->writeln("<fg=red>Confirmation is required to run migrations!</fg=red>"); if (!$this->askConfirmation()) { $this->writeln("<comment>Cancelling operation...</comment>"); return false; } return true; }
[ "protected", "function", "verifyEnvironment", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "option", "(", "'force'", ")", "||", "$", "this", "->", "config", "->", "isSafe", "(", ")", ")", "{", "//Safe to run", "return", "true", ";", "}", ...
Check if current environment is safe to run migration. @return bool
[ "Check", "if", "current", "environment", "is", "safe", "to", "run", "migration", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Command/Migrate/AbstractCommand.php#L60-L76
spiral/framework
src/Console/Logger/DebugListener.php
DebugListener.withOutput
public function withOutput(OutputInterface $output): self { $listener = clone $this; $listener->output = $output; return $listener; }
php
public function withOutput(OutputInterface $output): self { $listener = clone $this; $listener->output = $output; return $listener; }
[ "public", "function", "withOutput", "(", "OutputInterface", "$", "output", ")", ":", "self", "{", "$", "listener", "=", "clone", "$", "this", ";", "$", "listener", "->", "output", "=", "$", "output", ";", "return", "$", "listener", ";", "}" ]
Configure listener with new output. @param OutputInterface $output @return DebugListener
[ "Configure", "listener", "with", "new", "output", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Console/Logger/DebugListener.php#L77-L83
spiral/framework
src/Console/Logger/DebugListener.php
DebugListener.enable
public function enable(): self { if (!empty($this->logs)) { $this->logs->addListener($this); } return $this; }
php
public function enable(): self { if (!empty($this->logs)) { $this->logs->addListener($this); } return $this; }
[ "public", "function", "enable", "(", ")", ":", "self", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "logs", ")", ")", "{", "$", "this", "->", "logs", "->", "addListener", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}"...
Enable logging in console mode. @return DebugListener
[ "Enable", "logging", "in", "console", "mode", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Console/Logger/DebugListener.php#L90-L97
spiral/framework
src/Console/Logger/DebugListener.php
DebugListener.disable
public function disable(): self { if (!empty($this->logs)) { $this->logs->removeListener($this); } return $this; }
php
public function disable(): self { if (!empty($this->logs)) { $this->logs->removeListener($this); } return $this; }
[ "public", "function", "disable", "(", ")", ":", "self", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "logs", ")", ")", "{", "$", "this", "->", "logs", "->", "removeListener", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", ...
Disable displaying logs in console. @return DebugListener
[ "Disable", "displaying", "logs", "in", "console", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Console/Logger/DebugListener.php#L104-L111
spiral/framework
src/Http/Middleware/SessionMiddleware.php
SessionMiddleware.fetchID
protected function fetchID(Request $request): ?string { $cookies = $request->getCookieParams(); if (empty($cookies[$this->config->getCookie()])) { return null; } return $cookies[$this->config->getCookie()]; }
php
protected function fetchID(Request $request): ?string { $cookies = $request->getCookieParams(); if (empty($cookies[$this->config->getCookie()])) { return null; } return $cookies[$this->config->getCookie()]; }
[ "protected", "function", "fetchID", "(", "Request", "$", "request", ")", ":", "?", "string", "{", "$", "cookies", "=", "$", "request", "->", "getCookieParams", "(", ")", ";", "if", "(", "empty", "(", "$", "cookies", "[", "$", "this", "->", "config", ...
Attempt to locate session ID in request. @param Request $request @return string|null
[ "Attempt", "to", "locate", "session", "ID", "in", "request", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Http/Middleware/SessionMiddleware.php#L120-L128
spiral/framework
src/Http/Middleware/SessionMiddleware.php
SessionMiddleware.clientSignature
protected function clientSignature(Request $request): string { $signature = ''; foreach (static::SIGNATURE_HEADERS as $header) { $signature .= $request->getHeaderLine($header) . ';'; } return hash('sha256', $signature); }
php
protected function clientSignature(Request $request): string { $signature = ''; foreach (static::SIGNATURE_HEADERS as $header) { $signature .= $request->getHeaderLine($header) . ';'; } return hash('sha256', $signature); }
[ "protected", "function", "clientSignature", "(", "Request", "$", "request", ")", ":", "string", "{", "$", "signature", "=", "''", ";", "foreach", "(", "static", "::", "SIGNATURE_HEADERS", "as", "$", "header", ")", "{", "$", "signature", ".=", "$", "request...
Must return string which identifies client on other end. Not for security check but for session fixation. @param Request $request @return string
[ "Must", "return", "string", "which", "identifies", "client", "on", "other", "end", ".", "Not", "for", "security", "check", "but", "for", "session", "fixation", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Http/Middleware/SessionMiddleware.php#L153-L161
spiral/framework
src/Http/Middleware/SessionMiddleware.php
SessionMiddleware.sessionCookie
private function sessionCookie(UriInterface $uri, string $id = null): Cookie { return Cookie::create( $this->config->getCookie(), $id, $this->config->getLifetime(), $this->httpConfig->basePath(), $this->httpConfig->cookieDomain($uri), $this->config->isSecure(), true ); }
php
private function sessionCookie(UriInterface $uri, string $id = null): Cookie { return Cookie::create( $this->config->getCookie(), $id, $this->config->getLifetime(), $this->httpConfig->basePath(), $this->httpConfig->cookieDomain($uri), $this->config->isSecure(), true ); }
[ "private", "function", "sessionCookie", "(", "UriInterface", "$", "uri", ",", "string", "$", "id", "=", "null", ")", ":", "Cookie", "{", "return", "Cookie", "::", "create", "(", "$", "this", "->", "config", "->", "getCookie", "(", ")", ",", "$", "id", ...
Generate session cookie. @param UriInterface $uri Incoming uri. @param string|null $id @return Cookie
[ "Generate", "session", "cookie", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Http/Middleware/SessionMiddleware.php#L170-L181
spiral/framework
src/Snapshots/FileSnapshotter.php
FileSnapshotter.rotateSnapshots
protected function rotateSnapshots() { $finder = new Finder(); $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) { return $b->getMTime() - $a->getMTime(); }); $count = 0; foreach ($finder as $file) { $count++; if ($count > $this->maxFiles) { try { $this->files->delete($file->getRealPath()); } catch (FilesException $e) { // ignore } } } }
php
protected function rotateSnapshots() { $finder = new Finder(); $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) { return $b->getMTime() - $a->getMTime(); }); $count = 0; foreach ($finder as $file) { $count++; if ($count > $this->maxFiles) { try { $this->files->delete($file->getRealPath()); } catch (FilesException $e) { // ignore } } } }
[ "protected", "function", "rotateSnapshots", "(", ")", "{", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "finder", "->", "in", "(", "$", "this", "->", "directory", ")", "->", "sort", "(", "function", "(", "SplFileInfo", "$", "a", ",", "Spl...
Remove older snapshots.
[ "Remove", "older", "snapshots", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Snapshots/FileSnapshotter.php#L92-L110
spiral/framework
src/Bootloader/Http/SessionBootloader.php
SessionBootloader.boot
public function boot( ConfiguratorInterface $config, HttpBootloader $http, DirectoriesInterface $directories ) { $config->setDefaults('session', [ 'lifetime' => 86400, 'cookie' => 'sid', 'secure' => false, 'handler' => new Autowire(FileHandler::class, [ 'directory' => $directories->get('runtime') . 'session', 'lifetime' => 86400 ] ) ]); $session = $config->getConfig('session'); $http->whitelistCookie($session['cookie']); $http->addMiddleware(SessionMiddleware::class); }
php
public function boot( ConfiguratorInterface $config, HttpBootloader $http, DirectoriesInterface $directories ) { $config->setDefaults('session', [ 'lifetime' => 86400, 'cookie' => 'sid', 'secure' => false, 'handler' => new Autowire(FileHandler::class, [ 'directory' => $directories->get('runtime') . 'session', 'lifetime' => 86400 ] ) ]); $session = $config->getConfig('session'); $http->whitelistCookie($session['cookie']); $http->addMiddleware(SessionMiddleware::class); }
[ "public", "function", "boot", "(", "ConfiguratorInterface", "$", "config", ",", "HttpBootloader", "$", "http", ",", "DirectoriesInterface", "$", "directories", ")", "{", "$", "config", "->", "setDefaults", "(", "'session'", ",", "[", "'lifetime'", "=>", "86400",...
Automatically registers session starter middleware and excludes session cookie from cookie protection. @param ConfiguratorInterface $config @param HttpBootloader $http @param DirectoriesInterface $directories
[ "Automatically", "registers", "session", "starter", "middleware", "and", "excludes", "session", "cookie", "from", "cookie", "protection", "." ]
train
https://github.com/spiral/framework/blob/cd425681c470ddaec43d3ca32028132475738317/src/Bootloader/Http/SessionBootloader.php#L36-L56