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
secucard/secucard-connect-php-sdk
src/SecucardConnect/Event/EventDispatcher.php
EventDispatcher.dispatch
public function dispatch($eventStr) { try { // decode as array because data proprty, which has unknown structure (only known by handler), // must remain array after mapping to event $arr = MapperUtil::jsonDecode($eventStr, true); $event = MapperUtil::map($arr, Event::class); } catch (Exception $e) { throw new ClientError("Invalid event JSON", $e); } foreach ($this->handlerMap as $callback) { try { if ($callback->handle($event)) { return; } } catch (Exception $e) { if (!$e instanceof AbstractError) { throw new ClientError("Unknown error processing the event", $e); } else { throw $e; } } } }
php
public function dispatch($eventStr) { try { // decode as array because data proprty, which has unknown structure (only known by handler), // must remain array after mapping to event $arr = MapperUtil::jsonDecode($eventStr, true); $event = MapperUtil::map($arr, Event::class); } catch (Exception $e) { throw new ClientError("Invalid event JSON", $e); } foreach ($this->handlerMap as $callback) { try { if ($callback->handle($event)) { return; } } catch (Exception $e) { if (!$e instanceof AbstractError) { throw new ClientError("Unknown error processing the event", $e); } else { throw $e; } } } }
[ "public", "function", "dispatch", "(", "$", "eventStr", ")", "{", "try", "{", "// decode as array because data proprty, which has unknown structure (only known by handler),", "// must remain array after mapping to event", "$", "arr", "=", "MapperUtil", "::", "jsonDecode", "(", ...
Dispatch the event string to a responsible handler if any. @param string $eventStr The event JSON. @return void @throws AbstractError
[ "Dispatch", "the", "event", "string", "to", "a", "responsible", "handler", "if", "any", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Event/EventDispatcher.php#L42-L66
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/FileStorage.php
FileStorage.set
public function set($key, $value) { // take care about replacing keys ! if (is_resource($value) || $value instanceof StreamInterface) { $res = file_put_contents($this->filePath($key), $value); if ($res !== false) { // clear plain storage from key return $this->deleteStore($key); } return $res; } else { $this->storage[$key] = $value; $res = $this->save(); if ($res !== false) { // clear file storage from key return $this->deleteFile($key); } return $res; } }
php
public function set($key, $value) { // take care about replacing keys ! if (is_resource($value) || $value instanceof StreamInterface) { $res = file_put_contents($this->filePath($key), $value); if ($res !== false) { // clear plain storage from key return $this->deleteStore($key); } return $res; } else { $this->storage[$key] = $value; $res = $this->save(); if ($res !== false) { // clear file storage from key return $this->deleteFile($key); } return $res; } }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "// take care about replacing keys !", "if", "(", "is_resource", "(", "$", "value", ")", "||", "$", "value", "instanceof", "StreamInterface", ")", "{", "$", "res", "=", "file_put_cont...
Set an item in the cache @param string $key @param mixed $value @return bool
[ "Set", "an", "item", "in", "the", "cache" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/FileStorage.php#L68-L87
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/FileStorage.php
FileStorage.delete
public function delete($key) { $res = $this->deleteFile($key); if ($res === false) { return false; } return $this->deleteStore($key); }
php
public function delete($key) { $res = $this->deleteFile($key); if ($res === false) { return false; } return $this->deleteStore($key); }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "$", "res", "=", "$", "this", "->", "deleteFile", "(", "$", "key", ")", ";", "if", "(", "$", "res", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "...
Remove a key from the cache. @param string $key @return bool
[ "Remove", "a", "key", "from", "the", "cache", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/FileStorage.php#L96-L104
train
polyfony-inc/polyfony
Private/Polyfony/Mail.php
Mail.configureEnvironmentSpecifics
private function configureEnvironmentSpecifics() { // if we are in production we set the actual recipients if(Config::isProd()) { // set the main recipients foreach($this->recipients['to'] as $mail => $name) { // add to the mailer $this->mailer->addAddress($mail, $name); } // set the carbon copy recipients foreach($this->recipients['cc'] as $mail => $name) { // add to the mailer $this->mailer->addCC($mail, $name); } // set the hidden recipients foreach($this->recipients['bcc'] as $mail => $name) { // add to the mailer $this->mailer->addBCC($mail, $name); } } // if we are in the development enviroment else { // add the bypass address only $this->mailer->addAddress(Config::get('mail', 'bypass_mail')); } }
php
private function configureEnvironmentSpecifics() { // if we are in production we set the actual recipients if(Config::isProd()) { // set the main recipients foreach($this->recipients['to'] as $mail => $name) { // add to the mailer $this->mailer->addAddress($mail, $name); } // set the carbon copy recipients foreach($this->recipients['cc'] as $mail => $name) { // add to the mailer $this->mailer->addCC($mail, $name); } // set the hidden recipients foreach($this->recipients['bcc'] as $mail => $name) { // add to the mailer $this->mailer->addBCC($mail, $name); } } // if we are in the development enviroment else { // add the bypass address only $this->mailer->addAddress(Config::get('mail', 'bypass_mail')); } }
[ "private", "function", "configureEnvironmentSpecifics", "(", ")", "{", "// if we are in production we set the actual recipients", "if", "(", "Config", "::", "isProd", "(", ")", ")", "{", "// set the main recipients", "foreach", "(", "$", "this", "->", "recipients", "[",...
this applies options that are only used in development, or only in production
[ "this", "applies", "options", "that", "are", "only", "used", "in", "development", "or", "only", "in", "production" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Mail.php#L303-L327
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setLinks
public static function setLinks(array $links, bool $replace_existing=false) :void { // if we want to purge existing links !$replace_existing ?: self::$_links = []; // href is the key for storing links foreach($links as $href_or_index => $attributes_or_href) { // if arguments are provided if(is_array($attributes_or_href)) { // if we have a stylesheet if( // if a rel is set, and it's not a stylesheet !array_key_exists('rel',$attributes_or_href) || // and it's not a stylesheet $attributes_or_href['rel'] == 'stylesheet' ) { // also rewrite the path of assets that used relative shortcuts $attributes_or_href['href'] = self::getPublicAssetPath($href_or_index,'Css'); // force the type $attributes_or_href['type'] = 'text/css'; // force the rel $attributes_or_href['rel'] = 'stylesheet'; // if the media key is implicit array_key_exists('media', $attributes_or_href) ?: $attributes_or_href['media'] = 'all'; // push the slightly alternated stylesheet self::$_links[$href_or_index] = $attributes_or_href; } // otherwize we don't know what we're dealing with else { // just set its href $attributes_or_href['href'] = $href_or_index; // push that link and its attributes self::$_links[$href_or_index] = $attributes_or_href; } } // else only an href is provided, we assume it is a stylesheet else { // push that link alone self::$_links[$attributes_or_href] = [ // we assume it is a generic all media stylesheet 'rel' =>'stylesheet', 'type' =>'text/css', 'media' =>'all', // and we set its href 'href' =>self::getPublicAssetPath($attributes_or_href, 'Css') ]; } } }
php
public static function setLinks(array $links, bool $replace_existing=false) :void { // if we want to purge existing links !$replace_existing ?: self::$_links = []; // href is the key for storing links foreach($links as $href_or_index => $attributes_or_href) { // if arguments are provided if(is_array($attributes_or_href)) { // if we have a stylesheet if( // if a rel is set, and it's not a stylesheet !array_key_exists('rel',$attributes_or_href) || // and it's not a stylesheet $attributes_or_href['rel'] == 'stylesheet' ) { // also rewrite the path of assets that used relative shortcuts $attributes_or_href['href'] = self::getPublicAssetPath($href_or_index,'Css'); // force the type $attributes_or_href['type'] = 'text/css'; // force the rel $attributes_or_href['rel'] = 'stylesheet'; // if the media key is implicit array_key_exists('media', $attributes_or_href) ?: $attributes_or_href['media'] = 'all'; // push the slightly alternated stylesheet self::$_links[$href_or_index] = $attributes_or_href; } // otherwize we don't know what we're dealing with else { // just set its href $attributes_or_href['href'] = $href_or_index; // push that link and its attributes self::$_links[$href_or_index] = $attributes_or_href; } } // else only an href is provided, we assume it is a stylesheet else { // push that link alone self::$_links[$attributes_or_href] = [ // we assume it is a generic all media stylesheet 'rel' =>'stylesheet', 'type' =>'text/css', 'media' =>'all', // and we set its href 'href' =>self::getPublicAssetPath($attributes_or_href, 'Css') ]; } } }
[ "public", "static", "function", "setLinks", "(", "array", "$", "links", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing links", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_links", "="...
set links for the current HTML page
[ "set", "links", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L15-L61
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setScripts
public static function setScripts(array $scripts, bool $replace_existing=false) :void { // if we want to purge existing scripts !$replace_existing ?: self::$_scripts = []; // for each script we have to set foreach($scripts as $script) { // rewrite its path self::$_scripts[] = self::getPublicAssetPath($script, 'Js'); } }
php
public static function setScripts(array $scripts, bool $replace_existing=false) :void { // if we want to purge existing scripts !$replace_existing ?: self::$_scripts = []; // for each script we have to set foreach($scripts as $script) { // rewrite its path self::$_scripts[] = self::getPublicAssetPath($script, 'Js'); } }
[ "public", "static", "function", "setScripts", "(", "array", "$", "scripts", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing scripts", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_scripts...
set scripts for the current HTML page
[ "set", "scripts", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L64-L72
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setMetas
public static function setMetas(array $metas, bool $replace_existing=false) :void { // if we want to purge existing metas !$replace_existing ?: self::$_metas = []; // name is the key for storing metas self::$_metas += $metas; }
php
public static function setMetas(array $metas, bool $replace_existing=false) :void { // if we want to purge existing metas !$replace_existing ?: self::$_metas = []; // name is the key for storing metas self::$_metas += $metas; }
[ "public", "static", "function", "setMetas", "(", "array", "$", "metas", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing metas", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_metas", "="...
set metas for the current HTML page
[ "set", "metas", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L76-L81
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.set
public static function set(array $assets) :void { // for each batch foreach($assets as $category => $scripts_or_links_or_metas) { // if the batch is scripts if($category == 'scripts') { self::setScripts($scripts_or_links_or_metas); } // if the batch is links elseif($category == 'links') { self::setLinks($scripts_or_links_or_metas); } // if the match is metas elseif($category == 'metas') { self::setMetas($scripts_or_links_or_metas); } } }
php
public static function set(array $assets) :void { // for each batch foreach($assets as $category => $scripts_or_links_or_metas) { // if the batch is scripts if($category == 'scripts') { self::setScripts($scripts_or_links_or_metas); } // if the batch is links elseif($category == 'links') { self::setLinks($scripts_or_links_or_metas); } // if the match is metas elseif($category == 'metas') { self::setMetas($scripts_or_links_or_metas); } } }
[ "public", "static", "function", "set", "(", "array", "$", "assets", ")", ":", "void", "{", "// for each batch", "foreach", "(", "$", "assets", "as", "$", "category", "=>", "$", "scripts_or_links_or_metas", ")", "{", "// if the batch is scripts", "if", "(", "$"...
shortcuts to quickly set multiple things
[ "shortcuts", "to", "quickly", "set", "multiple", "things" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L84-L100
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildAndGetPage
public static function buildAndGetPage(string $content) :string { // initial content $page = '<!doctype html><html lang="'.\Polyfony\Locales::getLanguage().'"><head><title>'.(isset(self::$_metas['title']) ? self::$_metas['title'] : '').'</title><meta http-equiv="content-type" content="text/html; charset=' . \Polyfony\Response::getCharset() . '" />'; // add the meta tags and the links $page .= self::buildMetasTags() . self::buildLinksTags(); // close the head, add the body, and add the scripts $page .= '</head><body>' . $content . self::buildScriptsTags(); // add the profiler (if enabled) $page .= \Polyfony\Config::get('profiler', 'enable') ? new \Polyfony\Profiler\HTML : ''; // close the document and return the assembled html page return $page . '</body></html>'; }
php
public static function buildAndGetPage(string $content) :string { // initial content $page = '<!doctype html><html lang="'.\Polyfony\Locales::getLanguage().'"><head><title>'.(isset(self::$_metas['title']) ? self::$_metas['title'] : '').'</title><meta http-equiv="content-type" content="text/html; charset=' . \Polyfony\Response::getCharset() . '" />'; // add the meta tags and the links $page .= self::buildMetasTags() . self::buildLinksTags(); // close the head, add the body, and add the scripts $page .= '</head><body>' . $content . self::buildScriptsTags(); // add the profiler (if enabled) $page .= \Polyfony\Config::get('profiler', 'enable') ? new \Polyfony\Profiler\HTML : ''; // close the document and return the assembled html page return $page . '</body></html>'; }
[ "public", "static", "function", "buildAndGetPage", "(", "string", "$", "content", ")", ":", "string", "{", "// initial content", "$", "page", "=", "'<!doctype html><html lang=\"'", ".", "\\", "Polyfony", "\\", "Locales", "::", "getLanguage", "(", ")", ".", "'\">...
build an html page
[ "build", "an", "html", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L103-L115
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildMetasTags
private static function buildMetasTags() :string { // this is where formatted meta tags go $metas = ''; // for each available meta foreach(self::$_metas as $name => $content) { // add the formated the meta $metas .= '<meta name="'.$name.'" content="'.\Polyfony\Format::htmlSafe($content).'" />'; } return $metas; }
php
private static function buildMetasTags() :string { // this is where formatted meta tags go $metas = ''; // for each available meta foreach(self::$_metas as $name => $content) { // add the formated the meta $metas .= '<meta name="'.$name.'" content="'.\Polyfony\Format::htmlSafe($content).'" />'; } return $metas; }
[ "private", "static", "function", "buildMetasTags", "(", ")", ":", "string", "{", "// this is where formatted meta tags go", "$", "metas", "=", "''", ";", "// for each available meta", "foreach", "(", "self", "::", "$", "_metas", "as", "$", "name", "=>", "$", "co...
builds meta code
[ "builds", "meta", "code" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L120-L130
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildLinksTags
private static function buildLinksTags() :string { // this is where formatted links tags go $links = []; // pack and minify self::packAndMinifyLinks(); // for each available link foreach(self::$_links as $href => $attributes) { // sort the attributes (compulse order needs) ksort($attributes); // build as base stylesheet link and merge its attributes $links[] = new \Polyfony\Element('link', $attributes); } return implode('', $links); }
php
private static function buildLinksTags() :string { // this is where formatted links tags go $links = []; // pack and minify self::packAndMinifyLinks(); // for each available link foreach(self::$_links as $href => $attributes) { // sort the attributes (compulse order needs) ksort($attributes); // build as base stylesheet link and merge its attributes $links[] = new \Polyfony\Element('link', $attributes); } return implode('', $links); }
[ "private", "static", "function", "buildLinksTags", "(", ")", ":", "string", "{", "// this is where formatted links tags go", "$", "links", "=", "[", "]", ";", "// pack and minify", "self", "::", "packAndMinifyLinks", "(", ")", ";", "// for each available link", "forea...
build links code
[ "build", "links", "code" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L133-L146
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.doesThisPackNeedRegeneration
private static function doesThisPackNeedRegeneration(string $pack_path) :bool { return // if the file does not exist !file_exists($pack_path) || // or if we're not allowed to use cached items !\Polyfony\Config::get('response','cache') || // of if the request explicitely disallows that !\Polyfony\Request::isCacheAllowed(); }
php
private static function doesThisPackNeedRegeneration(string $pack_path) :bool { return // if the file does not exist !file_exists($pack_path) || // or if we're not allowed to use cached items !\Polyfony\Config::get('response','cache') || // of if the request explicitely disallows that !\Polyfony\Request::isCacheAllowed(); }
[ "private", "static", "function", "doesThisPackNeedRegeneration", "(", "string", "$", "pack_path", ")", ":", "bool", "{", "return", "// if the file does not exist", "!", "file_exists", "(", "$", "pack_path", ")", "||", "// or if we're not allowed to use cached items", "!",...
if this pack needs to be generated again
[ "if", "this", "pack", "needs", "to", "be", "generated", "again" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L266-L274
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.getPublicAssetPath
private static function getPublicAssetPath(string $asset_path, string $asset_type) :string { // if the asset path is absolute in any way return (substr($asset_path,0,1) == '/' || substr($asset_path,0,4) == 'http') ? // it is returned as is, // otherwise it is made relative to the Assets folder $asset_path : "/Assets/{$asset_type}/$asset_path"; }
php
private static function getPublicAssetPath(string $asset_path, string $asset_type) :string { // if the asset path is absolute in any way return (substr($asset_path,0,1) == '/' || substr($asset_path,0,4) == 'http') ? // it is returned as is, // otherwise it is made relative to the Assets folder $asset_path : "/Assets/{$asset_type}/$asset_path"; }
[ "private", "static", "function", "getPublicAssetPath", "(", "string", "$", "asset_path", ",", "string", "$", "asset_type", ")", ":", "string", "{", "// if the asset path is absolute in any way", "return", "(", "substr", "(", "$", "asset_path", ",", "0", ",", "1", ...
assets path converter
[ "assets", "path", "converter" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L277-L282
train
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.getMinifiedPackIfAllowed
private static function getMinifiedPackIfAllowed(string $pack_contents, object $packer_object=null) :string { // if we are allowed to minify return \Polyfony\Config::get('response','minify') ? ($packer_object)->add($pack_contents)->minify() : $pack_contents; }
php
private static function getMinifiedPackIfAllowed(string $pack_contents, object $packer_object=null) :string { // if we are allowed to minify return \Polyfony\Config::get('response','minify') ? ($packer_object)->add($pack_contents)->minify() : $pack_contents; }
[ "private", "static", "function", "getMinifiedPackIfAllowed", "(", "string", "$", "pack_contents", ",", "object", "$", "packer_object", "=", "null", ")", ":", "string", "{", "// if we are allowed to minify", "return", "\\", "Polyfony", "\\", "Config", "::", "get", ...
minify the packed content if it's allowed, otherwise return is at is
[ "minify", "the", "packed", "content", "if", "it", "s", "allowed", "otherwise", "return", "is", "at", "is" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L294-L300
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.addMissingAttributes
public function addMissingAttributes() { foreach ($this->getSchema() as $key => $settings) { if (!array_has($this->attributes, $key)) { array_set($this->attributes, $key, array_get($settings, 'default', null)); } } }
php
public function addMissingAttributes() { foreach ($this->getSchema() as $key => $settings) { if (!array_has($this->attributes, $key)) { array_set($this->attributes, $key, array_get($settings, 'default', null)); } } }
[ "public", "function", "addMissingAttributes", "(", ")", "{", "foreach", "(", "$", "this", "->", "getSchema", "(", ")", "as", "$", "key", "=>", "$", "settings", ")", "{", "if", "(", "!", "array_has", "(", "$", "this", "->", "attributes", ",", "$", "ke...
Set's mising attributes. This covers situations where values have defaults but are not fillable, or date field. @return void
[ "Set", "s", "mising", "attributes", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L109-L116
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.hasWriteAccess
public function hasWriteAccess($key) { if (static::$unguarded) { return true; } // Attribute is guarded. if (in_array($key, $this->getGuarded())) { return false; } if (($method = $this->getAuthMethod($key)) !== false) { return $this->$method($key); } // Check for the presence of a mutator for the auth operation // which simply lets the developers check if the current user // has the authority to update this value. if ($this->hasAuthAttributeMutator($key)) { $method = 'auth'.Str::studly($key).'Attribute'; return $this->{$method}($key); } return true; }
php
public function hasWriteAccess($key) { if (static::$unguarded) { return true; } // Attribute is guarded. if (in_array($key, $this->getGuarded())) { return false; } if (($method = $this->getAuthMethod($key)) !== false) { return $this->$method($key); } // Check for the presence of a mutator for the auth operation // which simply lets the developers check if the current user // has the authority to update this value. if ($this->hasAuthAttributeMutator($key)) { $method = 'auth'.Str::studly($key).'Attribute'; return $this->{$method}($key); } return true; }
[ "public", "function", "hasWriteAccess", "(", "$", "key", ")", "{", "if", "(", "static", "::", "$", "unguarded", ")", "{", "return", "true", ";", "}", "// Attribute is guarded.", "if", "(", "in_array", "(", "$", "key", ",", "$", "this", "->", "getGuarded"...
Has write access to a given key on this model. @param string $key @return bool
[ "Has", "write", "access", "to", "a", "given", "key", "on", "this", "model", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L145-L170
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.setDefaultValuesForAttributes
public function setDefaultValuesForAttributes() { // Only works on new models. if ($this->exists) { return $this; } // Defaults on attributes. $defaults = $this->getAttributesFromSchema('default', true); // Remove attributes that have been given values. $defaults = array_except($defaults, array_keys($this->getDirty())); // Unguard. static::unguard(); // Allocate values. foreach ($defaults as $key => $value) { $this->{$key} = $value; } // Reguard. static::reguard(); return $this; }
php
public function setDefaultValuesForAttributes() { // Only works on new models. if ($this->exists) { return $this; } // Defaults on attributes. $defaults = $this->getAttributesFromSchema('default', true); // Remove attributes that have been given values. $defaults = array_except($defaults, array_keys($this->getDirty())); // Unguard. static::unguard(); // Allocate values. foreach ($defaults as $key => $value) { $this->{$key} = $value; } // Reguard. static::reguard(); return $this; }
[ "public", "function", "setDefaultValuesForAttributes", "(", ")", "{", "// Only works on new models.", "if", "(", "$", "this", "->", "exists", ")", "{", "return", "$", "this", ";", "}", "// Defaults on attributes.", "$", "defaults", "=", "$", "this", "->", "getAt...
Set default values on this attribute. @return $this
[ "Set", "default", "values", "on", "this", "attribute", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L177-L202
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastParams
public function getCastParams() { if ($this->getIncrementing()) { return array_merge( [ $this->getKeyName() => $this->getKeyType(), ], $this->getAttributesFromSchema('cast', true) ); } return $this->getAttributesFromSchema('cast-params', true); }
php
public function getCastParams() { if ($this->getIncrementing()) { return array_merge( [ $this->getKeyName() => $this->getKeyType(), ], $this->getAttributesFromSchema('cast', true) ); } return $this->getAttributesFromSchema('cast-params', true); }
[ "public", "function", "getCastParams", "(", ")", "{", "if", "(", "$", "this", "->", "getIncrementing", "(", ")", ")", "{", "return", "array_merge", "(", "[", "$", "this", "->", "getKeyName", "(", ")", "=>", "$", "this", "->", "getKeyType", "(", ")", ...
Get the casts params array. @return array
[ "Get", "the", "casts", "params", "array", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L228-L240
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastFromDefinition
protected function getCastFromDefinition($type) { // Custom definitions. if (array_has(static::$cast_from, $type)) { return array_get(static::$cast_from, $type); } // Fallback to default. if (array_has(static::$default_cast_from, $type)) { return array_get(static::$default_cast_from, $type); } return false; }
php
protected function getCastFromDefinition($type) { // Custom definitions. if (array_has(static::$cast_from, $type)) { return array_get(static::$cast_from, $type); } // Fallback to default. if (array_has(static::$default_cast_from, $type)) { return array_get(static::$default_cast_from, $type); } return false; }
[ "protected", "function", "getCastFromDefinition", "(", "$", "type", ")", "{", "// Custom definitions.", "if", "(", "array_has", "(", "static", "::", "$", "cast_from", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_fro...
Get the method to cast this attribte type. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "type", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L290-L303
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastAsParamaters
protected function getCastAsParamaters($key) { $cast_params = $this->getCastParams(); $paramaters = explode(':', array_get($cast_params, $key, '')); $parsed = $this->parseCastParamaters($paramaters); return $parsed; }
php
protected function getCastAsParamaters($key) { $cast_params = $this->getCastParams(); $paramaters = explode(':', array_get($cast_params, $key, '')); $parsed = $this->parseCastParamaters($paramaters); return $parsed; }
[ "protected", "function", "getCastAsParamaters", "(", "$", "key", ")", "{", "$", "cast_params", "=", "$", "this", "->", "getCastParams", "(", ")", ";", "$", "paramaters", "=", "explode", "(", "':'", ",", "array_get", "(", "$", "cast_params", ",", "$", "ke...
Get the method to cast this attribte tyepca. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "tyepca", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L312-L320
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.parseCastParamaters
private function parseCastParamaters($paramaters) { foreach ($paramaters as &$value) { // Local callable method. ($someMethod()) if (substr($value, 0, 1) === '$' && stripos($value, '()') !== false) { $method = substr($value, 1, -2); $value = is_callable([$this, $method]) ? $this->{$method}() : null; // Local attribute. ($some_attribute) } elseif (substr($value, 0, 1) === '$') { $key = substr($value, 1); $value = $this->{$key}; // Callable function (eg helper). (some_function()) } elseif (stripos($value, '()') !== false) { $method = substr($value, 0, -2); $value = is_callable($method) ? $method() : null; } // String value. } return $paramaters; }
php
private function parseCastParamaters($paramaters) { foreach ($paramaters as &$value) { // Local callable method. ($someMethod()) if (substr($value, 0, 1) === '$' && stripos($value, '()') !== false) { $method = substr($value, 1, -2); $value = is_callable([$this, $method]) ? $this->{$method}() : null; // Local attribute. ($some_attribute) } elseif (substr($value, 0, 1) === '$') { $key = substr($value, 1); $value = $this->{$key}; // Callable function (eg helper). (some_function()) } elseif (stripos($value, '()') !== false) { $method = substr($value, 0, -2); $value = is_callable($method) ? $method() : null; } // String value. } return $paramaters; }
[ "private", "function", "parseCastParamaters", "(", "$", "paramaters", ")", "{", "foreach", "(", "$", "paramaters", "as", "&", "$", "value", ")", "{", "// Local callable method. ($someMethod())", "if", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")"...
Parse the given cast parameters. @param array $paramaters @return array
[ "Parse", "the", "given", "cast", "parameters", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L329-L352
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getAuthMethod
public function getAuthMethod($key) { if (array_has($this->getAuths(), $key)) { $method = 'auth'.studly_case(array_get($this->getAuths(), $key)); return method_exists($this, $method) ? $method : false; } return false; }
php
public function getAuthMethod($key) { if (array_has($this->getAuths(), $key)) { $method = 'auth'.studly_case(array_get($this->getAuths(), $key)); return method_exists($this, $method) ? $method : false; } return false; }
[ "public", "function", "getAuthMethod", "(", "$", "key", ")", "{", "if", "(", "array_has", "(", "$", "this", "->", "getAuths", "(", ")", ",", "$", "key", ")", ")", "{", "$", "method", "=", "'auth'", ".", "studly_case", "(", "array_get", "(", "$", "t...
Get auth method. @param string $key @return string|array
[ "Get", "auth", "method", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L393-L402
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastToDefinition
protected function getCastToDefinition($type) { // Custom definitions. if (array_has(static::$cast_to, $type)) { return array_get(static::$cast_to, $type); } // Fallback to default. if (array_has(static::$default_cast_to, $type)) { return array_get(static::$default_cast_to, $type); } return false; }
php
protected function getCastToDefinition($type) { // Custom definitions. if (array_has(static::$cast_to, $type)) { return array_get(static::$cast_to, $type); } // Fallback to default. if (array_has(static::$default_cast_to, $type)) { return array_get(static::$default_cast_to, $type); } return false; }
[ "protected", "function", "getCastToDefinition", "(", "$", "type", ")", "{", "// Custom definitions.", "if", "(", "array_has", "(", "static", "::", "$", "cast_to", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_to", ...
Get the method to cast this attribte back to it's original form. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "back", "to", "it", "s", "original", "form", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L475-L488
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.savingValidation
public function savingValidation() { global $app; $this->preValidationCast(); $this->validator = new Validator($app['translator'], $this->getDirty(), $this->getAttributeRules()); if ($this->validator->fails()) { return false; } return true; }
php
public function savingValidation() { global $app; $this->preValidationCast(); $this->validator = new Validator($app['translator'], $this->getDirty(), $this->getAttributeRules()); if ($this->validator->fails()) { return false; } return true; }
[ "public", "function", "savingValidation", "(", ")", "{", "global", "$", "app", ";", "$", "this", "->", "preValidationCast", "(", ")", ";", "$", "this", "->", "validator", "=", "new", "Validator", "(", "$", "app", "[", "'translator'", "]", ",", "$", "th...
Validate the model before saving. @return array
[ "Validate", "the", "model", "before", "saving", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L687-L699
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.preValidationCast
private function preValidationCast() { $rules = $this->getAttributeRules(); // Check each dirty attribute. foreach ($this->getDirty() as $key => $value) { // Get the rules. $rules_array = explode('|', array_get($rules, $key, '')); // First item is always the cast type. $cast = array_get($rules_array, 0, false); // Check if the value can be nullable. $nullable = in_array('nullable', $rules_array); switch ($cast) { case 'string': $value = (string) $value; break; case 'boolean': $value = (bool) (int) $value; break; case 'integer': $value = (int) $value; break; case 'numeric': $value = (float) preg_replace('/[^0-9.-]*/', '', $value); break; } // Value is empty, let's nullify. if (empty($value) && $nullable) { $value = null; } $this->attributes[$key] = $value; } }
php
private function preValidationCast() { $rules = $this->getAttributeRules(); // Check each dirty attribute. foreach ($this->getDirty() as $key => $value) { // Get the rules. $rules_array = explode('|', array_get($rules, $key, '')); // First item is always the cast type. $cast = array_get($rules_array, 0, false); // Check if the value can be nullable. $nullable = in_array('nullable', $rules_array); switch ($cast) { case 'string': $value = (string) $value; break; case 'boolean': $value = (bool) (int) $value; break; case 'integer': $value = (int) $value; break; case 'numeric': $value = (float) preg_replace('/[^0-9.-]*/', '', $value); break; } // Value is empty, let's nullify. if (empty($value) && $nullable) { $value = null; } $this->attributes[$key] = $value; } }
[ "private", "function", "preValidationCast", "(", ")", "{", "$", "rules", "=", "$", "this", "->", "getAttributeRules", "(", ")", ";", "// Check each dirty attribute.", "foreach", "(", "$", "this", "->", "getDirty", "(", ")", "as", "$", "key", "=>", "$", "va...
Before validating, ensure the values are correctly casted. Mostly integer or boolean values where they can be set to either. eg 1 for true. @return void
[ "Before", "validating", "ensure", "the", "values", "are", "correctly", "casted", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L709-L746
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getAttributeRules
public function getAttributeRules() { $result = []; $attributes = $this->getAttributesFromSchema(); $casts = $this->getCasts(); $casts_back = $this->getAttributesFromSchema('cast-back', true); $rules = $this->getAttributesFromSchema('rules', true); // Build full rule for each attribute. foreach ($attributes as $key) { $result[$key] = []; } // If any casts back are configured, replace the value found in casts. // Handy if we read integer values as datetime, but save back as an integer. $casts = array_merge($casts, $casts_back); // Build full rule for each attribute. foreach ($casts as $key => $cast_type) { $cast_validator = $this->parseCastToValidator($cast_type); if (!empty($cast_validator)) { $result[$key][] = $cast_validator; } if ($this->exists) { $result[$key][] = 'sometimes'; } } // Assign specified rules. foreach ($rules as $key => $rule) { $result[$key][] = $rule; } unset($result[$this->getKeyName()]); foreach ($result as $key => $rules) { $result[$key] = implode('|', $rules); } return $result; }
php
public function getAttributeRules() { $result = []; $attributes = $this->getAttributesFromSchema(); $casts = $this->getCasts(); $casts_back = $this->getAttributesFromSchema('cast-back', true); $rules = $this->getAttributesFromSchema('rules', true); // Build full rule for each attribute. foreach ($attributes as $key) { $result[$key] = []; } // If any casts back are configured, replace the value found in casts. // Handy if we read integer values as datetime, but save back as an integer. $casts = array_merge($casts, $casts_back); // Build full rule for each attribute. foreach ($casts as $key => $cast_type) { $cast_validator = $this->parseCastToValidator($cast_type); if (!empty($cast_validator)) { $result[$key][] = $cast_validator; } if ($this->exists) { $result[$key][] = 'sometimes'; } } // Assign specified rules. foreach ($rules as $key => $rule) { $result[$key][] = $rule; } unset($result[$this->getKeyName()]); foreach ($result as $key => $rules) { $result[$key] = implode('|', $rules); } return $result; }
[ "public", "function", "getAttributeRules", "(", ")", "{", "$", "result", "=", "[", "]", ";", "$", "attributes", "=", "$", "this", "->", "getAttributesFromSchema", "(", ")", ";", "$", "casts", "=", "$", "this", "->", "getCasts", "(", ")", ";", "$", "c...
Get rules for attributes. @return array
[ "Get", "rules", "for", "attributes", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L753-L795
train
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.parseCastToValidator
private function parseCastToValidator($type) { if (array_has(static::$cast_validation, $type)) { return array_get(static::$cast_validation, $type); } if (array_has(static::$default_cast_validation, $type)) { return array_get(static::$default_cast_validation, $type); } return $type; }
php
private function parseCastToValidator($type) { if (array_has(static::$cast_validation, $type)) { return array_get(static::$cast_validation, $type); } if (array_has(static::$default_cast_validation, $type)) { return array_get(static::$default_cast_validation, $type); } return $type; }
[ "private", "function", "parseCastToValidator", "(", "$", "type", ")", "{", "if", "(", "array_has", "(", "static", "::", "$", "cast_validation", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_validation", ",", "$", ...
Convert attribute type to validation type. @param string $type @return string
[ "Convert", "attribute", "type", "to", "validation", "type", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L804-L815
train
polyfony-inc/polyfony
Private/Polyfony/Security/Accounts.php
Accounts.createCookieSession
private function createCookieSession(string $session_signature) :bool { // store a cookie with our current session key in it return Cook::put( Conf::get('security', 'cookie'), $session_signature, true, Conf::get('security', 'session_duration') ); }
php
private function createCookieSession(string $session_signature) :bool { // store a cookie with our current session key in it return Cook::put( Conf::get('security', 'cookie'), $session_signature, true, Conf::get('security', 'session_duration') ); }
[ "private", "function", "createCookieSession", "(", "string", "$", "session_signature", ")", ":", "bool", "{", "// store a cookie with our current session key in it", "return", "Cook", "::", "put", "(", "Conf", "::", "get", "(", "'security'", ",", "'cookie'", ")", ",...
first part of the session opening process
[ "first", "part", "of", "the", "session", "opening", "process" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Security/Accounts.php#L99-L109
train
polyfony-inc/polyfony
Private/Polyfony/Security/Accounts.php
Accounts.createDatabaseSessionUntil
private function createDatabaseSessionUntil(int $expiration_date, string $session_signature) :bool { // open the session return $this->set([ 'session_expiration_date' => $expiration_date, 'session_key' => $session_signature, 'last_login_origin' => Sec::getSafeRemoteAddress(), 'last_login_agent' => Sec::getSafeUserAgent(), 'last_login_date' => time() ])->save(); }
php
private function createDatabaseSessionUntil(int $expiration_date, string $session_signature) :bool { // open the session return $this->set([ 'session_expiration_date' => $expiration_date, 'session_key' => $session_signature, 'last_login_origin' => Sec::getSafeRemoteAddress(), 'last_login_agent' => Sec::getSafeUserAgent(), 'last_login_date' => time() ])->save(); }
[ "private", "function", "createDatabaseSessionUntil", "(", "int", "$", "expiration_date", ",", "string", "$", "session_signature", ")", ":", "bool", "{", "// open the session", "return", "$", "this", "->", "set", "(", "[", "'session_expiration_date'", "=>", "$", "e...
second part of the session opening process
[ "second", "part", "of", "the", "session", "opening", "process" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Security/Accounts.php#L112-L123
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.checkMode
static public function checkMode(int $mode) { if (!in_array($mode, array(self::NONE, self::READ, self::WRITE))) { throw new AclException('wrong mode'); } }
php
static public function checkMode(int $mode) { if (!in_array($mode, array(self::NONE, self::READ, self::WRITE))) { throw new AclException('wrong mode'); } }
[ "static", "public", "function", "checkMode", "(", "int", "$", "mode", ")", "{", "if", "(", "!", "in_array", "(", "$", "mode", ",", "array", "(", "self", "::", "NONE", ",", "self", "::", "READ", ",", "self", "::", "WRITE", ")", ")", ")", "{", "thr...
Checks the access mode enumaration @param int $mode WebAclRule::READ or WebAclRule::WRITE @throws AclException
[ "Checks", "the", "access", "mode", "enumaration" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L73-L77
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.makeValid
public function makeValid(): array { if ($this->isValid()) { return array($this); } $ret = array(); foreach ($this->resources as $uri => $res) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array($uri => $res); $tmp->classes = array(); $ret[] = $tmp; } foreach ($this->classes as $class) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array(); $tmp->classes = array($class => $class); $ret[] = $tmp; } return $ret; }
php
public function makeValid(): array { if ($this->isValid()) { return array($this); } $ret = array(); foreach ($this->resources as $uri => $res) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array($uri => $res); $tmp->classes = array(); $ret[] = $tmp; } foreach ($this->classes as $class) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array(); $tmp->classes = array($class => $class); $ret[] = $tmp; } return $ret; }
[ "public", "function", "makeValid", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "isValid", "(", ")", ")", "{", "return", "array", "(", "$", "this", ")", ";", "}", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this...
Returns collection of WebAclRule objects each describing exactly one resource or class. @return array @see isValid()
[ "Returns", "collection", "of", "WebAclRule", "objects", "each", "describing", "exactly", "one", "resource", "or", "class", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L264-L285
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.getAclMetadata
public function getAclMetadata(): Resource { $meta = (new Graph())->resource($this->uri ? $this->uri : '.'); $meta->addType('http://www.w3.org/ns/auth/acl#Authorization'); $meta->addLiteral(RC::titleProp(), 'Fedora WebAC rule'); foreach ($this->resources as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessTo', $i->getUri(true)); } foreach ($this->classes as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessToClass', $i); } foreach ($this->roles[self::USER] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agent', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agent', $i); } } foreach ($this->roles[self::GROUP] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agentClass', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agentClass', $i); } } if ($this->mode == self::WRITE) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Write'); } if ($this->mode >= self::READ) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Read'); } return $meta; }
php
public function getAclMetadata(): Resource { $meta = (new Graph())->resource($this->uri ? $this->uri : '.'); $meta->addType('http://www.w3.org/ns/auth/acl#Authorization'); $meta->addLiteral(RC::titleProp(), 'Fedora WebAC rule'); foreach ($this->resources as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessTo', $i->getUri(true)); } foreach ($this->classes as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessToClass', $i); } foreach ($this->roles[self::USER] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agent', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agent', $i); } } foreach ($this->roles[self::GROUP] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agentClass', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agentClass', $i); } } if ($this->mode == self::WRITE) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Write'); } if ($this->mode >= self::READ) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Read'); } return $meta; }
[ "public", "function", "getAclMetadata", "(", ")", ":", "Resource", "{", "$", "meta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "$", "this", "->", "uri", "?", "$", "this", "->", "uri", ":", "'.'", ")", ";", "$", "meta", "->",...
Returns ACL triples. @return Resource
[ "Returns", "ACL", "triples", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L291-L322
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.save
public function save(string $location = null): FedoraResource { if ($this->uri != '') { $meta = $this->getMetadata(); $meta->merge($this->getAclMetadata(), [RC::idProp()]); $this->setMetadata($meta); $this->updateMetadata(); } else { if ($location === null) { throw new InvalidArgumentException('location parameter missing'); } $meta = $this->getAclMetadata(); $meta->addResource(RC::idProp(), 'https://id.acdh.oeaw.ac.at/acl/' . microtime(true) . rand(0, 1000)); $res = $this->fedora->createResource($meta, '', $location, 'POST'); $this->uri = $res->getUri(); $this->fedora->getCache()->delete($res); $this->fedora->getCache()->add($this); } return $this; }
php
public function save(string $location = null): FedoraResource { if ($this->uri != '') { $meta = $this->getMetadata(); $meta->merge($this->getAclMetadata(), [RC::idProp()]); $this->setMetadata($meta); $this->updateMetadata(); } else { if ($location === null) { throw new InvalidArgumentException('location parameter missing'); } $meta = $this->getAclMetadata(); $meta->addResource(RC::idProp(), 'https://id.acdh.oeaw.ac.at/acl/' . microtime(true) . rand(0, 1000)); $res = $this->fedora->createResource($meta, '', $location, 'POST'); $this->uri = $res->getUri(); $this->fedora->getCache()->delete($res); $this->fedora->getCache()->add($this); } return $this; }
[ "public", "function", "save", "(", "string", "$", "location", "=", "null", ")", ":", "FedoraResource", "{", "if", "(", "$", "this", "->", "uri", "!=", "''", ")", "{", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "$", "meta", ...
Saves the ACL rule. If there is no corresponging Fedora resource, it is created as a Fedora child of a resource denpted by the `$location` parameter. @param string $location URI of the parent resource (typically an ACL collection) @return FedoraResource
[ "Saves", "the", "ACL", "rule", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L333-L352
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.delete
public function delete(bool $deep = false, bool $children = false, bool $references = false) { if ($this->uri != '') { parent::delete($deep, $children, $references); } $this->uri = ''; $this->resources = $this->classes = array(); $this->roles = array( self::USER => array(), self::GROUP => array() ); }
php
public function delete(bool $deep = false, bool $children = false, bool $references = false) { if ($this->uri != '') { parent::delete($deep, $children, $references); } $this->uri = ''; $this->resources = $this->classes = array(); $this->roles = array( self::USER => array(), self::GROUP => array() ); }
[ "public", "function", "delete", "(", "bool", "$", "deep", "=", "false", ",", "bool", "$", "children", "=", "false", ",", "bool", "$", "references", "=", "false", ")", "{", "if", "(", "$", "this", "->", "uri", "!=", "''", ")", "{", "parent", "::", ...
Removes the ACL rule from the Fedora @param bool $deep should tombstone resource will be deleted? @param bool $children should children be removed? @param bool $references should references to the resource be removed? (applies also for children when `$children == true`)
[ "Removes", "the", "ACL", "rule", "from", "the", "Fedora" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L361-L372
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.loadMetadata
protected function loadMetadata(bool $force = false) { $metaEmpty = $this->metadata == null; parent::loadMetadata($force); if ($metaEmpty || $force) { foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#mode') as $i) { $mode = preg_replace('#^.*(Read|Write)$#', '\\1', $i->getUri()); $dict = array('Read' => self::READ, 'Write' => self::WRITE); if (!isset($dict[$mode])) { throw new AclException('wrong mode: ' . $mode); } $this->mode = max(array($this->mode, $dict[$mode])); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessTo') as $i) { $uri = $this->fedora->standardizeUri($i->getUri()); $this->resources[$uri] = $this->fedora->getResourceByUri($uri); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessToClass') as $i) { $this->classes[$i->getUri()] = $i->getUri(); } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agent') as $i) { $i = (string) $i; $this->roles[self::USER][$i] = $i; } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agentClass') as $i) { $i = (string) $i; $this->roles[self::GROUP][$i] = $i; } } }
php
protected function loadMetadata(bool $force = false) { $metaEmpty = $this->metadata == null; parent::loadMetadata($force); if ($metaEmpty || $force) { foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#mode') as $i) { $mode = preg_replace('#^.*(Read|Write)$#', '\\1', $i->getUri()); $dict = array('Read' => self::READ, 'Write' => self::WRITE); if (!isset($dict[$mode])) { throw new AclException('wrong mode: ' . $mode); } $this->mode = max(array($this->mode, $dict[$mode])); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessTo') as $i) { $uri = $this->fedora->standardizeUri($i->getUri()); $this->resources[$uri] = $this->fedora->getResourceByUri($uri); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessToClass') as $i) { $this->classes[$i->getUri()] = $i->getUri(); } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agent') as $i) { $i = (string) $i; $this->roles[self::USER][$i] = $i; } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agentClass') as $i) { $i = (string) $i; $this->roles[self::GROUP][$i] = $i; } } }
[ "protected", "function", "loadMetadata", "(", "bool", "$", "force", "=", "false", ")", "{", "$", "metaEmpty", "=", "$", "this", "->", "metadata", "==", "null", ";", "parent", "::", "loadMetadata", "(", "$", "force", ")", ";", "if", "(", "$", "metaEmpty...
Loads current metadata from the Fedora and parses read ACL triples. @param bool $force enforce fetch from Fedora (when you want to make sure metadata are in line with ones in the Fedora or e.g. reset them back to their current state in Fedora) @throws AclException
[ "Loads", "current", "metadata", "from", "the", "Fedora", "and", "parses", "read", "ACL", "triples", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L406-L435
train
hnhdigital-os/laravel-model-schema
src/Concerns/GuardsAttributes.php
GuardsAttributes.getGuarded
public function getGuarded() { $guarded_create = !$this->exists ? $this->getAttributesFromSchema('guarded-create', false, true) : []; $guarded_update = $this->exists ? $this->getAttributesFromSchema('guarded-update', false, true) : []; $guarded = $this->getAttributesFromSchema('guarded', false, true); return array_merge($guarded_create, $guarded_update, $guarded); }
php
public function getGuarded() { $guarded_create = !$this->exists ? $this->getAttributesFromSchema('guarded-create', false, true) : []; $guarded_update = $this->exists ? $this->getAttributesFromSchema('guarded-update', false, true) : []; $guarded = $this->getAttributesFromSchema('guarded', false, true); return array_merge($guarded_create, $guarded_update, $guarded); }
[ "public", "function", "getGuarded", "(", ")", "{", "$", "guarded_create", "=", "!", "$", "this", "->", "exists", "?", "$", "this", "->", "getAttributesFromSchema", "(", "'guarded-create'", ",", "false", ",", "true", ")", ":", "[", "]", ";", "$", "guarded...
Get the guarded attributes for the model. @return array
[ "Get", "the", "guarded", "attributes", "for", "the", "model", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/GuardsAttributes.php#L36-L43
train
ventoviro/windwalker-core
src/Core/Event/CompositeDispatcher.php
CompositeDispatcher.setDispatchers
public function setDispatchers(array $dispatchers) { foreach ($dispatchers as $name => $dispatcher) { $this->addDispatcher($name, $dispatcher); } return $this; }
php
public function setDispatchers(array $dispatchers) { foreach ($dispatchers as $name => $dispatcher) { $this->addDispatcher($name, $dispatcher); } return $this; }
[ "public", "function", "setDispatchers", "(", "array", "$", "dispatchers", ")", "{", "foreach", "(", "$", "dispatchers", "as", "$", "name", "=>", "$", "dispatcher", ")", "{", "$", "this", "->", "addDispatcher", "(", "$", "name", ",", "$", "dispatcher", ")...
Method to set property dispatchers @param \Windwalker\Event\Dispatcher[] $dispatchers @return static Return self to support chaining.
[ "Method", "to", "set", "property", "dispatchers" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Event/CompositeDispatcher.php#L239-L246
train
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.validate
public function validate($justDie = false, $message = 'Invalid Token') { if (!$this->checkToken()) { if ($justDie) { exit($message); } throw new InvalidTokenException($message); } return true; }
php
public function validate($justDie = false, $message = 'Invalid Token') { if (!$this->checkToken()) { if ($justDie) { exit($message); } throw new InvalidTokenException($message); } return true; }
[ "public", "function", "validate", "(", "$", "justDie", "=", "false", ",", "$", "message", "=", "'Invalid Token'", ")", "{", "if", "(", "!", "$", "this", "->", "checkToken", "(", ")", ")", "{", "if", "(", "$", "justDie", ")", "{", "exit", "(", "$", ...
Validate token or die. @param bool $justDie @param string $message @return bool
[ "Validate", "token", "or", "die", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L81-L92
train
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.input
public function input($userId = null, $attribs = []) { $attribs['type'] = 'hidden'; $attribs['name'] = $this->getFormToken($userId); $attribs['value'] = 1; return h('input', $attribs, null); }
php
public function input($userId = null, $attribs = []) { $attribs['type'] = 'hidden'; $attribs['name'] = $this->getFormToken($userId); $attribs['value'] = 1; return h('input', $attribs, null); }
[ "public", "function", "input", "(", "$", "userId", "=", "null", ",", "$", "attribs", "=", "[", "]", ")", "{", "$", "attribs", "[", "'type'", "]", "=", "'hidden'", ";", "$", "attribs", "[", "'name'", "]", "=", "$", "this", "->", "getFormToken", "(",...
Create token input. @param mixed $userId @param array $attribs @return HtmlElement @throws \Exception
[ "Create", "token", "input", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L103-L110
train
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.getToken
public function getToken($forceNew = false) { /** @var Session $session */ $session = $this->session; $token = $session->get(static::TOKEN_KEY); // Create a token if ($token === null || $forceNew) { $token = $this->createToken(12); $session->set(static::TOKEN_KEY, $token); } return $token; }
php
public function getToken($forceNew = false) { /** @var Session $session */ $session = $this->session; $token = $session->get(static::TOKEN_KEY); // Create a token if ($token === null || $forceNew) { $token = $this->createToken(12); $session->set(static::TOKEN_KEY, $token); } return $token; }
[ "public", "function", "getToken", "(", "$", "forceNew", "=", "false", ")", "{", "/** @var Session $session */", "$", "session", "=", "$", "this", "->", "session", ";", "$", "token", "=", "$", "session", "->", "get", "(", "static", "::", "TOKEN_KEY", ")", ...
Get form token string. @param boolean $forceNew Force create new token. @return string @throws \UnexpectedValueException @throws \RuntimeException @throws \Exception
[ "Get", "form", "token", "string", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L145-L160
train
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.getFormToken
public function getFormToken($userId = null, $forceNew = false) { $userId = $userId ?: $this->userManager->getUser()->id; $userId = $userId ?: $this->session->getId(); $config = $this->config; return md5($config['system.secret'] . $userId . $this->getToken($forceNew)); }
php
public function getFormToken($userId = null, $forceNew = false) { $userId = $userId ?: $this->userManager->getUser()->id; $userId = $userId ?: $this->session->getId(); $config = $this->config; return md5($config['system.secret'] . $userId . $this->getToken($forceNew)); }
[ "public", "function", "getFormToken", "(", "$", "userId", "=", "null", ",", "$", "forceNew", "=", "false", ")", "{", "$", "userId", "=", "$", "userId", "?", ":", "$", "this", "->", "userManager", "->", "getUser", "(", ")", "->", "id", ";", "$", "us...
Get a token for specific user. @param mixed $userId An identify of current user. @param boolean $forceNew Force create new token. @return string @throws \RuntimeException @throws \UnexpectedValueException @throws \Exception
[ "Get", "a", "token", "for", "specific", "user", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L173-L181
train
locomotivemtl/charcoal-ui
src/Charcoal/Ui/PrioritizableTrait.php
PrioritizableTrait.setPriority
public function setPriority($priority) { if (!is_numeric($priority)) { throw new InvalidArgumentException( 'Priority must be an integer' ); } $this->priority = intval($priority); return $this; }
php
public function setPriority($priority) { if (!is_numeric($priority)) { throw new InvalidArgumentException( 'Priority must be an integer' ); } $this->priority = intval($priority); return $this; }
[ "public", "function", "setPriority", "(", "$", "priority", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "priority", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Priority must be an integer'", ")", ";", "}", "$", "this", "->", "prior...
Set the entity's priority index. @param integer $priority An index, for sorting. @throws InvalidArgumentException If the priority is not an integer. @return self
[ "Set", "the", "entity", "s", "priority", "index", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/PrioritizableTrait.php#L28-L38
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/parameter/RemoveProtocol.php
RemoveProtocol.transform
public function transform(string $value): string { if (strpos($value, 'hdl.handle.net') !== false) { $value = str_replace("http://", "", $value); }else if(strpos($value, 'https') !== false) { $value = str_replace("https://", "", $value); }else { $value = str_replace("http://", "", $value); } return $value; }
php
public function transform(string $value): string { if (strpos($value, 'hdl.handle.net') !== false) { $value = str_replace("http://", "", $value); }else if(strpos($value, 'https') !== false) { $value = str_replace("https://", "", $value); }else { $value = str_replace("http://", "", $value); } return $value; }
[ "public", "function", "transform", "(", "string", "$", "value", ")", ":", "string", "{", "if", "(", "strpos", "(", "$", "value", ",", "'hdl.handle.net'", ")", "!==", "false", ")", "{", "$", "value", "=", "str_replace", "(", "\"http://\"", ",", "\"\"", ...
Returns raw URL decoded value from the acdh identifier. @param string $value value to be transformed @return string
[ "Returns", "raw", "URL", "decoded", "value", "from", "the", "acdh", "identifier", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/parameter/RemoveProtocol.php#L52-L63
train
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Menu/AbstractMenu.php
AbstractMenu.items
public function items(callable $itemCallback = null) { $items = $this->items; uasort($items, [ $this, 'sortItemsByPriority' ]); $itemCallback = isset($itemCallback) ? $itemCallback : $this->itemCallback; foreach ($items as $item) { if ($itemCallback) { $itemCallback($item); } $GLOBALS['widget_template'] = $item->template(); yield $item->ident() => $item; $GLOBALS['widget_template'] = ''; } }
php
public function items(callable $itemCallback = null) { $items = $this->items; uasort($items, [ $this, 'sortItemsByPriority' ]); $itemCallback = isset($itemCallback) ? $itemCallback : $this->itemCallback; foreach ($items as $item) { if ($itemCallback) { $itemCallback($item); } $GLOBALS['widget_template'] = $item->template(); yield $item->ident() => $item; $GLOBALS['widget_template'] = ''; } }
[ "public", "function", "items", "(", "callable", "$", "itemCallback", "=", "null", ")", "{", "$", "items", "=", "$", "this", "->", "items", ";", "uasort", "(", "$", "items", ",", "[", "$", "this", ",", "'sortItemsByPriority'", "]", ")", ";", "$", "ite...
Menu Item generator. @param callable $itemCallback Optional. Item callback. @return MenuItemInterface[]
[ "Menu", "Item", "generator", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Menu/AbstractMenu.php#L125-L139
train
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.getRenderer
public function getRenderer($type = self::PHP, $config = []) { $type = strtolower($type); $class = sprintf('Windwalker\Core\Renderer\%sRenderer', ucfirst($type)); if (!class_exists($class)) { $class = sprintf('Windwalker\Renderer\%sRenderer', ucfirst($type)); } if (!class_exists($class)) { throw new \DomainException(sprintf('%s renderer not supported.', $type)); } if ($type === 'blade') { if (empty($config['cache_path'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'edge') { if (empty($config['cache_path']) && !isset($config['cache'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'twig') { if (empty($config['path_separator'])) { $config['path_separator'] = '.'; } } /** @var AbstractRenderer|CoreRendererInterface|GlobalVarsTrait $renderer */ $renderer = new $class(static::getGlobalPaths(), $config); $renderer->setPackageFinder($this->finder); $renderer->setGlobals($this->getGlobals()); return $renderer; }
php
public function getRenderer($type = self::PHP, $config = []) { $type = strtolower($type); $class = sprintf('Windwalker\Core\Renderer\%sRenderer', ucfirst($type)); if (!class_exists($class)) { $class = sprintf('Windwalker\Renderer\%sRenderer', ucfirst($type)); } if (!class_exists($class)) { throw new \DomainException(sprintf('%s renderer not supported.', $type)); } if ($type === 'blade') { if (empty($config['cache_path'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'edge') { if (empty($config['cache_path']) && !isset($config['cache'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'twig') { if (empty($config['path_separator'])) { $config['path_separator'] = '.'; } } /** @var AbstractRenderer|CoreRendererInterface|GlobalVarsTrait $renderer */ $renderer = new $class(static::getGlobalPaths(), $config); $renderer->setPackageFinder($this->finder); $renderer->setGlobals($this->getGlobals()); return $renderer; }
[ "public", "function", "getRenderer", "(", "$", "type", "=", "self", "::", "PHP", ",", "$", "config", "=", "[", "]", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "$", "class", "=", "sprintf", "(", "'Windwalker\\Core\\Renderer\\%...
Create a renderer object and auto inject the global paths. @param string $type Renderer engine name, php, blade, twig or mustache. @param array $config Renderer config array. @return AbstractRenderer|CoreRendererInterface @since 2.0
[ "Create", "a", "renderer", "object", "and", "auto", "inject", "the", "global", "paths", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L97-L136
train
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.addGlobalPath
public function addGlobalPath($path, $priority = PriorityQueue::LOW) { $this->getPaths()->insert($path, $priority); return $this; }
php
public function addGlobalPath($path, $priority = PriorityQueue::LOW) { $this->getPaths()->insert($path, $priority); return $this; }
[ "public", "function", "addGlobalPath", "(", "$", "path", ",", "$", "priority", "=", "PriorityQueue", "::", "LOW", ")", "{", "$", "this", "->", "getPaths", "(", ")", "->", "insert", "(", "$", "path", ",", "$", "priority", ")", ";", "return", "$", "thi...
Add a global path for Renderer search. @param string $path The path you want to set. @param int $priority Priority flag to order paths. @return static @since 2.0
[ "Add", "a", "global", "path", "for", "Renderer", "search", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L230-L235
train
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.getPaths
protected function getPaths() { if (!$this->paths) { $this->paths = new PriorityQueue(); $this->registerPaths(); } return $this->paths; }
php
protected function getPaths() { if (!$this->paths) { $this->paths = new PriorityQueue(); $this->registerPaths(); } return $this->paths; }
[ "protected", "function", "getPaths", "(", ")", "{", "if", "(", "!", "$", "this", "->", "paths", ")", "{", "$", "this", "->", "paths", "=", "new", "PriorityQueue", "(", ")", ";", "$", "this", "->", "registerPaths", "(", ")", ";", "}", "return", "$",...
Get or create paths queue. @return PriorityQueue @since 2.0
[ "Get", "or", "create", "paths", "queue", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L261-L270
train
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.registerPaths
protected function registerPaths() { $config = $this->config; // Priority (1) $this->addPath( realpath($config->get('path.templates')), PriorityQueue::LOW - 20 ); // Priority (2) $this->addPath( realpath(__DIR__ . '/../Resources/Templates'), PriorityQueue::LOW - 30 ); return $this; }
php
protected function registerPaths() { $config = $this->config; // Priority (1) $this->addPath( realpath($config->get('path.templates')), PriorityQueue::LOW - 20 ); // Priority (2) $this->addPath( realpath(__DIR__ . '/../Resources/Templates'), PriorityQueue::LOW - 30 ); return $this; }
[ "protected", "function", "registerPaths", "(", ")", "{", "$", "config", "=", "$", "this", "->", "config", ";", "// Priority (1)", "$", "this", "->", "addPath", "(", "realpath", "(", "$", "config", "->", "get", "(", "'path.templates'", ")", ")", ",", "Pri...
Register default global paths. @return static @since 2.0
[ "Register", "default", "global", "paths", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L279-L296
train
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.setPaths
public function setPaths($paths) { if (!$paths instanceof PriorityQueue) { $paths = new PriorityQueue($paths); } $this->paths = $paths; return $this; }
php
public function setPaths($paths) { if (!$paths instanceof PriorityQueue) { $paths = new PriorityQueue($paths); } $this->paths = $paths; return $this; }
[ "public", "function", "setPaths", "(", "$", "paths", ")", "{", "if", "(", "!", "$", "paths", "instanceof", "PriorityQueue", ")", "{", "$", "paths", "=", "new", "PriorityQueue", "(", "$", "paths", ")", ";", "}", "$", "this", "->", "paths", "=", "$", ...
Method to set property paths @param array $paths @return static Return self to support chaining.
[ "Method", "to", "set", "property", "paths" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L319-L328
train
ventoviro/windwalker-core
src/Core/Seeder/Command/SeedCommand.php
SeedCommand.init
public function init() { $this->addCommand(ImportCommand::class); $this->addCommand(ClearCommand::class); $this->addGlobalOption('c') ->alias('class') ->defaultValue('MainSeeder') ->description('The class to import.'); $this->addGlobalOption('d') ->alias('dir') ->description('The directory of this seeder.'); $this->addGlobalOption('p') ->alias('package') ->description('Package name to import seeder.'); parent::init(); }
php
public function init() { $this->addCommand(ImportCommand::class); $this->addCommand(ClearCommand::class); $this->addGlobalOption('c') ->alias('class') ->defaultValue('MainSeeder') ->description('The class to import.'); $this->addGlobalOption('d') ->alias('dir') ->description('The directory of this seeder.'); $this->addGlobalOption('p') ->alias('package') ->description('Package name to import seeder.'); parent::init(); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "addCommand", "(", "ImportCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "ClearCommand", "::", "class", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'c'", ...
Initialise command information. @return void
[ "Initialise", "command", "information", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Seeder/Command/SeedCommand.php#L60-L79
train
polyfony-inc/polyfony
Private/Polyfony/Filesystem.php
Filesystem.chroot
public static function chroot(string $path='/', bool $override = false) { // this is now deprecated, will probably be removed in a future release trigger_error( 'Usage of Polyfony\Filesystem is deprecated, require symfony/filesystem instead', E_USER_DEPRECATED ); // if chrooting is enabled in the configuration if(Config::get('filesystem', 'chroot') && !$override) { // if the path already has the proper (ch)root if(strpos($path, Config::get('filesystem', 'data_path')) === 0) { // remove the root, remove double dots $path = str_replace(array(Config::get('filesystem', 'data_path'), '..'), '', $path); // re-add the root return(Config::get('filesystem', 'data_path') . $path); } // the path doesn't start with the (ch)root else { // remove all double dots and add the root path return(Config::get('filesystem', 'data_path') . str_replace('..','',$path)); } } // return the path (altered or not) return($path); }
php
public static function chroot(string $path='/', bool $override = false) { // this is now deprecated, will probably be removed in a future release trigger_error( 'Usage of Polyfony\Filesystem is deprecated, require symfony/filesystem instead', E_USER_DEPRECATED ); // if chrooting is enabled in the configuration if(Config::get('filesystem', 'chroot') && !$override) { // if the path already has the proper (ch)root if(strpos($path, Config::get('filesystem', 'data_path')) === 0) { // remove the root, remove double dots $path = str_replace(array(Config::get('filesystem', 'data_path'), '..'), '', $path); // re-add the root return(Config::get('filesystem', 'data_path') . $path); } // the path doesn't start with the (ch)root else { // remove all double dots and add the root path return(Config::get('filesystem', 'data_path') . str_replace('..','',$path)); } } // return the path (altered or not) return($path); }
[ "public", "static", "function", "chroot", "(", "string", "$", "path", "=", "'/'", ",", "bool", "$", "override", "=", "false", ")", "{", "// this is now deprecated, will probably be removed in a future release", "trigger_error", "(", "'Usage of Polyfony\\Filesystem is deprec...
this will restrict a path to the data storage folder
[ "this", "will", "restrict", "a", "path", "to", "the", "data", "storage", "folder" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Filesystem.php#L14-L40
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.get
public function get($id) { if (empty($id)) { throw new \Exception('cannot load object with empty id'); } $params = new RequestParams(RequestOps::GET, $this->resourceMetadata, $id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error retrieving data'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
php
public function get($id) { if (empty($id)) { throw new \Exception('cannot load object with empty id'); } $params = new RequestParams(RequestOps::GET, $this->resourceMetadata, $id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error retrieving data'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'cannot load object with empty id'", ")", ";", "}", "$", "params", "=", "new", "RequestParams", "(", "Req...
Method to get object identified by id @param string $id @return BaseModel @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception
[ "Method", "to", "get", "object", "identified", "by", "id" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L226-L244
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.delete
public function delete(BaseModel $model) { if (empty($model->id)) { throw new Exception('Cannot delete object with empty primary key value'); } $params = new RequestParams(RequestOps::DELETE, $this->resourceMetadata, $model->id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error deleting data'); } $this->postProcess($jsonResponse); return $jsonResponse; }
php
public function delete(BaseModel $model) { if (empty($model->id)) { throw new Exception('Cannot delete object with empty primary key value'); } $params = new RequestParams(RequestOps::DELETE, $this->resourceMetadata, $model->id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error deleting data'); } $this->postProcess($jsonResponse); return $jsonResponse; }
[ "public", "function", "delete", "(", "BaseModel", "$", "model", ")", "{", "if", "(", "empty", "(", "$", "model", "->", "id", ")", ")", "{", "throw", "new", "Exception", "(", "'Cannot delete object with empty primary key value'", ")", ";", "}", "$", "params",...
Function to delete the model identified by id @param BaseModel $model @return bool @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception @internal param string $id default null
[ "Function", "to", "delete", "the", "model", "identified", "by", "id" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L276-L292
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.save
public function save(BaseModel $model) { if ($this->resourceMetadata->resourceClass != get_class($model)) { throw new Exception('Unable save data, data type and service must match.'); } // default add new object $method = RequestOps::CREATE; if (!empty($model->id)) { // update the existing record $method = RequestOps::UPDATE; } $params = new RequestParams($method, $this->resourceMetadata, $model->id, null, null, null, MapperUtil::jsonEncode($model, $model->jsonFilterProperties(), $model->jsonFilterNullProperties())); $jsonResponse = $this->request($params); if ($jsonResponse === false) { throw new Exception('Error updating model'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
php
public function save(BaseModel $model) { if ($this->resourceMetadata->resourceClass != get_class($model)) { throw new Exception('Unable save data, data type and service must match.'); } // default add new object $method = RequestOps::CREATE; if (!empty($model->id)) { // update the existing record $method = RequestOps::UPDATE; } $params = new RequestParams($method, $this->resourceMetadata, $model->id, null, null, null, MapperUtil::jsonEncode($model, $model->jsonFilterProperties(), $model->jsonFilterNullProperties())); $jsonResponse = $this->request($params); if ($jsonResponse === false) { throw new Exception('Error updating model'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
[ "public", "function", "save", "(", "BaseModel", "$", "model", ")", "{", "if", "(", "$", "this", "->", "resourceMetadata", "->", "resourceClass", "!=", "get_class", "(", "$", "model", ")", ")", "{", "throw", "new", "Exception", "(", "'Unable save data, data t...
Function to save object It can update existing or create new object, if the given object has an id with value null ist will create a new object. @param BaseModel $model The object to save. @return BaseModel The created object, has same type as the given input. @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception
[ "Function", "to", "save", "object", "It", "can", "update", "existing", "or", "create", "new", "object", "if", "the", "given", "object", "has", "an", "id", "with", "value", "null", "ist", "will", "create", "a", "new", "object", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L307-L334
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.initMediaResource
protected function initMediaResource(&$arg) { if (is_string($arg)) { $mr = new MediaResource(); $mr->setUrl($arg); } else { $mr = $arg; } $mr->setHttpClient($this->httpClient); $mr->setStore($this->storage); return $mr; }
php
protected function initMediaResource(&$arg) { if (is_string($arg)) { $mr = new MediaResource(); $mr->setUrl($arg); } else { $mr = $arg; } $mr->setHttpClient($this->httpClient); $mr->setStore($this->storage); return $mr; }
[ "protected", "function", "initMediaResource", "(", "&", "$", "arg", ")", "{", "if", "(", "is_string", "(", "$", "arg", ")", ")", "{", "$", "mr", "=", "new", "MediaResource", "(", ")", ";", "$", "mr", "->", "setUrl", "(", "$", "arg", ")", ";", "}"...
Create new or complete a media resource object. @param MediaResource|string $arg The media resource to initialize or a url of a resource. @return MediaResource The initialized media resource instance.
[ "Create", "new", "or", "complete", "a", "media", "resource", "object", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L702-L714
train
ventoviro/windwalker-core
src/Core/Package/Resolver/AbstractPackageObjectResolver.php
AbstractPackageObjectResolver.getNamespaces
public static function getNamespaces() { $called = get_called_class(); if (!isset(static::$namespaces[$called])) { static::$namespaces[$called] = new PriorityQueue(); } return static::$namespaces[$called]; }
php
public static function getNamespaces() { $called = get_called_class(); if (!isset(static::$namespaces[$called])) { static::$namespaces[$called] = new PriorityQueue(); } return static::$namespaces[$called]; }
[ "public", "static", "function", "getNamespaces", "(", ")", "{", "$", "called", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "namespaces", "[", "$", "called", "]", ")", ")", "{", "static", "::", "$", "name...
Method to get property Namespaces @return PriorityQueue
[ "Method", "to", "get", "property", "Namespaces" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Package/Resolver/AbstractPackageObjectResolver.php#L171-L180
train
ventoviro/windwalker-core
src/Core/View/ViewModel.php
ViewModel.getRepository
public function getRepository($name = null) { $name = strtolower($name); if ($name) { if (isset($this->repositories[$name])) { return $this->repositories[$name]; } return $this->getNullRepository(); } return $this->repository ?: $this->getNullRepository(); }
php
public function getRepository($name = null) { $name = strtolower($name); if ($name) { if (isset($this->repositories[$name])) { return $this->repositories[$name]; } return $this->getNullRepository(); } return $this->repository ?: $this->getNullRepository(); }
[ "public", "function", "getRepository", "(", "$", "name", "=", "null", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "repositories", "[", "$", "n...
Method to get property Model @param string $name @return Repository
[ "Method", "to", "get", "property", "Model" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/ViewModel.php#L48-L61
train
ventoviro/windwalker-core
src/Core/View/ViewModel.php
ViewModel.getNullRepository
public function getNullRepository() { if (!$this->nullRepository) { $this->nullRepository = new Repository(); $this->nullRepository['is.null'] = true; $this->nullRepository['null'] = true; return $this->nullRepository; } return $this->nullRepository; }
php
public function getNullRepository() { if (!$this->nullRepository) { $this->nullRepository = new Repository(); $this->nullRepository['is.null'] = true; $this->nullRepository['null'] = true; return $this->nullRepository; } return $this->nullRepository; }
[ "public", "function", "getNullRepository", "(", ")", "{", "if", "(", "!", "$", "this", "->", "nullRepository", ")", "{", "$", "this", "->", "nullRepository", "=", "new", "Repository", "(", ")", ";", "$", "this", "->", "nullRepository", "[", "'is.null'", ...
Method to get property NullModel @return Repository
[ "Method", "to", "get", "property", "NullModel" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/ViewModel.php#L258-L270
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/MediaResourceTrait.php
MediaResourceTrait.clear
public function clear() { if (empty($this->store)) { throw new ClientError('Missing store instance to use for this operation.'); } if (!empty($this->url)) { $this->store->delete($this->getKey($this->url)); } $this->cached = false; }
php
public function clear() { if (empty($this->store)) { throw new ClientError('Missing store instance to use for this operation.'); } if (!empty($this->url)) { $this->store->delete($this->getKey($this->url)); } $this->cached = false; }
[ "public", "function", "clear", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "store", ")", ")", "{", "throw", "new", "ClientError", "(", "'Missing store instance to use for this operation.'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", ...
Removes this object from cache. @throws ClientError
[ "Removes", "this", "object", "from", "cache", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/MediaResourceTrait.php#L80-L91
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/MediaResourceTrait.php
MediaResourceTrait.getContents
public function getContents($cache = true) { $result = $this->downloadMe($cache); if ($cache) { $result = $this->store->get($this->getKey($this->url)); } return $result; }
php
public function getContents($cache = true) { $result = $this->downloadMe($cache); if ($cache) { $result = $this->store->get($this->getKey($this->url)); } return $result; }
[ "public", "function", "getContents", "(", "$", "cache", "=", "true", ")", "{", "$", "result", "=", "$", "this", "->", "downloadMe", "(", "$", "cache", ")", ";", "if", "(", "$", "cache", ")", "{", "$", "result", "=", "$", "this", "->", "store", "-...
Return the contents of this resource as stream. @param bool $cache True if the content should be cached locally by using the storage instance passed when creating the secucard connect API client. @return StreamInterface @throws ClientError
[ "Return", "the", "contents", "of", "this", "resource", "as", "stream", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/MediaResourceTrait.php#L110-L118
train
Blobfolio/blob-common
lib/blobfolio/common/dom.php
dom.get_nodes_by_class
public static function get_nodes_by_class($parent, $class=null, bool $all=false) { $nodes = array(); if (! \method_exists($parent, 'getElementsByTagName')) { return $nodes; } ref\cast::array($class); $class = \array_map('trim', $class); foreach ($class as $k=>$v) { $class[$k] = \ltrim($class[$k], '.'); } $class = \array_filter($class, 'strlen'); \sort($class); $class = \array_unique($class); if (! \count($class)) { return $nodes; } $possible = $parent->getElementsByTagName('*'); if ($possible->length) { foreach ($possible as $child) { if ($child->hasAttribute('class')) { $classes = $child->getAttribute('class'); ref\sanitize::whitespace($classes); $classes = \explode(' ', $classes); $overlap = \array_intersect($classes, $class); if (\count($overlap) && (! $all || \count($overlap) === \count($class))) { $nodes[] = $child; } } } } return $nodes; }
php
public static function get_nodes_by_class($parent, $class=null, bool $all=false) { $nodes = array(); if (! \method_exists($parent, 'getElementsByTagName')) { return $nodes; } ref\cast::array($class); $class = \array_map('trim', $class); foreach ($class as $k=>$v) { $class[$k] = \ltrim($class[$k], '.'); } $class = \array_filter($class, 'strlen'); \sort($class); $class = \array_unique($class); if (! \count($class)) { return $nodes; } $possible = $parent->getElementsByTagName('*'); if ($possible->length) { foreach ($possible as $child) { if ($child->hasAttribute('class')) { $classes = $child->getAttribute('class'); ref\sanitize::whitespace($classes); $classes = \explode(' ', $classes); $overlap = \array_intersect($classes, $class); if (\count($overlap) && (! $all || \count($overlap) === \count($class))) { $nodes[] = $child; } } } } return $nodes; }
[ "public", "static", "function", "get_nodes_by_class", "(", "$", "parent", ",", "$", "class", "=", "null", ",", "bool", "$", "all", "=", "false", ")", "{", "$", "nodes", "=", "array", "(", ")", ";", "if", "(", "!", "\\", "method_exists", "(", "$", "...
Get Nodes By Class This will return an array of DOMNode objects containing the specified class(es). This does not use DOMXPath. @param mixed $parent DOMDocument, DOMElement, etc. @param string|array $class One or more classes. @param bool $all Matches must contain *all* passed classes instead of *any*. @return array Nodes.
[ "Get", "Nodes", "By", "Class" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/dom.php#L145-L181
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.cancel
public function cancel($paymentId, $contractId = null, $amount = null, $reduceStakeholderPayment = false) { $object = [ 'contract' => $contractId, 'amount' => $amount, 'reduce_stakeholder_payment' => $reduceStakeholderPayment ]; $res = $this->execute($paymentId, 'cancel', null, $object); if (is_object($res)) { return $res; } return $res; }
php
public function cancel($paymentId, $contractId = null, $amount = null, $reduceStakeholderPayment = false) { $object = [ 'contract' => $contractId, 'amount' => $amount, 'reduce_stakeholder_payment' => $reduceStakeholderPayment ]; $res = $this->execute($paymentId, 'cancel', null, $object); if (is_object($res)) { return $res; } return $res; }
[ "public", "function", "cancel", "(", "$", "paymentId", ",", "$", "contractId", "=", "null", ",", "$", "amount", "=", "null", ",", "$", "reduceStakeholderPayment", "=", "false", ")", "{", "$", "object", "=", "[", "'contract'", "=>", "$", "contractId", ","...
Cancel or Refund an existing transaction. Currently, partial refunds are are not allowed for all payment products. @param string $paymentId The payment transaction id. @param string $contractId The id of the contract that was used to create this transaction. @param int $amount The amount that you want to refund to the payer. Use '0' for a full refund. @param bool $reduceStakeholderPayment TRUE if you want to change the amount of the stakeholder positions too (on partial refund) @return array ['result', 'demo', 'new_trans_id', 'remaining_amount', 'refund_waiting_for_payment'] @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Cancel", "or", "Refund", "an", "existing", "transaction", ".", "Currently", "partial", "refunds", "are", "are", "not", "allowed", "for", "all", "payment", "products", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L36-L50
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.capture
public function capture($paymentId, $contractId = null) { $class = $this->resourceMetadata->resourceClass; $object = [ 'contract' => $contractId, ]; $res = $this->execute($paymentId, 'capture', null, $object, $class); if ($res) { return true; } return false; }
php
public function capture($paymentId, $contractId = null) { $class = $this->resourceMetadata->resourceClass; $object = [ 'contract' => $contractId, ]; $res = $this->execute($paymentId, 'capture', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "capture", "(", "$", "paymentId", ",", "$", "contractId", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "$", "object", "=", "[", "'contract'", "=>", "$", "contractId", "...
Capture a pre-authorized payment transaction. @param string $paymentId The payment transaction id @param string $contractId The id of the contract that was used to create this transaction. @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Capture", "a", "pre", "-", "authorized", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L63-L78
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.updateBasket
public function updateBasket($paymentId, array $basket, $contractId = null) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->basket = $basket; $object->contract = $contractId; $res = $this->updateWithAction($paymentId, 'basket', null, $object, $class); if ($res) { return true; } return false; }
php
public function updateBasket($paymentId, array $basket, $contractId = null) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->basket = $basket; $object->contract = $contractId; $res = $this->updateWithAction($paymentId, 'basket', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "updateBasket", "(", "$", "paymentId", ",", "array", "$", "basket", ",", "$", "contractId", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transacti...
Add additional basket items to the payment transaction. F.e. for adding stakeholder payment items. @param string $paymentId The payment transaction id @param Basket[] $basket @param string $contractId The id of the contract that was used to create this transaction. @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Add", "additional", "basket", "items", "to", "the", "payment", "transaction", ".", "F", ".", "e", ".", "for", "adding", "stakeholder", "payment", "items", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L92-L109
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.reverseAccrual
public function reverseAccrual($paymentId) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->accrual = false; $res = $this->updateWithAction($paymentId, 'accrual', null, $object, $class); if ($res) { return true; } return false; }
php
public function reverseAccrual($paymentId) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->accrual = false; $res = $this->updateWithAction($paymentId, 'accrual', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "reverseAccrual", "(", "$", "paymentId", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new", "$", "class", "(", ")...
Remove the accrual flag of an existing payment transaction. @param string $paymentId The payment transaction id @return bool @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Remove", "the", "accrual", "flag", "of", "an", "existing", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L121-L137
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.initSubsequent
public function initSubsequent($paymentId, $amount, array $basket) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->amount = $amount; $object->basket = $basket; $res = $this->execute($paymentId, 'subsequent', null, $object, $class); if ($res) { return true; } return false; }
php
public function initSubsequent($paymentId, $amount, array $basket) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->amount = $amount; $object->basket = $basket; $res = $this->execute($paymentId, 'subsequent', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "initSubsequent", "(", "$", "paymentId", ",", "$", "amount", ",", "array", "$", "basket", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", ...
Subsequent posting to a approved transaction. This can only be executed once per payment transaction. @param string $paymentId The payment transaction id @param int $amount The new total amount (max. 120% of the old amount) @param Basket[] $basket The new basket items @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Subsequent", "posting", "to", "a", "approved", "transaction", ".", "This", "can", "only", "be", "executed", "once", "per", "payment", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L151-L168
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.updateSubscription
public function updateSubscription($paymentId, $purpose) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->subscription = new Subscription(); $object->subscription->purpose = $purpose; $res = $this->updateWithAction($paymentId, 'subscription', null, $object, $class); if ($res) { return true; } return false; }
php
public function updateSubscription($paymentId, $purpose) { $class = $this->resourceMetadata->resourceClass; /** * @var $object Transaction */ $object = new $class(); $object->id = $paymentId; $object->subscription = new Subscription(); $object->subscription->purpose = $purpose; $res = $this->updateWithAction($paymentId, 'subscription', null, $object, $class); if ($res) { return true; } return false; }
[ "public", "function", "updateSubscription", "(", "$", "paymentId", ",", "$", "purpose", ")", "{", "$", "class", "=", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ";", "/**\n * @var $object Transaction\n */", "$", "object", "=", "new"...
Create or update a subscription for a existing transaction @param string $paymentId The payment transaction id @param string $purpose The purpose of the subscription @return bool TRUE if successful, FALSE otherwise. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Create", "or", "update", "a", "subscription", "for", "a", "existing", "transaction" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L212-L229
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/Service/PaymentService.php
PaymentService.onStatusChange
public function onStatusChange($fn) { $this->registerEventHandler(static::class, $fn === null ? null : new PaymentChanged($fn, $this)); }
php
public function onStatusChange($fn) { $this->registerEventHandler(static::class, $fn === null ? null : new PaymentChanged($fn, $this)); }
[ "public", "function", "onStatusChange", "(", "$", "fn", ")", "{", "$", "this", "->", "registerEventHandler", "(", "static", "::", "class", ",", "$", "fn", "===", "null", "?", "null", ":", "new", "PaymentChanged", "(", "$", "fn", ",", "$", "this", ")", ...
Set a callback to be notified when a creditcard has changed. Pass null to remove a previous setting. @param callable|null $fn Any function which accepts a "Transaction" model class argument.
[ "Set", "a", "callback", "to", "be", "notified", "when", "a", "creditcard", "has", "changed", ".", "Pass", "null", "to", "remove", "a", "previous", "setting", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/Service/PaymentService.php#L236-L239
train
acdh-oeaw/repo-php-util
src/acdhOeaw/util/RepoConfig.php
RepoConfig.get
static public function get(string $property, bool $noException = false) { $value = @self::$config->get($property); if ($value === null && $noException === false) { throw new InvalidArgumentException('configuration property ' . $property . ' does not exist'); } return $value; }
php
static public function get(string $property, bool $noException = false) { $value = @self::$config->get($property); if ($value === null && $noException === false) { throw new InvalidArgumentException('configuration property ' . $property . ' does not exist'); } return $value; }
[ "static", "public", "function", "get", "(", "string", "$", "property", ",", "bool", "$", "noException", "=", "false", ")", "{", "$", "value", "=", "@", "self", "::", "$", "config", "->", "get", "(", "$", "property", ")", ";", "if", "(", "$", "value...
Returns given configuration property value. If property is not set, throws an error. Property value can be a literal as well as an composed object (e.g. array depending on the parsed ini file content). @param string $property configuration property name @param bool $noException should exception be avoided when property is not defined? @return mixed configuration property value @throws InvalidArgumentException
[ "Returns", "given", "configuration", "property", "value", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/RepoConfig.php#L72-L78
train
acdh-oeaw/repo-php-util
src/acdhOeaw/util/RepoConfig.php
RepoConfig.askForUserConfirmation
static public function askForUserConfirmation(bool $throwException = false): bool { echo "\n######################################################\n\n"; echo "Are you sure that you want to import data to the following instance?! \n\n "; echo "Type 'yes' to continue! \n\n"; echo self::get('sparqlUrl') . "\n"; echo self::get('fedoraApiUrl') . "\n"; $handle = fopen ("php://stdin","r"); $line = trim(fgets($handle)); fclose($handle); if ($line !== 'yes' && $throwException) { throw new RuntimeException('Configuration revoked by the user'); } return $line === 'yes'; }
php
static public function askForUserConfirmation(bool $throwException = false): bool { echo "\n######################################################\n\n"; echo "Are you sure that you want to import data to the following instance?! \n\n "; echo "Type 'yes' to continue! \n\n"; echo self::get('sparqlUrl') . "\n"; echo self::get('fedoraApiUrl') . "\n"; $handle = fopen ("php://stdin","r"); $line = trim(fgets($handle)); fclose($handle); if ($line !== 'yes' && $throwException) { throw new RuntimeException('Configuration revoked by the user'); } return $line === 'yes'; }
[ "static", "public", "function", "askForUserConfirmation", "(", "bool", "$", "throwException", "=", "false", ")", ":", "bool", "{", "echo", "\"\\n######################################################\\n\\n\"", ";", "echo", "\"Are you sure that you want to import data to the follo...
Displays Fedora and SPARQL endpoint URLs to the user and asks for confirmation. @param bool $throwException should an exception be thrown on lack of confirmation? @return bool
[ "Displays", "Fedora", "and", "SPARQL", "endpoint", "URLs", "to", "the", "user", "and", "asks", "for", "confirmation", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/RepoConfig.php#L145-L158
train
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Layout/LayoutBuilder.php
LayoutBuilder.build
public function build($options) { $container = $this->container; $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE; $obj = $this->factory->create($objType, [ 'logger' => $container['logger'], 'view' => $container['view'] ]); $obj->setData($options); return $obj; }
php
public function build($options) { $container = $this->container; $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE; $obj = $this->factory->create($objType, [ 'logger' => $container['logger'], 'view' => $container['view'] ]); $obj->setData($options); return $obj; }
[ "public", "function", "build", "(", "$", "options", ")", "{", "$", "container", "=", "$", "this", "->", "container", ";", "$", "objType", "=", "isset", "(", "$", "options", "[", "'type'", "]", ")", "?", "$", "options", "[", "'type'", "]", ":", "sel...
Build and return a new layout. @param array|\ArrayAccess $options The layout build options. @return LayoutInterface
[ "Build", "and", "return", "a", "new", "layout", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Layout/LayoutBuilder.php#L55-L67
train
hiqdev/yii2-language
src/Module.php
Module.detectLanguage
public function detectLanguage() { $acceptableLanguages = Yii::$app->getRequest()->getAcceptableLanguages(); foreach ($acceptableLanguages as $language) { if ($this->isValidLanguage($language)) { return $language; } } foreach ($acceptableLanguages as $language) { $pattern = preg_quote(substr($language, 0, 2), '/'); foreach ($this->languages as $key => $value) { if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) { return $this->isValidLanguage($key) ? $key : $value; } } } return false; }
php
public function detectLanguage() { $acceptableLanguages = Yii::$app->getRequest()->getAcceptableLanguages(); foreach ($acceptableLanguages as $language) { if ($this->isValidLanguage($language)) { return $language; } } foreach ($acceptableLanguages as $language) { $pattern = preg_quote(substr($language, 0, 2), '/'); foreach ($this->languages as $key => $value) { if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) { return $this->isValidLanguage($key) ? $key : $value; } } } return false; }
[ "public", "function", "detectLanguage", "(", ")", "{", "$", "acceptableLanguages", "=", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", "->", "getAcceptableLanguages", "(", ")", ";", "foreach", "(", "$", "acceptableLanguages", "as", "$", "language", "...
Determine language based on UserAgent.
[ "Determine", "language", "based", "on", "UserAgent", "." ]
c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3
https://github.com/hiqdev/yii2-language/blob/c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3/src/Module.php#L109-L127
train
hiqdev/yii2-language
src/Module.php
Module.saveLanguageIntoCookie
private function saveLanguageIntoCookie($language) { $cookie = new Cookie([ 'name' => $this->cookieName, 'value' => $language, 'expire' => time() + 86400 * $this->expireDays, ]); Yii::$app->response->cookies->add($cookie); }
php
private function saveLanguageIntoCookie($language) { $cookie = new Cookie([ 'name' => $this->cookieName, 'value' => $language, 'expire' => time() + 86400 * $this->expireDays, ]); Yii::$app->response->cookies->add($cookie); }
[ "private", "function", "saveLanguageIntoCookie", "(", "$", "language", ")", "{", "$", "cookie", "=", "new", "Cookie", "(", "[", "'name'", "=>", "$", "this", "->", "cookieName", ",", "'value'", "=>", "$", "language", ",", "'expire'", "=>", "time", "(", ")...
Save language into cookie. @param string $language
[ "Save", "language", "into", "cookie", "." ]
c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3
https://github.com/hiqdev/yii2-language/blob/c4aec9dafe13f4d96e0bf4a8997b74bf49663fa3/src/Module.php#L133-L141
train
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.excerpt
public static function excerpt($str='', $args=null) { ref\cast::string($str, true); ref\sanitize::whitespace($str, 0); $str = \strip_tags($str); $options = data::parse_args($args, constants::EXCERPT); if ($options['length'] < 1) { return ''; } $options['unit'] = \strtolower($options['unit']); switch (\substr($options['unit'], 0, 4)) { case 'char': $options['unit'] = 'character'; break; case 'word': $options['unit'] = 'word'; break; } // Character limit. if ( ('character' === $options['unit']) && mb::strlen($str) > $options['length'] ) { $str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix']; } // Word limit. elseif ( ('word' === $options['unit']) && \substr_count($str, ' ') > $options['length'] - 1 ) { $str = \explode(' ', $str); $str = \array_slice($str, 0, $options['length']); $str = \implode(' ', $str) . $options['suffix']; } return $str; }
php
public static function excerpt($str='', $args=null) { ref\cast::string($str, true); ref\sanitize::whitespace($str, 0); $str = \strip_tags($str); $options = data::parse_args($args, constants::EXCERPT); if ($options['length'] < 1) { return ''; } $options['unit'] = \strtolower($options['unit']); switch (\substr($options['unit'], 0, 4)) { case 'char': $options['unit'] = 'character'; break; case 'word': $options['unit'] = 'word'; break; } // Character limit. if ( ('character' === $options['unit']) && mb::strlen($str) > $options['length'] ) { $str = \trim(mb::substr($str, 0, $options['length'])) . $options['suffix']; } // Word limit. elseif ( ('word' === $options['unit']) && \substr_count($str, ' ') > $options['length'] - 1 ) { $str = \explode(' ', $str); $str = \array_slice($str, 0, $options['length']); $str = \implode(' ', $str) . $options['suffix']; } return $str; }
[ "public", "static", "function", "excerpt", "(", "$", "str", "=", "''", ",", "$", "args", "=", "null", ")", "{", "ref", "\\", "cast", "::", "string", "(", "$", "str", ",", "true", ")", ";", "ref", "\\", "sanitize", "::", "whitespace", "(", "$", "s...
Generate Text Except @param string $str String. @param mixed $args Arguments. @arg int $length Length limit. @arg string $unit Unit to examine, "character" or "word". @arg string $suffix Suffix, e.g. ... @return string Excerpt.
[ "Generate", "Text", "Except" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L214-L252
train
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.list_to_array
public static function list_to_array($list, $args=null) { ref\format::list_to_array($list, $args); return $list; }
php
public static function list_to_array($list, $args=null) { ref\format::list_to_array($list, $args); return $list; }
[ "public", "static", "function", "list_to_array", "(", "$", "list", ",", "$", "args", "=", "null", ")", "{", "ref", "\\", "format", "::", "list_to_array", "(", "$", "list", ",", "$", "args", ")", ";", "return", "$", "list", ";", "}" ]
List to Array Convert a delimited list into a proper array. @param mixed $list List. @param mixed $args Arguments or delimiter. @args string $delimiter Delimiter. @args bool $trim Trim. @args bool $unique Unique. @args bool $sort Sort output. @args string $cast Cast to type. @args mixed $min Minimum value. @args mixed $max Maximum value. @return array List.
[ "List", "to", "Array" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L419-L422
train
Blobfolio/blob-common
lib/blobfolio/common/format.php
format.to_csv
public static function to_csv($data=null, $headers=null, string $delimiter=',', string $eol="\n") { ref\cast::array($data); $data = \array_values(\array_filter($data, 'is_array')); ref\cast::array($headers); $out = array(); // Grab headers from data? if ( ! \count($headers) && \count($data) && (cast::array_type($data[0]) === 'associative') ) { $headers = \array_keys($data[0]); } // Output headers, if applicable. if (\count($headers)) { foreach ($headers as $k=>$v) { ref\cast::string($headers[$k], true); } ref\sanitize::csv($headers); $out[] = '"' . \implode('"' . $delimiter . '"', $headers) . '"'; } // Output data. if (\count($data)) { foreach ($data as $line) { foreach ($line as $k=>$v) { ref\cast::string($line[$k], true); } ref\sanitize::csv($line); $out[] = '"' . \implode('"' . $delimiter . '"', $line) . '"'; } } return \implode($eol, $out); }
php
public static function to_csv($data=null, $headers=null, string $delimiter=',', string $eol="\n") { ref\cast::array($data); $data = \array_values(\array_filter($data, 'is_array')); ref\cast::array($headers); $out = array(); // Grab headers from data? if ( ! \count($headers) && \count($data) && (cast::array_type($data[0]) === 'associative') ) { $headers = \array_keys($data[0]); } // Output headers, if applicable. if (\count($headers)) { foreach ($headers as $k=>$v) { ref\cast::string($headers[$k], true); } ref\sanitize::csv($headers); $out[] = '"' . \implode('"' . $delimiter . '"', $headers) . '"'; } // Output data. if (\count($data)) { foreach ($data as $line) { foreach ($line as $k=>$v) { ref\cast::string($line[$k], true); } ref\sanitize::csv($line); $out[] = '"' . \implode('"' . $delimiter . '"', $line) . '"'; } } return \implode($eol, $out); }
[ "public", "static", "function", "to_csv", "(", "$", "data", "=", "null", ",", "$", "headers", "=", "null", ",", "string", "$", "delimiter", "=", "','", ",", "string", "$", "eol", "=", "\"\\n\"", ")", "{", "ref", "\\", "cast", "::", "array", "(", "$...
Generate CSV from Data @param array $data Data (row=>cells). @param array $headers Headers. @param string $delimiter Delimiter. @param string $eol Line ending type. @return string CSV content.
[ "Generate", "CSV", "from", "Data" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/format.php#L521-L562
train
Blobfolio/blob-common
lib/blobfolio/common/sanitize.php
sanitize.domain
public static function domain($str='', bool $unicode=false) { ref\sanitize::domain($str, $unicode); return $str; }
php
public static function domain($str='', bool $unicode=false) { ref\sanitize::domain($str, $unicode); return $str; }
[ "public", "static", "function", "domain", "(", "$", "str", "=", "''", ",", "bool", "$", "unicode", "=", "false", ")", "{", "ref", "\\", "sanitize", "::", "domain", "(", "$", "str", ",", "$", "unicode", ")", ";", "return", "$", "str", ";", "}" ]
Domain Name. This locates the domain name portion of a URL, removes leading "www." subdomains, and ignores IP addresses. @param string $str Domain. @param bool $unicode Unicode. @return string Domain.
[ "Domain", "Name", "." ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/sanitize.php#L131-L134
train
Blobfolio/blob-common
lib/blobfolio/common/sanitize.php
sanitize.to_range
public static function to_range($value, $min=null, $max=null) { ref\sanitize::to_range($value, $min, $max); return $value; }
php
public static function to_range($value, $min=null, $max=null) { ref\sanitize::to_range($value, $min, $max); return $value; }
[ "public", "static", "function", "to_range", "(", "$", "value", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "ref", "\\", "sanitize", "::", "to_range", "(", "$", "value", ",", "$", "min", ",", "$", "max", ")", ";", "return...
Confine a Value to a Range @param mixed $value Value. @param mixed $min Min. @param mixed $max Max. @return mixed Value.
[ "Confine", "a", "Value", "to", "a", "Range" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/sanitize.php#L385-L388
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Event/DefaultEventHandler.php
DefaultEventHandler.accept
protected function accept(Event $event) { return $event->target === $this->eventTarget && $event->type === $this->eventType; }
php
protected function accept(Event $event) { return $event->target === $this->eventTarget && $event->type === $this->eventType; }
[ "protected", "function", "accept", "(", "Event", "$", "event", ")", "{", "return", "$", "event", "->", "target", "===", "$", "this", "->", "eventTarget", "&&", "$", "event", "->", "type", "===", "$", "this", "->", "eventType", ";", "}" ]
Can be used by handlers to determine if a handler should process the given event. The default decision is made by comparing the given and this instances event target and event type. May be overridden to adapt. @param Event $event The event to process. @return bool True if can handle, false else.
[ "Can", "be", "used", "by", "handlers", "to", "determine", "if", "a", "handler", "should", "process", "the", "given", "event", ".", "The", "default", "decision", "is", "made", "by", "comparing", "the", "given", "and", "this", "instances", "event", "target", ...
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Event/DefaultEventHandler.php#L55-L58
train
ventoviro/windwalker-core
src/Core/Schedule/ScheduleEvent.php
ScheduleEvent.setExpression
public function setExpression($expression) { if (is_string($expression)) { $expression = CronExpression::factory($expression); } $this->expression = $expression; return $this; }
php
public function setExpression($expression) { if (is_string($expression)) { $expression = CronExpression::factory($expression); } $this->expression = $expression; return $this; }
[ "public", "function", "setExpression", "(", "$", "expression", ")", "{", "if", "(", "is_string", "(", "$", "expression", ")", ")", "{", "$", "expression", "=", "CronExpression", "::", "factory", "(", "$", "expression", ")", ";", "}", "$", "this", "->", ...
Method to set property expression @param CronExpression|string $expression @return static Return self to support chaining. @since 3.5.3
[ "Method", "to", "set", "property", "expression" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Schedule/ScheduleEvent.php#L151-L160
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.isValid
public function isValid() { $data = $this->toArray(); $missing = array_diff(self::$REQUIRED_FIELDS, array_keys($data)); if ($missing) { throw new \InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing)); } return true; }
php
public function isValid() { $data = $this->toArray(); $missing = array_diff(self::$REQUIRED_FIELDS, array_keys($data)); if ($missing) { throw new \InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing)); } return true; }
[ "public", "function", "isValid", "(", ")", "{", "$", "data", "=", "$", "this", "->", "toArray", "(", ")", ";", "$", "missing", "=", "array_diff", "(", "self", "::", "$", "REQUIRED_FIELDS", ",", "array_keys", "(", "$", "data", ")", ")", ";", "if", "...
Validates the configuration for the api client @throws \InvalidArgumentException If some required param is missing @return true
[ "Validates", "the", "configuration", "for", "the", "api", "client" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L120-L131
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.setAuth
public function setAuth($auth) { $auth = strtolower($auth); if (!in_array($auth, [self::AUTHENTICATION_METHOD_OAUTH])) { throw new \InvalidArgumentException('Parameter "auth" must be filled and valid'); } $this->auth = $auth; return $this; }
php
public function setAuth($auth) { $auth = strtolower($auth); if (!in_array($auth, [self::AUTHENTICATION_METHOD_OAUTH])) { throw new \InvalidArgumentException('Parameter "auth" must be filled and valid'); } $this->auth = $auth; return $this; }
[ "public", "function", "setAuth", "(", "$", "auth", ")", "{", "$", "auth", "=", "strtolower", "(", "$", "auth", ")", ";", "if", "(", "!", "in_array", "(", "$", "auth", ",", "[", "self", "::", "AUTHENTICATION_METHOD_OAUTH", "]", ")", ")", "{", "throw",...
Define the authentication method @param string $auth @throws \InvalidArgumentException If some required param is missing or invalid @return self
[ "Define", "the", "authentication", "method" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L264-L274
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/ApiClientConfiguration.php
ApiClientConfiguration.setAcceptLanguage
public function setAcceptLanguage($accept_language) { $accept_language = strtolower($accept_language); if (!in_array($accept_language, [self::ACCEPT_LANGUAGE_EN, self::ACCEPT_LANGUAGE_DE])) { throw new \InvalidArgumentException('Parameter "accept_language" must be valid'); } $this->accept_language = $accept_language; return $this; }
php
public function setAcceptLanguage($accept_language) { $accept_language = strtolower($accept_language); if (!in_array($accept_language, [self::ACCEPT_LANGUAGE_EN, self::ACCEPT_LANGUAGE_DE])) { throw new \InvalidArgumentException('Parameter "accept_language" must be valid'); } $this->accept_language = $accept_language; return $this; }
[ "public", "function", "setAcceptLanguage", "(", "$", "accept_language", ")", "{", "$", "accept_language", "=", "strtolower", "(", "$", "accept_language", ")", ";", "if", "(", "!", "in_array", "(", "$", "accept_language", ",", "[", "self", "::", "ACCEPT_LANGUAG...
Define the language of the error and other api messages @param string $accept_language @throws \InvalidArgumentException If the given param is invalid @return self
[ "Define", "the", "language", "of", "the", "error", "and", "other", "api", "messages" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/ApiClientConfiguration.php#L318-L328
train
diff-sniffer/core
src/Diff.php
Diff.filter
public function filter(string $path, array $report) : array { $report['messages'] = isset($this->paths[$path]) ? array_intersect_key( $report['messages'], array_flip($this->paths[$path]) ) : []; $errors = $warnings = $fixable = 0; foreach ($report['messages'] as $line) { foreach ($line as $messages) { foreach ($messages as $message) { switch ($message['type']) { case 'ERROR': $errors++; break; case 'WARNING': $warnings++; break; } if ($message['fixable']) { $fixable++; } } } } return array_merge($report, [ 'errors' => $errors, 'warnings' => $warnings, 'fixable' => $fixable, ]); }
php
public function filter(string $path, array $report) : array { $report['messages'] = isset($this->paths[$path]) ? array_intersect_key( $report['messages'], array_flip($this->paths[$path]) ) : []; $errors = $warnings = $fixable = 0; foreach ($report['messages'] as $line) { foreach ($line as $messages) { foreach ($messages as $message) { switch ($message['type']) { case 'ERROR': $errors++; break; case 'WARNING': $warnings++; break; } if ($message['fixable']) { $fixable++; } } } } return array_merge($report, [ 'errors' => $errors, 'warnings' => $warnings, 'fixable' => $fixable, ]); }
[ "public", "function", "filter", "(", "string", "$", "path", ",", "array", "$", "report", ")", ":", "array", "{", "$", "report", "[", "'messages'", "]", "=", "isset", "(", "$", "this", "->", "paths", "[", "$", "path", "]", ")", "?", "array_intersect_k...
Filters file report producing another one containing only the lines affected by diff @param string $path File path @param array $report Report data @return array
[ "Filters", "file", "report", "producing", "another", "one", "containing", "only", "the", "lines", "affected", "by", "diff" ]
583369a5f5c91496862f6bdf60b69565da4bc05d
https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/Diff.php#L56-L89
train
diff-sniffer/core
src/Diff.php
Diff.parse
private function parse(string $diff) : array { $diff = preg_split("/((\r?\n)|(\r\n?))/", $diff); $paths = []; $number = 0; $path = null; foreach ($diff as $line) { if (preg_match('~^\+\+\+\s(.*)~', $line, $matches)) { $path = substr($matches[1], strpos($matches[1], '/') + 1); } elseif (preg_match( '~^@@ -[0-9]+,[0-9]+? \+([0-9]+),[0-9]+? @@.*$~', $line, $matches )) { $number = (int) $matches[1]; } elseif (preg_match('~^\+(.*)~', $line, $matches)) { $paths[$path][] = $number; $number++; } elseif (preg_match('~^[^-]+(.*)~', $line, $matches)) { $number++; } } return $paths; }
php
private function parse(string $diff) : array { $diff = preg_split("/((\r?\n)|(\r\n?))/", $diff); $paths = []; $number = 0; $path = null; foreach ($diff as $line) { if (preg_match('~^\+\+\+\s(.*)~', $line, $matches)) { $path = substr($matches[1], strpos($matches[1], '/') + 1); } elseif (preg_match( '~^@@ -[0-9]+,[0-9]+? \+([0-9]+),[0-9]+? @@.*$~', $line, $matches )) { $number = (int) $matches[1]; } elseif (preg_match('~^\+(.*)~', $line, $matches)) { $paths[$path][] = $number; $number++; } elseif (preg_match('~^[^-]+(.*)~', $line, $matches)) { $number++; } } return $paths; }
[ "private", "function", "parse", "(", "string", "$", "diff", ")", ":", "array", "{", "$", "diff", "=", "preg_split", "(", "\"/((\\r?\\n)|(\\r\\n?))/\"", ",", "$", "diff", ")", ";", "$", "paths", "=", "[", "]", ";", "$", "number", "=", "0", ";", "$", ...
Parses diff and returns array containing affected paths and line numbers @param string $diff Diff output @return array
[ "Parses", "diff", "and", "returns", "array", "containing", "affected", "paths", "and", "line", "numbers" ]
583369a5f5c91496862f6bdf60b69565da4bc05d
https://github.com/diff-sniffer/core/blob/583369a5f5c91496862f6bdf60b69565da4bc05d/src/Diff.php#L98-L123
train
polyfony-inc/polyfony
Private/Polyfony/Bundles.php
Bundles.init
public static function init() :void { // marker Profiler::setMarker('Bundles.init', 'framework'); // if cache is enabled and in prod load the cache, else parse bundles Config::isProd() && Cache::has('Includes') ? self::loadCachedDependencies() : self::loadDependencies(); // now that we have the list of config files, pass them to the config class Config::includeBundlesConfigs(self::$_configs); // now that we have the list of route files, pass them to the router class Router::includeBundlesRoutes(self::$_routes); // marker Profiler::releaseMarker('Bundles.init'); }
php
public static function init() :void { // marker Profiler::setMarker('Bundles.init', 'framework'); // if cache is enabled and in prod load the cache, else parse bundles Config::isProd() && Cache::has('Includes') ? self::loadCachedDependencies() : self::loadDependencies(); // now that we have the list of config files, pass them to the config class Config::includeBundlesConfigs(self::$_configs); // now that we have the list of route files, pass them to the router class Router::includeBundlesRoutes(self::$_routes); // marker Profiler::releaseMarker('Bundles.init'); }
[ "public", "static", "function", "init", "(", ")", ":", "void", "{", "// marker", "Profiler", "::", "setMarker", "(", "'Bundles.init'", ",", "'framework'", ")", ";", "// if cache is enabled and in prod load the cache, else parse bundles", "Config", "::", "isProd", "(", ...
will get the list of bundles and get their routes and runtimes
[ "will", "get", "the", "list", "of", "bundles", "and", "get", "their", "routes", "and", "runtimes" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Bundles.php#L12-L29
train
polyfony-inc/polyfony
Private/Polyfony/Bundles.php
Bundles.getLocales
public static function getLocales(string $bundle) :array { // declare an array to hold the list $locales = array(); // set the locales path $locales_path = "../Private/Bundles/{$bundle}/Locales/"; // if the directory exists if(file_exists($locales_path) && is_dir($locales_path)) { // for each file in the directory foreach(scandir($locales_path) as $locales_file) { // if the file is a normal one if(substr($locales_file,0,1) != '.' ) { // push it into the array of locales $locales[] = $locales_path . $locales_file ; } } } // return all found locales return($locales); }
php
public static function getLocales(string $bundle) :array { // declare an array to hold the list $locales = array(); // set the locales path $locales_path = "../Private/Bundles/{$bundle}/Locales/"; // if the directory exists if(file_exists($locales_path) && is_dir($locales_path)) { // for each file in the directory foreach(scandir($locales_path) as $locales_file) { // if the file is a normal one if(substr($locales_file,0,1) != '.' ) { // push it into the array of locales $locales[] = $locales_path . $locales_file ; } } } // return all found locales return($locales); }
[ "public", "static", "function", "getLocales", "(", "string", "$", "bundle", ")", ":", "array", "{", "// declare an array to hold the list", "$", "locales", "=", "array", "(", ")", ";", "// set the locales path", "$", "locales_path", "=", "\"../Private/Bundles/{$bundle...
get locales for a bundle
[ "get", "locales", "for", "a", "bundle" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Bundles.php#L70-L90
train
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Payment/CustomersService.php
CustomersService.process
private function process(Customer &$customer) { if (isset($customer->contact) && isset($customer->contact->picture)) { $customer->contact->pictureObject = $this->initMediaResource($customer->contact->picture); } }
php
private function process(Customer &$customer) { if (isset($customer->contact) && isset($customer->contact->picture)) { $customer->contact->pictureObject = $this->initMediaResource($customer->contact->picture); } }
[ "private", "function", "process", "(", "Customer", "&", "$", "customer", ")", "{", "if", "(", "isset", "(", "$", "customer", "->", "contact", ")", "&&", "isset", "(", "$", "customer", "->", "contact", "->", "picture", ")", ")", "{", "$", "customer", ...
Handles proper picture object initialization after retrieval of a customer. @param Customer $customer
[ "Handles", "proper", "picture", "object", "initialization", "after", "retrieval", "of", "a", "customer", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Payment/CustomersService.php#L43-L48
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/CheckAcess.php
CheckAcess.check
static public function check(FedoraResource $res): bool { if (self::$client === null) { self::$client = new Client([ 'verify' => false, ]); } $headers = []; if (isset($_SERVER['PHP_AUTH_USER'])) { $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); } $cookies = []; foreach ($_COOKIE as $k => $v) { $cookies[] = $k . '=' . $v; } if (count($cookies) > 0) { $headers['Cookie'] = implode('; ', $cookies); } $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers); try { $resp = self::$client->send($req); return true; } catch (RequestException $ex) { if ($ex->hasResponse()) { $resp = $ex->getResponse(); if (in_array($resp->getStatusCode(), [401, 403])) { return false; } } throw $ex; } }
php
static public function check(FedoraResource $res): bool { if (self::$client === null) { self::$client = new Client([ 'verify' => false, ]); } $headers = []; if (isset($_SERVER['PHP_AUTH_USER'])) { $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); } $cookies = []; foreach ($_COOKIE as $k => $v) { $cookies[] = $k . '=' . $v; } if (count($cookies) > 0) { $headers['Cookie'] = implode('; ', $cookies); } $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers); try { $resp = self::$client->send($req); return true; } catch (RequestException $ex) { if ($ex->hasResponse()) { $resp = $ex->getResponse(); if (in_array($resp->getStatusCode(), [401, 403])) { return false; } } throw $ex; } }
[ "static", "public", "function", "check", "(", "FedoraResource", "$", "res", ")", ":", "bool", "{", "if", "(", "self", "::", "$", "client", "===", "null", ")", "{", "self", "::", "$", "client", "=", "new", "Client", "(", "[", "'verify'", "=>", "false"...
Checks if a given resource is accessible with same credentials as ones provided in the current request. @param FedoraResource $res @return bool @throws RequestException
[ "Checks", "if", "a", "given", "resource", "is", "accessible", "with", "same", "credentials", "as", "ones", "provided", "in", "the", "current", "request", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/CheckAcess.php#L55-L87
train
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.redirect
public static function redirect(string $source_url, string $redirection_url, int $status_code=301) { // create a new route $route = new Route(); // add it to the list of known routes self::$_routes[$route->name] = $route ->setUrl($source_url) ->setRedirect($redirection_url, $status_code); // return the route for finer tuning return self::$_routes[$route->name]; }
php
public static function redirect(string $source_url, string $redirection_url, int $status_code=301) { // create a new route $route = new Route(); // add it to the list of known routes self::$_routes[$route->name] = $route ->setUrl($source_url) ->setRedirect($redirection_url, $status_code); // return the route for finer tuning return self::$_routes[$route->name]; }
[ "public", "static", "function", "redirect", "(", "string", "$", "source_url", ",", "string", "$", "redirection_url", ",", "int", "$", "status_code", "=", "301", ")", "{", "// create a new route", "$", "route", "=", "new", "Route", "(", ")", ";", "// add it t...
new syntax for quick redirects
[ "new", "syntax", "for", "quick", "redirects" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L103-L112
train
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.getRoute
public static function getRoute(string $route_name) { // return the route of false return self::hasRoute($route_name) ? self::$_routes[$route_name] : false; }
php
public static function getRoute(string $route_name) { // return the route of false return self::hasRoute($route_name) ? self::$_routes[$route_name] : false; }
[ "public", "static", "function", "getRoute", "(", "string", "$", "route_name", ")", "{", "// return the route of false", "return", "self", "::", "hasRoute", "(", "$", "route_name", ")", "?", "self", "::", "$", "_routes", "[", "$", "route_name", "]", ":", "fal...
get a specific route
[ "get", "a", "specific", "route" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L121-L124
train
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.routeMatch
private static function routeMatch(string $request_url, string $request_method, Route $route) :bool { // if the method is set for that route, and it doesn't match if(!$route->hasMethod($request_method)) { return false; } // if the url doesn't begin with the static segment or that route if(!$route->hasStaticUrlSegment($request_url)) { return false; } // if we've got a redirect, let's go for it $route->redirectIfItIsOne(); // get a list of current request parameters, with numerical indexes $indexed_request_parameters = Request::getUrlIndexedParameters($route->staticSegment); // if restricttion against url parameters don't match if(!$route->validatesTheseParameters($indexed_request_parameters)) { return false; } // send the named parameters to the request class $route->sendNamedParametersToRequest($indexed_request_parameters); // deduce the dynamic action from the url parameters if necessary $route->deduceAction(); // check if they match defined constraints return true; }
php
private static function routeMatch(string $request_url, string $request_method, Route $route) :bool { // if the method is set for that route, and it doesn't match if(!$route->hasMethod($request_method)) { return false; } // if the url doesn't begin with the static segment or that route if(!$route->hasStaticUrlSegment($request_url)) { return false; } // if we've got a redirect, let's go for it $route->redirectIfItIsOne(); // get a list of current request parameters, with numerical indexes $indexed_request_parameters = Request::getUrlIndexedParameters($route->staticSegment); // if restricttion against url parameters don't match if(!$route->validatesTheseParameters($indexed_request_parameters)) { return false; } // send the named parameters to the request class $route->sendNamedParametersToRequest($indexed_request_parameters); // deduce the dynamic action from the url parameters if necessary $route->deduceAction(); // check if they match defined constraints return true; }
[ "private", "static", "function", "routeMatch", "(", "string", "$", "request_url", ",", "string", "$", "request_method", ",", "Route", "$", "route", ")", ":", "bool", "{", "// if the method is set for that route, and it doesn't match", "if", "(", "!", "$", "route", ...
Test to see if this route is valid against the URL. @access private @param array $requestUrl The URL to test the route against. @param Core\Route $route A Route declared by the application. @return boolean
[ "Test", "to", "see", "if", "this", "route", "is", "valid", "against", "the", "URL", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L178-L203
train
polyfony-inc/polyfony
Private/Polyfony/Router.php
Router.reverse
public static function reverse( string $route_name, array $parameters = [], bool $is_absolute = false, bool $force_tls = false ) :string { // if the specified route doesn't exist if(!self::hasRoute($route_name)) { // we cannot reverse a route that does not exist throw new Exception("Router::reverse() : The [{$route_name}] route does not exist"); } // return the reversed url return self::$_routes[$route_name]->getAssembledUrl($parameters, $is_absolute, $force_tls); }
php
public static function reverse( string $route_name, array $parameters = [], bool $is_absolute = false, bool $force_tls = false ) :string { // if the specified route doesn't exist if(!self::hasRoute($route_name)) { // we cannot reverse a route that does not exist throw new Exception("Router::reverse() : The [{$route_name}] route does not exist"); } // return the reversed url return self::$_routes[$route_name]->getAssembledUrl($parameters, $is_absolute, $force_tls); }
[ "public", "static", "function", "reverse", "(", "string", "$", "route_name", ",", "array", "$", "parameters", "=", "[", "]", ",", "bool", "$", "is_absolute", "=", "false", ",", "bool", "$", "force_tls", "=", "false", ")", ":", "string", "{", "// if the s...
Reverse the router. Make a URL out of a route name and parameters, rather than parsing one. Note that this function does not care about URL paths! @access public @param string $route_name The name of the route we wish to generate a URL for. @param array $parameters The parameters that the route requires. @return string @throws \Exception If the route does not exist. @static
[ "Reverse", "the", "router", "." ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Router.php#L218-L231
train
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.error
public function error($code, $message, $file, $line, $context = null) { if (error_reporting() === 0) { return; } $content = sprintf('%s. File: %s (line: %s)', $message, $file, $line); throw new \ErrorException($content, 500, $code, $file, $line, new \Error()); }
php
public function error($code, $message, $file, $line, $context = null) { if (error_reporting() === 0) { return; } $content = sprintf('%s. File: %s (line: %s)', $message, $file, $line); throw new \ErrorException($content, 500, $code, $file, $line, new \Error()); }
[ "public", "function", "error", "(", "$", "code", ",", "$", "message", ",", "$", "file", ",", "$", "line", ",", "$", "context", "=", "null", ")", "{", "if", "(", "error_reporting", "(", ")", "===", "0", ")", "{", "return", ";", "}", "$", "content"...
The error handler. @param integer $code The level of the error raised, as an integer. @param string $message The error message, as a string. @param string $file The filename that the error was raised in, as a string. @param integer $line The line number the error was raised at, as an integer. @param mixed $context An array that contains variables in the scope which this error occurred. @throws \ErrorException @return void @see http://php.net/manual/en/function.set-error-handler.php
[ "The", "error", "handler", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L115-L124
train
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.exception
public function exception($exception) { try { foreach ($this->handlers as $handler) { $handler($exception); } } catch (\Throwable $e) { $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e; if ($this->app->get('system.debug')) { exit($msg); } exit($e->getMessage()); } exit(); }
php
public function exception($exception) { try { foreach ($this->handlers as $handler) { $handler($exception); } } catch (\Throwable $e) { $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e; if ($this->app->get('system.debug')) { exit($msg); } exit($e->getMessage()); } exit(); }
[ "public", "function", "exception", "(", "$", "exception", ")", "{", "try", "{", "foreach", "(", "$", "this", "->", "handlers", "as", "$", "handler", ")", "{", "$", "handler", "(", "$", "exception", ")", ";", "}", "}", "catch", "(", "\\", "Throwable",...
The exception handler. @param \Throwable|\Exception $exception The exception object. @return void @link http://php.net/manual/en/function.set-exception-handler.php
[ "The", "exception", "handler", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L135-L152
train
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.setErrorTemplate
public function setErrorTemplate($errorTemplate, $engine = null) { if (!\is_string($errorTemplate)) { throw new \InvalidArgumentException('Please use string as template name (Example: "folder.file").'); } $this->errorTemplate = $errorTemplate; if ($engine) { $this->setEngine($engine); } }
php
public function setErrorTemplate($errorTemplate, $engine = null) { if (!\is_string($errorTemplate)) { throw new \InvalidArgumentException('Please use string as template name (Example: "folder.file").'); } $this->errorTemplate = $errorTemplate; if ($engine) { $this->setEngine($engine); } }
[ "public", "function", "setErrorTemplate", "(", "$", "errorTemplate", ",", "$", "engine", "=", "null", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "errorTemplate", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Please use s...
Method to set property errorTemplate @param string $errorTemplate @param string $engine @return void @throws \InvalidArgumentException
[ "Method", "to", "set", "property", "errorTemplate" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L201-L212
train
ventoviro/windwalker-core
src/Core/Error/ErrorManager.php
ErrorManager.addHandler
public function addHandler(callable $handler, $name = null) { if ($name) { $this->handlers[$name] = $handler; } else { $this->handlers[] = $handler; } return $this; }
php
public function addHandler(callable $handler, $name = null) { if ($name) { $this->handlers[$name] = $handler; } else { $this->handlers[] = $handler; } return $this; }
[ "public", "function", "addHandler", "(", "callable", "$", "handler", ",", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", ")", "{", "$", "this", "->", "handlers", "[", "$", "name", "]", "=", "$", "handler", ";", "}", "else", "{", "$",...
Method to set property handler @param callable $handler @param string $name @return static Return self to support chaining.
[ "Method", "to", "set", "property", "handler" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Error/ErrorManager.php#L288-L297
train
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/parameter/AddParam.php
AddParam.transform
public function transform(string $value, string $paramName = '', string $paramValue = ''): string { $value = parse_url($value); if (!isset($value['query'])) { $value['query'] = ''; } $param = []; parse_str($value['query'], $param); if (!isset($param[$paramName])) { $param[$paramName] = $paramValue; } else { if (!is_array($param[$paramName])) { $param[$paramName] = [$param[$paramName]]; } $param[$paramName][] = $paramValue; $param[$paramName] = array_unique($param[$paramName]); } $value['query'] = http_build_query($param); $scheme = isset($value['scheme']) ? $value['scheme'] . '://' : ''; $host = isset($value['host']) ? $value['host'] : ''; $port = isset($value['port']) ? ':' . $value['port'] : ''; $user = isset($value['user']) ? $value['user'] : ''; $pass = isset($value['pass']) ? ':' . $value['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($value['path']) ? $value['path'] : ''; $query = isset($value['query']) ? '?' . $value['query'] : ''; $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : ''; return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; }
php
public function transform(string $value, string $paramName = '', string $paramValue = ''): string { $value = parse_url($value); if (!isset($value['query'])) { $value['query'] = ''; } $param = []; parse_str($value['query'], $param); if (!isset($param[$paramName])) { $param[$paramName] = $paramValue; } else { if (!is_array($param[$paramName])) { $param[$paramName] = [$param[$paramName]]; } $param[$paramName][] = $paramValue; $param[$paramName] = array_unique($param[$paramName]); } $value['query'] = http_build_query($param); $scheme = isset($value['scheme']) ? $value['scheme'] . '://' : ''; $host = isset($value['host']) ? $value['host'] : ''; $port = isset($value['port']) ? ':' . $value['port'] : ''; $user = isset($value['user']) ? $value['user'] : ''; $pass = isset($value['pass']) ? ':' . $value['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($value['path']) ? $value['path'] : ''; $query = isset($value['query']) ? '?' . $value['query'] : ''; $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : ''; return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; }
[ "public", "function", "transform", "(", "string", "$", "value", ",", "string", "$", "paramName", "=", "''", ",", "string", "$", "paramValue", "=", "''", ")", ":", "string", "{", "$", "value", "=", "parse_url", "(", "$", "value", ")", ";", "if", "(", ...
Adds a given query parameter value to the URL. If the parameter already exists in the query, it's turned into an array. @param string $value URL to be transformed @param string $paramName query parameter name @param string $paramValue query parameter value @return string
[ "Adds", "a", "given", "query", "parameter", "value", "to", "the", "URL", ".", "If", "the", "parameter", "already", "exists", "in", "the", "query", "it", "s", "turned", "into", "an", "array", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/parameter/AddParam.php#L57-L87
train
locomotivemtl/charcoal-ui
src/Charcoal/Ui/FormGroup/FormGroupTrait.php
FormGroupTrait.inputs
public function inputs(callable $inputCallback = null) { $groups = $this->groups; uasort($groups, [ $this, 'sortItemsByPriority' ]); $inputCallback = isset($inputCallback) ? $inputCallback : $this->inputCallback; foreach ($inputs as $input) { if (!$input->l10nMode()) { $input->setL10nMode($this->l10nMode()); } if ($inputCallback) { $inputCallback($input); } $GLOBALS['widget_template'] = $input->template(); yield $input->ident() => $input; $GLOBALS['widget_template'] = ''; } }
php
public function inputs(callable $inputCallback = null) { $groups = $this->groups; uasort($groups, [ $this, 'sortItemsByPriority' ]); $inputCallback = isset($inputCallback) ? $inputCallback : $this->inputCallback; foreach ($inputs as $input) { if (!$input->l10nMode()) { $input->setL10nMode($this->l10nMode()); } if ($inputCallback) { $inputCallback($input); } $GLOBALS['widget_template'] = $input->template(); yield $input->ident() => $input; $GLOBALS['widget_template'] = ''; } }
[ "public", "function", "inputs", "(", "callable", "$", "inputCallback", "=", "null", ")", "{", "$", "groups", "=", "$", "this", "->", "groups", ";", "uasort", "(", "$", "groups", ",", "[", "$", "this", ",", "'sortItemsByPriority'", "]", ")", ";", "$", ...
Form Input generator. @param callable $inputCallback Optional. Input callback. @return FormGroupInterface[]|Generator
[ "Form", "Input", "generator", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/FormGroup/FormGroupTrait.php#L218-L235
train
acdh-oeaw/repo-php-util
src/acdhOeaw/util/MetadataCollection.php
MetadataCollection.import
public function import(string $namespace, int $singleOutNmsp): array { $dict = array(self::SKIP, self::CREATE); if (!in_array($singleOutNmsp, $dict)) { throw new InvalidArgumentException('singleOutNmsp parameters must be one of MetadataCollection::SKIP, MetadataCollection::CREATE'); } $this->autoCommitCounter = 0; $this->removeLiteralIds(); $this->promoteUrisToIds(); $toBeImported = $this->filterResources($namespace, $singleOutNmsp); $fedoraResources = $this->assureUuids($toBeImported); foreach ($toBeImported as $n => $res) { $uri = $res->getUri(); $fedoraRes = $fedoraResources[$uri]; echo self::$debug ? "Importing " . $uri . " (" . ($n + 1) . "/" . count($toBeImported) . ")\n" : ""; $this->sanitizeResource($res, $namespace); echo self::$debug ? "\tupdating " . $fedoraRes->getUri(true) . "\n" : ""; $meta = $fedoraRes->getMetadata(); $meta->merge($res, array(RC::idProp())); $fedoraRes->setMetadata($meta, false); $fedoraRes->updateMetadata(); $this->handleAutoCommit(); } return array_values($fedoraResources); }
php
public function import(string $namespace, int $singleOutNmsp): array { $dict = array(self::SKIP, self::CREATE); if (!in_array($singleOutNmsp, $dict)) { throw new InvalidArgumentException('singleOutNmsp parameters must be one of MetadataCollection::SKIP, MetadataCollection::CREATE'); } $this->autoCommitCounter = 0; $this->removeLiteralIds(); $this->promoteUrisToIds(); $toBeImported = $this->filterResources($namespace, $singleOutNmsp); $fedoraResources = $this->assureUuids($toBeImported); foreach ($toBeImported as $n => $res) { $uri = $res->getUri(); $fedoraRes = $fedoraResources[$uri]; echo self::$debug ? "Importing " . $uri . " (" . ($n + 1) . "/" . count($toBeImported) . ")\n" : ""; $this->sanitizeResource($res, $namespace); echo self::$debug ? "\tupdating " . $fedoraRes->getUri(true) . "\n" : ""; $meta = $fedoraRes->getMetadata(); $meta->merge($res, array(RC::idProp())); $fedoraRes->setMetadata($meta, false); $fedoraRes->updateMetadata(); $this->handleAutoCommit(); } return array_values($fedoraResources); }
[ "public", "function", "import", "(", "string", "$", "namespace", ",", "int", "$", "singleOutNmsp", ")", ":", "array", "{", "$", "dict", "=", "array", "(", "self", "::", "SKIP", ",", "self", "::", "CREATE", ")", ";", "if", "(", "!", "in_array", "(", ...
Imports the whole graph by looping over all resources. A repository resource is created for every node containing at least one cfg:fedoraIdProp property and: - containg at least one other property - or being within $namespace - or when $singleOutNmsp equals to MetadataCollection::CREATE Resources without cfg:fedoraIdProp property are skipped as we are unable to identify them on the next import (which would lead to duplication). Resource with a fully qualified URI is considered as having cfg:fedoraIdProp (its URI is taken as cfg:fedoraIdProp property value). Resources in the graph can denote relationships in any way but all object URIs already existing in the repository and all object URIs in the $namespace will be turned into ACDH ids. This means graph can not contain circular dependencies between resources which do not already exist in the repository, like: ``` _:a some:Prop _:b . _:b some:Prop _:a . ``` The $errorOnCycle parameter determines behaviour of the method when such a cycle exists in the graph. @param string $namespace repository resources will be created for all resources in this namespace @param int $singleOutNmsp should repository resources be created representing URIs outside $namespace (MetadataCollection::SKIP or MetadataCollection::CREATE) @return array @throws InvalidArgumentException
[ "Imports", "the", "whole", "graph", "by", "looping", "over", "all", "resources", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/util/MetadataCollection.php#L197-L224
train