repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
boomcms/boom-core
src/BoomCMS/Theme/ThemeManager.php
ThemeManager.findAndInstallThemes
public function findAndInstallThemes(): array { $theme = new Theme(); $directories = $this->filesystem->directories($theme->getThemesDirectory()); $themes = []; if (is_array($directories)) { foreach ($directories as $directory) { $themeName = basename($directory); $themes[] = new Theme($themeName); } } $this->cache->forever($this->cacheKey, $themes); return $themes; }
php
public function findAndInstallThemes(): array { $theme = new Theme(); $directories = $this->filesystem->directories($theme->getThemesDirectory()); $themes = []; if (is_array($directories)) { foreach ($directories as $directory) { $themeName = basename($directory); $themes[] = new Theme($themeName); } } $this->cache->forever($this->cacheKey, $themes); return $themes; }
[ "public", "function", "findAndInstallThemes", "(", ")", ":", "array", "{", "$", "theme", "=", "new", "Theme", "(", ")", ";", "$", "directories", "=", "$", "this", "->", "filesystem", "->", "directories", "(", "$", "theme", "->", "getThemesDirectory", "(", ")", ")", ";", "$", "themes", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "directories", ")", ")", "{", "foreach", "(", "$", "directories", "as", "$", "directory", ")", "{", "$", "themeName", "=", "basename", "(", "$", "directory", ")", ";", "$", "themes", "[", "]", "=", "new", "Theme", "(", "$", "themeName", ")", ";", "}", "}", "$", "this", "->", "cache", "->", "forever", "(", "$", "this", "->", "cacheKey", ",", "$", "themes", ")", ";", "return", "$", "themes", ";", "}" ]
Create a cache of the themes which are available on the filesystem.
[ "Create", "a", "cache", "of", "the", "themes", "which", "are", "available", "on", "the", "filesystem", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Theme/ThemeManager.php#L85-L101
train
boomcms/boom-core
src/BoomCMS/Theme/ThemeManager.php
ThemeManager.getInstalledThemes
public function getInstalledThemes(): array { $installed = $this->cache->get($this->cacheKey); if ($installed !== null) { return $installed; } return $this->findAndInstallThemes(); }
php
public function getInstalledThemes(): array { $installed = $this->cache->get($this->cacheKey); if ($installed !== null) { return $installed; } return $this->findAndInstallThemes(); }
[ "public", "function", "getInstalledThemes", "(", ")", ":", "array", "{", "$", "installed", "=", "$", "this", "->", "cache", "->", "get", "(", "$", "this", "->", "cacheKey", ")", ";", "if", "(", "$", "installed", "!==", "null", ")", "{", "return", "$", "installed", ";", "}", "return", "$", "this", "->", "findAndInstallThemes", "(", ")", ";", "}" ]
Retrieves the installed themes from the cache. If the cache entry doesn't exist then it is created.
[ "Retrieves", "the", "installed", "themes", "from", "the", "cache", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Theme/ThemeManager.php#L108-L117
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Asset/AssetController.php
AssetController.createFromBlob
public function createFromBlob(Request $request, Site $site): array { $this->authorize('uploadAssets', $site); $file = $request->file('file'); $error = $this->validateFile($file); if ($error !== true) { return []; } $description = trans('boomcms::asset.automatic-upload-description', [ 'url' => $request->input('url'), ]); $asset = AssetFacade::createFromFile($file); $asset->setDescription($description); AssetFacade::save($asset); $album = AlbumFacade::findOrCreate('Text editor uploads'); $album->addAssets([$asset->getId()]); return [ 'location' => route('asset', ['asset' => $asset]), ]; }
php
public function createFromBlob(Request $request, Site $site): array { $this->authorize('uploadAssets', $site); $file = $request->file('file'); $error = $this->validateFile($file); if ($error !== true) { return []; } $description = trans('boomcms::asset.automatic-upload-description', [ 'url' => $request->input('url'), ]); $asset = AssetFacade::createFromFile($file); $asset->setDescription($description); AssetFacade::save($asset); $album = AlbumFacade::findOrCreate('Text editor uploads'); $album->addAssets([$asset->getId()]); return [ 'location' => route('asset', ['asset' => $asset]), ]; }
[ "public", "function", "createFromBlob", "(", "Request", "$", "request", ",", "Site", "$", "site", ")", ":", "array", "{", "$", "this", "->", "authorize", "(", "'uploadAssets'", ",", "$", "site", ")", ";", "$", "file", "=", "$", "request", "->", "file", "(", "'file'", ")", ";", "$", "error", "=", "$", "this", "->", "validateFile", "(", "$", "file", ")", ";", "if", "(", "$", "error", "!==", "true", ")", "{", "return", "[", "]", ";", "}", "$", "description", "=", "trans", "(", "'boomcms::asset.automatic-upload-description'", ",", "[", "'url'", "=>", "$", "request", "->", "input", "(", "'url'", ")", ",", "]", ")", ";", "$", "asset", "=", "AssetFacade", "::", "createFromFile", "(", "$", "file", ")", ";", "$", "asset", "->", "setDescription", "(", "$", "description", ")", ";", "AssetFacade", "::", "save", "(", "$", "asset", ")", ";", "$", "album", "=", "AlbumFacade", "::", "findOrCreate", "(", "'Text editor uploads'", ")", ";", "$", "album", "->", "addAssets", "(", "[", "$", "asset", "->", "getId", "(", ")", "]", ")", ";", "return", "[", "'location'", "=>", "route", "(", "'asset'", ",", "[", "'asset'", "=>", "$", "asset", "]", ")", ",", "]", ";", "}" ]
Controller for handling a single file upload from TinyMCE. @see https://www.tinymce.com/docs/configure/file-image-upload/#automatic_uploads @param Request $request @return array
[ "Controller", "for", "handling", "a", "single", "file", "upload", "from", "TinyMCE", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Asset/AssetController.php#L30-L55
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Asset/AssetController.php
AssetController.download
public function download(Asset $asset) { return Response::file(AssetFacade::path($asset), [ 'Content-Type' => $asset->getMimetype(), 'Content-Disposition' => 'download; filename="'.$asset->getOriginalFilename().'"', ]); }
php
public function download(Asset $asset) { return Response::file(AssetFacade::path($asset), [ 'Content-Type' => $asset->getMimetype(), 'Content-Disposition' => 'download; filename="'.$asset->getOriginalFilename().'"', ]); }
[ "public", "function", "download", "(", "Asset", "$", "asset", ")", "{", "return", "Response", "::", "file", "(", "AssetFacade", "::", "path", "(", "$", "asset", ")", ",", "[", "'Content-Type'", "=>", "$", "asset", "->", "getMimetype", "(", ")", ",", "'Content-Disposition'", "=>", "'download; filename=\"'", ".", "$", "asset", "->", "getOriginalFilename", "(", ")", ".", "'\"'", ",", "]", ")", ";", "}" ]
Download the given asset. @param Asset $asset
[ "Download", "the", "given", "asset", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Asset/AssetController.php#L72-L78
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Asset/AssetController.php
AssetController.embed
public function embed(Request $request, Asset $asset): View { $viewPrefix = 'boomcms::assets.embed.'; $assetType = strtolower(class_basename($asset->getType())); $viewName = $viewPrefix.$assetType; if (!view()->exists($viewName)) { $viewName = $viewPrefix.'default'; } return view()->make($viewName, [ 'asset' => $asset, 'height' => $request->input('height'), 'width' => $request->input('width'), ]); }
php
public function embed(Request $request, Asset $asset): View { $viewPrefix = 'boomcms::assets.embed.'; $assetType = strtolower(class_basename($asset->getType())); $viewName = $viewPrefix.$assetType; if (!view()->exists($viewName)) { $viewName = $viewPrefix.'default'; } return view()->make($viewName, [ 'asset' => $asset, 'height' => $request->input('height'), 'width' => $request->input('width'), ]); }
[ "public", "function", "embed", "(", "Request", "$", "request", ",", "Asset", "$", "asset", ")", ":", "View", "{", "$", "viewPrefix", "=", "'boomcms::assets.embed.'", ";", "$", "assetType", "=", "strtolower", "(", "class_basename", "(", "$", "asset", "->", "getType", "(", ")", ")", ")", ";", "$", "viewName", "=", "$", "viewPrefix", ".", "$", "assetType", ";", "if", "(", "!", "view", "(", ")", "->", "exists", "(", "$", "viewName", ")", ")", "{", "$", "viewName", "=", "$", "viewPrefix", ".", "'default'", ";", "}", "return", "view", "(", ")", "->", "make", "(", "$", "viewName", ",", "[", "'asset'", "=>", "$", "asset", ",", "'height'", "=>", "$", "request", "->", "input", "(", "'height'", ")", ",", "'width'", "=>", "$", "request", "->", "input", "(", "'width'", ")", ",", "]", ")", ";", "}" ]
Returns the HTML to embed the given asset. @param Request $request @param Asset $asset @return View
[ "Returns", "the", "HTML", "to", "embed", "the", "given", "asset", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Asset/AssetController.php#L88-L103
train
boomcms/boom-core
src/BoomCMS/FileInfo/Drivers/Svg.php
Svg.getXmlAttrs
protected function getXmlAttrs() { if ($this->xmlAttrs === null) { $xml = simplexml_load_file($this->file->getPathname()); $this->xmlAttrs = $xml->attributes(); } return $this->xmlAttrs; }
php
protected function getXmlAttrs() { if ($this->xmlAttrs === null) { $xml = simplexml_load_file($this->file->getPathname()); $this->xmlAttrs = $xml->attributes(); } return $this->xmlAttrs; }
[ "protected", "function", "getXmlAttrs", "(", ")", "{", "if", "(", "$", "this", "->", "xmlAttrs", "===", "null", ")", "{", "$", "xml", "=", "simplexml_load_file", "(", "$", "this", "->", "file", "->", "getPathname", "(", ")", ")", ";", "$", "this", "->", "xmlAttrs", "=", "$", "xml", "->", "attributes", "(", ")", ";", "}", "return", "$", "this", "->", "xmlAttrs", ";", "}" ]
Reads the SVG file and returns the XML attributes as an object. @return object
[ "Reads", "the", "SVG", "file", "and", "returns", "the", "XML", "attributes", "as", "an", "object", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/FileInfo/Drivers/Svg.php#L54-L62
train
markstory/mini-asset
src/Filter/CssCompressor.php
CssCompressor.output
public function output($filename, $input) { $env = array('NODE_PATH' => $this->_settings['node_path']); $tmpfile = tempnam(sys_get_temp_dir(), 'miniasset_css_compressor'); $this->generateScript($tmpfile, $input); $cmd = $this->_settings['node'] . ' ' . $tmpfile; return $this->_runCmd($cmd, '', $env); }
php
public function output($filename, $input) { $env = array('NODE_PATH' => $this->_settings['node_path']); $tmpfile = tempnam(sys_get_temp_dir(), 'miniasset_css_compressor'); $this->generateScript($tmpfile, $input); $cmd = $this->_settings['node'] . ' ' . $tmpfile; return $this->_runCmd($cmd, '', $env); }
[ "public", "function", "output", "(", "$", "filename", ",", "$", "input", ")", "{", "$", "env", "=", "array", "(", "'NODE_PATH'", "=>", "$", "this", "->", "_settings", "[", "'node_path'", "]", ")", ";", "$", "tmpfile", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'miniasset_css_compressor'", ")", ";", "$", "this", "->", "generateScript", "(", "$", "tmpfile", ",", "$", "input", ")", ";", "$", "cmd", "=", "$", "this", "->", "_settings", "[", "'node'", "]", ".", "' '", ".", "$", "tmpfile", ";", "return", "$", "this", "->", "_runCmd", "(", "$", "cmd", ",", "''", ",", "$", "env", ")", ";", "}" ]
Run `cleancss` against the output and compress it. @param string $filename Name of the file being generated. @param string $input The uncompressed contents for $filename. @return string Compressed contents.
[ "Run", "cleancss", "against", "the", "output", "and", "compress", "it", "." ]
5564bcbe2749a28d7978d36362c390bce39083a3
https://github.com/markstory/mini-asset/blob/5564bcbe2749a28d7978d36362c390bce39083a3/src/Filter/CssCompressor.php#L28-L37
train
markstory/mini-asset
src/Filter/CssCompressor.php
CssCompressor.generateScript
protected function generateScript($file, $input) { $script = <<<JS var csscompressor = require('css-compressor'); var util = require('util'); var source = %s; util.print(csscompressor.cssmin(source)); process.exit(0); JS; file_put_contents($file, sprintf($script, json_encode($input))); }
php
protected function generateScript($file, $input) { $script = <<<JS var csscompressor = require('css-compressor'); var util = require('util'); var source = %s; util.print(csscompressor.cssmin(source)); process.exit(0); JS; file_put_contents($file, sprintf($script, json_encode($input))); }
[ "protected", "function", "generateScript", "(", "$", "file", ",", "$", "input", ")", "{", "$", "script", "=", " <<<JS\nvar csscompressor = require('css-compressor');\nvar util = require('util');\n\nvar source = %s;\nutil.print(csscompressor.cssmin(source));\n\nprocess.exit(0);\nJS", ";", "file_put_contents", "(", "$", "file", ",", "sprintf", "(", "$", "script", ",", "json_encode", "(", "$", "input", ")", ")", ")", ";", "}" ]
Generates a small bit of Javascript code to invoke cleancss with.
[ "Generates", "a", "small", "bit", "of", "Javascript", "code", "to", "invoke", "cleancss", "with", "." ]
5564bcbe2749a28d7978d36362c390bce39083a3
https://github.com/markstory/mini-asset/blob/5564bcbe2749a28d7978d36362c390bce39083a3/src/Filter/CssCompressor.php#L42-L54
train
markstory/mini-asset
src/Utility/CssUtils.php
CssUtils.extractImports
public static function extractImports($css) { $imports = []; preg_match_all(static::IMPORT_PATTERN, $css, $matches, PREG_SET_ORDER); if (empty($matches)) { return $imports; } foreach ($matches as $match) { $url = empty($match[2]) ? $match[4] : $match[2]; $imports[] = $url; } return $imports; }
php
public static function extractImports($css) { $imports = []; preg_match_all(static::IMPORT_PATTERN, $css, $matches, PREG_SET_ORDER); if (empty($matches)) { return $imports; } foreach ($matches as $match) { $url = empty($match[2]) ? $match[4] : $match[2]; $imports[] = $url; } return $imports; }
[ "public", "static", "function", "extractImports", "(", "$", "css", ")", "{", "$", "imports", "=", "[", "]", ";", "preg_match_all", "(", "static", "::", "IMPORT_PATTERN", ",", "$", "css", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ";", "if", "(", "empty", "(", "$", "matches", ")", ")", "{", "return", "$", "imports", ";", "}", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "$", "url", "=", "empty", "(", "$", "match", "[", "2", "]", ")", "?", "$", "match", "[", "4", "]", ":", "$", "match", "[", "2", "]", ";", "$", "imports", "[", "]", "=", "$", "url", ";", "}", "return", "$", "imports", ";", "}" ]
Extract the urls in import directives. @param string $css The CSS to parse. @return array An array of CSS files that were used in imports.
[ "Extract", "the", "urls", "in", "import", "directives", "." ]
5564bcbe2749a28d7978d36362c390bce39083a3
https://github.com/markstory/mini-asset/blob/5564bcbe2749a28d7978d36362c390bce39083a3/src/Utility/CssUtils.php#L29-L41
train
boomcms/boom-core
src/BoomCMS/FileInfo/Drivers/Word.php
Word.readMetadata
protected function readMetadata(): array { try { $phpWord = IOFactory::load($this->file->getPathname()); $docinfo = $phpWord->getDocInfo(); $attrs = [ 'creator' => $docinfo->getCreator(), 'created' => $docinfo->getCreated(), 'lastModifiedBy' => $docinfo->getLastModifiedBy(), 'modified' => $docinfo->getModified(), 'title' => $docinfo->getTitle(), 'description' => $docinfo->getDescription(), 'subject' => $docinfo->getSubject(), 'keywords' => $docinfo->getKeywords(), 'category' => $docinfo->getCategory(), 'company' => $docinfo->getCompany(), 'manager' => $docinfo->getManager(), ]; foreach ($attrs as $key => $value) { if (empty($value)) { unset($attrs[$key]); } } return $attrs; } catch (Exception $e) { return []; } }
php
protected function readMetadata(): array { try { $phpWord = IOFactory::load($this->file->getPathname()); $docinfo = $phpWord->getDocInfo(); $attrs = [ 'creator' => $docinfo->getCreator(), 'created' => $docinfo->getCreated(), 'lastModifiedBy' => $docinfo->getLastModifiedBy(), 'modified' => $docinfo->getModified(), 'title' => $docinfo->getTitle(), 'description' => $docinfo->getDescription(), 'subject' => $docinfo->getSubject(), 'keywords' => $docinfo->getKeywords(), 'category' => $docinfo->getCategory(), 'company' => $docinfo->getCompany(), 'manager' => $docinfo->getManager(), ]; foreach ($attrs as $key => $value) { if (empty($value)) { unset($attrs[$key]); } } return $attrs; } catch (Exception $e) { return []; } }
[ "protected", "function", "readMetadata", "(", ")", ":", "array", "{", "try", "{", "$", "phpWord", "=", "IOFactory", "::", "load", "(", "$", "this", "->", "file", "->", "getPathname", "(", ")", ")", ";", "$", "docinfo", "=", "$", "phpWord", "->", "getDocInfo", "(", ")", ";", "$", "attrs", "=", "[", "'creator'", "=>", "$", "docinfo", "->", "getCreator", "(", ")", ",", "'created'", "=>", "$", "docinfo", "->", "getCreated", "(", ")", ",", "'lastModifiedBy'", "=>", "$", "docinfo", "->", "getLastModifiedBy", "(", ")", ",", "'modified'", "=>", "$", "docinfo", "->", "getModified", "(", ")", ",", "'title'", "=>", "$", "docinfo", "->", "getTitle", "(", ")", ",", "'description'", "=>", "$", "docinfo", "->", "getDescription", "(", ")", ",", "'subject'", "=>", "$", "docinfo", "->", "getSubject", "(", ")", ",", "'keywords'", "=>", "$", "docinfo", "->", "getKeywords", "(", ")", ",", "'category'", "=>", "$", "docinfo", "->", "getCategory", "(", ")", ",", "'company'", "=>", "$", "docinfo", "->", "getCompany", "(", ")", ",", "'manager'", "=>", "$", "docinfo", "->", "getManager", "(", ")", ",", "]", ";", "foreach", "(", "$", "attrs", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "unset", "(", "$", "attrs", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "attrs", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "[", "]", ";", "}", "}" ]
Retrieves metadata from the file and turns it into an array. @return array
[ "Retrieves", "metadata", "from", "the", "file", "and", "turns", "it", "into", "an", "array", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/FileInfo/Drivers/Word.php#L44-L74
train
boomcms/boom-core
src/BoomCMS/Editor/Editor.php
Editor.getTime
public function getTime() { // Time should only be used with the history state. if (!$this->isHistory()) { return new DateTime('now'); } $timestamp = $this->session->get($this->timePersistenceKey, time()); return (new DateTime())->setTimestamp($timestamp); }
php
public function getTime() { // Time should only be used with the history state. if (!$this->isHistory()) { return new DateTime('now'); } $timestamp = $this->session->get($this->timePersistenceKey, time()); return (new DateTime())->setTimestamp($timestamp); }
[ "public", "function", "getTime", "(", ")", "{", "// Time should only be used with the history state.", "if", "(", "!", "$", "this", "->", "isHistory", "(", ")", ")", "{", "return", "new", "DateTime", "(", "'now'", ")", ";", "}", "$", "timestamp", "=", "$", "this", "->", "session", "->", "get", "(", "$", "this", "->", "timePersistenceKey", ",", "time", "(", ")", ")", ";", "return", "(", "new", "DateTime", "(", ")", ")", "->", "setTimestamp", "(", "$", "timestamp", ")", ";", "}" ]
Get the time to view pages at. @return DateTime
[ "Get", "the", "time", "to", "view", "pages", "at", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Editor/Editor.php#L81-L91
train
boomcms/boom-core
src/BoomCMS/Editor/Editor.php
Editor.setTime
public function setTime(DateTime $time = null) { $timestamp = $time ? $time->getTimestamp() : null; $this->session->put($this->timePersistenceKey, $timestamp); if ($time) { $this->setState(static::HISTORY); } return $this; }
php
public function setTime(DateTime $time = null) { $timestamp = $time ? $time->getTimestamp() : null; $this->session->put($this->timePersistenceKey, $timestamp); if ($time) { $this->setState(static::HISTORY); } return $this; }
[ "public", "function", "setTime", "(", "DateTime", "$", "time", "=", "null", ")", "{", "$", "timestamp", "=", "$", "time", "?", "$", "time", "->", "getTimestamp", "(", ")", ":", "null", ";", "$", "this", "->", "session", "->", "put", "(", "$", "this", "->", "timePersistenceKey", ",", "$", "timestamp", ")", ";", "if", "(", "$", "time", ")", "{", "$", "this", "->", "setState", "(", "static", "::", "HISTORY", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set a time at which to view pages at. @param DateTime $time @return $this
[ "Set", "a", "time", "at", "which", "to", "view", "pages", "at", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Editor/Editor.php#L182-L193
train
boomcms/boom-core
src/BoomCMS/Support/Str.php
Str.filesize
public static function filesize($bytes) { $precision = (($bytes % 1024) === 0 || $bytes <= 1024) ? 0 : 1; $formatter = new ByteSize\Formatter\Binary(); $formatter->setPrecision($precision); return $formatter->format($bytes); }
php
public static function filesize($bytes) { $precision = (($bytes % 1024) === 0 || $bytes <= 1024) ? 0 : 1; $formatter = new ByteSize\Formatter\Binary(); $formatter->setPrecision($precision); return $formatter->format($bytes); }
[ "public", "static", "function", "filesize", "(", "$", "bytes", ")", "{", "$", "precision", "=", "(", "(", "$", "bytes", "%", "1024", ")", "===", "0", "||", "$", "bytes", "<=", "1024", ")", "?", "0", ":", "1", ";", "$", "formatter", "=", "new", "ByteSize", "\\", "Formatter", "\\", "Binary", "(", ")", ";", "$", "formatter", "->", "setPrecision", "(", "$", "precision", ")", ";", "return", "$", "formatter", "->", "format", "(", "$", "bytes", ")", ";", "}" ]
Turn a number of bytes into a human friendly filesize. @param int $bytes @return string
[ "Turn", "a", "number", "of", "bytes", "into", "a", "human", "friendly", "filesize", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Support/Str.php#L27-L35
train
boomcms/boom-core
src/BoomCMS/Support/Str.php
Str.nl2paragraph
public static function nl2paragraph($text) { $paragraphs = explode("\n", $text); foreach ($paragraphs as &$paragraph) { $paragraph = "<p>$paragraph</p>"; } return implode('', $paragraphs); }
php
public static function nl2paragraph($text) { $paragraphs = explode("\n", $text); foreach ($paragraphs as &$paragraph) { $paragraph = "<p>$paragraph</p>"; } return implode('', $paragraphs); }
[ "public", "static", "function", "nl2paragraph", "(", "$", "text", ")", "{", "$", "paragraphs", "=", "explode", "(", "\"\\n\"", ",", "$", "text", ")", ";", "foreach", "(", "$", "paragraphs", "as", "&", "$", "paragraph", ")", "{", "$", "paragraph", "=", "\"<p>$paragraph</p>\"", ";", "}", "return", "implode", "(", "''", ",", "$", "paragraphs", ")", ";", "}" ]
Adds paragraph HTML tags to text treating each new line as a paragraph break. @param string $text @return string
[ "Adds", "paragraph", "HTML", "tags", "to", "text", "treating", "each", "new", "line", "as", "a", "paragraph", "break", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Support/Str.php#L78-L87
train
boomcms/boom-core
src/BoomCMS/Support/Str.php
Str.unique
public static function unique($initial, Closure $closure) { $append = 0; do { $string = ($append > 0) ? ($initial.$append) : $initial; $append++; } while ($closure($string) === false); return $string; }
php
public static function unique($initial, Closure $closure) { $append = 0; do { $string = ($append > 0) ? ($initial.$append) : $initial; $append++; } while ($closure($string) === false); return $string; }
[ "public", "static", "function", "unique", "(", "$", "initial", ",", "Closure", "$", "closure", ")", "{", "$", "append", "=", "0", ";", "do", "{", "$", "string", "=", "(", "$", "append", ">", "0", ")", "?", "(", "$", "initial", ".", "$", "append", ")", ":", "$", "initial", ";", "$", "append", "++", ";", "}", "while", "(", "$", "closure", "(", "$", "string", ")", "===", "false", ")", ";", "return", "$", "string", ";", "}" ]
Make a string unique. Increments a numeric suffix until the given closure returns true. @param string $initial @param Closure $closure @return string
[ "Make", "a", "string", "unique", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Support/Str.php#L114-L124
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Editor.php
Editor.getToolbar
public function getToolbar(EditorObject $editor, Request $request) { $page = PageFacade::find($request->input('page_id')); View::share([ 'page' => $page, 'editor' => $editor, 'auth' => auth(), 'person' => auth()->user(), ]); if ($editor->isHistory()) { return view('boomcms::editor.toolbar.history', [ 'previous' => $page->getCurrentVersion()->getPrevious(), 'next' => $page->getCurrentVersion()->getNext(), 'version' => $page->getCurrentVersion(), 'diff' => new Diff(), ]); } $toolbarFilename = ($editor->isEnabled()) ? 'edit' : 'preview'; return view("boomcms::editor.toolbar.$toolbarFilename"); }
php
public function getToolbar(EditorObject $editor, Request $request) { $page = PageFacade::find($request->input('page_id')); View::share([ 'page' => $page, 'editor' => $editor, 'auth' => auth(), 'person' => auth()->user(), ]); if ($editor->isHistory()) { return view('boomcms::editor.toolbar.history', [ 'previous' => $page->getCurrentVersion()->getPrevious(), 'next' => $page->getCurrentVersion()->getNext(), 'version' => $page->getCurrentVersion(), 'diff' => new Diff(), ]); } $toolbarFilename = ($editor->isEnabled()) ? 'edit' : 'preview'; return view("boomcms::editor.toolbar.$toolbarFilename"); }
[ "public", "function", "getToolbar", "(", "EditorObject", "$", "editor", ",", "Request", "$", "request", ")", "{", "$", "page", "=", "PageFacade", "::", "find", "(", "$", "request", "->", "input", "(", "'page_id'", ")", ")", ";", "View", "::", "share", "(", "[", "'page'", "=>", "$", "page", ",", "'editor'", "=>", "$", "editor", ",", "'auth'", "=>", "auth", "(", ")", ",", "'person'", "=>", "auth", "(", ")", "->", "user", "(", ")", ",", "]", ")", ";", "if", "(", "$", "editor", "->", "isHistory", "(", ")", ")", "{", "return", "view", "(", "'boomcms::editor.toolbar.history'", ",", "[", "'previous'", "=>", "$", "page", "->", "getCurrentVersion", "(", ")", "->", "getPrevious", "(", ")", ",", "'next'", "=>", "$", "page", "->", "getCurrentVersion", "(", ")", "->", "getNext", "(", ")", ",", "'version'", "=>", "$", "page", "->", "getCurrentVersion", "(", ")", ",", "'diff'", "=>", "new", "Diff", "(", ")", ",", "]", ")", ";", "}", "$", "toolbarFilename", "=", "(", "$", "editor", "->", "isEnabled", "(", ")", ")", "?", "'edit'", ":", "'preview'", ";", "return", "view", "(", "\"boomcms::editor.toolbar.$toolbarFilename\"", ")", ";", "}" ]
Displays the CMS interface with buttons for add page, settings, etc. Called from an iframe when logged into the CMS.
[ "Displays", "the", "CMS", "interface", "with", "buttons", "for", "add", "page", "settings", "etc", ".", "Called", "from", "an", "iframe", "when", "logged", "into", "the", "CMS", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Editor.php#L36-L59
train
boomcms/boom-core
src/BoomCMS/Observers/CreationLogObserver.php
CreationLogObserver.creating
public function creating(Model $model) { $model->created_at = time(); $model->created_by = $this->guard->check() ? $this->guard->user()->getId() : null; }
php
public function creating(Model $model) { $model->created_at = time(); $model->created_by = $this->guard->check() ? $this->guard->user()->getId() : null; }
[ "public", "function", "creating", "(", "Model", "$", "model", ")", "{", "$", "model", "->", "created_at", "=", "time", "(", ")", ";", "$", "model", "->", "created_by", "=", "$", "this", "->", "guard", "->", "check", "(", ")", "?", "$", "this", "->", "guard", "->", "user", "(", ")", "->", "getId", "(", ")", ":", "null", ";", "}" ]
Set created_at and created_by on the model prior to creation. @param Model $model @return void
[ "Set", "created_at", "and", "created_by", "on", "the", "model", "prior", "to", "creation", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Observers/CreationLogObserver.php#L30-L34
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.getStatus
public function getStatus(Page $page) { $this->authorize('edit', $page); return view("$this->viewPrefix.status", [ 'page' => $page, 'version' => $page->getCurrentVersion(), 'auth' => auth(), ]); }
php
public function getStatus(Page $page) { $this->authorize('edit', $page); return view("$this->viewPrefix.status", [ 'page' => $page, 'version' => $page->getCurrentVersion(), 'auth' => auth(), ]); }
[ "public", "function", "getStatus", "(", "Page", "$", "page", ")", "{", "$", "this", "->", "authorize", "(", "'edit'", ",", "$", "page", ")", ";", "return", "view", "(", "\"$this->viewPrefix.status\"", ",", "[", "'page'", "=>", "$", "page", ",", "'version'", "=>", "$", "page", "->", "getCurrentVersion", "(", ")", ",", "'auth'", "=>", "auth", "(", ")", ",", "]", ")", ";", "}" ]
Show the current status of the page. @param Page $page @return View
[ "Show", "the", "current", "status", "of", "the", "page", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L44-L53
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.getTemplate
public function getTemplate(Page $page) { $this->authorize('editTemplate', $page); return view("$this->viewPrefix.template", [ 'current' => $page->getTemplate(), 'templates' => TemplateFacade::findValid(), ]); }
php
public function getTemplate(Page $page) { $this->authorize('editTemplate', $page); return view("$this->viewPrefix.template", [ 'current' => $page->getTemplate(), 'templates' => TemplateFacade::findValid(), ]); }
[ "public", "function", "getTemplate", "(", "Page", "$", "page", ")", "{", "$", "this", "->", "authorize", "(", "'editTemplate'", ",", "$", "page", ")", ";", "return", "view", "(", "\"$this->viewPrefix.template\"", ",", "[", "'current'", "=>", "$", "page", "->", "getTemplate", "(", ")", ",", "'templates'", "=>", "TemplateFacade", "::", "findValid", "(", ")", ",", "]", ")", ";", "}" ]
Show a form to change the template of the page. @param Page $page @return View
[ "Show", "a", "form", "to", "change", "the", "template", "of", "the", "page", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L62-L70
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.requestApproval
public function requestApproval(Page $page) { $this->authorize('edit', $page); $page->markUpdatesAsPendingApproval(); Event::fire(new Events\PageApprovalRequested($page, auth()->user())); return $page->getCurrentVersion()->getStatus(); }
php
public function requestApproval(Page $page) { $this->authorize('edit', $page); $page->markUpdatesAsPendingApproval(); Event::fire(new Events\PageApprovalRequested($page, auth()->user())); return $page->getCurrentVersion()->getStatus(); }
[ "public", "function", "requestApproval", "(", "Page", "$", "page", ")", "{", "$", "this", "->", "authorize", "(", "'edit'", ",", "$", "page", ")", ";", "$", "page", "->", "markUpdatesAsPendingApproval", "(", ")", ";", "Event", "::", "fire", "(", "new", "Events", "\\", "PageApprovalRequested", "(", "$", "page", ",", "auth", "(", ")", "->", "user", "(", ")", ")", ")", ";", "return", "$", "page", "->", "getCurrentVersion", "(", ")", "->", "getStatus", "(", ")", ";", "}" ]
Mark the page as requiring approval. @param Page $page @return string
[ "Mark", "the", "page", "as", "requiring", "approval", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L79-L88
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.postEmbargo
public function postEmbargo(Request $request, Page $page) { $this->authorize('publish', $page); $embargoedUntil = new DateTime('@'.time()); if ($time = $request->input('embargoed_until')) { $timestamp = strtotime($time); $embargoedUntil->setTimestamp($timestamp); } $page->setEmbargoTime($embargoedUntil); $version = $page->getCurrentVersion(); if ($version->isPublished()) { Event::fire(new Events\PageWasPublished($page, auth()->user(), $version)); } elseif ($version->isEmbargoed()) { Event::fire(new Events\PageWasEmbargoed($page, auth()->user(), $version)); } return $version->getStatus(); }
php
public function postEmbargo(Request $request, Page $page) { $this->authorize('publish', $page); $embargoedUntil = new DateTime('@'.time()); if ($time = $request->input('embargoed_until')) { $timestamp = strtotime($time); $embargoedUntil->setTimestamp($timestamp); } $page->setEmbargoTime($embargoedUntil); $version = $page->getCurrentVersion(); if ($version->isPublished()) { Event::fire(new Events\PageWasPublished($page, auth()->user(), $version)); } elseif ($version->isEmbargoed()) { Event::fire(new Events\PageWasEmbargoed($page, auth()->user(), $version)); } return $version->getStatus(); }
[ "public", "function", "postEmbargo", "(", "Request", "$", "request", ",", "Page", "$", "page", ")", "{", "$", "this", "->", "authorize", "(", "'publish'", ",", "$", "page", ")", ";", "$", "embargoedUntil", "=", "new", "DateTime", "(", "'@'", ".", "time", "(", ")", ")", ";", "if", "(", "$", "time", "=", "$", "request", "->", "input", "(", "'embargoed_until'", ")", ")", "{", "$", "timestamp", "=", "strtotime", "(", "$", "time", ")", ";", "$", "embargoedUntil", "->", "setTimestamp", "(", "$", "timestamp", ")", ";", "}", "$", "page", "->", "setEmbargoTime", "(", "$", "embargoedUntil", ")", ";", "$", "version", "=", "$", "page", "->", "getCurrentVersion", "(", ")", ";", "if", "(", "$", "version", "->", "isPublished", "(", ")", ")", "{", "Event", "::", "fire", "(", "new", "Events", "\\", "PageWasPublished", "(", "$", "page", ",", "auth", "(", ")", "->", "user", "(", ")", ",", "$", "version", ")", ")", ";", "}", "elseif", "(", "$", "version", "->", "isEmbargoed", "(", ")", ")", "{", "Event", "::", "fire", "(", "new", "Events", "\\", "PageWasEmbargoed", "(", "$", "page", ",", "auth", "(", ")", "->", "user", "(", ")", ",", "$", "version", ")", ")", ";", "}", "return", "$", "version", "->", "getStatus", "(", ")", ";", "}" ]
Set an embargo time for the current drafts. @param Request $request @param Page $page @return string
[ "Set", "an", "embargo", "time", "for", "the", "current", "drafts", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L109-L131
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.postTemplate
public function postTemplate(Page $page, Template $template) { $this->authorize('editTemplate', $page); $page->setTemplate($template); Event::fire(new Events\PageTemplateWasChanged($page, $template)); return $page->getCurrentVersion()->getStatus(); }
php
public function postTemplate(Page $page, Template $template) { $this->authorize('editTemplate', $page); $page->setTemplate($template); Event::fire(new Events\PageTemplateWasChanged($page, $template)); return $page->getCurrentVersion()->getStatus(); }
[ "public", "function", "postTemplate", "(", "Page", "$", "page", ",", "Template", "$", "template", ")", "{", "$", "this", "->", "authorize", "(", "'editTemplate'", ",", "$", "page", ")", ";", "$", "page", "->", "setTemplate", "(", "$", "template", ")", ";", "Event", "::", "fire", "(", "new", "Events", "\\", "PageTemplateWasChanged", "(", "$", "page", ",", "$", "template", ")", ")", ";", "return", "$", "page", "->", "getCurrentVersion", "(", ")", "->", "getStatus", "(", ")", ";", "}" ]
Set the template of the page. @param Page $page @param Template $template @return string
[ "Set", "the", "template", "of", "the", "page", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L141-L150
train
boomcms/boom-core
src/BoomCMS/Http/Controllers/Page/Version.php
Version.postTitle
public function postTitle(Request $request, Page $page) { $this->authorize('edit', $page); $oldTitle = $page->getTitle(); $page->setTitle($request->input('title')); Event::fire(new Events\PageTitleWasChanged($page, $oldTitle, $page->getTitle())); return [ 'status' => $page->getCurrentVersion()->getStatus(), 'location' => (string) URLFacade::page($page), ]; }
php
public function postTitle(Request $request, Page $page) { $this->authorize('edit', $page); $oldTitle = $page->getTitle(); $page->setTitle($request->input('title')); Event::fire(new Events\PageTitleWasChanged($page, $oldTitle, $page->getTitle())); return [ 'status' => $page->getCurrentVersion()->getStatus(), 'location' => (string) URLFacade::page($page), ]; }
[ "public", "function", "postTitle", "(", "Request", "$", "request", ",", "Page", "$", "page", ")", "{", "$", "this", "->", "authorize", "(", "'edit'", ",", "$", "page", ")", ";", "$", "oldTitle", "=", "$", "page", "->", "getTitle", "(", ")", ";", "$", "page", "->", "setTitle", "(", "$", "request", "->", "input", "(", "'title'", ")", ")", ";", "Event", "::", "fire", "(", "new", "Events", "\\", "PageTitleWasChanged", "(", "$", "page", ",", "$", "oldTitle", ",", "$", "page", "->", "getTitle", "(", ")", ")", ")", ";", "return", "[", "'status'", "=>", "$", "page", "->", "getCurrentVersion", "(", ")", "->", "getStatus", "(", ")", ",", "'location'", "=>", "(", "string", ")", "URLFacade", "::", "page", "(", "$", "page", ")", ",", "]", ";", "}" ]
Set the title of the page. @param Request $request @param Page $page @return array
[ "Set", "the", "title", "of", "the", "page", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Http/Controllers/Page/Version.php#L160-L173
train
boomcms/boom-core
src/BoomCMS/Support/Helpers/Config.php
Config.merge
public static function merge($file) { if (file_exists($file)) { $config = c::get('boomcms', []); c::set('boomcms', array_merge_recursive(include $file, $config)); } }
php
public static function merge($file) { if (file_exists($file)) { $config = c::get('boomcms', []); c::set('boomcms', array_merge_recursive(include $file, $config)); } }
[ "public", "static", "function", "merge", "(", "$", "file", ")", "{", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "config", "=", "c", "::", "get", "(", "'boomcms'", ",", "[", "]", ")", ";", "c", "::", "set", "(", "'boomcms'", ",", "array_merge_recursive", "(", "include", "$", "file", ",", "$", "config", ")", ")", ";", "}", "}" ]
Recursively merges a file into the boomcms config group. @param string $file
[ "Recursively", "merges", "a", "file", "into", "the", "boomcms", "config", "group", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Support/Helpers/Config.php#L14-L20
train
boomcms/boom-core
src/BoomCMS/Observers/SetSiteObserver.php
SetSiteObserver.creating
public function creating(Model $model) { if ($model instanceof SingleSiteInterface) { $site = $this->router->getActiveSite() ?: $this->site->findDefault(); $model->{SingleSiteInterface::ATTR_SITE} = ($site ? $site->getId() : null); } }
php
public function creating(Model $model) { if ($model instanceof SingleSiteInterface) { $site = $this->router->getActiveSite() ?: $this->site->findDefault(); $model->{SingleSiteInterface::ATTR_SITE} = ($site ? $site->getId() : null); } }
[ "public", "function", "creating", "(", "Model", "$", "model", ")", "{", "if", "(", "$", "model", "instanceof", "SingleSiteInterface", ")", "{", "$", "site", "=", "$", "this", "->", "router", "->", "getActiveSite", "(", ")", "?", ":", "$", "this", "->", "site", "->", "findDefault", "(", ")", ";", "$", "model", "->", "{", "SingleSiteInterface", "::", "ATTR_SITE", "}", "=", "(", "$", "site", "?", "$", "site", "->", "getId", "(", ")", ":", "null", ")", ";", "}", "}" ]
Set the site_id of the model. If a site is currently active then it is used, otherwise the default site is used. @param Model $model @return void
[ "Set", "the", "site_id", "of", "the", "model", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Observers/SetSiteObserver.php#L40-L47
train
boomcms/boom-core
src/BoomCMS/Theme/Theme.php
Theme.init
public function init() { $filename = $this->getDirectory().DIRECTORY_SEPARATOR.$this->initFilename; if (File::exists($filename)) { File::requireOnce($filename); } }
php
public function init() { $filename = $this->getDirectory().DIRECTORY_SEPARATOR.$this->initFilename; if (File::exists($filename)) { File::requireOnce($filename); } }
[ "public", "function", "init", "(", ")", "{", "$", "filename", "=", "$", "this", "->", "getDirectory", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "initFilename", ";", "if", "(", "File", "::", "exists", "(", "$", "filename", ")", ")", "{", "File", "::", "requireOnce", "(", "$", "filename", ")", ";", "}", "}" ]
Includes the theme's init file, if it exists.
[ "Includes", "the", "theme", "s", "init", "file", "if", "it", "exists", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Theme/Theme.php#L109-L116
train
boomcms/boom-core
src/BoomCMS/Chunk/BaseChunk.php
BaseChunk.addAttributesToHtml
public function addAttributesToHtml($html) { $html = trim((string) $html); $attributes = array_merge($this->getRequiredAttributes(), $this->attributes()); $attributesString = Html::attributes($attributes); return preg_replace('|<(.*?)>|', "<$1$attributesString>", $html, 1); }
php
public function addAttributesToHtml($html) { $html = trim((string) $html); $attributes = array_merge($this->getRequiredAttributes(), $this->attributes()); $attributesString = Html::attributes($attributes); return preg_replace('|<(.*?)>|', "<$1$attributesString>", $html, 1); }
[ "public", "function", "addAttributesToHtml", "(", "$", "html", ")", "{", "$", "html", "=", "trim", "(", "(", "string", ")", "$", "html", ")", ";", "$", "attributes", "=", "array_merge", "(", "$", "this", "->", "getRequiredAttributes", "(", ")", ",", "$", "this", "->", "attributes", "(", ")", ")", ";", "$", "attributesString", "=", "Html", "::", "attributes", "(", "$", "attributes", ")", ";", "return", "preg_replace", "(", "'|<(.*?)>|'", ",", "\"<$1$attributesString>\"", ",", "$", "html", ",", "1", ")", ";", "}" ]
This adds the necessary classes to chunk HTML for them to be picked up by the JS editor. i.e. it makes chunks editable. @param string $html HTML to add classes to. @return string
[ "This", "adds", "the", "necessary", "classes", "to", "chunk", "HTML", "for", "them", "to", "be", "picked", "up", "by", "the", "JS", "editor", ".", "i", ".", "e", ".", "it", "makes", "chunks", "editable", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Chunk/BaseChunk.php#L137-L145
train
boomcms/boom-core
src/BoomCMS/Chunk/BaseChunk.php
BaseChunk.getRequiredAttributes
public function getRequiredAttributes() { return [ $this->attributePrefix.'chunk' => $this->getType(), $this->attributePrefix.'slot-name' => $this->slotname, $this->attributePrefix.'slot-template' => $this->template, $this->attributePrefix.'page' => $this->page->getId(), $this->attributePrefix.'chunk-id' => $this->getId(), $this->attributePrefix.'has-content' => $this->hasContent(), ]; }
php
public function getRequiredAttributes() { return [ $this->attributePrefix.'chunk' => $this->getType(), $this->attributePrefix.'slot-name' => $this->slotname, $this->attributePrefix.'slot-template' => $this->template, $this->attributePrefix.'page' => $this->page->getId(), $this->attributePrefix.'chunk-id' => $this->getId(), $this->attributePrefix.'has-content' => $this->hasContent(), ]; }
[ "public", "function", "getRequiredAttributes", "(", ")", "{", "return", "[", "$", "this", "->", "attributePrefix", ".", "'chunk'", "=>", "$", "this", "->", "getType", "(", ")", ",", "$", "this", "->", "attributePrefix", ".", "'slot-name'", "=>", "$", "this", "->", "slotname", ",", "$", "this", "->", "attributePrefix", ".", "'slot-template'", "=>", "$", "this", "->", "template", ",", "$", "this", "->", "attributePrefix", ".", "'page'", "=>", "$", "this", "->", "page", "->", "getId", "(", ")", ",", "$", "this", "->", "attributePrefix", ".", "'chunk-id'", "=>", "$", "this", "->", "getId", "(", ")", ",", "$", "this", "->", "attributePrefix", ".", "'has-content'", "=>", "$", "this", "->", "hasContent", "(", ")", ",", "]", ";", "}" ]
Returns an array of HTML attributes which are required to be make the chunk editable. To add other attributes see the attributes method. @return array
[ "Returns", "an", "array", "of", "HTML", "attributes", "which", "are", "required", "to", "be", "make", "the", "chunk", "editable", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Chunk/BaseChunk.php#L178-L188
train
boomcms/boom-core
src/BoomCMS/Chunk/BaseChunk.php
BaseChunk.render
public function render() { try { $html = $this->html(); if ($this->editable === true || Editor::isHistory()) { $html = $this->addAttributesToHtml($html); } return empty($html) ? $html : $this->before.$html.$this->after; } catch (\Exception $e) { if (App::environment() === 'local') { throw $e; } } }
php
public function render() { try { $html = $this->html(); if ($this->editable === true || Editor::isHistory()) { $html = $this->addAttributesToHtml($html); } return empty($html) ? $html : $this->before.$html.$this->after; } catch (\Exception $e) { if (App::environment() === 'local') { throw $e; } } }
[ "public", "function", "render", "(", ")", "{", "try", "{", "$", "html", "=", "$", "this", "->", "html", "(", ")", ";", "if", "(", "$", "this", "->", "editable", "===", "true", "||", "Editor", "::", "isHistory", "(", ")", ")", "{", "$", "html", "=", "$", "this", "->", "addAttributesToHtml", "(", "$", "html", ")", ";", "}", "return", "empty", "(", "$", "html", ")", "?", "$", "html", ":", "$", "this", "->", "before", ".", "$", "html", ".", "$", "this", "->", "after", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "App", "::", "environment", "(", ")", "===", "'local'", ")", "{", "throw", "$", "e", ";", "}", "}", "}" ]
Attempts to get the chunk data from the cache, otherwise calls _execute to generate the cache.
[ "Attempts", "to", "get", "the", "chunk", "data", "from", "the", "cache", "otherwise", "calls", "_execute", "to", "generate", "the", "cache", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Chunk/BaseChunk.php#L241-L256
train
boomcms/boom-core
src/BoomCMS/Chunk/BaseChunk.php
BaseChunk.html
public function html() { if (!$this->hasContent() && !$this->isEditable()) { return ''; } $content = $this->hasContent() ? $this->show() : $this->showDefault(); // If the return data is a View then assign any parameters to it. if ($content instanceof View && !empty($this->viewParams)) { $content->with($this->viewParams); } return (string) $content; }
php
public function html() { if (!$this->hasContent() && !$this->isEditable()) { return ''; } $content = $this->hasContent() ? $this->show() : $this->showDefault(); // If the return data is a View then assign any parameters to it. if ($content instanceof View && !empty($this->viewParams)) { $content->with($this->viewParams); } return (string) $content; }
[ "public", "function", "html", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasContent", "(", ")", "&&", "!", "$", "this", "->", "isEditable", "(", ")", ")", "{", "return", "''", ";", "}", "$", "content", "=", "$", "this", "->", "hasContent", "(", ")", "?", "$", "this", "->", "show", "(", ")", ":", "$", "this", "->", "showDefault", "(", ")", ";", "// If the return data is a View then assign any parameters to it.", "if", "(", "$", "content", "instanceof", "View", "&&", "!", "empty", "(", "$", "this", "->", "viewParams", ")", ")", "{", "$", "content", "->", "with", "(", "$", "this", "->", "viewParams", ")", ";", "}", "return", "(", "string", ")", "$", "content", ";", "}" ]
Generate the HTML to display the chunk. @return string
[ "Generate", "the", "HTML", "to", "display", "the", "chunk", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Chunk/BaseChunk.php#L282-L296
train
boomcms/boom-core
src/BoomCMS/Auth/RandomPassword.php
RandomPassword.addWordList
public function addWordList(string $path, $name): self { $this->generator->addWordList($path, $name); return $this; }
php
public function addWordList(string $path, $name): self { $this->generator->addWordList($path, $name); return $this; }
[ "public", "function", "addWordList", "(", "string", "$", "path", ",", "$", "name", ")", ":", "self", "{", "$", "this", "->", "generator", "->", "addWordList", "(", "$", "path", ",", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
Add a word list to the generator. @param string $path @param string $name @return $this
[ "Add", "a", "word", "list", "to", "the", "generator", "." ]
cc835772e3c33dac3e56c36a8db2c9e6da313c7b
https://github.com/boomcms/boom-core/blob/cc835772e3c33dac3e56c36a8db2c9e6da313c7b/src/BoomCMS/Auth/RandomPassword.php#L46-L51
train
krowinski/php-mysql-replication
src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
BinaryDataReader.unread
public function unread($data) { $this->readBytes -= strlen($data); $this->data = $data . $this->data; }
php
public function unread($data) { $this->readBytes -= strlen($data); $this->data = $data . $this->data; }
[ "public", "function", "unread", "(", "$", "data", ")", "{", "$", "this", "->", "readBytes", "-=", "strlen", "(", "$", "data", ")", ";", "$", "this", "->", "data", "=", "$", "data", ".", "$", "this", "->", "data", ";", "}" ]
Push again data in data buffer. It's use when you want to extract a bit from a value a let the rest of the code normally read the data @param string $data
[ "Push", "again", "data", "in", "data", "buffer", ".", "It", "s", "use", "when", "you", "want", "to", "extract", "a", "bit", "from", "a", "value", "a", "let", "the", "rest", "of", "the", "code", "normally", "read", "the", "data" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/BinaryDataReader/BinaryDataReader.php#L81-L85
train
krowinski/php-mysql-replication
src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
BinaryDataReader.readCodedBinary
public function readCodedBinary() { $c = ord($this->read(self::UNSIGNED_CHAR_LENGTH)); if ($c === self::NULL_COLUMN) { return ''; } if ($c < self::UNSIGNED_CHAR_COLUMN) { return $c; } if ($c === self::UNSIGNED_SHORT_COLUMN) { return $this->readUInt16(); } if ($c === self::UNSIGNED_INT24_COLUMN) { return $this->readUInt24(); } if ($c === self::UNSIGNED_INT64_COLUMN) { return $this->readUInt64(); } throw new BinaryDataReaderException('Column num ' . $c . ' not handled'); }
php
public function readCodedBinary() { $c = ord($this->read(self::UNSIGNED_CHAR_LENGTH)); if ($c === self::NULL_COLUMN) { return ''; } if ($c < self::UNSIGNED_CHAR_COLUMN) { return $c; } if ($c === self::UNSIGNED_SHORT_COLUMN) { return $this->readUInt16(); } if ($c === self::UNSIGNED_INT24_COLUMN) { return $this->readUInt24(); } if ($c === self::UNSIGNED_INT64_COLUMN) { return $this->readUInt64(); } throw new BinaryDataReaderException('Column num ' . $c . ' not handled'); }
[ "public", "function", "readCodedBinary", "(", ")", "{", "$", "c", "=", "ord", "(", "$", "this", "->", "read", "(", "self", "::", "UNSIGNED_CHAR_LENGTH", ")", ")", ";", "if", "(", "$", "c", "===", "self", "::", "NULL_COLUMN", ")", "{", "return", "''", ";", "}", "if", "(", "$", "c", "<", "self", "::", "UNSIGNED_CHAR_COLUMN", ")", "{", "return", "$", "c", ";", "}", "if", "(", "$", "c", "===", "self", "::", "UNSIGNED_SHORT_COLUMN", ")", "{", "return", "$", "this", "->", "readUInt16", "(", ")", ";", "}", "if", "(", "$", "c", "===", "self", "::", "UNSIGNED_INT24_COLUMN", ")", "{", "return", "$", "this", "->", "readUInt24", "(", ")", ";", "}", "if", "(", "$", "c", "===", "self", "::", "UNSIGNED_INT64_COLUMN", ")", "{", "return", "$", "this", "->", "readUInt64", "(", ")", ";", "}", "throw", "new", "BinaryDataReaderException", "(", "'Column num '", ".", "$", "c", ".", "' not handled'", ")", ";", "}" ]
Read a 'Length Coded Binary' number from the data buffer. Length coded numbers can be anywhere from 1 to 9 bytes depending on the value of the first byte. From PyMYSQL source code @return int|string @throws BinaryDataReaderException
[ "Read", "a", "Length", "Coded", "Binary", "number", "from", "the", "data", "buffer", ".", "Length", "coded", "numbers", "can", "be", "anywhere", "from", "1", "to", "9", "bytes", "depending", "on", "the", "value", "of", "the", "first", "byte", ".", "From", "PyMYSQL", "source", "code" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/BinaryDataReader/BinaryDataReader.php#L95-L115
train
krowinski/php-mysql-replication
src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
BinaryDataReader.readUIntBySize
public function readUIntBySize($size) { if ($size === self::UNSIGNED_CHAR_LENGTH) { return $this->readUInt8(); } if ($size === self::UNSIGNED_SHORT_LENGTH) { return $this->readUInt16(); } if ($size === self::UNSIGNED_INT24_LENGTH) { return $this->readUInt24(); } if ($size === self::UNSIGNED_INT32_LENGTH) { return $this->readUInt32(); } if ($size === self::UNSIGNED_INT40_LENGTH) { return $this->readUInt40(); } if ($size === self::UNSIGNED_INT48_LENGTH) { return $this->readUInt48(); } if ($size === self::UNSIGNED_INT56_LENGTH) { return $this->readUInt56(); } if ($size === self::UNSIGNED_INT64_LENGTH) { return $this->readUInt64(); } throw new BinaryDataReaderException('$size ' . $size . ' not handled'); }
php
public function readUIntBySize($size) { if ($size === self::UNSIGNED_CHAR_LENGTH) { return $this->readUInt8(); } if ($size === self::UNSIGNED_SHORT_LENGTH) { return $this->readUInt16(); } if ($size === self::UNSIGNED_INT24_LENGTH) { return $this->readUInt24(); } if ($size === self::UNSIGNED_INT32_LENGTH) { return $this->readUInt32(); } if ($size === self::UNSIGNED_INT40_LENGTH) { return $this->readUInt40(); } if ($size === self::UNSIGNED_INT48_LENGTH) { return $this->readUInt48(); } if ($size === self::UNSIGNED_INT56_LENGTH) { return $this->readUInt56(); } if ($size === self::UNSIGNED_INT64_LENGTH) { return $this->readUInt64(); } throw new BinaryDataReaderException('$size ' . $size . ' not handled'); }
[ "public", "function", "readUIntBySize", "(", "$", "size", ")", "{", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_CHAR_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt8", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_SHORT_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt16", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT24_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt24", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT32_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt32", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT40_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt40", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT48_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt48", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT56_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt56", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT64_LENGTH", ")", "{", "return", "$", "this", "->", "readUInt64", "(", ")", ";", "}", "throw", "new", "BinaryDataReaderException", "(", "'$size '", ".", "$", "size", ".", "' not handled'", ")", ";", "}" ]
Read a little endian integer values based on byte number @param int $size @return mixed @throws BinaryDataReaderException
[ "Read", "a", "little", "endian", "integer", "values", "based", "on", "byte", "number" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/BinaryDataReader/BinaryDataReader.php#L195-L223
train
krowinski/php-mysql-replication
src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
BinaryDataReader.readIntBeBySize
public function readIntBeBySize($size) { if ($size === self::UNSIGNED_CHAR_LENGTH) { return $this->readInt8(); } if ($size === self::UNSIGNED_SHORT_LENGTH) { return $this->readInt16Be(); } if ($size === self::UNSIGNED_INT24_LENGTH) { return $this->readInt24Be(); } if ($size === self::UNSIGNED_INT32_LENGTH) { return $this->readInt32Be(); } if ($size === self::UNSIGNED_INT40_LENGTH) { return $this->readInt40Be(); } throw new BinaryDataReaderException('$size ' . $size . ' not handled'); }
php
public function readIntBeBySize($size) { if ($size === self::UNSIGNED_CHAR_LENGTH) { return $this->readInt8(); } if ($size === self::UNSIGNED_SHORT_LENGTH) { return $this->readInt16Be(); } if ($size === self::UNSIGNED_INT24_LENGTH) { return $this->readInt24Be(); } if ($size === self::UNSIGNED_INT32_LENGTH) { return $this->readInt32Be(); } if ($size === self::UNSIGNED_INT40_LENGTH) { return $this->readInt40Be(); } throw new BinaryDataReaderException('$size ' . $size . ' not handled'); }
[ "public", "function", "readIntBeBySize", "(", "$", "size", ")", "{", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_CHAR_LENGTH", ")", "{", "return", "$", "this", "->", "readInt8", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_SHORT_LENGTH", ")", "{", "return", "$", "this", "->", "readInt16Be", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT24_LENGTH", ")", "{", "return", "$", "this", "->", "readInt24Be", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT32_LENGTH", ")", "{", "return", "$", "this", "->", "readInt32Be", "(", ")", ";", "}", "if", "(", "$", "size", "===", "self", "::", "UNSIGNED_INT40_LENGTH", ")", "{", "return", "$", "this", "->", "readInt40Be", "(", ")", ";", "}", "throw", "new", "BinaryDataReaderException", "(", "'$size '", ".", "$", "size", ".", "' not handled'", ")", ";", "}" ]
Read a big endian integer values based on byte number @param int $size @return int @throws BinaryDataReaderException
[ "Read", "a", "big", "endian", "integer", "values", "based", "on", "byte", "number" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/BinaryDataReader/BinaryDataReader.php#L280-L299
train
krowinski/php-mysql-replication
src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
BinaryDataReader.getBinarySlice
public function getBinarySlice($binary, $start, $size, $binaryLength) { $binary >>= $binaryLength - ($start + $size); $mask = ((1 << $size) - 1); return $binary & $mask; }
php
public function getBinarySlice($binary, $start, $size, $binaryLength) { $binary >>= $binaryLength - ($start + $size); $mask = ((1 << $size) - 1); return $binary & $mask; }
[ "public", "function", "getBinarySlice", "(", "$", "binary", ",", "$", "start", ",", "$", "size", ",", "$", "binaryLength", ")", "{", "$", "binary", ">>=", "$", "binaryLength", "-", "(", "$", "start", "+", "$", "size", ")", ";", "$", "mask", "=", "(", "(", "1", "<<", "$", "size", ")", "-", "1", ")", ";", "return", "$", "binary", "&", "$", "mask", ";", "}" ]
Read a part of binary data and extract a number @param int $binary @param int $start @param int $size @param int $binaryLength @return int
[ "Read", "a", "part", "of", "binary", "data", "and", "extract", "a", "number" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/BinaryDataReader/BinaryDataReader.php#L419-L425
train
krowinski/php-mysql-replication
src/MySQLReplication/Event/RowEvent/RowEvent.php
RowEvent.makeTableMapDTO
public function makeTableMapDTO() { $data = []; $data['table_id'] = $this->binaryDataReader->readTableId(); $this->binaryDataReader->advance(2); $data['schema_length'] = $this->binaryDataReader->readUInt8(); $data['schema_name'] = $this->binaryDataReader->read($data['schema_length']); if (Config::checkDataBasesOnly($data['schema_name'])) { return null; } $this->binaryDataReader->advance(1); $data['table_length'] = $this->binaryDataReader->readUInt8(); $data['table_name'] = $this->binaryDataReader->read($data['table_length']); if (Config::checkTablesOnly($data['table_name'])) { return null; } $this->binaryDataReader->advance(1); $data['columns_amount'] = $this->binaryDataReader->readCodedBinary(); $data['column_types'] = $this->binaryDataReader->read($data['columns_amount']); if ($this->cache->has($data['table_id'])) { return new TableMapDTO($this->eventInfo, $this->cache->get($data['table_id'])); } $this->binaryDataReader->readCodedBinary(); $columns = $this->repository->getFields($data['schema_name'], $data['table_name']); $fields = []; // if you drop tables and parse of logs you will get empty scheme if (!empty($columns)) { $columnLength = strlen($data['column_types']); for ($i = 0; $i < $columnLength; ++$i) { // this a dirty hack to prevent row events containing columns which have been dropped if (!isset($columns[$i])) { $columns[$i] = [ 'COLUMN_NAME' => 'DROPPED_COLUMN_' . $i, 'COLLATION_NAME' => null, 'CHARACTER_SET_NAME' => null, 'COLUMN_COMMENT' => null, 'COLUMN_TYPE' => 'BLOB', 'COLUMN_KEY' => '' ]; $type = ConstFieldType::IGNORE; } else { $type = ord($data['column_types'][$i]); } $fields[$i] = Columns::parse($type, $columns[$i], $this->binaryDataReader); } } $tableMap = new TableMap( $data['schema_name'], $data['table_name'], $data['table_id'], $data['columns_amount'], $fields ); $this->cache->set($data['table_id'], $tableMap); return new TableMapDTO($this->eventInfo, $tableMap); }
php
public function makeTableMapDTO() { $data = []; $data['table_id'] = $this->binaryDataReader->readTableId(); $this->binaryDataReader->advance(2); $data['schema_length'] = $this->binaryDataReader->readUInt8(); $data['schema_name'] = $this->binaryDataReader->read($data['schema_length']); if (Config::checkDataBasesOnly($data['schema_name'])) { return null; } $this->binaryDataReader->advance(1); $data['table_length'] = $this->binaryDataReader->readUInt8(); $data['table_name'] = $this->binaryDataReader->read($data['table_length']); if (Config::checkTablesOnly($data['table_name'])) { return null; } $this->binaryDataReader->advance(1); $data['columns_amount'] = $this->binaryDataReader->readCodedBinary(); $data['column_types'] = $this->binaryDataReader->read($data['columns_amount']); if ($this->cache->has($data['table_id'])) { return new TableMapDTO($this->eventInfo, $this->cache->get($data['table_id'])); } $this->binaryDataReader->readCodedBinary(); $columns = $this->repository->getFields($data['schema_name'], $data['table_name']); $fields = []; // if you drop tables and parse of logs you will get empty scheme if (!empty($columns)) { $columnLength = strlen($data['column_types']); for ($i = 0; $i < $columnLength; ++$i) { // this a dirty hack to prevent row events containing columns which have been dropped if (!isset($columns[$i])) { $columns[$i] = [ 'COLUMN_NAME' => 'DROPPED_COLUMN_' . $i, 'COLLATION_NAME' => null, 'CHARACTER_SET_NAME' => null, 'COLUMN_COMMENT' => null, 'COLUMN_TYPE' => 'BLOB', 'COLUMN_KEY' => '' ]; $type = ConstFieldType::IGNORE; } else { $type = ord($data['column_types'][$i]); } $fields[$i] = Columns::parse($type, $columns[$i], $this->binaryDataReader); } } $tableMap = new TableMap( $data['schema_name'], $data['table_name'], $data['table_id'], $data['columns_amount'], $fields ); $this->cache->set($data['table_id'], $tableMap); return new TableMapDTO($this->eventInfo, $tableMap); }
[ "public", "function", "makeTableMapDTO", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "data", "[", "'table_id'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "readTableId", "(", ")", ";", "$", "this", "->", "binaryDataReader", "->", "advance", "(", "2", ")", ";", "$", "data", "[", "'schema_length'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "readUInt8", "(", ")", ";", "$", "data", "[", "'schema_name'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "read", "(", "$", "data", "[", "'schema_length'", "]", ")", ";", "if", "(", "Config", "::", "checkDataBasesOnly", "(", "$", "data", "[", "'schema_name'", "]", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "binaryDataReader", "->", "advance", "(", "1", ")", ";", "$", "data", "[", "'table_length'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "readUInt8", "(", ")", ";", "$", "data", "[", "'table_name'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "read", "(", "$", "data", "[", "'table_length'", "]", ")", ";", "if", "(", "Config", "::", "checkTablesOnly", "(", "$", "data", "[", "'table_name'", "]", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "binaryDataReader", "->", "advance", "(", "1", ")", ";", "$", "data", "[", "'columns_amount'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "readCodedBinary", "(", ")", ";", "$", "data", "[", "'column_types'", "]", "=", "$", "this", "->", "binaryDataReader", "->", "read", "(", "$", "data", "[", "'columns_amount'", "]", ")", ";", "if", "(", "$", "this", "->", "cache", "->", "has", "(", "$", "data", "[", "'table_id'", "]", ")", ")", "{", "return", "new", "TableMapDTO", "(", "$", "this", "->", "eventInfo", ",", "$", "this", "->", "cache", "->", "get", "(", "$", "data", "[", "'table_id'", "]", ")", ")", ";", "}", "$", "this", "->", "binaryDataReader", "->", "readCodedBinary", "(", ")", ";", "$", "columns", "=", "$", "this", "->", "repository", "->", "getFields", "(", "$", "data", "[", "'schema_name'", "]", ",", "$", "data", "[", "'table_name'", "]", ")", ";", "$", "fields", "=", "[", "]", ";", "// if you drop tables and parse of logs you will get empty scheme", "if", "(", "!", "empty", "(", "$", "columns", ")", ")", "{", "$", "columnLength", "=", "strlen", "(", "$", "data", "[", "'column_types'", "]", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "columnLength", ";", "++", "$", "i", ")", "{", "// this a dirty hack to prevent row events containing columns which have been dropped", "if", "(", "!", "isset", "(", "$", "columns", "[", "$", "i", "]", ")", ")", "{", "$", "columns", "[", "$", "i", "]", "=", "[", "'COLUMN_NAME'", "=>", "'DROPPED_COLUMN_'", ".", "$", "i", ",", "'COLLATION_NAME'", "=>", "null", ",", "'CHARACTER_SET_NAME'", "=>", "null", ",", "'COLUMN_COMMENT'", "=>", "null", ",", "'COLUMN_TYPE'", "=>", "'BLOB'", ",", "'COLUMN_KEY'", "=>", "''", "]", ";", "$", "type", "=", "ConstFieldType", "::", "IGNORE", ";", "}", "else", "{", "$", "type", "=", "ord", "(", "$", "data", "[", "'column_types'", "]", "[", "$", "i", "]", ")", ";", "}", "$", "fields", "[", "$", "i", "]", "=", "Columns", "::", "parse", "(", "$", "type", ",", "$", "columns", "[", "$", "i", "]", ",", "$", "this", "->", "binaryDataReader", ")", ";", "}", "}", "$", "tableMap", "=", "new", "TableMap", "(", "$", "data", "[", "'schema_name'", "]", ",", "$", "data", "[", "'table_name'", "]", ",", "$", "data", "[", "'table_id'", "]", ",", "$", "data", "[", "'columns_amount'", "]", ",", "$", "fields", ")", ";", "$", "this", "->", "cache", "->", "set", "(", "$", "data", "[", "'table_id'", "]", ",", "$", "tableMap", ")", ";", "return", "new", "TableMapDTO", "(", "$", "this", "->", "eventInfo", ",", "$", "tableMap", ")", ";", "}" ]
This describe the structure of a table. It's send before a change append on a table. A end user of the lib should have no usage of this @return TableMapDTO @throws \Psr\SimpleCache\InvalidArgumentException @throws BinaryDataReaderException
[ "This", "describe", "the", "structure", "of", "a", "table", ".", "It", "s", "send", "before", "a", "change", "append", "on", "a", "table", ".", "A", "end", "user", "of", "the", "lib", "should", "have", "no", "usage", "of", "this" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/Event/RowEvent/RowEvent.php#L331-L399
train
krowinski/php-mysql-replication
src/MySQLReplication/Event/RowEvent/RowEvent.php
RowEvent.getBit
protected function getBit(array $column) { $res = ''; for ($byte = 0; $byte < $column['bytes']; ++$byte) { $current_byte = ''; $data = $this->binaryDataReader->readUInt8(); if (0 === $byte) { if (1 === $column['bytes']) { $end = $column['bits']; } else { $end = $column['bits'] % 8; if (0 === $end) { $end = 8; } } } else { $end = 8; } for ($bit = 0; $bit < $end; ++$bit) { if ($data & (1 << $bit)) { $current_byte .= '1'; } else { $current_byte .= '0'; } } $res .= strrev($current_byte); } return $res; }
php
protected function getBit(array $column) { $res = ''; for ($byte = 0; $byte < $column['bytes']; ++$byte) { $current_byte = ''; $data = $this->binaryDataReader->readUInt8(); if (0 === $byte) { if (1 === $column['bytes']) { $end = $column['bits']; } else { $end = $column['bits'] % 8; if (0 === $end) { $end = 8; } } } else { $end = 8; } for ($bit = 0; $bit < $end; ++$bit) { if ($data & (1 << $bit)) { $current_byte .= '1'; } else { $current_byte .= '0'; } } $res .= strrev($current_byte); } return $res; }
[ "protected", "function", "getBit", "(", "array", "$", "column", ")", "{", "$", "res", "=", "''", ";", "for", "(", "$", "byte", "=", "0", ";", "$", "byte", "<", "$", "column", "[", "'bytes'", "]", ";", "++", "$", "byte", ")", "{", "$", "current_byte", "=", "''", ";", "$", "data", "=", "$", "this", "->", "binaryDataReader", "->", "readUInt8", "(", ")", ";", "if", "(", "0", "===", "$", "byte", ")", "{", "if", "(", "1", "===", "$", "column", "[", "'bytes'", "]", ")", "{", "$", "end", "=", "$", "column", "[", "'bits'", "]", ";", "}", "else", "{", "$", "end", "=", "$", "column", "[", "'bits'", "]", "%", "8", ";", "if", "(", "0", "===", "$", "end", ")", "{", "$", "end", "=", "8", ";", "}", "}", "}", "else", "{", "$", "end", "=", "8", ";", "}", "for", "(", "$", "bit", "=", "0", ";", "$", "bit", "<", "$", "end", ";", "++", "$", "bit", ")", "{", "if", "(", "$", "data", "&", "(", "1", "<<", "$", "bit", ")", ")", "{", "$", "current_byte", ".=", "'1'", ";", "}", "else", "{", "$", "current_byte", ".=", "'0'", ";", "}", "}", "$", "res", ".=", "strrev", "(", "$", "current_byte", ")", ";", "}", "return", "$", "res", ";", "}" ]
Read MySQL BIT type @param array $column @return string
[ "Read", "MySQL", "BIT", "type" ]
966d858677c9a662fa2e1081b01c3b5fd80bccb0
https://github.com/krowinski/php-mysql-replication/blob/966d858677c9a662fa2e1081b01c3b5fd80bccb0/src/MySQLReplication/Event/RowEvent/RowEvent.php#L882-L913
train
optimaize/nameapi-client-php
src/org/nameapi/client/services/parser/OutputPersonName.php
OutputPersonName.getAll
public function getAll($termType) { $arr = array(); foreach ($this->terms as $term) { if ((string)$term->getTermType() === $termType) { array_push($arr, $term); } } return $arr; }
php
public function getAll($termType) { $arr = array(); foreach ($this->terms as $term) { if ((string)$term->getTermType() === $termType) { array_push($arr, $term); } } return $arr; }
[ "public", "function", "getAll", "(", "$", "termType", ")", "{", "$", "arr", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "terms", "as", "$", "term", ")", "{", "if", "(", "(", "string", ")", "$", "term", "->", "getTermType", "(", ")", "===", "$", "termType", ")", "{", "array_push", "(", "$", "arr", ",", "$", "term", ")", ";", "}", "}", "return", "$", "arr", ";", "}" ]
Returns all terms that have the given term type, or empty array if none. @param string $termType @return Term[]
[ "Returns", "all", "terms", "that", "have", "the", "given", "term", "type", "or", "empty", "array", "if", "none", "." ]
5cbf52f20fac8fc84b4b27219073285f06237ed2
https://github.com/optimaize/nameapi-client-php/blob/5cbf52f20fac8fc84b4b27219073285f06237ed2/src/org/nameapi/client/services/parser/OutputPersonName.php#L35-L43
train
optimaize/nameapi-client-php
src/org/nameapi/client/services/parser/OutputPersonName.php
OutputPersonName.getFirst
public function getFirst($termType) { foreach ($this->terms as $term) { if ((string)$term->getTermType() === $termType) { return $term; } } return null; }
php
public function getFirst($termType) { foreach ($this->terms as $term) { if ((string)$term->getTermType() === $termType) { return $term; } } return null; }
[ "public", "function", "getFirst", "(", "$", "termType", ")", "{", "foreach", "(", "$", "this", "->", "terms", "as", "$", "term", ")", "{", "if", "(", "(", "string", ")", "$", "term", "->", "getTermType", "(", ")", "===", "$", "termType", ")", "{", "return", "$", "term", ";", "}", "}", "return", "null", ";", "}" ]
Returns the first term that has the given term type, or null if none. @param string $termType @return Term
[ "Returns", "the", "first", "term", "that", "has", "the", "given", "term", "type", "or", "null", "if", "none", "." ]
5cbf52f20fac8fc84b4b27219073285f06237ed2
https://github.com/optimaize/nameapi-client-php/blob/5cbf52f20fac8fc84b4b27219073285f06237ed2/src/org/nameapi/client/services/parser/OutputPersonName.php#L50-L57
train
LucidTaZ/yii2-scssphp
src/ScssAssetConverter.php
ScssAssetConverter.convert
public function convert($asset, $basePath) { $extension = $this->getExtension($asset); if ($extension !== 'scss') { return $asset; } $cssAsset = $this->getCssAsset($asset, 'css'); $inFile = "$basePath/$asset"; $outFile = "$basePath/$cssAsset"; $this->compiler->setImportPaths(dirname($inFile)); if (!$this->storage->exists($inFile)) { Yii::error("Input file $inFile not found.", __METHOD__); return $asset; } $this->convertAndSaveIfNeeded($inFile, $outFile); return $cssAsset; }
php
public function convert($asset, $basePath) { $extension = $this->getExtension($asset); if ($extension !== 'scss') { return $asset; } $cssAsset = $this->getCssAsset($asset, 'css'); $inFile = "$basePath/$asset"; $outFile = "$basePath/$cssAsset"; $this->compiler->setImportPaths(dirname($inFile)); if (!$this->storage->exists($inFile)) { Yii::error("Input file $inFile not found.", __METHOD__); return $asset; } $this->convertAndSaveIfNeeded($inFile, $outFile); return $cssAsset; }
[ "public", "function", "convert", "(", "$", "asset", ",", "$", "basePath", ")", "{", "$", "extension", "=", "$", "this", "->", "getExtension", "(", "$", "asset", ")", ";", "if", "(", "$", "extension", "!==", "'scss'", ")", "{", "return", "$", "asset", ";", "}", "$", "cssAsset", "=", "$", "this", "->", "getCssAsset", "(", "$", "asset", ",", "'css'", ")", ";", "$", "inFile", "=", "\"$basePath/$asset\"", ";", "$", "outFile", "=", "\"$basePath/$cssAsset\"", ";", "$", "this", "->", "compiler", "->", "setImportPaths", "(", "dirname", "(", "$", "inFile", ")", ")", ";", "if", "(", "!", "$", "this", "->", "storage", "->", "exists", "(", "$", "inFile", ")", ")", "{", "Yii", "::", "error", "(", "\"Input file $inFile not found.\"", ",", "__METHOD__", ")", ";", "return", "$", "asset", ";", "}", "$", "this", "->", "convertAndSaveIfNeeded", "(", "$", "inFile", ",", "$", "outFile", ")", ";", "return", "$", "cssAsset", ";", "}" ]
Converts a given SCSS asset file into a CSS file. @param string $asset the asset file path, relative to $basePath @param string $basePath the directory the $asset is relative to. @return string the converted asset file path, relative to $basePath.
[ "Converts", "a", "given", "SCSS", "asset", "file", "into", "a", "CSS", "file", "." ]
371e8e45dd98e08ccba76c7eabc4653334f1c517
https://github.com/LucidTaZ/yii2-scssphp/blob/371e8e45dd98e08ccba76c7eabc4653334f1c517/src/ScssAssetConverter.php#L53-L74
train
LucidTaZ/yii2-scssphp
src/ScssAssetConverter.php
ScssAssetConverter.getCssAsset
protected function getCssAsset(string $filename, string $newExtension): string { $extensionlessFilename = pathinfo($filename, PATHINFO_FILENAME); /** @var int $filenamePosition */ $filenamePosition = strrpos($filename, $extensionlessFilename); $relativePath = substr($filename, 0, $filenamePosition); return "$relativePath$extensionlessFilename.$newExtension"; }
php
protected function getCssAsset(string $filename, string $newExtension): string { $extensionlessFilename = pathinfo($filename, PATHINFO_FILENAME); /** @var int $filenamePosition */ $filenamePosition = strrpos($filename, $extensionlessFilename); $relativePath = substr($filename, 0, $filenamePosition); return "$relativePath$extensionlessFilename.$newExtension"; }
[ "protected", "function", "getCssAsset", "(", "string", "$", "filename", ",", "string", "$", "newExtension", ")", ":", "string", "{", "$", "extensionlessFilename", "=", "pathinfo", "(", "$", "filename", ",", "PATHINFO_FILENAME", ")", ";", "/** @var int $filenamePosition */", "$", "filenamePosition", "=", "strrpos", "(", "$", "filename", ",", "$", "extensionlessFilename", ")", ";", "$", "relativePath", "=", "substr", "(", "$", "filename", ",", "0", ",", "$", "filenamePosition", ")", ";", "return", "\"$relativePath$extensionlessFilename.$newExtension\"", ";", "}" ]
Get the relative path and filename of the asset @param string $filename e.g. path/asset.css @param string $newExtension e.g. scss @return string e.g. path/asset.scss
[ "Get", "the", "relative", "path", "and", "filename", "of", "the", "asset" ]
371e8e45dd98e08ccba76c7eabc4653334f1c517
https://github.com/LucidTaZ/yii2-scssphp/blob/371e8e45dd98e08ccba76c7eabc4653334f1c517/src/ScssAssetConverter.php#L87-L94
train
core23/AntiSpamBundle
src/Provider/SessionTimeProvider.php
SessionTimeProvider.hasFormProtection
private function hasFormProtection(string $name): bool { $key = $this->getSessionKey($name); return $this->session->has($key); }
php
private function hasFormProtection(string $name): bool { $key = $this->getSessionKey($name); return $this->session->has($key); }
[ "private", "function", "hasFormProtection", "(", "string", "$", "name", ")", ":", "bool", "{", "$", "key", "=", "$", "this", "->", "getSessionKey", "(", "$", "name", ")", ";", "return", "$", "this", "->", "session", "->", "has", "(", "$", "key", ")", ";", "}" ]
Check if a form has a time protection. @param string $name @return bool
[ "Check", "if", "a", "form", "has", "a", "time", "protection", "." ]
849fc7394c36c94594eb3e79afe2747c7872989c
https://github.com/core23/AntiSpamBundle/blob/849fc7394c36c94594eb3e79afe2747c7872989c/src/Provider/SessionTimeProvider.php#L92-L97
train
core23/AntiSpamBundle
src/Provider/SessionTimeProvider.php
SessionTimeProvider.getFormTime
private function getFormTime(string $name): ?DateTime { $key = $this->getSessionKey($name); if ($this->hasFormProtection($name)) { return $this->session->get($key); } return null; }
php
private function getFormTime(string $name): ?DateTime { $key = $this->getSessionKey($name); if ($this->hasFormProtection($name)) { return $this->session->get($key); } return null; }
[ "private", "function", "getFormTime", "(", "string", "$", "name", ")", ":", "?", "DateTime", "{", "$", "key", "=", "$", "this", "->", "getSessionKey", "(", "$", "name", ")", ";", "if", "(", "$", "this", "->", "hasFormProtection", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "session", "->", "get", "(", "$", "key", ")", ";", "}", "return", "null", ";", "}" ]
Gets the form time for specified form. @param string $name Name of form to get @return DateTime|null
[ "Gets", "the", "form", "time", "for", "specified", "form", "." ]
849fc7394c36c94594eb3e79afe2747c7872989c
https://github.com/core23/AntiSpamBundle/blob/849fc7394c36c94594eb3e79afe2747c7872989c/src/Provider/SessionTimeProvider.php#L106-L115
train
localheinz/json-normalizer
src/Json.php
Json.format
public function format(): Format\Format { if (null === $this->format) { $this->format = Format\Format::fromJson($this); } return $this->format; }
php
public function format(): Format\Format { if (null === $this->format) { $this->format = Format\Format::fromJson($this); } return $this->format; }
[ "public", "function", "format", "(", ")", ":", "Format", "\\", "Format", "{", "if", "(", "null", "===", "$", "this", "->", "format", ")", "{", "$", "this", "->", "format", "=", "Format", "\\", "Format", "::", "fromJson", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "format", ";", "}" ]
Returns the format of the original JSON value. @return Format\Format
[ "Returns", "the", "format", "of", "the", "original", "JSON", "value", "." ]
fda4072ade8958186c596ba78f11db08c742aa72
https://github.com/localheinz/json-normalizer/blob/fda4072ade8958186c596ba78f11db08c742aa72/src/Json.php#L95-L102
train
hiqdev/yii2-cart
src/ShoppingCart.php
ShoppingCart.setSerialized
public function setSerialized($serialized) { try { parent::setSerialized($serialized); } catch (\Exception $e) { Yii::error('Failed to unserlialize cart: ' . $e->getMessage(), __METHOD__); $this->_positions = []; $this->saveToSession(); } }
php
public function setSerialized($serialized) { try { parent::setSerialized($serialized); } catch (\Exception $e) { Yii::error('Failed to unserlialize cart: ' . $e->getMessage(), __METHOD__); $this->_positions = []; $this->saveToSession(); } }
[ "public", "function", "setSerialized", "(", "$", "serialized", ")", "{", "try", "{", "parent", "::", "setSerialized", "(", "$", "serialized", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "Yii", "::", "error", "(", "'Failed to unserlialize cart: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "__METHOD__", ")", ";", "$", "this", "->", "_positions", "=", "[", "]", ";", "$", "this", "->", "saveToSession", "(", ")", ";", "}", "}" ]
Sets cart from serialized string @param string $serialized
[ "Sets", "cart", "from", "serialized", "string" ]
de138048f7ef5c3b09a89d905000b96bec768dd8
https://github.com/hiqdev/yii2-cart/blob/de138048f7ef5c3b09a89d905000b96bec768dd8/src/ShoppingCart.php#L79-L88
train
carono/php-commerceml
src/CommerceML.php
CommerceML.addXmls
public function addXmls($importXml = false, $offersXml = false, $ordersXml = false) { $this->loadImportXml($importXml); $this->loadOffersXml($offersXml); $this->loadOrdersXml($ordersXml); }
php
public function addXmls($importXml = false, $offersXml = false, $ordersXml = false) { $this->loadImportXml($importXml); $this->loadOffersXml($offersXml); $this->loadOrdersXml($ordersXml); }
[ "public", "function", "addXmls", "(", "$", "importXml", "=", "false", ",", "$", "offersXml", "=", "false", ",", "$", "ordersXml", "=", "false", ")", "{", "$", "this", "->", "loadImportXml", "(", "$", "importXml", ")", ";", "$", "this", "->", "loadOffersXml", "(", "$", "offersXml", ")", ";", "$", "this", "->", "loadOrdersXml", "(", "$", "ordersXml", ")", ";", "}" ]
Add XML files. @param string|bool $importXml @param string|bool $offersXml @param bool $ordersXml
[ "Add", "XML", "files", "." ]
3f2121b92df7981a4081c2fd06abb4998ac33166
https://github.com/carono/php-commerceml/blob/3f2121b92df7981a4081c2fd06abb4998ac33166/src/CommerceML.php#L57-L62
train
sandfoxme/bencode
src/Engine/Decoder.php
Decoder.push
private function push(int $newState) { array_push($this->stateStack, $this->state); $this->state = $newState; if ($this->state !== self::STATE_ROOT) { array_push($this->valueStack, $this->value); } $this->value = []; }
php
private function push(int $newState) { array_push($this->stateStack, $this->state); $this->state = $newState; if ($this->state !== self::STATE_ROOT) { array_push($this->valueStack, $this->value); } $this->value = []; }
[ "private", "function", "push", "(", "int", "$", "newState", ")", "{", "array_push", "(", "$", "this", "->", "stateStack", ",", "$", "this", "->", "state", ")", ";", "$", "this", "->", "state", "=", "$", "newState", ";", "if", "(", "$", "this", "->", "state", "!==", "self", "::", "STATE_ROOT", ")", "{", "array_push", "(", "$", "this", "->", "valueStack", ",", "$", "this", "->", "value", ")", ";", "}", "$", "this", "->", "value", "=", "[", "]", ";", "}" ]
Push previous layer to the stack and set new state @param int $newState
[ "Push", "previous", "layer", "to", "the", "stack", "and", "set", "new", "state" ]
ede63d107e9b39c73db630746ff29ad56fce73fd
https://github.com/sandfoxme/bencode/blob/ede63d107e9b39c73db630746ff29ad56fce73fd/src/Engine/Decoder.php#L229-L238
train
sandfoxme/bencode
src/Engine/Decoder.php
Decoder.pop
private function pop($valueToPrevLevel) { $this->state = array_pop($this->stateStack); if ($this->state !== self::STATE_ROOT) { $this->value = array_pop($this->valueStack); $this->value []= $valueToPrevLevel; } else { // we have final result $this->decoded = $valueToPrevLevel; } }
php
private function pop($valueToPrevLevel) { $this->state = array_pop($this->stateStack); if ($this->state !== self::STATE_ROOT) { $this->value = array_pop($this->valueStack); $this->value []= $valueToPrevLevel; } else { // we have final result $this->decoded = $valueToPrevLevel; } }
[ "private", "function", "pop", "(", "$", "valueToPrevLevel", ")", "{", "$", "this", "->", "state", "=", "array_pop", "(", "$", "this", "->", "stateStack", ")", ";", "if", "(", "$", "this", "->", "state", "!==", "self", "::", "STATE_ROOT", ")", "{", "$", "this", "->", "value", "=", "array_pop", "(", "$", "this", "->", "valueStack", ")", ";", "$", "this", "->", "value", "[", "]", "=", "$", "valueToPrevLevel", ";", "}", "else", "{", "// we have final result", "$", "this", "->", "decoded", "=", "$", "valueToPrevLevel", ";", "}", "}" ]
Pop previous layer from the stack and give it a parsed value @param mixed $valueToPrevLevel
[ "Pop", "previous", "layer", "from", "the", "stack", "and", "give", "it", "a", "parsed", "value" ]
ede63d107e9b39c73db630746ff29ad56fce73fd
https://github.com/sandfoxme/bencode/blob/ede63d107e9b39c73db630746ff29ad56fce73fd/src/Engine/Decoder.php#L244-L255
train
core23/AntiSpamBundle
src/Twig/Extension/StringTwigExtension.php
StringTwigExtension.antispam
public function antispam(string $string, bool $html = true): string { if ($html) { return preg_replace_callback(self::MAIL_HTML_PATTERN, [$this, 'encryptMail'], $string) ?: ''; } return preg_replace_callback(self::MAIL_TEXT_PATTERN, [$this, 'encryptMailText'], $string) ?: ''; }
php
public function antispam(string $string, bool $html = true): string { if ($html) { return preg_replace_callback(self::MAIL_HTML_PATTERN, [$this, 'encryptMail'], $string) ?: ''; } return preg_replace_callback(self::MAIL_TEXT_PATTERN, [$this, 'encryptMailText'], $string) ?: ''; }
[ "public", "function", "antispam", "(", "string", "$", "string", ",", "bool", "$", "html", "=", "true", ")", ":", "string", "{", "if", "(", "$", "html", ")", "{", "return", "preg_replace_callback", "(", "self", "::", "MAIL_HTML_PATTERN", ",", "[", "$", "this", ",", "'encryptMail'", "]", ",", "$", "string", ")", "?", ":", "''", ";", "}", "return", "preg_replace_callback", "(", "self", "::", "MAIL_TEXT_PATTERN", ",", "[", "$", "this", ",", "'encryptMailText'", "]", ",", "$", "string", ")", "?", ":", "''", ";", "}" ]
Replaces E-Mail addresses with an alternative text representation. @param string $string input string @param bool $html Secure html or text @return string with replaced links
[ "Replaces", "E", "-", "Mail", "addresses", "with", "an", "alternative", "text", "representation", "." ]
849fc7394c36c94594eb3e79afe2747c7872989c
https://github.com/core23/AntiSpamBundle/blob/849fc7394c36c94594eb3e79afe2747c7872989c/src/Twig/Extension/StringTwigExtension.php#L69-L76
train
rinvex/cortex-categories
src/Http/Controllers/Adminarea/CategoriesController.php
CategoriesController.import
public function import(Category $category, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $category, 'tabs' => 'adminarea.categories.tabs', 'url' => route('adminarea.categories.stash'), 'id' => "adminarea-categories-{$category->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function import(Category $category, ImportRecordsDataTable $importRecordsDataTable) { return $importRecordsDataTable->with([ 'resource' => $category, 'tabs' => 'adminarea.categories.tabs', 'url' => route('adminarea.categories.stash'), 'id' => "adminarea-categories-{$category->getRouteKey()}-import-table", ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "import", "(", "Category", "$", "category", ",", "ImportRecordsDataTable", "$", "importRecordsDataTable", ")", "{", "return", "$", "importRecordsDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "category", ",", "'tabs'", "=>", "'adminarea.categories.tabs'", ",", "'url'", "=>", "route", "(", "'adminarea.categories.stash'", ")", ",", "'id'", "=>", "\"adminarea-categories-{$category->getRouteKey()}-import-table\"", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
Import categories. @param \Cortex\Categories\Models\Category $category @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable @return \Illuminate\View\View
[ "Import", "categories", "." ]
f5465b052f5eb3dbf918cadad26be8583d254fb7
https://github.com/rinvex/cortex-categories/blob/f5465b052f5eb3dbf918cadad26be8583d254fb7/src/Http/Controllers/Adminarea/CategoriesController.php#L65-L73
train
rinvex/cortex-categories
src/Http/Controllers/Adminarea/CategoriesController.php
CategoriesController.destroy
public function destroy(Category $category) { $category->delete(); return intend([ 'url' => route('adminarea.categories.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])], ]); }
php
public function destroy(Category $category) { $category->delete(); return intend([ 'url' => route('adminarea.categories.index'), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])], ]); }
[ "public", "function", "destroy", "(", "Category", "$", "category", ")", "{", "$", "category", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.categories.index'", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/categories::common.category'", ")", ",", "'identifier'", "=>", "$", "category", "->", "name", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given category. @param \Cortex\Categories\Models\Category $category @throws \Exception @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "category", "." ]
f5465b052f5eb3dbf918cadad26be8583d254fb7
https://github.com/rinvex/cortex-categories/blob/f5465b052f5eb3dbf918cadad26be8583d254fb7/src/Http/Controllers/Adminarea/CategoriesController.php#L206-L214
train
sandfoxme/bencode
src/Bencode.php
Bencode.dump
public static function dump(string $filename, $data, array $options = []): bool { return file_put_contents($filename, self::encode($data, $options)) !== false; }
php
public static function dump(string $filename, $data, array $options = []): bool { return file_put_contents($filename, self::encode($data, $options)) !== false; }
[ "public", "static", "function", "dump", "(", "string", "$", "filename", ",", "$", "data", ",", "array", "$", "options", "=", "[", "]", ")", ":", "bool", "{", "return", "file_put_contents", "(", "$", "filename", ",", "self", "::", "encode", "(", "$", "data", ",", "$", "options", ")", ")", "!==", "false", ";", "}" ]
Dump data to bencoded file @param string $filename @param mixed $data @param array $options @return bool success of file_put_contents
[ "Dump", "data", "to", "bencoded", "file" ]
ede63d107e9b39c73db630746ff29ad56fce73fd
https://github.com/sandfoxme/bencode/blob/ede63d107e9b39c73db630746ff29ad56fce73fd/src/Bencode.php#L48-L51
train
thomaswelton/laravel-gravatar
src/Gravatar.php
Gravatar.image
public function image($email, $alt = null, $attributes = [], $rating = null) { $dimensions = []; if (array_key_exists('width', $attributes)) { $dimensions[] = $attributes['width']; } if (array_key_exists('height', $attributes)) { $dimensions[] = $attributes['height']; } if (count($dimensions) > 0) { $size = min(self::MAX_SIZE, max($dimensions)); } else { $size = $this->defaultSize; } $src = $this->src($email, $size, $rating); if (!array_key_exists('width', $attributes) && !array_key_exists('height', $attributes)) { $attributes['width'] = $this->size; $attributes['height'] = $this->size; } return $this->formatImage($src, $alt, $attributes); }
php
public function image($email, $alt = null, $attributes = [], $rating = null) { $dimensions = []; if (array_key_exists('width', $attributes)) { $dimensions[] = $attributes['width']; } if (array_key_exists('height', $attributes)) { $dimensions[] = $attributes['height']; } if (count($dimensions) > 0) { $size = min(self::MAX_SIZE, max($dimensions)); } else { $size = $this->defaultSize; } $src = $this->src($email, $size, $rating); if (!array_key_exists('width', $attributes) && !array_key_exists('height', $attributes)) { $attributes['width'] = $this->size; $attributes['height'] = $this->size; } return $this->formatImage($src, $alt, $attributes); }
[ "public", "function", "image", "(", "$", "email", ",", "$", "alt", "=", "null", ",", "$", "attributes", "=", "[", "]", ",", "$", "rating", "=", "null", ")", "{", "$", "dimensions", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'width'", ",", "$", "attributes", ")", ")", "{", "$", "dimensions", "[", "]", "=", "$", "attributes", "[", "'width'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'height'", ",", "$", "attributes", ")", ")", "{", "$", "dimensions", "[", "]", "=", "$", "attributes", "[", "'height'", "]", ";", "}", "if", "(", "count", "(", "$", "dimensions", ")", ">", "0", ")", "{", "$", "size", "=", "min", "(", "self", "::", "MAX_SIZE", ",", "max", "(", "$", "dimensions", ")", ")", ";", "}", "else", "{", "$", "size", "=", "$", "this", "->", "defaultSize", ";", "}", "$", "src", "=", "$", "this", "->", "src", "(", "$", "email", ",", "$", "size", ",", "$", "rating", ")", ";", "if", "(", "!", "array_key_exists", "(", "'width'", ",", "$", "attributes", ")", "&&", "!", "array_key_exists", "(", "'height'", ",", "$", "attributes", ")", ")", "{", "$", "attributes", "[", "'width'", "]", "=", "$", "this", "->", "size", ";", "$", "attributes", "[", "'height'", "]", "=", "$", "this", "->", "size", ";", "}", "return", "$", "this", "->", "formatImage", "(", "$", "src", ",", "$", "alt", ",", "$", "attributes", ")", ";", "}" ]
Return the code of HTML image for a Gravatar. @param string $email The email address. @param string $alt The alt attribute for the image. @param array $attributes Override the 'height' and the 'width' of the image if you want. @param null|string $rating Override the default rating if you want to. @return string The code of the HTML image.
[ "Return", "the", "code", "of", "HTML", "image", "for", "a", "Gravatar", "." ]
1d4ef2f18db9f0d3802c312551ffc7204c411589
https://github.com/thomaswelton/laravel-gravatar/blob/1d4ef2f18db9f0d3802c312551ffc7204c411589/src/Gravatar.php#L68-L93
train
thomaswelton/laravel-gravatar
src/Gravatar.php
Gravatar.exists
public function exists($email) { $this->setDefaultImage('404'); $url = $this->buildGravatarURL($email); $headers = get_headers($url, 1); return substr($headers[0], 9, 3) == '200'; }
php
public function exists($email) { $this->setDefaultImage('404'); $url = $this->buildGravatarURL($email); $headers = get_headers($url, 1); return substr($headers[0], 9, 3) == '200'; }
[ "public", "function", "exists", "(", "$", "email", ")", "{", "$", "this", "->", "setDefaultImage", "(", "'404'", ")", ";", "$", "url", "=", "$", "this", "->", "buildGravatarURL", "(", "$", "email", ")", ";", "$", "headers", "=", "get_headers", "(", "$", "url", ",", "1", ")", ";", "return", "substr", "(", "$", "headers", "[", "0", "]", ",", "9", ",", "3", ")", "==", "'200'", ";", "}" ]
Check if a Gravatar image exists. @param string $email The email address. @return bool True if the Gravatar exists, false otherwise.
[ "Check", "if", "a", "Gravatar", "image", "exists", "." ]
1d4ef2f18db9f0d3802c312551ffc7204c411589
https://github.com/thomaswelton/laravel-gravatar/blob/1d4ef2f18db9f0d3802c312551ffc7204c411589/src/Gravatar.php#L102-L110
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.formatLine
protected function formatLine($string, $indent = 0) { return str_repeat($this->spaces, $indent) . $string . $this->linebreak; }
php
protected function formatLine($string, $indent = 0) { return str_repeat($this->spaces, $indent) . $string . $this->linebreak; }
[ "protected", "function", "formatLine", "(", "$", "string", ",", "$", "indent", "=", "0", ")", "{", "return", "str_repeat", "(", "$", "this", "->", "spaces", ",", "$", "indent", ")", ".", "$", "string", ".", "$", "this", "->", "linebreak", ";", "}" ]
Formats a line
[ "Formats", "a", "line" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L149-L152
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.writeObjectInheritance
protected function writeObjectInheritance($object, $parentName) { try { $parent = $this->reflector->getClass($parentName); $longName = $parent->getName(); $this->writeObjectElement($parent); } catch (\Exception $e) { // object is undeclared in data source $parts = explode('\\', $parentName); $shortName = array_pop($parts); $longName = $parentName; $ns = implode($this->namespaceSeparator, $parts); if (!isset($this->objects[$ns])) { $this->objects[$ns] = array(); } if (!array_key_exists($shortName, $this->objects[$ns])) { $type = $object->isInterface() ? 'interface' : 'class'; $this->pushObject($ns, $shortName, $longName, $type); } } $this->pushEdge(array($object->getName(), $longName)); }
php
protected function writeObjectInheritance($object, $parentName) { try { $parent = $this->reflector->getClass($parentName); $longName = $parent->getName(); $this->writeObjectElement($parent); } catch (\Exception $e) { // object is undeclared in data source $parts = explode('\\', $parentName); $shortName = array_pop($parts); $longName = $parentName; $ns = implode($this->namespaceSeparator, $parts); if (!isset($this->objects[$ns])) { $this->objects[$ns] = array(); } if (!array_key_exists($shortName, $this->objects[$ns])) { $type = $object->isInterface() ? 'interface' : 'class'; $this->pushObject($ns, $shortName, $longName, $type); } } $this->pushEdge(array($object->getName(), $longName)); }
[ "protected", "function", "writeObjectInheritance", "(", "$", "object", ",", "$", "parentName", ")", "{", "try", "{", "$", "parent", "=", "$", "this", "->", "reflector", "->", "getClass", "(", "$", "parentName", ")", ";", "$", "longName", "=", "$", "parent", "->", "getName", "(", ")", ";", "$", "this", "->", "writeObjectElement", "(", "$", "parent", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// object is undeclared in data source", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "parentName", ")", ";", "$", "shortName", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "longName", "=", "$", "parentName", ";", "$", "ns", "=", "implode", "(", "$", "this", "->", "namespaceSeparator", ",", "$", "parts", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "objects", "[", "$", "ns", "]", ")", ")", "{", "$", "this", "->", "objects", "[", "$", "ns", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "shortName", ",", "$", "this", "->", "objects", "[", "$", "ns", "]", ")", ")", "{", "$", "type", "=", "$", "object", "->", "isInterface", "(", ")", "?", "'interface'", ":", "'class'", ";", "$", "this", "->", "pushObject", "(", "$", "ns", ",", "$", "shortName", ",", "$", "longName", ",", "$", "type", ")", ";", "}", "}", "$", "this", "->", "pushEdge", "(", "array", "(", "$", "object", "->", "getName", "(", ")", ",", "$", "longName", ")", ")", ";", "}" ]
Prints an object inheritance @param ReflectionClass $object class/interface instance @param string $parentName Fully qualified name of the parent @return void
[ "Prints", "an", "object", "inheritance" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L207-L233
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.writeObjectInterfaces
protected function writeObjectInterfaces($object, $interfaces) { foreach ($interfaces as $interfaceName) { try { $interface = $this->reflector->getClass($interfaceName); $longName = $interface->getName(); $this->writeObjectElement($interface); } catch (\Exception $e) { // interface is undeclared in data source $parts = explode('\\', $interfaceName); $shortName = array_pop($parts); $longName = $interfaceName; $ns = implode($this->namespaceSeparator, $parts); if (!isset($this->objects[$ns])) { $this->objects[$ns] = array(); } if (!array_key_exists($shortName, $this->objects[$ns])) { $this->pushObject($ns, $shortName, $longName, 'interface'); } } $this->pushEdge( array($object->getName(), $longName), array('arrowhead' => 'empty', 'style' => 'dashed') ); } }
php
protected function writeObjectInterfaces($object, $interfaces) { foreach ($interfaces as $interfaceName) { try { $interface = $this->reflector->getClass($interfaceName); $longName = $interface->getName(); $this->writeObjectElement($interface); } catch (\Exception $e) { // interface is undeclared in data source $parts = explode('\\', $interfaceName); $shortName = array_pop($parts); $longName = $interfaceName; $ns = implode($this->namespaceSeparator, $parts); if (!isset($this->objects[$ns])) { $this->objects[$ns] = array(); } if (!array_key_exists($shortName, $this->objects[$ns])) { $this->pushObject($ns, $shortName, $longName, 'interface'); } } $this->pushEdge( array($object->getName(), $longName), array('arrowhead' => 'empty', 'style' => 'dashed') ); } }
[ "protected", "function", "writeObjectInterfaces", "(", "$", "object", ",", "$", "interfaces", ")", "{", "foreach", "(", "$", "interfaces", "as", "$", "interfaceName", ")", "{", "try", "{", "$", "interface", "=", "$", "this", "->", "reflector", "->", "getClass", "(", "$", "interfaceName", ")", ";", "$", "longName", "=", "$", "interface", "->", "getName", "(", ")", ";", "$", "this", "->", "writeObjectElement", "(", "$", "interface", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// interface is undeclared in data source", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "interfaceName", ")", ";", "$", "shortName", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "longName", "=", "$", "interfaceName", ";", "$", "ns", "=", "implode", "(", "$", "this", "->", "namespaceSeparator", ",", "$", "parts", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "objects", "[", "$", "ns", "]", ")", ")", "{", "$", "this", "->", "objects", "[", "$", "ns", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "shortName", ",", "$", "this", "->", "objects", "[", "$", "ns", "]", ")", ")", "{", "$", "this", "->", "pushObject", "(", "$", "ns", ",", "$", "shortName", ",", "$", "longName", ",", "'interface'", ")", ";", "}", "}", "$", "this", "->", "pushEdge", "(", "array", "(", "$", "object", "->", "getName", "(", ")", ",", "$", "longName", ")", ",", "array", "(", "'arrowhead'", "=>", "'empty'", ",", "'style'", "=>", "'dashed'", ")", ")", ";", "}", "}" ]
Prints interfaces that implement an object @param ReflectionClass $object class/interface instance @param array $interfaces Names of each interface implemented @return void
[ "Prints", "interfaces", "that", "implement", "an", "object" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L243-L273
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.writeConstantElements
protected function writeConstantElements($constants, $format = '%s %s\l', $indent = -1) { $constantString = ''; foreach ($constants as $name => $value) { $line = sprintf($format, '+', $name); if ($indent >= 0) { $constantString .= $this->formatLine($line, $indent); } else { $constantString .= $line; } } return $constantString; }
php
protected function writeConstantElements($constants, $format = '%s %s\l', $indent = -1) { $constantString = ''; foreach ($constants as $name => $value) { $line = sprintf($format, '+', $name); if ($indent >= 0) { $constantString .= $this->formatLine($line, $indent); } else { $constantString .= $line; } } return $constantString; }
[ "protected", "function", "writeConstantElements", "(", "$", "constants", ",", "$", "format", "=", "'%s %s\\l'", ",", "$", "indent", "=", "-", "1", ")", "{", "$", "constantString", "=", "''", ";", "foreach", "(", "$", "constants", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "line", "=", "sprintf", "(", "$", "format", ",", "'+'", ",", "$", "name", ")", ";", "if", "(", "$", "indent", ">=", "0", ")", "{", "$", "constantString", ".=", "$", "this", "->", "formatLine", "(", "$", "line", ",", "$", "indent", ")", ";", "}", "else", "{", "$", "constantString", ".=", "$", "line", ";", "}", "}", "return", "$", "constantString", ";", "}" ]
Prints class constants @param ReflectionConstant[] $constants List of constant instance @param string $format (optional) Constant formatter @param int $indent (optional) Indent multiplier @return string
[ "Prints", "class", "constants" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L284-L297
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.writePropertyElements
protected function writePropertyElements($properties, $format = '%s %s\l', $indent = -1) { $propertyString = ''; foreach ($properties as $property) { if ($property->isPrivate()) { $visibility = '-'; } elseif ($property->isProtected()) { $visibility = '#'; } else { $visibility = '+'; } $line = sprintf( $format, $visibility, $property->getName() ); if ($indent >= 0) { $propertyString .= $this->formatLine($line, $indent); } else { $propertyString .= $line; } } return $propertyString; }
php
protected function writePropertyElements($properties, $format = '%s %s\l', $indent = -1) { $propertyString = ''; foreach ($properties as $property) { if ($property->isPrivate()) { $visibility = '-'; } elseif ($property->isProtected()) { $visibility = '#'; } else { $visibility = '+'; } $line = sprintf( $format, $visibility, $property->getName() ); if ($indent >= 0) { $propertyString .= $this->formatLine($line, $indent); } else { $propertyString .= $line; } } return $propertyString; }
[ "protected", "function", "writePropertyElements", "(", "$", "properties", ",", "$", "format", "=", "'%s %s\\l'", ",", "$", "indent", "=", "-", "1", ")", "{", "$", "propertyString", "=", "''", ";", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "if", "(", "$", "property", "->", "isPrivate", "(", ")", ")", "{", "$", "visibility", "=", "'-'", ";", "}", "elseif", "(", "$", "property", "->", "isProtected", "(", ")", ")", "{", "$", "visibility", "=", "'#'", ";", "}", "else", "{", "$", "visibility", "=", "'+'", ";", "}", "$", "line", "=", "sprintf", "(", "$", "format", ",", "$", "visibility", ",", "$", "property", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "indent", ">=", "0", ")", "{", "$", "propertyString", ".=", "$", "this", "->", "formatLine", "(", "$", "line", ",", "$", "indent", ")", ";", "}", "else", "{", "$", "propertyString", ".=", "$", "line", ";", "}", "}", "return", "$", "propertyString", ";", "}" ]
Prints class properties @param ReflectionProperty[] $properties List of property instance @param string $format (optional) Property formatter @param int $indent (optional) Indent multiplier @return string
[ "Prints", "class", "properties" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L308-L333
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/AbstractProcessor.php
AbstractProcessor.writeMethodElements
protected function writeMethodElements($methods, $format = '%s %s()\l', $indent = -1) { $methodString = ''; foreach ($methods as $method) { if ($method->isPrivate()) { $visibility = '-'; } elseif ($method->isProtected()) { $visibility = '#'; } else { $visibility = '+'; } if ($method->isStatic()) { $modifier = '<u>%s</u>'; } elseif ($method->isAbstract()) { $modifier = '<i>%s</i>'; } else { $modifier = '%s'; } $line = sprintf( $format, $visibility, sprintf($modifier, $method->getShortName()) ); if ($indent >= 0) { $methodString .= $this->formatLine($line, $indent); } else { $methodString .= $line; } } return $methodString; }
php
protected function writeMethodElements($methods, $format = '%s %s()\l', $indent = -1) { $methodString = ''; foreach ($methods as $method) { if ($method->isPrivate()) { $visibility = '-'; } elseif ($method->isProtected()) { $visibility = '#'; } else { $visibility = '+'; } if ($method->isStatic()) { $modifier = '<u>%s</u>'; } elseif ($method->isAbstract()) { $modifier = '<i>%s</i>'; } else { $modifier = '%s'; } $line = sprintf( $format, $visibility, sprintf($modifier, $method->getShortName()) ); if ($indent >= 0) { $methodString .= $this->formatLine($line, $indent); } else { $methodString .= $line; } } return $methodString; }
[ "protected", "function", "writeMethodElements", "(", "$", "methods", ",", "$", "format", "=", "'%s %s()\\l'", ",", "$", "indent", "=", "-", "1", ")", "{", "$", "methodString", "=", "''", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "$", "method", "->", "isPrivate", "(", ")", ")", "{", "$", "visibility", "=", "'-'", ";", "}", "elseif", "(", "$", "method", "->", "isProtected", "(", ")", ")", "{", "$", "visibility", "=", "'#'", ";", "}", "else", "{", "$", "visibility", "=", "'+'", ";", "}", "if", "(", "$", "method", "->", "isStatic", "(", ")", ")", "{", "$", "modifier", "=", "'<u>%s</u>'", ";", "}", "elseif", "(", "$", "method", "->", "isAbstract", "(", ")", ")", "{", "$", "modifier", "=", "'<i>%s</i>'", ";", "}", "else", "{", "$", "modifier", "=", "'%s'", ";", "}", "$", "line", "=", "sprintf", "(", "$", "format", ",", "$", "visibility", ",", "sprintf", "(", "$", "modifier", ",", "$", "method", "->", "getShortName", "(", ")", ")", ")", ";", "if", "(", "$", "indent", ">=", "0", ")", "{", "$", "methodString", ".=", "$", "this", "->", "formatLine", "(", "$", "line", ",", "$", "indent", ")", ";", "}", "else", "{", "$", "methodString", ".=", "$", "line", ";", "}", "}", "return", "$", "methodString", ";", "}" ]
Prints class methods @param ReflectionMethod[] $methods List of method instance @param string $format (optional) Method formatter @param int $indent (optional) Indent multiplier @return string
[ "Prints", "class", "methods" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/AbstractProcessor.php#L344-L377
train
llaville/umlwriter
src/Bartlett/UmlWriter/Processor/GraphvizProcessor.php
GraphvizProcessor.writeGraphHeader
protected function writeGraphHeader() { $nodeAttributes = array( 'fontname' => "Verdana", 'fontsize' => 8, 'shape' => "none", 'margin' => 0, 'fillcolor' => '#FEFECE', 'style' => 'filled', ); $edgeAttributes = array( 'fontname' => "Verdana", 'fontsize' => 8, ); $indent = 1; $graph = $this->formatLine('digraph ' . $this->graphId . ' {'); $graph .= $this->formatLine('overlap = false;', $indent); $graph .= $this->formatLine('node [' . $this->attributes($nodeAttributes) . '];', $indent); $graph .= $this->formatLine('edge [' . $this->attributes($edgeAttributes) . '];', $indent); return $graph; }
php
protected function writeGraphHeader() { $nodeAttributes = array( 'fontname' => "Verdana", 'fontsize' => 8, 'shape' => "none", 'margin' => 0, 'fillcolor' => '#FEFECE', 'style' => 'filled', ); $edgeAttributes = array( 'fontname' => "Verdana", 'fontsize' => 8, ); $indent = 1; $graph = $this->formatLine('digraph ' . $this->graphId . ' {'); $graph .= $this->formatLine('overlap = false;', $indent); $graph .= $this->formatLine('node [' . $this->attributes($nodeAttributes) . '];', $indent); $graph .= $this->formatLine('edge [' . $this->attributes($edgeAttributes) . '];', $indent); return $graph; }
[ "protected", "function", "writeGraphHeader", "(", ")", "{", "$", "nodeAttributes", "=", "array", "(", "'fontname'", "=>", "\"Verdana\"", ",", "'fontsize'", "=>", "8", ",", "'shape'", "=>", "\"none\"", ",", "'margin'", "=>", "0", ",", "'fillcolor'", "=>", "'#FEFECE'", ",", "'style'", "=>", "'filled'", ",", ")", ";", "$", "edgeAttributes", "=", "array", "(", "'fontname'", "=>", "\"Verdana\"", ",", "'fontsize'", "=>", "8", ",", ")", ";", "$", "indent", "=", "1", ";", "$", "graph", "=", "$", "this", "->", "formatLine", "(", "'digraph '", ".", "$", "this", "->", "graphId", ".", "' {'", ")", ";", "$", "graph", ".=", "$", "this", "->", "formatLine", "(", "'overlap = false;'", ",", "$", "indent", ")", ";", "$", "graph", ".=", "$", "this", "->", "formatLine", "(", "'node ['", ".", "$", "this", "->", "attributes", "(", "$", "nodeAttributes", ")", ".", "'];'", ",", "$", "indent", ")", ";", "$", "graph", ".=", "$", "this", "->", "formatLine", "(", "'edge ['", ".", "$", "this", "->", "attributes", "(", "$", "edgeAttributes", ")", ".", "'];'", ",", "$", "indent", ")", ";", "return", "$", "graph", ";", "}" ]
Prints header of the main graph @return string
[ "Prints", "header", "of", "the", "main", "graph" ]
52248a8990522e88c91a2b7446406dbb43b3903e
https://github.com/llaville/umlwriter/blob/52248a8990522e88c91a2b7446406dbb43b3903e/src/Bartlett/UmlWriter/Processor/GraphvizProcessor.php#L88-L112
train
rinvex/cortex-foundation
src/Console/Commands/ModuleMakeCommand.php
ModuleMakeCommand.generateSamples
protected function generateSamples(): void { $module = str_after($this->getNameInput(), '/'); $this->call('make:config', ['name' => 'config', '--module' => $this->getNameInput()]); $this->call('make:model', ['name' => 'Example', '--module' => $this->getNameInput()]); $this->call('make:policy', ['name' => 'ExamplePolicy', '--module' => $this->getNameInput()]); $this->call('make:provider', ['name' => ucfirst($module).'ServiceProvider', '--module' => $this->getNameInput()]); $this->call('make:command', ['name' => 'ExampleCommand', '--module' => $this->getNameInput()]); $this->call('make:controller', ['name' => 'ExampleController', '--module' => $this->getNameInput()]); $this->call('make:request', ['name' => 'ExampleRequest', '--module' => $this->getNameInput()]); $this->call('make:middleware', ['name' => 'ExampleMiddleware', '--module' => $this->getNameInput()]); $this->call('make:transformer', ['name' => 'ExampleTransformer', '--model' => 'Example', '--module' => $this->getNameInput()]); $this->call('make:datatable', ['name' => 'ExampleDatatable', '--model' => 'Example', '--transformer' => 'ExampleTransformer', '--module' => $this->getNameInput()]); $this->warn('Optionally create migrations and seeds (it may take some time):'); $this->warn("artisan make:migration create_{$module}_example_table --module {$this->getNameInput()}"); $this->warn("artisan make:seeder ExampleSeeder --module {$this->getNameInput()}"); }
php
protected function generateSamples(): void { $module = str_after($this->getNameInput(), '/'); $this->call('make:config', ['name' => 'config', '--module' => $this->getNameInput()]); $this->call('make:model', ['name' => 'Example', '--module' => $this->getNameInput()]); $this->call('make:policy', ['name' => 'ExamplePolicy', '--module' => $this->getNameInput()]); $this->call('make:provider', ['name' => ucfirst($module).'ServiceProvider', '--module' => $this->getNameInput()]); $this->call('make:command', ['name' => 'ExampleCommand', '--module' => $this->getNameInput()]); $this->call('make:controller', ['name' => 'ExampleController', '--module' => $this->getNameInput()]); $this->call('make:request', ['name' => 'ExampleRequest', '--module' => $this->getNameInput()]); $this->call('make:middleware', ['name' => 'ExampleMiddleware', '--module' => $this->getNameInput()]); $this->call('make:transformer', ['name' => 'ExampleTransformer', '--model' => 'Example', '--module' => $this->getNameInput()]); $this->call('make:datatable', ['name' => 'ExampleDatatable', '--model' => 'Example', '--transformer' => 'ExampleTransformer', '--module' => $this->getNameInput()]); $this->warn('Optionally create migrations and seeds (it may take some time):'); $this->warn("artisan make:migration create_{$module}_example_table --module {$this->getNameInput()}"); $this->warn("artisan make:seeder ExampleSeeder --module {$this->getNameInput()}"); }
[ "protected", "function", "generateSamples", "(", ")", ":", "void", "{", "$", "module", "=", "str_after", "(", "$", "this", "->", "getNameInput", "(", ")", ",", "'/'", ")", ";", "$", "this", "->", "call", "(", "'make:config'", ",", "[", "'name'", "=>", "'config'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:model'", ",", "[", "'name'", "=>", "'Example'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:policy'", ",", "[", "'name'", "=>", "'ExamplePolicy'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:provider'", ",", "[", "'name'", "=>", "ucfirst", "(", "$", "module", ")", ".", "'ServiceProvider'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:command'", ",", "[", "'name'", "=>", "'ExampleCommand'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:controller'", ",", "[", "'name'", "=>", "'ExampleController'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:request'", ",", "[", "'name'", "=>", "'ExampleRequest'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:middleware'", ",", "[", "'name'", "=>", "'ExampleMiddleware'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:transformer'", ",", "[", "'name'", "=>", "'ExampleTransformer'", ",", "'--model'", "=>", "'Example'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "call", "(", "'make:datatable'", ",", "[", "'name'", "=>", "'ExampleDatatable'", ",", "'--model'", "=>", "'Example'", ",", "'--transformer'", "=>", "'ExampleTransformer'", ",", "'--module'", "=>", "$", "this", "->", "getNameInput", "(", ")", "]", ")", ";", "$", "this", "->", "warn", "(", "'Optionally create migrations and seeds (it may take some time):'", ")", ";", "$", "this", "->", "warn", "(", "\"artisan make:migration create_{$module}_example_table --module {$this->getNameInput()}\"", ")", ";", "$", "this", "->", "warn", "(", "\"artisan make:seeder ExampleSeeder --module {$this->getNameInput()}\"", ")", ";", "}" ]
Generate code samples. @return void
[ "Generate", "code", "samples", "." ]
230c100d98131c76f777e5036b3e7cd83af49e6e
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Console/Commands/ModuleMakeCommand.php#L108-L126
train
rinvex/cortex-foundation
src/Console/Commands/ModuleMakeCommand.php
ModuleMakeCommand.processStubs
protected function processStubs($stubs, $path): void { $this->makeDirectory($path); $this->files->copyDirectory($stubs, $path); $files = [ ($phpunit = $path.DIRECTORY_SEPARATOR.'phpunit.xml.dist') => $this->files->get($phpunit), ($composer = $path.DIRECTORY_SEPARATOR.'composer.json') => $this->files->get($composer), ($changelog = $path.DIRECTORY_SEPARATOR.'CHANGELOG.md') => $this->files->get($changelog), ($readme = $path.DIRECTORY_SEPARATOR.'README.md') => $this->files->get($readme), ]; $module = ucfirst(str_after($this->getNameInput(), '/')); $name = implode(' ', array_map('ucfirst', explode('/', $this->getNameInput()))); $jsonNamespace = implode('\\\\', array_map('ucfirst', explode('/', $this->getNameInput()))); foreach ($files as $key => &$file) { $file = str_replace('DummyModuleName', $name, $file); $file = str_replace('Dummy\\\\Module', $jsonNamespace, $file); $file = str_replace('DummyModuleServiceProvider', $jsonNamespace."\\\\Providers\\\\{$module}ServiceProvider", $file); $file = str_replace('dummy/module', $this->getNameInput(), $file); $file = str_replace('dummy-module', str_replace('/', '-', $this->getNameInput()), $file); $file = str_replace('dummy:module', str_replace('/', ':', $this->getNameInput()), $file); $file = str_replace('dummy.module', str_replace('/', '.', $this->getNameInput()), $file); $this->files->put($key, $file); } }
php
protected function processStubs($stubs, $path): void { $this->makeDirectory($path); $this->files->copyDirectory($stubs, $path); $files = [ ($phpunit = $path.DIRECTORY_SEPARATOR.'phpunit.xml.dist') => $this->files->get($phpunit), ($composer = $path.DIRECTORY_SEPARATOR.'composer.json') => $this->files->get($composer), ($changelog = $path.DIRECTORY_SEPARATOR.'CHANGELOG.md') => $this->files->get($changelog), ($readme = $path.DIRECTORY_SEPARATOR.'README.md') => $this->files->get($readme), ]; $module = ucfirst(str_after($this->getNameInput(), '/')); $name = implode(' ', array_map('ucfirst', explode('/', $this->getNameInput()))); $jsonNamespace = implode('\\\\', array_map('ucfirst', explode('/', $this->getNameInput()))); foreach ($files as $key => &$file) { $file = str_replace('DummyModuleName', $name, $file); $file = str_replace('Dummy\\\\Module', $jsonNamespace, $file); $file = str_replace('DummyModuleServiceProvider', $jsonNamespace."\\\\Providers\\\\{$module}ServiceProvider", $file); $file = str_replace('dummy/module', $this->getNameInput(), $file); $file = str_replace('dummy-module', str_replace('/', '-', $this->getNameInput()), $file); $file = str_replace('dummy:module', str_replace('/', ':', $this->getNameInput()), $file); $file = str_replace('dummy.module', str_replace('/', '.', $this->getNameInput()), $file); $this->files->put($key, $file); } }
[ "protected", "function", "processStubs", "(", "$", "stubs", ",", "$", "path", ")", ":", "void", "{", "$", "this", "->", "makeDirectory", "(", "$", "path", ")", ";", "$", "this", "->", "files", "->", "copyDirectory", "(", "$", "stubs", ",", "$", "path", ")", ";", "$", "files", "=", "[", "(", "$", "phpunit", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'phpunit.xml.dist'", ")", "=>", "$", "this", "->", "files", "->", "get", "(", "$", "phpunit", ")", ",", "(", "$", "composer", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'composer.json'", ")", "=>", "$", "this", "->", "files", "->", "get", "(", "$", "composer", ")", ",", "(", "$", "changelog", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'CHANGELOG.md'", ")", "=>", "$", "this", "->", "files", "->", "get", "(", "$", "changelog", ")", ",", "(", "$", "readme", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'README.md'", ")", "=>", "$", "this", "->", "files", "->", "get", "(", "$", "readme", ")", ",", "]", ";", "$", "module", "=", "ucfirst", "(", "str_after", "(", "$", "this", "->", "getNameInput", "(", ")", ",", "'/'", ")", ")", ";", "$", "name", "=", "implode", "(", "' '", ",", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'/'", ",", "$", "this", "->", "getNameInput", "(", ")", ")", ")", ")", ";", "$", "jsonNamespace", "=", "implode", "(", "'\\\\\\\\'", ",", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'/'", ",", "$", "this", "->", "getNameInput", "(", ")", ")", ")", ")", ";", "foreach", "(", "$", "files", "as", "$", "key", "=>", "&", "$", "file", ")", "{", "$", "file", "=", "str_replace", "(", "'DummyModuleName'", ",", "$", "name", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'Dummy\\\\\\\\Module'", ",", "$", "jsonNamespace", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'DummyModuleServiceProvider'", ",", "$", "jsonNamespace", ".", "\"\\\\\\\\Providers\\\\\\\\{$module}ServiceProvider\"", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'dummy/module'", ",", "$", "this", "->", "getNameInput", "(", ")", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'dummy-module'", ",", "str_replace", "(", "'/'", ",", "'-'", ",", "$", "this", "->", "getNameInput", "(", ")", ")", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'dummy:module'", ",", "str_replace", "(", "'/'", ",", "':'", ",", "$", "this", "->", "getNameInput", "(", ")", ")", ",", "$", "file", ")", ";", "$", "file", "=", "str_replace", "(", "'dummy.module'", ",", "str_replace", "(", "'/'", ",", "'.'", ",", "$", "this", "->", "getNameInput", "(", ")", ")", ",", "$", "file", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "key", ",", "$", "file", ")", ";", "}", "}" ]
Process stubs placeholders. @param string $stubs @param string $path @return void
[ "Process", "stubs", "placeholders", "." ]
230c100d98131c76f777e5036b3e7cd83af49e6e
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Console/Commands/ModuleMakeCommand.php#L136-L164
train
rinvex/cortex-foundation
src/Traits/ConsoleMakeModuleCommand.php
ConsoleMakeModuleCommand.rootNamespace
protected function rootNamespace(): string { return $this->rootNamespace ?? $this->rootNamespace = implode('\\', array_map('ucfirst', explode('/', trim($this->moduleName())))); }
php
protected function rootNamespace(): string { return $this->rootNamespace ?? $this->rootNamespace = implode('\\', array_map('ucfirst', explode('/', trim($this->moduleName())))); }
[ "protected", "function", "rootNamespace", "(", ")", ":", "string", "{", "return", "$", "this", "->", "rootNamespace", "??", "$", "this", "->", "rootNamespace", "=", "implode", "(", "'\\\\'", ",", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'/'", ",", "trim", "(", "$", "this", "->", "moduleName", "(", ")", ")", ")", ")", ")", ";", "}" ]
Get the root namespace for the class. @return string
[ "Get", "the", "root", "namespace", "for", "the", "class", "." ]
230c100d98131c76f777e5036b3e7cd83af49e6e
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Traits/ConsoleMakeModuleCommand.php#L50-L53
train
rinvex/cortex-foundation
src/Traits/ConsoleMakeModuleCommand.php
ConsoleMakeModuleCommand.moduleName
protected function moduleName(): string { return $this->moduleName ?? $this->input->getOption('module') ?? $this->moduleName = $this->ask('What is your module?'); }
php
protected function moduleName(): string { return $this->moduleName ?? $this->input->getOption('module') ?? $this->moduleName = $this->ask('What is your module?'); }
[ "protected", "function", "moduleName", "(", ")", ":", "string", "{", "return", "$", "this", "->", "moduleName", "??", "$", "this", "->", "input", "->", "getOption", "(", "'module'", ")", "??", "$", "this", "->", "moduleName", "=", "$", "this", "->", "ask", "(", "'What is your module?'", ")", ";", "}" ]
Get the module name for the class. @return string
[ "Get", "the", "module", "name", "for", "the", "class", "." ]
230c100d98131c76f777e5036b3e7cd83af49e6e
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Traits/ConsoleMakeModuleCommand.php#L60-L63
train
swoft-cloud/swoft-rpc-server
src/Middleware/HandlerAdapterMiddleware.php
HandlerAdapterMiddleware.process
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE); /* @var \Swoft\Rpc\Server\Router\HandlerAdapter $handlerAdapter */ $handlerAdapter = App::getBean('serviceHandlerAdapter'); $response = $handlerAdapter->doHandler($request, $serviceHandler); return $response; }
php
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE); /* @var \Swoft\Rpc\Server\Router\HandlerAdapter $handlerAdapter */ $handlerAdapter = App::getBean('serviceHandlerAdapter'); $response = $handlerAdapter->doHandler($request, $serviceHandler); return $response; }
[ "public", "function", "process", "(", "ServerRequestInterface", "$", "request", ",", "RequestHandlerInterface", "$", "handler", ")", ":", "ResponseInterface", "{", "$", "serviceHandler", "=", "$", "request", "->", "getAttribute", "(", "RouterMiddleware", "::", "ATTRIBUTE", ")", ";", "/* @var \\Swoft\\Rpc\\Server\\Router\\HandlerAdapter $handlerAdapter */", "$", "handlerAdapter", "=", "App", "::", "getBean", "(", "'serviceHandlerAdapter'", ")", ";", "$", "response", "=", "$", "handlerAdapter", "->", "doHandler", "(", "$", "request", ",", "$", "serviceHandler", ")", ";", "return", "$", "response", ";", "}" ]
execute service with handler @param \Psr\Http\Message\ServerRequestInterface $request @param \Psr\Http\Server\RequestHandlerInterface $handler @return \Psr\Http\Message\ResponseInterface
[ "execute", "service", "with", "handler" ]
527ce20421ad46919b16ebdcc12658f0e3807a07
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Middleware/HandlerAdapterMiddleware.php#L27-L36
train
spiral/orm
source/Spiral/ORM/Entities/RecordSource.php
RecordSource.findByPK
public function findByPK($id, array $load = []) { return $this->getSelector()->wherePK($id)->load($load)->findOne(); }
php
public function findByPK($id, array $load = []) { return $this->getSelector()->wherePK($id)->load($load)->findOne(); }
[ "public", "function", "findByPK", "(", "$", "id", ",", "array", "$", "load", "=", "[", "]", ")", "{", "return", "$", "this", "->", "getSelector", "(", ")", "->", "wherePK", "(", "$", "id", ")", "->", "load", "(", "$", "load", ")", "->", "findOne", "(", ")", ";", "}" ]
Find document by it's primary key. @see findOne() @param string|int $id Primary key value. @param array $load Relations to pre-load. @return EntityInterface|Record|null
[ "Find", "document", "by", "it", "s", "primary", "key", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSource.php#L121-L124
train
spiral/orm
source/Spiral/ORM/Entities/RecordSource.php
RecordSource.findOne
public function findOne(array $query = [], array $sortBy = [], array $load = []) { return $this->getSelector()->orderBy($sortBy)->load($load)->findOne($query); }
php
public function findOne(array $query = [], array $sortBy = [], array $load = []) { return $this->getSelector()->orderBy($sortBy)->load($load)->findOne($query); }
[ "public", "function", "findOne", "(", "array", "$", "query", "=", "[", "]", ",", "array", "$", "sortBy", "=", "[", "]", ",", "array", "$", "load", "=", "[", "]", ")", "{", "return", "$", "this", "->", "getSelector", "(", ")", "->", "orderBy", "(", "$", "sortBy", ")", "->", "load", "(", "$", "load", ")", "->", "findOne", "(", "$", "query", ")", ";", "}" ]
Select one document from mongo collection. @param array $query Fields and conditions to query by. @param array $sortBy Always specify sort by to ensure that results are stable. @param array $load Relations to pre-load. @return EntityInterface|Record|null
[ "Select", "one", "document", "from", "mongo", "collection", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSource.php#L135-L138
train
spiral/orm
source/Spiral/ORM/Schemas/RecordSchema.php
RecordSchema.getIndexes
public function getIndexes(): \Generator { $definitions = $this->reflection->getProperty('indexes') ?? []; foreach ($definitions as $definition) { yield $this->castIndex($definition); } }
php
public function getIndexes(): \Generator { $definitions = $this->reflection->getProperty('indexes') ?? []; foreach ($definitions as $definition) { yield $this->castIndex($definition); } }
[ "public", "function", "getIndexes", "(", ")", ":", "\\", "Generator", "{", "$", "definitions", "=", "$", "this", "->", "reflection", "->", "getProperty", "(", "'indexes'", ")", "??", "[", "]", ";", "foreach", "(", "$", "definitions", "as", "$", "definition", ")", "{", "yield", "$", "this", "->", "castIndex", "(", "$", "definition", ")", ";", "}", "}" ]
Returns set of declared indexes. Example: const INDEXES = [ [self::UNIQUE, 'email'], [self::INDEX, 'status', 'balance'], [self::INDEX, 'public_id'] ]; @do generator @return \Generator|IndexDefinition[] @throws DefinitionException
[ "Returns", "set", "of", "declared", "indexes", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RecordSchema.php#L158-L165
train
spiral/orm
source/Spiral/ORM/Schemas/RecordSchema.php
RecordSchema.packDefaults
protected function packDefaults(AbstractTable $table): array { //We need mutators to normalize default values $mutators = $this->buildMutators($table); $defaults = []; foreach ($table->getColumns() as $column) { $field = $column->getName(); $default = $column->getDefaultValue(); //For non null values let's apply mutators to typecast it if (!is_null($default) && !is_object($default) && !$column->isNullable()) { $default = $this->mutateValue($mutators, $field, $default); } $defaults[$field] = $default; } return $defaults; }
php
protected function packDefaults(AbstractTable $table): array { //We need mutators to normalize default values $mutators = $this->buildMutators($table); $defaults = []; foreach ($table->getColumns() as $column) { $field = $column->getName(); $default = $column->getDefaultValue(); //For non null values let's apply mutators to typecast it if (!is_null($default) && !is_object($default) && !$column->isNullable()) { $default = $this->mutateValue($mutators, $field, $default); } $defaults[$field] = $default; } return $defaults; }
[ "protected", "function", "packDefaults", "(", "AbstractTable", "$", "table", ")", ":", "array", "{", "//We need mutators to normalize default values", "$", "mutators", "=", "$", "this", "->", "buildMutators", "(", "$", "table", ")", ";", "$", "defaults", "=", "[", "]", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "field", "=", "$", "column", "->", "getName", "(", ")", ";", "$", "default", "=", "$", "column", "->", "getDefaultValue", "(", ")", ";", "//For non null values let's apply mutators to typecast it", "if", "(", "!", "is_null", "(", "$", "default", ")", "&&", "!", "is_object", "(", "$", "default", ")", "&&", "!", "$", "column", "->", "isNullable", "(", ")", ")", "{", "$", "default", "=", "$", "this", "->", "mutateValue", "(", "$", "mutators", ",", "$", "field", ",", "$", "default", ")", ";", "}", "$", "defaults", "[", "$", "field", "]", "=", "$", "default", ";", "}", "return", "$", "defaults", ";", "}" ]
Generate set of default values to be used by record. @param AbstractTable $table @return array
[ "Generate", "set", "of", "default", "values", "to", "be", "used", "by", "record", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RecordSchema.php#L238-L258
train
spiral/orm
source/Spiral/ORM/Schemas/RecordSchema.php
RecordSchema.mutateValue
protected function mutateValue(array $mutators, string $field, $default) { //Let's process default value using associated setter if (isset($mutators[RecordEntity::MUTATOR_SETTER][$field])) { try { $setter = $mutators[RecordEntity::MUTATOR_SETTER][$field]; $default = call_user_func($setter, $default); return $default; } catch (\Exception $exception) { //Unable to generate default value, use null or empty array as fallback } } if (isset($mutators[RecordEntity::MUTATOR_ACCESSOR][$field])) { $default = $this->accessorDefault( $default, $mutators[RecordEntity::MUTATOR_ACCESSOR][$field] ); return $default; } return $default; }
php
protected function mutateValue(array $mutators, string $field, $default) { //Let's process default value using associated setter if (isset($mutators[RecordEntity::MUTATOR_SETTER][$field])) { try { $setter = $mutators[RecordEntity::MUTATOR_SETTER][$field]; $default = call_user_func($setter, $default); return $default; } catch (\Exception $exception) { //Unable to generate default value, use null or empty array as fallback } } if (isset($mutators[RecordEntity::MUTATOR_ACCESSOR][$field])) { $default = $this->accessorDefault( $default, $mutators[RecordEntity::MUTATOR_ACCESSOR][$field] ); return $default; } return $default; }
[ "protected", "function", "mutateValue", "(", "array", "$", "mutators", ",", "string", "$", "field", ",", "$", "default", ")", "{", "//Let's process default value using associated setter", "if", "(", "isset", "(", "$", "mutators", "[", "RecordEntity", "::", "MUTATOR_SETTER", "]", "[", "$", "field", "]", ")", ")", "{", "try", "{", "$", "setter", "=", "$", "mutators", "[", "RecordEntity", "::", "MUTATOR_SETTER", "]", "[", "$", "field", "]", ";", "$", "default", "=", "call_user_func", "(", "$", "setter", ",", "$", "default", ")", ";", "return", "$", "default", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "//Unable to generate default value, use null or empty array as fallback", "}", "}", "if", "(", "isset", "(", "$", "mutators", "[", "RecordEntity", "::", "MUTATOR_ACCESSOR", "]", "[", "$", "field", "]", ")", ")", "{", "$", "default", "=", "$", "this", "->", "accessorDefault", "(", "$", "default", ",", "$", "mutators", "[", "RecordEntity", "::", "MUTATOR_ACCESSOR", "]", "[", "$", "field", "]", ")", ";", "return", "$", "default", ";", "}", "return", "$", "default", ";", "}" ]
Process value thought associated mutator if any. @param array $mutators @param string $field @param mixed $default @return mixed
[ "Process", "value", "thought", "associated", "mutator", "if", "any", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RecordSchema.php#L396-L420
train
flownative/flow-google-cloudstorage
Classes/Command/GcsCommandController.php
GcsCommandController.republishCommand
public function republishCommand(string $collection = 'persistent'): void { $collectionName = $collection; $collection = $this->resourceManager->getCollection($collectionName); if (!$collection) { $this->outputLine('<error>The collection %s does not exist.</error>', [$collectionName]); exit(1); } $target = $collection->getTarget(); if (!$target instanceof GcsTarget) { $this->outputLine('<error>The target defined in collection %s is not a Google Cloud Storage target.</error>', [$collectionName]); exit(1); } $this->outputLine('Republishing collection ...'); $this->output->progressStart(); try { foreach ($collection->getObjects() as $object) { /** @var StorageObject $object */ $resource = $this->resourceManager->getResourceBySha1($object->getSha1()); if ($resource) { $target->publishResource($resource, $collection); } $this->output->progressAdvance(); } } catch (\Exception $e) { $this->outputLine('<error>Publishing failed</error>'); $this->outputLine($e->getMessage()); $this->outputLine(get_class($e)); exit(2); } $this->output->progressFinish(); $this->outputLine(); }
php
public function republishCommand(string $collection = 'persistent'): void { $collectionName = $collection; $collection = $this->resourceManager->getCollection($collectionName); if (!$collection) { $this->outputLine('<error>The collection %s does not exist.</error>', [$collectionName]); exit(1); } $target = $collection->getTarget(); if (!$target instanceof GcsTarget) { $this->outputLine('<error>The target defined in collection %s is not a Google Cloud Storage target.</error>', [$collectionName]); exit(1); } $this->outputLine('Republishing collection ...'); $this->output->progressStart(); try { foreach ($collection->getObjects() as $object) { /** @var StorageObject $object */ $resource = $this->resourceManager->getResourceBySha1($object->getSha1()); if ($resource) { $target->publishResource($resource, $collection); } $this->output->progressAdvance(); } } catch (\Exception $e) { $this->outputLine('<error>Publishing failed</error>'); $this->outputLine($e->getMessage()); $this->outputLine(get_class($e)); exit(2); } $this->output->progressFinish(); $this->outputLine(); }
[ "public", "function", "republishCommand", "(", "string", "$", "collection", "=", "'persistent'", ")", ":", "void", "{", "$", "collectionName", "=", "$", "collection", ";", "$", "collection", "=", "$", "this", "->", "resourceManager", "->", "getCollection", "(", "$", "collectionName", ")", ";", "if", "(", "!", "$", "collection", ")", "{", "$", "this", "->", "outputLine", "(", "'<error>The collection %s does not exist.</error>'", ",", "[", "$", "collectionName", "]", ")", ";", "exit", "(", "1", ")", ";", "}", "$", "target", "=", "$", "collection", "->", "getTarget", "(", ")", ";", "if", "(", "!", "$", "target", "instanceof", "GcsTarget", ")", "{", "$", "this", "->", "outputLine", "(", "'<error>The target defined in collection %s is not a Google Cloud Storage target.</error>'", ",", "[", "$", "collectionName", "]", ")", ";", "exit", "(", "1", ")", ";", "}", "$", "this", "->", "outputLine", "(", "'Republishing collection ...'", ")", ";", "$", "this", "->", "output", "->", "progressStart", "(", ")", ";", "try", "{", "foreach", "(", "$", "collection", "->", "getObjects", "(", ")", "as", "$", "object", ")", "{", "/** @var StorageObject $object */", "$", "resource", "=", "$", "this", "->", "resourceManager", "->", "getResourceBySha1", "(", "$", "object", "->", "getSha1", "(", ")", ")", ";", "if", "(", "$", "resource", ")", "{", "$", "target", "->", "publishResource", "(", "$", "resource", ",", "$", "collection", ")", ";", "}", "$", "this", "->", "output", "->", "progressAdvance", "(", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "outputLine", "(", "'<error>Publishing failed</error>'", ")", ";", "$", "this", "->", "outputLine", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "$", "this", "->", "outputLine", "(", "get_class", "(", "$", "e", ")", ")", ";", "exit", "(", "2", ")", ";", "}", "$", "this", "->", "output", "->", "progressFinish", "(", ")", ";", "$", "this", "->", "outputLine", "(", ")", ";", "}" ]
Republish a collection This command forces publishing resources of the given collection by copying resources from the respective storage to target bucket. @param string $collection Name of the collection to publish
[ "Republish", "a", "collection" ]
78c76b2a0eb10fa514bbae71f93f351ee58dacd3
https://github.com/flownative/flow-google-cloudstorage/blob/78c76b2a0eb10fa514bbae71f93f351ee58dacd3/Classes/Command/GcsCommandController.php#L91-L125
train
hiqdev/hisite
src/controllers/SiteController.php
SiteController.actionLogout
public function actionLogout() { Yii::$app->user->logout(); $back = Yii::$app->request->post('back') ?: Yii::$app->request->get('back'); return $back ? $this->redirect($back) : $this->goHome(); }
php
public function actionLogout() { Yii::$app->user->logout(); $back = Yii::$app->request->post('back') ?: Yii::$app->request->get('back'); return $back ? $this->redirect($back) : $this->goHome(); }
[ "public", "function", "actionLogout", "(", ")", "{", "Yii", "::", "$", "app", "->", "user", "->", "logout", "(", ")", ";", "$", "back", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'back'", ")", "?", ":", "Yii", "::", "$", "app", "->", "request", "->", "get", "(", "'back'", ")", ";", "return", "$", "back", "?", "$", "this", "->", "redirect", "(", "$", "back", ")", ":", "$", "this", "->", "goHome", "(", ")", ";", "}" ]
Logout action. @return string
[ "Logout", "action", "." ]
5d4a6bad213072c560f64053925cd544ca2cd26a
https://github.com/hiqdev/hisite/blob/5d4a6bad213072c560f64053925cd544ca2cd26a/src/controllers/SiteController.php#L78-L84
train
hiqdev/hisite
src/controllers/SiteController.php
SiteController.actionContact
public function actionContact() { $model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } return $this->render('contact', compact('model')); }
php
public function actionContact() { $model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } return $this->render('contact', compact('model')); }
[ "public", "function", "actionContact", "(", ")", "{", "$", "model", "=", "new", "ContactForm", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "contact", "(", "Yii", "::", "$", "app", "->", "params", "[", "'adminEmail'", "]", ")", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'contactFormSubmitted'", ")", ";", "return", "$", "this", "->", "refresh", "(", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'contact'", ",", "compact", "(", "'model'", ")", ")", ";", "}" ]
Displays contact page and sends contact form. @return string
[ "Displays", "contact", "page", "and", "sends", "contact", "form", "." ]
5d4a6bad213072c560f64053925cd544ca2cd26a
https://github.com/hiqdev/hisite/blob/5d4a6bad213072c560f64053925cd544ca2cd26a/src/controllers/SiteController.php#L90-L100
train
spiral/orm
source/Spiral/ORM/Entities/RelationMap.php
RelationMap.extractRelations
public function extractRelations(array &$data) { //Fetch all relations $relations = array_intersect_key($data, $this->schema); foreach ($relations as $name => $relation) { $this->relations[$name] = $relation; unset($data[$name]); } }
php
public function extractRelations(array &$data) { //Fetch all relations $relations = array_intersect_key($data, $this->schema); foreach ($relations as $name => $relation) { $this->relations[$name] = $relation; unset($data[$name]); } }
[ "public", "function", "extractRelations", "(", "array", "&", "$", "data", ")", "{", "//Fetch all relations", "$", "relations", "=", "array_intersect_key", "(", "$", "data", ",", "$", "this", "->", "schema", ")", ";", "foreach", "(", "$", "relations", "as", "$", "name", "=>", "$", "relation", ")", "{", "$", "this", "->", "relations", "[", "$", "name", "]", "=", "$", "relation", ";", "unset", "(", "$", "data", "[", "$", "name", "]", ")", ";", "}", "}" ]
Extract relations data from given entity fields. @param array $data
[ "Extract", "relations", "data", "from", "given", "entity", "fields", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RelationMap.php#L72-L81
train
spiral/orm
source/Spiral/ORM/Entities/RelationMap.php
RelationMap.queueRelations
public function queueRelations(ContextualCommandInterface $parent): ContextualCommandInterface { if (empty($this->relations)) { //No relations exists, nothing to do return $parent; } //We have to execute multiple commands at once $transaction = new TransactionalCommand(); foreach ($this->leadingRelations() as $relation) { //Generating commands needed to save given relation prior to parent command if ($relation->isLoaded()) { $transaction->addCommand($relation->queueCommands($parent)); } } //Parent model save operations (true state that this is leading/primary command) $transaction->addCommand($parent, true); foreach ($this->dependedRelations() as $relation) { //Generating commands needed to save relations after parent command being executed if ($relation->isLoaded()) { $transaction->addCommand($relation->queueCommands($parent)); } } return $transaction; }
php
public function queueRelations(ContextualCommandInterface $parent): ContextualCommandInterface { if (empty($this->relations)) { //No relations exists, nothing to do return $parent; } //We have to execute multiple commands at once $transaction = new TransactionalCommand(); foreach ($this->leadingRelations() as $relation) { //Generating commands needed to save given relation prior to parent command if ($relation->isLoaded()) { $transaction->addCommand($relation->queueCommands($parent)); } } //Parent model save operations (true state that this is leading/primary command) $transaction->addCommand($parent, true); foreach ($this->dependedRelations() as $relation) { //Generating commands needed to save relations after parent command being executed if ($relation->isLoaded()) { $transaction->addCommand($relation->queueCommands($parent)); } } return $transaction; }
[ "public", "function", "queueRelations", "(", "ContextualCommandInterface", "$", "parent", ")", ":", "ContextualCommandInterface", "{", "if", "(", "empty", "(", "$", "this", "->", "relations", ")", ")", "{", "//No relations exists, nothing to do", "return", "$", "parent", ";", "}", "//We have to execute multiple commands at once", "$", "transaction", "=", "new", "TransactionalCommand", "(", ")", ";", "foreach", "(", "$", "this", "->", "leadingRelations", "(", ")", "as", "$", "relation", ")", "{", "//Generating commands needed to save given relation prior to parent command", "if", "(", "$", "relation", "->", "isLoaded", "(", ")", ")", "{", "$", "transaction", "->", "addCommand", "(", "$", "relation", "->", "queueCommands", "(", "$", "parent", ")", ")", ";", "}", "}", "//Parent model save operations (true state that this is leading/primary command)", "$", "transaction", "->", "addCommand", "(", "$", "parent", ",", "true", ")", ";", "foreach", "(", "$", "this", "->", "dependedRelations", "(", ")", "as", "$", "relation", ")", "{", "//Generating commands needed to save relations after parent command being executed", "if", "(", "$", "relation", "->", "isLoaded", "(", ")", ")", "{", "$", "transaction", "->", "addCommand", "(", "$", "relation", "->", "queueCommands", "(", "$", "parent", ")", ")", ";", "}", "}", "return", "$", "transaction", ";", "}" ]
Generate command tree with or without relation to parent command in order to specify update or insert sequence. Commands might define dependencies between each other in order to extend FK values. @param ContextualCommandInterface $parent @return ContextualCommandInterface
[ "Generate", "command", "tree", "with", "or", "without", "relation", "to", "parent", "command", "in", "order", "to", "specify", "update", "or", "insert", "sequence", ".", "Commands", "might", "define", "dependencies", "between", "each", "other", "in", "order", "to", "extend", "FK", "values", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RelationMap.php#L92-L120
train
spiral/orm
source/Spiral/ORM/Entities/RelationMap.php
RelationMap.get
public function get(string $relation): RelationInterface { if (isset($this->relations[$relation]) && $this->relations[$relation] instanceof RelationInterface) { return $this->relations[$relation]; } $instance = $this->orm->makeRelation($this->class, $relation); if (array_key_exists($relation, $this->relations)) { //Indicating that relation is loaded $instance = $instance->withContext($this->parent, true, $this->relations[$relation]); } else { //Not loaded relation $instance = $instance->withContext($this->parent, false); } return $this->relations[$relation] = $instance; }
php
public function get(string $relation): RelationInterface { if (isset($this->relations[$relation]) && $this->relations[$relation] instanceof RelationInterface) { return $this->relations[$relation]; } $instance = $this->orm->makeRelation($this->class, $relation); if (array_key_exists($relation, $this->relations)) { //Indicating that relation is loaded $instance = $instance->withContext($this->parent, true, $this->relations[$relation]); } else { //Not loaded relation $instance = $instance->withContext($this->parent, false); } return $this->relations[$relation] = $instance; }
[ "public", "function", "get", "(", "string", "$", "relation", ")", ":", "RelationInterface", "{", "if", "(", "isset", "(", "$", "this", "->", "relations", "[", "$", "relation", "]", ")", "&&", "$", "this", "->", "relations", "[", "$", "relation", "]", "instanceof", "RelationInterface", ")", "{", "return", "$", "this", "->", "relations", "[", "$", "relation", "]", ";", "}", "$", "instance", "=", "$", "this", "->", "orm", "->", "makeRelation", "(", "$", "this", "->", "class", ",", "$", "relation", ")", ";", "if", "(", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "relations", ")", ")", "{", "//Indicating that relation is loaded", "$", "instance", "=", "$", "instance", "->", "withContext", "(", "$", "this", "->", "parent", ",", "true", ",", "$", "this", "->", "relations", "[", "$", "relation", "]", ")", ";", "}", "else", "{", "//Not loaded relation", "$", "instance", "=", "$", "instance", "->", "withContext", "(", "$", "this", "->", "parent", ",", "false", ")", ";", "}", "return", "$", "this", "->", "relations", "[", "$", "relation", "]", "=", "$", "instance", ";", "}" ]
Get associated relation instance. @param string $relation @return RelationInterface
[ "Get", "associated", "relation", "instance", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RelationMap.php#L183-L199
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.isJoined
public function isJoined(): bool { if (!empty($this->options['using'])) { return true; } return in_array($this->getMethod(), [self::INLOAD, self::JOIN, self::LEFT_JOIN]); }
php
public function isJoined(): bool { if (!empty($this->options['using'])) { return true; } return in_array($this->getMethod(), [self::INLOAD, self::JOIN, self::LEFT_JOIN]); }
[ "public", "function", "isJoined", "(", ")", ":", "bool", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'using'", "]", ")", ")", "{", "return", "true", ";", "}", "return", "in_array", "(", "$", "this", "->", "getMethod", "(", ")", ",", "[", "self", "::", "INLOAD", ",", "self", "::", "JOIN", ",", "self", "::", "LEFT_JOIN", "]", ")", ";", "}" ]
Indicated that loaded must generate JOIN statement. @return bool
[ "Indicated", "that", "loaded", "must", "generate", "JOIN", "statement", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L109-L116
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.isLoaded
public function isLoaded(): bool { return $this->getMethod() !== self::JOIN && $this->getMethod() !== self::LEFT_JOIN; }
php
public function isLoaded(): bool { return $this->getMethod() !== self::JOIN && $this->getMethod() !== self::LEFT_JOIN; }
[ "public", "function", "isLoaded", "(", ")", ":", "bool", "{", "return", "$", "this", "->", "getMethod", "(", ")", "!==", "self", "::", "JOIN", "&&", "$", "this", "->", "getMethod", "(", ")", "!==", "self", "::", "LEFT_JOIN", ";", "}" ]
Indication that loader want to load data. @return bool
[ "Indication", "that", "loader", "want", "to", "load", "data", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L123-L126
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.configureQuery
protected function configureQuery(SelectQuery $query, bool $loadColumns = true, array $outerKeys = []): SelectQuery { if ($loadColumns) { if ($this->isJoined()) { //Mounting columns $this->mountColumns($query, $this->options['minify']); } else { //This is initial set of columns (remove all existed) $this->mountColumns($query, $this->options['minify'], '', true); } } return parent::configureQuery($query); }
php
protected function configureQuery(SelectQuery $query, bool $loadColumns = true, array $outerKeys = []): SelectQuery { if ($loadColumns) { if ($this->isJoined()) { //Mounting columns $this->mountColumns($query, $this->options['minify']); } else { //This is initial set of columns (remove all existed) $this->mountColumns($query, $this->options['minify'], '', true); } } return parent::configureQuery($query); }
[ "protected", "function", "configureQuery", "(", "SelectQuery", "$", "query", ",", "bool", "$", "loadColumns", "=", "true", ",", "array", "$", "outerKeys", "=", "[", "]", ")", ":", "SelectQuery", "{", "if", "(", "$", "loadColumns", ")", "{", "if", "(", "$", "this", "->", "isJoined", "(", ")", ")", "{", "//Mounting columns", "$", "this", "->", "mountColumns", "(", "$", "query", ",", "$", "this", "->", "options", "[", "'minify'", "]", ")", ";", "}", "else", "{", "//This is initial set of columns (remove all existed)", "$", "this", "->", "mountColumns", "(", "$", "query", ",", "$", "this", "->", "options", "[", "'minify'", "]", ",", "''", ",", "true", ")", ";", "}", "}", "return", "parent", "::", "configureQuery", "(", "$", "query", ")", ";", "}" ]
Configure query with conditions, joins and columns. @param SelectQuery $query @param bool $loadColumns @param array $outerKeys Set of OUTER_KEY values collected by parent loader. @return SelectQuery
[ "Configure", "query", "with", "conditions", "joins", "and", "columns", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L169-L182
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.getAlias
protected function getAlias(): string { if (!empty($this->options['using'])) { //We are using another relation (presumably defined by with() to load data). return $this->options['using']; } if (!empty($this->options['alias'])) { return $this->options['alias']; } throw new LoaderException("Unable to resolve loader alias"); }
php
protected function getAlias(): string { if (!empty($this->options['using'])) { //We are using another relation (presumably defined by with() to load data). return $this->options['using']; } if (!empty($this->options['alias'])) { return $this->options['alias']; } throw new LoaderException("Unable to resolve loader alias"); }
[ "protected", "function", "getAlias", "(", ")", ":", "string", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'using'", "]", ")", ")", "{", "//We are using another relation (presumably defined by with() to load data).", "return", "$", "this", "->", "options", "[", "'using'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'alias'", "]", ")", ")", "{", "return", "$", "this", "->", "options", "[", "'alias'", "]", ";", "}", "throw", "new", "LoaderException", "(", "\"Unable to resolve loader alias\"", ")", ";", "}" ]
Relation table alias. @return string
[ "Relation", "table", "alias", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L189-L201
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.localKey
protected function localKey($key) { if (empty($this->schema[$key])) { return null; } return $this->getAlias() . '.' . $this->schema[$key]; }
php
protected function localKey($key) { if (empty($this->schema[$key])) { return null; } return $this->getAlias() . '.' . $this->schema[$key]; }
[ "protected", "function", "localKey", "(", "$", "key", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "schema", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "getAlias", "(", ")", ".", "'.'", ".", "$", "this", "->", "schema", "[", "$", "key", "]", ";", "}" ]
Generate sql identifier using loader alias and value from relation definition. Key name to be fetched from schema. Example: $this->getKey(Record::OUTER_KEY); @param string $key @return string|null
[ "Generate", "sql", "identifier", "using", "loader", "alias", "and", "value", "from", "relation", "definition", ".", "Key", "name", "to", "be", "fetched", "from", "schema", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L234-L241
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/RelationLoader.php
RelationLoader.ensureAlias
protected function ensureAlias(AbstractLoader $parent) { //Let's calculate loader alias if (empty($this->options['alias'])) { if ($this->isLoaded() && $this->isJoined()) { //Let's create unique alias, we are able to do that for relations just loaded $this->options['alias'] = 'd' . decoct(++self::$countLevels); } else { //Let's use parent alias to continue chain $this->options['alias'] = $parent->getAlias() . '_' . $this->relation; } } }
php
protected function ensureAlias(AbstractLoader $parent) { //Let's calculate loader alias if (empty($this->options['alias'])) { if ($this->isLoaded() && $this->isJoined()) { //Let's create unique alias, we are able to do that for relations just loaded $this->options['alias'] = 'd' . decoct(++self::$countLevels); } else { //Let's use parent alias to continue chain $this->options['alias'] = $parent->getAlias() . '_' . $this->relation; } } }
[ "protected", "function", "ensureAlias", "(", "AbstractLoader", "$", "parent", ")", "{", "//Let's calculate loader alias", "if", "(", "empty", "(", "$", "this", "->", "options", "[", "'alias'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "isLoaded", "(", ")", "&&", "$", "this", "->", "isJoined", "(", ")", ")", "{", "//Let's create unique alias, we are able to do that for relations just loaded", "$", "this", "->", "options", "[", "'alias'", "]", "=", "'d'", ".", "decoct", "(", "++", "self", "::", "$", "countLevels", ")", ";", "}", "else", "{", "//Let's use parent alias to continue chain", "$", "this", "->", "options", "[", "'alias'", "]", "=", "$", "parent", "->", "getAlias", "(", ")", ".", "'_'", ".", "$", "this", "->", "relation", ";", "}", "}", "}" ]
Ensure table alias. @param AbstractLoader $parent
[ "Ensure", "table", "alias", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RelationLoader.php#L260-L272
train
swoft-cloud/swoft-rpc-server
src/Router/HandlerAdapter.php
HandlerAdapter.doHandler
public function doHandler(ServerRequestInterface $request, array $handler): Response { // the function params of service $data = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA); $params = $data['params'] ?? []; list($serviceClass, $method) = $handler; $service = App::getBean($serviceClass); // execute handler with params $response = PhpHelper::call([$service, $method], $params); $response = ResponseHelper::formatData($response); // response if (! $response instanceof Response) { $response = (new Response())->withAttribute(self::ATTRIBUTE, $response); } return $response; }
php
public function doHandler(ServerRequestInterface $request, array $handler): Response { // the function params of service $data = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA); $params = $data['params'] ?? []; list($serviceClass, $method) = $handler; $service = App::getBean($serviceClass); // execute handler with params $response = PhpHelper::call([$service, $method], $params); $response = ResponseHelper::formatData($response); // response if (! $response instanceof Response) { $response = (new Response())->withAttribute(self::ATTRIBUTE, $response); } return $response; }
[ "public", "function", "doHandler", "(", "ServerRequestInterface", "$", "request", ",", "array", "$", "handler", ")", ":", "Response", "{", "// the function params of service", "$", "data", "=", "$", "request", "->", "getAttribute", "(", "PackerMiddleware", "::", "ATTRIBUTE_DATA", ")", ";", "$", "params", "=", "$", "data", "[", "'params'", "]", "??", "[", "]", ";", "list", "(", "$", "serviceClass", ",", "$", "method", ")", "=", "$", "handler", ";", "$", "service", "=", "App", "::", "getBean", "(", "$", "serviceClass", ")", ";", "// execute handler with params", "$", "response", "=", "PhpHelper", "::", "call", "(", "[", "$", "service", ",", "$", "method", "]", ",", "$", "params", ")", ";", "$", "response", "=", "ResponseHelper", "::", "formatData", "(", "$", "response", ")", ";", "// response", "if", "(", "!", "$", "response", "instanceof", "Response", ")", "{", "$", "response", "=", "(", "new", "Response", "(", ")", ")", "->", "withAttribute", "(", "self", "::", "ATTRIBUTE", ",", "$", "response", ")", ";", "}", "return", "$", "response", ";", "}" ]
Execute service handler @param \Psr\Http\Message\ServerRequestInterface $request @param array $handler @return Response
[ "Execute", "service", "handler" ]
527ce20421ad46919b16ebdcc12658f0e3807a07
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Router/HandlerAdapter.php#L32-L51
train
spiral/orm
source/Spiral/ORM/Schemas/Definitions/IndexDefinition.php
IndexDefinition.getName
public function getName(): string { if (!empty($this->name)) { return $this->name; } $name = ($this->isUnique() ? 'unique_' : 'index_') . join('_', $this->getColumns()); return strlen($name) > 64 ? md5($name) : $name; }
php
public function getName(): string { if (!empty($this->name)) { return $this->name; } $name = ($this->isUnique() ? 'unique_' : 'index_') . join('_', $this->getColumns()); return strlen($name) > 64 ? md5($name) : $name; }
[ "public", "function", "getName", "(", ")", ":", "string", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "name", ")", ")", "{", "return", "$", "this", "->", "name", ";", "}", "$", "name", "=", "(", "$", "this", "->", "isUnique", "(", ")", "?", "'unique_'", ":", "'index_'", ")", ".", "join", "(", "'_'", ",", "$", "this", "->", "getColumns", "(", ")", ")", ";", "return", "strlen", "(", "$", "name", ")", ">", "64", "?", "md5", "(", "$", "name", ")", ":", "$", "name", ";", "}" ]
Generate unique index name. @return string
[ "Generate", "unique", "index", "name", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Definitions/IndexDefinition.php#L64-L73
train
spiral/orm
source/Spiral/ORM/Entities/Loaders/Traits/ColumnsTrait.php
ColumnsTrait.mountColumns
protected function mountColumns( SelectQuery $query, bool $minify = false, string $prefix = '', bool $overwrite = false ) { //Column source alias $alias = $this->getAlias(); $columns = $overwrite ? [] : $query->getColumns(); foreach ($this->getColumns() as $name) { $column = $name; if ($minify) { //Let's use column number instead of full name $column = 'c' . count($columns); } $columns[] = "{$alias}.{$name} AS {$prefix}{$column}"; } //Updating column set $query->columns($columns); }
php
protected function mountColumns( SelectQuery $query, bool $minify = false, string $prefix = '', bool $overwrite = false ) { //Column source alias $alias = $this->getAlias(); $columns = $overwrite ? [] : $query->getColumns(); foreach ($this->getColumns() as $name) { $column = $name; if ($minify) { //Let's use column number instead of full name $column = 'c' . count($columns); } $columns[] = "{$alias}.{$name} AS {$prefix}{$column}"; } //Updating column set $query->columns($columns); }
[ "protected", "function", "mountColumns", "(", "SelectQuery", "$", "query", ",", "bool", "$", "minify", "=", "false", ",", "string", "$", "prefix", "=", "''", ",", "bool", "$", "overwrite", "=", "false", ")", "{", "//Column source alias", "$", "alias", "=", "$", "this", "->", "getAlias", "(", ")", ";", "$", "columns", "=", "$", "overwrite", "?", "[", "]", ":", "$", "query", "->", "getColumns", "(", ")", ";", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "name", ")", "{", "$", "column", "=", "$", "name", ";", "if", "(", "$", "minify", ")", "{", "//Let's use column number instead of full name", "$", "column", "=", "'c'", ".", "count", "(", "$", "columns", ")", ";", "}", "$", "columns", "[", "]", "=", "\"{$alias}.{$name} AS {$prefix}{$column}\"", ";", "}", "//Updating column set", "$", "query", "->", "columns", "(", "$", "columns", ")", ";", "}" ]
Set columns into SelectQuery. @param SelectQuery $query @param bool $minify Minify column names (will work in case when query parsed in FETCH_NUM mode). @param string $prefix Prefix to be added for each column name. @param bool $overwrite When set to true existed columns will be removed.
[ "Set", "columns", "into", "SelectQuery", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/Traits/ColumnsTrait.php#L26-L49
train
spiral/orm
source/Spiral/ORM/Schemas/Definitions/RelationDefinition.php
RelationDefinition.withContext
public function withContext(RelationContext $source, RelationContext $target = null): self { $definition = clone $this; $definition->sourceContext = $source; $definition->targetContext = $target; return $definition; }
php
public function withContext(RelationContext $source, RelationContext $target = null): self { $definition = clone $this; $definition->sourceContext = $source; $definition->targetContext = $target; return $definition; }
[ "public", "function", "withContext", "(", "RelationContext", "$", "source", ",", "RelationContext", "$", "target", "=", "null", ")", ":", "self", "{", "$", "definition", "=", "clone", "$", "this", ";", "$", "definition", "->", "sourceContext", "=", "$", "source", ";", "$", "definition", "->", "targetContext", "=", "$", "target", ";", "return", "$", "definition", ";", "}" ]
Set relation contexts. @param RelationContext $source @param RelationContext|null $target @return RelationDefinition
[ "Set", "relation", "contexts", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Definitions/RelationDefinition.php#L160-L167
train
spiral/orm
source/Spiral/ORM/Schemas/SchemaLocator.php
SchemaLocator.locateSchemas
public function locateSchemas(): array { if (!$this->container->has(ClassesInterface::class)) { return []; } /** * @var ClassesInterface $classes */ $classes = $this->container->get(ClassesInterface::class); $schemas = []; foreach ($classes->getClasses(RecordEntity::class) as $class) { if ($class['abstract']) { continue; } $schemas[] = $this->container->get(FactoryInterface::class)->make( RecordSchema::class, ['reflection' => new ReflectionEntity($class['name']),] ); } return $schemas; }
php
public function locateSchemas(): array { if (!$this->container->has(ClassesInterface::class)) { return []; } /** * @var ClassesInterface $classes */ $classes = $this->container->get(ClassesInterface::class); $schemas = []; foreach ($classes->getClasses(RecordEntity::class) as $class) { if ($class['abstract']) { continue; } $schemas[] = $this->container->get(FactoryInterface::class)->make( RecordSchema::class, ['reflection' => new ReflectionEntity($class['name']),] ); } return $schemas; }
[ "public", "function", "locateSchemas", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "container", "->", "has", "(", "ClassesInterface", "::", "class", ")", ")", "{", "return", "[", "]", ";", "}", "/**\n * @var ClassesInterface $classes\n */", "$", "classes", "=", "$", "this", "->", "container", "->", "get", "(", "ClassesInterface", "::", "class", ")", ";", "$", "schemas", "=", "[", "]", ";", "foreach", "(", "$", "classes", "->", "getClasses", "(", "RecordEntity", "::", "class", ")", "as", "$", "class", ")", "{", "if", "(", "$", "class", "[", "'abstract'", "]", ")", "{", "continue", ";", "}", "$", "schemas", "[", "]", "=", "$", "this", "->", "container", "->", "get", "(", "FactoryInterface", "::", "class", ")", "->", "make", "(", "RecordSchema", "::", "class", ",", "[", "'reflection'", "=>", "new", "ReflectionEntity", "(", "$", "class", "[", "'name'", "]", ")", ",", "]", ")", ";", "}", "return", "$", "schemas", ";", "}" ]
Locate all available document schemas in a project. @return SchemaInterface[]
[ "Locate", "all", "available", "document", "schemas", "in", "a", "project", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaLocator.php#L45-L69
train
spiral/orm
source/Spiral/ORM/Schemas/RelationBuilder.php
RelationBuilder.registerRelation
public function registerRelation(SchemaBuilder $builder, RelationDefinition $definition) { if (!$this->config->hasRelation($definition->getType())) { throw new DefinitionException(sprintf( "Undefined relation type '%s' in '%s'.'%s'", $definition->getType(), $definition->sourceContext()->getClass(), $definition->getName() )); } if ($definition->isLateBinded()) { /** * Late binded relations locate their parent based on all existed records. */ $definition = $this->locateOuter($builder, $definition); } $class = $this->config->relationClass( $definition->getType(), RelationsConfig::SCHEMA_CLASS ); //Creating relation schema $relation = $this->factory->make($class, compact('definition')); $this->relations[] = $relation; }
php
public function registerRelation(SchemaBuilder $builder, RelationDefinition $definition) { if (!$this->config->hasRelation($definition->getType())) { throw new DefinitionException(sprintf( "Undefined relation type '%s' in '%s'.'%s'", $definition->getType(), $definition->sourceContext()->getClass(), $definition->getName() )); } if ($definition->isLateBinded()) { /** * Late binded relations locate their parent based on all existed records. */ $definition = $this->locateOuter($builder, $definition); } $class = $this->config->relationClass( $definition->getType(), RelationsConfig::SCHEMA_CLASS ); //Creating relation schema $relation = $this->factory->make($class, compact('definition')); $this->relations[] = $relation; }
[ "public", "function", "registerRelation", "(", "SchemaBuilder", "$", "builder", ",", "RelationDefinition", "$", "definition", ")", "{", "if", "(", "!", "$", "this", "->", "config", "->", "hasRelation", "(", "$", "definition", "->", "getType", "(", ")", ")", ")", "{", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"Undefined relation type '%s' in '%s'.'%s'\"", ",", "$", "definition", "->", "getType", "(", ")", ",", "$", "definition", "->", "sourceContext", "(", ")", "->", "getClass", "(", ")", ",", "$", "definition", "->", "getName", "(", ")", ")", ")", ";", "}", "if", "(", "$", "definition", "->", "isLateBinded", "(", ")", ")", "{", "/**\n * Late binded relations locate their parent based on all existed records.\n */", "$", "definition", "=", "$", "this", "->", "locateOuter", "(", "$", "builder", ",", "$", "definition", ")", ";", "}", "$", "class", "=", "$", "this", "->", "config", "->", "relationClass", "(", "$", "definition", "->", "getType", "(", ")", ",", "RelationsConfig", "::", "SCHEMA_CLASS", ")", ";", "//Creating relation schema", "$", "relation", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "class", ",", "compact", "(", "'definition'", ")", ")", ";", "$", "this", "->", "relations", "[", "]", "=", "$", "relation", ";", "}" ]
Registering new relation definition. At this moment function would not check if relation is unique and will redeclare it. @param SchemaBuilder $builder @param RelationDefinition $definition Relation options (definition). @throws DefinitionException
[ "Registering", "new", "relation", "definition", ".", "At", "this", "moment", "function", "would", "not", "check", "if", "relation", "is", "unique", "and", "will", "redeclare", "it", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RelationBuilder.php#L60-L87
train
spiral/orm
source/Spiral/ORM/Schemas/RelationBuilder.php
RelationBuilder.inverseRelations
public function inverseRelations(SchemaBuilder $builder) { /** * Inverse process is relation specific. */ foreach ($this->relations as $relation) { $definition = $relation->getDefinition(); if ($definition->needInversion()) { if (!$relation instanceof InversableRelationInterface) { throw new DefinitionException(sprintf( "Unable to inverse relation '%s'.'%s', relation schema '%s' is non inversable", $definition->sourceContext()->getClass(), $definition->getName(), get_class($relation) )); } $inversed = $relation->inverseDefinition($builder, $definition->getInverse()); foreach ($inversed as $definition) { $this->registerRelation($builder, $definition); } } } }
php
public function inverseRelations(SchemaBuilder $builder) { /** * Inverse process is relation specific. */ foreach ($this->relations as $relation) { $definition = $relation->getDefinition(); if ($definition->needInversion()) { if (!$relation instanceof InversableRelationInterface) { throw new DefinitionException(sprintf( "Unable to inverse relation '%s'.'%s', relation schema '%s' is non inversable", $definition->sourceContext()->getClass(), $definition->getName(), get_class($relation) )); } $inversed = $relation->inverseDefinition($builder, $definition->getInverse()); foreach ($inversed as $definition) { $this->registerRelation($builder, $definition); } } } }
[ "public", "function", "inverseRelations", "(", "SchemaBuilder", "$", "builder", ")", "{", "/**\n * Inverse process is relation specific.\n */", "foreach", "(", "$", "this", "->", "relations", "as", "$", "relation", ")", "{", "$", "definition", "=", "$", "relation", "->", "getDefinition", "(", ")", ";", "if", "(", "$", "definition", "->", "needInversion", "(", ")", ")", "{", "if", "(", "!", "$", "relation", "instanceof", "InversableRelationInterface", ")", "{", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"Unable to inverse relation '%s'.'%s', relation schema '%s' is non inversable\"", ",", "$", "definition", "->", "sourceContext", "(", ")", "->", "getClass", "(", ")", ",", "$", "definition", "->", "getName", "(", ")", ",", "get_class", "(", "$", "relation", ")", ")", ")", ";", "}", "$", "inversed", "=", "$", "relation", "->", "inverseDefinition", "(", "$", "builder", ",", "$", "definition", "->", "getInverse", "(", ")", ")", ";", "foreach", "(", "$", "inversed", "as", "$", "definition", ")", "{", "$", "this", "->", "registerRelation", "(", "$", "builder", ",", "$", "definition", ")", ";", "}", "}", "}", "}" ]
Create inverse relations where needed. @param SchemaBuilder $builder @throws DefinitionException
[ "Create", "inverse", "relations", "where", "needed", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RelationBuilder.php#L96-L120
train
spiral/orm
source/Spiral/ORM/Schemas/RelationBuilder.php
RelationBuilder.packRelations
public function packRelations(string $class, SchemaBuilder $builder): array { $result = []; foreach ($this->relations as $relation) { $definition = $relation->getDefinition(); if ($definition->sourceContext()->getClass() == $class) { //Packing relation, relation schema are given with associated table $result[$definition->getName()] = $relation->packRelation($builder); } } return $result; }
php
public function packRelations(string $class, SchemaBuilder $builder): array { $result = []; foreach ($this->relations as $relation) { $definition = $relation->getDefinition(); if ($definition->sourceContext()->getClass() == $class) { //Packing relation, relation schema are given with associated table $result[$definition->getName()] = $relation->packRelation($builder); } } return $result; }
[ "public", "function", "packRelations", "(", "string", "$", "class", ",", "SchemaBuilder", "$", "builder", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "relations", "as", "$", "relation", ")", "{", "$", "definition", "=", "$", "relation", "->", "getDefinition", "(", ")", ";", "if", "(", "$", "definition", "->", "sourceContext", "(", ")", "->", "getClass", "(", ")", "==", "$", "class", ")", "{", "//Packing relation, relation schema are given with associated table", "$", "result", "[", "$", "definition", "->", "getName", "(", ")", "]", "=", "$", "relation", "->", "packRelation", "(", "$", "builder", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Pack relation schemas for specific model class in order to be saved in memory. @param string $class @param SchemaBuilder $builder @return array
[ "Pack", "relation", "schemas", "for", "specific", "model", "class", "in", "order", "to", "be", "saved", "in", "memory", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RelationBuilder.php#L158-L171
train
spiral/orm
source/Spiral/ORM/Schemas/RelationBuilder.php
RelationBuilder.locateOuter
protected function locateOuter( SchemaBuilder $builder, RelationDefinition $definition ): RelationDefinition { /** * todo: add functionality to resolve database alias */ if (!empty($definition->targetContext())) { //Nothing to do, already have outer parent return $definition; } $found = null; foreach ($builder->getSchemas() as $schema) { if ($this->matchBinded($definition->getTarget(), $schema)) { if (!empty($found)) { //Multiple records found throw new DefinitionException(sprintf( "Ambiguous target of '%s' for late binded relation %s.%s", $definition->getTarget(), $definition->sourceContext()->getClass(), $definition->getName() )); } $found = $schema; } } if (empty($found)) { throw new DefinitionException(sprintf( "Unable to locate outer record of '%s' for late binded relation %s.%s", $definition->getTarget(), $definition->sourceContext()->getClass(), $definition->getName() )); } return $definition->withContext( $definition->sourceContext(), RelationContext::createContent( $found, $builder->requestTable($found->getTable(), $found->getDatabase()) ) ); }
php
protected function locateOuter( SchemaBuilder $builder, RelationDefinition $definition ): RelationDefinition { /** * todo: add functionality to resolve database alias */ if (!empty($definition->targetContext())) { //Nothing to do, already have outer parent return $definition; } $found = null; foreach ($builder->getSchemas() as $schema) { if ($this->matchBinded($definition->getTarget(), $schema)) { if (!empty($found)) { //Multiple records found throw new DefinitionException(sprintf( "Ambiguous target of '%s' for late binded relation %s.%s", $definition->getTarget(), $definition->sourceContext()->getClass(), $definition->getName() )); } $found = $schema; } } if (empty($found)) { throw new DefinitionException(sprintf( "Unable to locate outer record of '%s' for late binded relation %s.%s", $definition->getTarget(), $definition->sourceContext()->getClass(), $definition->getName() )); } return $definition->withContext( $definition->sourceContext(), RelationContext::createContent( $found, $builder->requestTable($found->getTable(), $found->getDatabase()) ) ); }
[ "protected", "function", "locateOuter", "(", "SchemaBuilder", "$", "builder", ",", "RelationDefinition", "$", "definition", ")", ":", "RelationDefinition", "{", "/**\n * todo: add functionality to resolve database alias\n */", "if", "(", "!", "empty", "(", "$", "definition", "->", "targetContext", "(", ")", ")", ")", "{", "//Nothing to do, already have outer parent", "return", "$", "definition", ";", "}", "$", "found", "=", "null", ";", "foreach", "(", "$", "builder", "->", "getSchemas", "(", ")", "as", "$", "schema", ")", "{", "if", "(", "$", "this", "->", "matchBinded", "(", "$", "definition", "->", "getTarget", "(", ")", ",", "$", "schema", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "found", ")", ")", "{", "//Multiple records found", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"Ambiguous target of '%s' for late binded relation %s.%s\"", ",", "$", "definition", "->", "getTarget", "(", ")", ",", "$", "definition", "->", "sourceContext", "(", ")", "->", "getClass", "(", ")", ",", "$", "definition", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "found", "=", "$", "schema", ";", "}", "}", "if", "(", "empty", "(", "$", "found", ")", ")", "{", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"Unable to locate outer record of '%s' for late binded relation %s.%s\"", ",", "$", "definition", "->", "getTarget", "(", ")", ",", "$", "definition", "->", "sourceContext", "(", ")", "->", "getClass", "(", ")", ",", "$", "definition", "->", "getName", "(", ")", ")", ")", ";", "}", "return", "$", "definition", "->", "withContext", "(", "$", "definition", "->", "sourceContext", "(", ")", ",", "RelationContext", "::", "createContent", "(", "$", "found", ",", "$", "builder", "->", "requestTable", "(", "$", "found", "->", "getTable", "(", ")", ",", "$", "found", "->", "getDatabase", "(", ")", ")", ")", ")", ";", "}" ]
Populate entity target based on interface or role. @param SchemaBuilder $builder @param \Spiral\ORM\Schemas\Definitions\RelationDefinition $definition @return \Spiral\ORM\Schemas\Definitions\RelationDefinition @throws DefinitionException
[ "Populate", "entity", "target", "based", "on", "interface", "or", "role", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RelationBuilder.php#L183-L229
train
spiral/orm
source/Spiral/ORM/Schemas/RelationBuilder.php
RelationBuilder.matchBinded
private function matchBinded(string $target, SchemaInterface $schema): bool { if ($schema->getRole() == $target) { return true; } if (interface_exists($target) && is_a($schema->getClass(), $target, true)) { //Match by interface return true; } return false; }
php
private function matchBinded(string $target, SchemaInterface $schema): bool { if ($schema->getRole() == $target) { return true; } if (interface_exists($target) && is_a($schema->getClass(), $target, true)) { //Match by interface return true; } return false; }
[ "private", "function", "matchBinded", "(", "string", "$", "target", ",", "SchemaInterface", "$", "schema", ")", ":", "bool", "{", "if", "(", "$", "schema", "->", "getRole", "(", ")", "==", "$", "target", ")", "{", "return", "true", ";", "}", "if", "(", "interface_exists", "(", "$", "target", ")", "&&", "is_a", "(", "$", "schema", "->", "getClass", "(", ")", ",", "$", "target", ",", "true", ")", ")", "{", "//Match by interface", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if schema matches relation target. @param string $target @param \Spiral\ORM\Schemas\SchemaInterface $schema @return bool
[ "Check", "if", "schema", "matches", "relation", "target", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/RelationBuilder.php#L239-L251
train
rinvex/cortex-foundation
src/Http/Controllers/AuthorizedController.php
AuthorizedController.mapResourceAbilities
protected function mapResourceAbilities(): array { // Reflect calling controller $controller = new ReflectionClass(static::class); // Get public methods and filter magic methods $methods = array_filter($controller->getMethods(ReflectionMethod::IS_PUBLIC), function ($item) use ($controller) { return $item->class === $controller->name && mb_substr($item->name, 0, 2) !== '__' && ! in_array($item->name, $this->resourceActionWhitelist); }); // Get controller actions $actions = array_combine($items = array_map(function ($action) { return $action->name; }, $methods), $items); // Map resource actions to resourse abilities array_walk($actions, function ($value, $key) use (&$actions) { $actions[$key] = array_get($this->resourceAbilityMap(), $key, $value); }); return $actions; }
php
protected function mapResourceAbilities(): array { // Reflect calling controller $controller = new ReflectionClass(static::class); // Get public methods and filter magic methods $methods = array_filter($controller->getMethods(ReflectionMethod::IS_PUBLIC), function ($item) use ($controller) { return $item->class === $controller->name && mb_substr($item->name, 0, 2) !== '__' && ! in_array($item->name, $this->resourceActionWhitelist); }); // Get controller actions $actions = array_combine($items = array_map(function ($action) { return $action->name; }, $methods), $items); // Map resource actions to resourse abilities array_walk($actions, function ($value, $key) use (&$actions) { $actions[$key] = array_get($this->resourceAbilityMap(), $key, $value); }); return $actions; }
[ "protected", "function", "mapResourceAbilities", "(", ")", ":", "array", "{", "// Reflect calling controller", "$", "controller", "=", "new", "ReflectionClass", "(", "static", "::", "class", ")", ";", "// Get public methods and filter magic methods", "$", "methods", "=", "array_filter", "(", "$", "controller", "->", "getMethods", "(", "ReflectionMethod", "::", "IS_PUBLIC", ")", ",", "function", "(", "$", "item", ")", "use", "(", "$", "controller", ")", "{", "return", "$", "item", "->", "class", "===", "$", "controller", "->", "name", "&&", "mb_substr", "(", "$", "item", "->", "name", ",", "0", ",", "2", ")", "!==", "'__'", "&&", "!", "in_array", "(", "$", "item", "->", "name", ",", "$", "this", "->", "resourceActionWhitelist", ")", ";", "}", ")", ";", "// Get controller actions", "$", "actions", "=", "array_combine", "(", "$", "items", "=", "array_map", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "->", "name", ";", "}", ",", "$", "methods", ")", ",", "$", "items", ")", ";", "// Map resource actions to resourse abilities", "array_walk", "(", "$", "actions", ",", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "&", "$", "actions", ")", "{", "$", "actions", "[", "$", "key", "]", "=", "array_get", "(", "$", "this", "->", "resourceAbilityMap", "(", ")", ",", "$", "key", ",", "$", "value", ")", ";", "}", ")", ";", "return", "$", "actions", ";", "}" ]
Map resource actions to resource abilities. @throws \ReflectionException @return array
[ "Map", "resource", "actions", "to", "resource", "abilities", "." ]
230c100d98131c76f777e5036b3e7cd83af49e6e
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Http/Controllers/AuthorizedController.php#L107-L128
train
spiral/orm
source/Spiral/ORM/Entities/Relations/HasManyRelation.php
HasManyRelation.add
public function add(RecordInterface $record): self { $this->assertValid($record); $this->loadData(true)->instances[] = $record; return $this; }
php
public function add(RecordInterface $record): self { $this->assertValid($record); $this->loadData(true)->instances[] = $record; return $this; }
[ "public", "function", "add", "(", "RecordInterface", "$", "record", ")", ":", "self", "{", "$", "this", "->", "assertValid", "(", "$", "record", ")", ";", "$", "this", "->", "loadData", "(", "true", ")", "->", "instances", "[", "]", "=", "$", "record", ";", "return", "$", "this", ";", "}" ]
Add new record into entity set. Attention, usage of this method WILL load relation data unless partial. @param RecordInterface $record @return self @throws RelationException
[ "Add", "new", "record", "into", "entity", "set", ".", "Attention", "usage", "of", "this", "method", "WILL", "load", "relation", "data", "unless", "partial", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasManyRelation.php#L97-L103
train
spiral/orm
source/Spiral/ORM/Entities/Relations/HasManyRelation.php
HasManyRelation.delete
public function delete(RecordInterface $record): self { $this->loadData(true); $this->assertValid($record); foreach ($this->instances as $index => $instance) { if ($this->match($instance, $record)) { //Remove from save unset($this->instances[$index]); $this->deleteInstances[] = $instance; break; } } $this->instances = array_values($this->instances); return $this; }
php
public function delete(RecordInterface $record): self { $this->loadData(true); $this->assertValid($record); foreach ($this->instances as $index => $instance) { if ($this->match($instance, $record)) { //Remove from save unset($this->instances[$index]); $this->deleteInstances[] = $instance; break; } } $this->instances = array_values($this->instances); return $this; }
[ "public", "function", "delete", "(", "RecordInterface", "$", "record", ")", ":", "self", "{", "$", "this", "->", "loadData", "(", "true", ")", ";", "$", "this", "->", "assertValid", "(", "$", "record", ")", ";", "foreach", "(", "$", "this", "->", "instances", "as", "$", "index", "=>", "$", "instance", ")", "{", "if", "(", "$", "this", "->", "match", "(", "$", "instance", ",", "$", "record", ")", ")", "{", "//Remove from save", "unset", "(", "$", "this", "->", "instances", "[", "$", "index", "]", ")", ";", "$", "this", "->", "deleteInstances", "[", "]", "=", "$", "instance", ";", "break", ";", "}", "}", "$", "this", "->", "instances", "=", "array_values", "(", "$", "this", "->", "instances", ")", ";", "return", "$", "this", ";", "}" ]
Delete one record, strict compaction, make sure exactly same instance is given. @param RecordInterface $record @return self @throws RelationException
[ "Delete", "one", "record", "strict", "compaction", "make", "sure", "exactly", "same", "instance", "is", "given", "." ]
a301cd1b664e65496dab648d77ee92bf4fb6949b
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasManyRelation.php#L114-L131
train
nicmart/DomainSpecificQuery
src/Lucene/TreeExpression.php
TreeExpression.setExpressions
public function setExpressions(array $expressions) { $this->expressions = array(); foreach ($expressions as $expression) { $this->addExpression($expression); } return $this; }
php
public function setExpressions(array $expressions) { $this->expressions = array(); foreach ($expressions as $expression) { $this->addExpression($expression); } return $this; }
[ "public", "function", "setExpressions", "(", "array", "$", "expressions", ")", "{", "$", "this", "->", "expressions", "=", "array", "(", ")", ";", "foreach", "(", "$", "expressions", "as", "$", "expression", ")", "{", "$", "this", "->", "addExpression", "(", "$", "expression", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the set of subexpressions @param LuceneExpression[] $expressions The array of expressions @return $this
[ "Set", "the", "set", "of", "subexpressions" ]
7c01fe94337afdfae5884809e8b5487127a63ac3
https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/TreeExpression.php#L65-L74
train
Dhii/placeholder-template-abstract
src/DefaultPlaceholderValueAwareTrait.php
DefaultPlaceholderValueAwareTrait._setDefaultPlaceholderValue
protected function _setDefaultPlaceholderValue($value) { if (!is_null($value)) { $value = $this->_normalizeStringable($value); } $this->defaultPlaceholderValue = $value; }
php
protected function _setDefaultPlaceholderValue($value) { if (!is_null($value)) { $value = $this->_normalizeStringable($value); } $this->defaultPlaceholderValue = $value; }
[ "protected", "function", "_setDefaultPlaceholderValue", "(", "$", "value", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "_normalizeStringable", "(", "$", "value", ")", ";", "}", "$", "this", "->", "defaultPlaceholderValue", "=", "$", "value", ";", "}" ]
Assigns a default placeholder value to this instance. @since [*next-version*] @param Stringable|string|int|float|bool $value The default value. @throws InvalidArgumentException If value is invalid.
[ "Assigns", "a", "default", "placeholder", "value", "to", "this", "instance", "." ]
bfa7cea3b1e078b19bcf59d9a3da63b8c12ed03b
https://github.com/Dhii/placeholder-template-abstract/blob/bfa7cea3b1e078b19bcf59d9a3da63b8c12ed03b/src/DefaultPlaceholderValueAwareTrait.php#L45-L52
train
sil-project/SeedBatchBundle
src/Admin/PlotAdmin.php
PlotAdmin.validateCode
public function validateCode(ErrorElement $errorElement, $object) { $code = $object->getCode(); $registry = $this->getConfigurationPool()->getContainer()->get('blast_core.code_generators'); $codeGenerator = $registry->getCodeGenerator(Plot::class); if (!empty($code) && !$codeGenerator->validate($code)) { $msg = 'Wrong format for plot code. It shoud be: ' . $codeGenerator::getHelp(); $errorElement ->with('code') ->addViolation($msg) ->end() ; } }
php
public function validateCode(ErrorElement $errorElement, $object) { $code = $object->getCode(); $registry = $this->getConfigurationPool()->getContainer()->get('blast_core.code_generators'); $codeGenerator = $registry->getCodeGenerator(Plot::class); if (!empty($code) && !$codeGenerator->validate($code)) { $msg = 'Wrong format for plot code. It shoud be: ' . $codeGenerator::getHelp(); $errorElement ->with('code') ->addViolation($msg) ->end() ; } }
[ "public", "function", "validateCode", "(", "ErrorElement", "$", "errorElement", ",", "$", "object", ")", "{", "$", "code", "=", "$", "object", "->", "getCode", "(", ")", ";", "$", "registry", "=", "$", "this", "->", "getConfigurationPool", "(", ")", "->", "getContainer", "(", ")", "->", "get", "(", "'blast_core.code_generators'", ")", ";", "$", "codeGenerator", "=", "$", "registry", "->", "getCodeGenerator", "(", "Plot", "::", "class", ")", ";", "if", "(", "!", "empty", "(", "$", "code", ")", "&&", "!", "$", "codeGenerator", "->", "validate", "(", "$", "code", ")", ")", "{", "$", "msg", "=", "'Wrong format for plot code. It shoud be: '", ".", "$", "codeGenerator", "::", "getHelp", "(", ")", ";", "$", "errorElement", "->", "with", "(", "'code'", ")", "->", "addViolation", "(", "$", "msg", ")", "->", "end", "(", ")", ";", "}", "}" ]
Plot code validator. @param ErrorElement $errorElement @param Plot $object
[ "Plot", "code", "validator", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Admin/PlotAdmin.php#L53-L66
train