repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addLink
public function addLink($linkSrc, $linkName = null, $style = null) { if($this->_insideOf == 'section') { $link = new PHPWord_Section_Link($linkSrc, $linkName, $style); $rID = PHPWord_Media::addSectionLinkElement($linkSrc); $link->setRelationId($rID); $this->_elementCollection[] = $link; return $link; } else { trigger_error('Unsupported Link header / footer reference'); return false; } }
php
public function addLink($linkSrc, $linkName = null, $style = null) { if($this->_insideOf == 'section') { $link = new PHPWord_Section_Link($linkSrc, $linkName, $style); $rID = PHPWord_Media::addSectionLinkElement($linkSrc); $link->setRelationId($rID); $this->_elementCollection[] = $link; return $link; } else { trigger_error('Unsupported Link header / footer reference'); return false; } }
[ "public", "function", "addLink", "(", "$", "linkSrc", ",", "$", "linkName", "=", "null", ",", "$", "style", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_insideOf", "==", "'section'", ")", "{", "$", "link", "=", "new", "PHPWord_Section_Link", "(", "$", "linkSrc", ",", "$", "linkName", ",", "$", "style", ")", ";", "$", "rID", "=", "PHPWord_Media", "::", "addSectionLinkElement", "(", "$", "linkSrc", ")", ";", "$", "link", "->", "setRelationId", "(", "$", "rID", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "link", ";", "return", "$", "link", ";", "}", "else", "{", "trigger_error", "(", "'Unsupported Link header / footer reference'", ")", ";", "return", "false", ";", "}", "}" ]
Add a Link Element @param string $linkSrc @param string $linkName @param mixed $style @return PHPWord_Section_Link
[ "Add", "a", "Link", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L124-L137
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addListItem
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) { $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); $this->_elementCollection[] = $listItem; return $listItem; }
php
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) { $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); $this->_elementCollection[] = $listItem; return $listItem; }
[ "public", "function", "addListItem", "(", "$", "text", ",", "$", "depth", "=", "0", ",", "$", "styleText", "=", "null", ",", "$", "styleList", "=", "null", ")", "{", "$", "listItem", "=", "new", "PHPWord_Section_ListItem", "(", "$", "text", ",", "$", "depth", ",", "$", "styleText", ",", "$", "styleList", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "listItem", ";", "return", "$", "listItem", ";", "}" ]
Add a ListItem Element @param string $text @param int $depth @param mixed $styleText @param mixed $styleList @return PHPWord_Section_ListItem
[ "Add", "a", "ListItem", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L157-L161
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addImage
public function addImage($src, $style = null) { $image = new PHPWord_Section_Image($src, $style); if(!is_null($image->getSource())) { if($this->_insideOf == 'section') { $rID = PHPWord_Media::addSectionMediaElement($src, 'image'); } elseif($this->_insideOf == 'header') { $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src); } elseif($this->_insideOf == 'footer') { $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src); } $image->setRelationId($rID); $this->_elementCollection[] = $image; return $image; } else { trigger_error('Source does not exist or unsupported image type.'); } }
php
public function addImage($src, $style = null) { $image = new PHPWord_Section_Image($src, $style); if(!is_null($image->getSource())) { if($this->_insideOf == 'section') { $rID = PHPWord_Media::addSectionMediaElement($src, 'image'); } elseif($this->_insideOf == 'header') { $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src); } elseif($this->_insideOf == 'footer') { $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src); } $image->setRelationId($rID); $this->_elementCollection[] = $image; return $image; } else { trigger_error('Source does not exist or unsupported image type.'); } }
[ "public", "function", "addImage", "(", "$", "src", ",", "$", "style", "=", "null", ")", "{", "$", "image", "=", "new", "PHPWord_Section_Image", "(", "$", "src", ",", "$", "style", ")", ";", "if", "(", "!", "is_null", "(", "$", "image", "->", "getSource", "(", ")", ")", ")", "{", "if", "(", "$", "this", "->", "_insideOf", "==", "'section'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addSectionMediaElement", "(", "$", "src", ",", "'image'", ")", ";", "}", "elseif", "(", "$", "this", "->", "_insideOf", "==", "'header'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addHeaderMediaElement", "(", "$", "this", "->", "_pCount", ",", "$", "src", ")", ";", "}", "elseif", "(", "$", "this", "->", "_insideOf", "==", "'footer'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addFooterMediaElement", "(", "$", "this", "->", "_pCount", ",", "$", "src", ")", ";", "}", "$", "image", "->", "setRelationId", "(", "$", "rID", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "image", ";", "return", "$", "image", ";", "}", "else", "{", "trigger_error", "(", "'Source does not exist or unsupported image type.'", ")", ";", "}", "}" ]
Add a Image Element @param string $src @param mixed $style @return PHPWord_Section_Image
[ "Add", "a", "Image", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L170-L188
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addMemoryImage
public function addMemoryImage($link, $style = null) { $memoryImage = new PHPWord_Section_MemoryImage($link, $style); if(!is_null($memoryImage->getSource())) { if($this->_insideOf == 'section') { $rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); } elseif($this->_insideOf == 'header') { $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage); } elseif($this->_insideOf == 'footer') { $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $link, $memoryImage); } $memoryImage->setRelationId($rID); $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { trigger_error('Unsupported image type.'); } }
php
public function addMemoryImage($link, $style = null) { $memoryImage = new PHPWord_Section_MemoryImage($link, $style); if(!is_null($memoryImage->getSource())) { if($this->_insideOf == 'section') { $rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); } elseif($this->_insideOf == 'header') { $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage); } elseif($this->_insideOf == 'footer') { $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $link, $memoryImage); } $memoryImage->setRelationId($rID); $this->_elementCollection[] = $memoryImage; return $memoryImage; } else { trigger_error('Unsupported image type.'); } }
[ "public", "function", "addMemoryImage", "(", "$", "link", ",", "$", "style", "=", "null", ")", "{", "$", "memoryImage", "=", "new", "PHPWord_Section_MemoryImage", "(", "$", "link", ",", "$", "style", ")", ";", "if", "(", "!", "is_null", "(", "$", "memoryImage", "->", "getSource", "(", ")", ")", ")", "{", "if", "(", "$", "this", "->", "_insideOf", "==", "'section'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addSectionMediaElement", "(", "$", "link", ",", "'image'", ",", "$", "memoryImage", ")", ";", "}", "elseif", "(", "$", "this", "->", "_insideOf", "==", "'header'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addHeaderMediaElement", "(", "$", "this", "->", "_pCount", ",", "$", "link", ",", "$", "memoryImage", ")", ";", "}", "elseif", "(", "$", "this", "->", "_insideOf", "==", "'footer'", ")", "{", "$", "rID", "=", "PHPWord_Media", "::", "addFooterMediaElement", "(", "$", "this", "->", "_pCount", ",", "$", "link", ",", "$", "memoryImage", ")", ";", "}", "$", "memoryImage", "->", "setRelationId", "(", "$", "rID", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "memoryImage", ";", "return", "$", "memoryImage", ";", "}", "else", "{", "trigger_error", "(", "'Unsupported image type.'", ")", ";", "}", "}" ]
Add a by PHP created Image Element @param string $link @param mixed $style @return PHPWord_Section_MemoryImage
[ "Add", "a", "by", "PHP", "created", "Image", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L197-L214
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addObject
public function addObject($src, $style = null) { $object = new PHPWord_Section_Object($src, $style); if(!is_null($object->getSource())) { $inf = pathinfo($src); $ext = $inf['extension']; if(strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') { $ext = substr($ext, 0, -1); } $iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/'; if(!file_exists($iconSrc.'_'.$ext.'.png')) { $iconSrc = $iconSrc.'_default.png'; } else { $iconSrc .= '_'.$ext.'.png'; } $rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); $data = PHPWord_Media::addSectionMediaElement($src, 'oleObject'); $rID = $data[0]; $objectId = $data[1]; $object->setRelationId($rID); $object->setObjectId($objectId); $object->setImageRelationId($rIDimg); $this->_elementCollection[] = $object; return $object; } else { trigger_error('Source does not exist or unsupported object type.'); } }
php
public function addObject($src, $style = null) { $object = new PHPWord_Section_Object($src, $style); if(!is_null($object->getSource())) { $inf = pathinfo($src); $ext = $inf['extension']; if(strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') { $ext = substr($ext, 0, -1); } $iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/'; if(!file_exists($iconSrc.'_'.$ext.'.png')) { $iconSrc = $iconSrc.'_default.png'; } else { $iconSrc .= '_'.$ext.'.png'; } $rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); $data = PHPWord_Media::addSectionMediaElement($src, 'oleObject'); $rID = $data[0]; $objectId = $data[1]; $object->setRelationId($rID); $object->setObjectId($objectId); $object->setImageRelationId($rIDimg); $this->_elementCollection[] = $object; return $object; } else { trigger_error('Source does not exist or unsupported object type.'); } }
[ "public", "function", "addObject", "(", "$", "src", ",", "$", "style", "=", "null", ")", "{", "$", "object", "=", "new", "PHPWord_Section_Object", "(", "$", "src", ",", "$", "style", ")", ";", "if", "(", "!", "is_null", "(", "$", "object", "->", "getSource", "(", ")", ")", ")", "{", "$", "inf", "=", "pathinfo", "(", "$", "src", ")", ";", "$", "ext", "=", "$", "inf", "[", "'extension'", "]", ";", "if", "(", "strlen", "(", "$", "ext", ")", "==", "4", "&&", "strtolower", "(", "substr", "(", "$", "ext", ",", "-", "1", ")", ")", "==", "'x'", ")", "{", "$", "ext", "=", "substr", "(", "$", "ext", ",", "0", ",", "-", "1", ")", ";", "}", "$", "iconSrc", "=", "PHPWORD_BASE_PATH", ".", "'PHPWord/_staticDocParts/'", ";", "if", "(", "!", "file_exists", "(", "$", "iconSrc", ".", "'_'", ".", "$", "ext", ".", "'.png'", ")", ")", "{", "$", "iconSrc", "=", "$", "iconSrc", ".", "'_default.png'", ";", "}", "else", "{", "$", "iconSrc", ".=", "'_'", ".", "$", "ext", ".", "'.png'", ";", "}", "$", "rIDimg", "=", "PHPWord_Media", "::", "addSectionMediaElement", "(", "$", "iconSrc", ",", "'image'", ")", ";", "$", "data", "=", "PHPWord_Media", "::", "addSectionMediaElement", "(", "$", "src", ",", "'oleObject'", ")", ";", "$", "rID", "=", "$", "data", "[", "0", "]", ";", "$", "objectId", "=", "$", "data", "[", "1", "]", ";", "$", "object", "->", "setRelationId", "(", "$", "rID", ")", ";", "$", "object", "->", "setObjectId", "(", "$", "objectId", ")", ";", "$", "object", "->", "setImageRelationId", "(", "$", "rIDimg", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "object", ";", "return", "$", "object", ";", "}", "else", "{", "trigger_error", "(", "'Source does not exist or unsupported object type.'", ")", ";", "}", "}" ]
Add a OLE-Object Element @param string $src @param mixed $style @return PHPWord_Section_Object
[ "Add", "a", "OLE", "-", "Object", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L223-L254
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.addPreserveText
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if($this->_insideOf == 'footer' || $this->_insideOf == 'header') { $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; } else { trigger_error('addPreserveText only supported in footer/header.'); } }
php
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if($this->_insideOf == 'footer' || $this->_insideOf == 'header') { $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; } else { trigger_error('addPreserveText only supported in footer/header.'); } }
[ "public", "function", "addPreserveText", "(", "$", "text", ",", "$", "styleFont", "=", "null", ",", "$", "styleParagraph", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_insideOf", "==", "'footer'", "||", "$", "this", "->", "_insideOf", "==", "'header'", ")", "{", "$", "ptext", "=", "new", "PHPWord_Section_Footer_PreserveText", "(", "$", "text", ",", "$", "styleFont", ",", "$", "styleParagraph", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "ptext", ";", "return", "$", "ptext", ";", "}", "else", "{", "trigger_error", "(", "'addPreserveText only supported in footer/header.'", ")", ";", "}", "}" ]
Add a PreserveText Element @param string $text @param mixed $styleFont @param mixed $styleParagraph @return PHPWord_Section_Footer_PreserveText
[ "Add", "a", "PreserveText", "Element" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L264-L272
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Section/Table/Cell.php
PHPWord_Section_Table_Cell.createTextRun
public function createTextRun($styleParagraph = null) { $textRun = new PHPWord_Section_TextRun($styleParagraph); $this->_elementCollection[] = $textRun; return $textRun; }
php
public function createTextRun($styleParagraph = null) { $textRun = new PHPWord_Section_TextRun($styleParagraph); $this->_elementCollection[] = $textRun; return $textRun; }
[ "public", "function", "createTextRun", "(", "$", "styleParagraph", "=", "null", ")", "{", "$", "textRun", "=", "new", "PHPWord_Section_TextRun", "(", "$", "styleParagraph", ")", ";", "$", "this", "->", "_elementCollection", "[", "]", "=", "$", "textRun", ";", "return", "$", "textRun", ";", "}" ]
Create a new TextRun @return PHPWord_Section_TextRun
[ "Create", "a", "new", "TextRun" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Table/Cell.php#L279-L283
webforge-labs/psc-cms
lib/PHPWord/PHPWord/TOC.php
PHPWord_TOC.addTitle
public static function addTitle($text, $depth = 0) { $anchor = '_Toc'.++self::$_anchor; $bookmarkId = self::$_bookmarkId++; $title = array(); $title['text'] = $text; $title['depth'] = $depth; $title['anchor'] = $anchor; $title['bookmarkId'] = $bookmarkId; self::$_titles[] = $title; return array($anchor, $bookmarkId); }
php
public static function addTitle($text, $depth = 0) { $anchor = '_Toc'.++self::$_anchor; $bookmarkId = self::$_bookmarkId++; $title = array(); $title['text'] = $text; $title['depth'] = $depth; $title['anchor'] = $anchor; $title['bookmarkId'] = $bookmarkId; self::$_titles[] = $title; return array($anchor, $bookmarkId); }
[ "public", "static", "function", "addTitle", "(", "$", "text", ",", "$", "depth", "=", "0", ")", "{", "$", "anchor", "=", "'_Toc'", ".", "++", "self", "::", "$", "_anchor", ";", "$", "bookmarkId", "=", "self", "::", "$", "_bookmarkId", "++", ";", "$", "title", "=", "array", "(", ")", ";", "$", "title", "[", "'text'", "]", "=", "$", "text", ";", "$", "title", "[", "'depth'", "]", "=", "$", "depth", ";", "$", "title", "[", "'anchor'", "]", "=", "$", "anchor", ";", "$", "title", "[", "'bookmarkId'", "]", "=", "$", "bookmarkId", ";", "self", "::", "$", "_titles", "[", "]", "=", "$", "title", ";", "return", "array", "(", "$", "anchor", ",", "$", "bookmarkId", ")", ";", "}" ]
Add a Title @return array
[ "Add", "a", "Title" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/TOC.php#L113-L126
phpmob/changmin
src/PhpMob/ChangMinBundle/Fixture/AdminUserFactory.php
AdminUserFactory.create
public function create(array $options = []) { $options = $this->optionsResolver->resolve($options); /** @var AdminUserInterface $user */ $user = $this->userFactory->createNew(); $user->setEmail($options['email']); $user->setUsername($options['username']); $user->setPlainPassword($options['password']); $user->setDisplayName($options['displayName']); $user->setEnabled($options['enabled']); $roles = array_replace(['ROLE_ADMINISTRATION_ACCESS'], $options['roles']); foreach ($roles as $role) { $user->addRole($role); } return $user; }
php
public function create(array $options = []) { $options = $this->optionsResolver->resolve($options); /** @var AdminUserInterface $user */ $user = $this->userFactory->createNew(); $user->setEmail($options['email']); $user->setUsername($options['username']); $user->setPlainPassword($options['password']); $user->setDisplayName($options['displayName']); $user->setEnabled($options['enabled']); $roles = array_replace(['ROLE_ADMINISTRATION_ACCESS'], $options['roles']); foreach ($roles as $role) { $user->addRole($role); } return $user; }
[ "public", "function", "create", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "optionsResolver", "->", "resolve", "(", "$", "options", ")", ";", "/** @var AdminUserInterface $user */", "$", "user", "=", "$", "this", "->", "userFactory", "->", "createNew", "(", ")", ";", "$", "user", "->", "setEmail", "(", "$", "options", "[", "'email'", "]", ")", ";", "$", "user", "->", "setUsername", "(", "$", "options", "[", "'username'", "]", ")", ";", "$", "user", "->", "setPlainPassword", "(", "$", "options", "[", "'password'", "]", ")", ";", "$", "user", "->", "setDisplayName", "(", "$", "options", "[", "'displayName'", "]", ")", ";", "$", "user", "->", "setEnabled", "(", "$", "options", "[", "'enabled'", "]", ")", ";", "$", "roles", "=", "array_replace", "(", "[", "'ROLE_ADMINISTRATION_ACCESS'", "]", ",", "$", "options", "[", "'roles'", "]", ")", ";", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "$", "user", "->", "addRole", "(", "$", "role", ")", ";", "}", "return", "$", "user", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Fixture/AdminUserFactory.php#L47-L66
phpmob/changmin
src/PhpMob/ChangMinBundle/Fixture/AdminUserFactory.php
AdminUserFactory.configureOptions
protected function configureOptions(OptionsResolver $resolver) { $resolver ->setDefault('email', function (Options $options) { return $this->faker->email; }) ->setDefault('username', function (Options $options) { return $this->faker->userName; }) ->setDefault('displayName', function (Options $options) { return $this->faker->name; }) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') ->setDefault('password', 'password123') ->setDefault('roles', ['ROLE_ADMINISTRATION_ACCESS']) ; }
php
protected function configureOptions(OptionsResolver $resolver) { $resolver ->setDefault('email', function (Options $options) { return $this->faker->email; }) ->setDefault('username', function (Options $options) { return $this->faker->userName; }) ->setDefault('displayName', function (Options $options) { return $this->faker->name; }) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') ->setDefault('password', 'password123') ->setDefault('roles', ['ROLE_ADMINISTRATION_ACCESS']) ; }
[ "protected", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "$", "resolver", "->", "setDefault", "(", "'email'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "this", "->", "faker", "->", "email", ";", "}", ")", "->", "setDefault", "(", "'username'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "this", "->", "faker", "->", "userName", ";", "}", ")", "->", "setDefault", "(", "'displayName'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "this", "->", "faker", "->", "name", ";", "}", ")", "->", "setDefault", "(", "'enabled'", ",", "true", ")", "->", "setAllowedTypes", "(", "'enabled'", ",", "'bool'", ")", "->", "setDefault", "(", "'password'", ",", "'password123'", ")", "->", "setDefault", "(", "'roles'", ",", "[", "'ROLE_ADMINISTRATION_ACCESS'", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Fixture/AdminUserFactory.php#L71-L88
transfer-framework/ezplatform
src/Transfer/EzPlatform/Worker/Transformer/EzClassSpecToArrayTransformer.php
EzClassSpecToArrayTransformer.handle
public function handle($ezclasspec) { $ezclasspec = json_decode($ezclasspec, true); $array = []; foreach ($ezclasspec['class_list'] as $class) { $array[$class['class_identifier']] = $this->mapContentType($class); } return $array; }
php
public function handle($ezclasspec) { $ezclasspec = json_decode($ezclasspec, true); $array = []; foreach ($ezclasspec['class_list'] as $class) { $array[$class['class_identifier']] = $this->mapContentType($class); } return $array; }
[ "public", "function", "handle", "(", "$", "ezclasspec", ")", "{", "$", "ezclasspec", "=", "json_decode", "(", "$", "ezclasspec", ",", "true", ")", ";", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "ezclasspec", "[", "'class_list'", "]", "as", "$", "class", ")", "{", "$", "array", "[", "$", "class", "[", "'class_identifier'", "]", "]", "=", "$", "this", "->", "mapContentType", "(", "$", "class", ")", ";", "}", "return", "$", "array", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Worker/Transformer/EzClassSpecToArrayTransformer.php#L24-L34
transfer-framework/ezplatform
src/Transfer/EzPlatform/Worker/Transformer/EzClassSpecToArrayTransformer.php
EzClassSpecToArrayTransformer.mapField
protected function mapField($attibute) { $field = array(); foreach ($attibute as $key => $value) { switch ($key) { case 'name': $field['name'] = $this->uctToUtf($value); break; case 'datatype': $field['type'] = $value; break; case 'desc': $field['description'] = $this->uctToUtf($value); break; case 'required': $field['is_required'] = (bool) $value; break; } } return $field; }
php
protected function mapField($attibute) { $field = array(); foreach ($attibute as $key => $value) { switch ($key) { case 'name': $field['name'] = $this->uctToUtf($value); break; case 'datatype': $field['type'] = $value; break; case 'desc': $field['description'] = $this->uctToUtf($value); break; case 'required': $field['is_required'] = (bool) $value; break; } } return $field; }
[ "protected", "function", "mapField", "(", "$", "attibute", ")", "{", "$", "field", "=", "array", "(", ")", ";", "foreach", "(", "$", "attibute", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "'name'", ":", "$", "field", "[", "'name'", "]", "=", "$", "this", "->", "uctToUtf", "(", "$", "value", ")", ";", "break", ";", "case", "'datatype'", ":", "$", "field", "[", "'type'", "]", "=", "$", "value", ";", "break", ";", "case", "'desc'", ":", "$", "field", "[", "'description'", "]", "=", "$", "this", "->", "uctToUtf", "(", "$", "value", ")", ";", "break", ";", "case", "'required'", ":", "$", "field", "[", "'is_required'", "]", "=", "(", "bool", ")", "$", "value", ";", "break", ";", "}", "}", "return", "$", "field", ";", "}" ]
@param array $attibute @return array
[ "@param", "array", "$attibute" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Worker/Transformer/EzClassSpecToArrayTransformer.php#L65-L86
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.has
public function has(Enum $enum) { $this->checkType($enum); return isset($this->valueMap[$enum->getConstName()]); }
php
public function has(Enum $enum) { $this->checkType($enum); return isset($this->valueMap[$enum->getConstName()]); }
[ "public", "function", "has", "(", "Enum", "$", "enum", ")", "{", "$", "this", "->", "checkType", "(", "$", "enum", ")", ";", "return", "isset", "(", "$", "this", "->", "valueMap", "[", "$", "enum", "->", "getConstName", "(", ")", "]", ")", ";", "}" ]
@param Enum $enum An offset to check for. @return boolean true on success or false on failure. @throws InvalidArgumentException
[ "@param", "Enum", "$enum", "An", "offset", "to", "check", "for", "." ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L74-L79
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.get
public function get(Enum $enum, $notPresentValue = null) { $this->checkType($enum); return isset($this->valueMap[$enum->getConstName()]) ? $this->valueMap[$enum->getConstName()] : $notPresentValue; }
php
public function get(Enum $enum, $notPresentValue = null) { $this->checkType($enum); return isset($this->valueMap[$enum->getConstName()]) ? $this->valueMap[$enum->getConstName()] : $notPresentValue; }
[ "public", "function", "get", "(", "Enum", "$", "enum", ",", "$", "notPresentValue", "=", "null", ")", "{", "$", "this", "->", "checkType", "(", "$", "enum", ")", ";", "return", "isset", "(", "$", "this", "->", "valueMap", "[", "$", "enum", "->", "getConstName", "(", ")", "]", ")", "?", "$", "this", "->", "valueMap", "[", "$", "enum", "->", "getConstName", "(", ")", "]", ":", "$", "notPresentValue", ";", "}" ]
@param Enum $enum The offset to retrieve. @param mixed $notPresentValue The value to return when the enum is not mapped @return mixed Can return all value types. @throws InvalidArgumentException
[ "@param", "Enum", "$enum", "The", "offset", "to", "retrieve", ".", "@param", "mixed", "$notPresentValue", "The", "value", "to", "return", "when", "the", "enum", "is", "not", "mapped" ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L89-L96
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.map
public function map(Enum $enum, $value) { $this->checkType($enum); $this->valueMap[$enum->getConstName()] = $value; $this->mappedEnums[] = $enum; return $this; }
php
public function map(Enum $enum, $value) { $this->checkType($enum); $this->valueMap[$enum->getConstName()] = $value; $this->mappedEnums[] = $enum; return $this; }
[ "public", "function", "map", "(", "Enum", "$", "enum", ",", "$", "value", ")", "{", "$", "this", "->", "checkType", "(", "$", "enum", ")", ";", "$", "this", "->", "valueMap", "[", "$", "enum", "->", "getConstName", "(", ")", "]", "=", "$", "value", ";", "$", "this", "->", "mappedEnums", "[", "]", "=", "$", "enum", ";", "return", "$", "this", ";", "}" ]
@param Enum $enum The offset to assign the value to. @param mixed $value The value to set. @return $this @throws InvalidArgumentException
[ "@param", "Enum", "$enum", "The", "offset", "to", "assign", "the", "value", "to", ".", "@param", "mixed", "$value", "The", "value", "to", "set", "." ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L106-L114
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.remove
public function remove(Enum $enum) { $this->checkType($enum); $enumName = $enum->getConstName(); if (isset($this->valueMap[$enumName])) { $value = $this->valueMap[$enumName]; unset($this->valueMap[$enumName]); $index = array_search($enum, $this->mappedEnums); unset($this->mappedEnums[$index]); return $value; } return null; }
php
public function remove(Enum $enum) { $this->checkType($enum); $enumName = $enum->getConstName(); if (isset($this->valueMap[$enumName])) { $value = $this->valueMap[$enumName]; unset($this->valueMap[$enumName]); $index = array_search($enum, $this->mappedEnums); unset($this->mappedEnums[$index]); return $value; } return null; }
[ "public", "function", "remove", "(", "Enum", "$", "enum", ")", "{", "$", "this", "->", "checkType", "(", "$", "enum", ")", ";", "$", "enumName", "=", "$", "enum", "->", "getConstName", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "valueMap", "[", "$", "enumName", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "valueMap", "[", "$", "enumName", "]", ";", "unset", "(", "$", "this", "->", "valueMap", "[", "$", "enumName", "]", ")", ";", "$", "index", "=", "array_search", "(", "$", "enum", ",", "$", "this", "->", "mappedEnums", ")", ";", "unset", "(", "$", "this", "->", "mappedEnums", "[", "$", "index", "]", ")", ";", "return", "$", "value", ";", "}", "return", "null", ";", "}" ]
@param Enum $enum The offset to unset. @return mixed|null the removed value on success, null otherwise @throws InvalidArgumentException
[ "@param", "Enum", "$enum", "The", "offset", "to", "unset", "." ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L123-L141
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.checkType
protected function checkType(Enum $enum) { if (get_class($enum) !== $this->fqcn) { throw new InvalidArgumentException(sprintf('Provided variable $enum is not of type %s', $this->fqcn)); } }
php
protected function checkType(Enum $enum) { if (get_class($enum) !== $this->fqcn) { throw new InvalidArgumentException(sprintf('Provided variable $enum is not of type %s', $this->fqcn)); } }
[ "protected", "function", "checkType", "(", "Enum", "$", "enum", ")", "{", "if", "(", "get_class", "(", "$", "enum", ")", "!==", "$", "this", "->", "fqcn", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Provided variable $enum is not of type %s'", ",", "$", "this", "->", "fqcn", ")", ")", ";", "}", "}" ]
@param Enum $enum @throws InvalidArgumentException
[ "@param", "Enum", "$enum" ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L165-L170
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.current
public function current() { return isset($this->mappedEnums[$this->iteratorIndex]) ? $this->valueMap[$this->mappedEnums[$this->iteratorIndex]->getConstName()] : null; }
php
public function current() { return isset($this->mappedEnums[$this->iteratorIndex]) ? $this->valueMap[$this->mappedEnums[$this->iteratorIndex]->getConstName()] : null; }
[ "public", "function", "current", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "mappedEnums", "[", "$", "this", "->", "iteratorIndex", "]", ")", "?", "$", "this", "->", "valueMap", "[", "$", "this", "->", "mappedEnums", "[", "$", "this", "->", "iteratorIndex", "]", "->", "getConstName", "(", ")", "]", ":", "null", ";", "}" ]
Return the current element @link http://php.net/manual/en/iterator.current.php @return mixed
[ "Return", "the", "current", "element" ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L179-L184
gerritdrost/phenum
src/GerritDrost/Lib/Enum/EnumMap.php
EnumMap.key
public function key() { return isset($this->mappedEnums[$this->iteratorIndex]) ? $this->mappedEnums[$this->iteratorIndex] : null; }
php
public function key() { return isset($this->mappedEnums[$this->iteratorIndex]) ? $this->mappedEnums[$this->iteratorIndex] : null; }
[ "public", "function", "key", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "mappedEnums", "[", "$", "this", "->", "iteratorIndex", "]", ")", "?", "$", "this", "->", "mappedEnums", "[", "$", "this", "->", "iteratorIndex", "]", ":", "null", ";", "}" ]
Return the key of the current element @link http://php.net/manual/en/iterator.key.php @return Enum
[ "Return", "the", "key", "of", "the", "current", "element" ]
train
https://github.com/gerritdrost/phenum/blob/935ba4911d0591dea9a2c94a1c1ab5babeec92cb/src/GerritDrost/Lib/Enum/EnumMap.php#L205-L210
webforge-labs/psc-cms
lib/Psc/Code/Differ.php
Differ.getDiffs
public function getDiffs() { $diffs = array(); foreach ($this->diffs as $diff) { if ($diff[1] !== self::OLD) { $diffs[] = $diff; } } return $diffs; }
php
public function getDiffs() { $diffs = array(); foreach ($this->diffs as $diff) { if ($diff[1] !== self::OLD) { $diffs[] = $diff; } } return $diffs; }
[ "public", "function", "getDiffs", "(", ")", "{", "$", "diffs", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "diffs", "as", "$", "diff", ")", "{", "if", "(", "$", "diff", "[", "1", "]", "!==", "self", "::", "OLD", ")", "{", "$", "diffs", "[", "]", "=", "$", "diff", ";", "}", "}", "return", "$", "diffs", ";", "}" ]
Gibt alle Diffs ohne old zurück
[ "Gibt", "alle", "Diffs", "ohne", "old", "zurück" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Differ.php#L45-L53
webforge-labs/psc-cms
lib/Psc/Doctrine/Helper.php
Helper.reindex
public static function reindex($collection, $getIndex = 'getIdentifier') { if (!Code::isTraversable($collection)) { throw new \InvalidArgumentException('$collection muss Traversable sein. '.Code::varInfo($collection)); } $getIndex = Code::castGetter($getIndex); $ret = array(); foreach ($collection as $o) { $ret[$getIndex($o)] = $o; } return $ret; }
php
public static function reindex($collection, $getIndex = 'getIdentifier') { if (!Code::isTraversable($collection)) { throw new \InvalidArgumentException('$collection muss Traversable sein. '.Code::varInfo($collection)); } $getIndex = Code::castGetter($getIndex); $ret = array(); foreach ($collection as $o) { $ret[$getIndex($o)] = $o; } return $ret; }
[ "public", "static", "function", "reindex", "(", "$", "collection", ",", "$", "getIndex", "=", "'getIdentifier'", ")", "{", "if", "(", "!", "Code", "::", "isTraversable", "(", "$", "collection", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$collection muss Traversable sein. '", ".", "Code", "::", "varInfo", "(", "$", "collection", ")", ")", ";", "}", "$", "getIndex", "=", "Code", "::", "castGetter", "(", "$", "getIndex", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "collection", "as", "$", "o", ")", "{", "$", "ret", "[", "$", "getIndex", "(", "$", "o", ")", "]", "=", "$", "o", ";", "}", "return", "$", "ret", ";", "}" ]
Organisiert die Collection mit einem neuen Index macht eine Kopie der $collection, deshalb erstmal nur array erlaubt, bis ich weiß, was da die arraycollection macht @param string|Closure $getIndex wenn ein Closure wird als erster Parameter das Objekt der Collection übergeben. wenn ein string ist dies der Name des Getters des indexes für das Objekt in $collection @TODO was ist schneller: 1. $getIndex in ein Closure zu casten und dann einfach durchlaufe, 2. oder $getIndex als String zu benutzen und jedes mal in der Schleife abfragen ob $getIndex ein String oder ein Closure ist @return array
[ "Organisiert", "die", "Collection", "mit", "einem", "neuen", "Index" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Helper.php#L48-L60
webforge-labs/psc-cms
lib/Psc/Doctrine/Helper.php
Helper.map
public static function map($collection, $getProperty) { $getProperty = Code::castGetter($getProperty); $ret = array(); foreach ($collection as $key =>$o) { // nicht direkt collection bearbeiten weil dies bei einen ArrayCollection glaub ich $collection verändern würde $ret[$key] = $getProperty($o); } return $ret; }
php
public static function map($collection, $getProperty) { $getProperty = Code::castGetter($getProperty); $ret = array(); foreach ($collection as $key =>$o) { // nicht direkt collection bearbeiten weil dies bei einen ArrayCollection glaub ich $collection verändern würde $ret[$key] = $getProperty($o); } return $ret; }
[ "public", "static", "function", "map", "(", "$", "collection", ",", "$", "getProperty", ")", "{", "$", "getProperty", "=", "Code", "::", "castGetter", "(", "$", "getProperty", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "collection", "as", "$", "key", "=>", "$", "o", ")", "{", "// nicht direkt collection bearbeiten weil dies bei einen ArrayCollection glaub ich $collection verändern würde", "$", "ret", "[", "$", "key", "]", "=", "$", "getProperty", "(", "$", "o", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Konvertiert den Array in nur Werte die die Propertys von $getProperty sind ist z. B: Praktisch um in PHP Unit Objekte vergleichen zu können Schlüssel bleiben erhalten! $phpUnit->assertEquals(Helper::convert($expectedModes, 'getIdentifier'), Helper::convert($actualModes, 'getIdentifier'), 1,10,TRUE); @return array
[ "Konvertiert", "den", "Array", "in", "nur", "Werte", "die", "die", "Propertys", "von", "$getProperty", "sind" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Helper.php#L73-L81
webforge-labs/psc-cms
lib/Psc/Doctrine/Helper.php
Helper.mergeUnique
public static function mergeUnique(Array $collection1, Array $collection2, $getIndex1, $getIndex2 = NULL) { $getIndex1 = Code::castGetter($getIndex1); if (!isset($getIndex2)) $getIndex2 = $getIndex1; else $getIndex2 = Code::castGetter($getIndex2); $merge = array(); foreach ($collection1 as $o) { $merge[$getIndex1($o)] = $o; } foreach ($collection2 as $o) { $index = $getIndex2($o); if (!array_key_exists($index,$merge)) { $merge[$index] = $o; } } return $merge; }
php
public static function mergeUnique(Array $collection1, Array $collection2, $getIndex1, $getIndex2 = NULL) { $getIndex1 = Code::castGetter($getIndex1); if (!isset($getIndex2)) $getIndex2 = $getIndex1; else $getIndex2 = Code::castGetter($getIndex2); $merge = array(); foreach ($collection1 as $o) { $merge[$getIndex1($o)] = $o; } foreach ($collection2 as $o) { $index = $getIndex2($o); if (!array_key_exists($index,$merge)) { $merge[$index] = $o; } } return $merge; }
[ "public", "static", "function", "mergeUnique", "(", "Array", "$", "collection1", ",", "Array", "$", "collection2", ",", "$", "getIndex1", ",", "$", "getIndex2", "=", "NULL", ")", "{", "$", "getIndex1", "=", "Code", "::", "castGetter", "(", "$", "getIndex1", ")", ";", "if", "(", "!", "isset", "(", "$", "getIndex2", ")", ")", "$", "getIndex2", "=", "$", "getIndex1", ";", "else", "$", "getIndex2", "=", "Code", "::", "castGetter", "(", "$", "getIndex2", ")", ";", "$", "merge", "=", "array", "(", ")", ";", "foreach", "(", "$", "collection1", "as", "$", "o", ")", "{", "$", "merge", "[", "$", "getIndex1", "(", "$", "o", ")", "]", "=", "$", "o", ";", "}", "foreach", "(", "$", "collection2", "as", "$", "o", ")", "{", "$", "index", "=", "$", "getIndex2", "(", "$", "o", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "index", ",", "$", "merge", ")", ")", "{", "$", "merge", "[", "$", "index", "]", "=", "$", "o", ";", "}", "}", "return", "$", "merge", ";", "}" ]
Fügt die beiden Collections Ahand der Funktion $getIndex zusammen der Array hat als schlüssel die werte von jedem objekt der collection auf das $getIndex angewandt wurde jedes Element kommt nur einmal vor. @see Code::castGetter()
[ "Fügt", "die", "beiden", "Collections", "Ahand", "der", "Funktion", "$getIndex", "zusammen" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Helper.php#L100-L119
webforge-labs/psc-cms
lib/Psc/Doctrine/Helper.php
Helper.deleteDiff
public static function deleteDiff($dbCollection, $actualItems) { $convert = $actualItems instanceof Collection; $dbCollection = Code::castArray($dbCollection); $actualItems = self::reindex(Code::castArray($actualItems)); /* Es ist gar nicht so leicht dass mit den php diff etc funktionen (außer vielleicht array_diff_key) nachzubauen wir haben folgende Probleme: die udiff funktionen wollen alle die Schlüssel vergleichen, man kann ihnen nicht sagen: alle schlüssel sind gleich. da sie anscheinend die vergleiche anhand der reihenfolge der Element-Indizes (mit Transitivität) ermitteln wir könnten hier reindex($db), reindex($actual) und dann array_diff_key() machen, dann wären jedoch die schlüssel nicht mehr numerisch und wir müssten nochmal mit array_merge() drüber (wieder linear schlüsseln) man müsste hier testen was schneller ist. */ $diff = array(); foreach ($dbCollection as $a) { if (!array_key_exists($a->getIdentifier(),$actualItems)) { $diff[] = $a; } } if ($convert) return new ArrayCollection($diff); else return $diff; }
php
public static function deleteDiff($dbCollection, $actualItems) { $convert = $actualItems instanceof Collection; $dbCollection = Code::castArray($dbCollection); $actualItems = self::reindex(Code::castArray($actualItems)); /* Es ist gar nicht so leicht dass mit den php diff etc funktionen (außer vielleicht array_diff_key) nachzubauen wir haben folgende Probleme: die udiff funktionen wollen alle die Schlüssel vergleichen, man kann ihnen nicht sagen: alle schlüssel sind gleich. da sie anscheinend die vergleiche anhand der reihenfolge der Element-Indizes (mit Transitivität) ermitteln wir könnten hier reindex($db), reindex($actual) und dann array_diff_key() machen, dann wären jedoch die schlüssel nicht mehr numerisch und wir müssten nochmal mit array_merge() drüber (wieder linear schlüsseln) man müsste hier testen was schneller ist. */ $diff = array(); foreach ($dbCollection as $a) { if (!array_key_exists($a->getIdentifier(),$actualItems)) { $diff[] = $a; } } if ($convert) return new ArrayCollection($diff); else return $diff; }
[ "public", "static", "function", "deleteDiff", "(", "$", "dbCollection", ",", "$", "actualItems", ")", "{", "$", "convert", "=", "$", "actualItems", "instanceof", "Collection", ";", "$", "dbCollection", "=", "Code", "::", "castArray", "(", "$", "dbCollection", ")", ";", "$", "actualItems", "=", "self", "::", "reindex", "(", "Code", "::", "castArray", "(", "$", "actualItems", ")", ")", ";", "/* Es ist gar nicht so leicht dass mit den php diff etc funktionen (außer vielleicht array_diff_key) nachzubauen\n \n wir haben folgende Probleme: die udiff funktionen wollen alle die Schlüssel vergleichen, man kann ihnen nicht sagen:\n alle schlüssel sind gleich. da sie anscheinend die vergleiche anhand der reihenfolge der Element-Indizes (mit Transitivität) ermitteln\n \n wir könnten hier reindex($db), reindex($actual) und dann array_diff_key() machen, dann wären jedoch die schlüssel nicht mehr numerisch und wir müssten nochmal mit array_merge() drüber (wieder linear schlüsseln)\n \n man müsste hier testen was schneller ist.\n */", "$", "diff", "=", "array", "(", ")", ";", "foreach", "(", "$", "dbCollection", "as", "$", "a", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "a", "->", "getIdentifier", "(", ")", ",", "$", "actualItems", ")", ")", "{", "$", "diff", "[", "]", "=", "$", "a", ";", "}", "}", "if", "(", "$", "convert", ")", "return", "new", "ArrayCollection", "(", "$", "diff", ")", ";", "else", "return", "$", "diff", ";", "}" ]
Gibt die Elemente aus der $dbCollection zurück, die gelöscht werden müssen (die nicht in $actualItems sind) ist sortierungsunabhängig (die schlüssel werden nicht gecheckt) die Schlüssel sind nicht von 0 - x sondern wild @param \Doctrine\Common\Collections\Collection|array $dbCollection @param \Doctrine\Common\Collections\Collection|array $actualItems ist dies ein array, wird ein array zurückgeeben, ist dies eine collection, eine collection @return ArrayCollection|array
[ "Gibt", "die", "Elemente", "aus", "der", "$dbCollection", "zurück", "die", "gelöscht", "werden", "müssen", "(", "die", "nicht", "in", "$actualItems", "sind", ")" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Helper.php#L131-L157
webforge-labs/psc-cms
lib/Psc/Doctrine/Helper.php
Helper.doSafe
public static function doSafe($flags, Closure $what, EntityManager $em = NULL) { if (!isset($em)) $em = self::em(); $transaction = $flags & self::IN_TRANSACTION; $logging = $flags & self::WITH_LOGGING; $rollback = $flags & self::ROLLBACK; try { if ($transaction) $em->beginTransaction(); if ($logging) self::enableSQLLogging(); /* ausführen */ $ret = $what($em); /* flush */ $em->flush(); /* commit */ if ($transaction && !$rollback) $em->commit(); if ($rollback) $em->rollback(); /* log */ if ($logging) { if ($flags & self::RETURN_LOG) return self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/',TRUE); else self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/'); } return $ret; } catch (\Exception $e) { if ($transaction) $em->rollback(); if ($logging && !($flags & self::RETURN_LOG)) { self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/'); } $em->close(); throw $e; } }
php
public static function doSafe($flags, Closure $what, EntityManager $em = NULL) { if (!isset($em)) $em = self::em(); $transaction = $flags & self::IN_TRANSACTION; $logging = $flags & self::WITH_LOGGING; $rollback = $flags & self::ROLLBACK; try { if ($transaction) $em->beginTransaction(); if ($logging) self::enableSQLLogging(); /* ausführen */ $ret = $what($em); /* flush */ $em->flush(); /* commit */ if ($transaction && !$rollback) $em->commit(); if ($rollback) $em->rollback(); /* log */ if ($logging) { if ($flags & self::RETURN_LOG) return self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/',TRUE); else self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/'); } return $ret; } catch (\Exception $e) { if ($transaction) $em->rollback(); if ($logging && !($flags & self::RETURN_LOG)) { self::printSQLLog('/^(INSERT INTO|DELETE|UPDATE)/'); } $em->close(); throw $e; } }
[ "public", "static", "function", "doSafe", "(", "$", "flags", ",", "Closure", "$", "what", ",", "EntityManager", "$", "em", "=", "NULL", ")", "{", "if", "(", "!", "isset", "(", "$", "em", ")", ")", "$", "em", "=", "self", "::", "em", "(", ")", ";", "$", "transaction", "=", "$", "flags", "&", "self", "::", "IN_TRANSACTION", ";", "$", "logging", "=", "$", "flags", "&", "self", "::", "WITH_LOGGING", ";", "$", "rollback", "=", "$", "flags", "&", "self", "::", "ROLLBACK", ";", "try", "{", "if", "(", "$", "transaction", ")", "$", "em", "->", "beginTransaction", "(", ")", ";", "if", "(", "$", "logging", ")", "self", "::", "enableSQLLogging", "(", ")", ";", "/* ausführen */", "$", "ret", "=", "$", "what", "(", "$", "em", ")", ";", "/* flush */", "$", "em", "->", "flush", "(", ")", ";", "/* commit */", "if", "(", "$", "transaction", "&&", "!", "$", "rollback", ")", "$", "em", "->", "commit", "(", ")", ";", "if", "(", "$", "rollback", ")", "$", "em", "->", "rollback", "(", ")", ";", "/* log */", "if", "(", "$", "logging", ")", "{", "if", "(", "$", "flags", "&", "self", "::", "RETURN_LOG", ")", "return", "self", "::", "printSQLLog", "(", "'/^(INSERT INTO|DELETE|UPDATE)/'", ",", "TRUE", ")", ";", "else", "self", "::", "printSQLLog", "(", "'/^(INSERT INTO|DELETE|UPDATE)/'", ")", ";", "}", "return", "$", "ret", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "transaction", ")", "$", "em", "->", "rollback", "(", ")", ";", "if", "(", "$", "logging", "&&", "!", "(", "$", "flags", "&", "self", "::", "RETURN_LOG", ")", ")", "{", "self", "::", "printSQLLog", "(", "'/^(INSERT INTO|DELETE|UPDATE)/'", ")", ";", "}", "$", "em", "->", "close", "(", ")", ";", "throw", "$", "e", ";", "}", "}" ]
Führt Datenbank Aktionen innerhalb eine Safe-Umgebung (try catch - transactional) aus und kann dabei loggen $what bekommt als erstes Argument $em übergeben
[ "Führt", "Datenbank", "Aktionen", "innerhalb", "eine", "Safe", "-", "Umgebung", "(", "try", "catch", "-", "transactional", ")", "aus", "und", "kann", "dabei", "loggen", "$what", "bekommt", "als", "erstes", "Argument", "$em", "übergeben" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/Helper.php#L364-L412
bpolaszek/where
src/SelectQuery/SelectQueryBuilder.php
SelectQueryBuilder.split
public function split(int $buffer, int $max, int $offsetStart = 0): iterable { for ($offset = $offsetStart; $offset < $max; $offset += $buffer) { yield $offset => $this->offset($offset)->limit($buffer); } }
php
public function split(int $buffer, int $max, int $offsetStart = 0): iterable { for ($offset = $offsetStart; $offset < $max; $offset += $buffer) { yield $offset => $this->offset($offset)->limit($buffer); } }
[ "public", "function", "split", "(", "int", "$", "buffer", ",", "int", "$", "max", ",", "int", "$", "offsetStart", "=", "0", ")", ":", "iterable", "{", "for", "(", "$", "offset", "=", "$", "offsetStart", ";", "$", "offset", "<", "$", "max", ";", "$", "offset", "+=", "$", "buffer", ")", "{", "yield", "$", "offset", "=>", "$", "this", "->", "offset", "(", "$", "offset", ")", "->", "limit", "(", "$", "buffer", ")", ";", "}", "}" ]
Split current query into multiple sub-queries (with OFFSET and LIMIT). @param int $buffer @param int $max @param int $offsetStart @return iterable|self[]
[ "Split", "current", "query", "into", "multiple", "sub", "-", "queries", "(", "with", "OFFSET", "and", "LIMIT", ")", "." ]
train
https://github.com/bpolaszek/where/blob/f40c6a97bca831c633ee3b87e2c7e3591af4fdff/src/SelectQuery/SelectQueryBuilder.php#L590-L595
webforge-labs/psc-cms
lib/Psc/Form/DataInput.php
DataInput.get
public function get($keys, $do = self::RETURN_NULL, $default = NULL) { // der default NULL für exception ist eigentlich uninteressant, da es zur Auswertung dieses Wertes vor der Exception nie kommt return parent::get($keys, $do, ($do === self::RETURN_NULL || $do === self::THROW_EXCEPTION) ? NULL : $do); }
php
public function get($keys, $do = self::RETURN_NULL, $default = NULL) { // der default NULL für exception ist eigentlich uninteressant, da es zur Auswertung dieses Wertes vor der Exception nie kommt return parent::get($keys, $do, ($do === self::RETURN_NULL || $do === self::THROW_EXCEPTION) ? NULL : $do); }
[ "public", "function", "get", "(", "$", "keys", ",", "$", "do", "=", "self", "::", "RETURN_NULL", ",", "$", "default", "=", "NULL", ")", "{", "// der default NULL für exception ist eigentlich uninteressant, da es zur Auswertung dieses Wertes vor der Exception nie kommt", "return", "parent", "::", "get", "(", "$", "keys", ",", "$", "do", ",", "(", "$", "do", "===", "self", "::", "RETURN_NULL", "||", "$", "do", "===", "self", "::", "THROW_EXCEPTION", ")", "?", "NULL", ":", "$", "do", ")", ";", "}" ]
Gibt das Feld mit einem Defaultwert belegt zurück Im FormDataInput ist der dritte Parameter wirkungslos (er wird auf dasselbe wie $do gesetzt) Deshalb ist hier der dritte Parameter unwirksam denn hier gilt $do = $default zu beachten ist auch, dass der Defaultwert im FormDataInput auch genommen wird wenn der Wert trim() === '' ist also der $default -Wert wird genommen wenn: - im Array die Schlüssel $keys nicht vorkommen - der Wert der Schlüssel $keys im Array entweder === NULL oder trim() == '' ist @see DataInput::get();
[ "Gibt", "das", "Feld", "mit", "einem", "Defaultwert", "belegt", "zurück" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/DataInput.php#L36-L39
CakeCMS/Core
src/Utility/Toolbar.php
Toolbar.getInstance
public static function getInstance($name = self::DEFAULT_NAME) { if (empty(self::$_instances[$name])) { self::$_instances[$name] = new Toolbar($name); } return self::$_instances[$name]; }
php
public static function getInstance($name = self::DEFAULT_NAME) { if (empty(self::$_instances[$name])) { self::$_instances[$name] = new Toolbar($name); } return self::$_instances[$name]; }
[ "public", "static", "function", "getInstance", "(", "$", "name", "=", "self", "::", "DEFAULT_NAME", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "_instances", "[", "$", "name", "]", ")", ")", "{", "self", "::", "$", "_instances", "[", "$", "name", "]", "=", "new", "Toolbar", "(", "$", "name", ")", ";", "}", "return", "self", "::", "$", "_instances", "[", "$", "name", "]", ";", "}" ]
Get toolbar instance. @param string $name @return array|Toolbar
[ "Get", "toolbar", "instance", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Toolbar.php#L92-L99
CakeCMS/Core
src/Utility/Toolbar.php
Toolbar.loadItemType
public function loadItemType($type) { $signature = md5($type); if (isset($this->_buttons[$signature])) { return $this->_buttons[$signature]; } list($plugin, $name) = pluginSplit($type); $alias = Slug::filter($name, '_'); $aliasClass = Inflector::classify($alias); $className = $this->_getItemClassName($plugin, $aliasClass); if (!$className) { return false; } $this->_buttons[$signature] = new $className($this); return $this->_buttons[$signature]; }
php
public function loadItemType($type) { $signature = md5($type); if (isset($this->_buttons[$signature])) { return $this->_buttons[$signature]; } list($plugin, $name) = pluginSplit($type); $alias = Slug::filter($name, '_'); $aliasClass = Inflector::classify($alias); $className = $this->_getItemClassName($plugin, $aliasClass); if (!$className) { return false; } $this->_buttons[$signature] = new $className($this); return $this->_buttons[$signature]; }
[ "public", "function", "loadItemType", "(", "$", "type", ")", "{", "$", "signature", "=", "md5", "(", "$", "type", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_buttons", "[", "$", "signature", "]", ")", ")", "{", "return", "$", "this", "->", "_buttons", "[", "$", "signature", "]", ";", "}", "list", "(", "$", "plugin", ",", "$", "name", ")", "=", "pluginSplit", "(", "$", "type", ")", ";", "$", "alias", "=", "Slug", "::", "filter", "(", "$", "name", ",", "'_'", ")", ";", "$", "aliasClass", "=", "Inflector", "::", "classify", "(", "$", "alias", ")", ";", "$", "className", "=", "$", "this", "->", "_getItemClassName", "(", "$", "plugin", ",", "$", "aliasClass", ")", ";", "if", "(", "!", "$", "className", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_buttons", "[", "$", "signature", "]", "=", "new", "$", "className", "(", "$", "this", ")", ";", "return", "$", "this", "->", "_buttons", "[", "$", "signature", "]", ";", "}" ]
Load object of item type. @param $type @return ToolbarItem|bool
[ "Load", "object", "of", "item", "type", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Toolbar.php#L127-L146
CakeCMS/Core
src/Utility/Toolbar.php
Toolbar.render
public function render() { $i = 0; $output = []; $count = count($this->_items); foreach ($this->_items as $item) { $i++; $item['class'] = 'item-wrapper tb-item-' . $i; if ($i == 1) { $item['class'] .= ' first'; } if ($i == $count) { $item['class'] .= ' last'; } $output[] = $this->renderItem($item); } return implode(PHP_EOL, $output); }
php
public function render() { $i = 0; $output = []; $count = count($this->_items); foreach ($this->_items as $item) { $i++; $item['class'] = 'item-wrapper tb-item-' . $i; if ($i == 1) { $item['class'] .= ' first'; } if ($i == $count) { $item['class'] .= ' last'; } $output[] = $this->renderItem($item); } return implode(PHP_EOL, $output); }
[ "public", "function", "render", "(", ")", "{", "$", "i", "=", "0", ";", "$", "output", "=", "[", "]", ";", "$", "count", "=", "count", "(", "$", "this", "->", "_items", ")", ";", "foreach", "(", "$", "this", "->", "_items", "as", "$", "item", ")", "{", "$", "i", "++", ";", "$", "item", "[", "'class'", "]", "=", "'item-wrapper tb-item-'", ".", "$", "i", ";", "if", "(", "$", "i", "==", "1", ")", "{", "$", "item", "[", "'class'", "]", ".=", "' first'", ";", "}", "if", "(", "$", "i", "==", "$", "count", ")", "{", "$", "item", "[", "'class'", "]", ".=", "' last'", ";", "}", "$", "output", "[", "]", "=", "$", "this", "->", "renderItem", "(", "$", "item", ")", ";", "}", "return", "implode", "(", "PHP_EOL", ",", "$", "output", ")", ";", "}" ]
Render toolbar items. @return string @SuppressWarnings(PHPMD.ShortVariable)
[ "Render", "toolbar", "items", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Toolbar.php#L167-L188
CakeCMS/Core
src/Utility/Toolbar.php
Toolbar.renderItem
public function renderItem(&$node) { $type = $node[0]; $item = $this->loadItemType($type); if ($item === false) { return null; } return $item->render($node); }
php
public function renderItem(&$node) { $type = $node[0]; $item = $this->loadItemType($type); if ($item === false) { return null; } return $item->render($node); }
[ "public", "function", "renderItem", "(", "&", "$", "node", ")", "{", "$", "type", "=", "$", "node", "[", "0", "]", ";", "$", "item", "=", "$", "this", "->", "loadItemType", "(", "$", "type", ")", ";", "if", "(", "$", "item", "===", "false", ")", "{", "return", "null", ";", "}", "return", "$", "item", "->", "render", "(", "$", "node", ")", ";", "}" ]
Render toolbar item html. @param $node @return null|string
[ "Render", "toolbar", "item", "html", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Toolbar.php#L196-L206
CakeCMS/Core
src/Utility/Toolbar.php
Toolbar._getItemClassName
protected function _getItemClassName($plugin, $aliasClass) { if ($plugin === null) { $plugin = 'Core'; } $buttonClass = $plugin . '.' . self::CLASS_NAME_PREFIX . $aliasClass; $className = App::className($buttonClass, self::CLASS_TYPE); if ($className === false) { $buttonClass = self::CLASS_NAME_PREFIX . $aliasClass; $className = App::className($buttonClass, self::CLASS_TYPE); } return $className; }
php
protected function _getItemClassName($plugin, $aliasClass) { if ($plugin === null) { $plugin = 'Core'; } $buttonClass = $plugin . '.' . self::CLASS_NAME_PREFIX . $aliasClass; $className = App::className($buttonClass, self::CLASS_TYPE); if ($className === false) { $buttonClass = self::CLASS_NAME_PREFIX . $aliasClass; $className = App::className($buttonClass, self::CLASS_TYPE); } return $className; }
[ "protected", "function", "_getItemClassName", "(", "$", "plugin", ",", "$", "aliasClass", ")", "{", "if", "(", "$", "plugin", "===", "null", ")", "{", "$", "plugin", "=", "'Core'", ";", "}", "$", "buttonClass", "=", "$", "plugin", ".", "'.'", ".", "self", "::", "CLASS_NAME_PREFIX", ".", "$", "aliasClass", ";", "$", "className", "=", "App", "::", "className", "(", "$", "buttonClass", ",", "self", "::", "CLASS_TYPE", ")", ";", "if", "(", "$", "className", "===", "false", ")", "{", "$", "buttonClass", "=", "self", "::", "CLASS_NAME_PREFIX", ".", "$", "aliasClass", ";", "$", "className", "=", "App", "::", "className", "(", "$", "buttonClass", ",", "self", "::", "CLASS_TYPE", ")", ";", "}", "return", "$", "className", ";", "}" ]
Get full class name. @param string $plugin @param string $aliasClass @return bool|string
[ "Get", "full", "class", "name", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Toolbar.php#L215-L230
spiral-modules/scaffolder
source/Scaffolder/Commands/ServiceCommand.php
ServiceCommand.perform
public function perform() { /** @var ServiceDeclaration $declaration */ $declaration = $this->createDeclaration(); foreach ($this->option('method') as $method) { $declaration->method($method)->setAccess(MethodDeclaration::ACCESS_PUBLIC); } $this->writeDeclaration($declaration); }
php
public function perform() { /** @var ServiceDeclaration $declaration */ $declaration = $this->createDeclaration(); foreach ($this->option('method') as $method) { $declaration->method($method)->setAccess(MethodDeclaration::ACCESS_PUBLIC); } $this->writeDeclaration($declaration); }
[ "public", "function", "perform", "(", ")", "{", "/** @var ServiceDeclaration $declaration */", "$", "declaration", "=", "$", "this", "->", "createDeclaration", "(", ")", ";", "foreach", "(", "$", "this", "->", "option", "(", "'method'", ")", "as", "$", "method", ")", "{", "$", "declaration", "->", "method", "(", "$", "method", ")", "->", "setAccess", "(", "MethodDeclaration", "::", "ACCESS_PUBLIC", ")", ";", "}", "$", "this", "->", "writeDeclaration", "(", "$", "declaration", ")", ";", "}" ]
Create controller declaration.
[ "Create", "controller", "declaration", "." ]
train
https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Commands/ServiceCommand.php#L36-L46
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._addClass
protected function _addClass(array $options = [], $class = null, $key = 'class') { if (Arr::key($key, $options) && Str::trim($options[$key])) { $options[$key] .= ' ' . $class; } else { $options[$key] = $class; } return $options; }
php
protected function _addClass(array $options = [], $class = null, $key = 'class') { if (Arr::key($key, $options) && Str::trim($options[$key])) { $options[$key] .= ' ' . $class; } else { $options[$key] = $class; } return $options; }
[ "protected", "function", "_addClass", "(", "array", "$", "options", "=", "[", "]", ",", "$", "class", "=", "null", ",", "$", "key", "=", "'class'", ")", "{", "if", "(", "Arr", "::", "key", "(", "$", "key", ",", "$", "options", ")", "&&", "Str", "::", "trim", "(", "$", "options", "[", "$", "key", "]", ")", ")", "{", "$", "options", "[", "$", "key", "]", ".=", "' '", ".", "$", "class", ";", "}", "else", "{", "$", "options", "[", "$", "key", "]", "=", "$", "class", ";", "}", "return", "$", "options", ";", "}" ]
Adds the given class to the element options @param array $options Array options/attributes to add a class to @param string $class The class name being added. @param string $key the key to use for class. @return array Array of options with $key set.
[ "Adds", "the", "given", "class", "to", "the", "element", "options" ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L40-L48
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._createIcon
protected function _createIcon(HtmlHelper $html, $title, array $options = []) { list($options, $iconOptions) = $this->_createIconAttr($options); if (Arr::key('createIcon', $iconOptions)) { unset($iconOptions['createIcon']); $title = $html->icon($options['icon'], $iconOptions) . PHP_EOL . $title; unset($options['icon']); } if (Arr::key('iconInline', $options)) { unset($options['iconInline']); } return [$title, $options]; }
php
protected function _createIcon(HtmlHelper $html, $title, array $options = []) { list($options, $iconOptions) = $this->_createIconAttr($options); if (Arr::key('createIcon', $iconOptions)) { unset($iconOptions['createIcon']); $title = $html->icon($options['icon'], $iconOptions) . PHP_EOL . $title; unset($options['icon']); } if (Arr::key('iconInline', $options)) { unset($options['iconInline']); } return [$title, $options]; }
[ "protected", "function", "_createIcon", "(", "HtmlHelper", "$", "html", ",", "$", "title", ",", "array", "$", "options", "=", "[", "]", ")", "{", "list", "(", "$", "options", ",", "$", "iconOptions", ")", "=", "$", "this", "->", "_createIconAttr", "(", "$", "options", ")", ";", "if", "(", "Arr", "::", "key", "(", "'createIcon'", ",", "$", "iconOptions", ")", ")", "{", "unset", "(", "$", "iconOptions", "[", "'createIcon'", "]", ")", ";", "$", "title", "=", "$", "html", "->", "icon", "(", "$", "options", "[", "'icon'", "]", ",", "$", "iconOptions", ")", ".", "PHP_EOL", ".", "$", "title", ";", "unset", "(", "$", "options", "[", "'icon'", "]", ")", ";", "}", "if", "(", "Arr", "::", "key", "(", "'iconInline'", ",", "$", "options", ")", ")", "{", "unset", "(", "$", "options", "[", "'iconInline'", "]", ")", ";", "}", "return", "[", "$", "title", ",", "$", "options", "]", ";", "}" ]
Create current icon. @param HtmlHelper $html @param string|int $title @param array $options @return array
[ "Create", "current", "icon", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L69-L84
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._createIconAttr
protected function _createIconAttr(array $options = []) { $iconOptions = ['class' => '']; if (Arr::key('icon', $options)) { if (Arr::key('iconClass', $options)) { $iconOptions = $this->_addClass($iconOptions, $options['iconClass']); unset($options['iconClass']); } list ($options, $iconOptions) = $this->_setIconOptions($options, $iconOptions); } return [$options, $iconOptions]; }
php
protected function _createIconAttr(array $options = []) { $iconOptions = ['class' => '']; if (Arr::key('icon', $options)) { if (Arr::key('iconClass', $options)) { $iconOptions = $this->_addClass($iconOptions, $options['iconClass']); unset($options['iconClass']); } list ($options, $iconOptions) = $this->_setIconOptions($options, $iconOptions); } return [$options, $iconOptions]; }
[ "protected", "function", "_createIconAttr", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "iconOptions", "=", "[", "'class'", "=>", "''", "]", ";", "if", "(", "Arr", "::", "key", "(", "'icon'", ",", "$", "options", ")", ")", "{", "if", "(", "Arr", "::", "key", "(", "'iconClass'", ",", "$", "options", ")", ")", "{", "$", "iconOptions", "=", "$", "this", "->", "_addClass", "(", "$", "iconOptions", ",", "$", "options", "[", "'iconClass'", "]", ")", ";", "unset", "(", "$", "options", "[", "'iconClass'", "]", ")", ";", "}", "list", "(", "$", "options", ",", "$", "iconOptions", ")", "=", "$", "this", "->", "_setIconOptions", "(", "$", "options", ",", "$", "iconOptions", ")", ";", "}", "return", "[", "$", "options", ",", "$", "iconOptions", "]", ";", "}" ]
Create icon attributes. @param array $options @return array
[ "Create", "icon", "attributes", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L92-L106
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._getBtnClass
protected function _getBtnClass(array $options = []) { if (Arr::key('button', $options)) { $button = $options['button']; unset($options['button']); if (is_callable($this->getConfig('prepareBtnClass'))) { return (array) call_user_func($this->getConfig('prepareBtnClass'), $this, $options, $button); } $options = $this->_setBtnClass($button, $options); } return $options; }
php
protected function _getBtnClass(array $options = []) { if (Arr::key('button', $options)) { $button = $options['button']; unset($options['button']); if (is_callable($this->getConfig('prepareBtnClass'))) { return (array) call_user_func($this->getConfig('prepareBtnClass'), $this, $options, $button); } $options = $this->_setBtnClass($button, $options); } return $options; }
[ "protected", "function", "_getBtnClass", "(", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "Arr", "::", "key", "(", "'button'", ",", "$", "options", ")", ")", "{", "$", "button", "=", "$", "options", "[", "'button'", "]", ";", "unset", "(", "$", "options", "[", "'button'", "]", ")", ";", "if", "(", "is_callable", "(", "$", "this", "->", "getConfig", "(", "'prepareBtnClass'", ")", ")", ")", "{", "return", "(", "array", ")", "call_user_func", "(", "$", "this", "->", "getConfig", "(", "'prepareBtnClass'", ")", ",", "$", "this", ",", "$", "options", ",", "$", "button", ")", ";", "}", "$", "options", "=", "$", "this", "->", "_setBtnClass", "(", "$", "button", ",", "$", "options", ")", ";", "}", "return", "$", "options", ";", "}" ]
Create and get button classes. @param array $options @return array
[ "Create", "and", "get", "button", "classes", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L114-L128
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._getToolTipAttr
protected function _getToolTipAttr(array $options = [], $toggle = 'tooltip') { if (Arr::key('tooltip', $options)) { $tooltip = $options['tooltip']; unset($options['tooltip']); if (is_callable($this->getConfig('prepareTooltip'))) { return (array) call_user_func($this->getConfig('prepareTooltip'), $this, $options, $tooltip); } $_options = [ 'data-toggle' => $toggle, 'data-placement' => 'top', ]; if (Arr::key('tooltipPos', $options)) { $_options['data-placement'] = (string) $options['tooltipPos']; unset($options['tooltipPos']); } $options = $this->_setTooltipTitle($tooltip, $options); return Hash::merge($_options, $options); } return $options; }
php
protected function _getToolTipAttr(array $options = [], $toggle = 'tooltip') { if (Arr::key('tooltip', $options)) { $tooltip = $options['tooltip']; unset($options['tooltip']); if (is_callable($this->getConfig('prepareTooltip'))) { return (array) call_user_func($this->getConfig('prepareTooltip'), $this, $options, $tooltip); } $_options = [ 'data-toggle' => $toggle, 'data-placement' => 'top', ]; if (Arr::key('tooltipPos', $options)) { $_options['data-placement'] = (string) $options['tooltipPos']; unset($options['tooltipPos']); } $options = $this->_setTooltipTitle($tooltip, $options); return Hash::merge($_options, $options); } return $options; }
[ "protected", "function", "_getToolTipAttr", "(", "array", "$", "options", "=", "[", "]", ",", "$", "toggle", "=", "'tooltip'", ")", "{", "if", "(", "Arr", "::", "key", "(", "'tooltip'", ",", "$", "options", ")", ")", "{", "$", "tooltip", "=", "$", "options", "[", "'tooltip'", "]", ";", "unset", "(", "$", "options", "[", "'tooltip'", "]", ")", ";", "if", "(", "is_callable", "(", "$", "this", "->", "getConfig", "(", "'prepareTooltip'", ")", ")", ")", "{", "return", "(", "array", ")", "call_user_func", "(", "$", "this", "->", "getConfig", "(", "'prepareTooltip'", ")", ",", "$", "this", ",", "$", "options", ",", "$", "tooltip", ")", ";", "}", "$", "_options", "=", "[", "'data-toggle'", "=>", "$", "toggle", ",", "'data-placement'", "=>", "'top'", ",", "]", ";", "if", "(", "Arr", "::", "key", "(", "'tooltipPos'", ",", "$", "options", ")", ")", "{", "$", "_options", "[", "'data-placement'", "]", "=", "(", "string", ")", "$", "options", "[", "'tooltipPos'", "]", ";", "unset", "(", "$", "options", "[", "'tooltipPos'", "]", ")", ";", "}", "$", "options", "=", "$", "this", "->", "_setTooltipTitle", "(", "$", "tooltip", ",", "$", "options", ")", ";", "return", "Hash", "::", "merge", "(", "$", "_options", ",", "$", "options", ")", ";", "}", "return", "$", "options", ";", "}" ]
Create and get tooltip attributes. @param array $options @param string $toggle @return array
[ "Create", "and", "get", "tooltip", "attributes", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L137-L163
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._prepareBeforeAfterContainer
protected function _prepareBeforeAfterContainer($type, $value) { $output = null; $iconClass = ($type === 'before') ? 'prefix' : 'postfix'; if ($value !== null) { $output = $value; if (is_string($output)) { $hasIcon = preg_match('/icon:[a-zA-Z]/', $output); if ($hasIcon > 0) { list (, $icon) = explode(':', $output, 2); $icon = Str::low($icon); $output = $this->Html->icon($icon, ['class' => $iconClass]); } } } return $output; }
php
protected function _prepareBeforeAfterContainer($type, $value) { $output = null; $iconClass = ($type === 'before') ? 'prefix' : 'postfix'; if ($value !== null) { $output = $value; if (is_string($output)) { $hasIcon = preg_match('/icon:[a-zA-Z]/', $output); if ($hasIcon > 0) { list (, $icon) = explode(':', $output, 2); $icon = Str::low($icon); $output = $this->Html->icon($icon, ['class' => $iconClass]); } } } return $output; }
[ "protected", "function", "_prepareBeforeAfterContainer", "(", "$", "type", ",", "$", "value", ")", "{", "$", "output", "=", "null", ";", "$", "iconClass", "=", "(", "$", "type", "===", "'before'", ")", "?", "'prefix'", ":", "'postfix'", ";", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "output", "=", "$", "value", ";", "if", "(", "is_string", "(", "$", "output", ")", ")", "{", "$", "hasIcon", "=", "preg_match", "(", "'/icon:[a-zA-Z]/'", ",", "$", "output", ")", ";", "if", "(", "$", "hasIcon", ">", "0", ")", "{", "list", "(", ",", "$", "icon", ")", "=", "explode", "(", "':'", ",", "$", "output", ",", "2", ")", ";", "$", "icon", "=", "Str", "::", "low", "(", "$", "icon", ")", ";", "$", "output", "=", "$", "this", "->", "Html", "->", "icon", "(", "$", "icon", ",", "[", "'class'", "=>", "$", "iconClass", "]", ")", ";", "}", "}", "}", "return", "$", "output", ";", "}" ]
Prepare before after content for input container. @param string|int $type Set before or after flag. @param string|int $value @return null|string
[ "Prepare", "before", "after", "content", "for", "input", "container", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L172-L190
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._setBtnClass
protected function _setBtnClass($button, array $options = []) { if ($button !== true) { $classes = [$this->_configRead('btnPref')]; foreach ((array) $button as $button) { $classes[] = $this->_configRead('btnPref') . '-' . $button; } $options = $this->_addClass($options, implode(' ', $classes)); } return $options; }
php
protected function _setBtnClass($button, array $options = []) { if ($button !== true) { $classes = [$this->_configRead('btnPref')]; foreach ((array) $button as $button) { $classes[] = $this->_configRead('btnPref') . '-' . $button; } $options = $this->_addClass($options, implode(' ', $classes)); } return $options; }
[ "protected", "function", "_setBtnClass", "(", "$", "button", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "button", "!==", "true", ")", "{", "$", "classes", "=", "[", "$", "this", "->", "_configRead", "(", "'btnPref'", ")", "]", ";", "foreach", "(", "(", "array", ")", "$", "button", "as", "$", "button", ")", "{", "$", "classes", "[", "]", "=", "$", "this", "->", "_configRead", "(", "'btnPref'", ")", ".", "'-'", ".", "$", "button", ";", "}", "$", "options", "=", "$", "this", "->", "_addClass", "(", "$", "options", ",", "implode", "(", "' '", ",", "$", "classes", ")", ")", ";", "}", "return", "$", "options", ";", "}" ]
Setup button classes by options. @param string $button @param array $options @return array
[ "Setup", "button", "classes", "by", "options", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L199-L210
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._setIconOptions
protected function _setIconOptions(array $options = [], array $iconOptions = []) { $icon = $options['icon']; if (Arr::key('iconInline', $options)) { $iconPrefix = $this->_configRead('iconPref'); $options = $this->_addClass($options, implode(' ', [ $this->_class('icon'), $iconPrefix, $iconPrefix . '-' . $icon ])); unset($options['icon']); } else { $options['escape'] = false; $iconOptions['createIcon'] = true; } return [$options, $iconOptions]; }
php
protected function _setIconOptions(array $options = [], array $iconOptions = []) { $icon = $options['icon']; if (Arr::key('iconInline', $options)) { $iconPrefix = $this->_configRead('iconPref'); $options = $this->_addClass($options, implode(' ', [ $this->_class('icon'), $iconPrefix, $iconPrefix . '-' . $icon ])); unset($options['icon']); } else { $options['escape'] = false; $iconOptions['createIcon'] = true; } return [$options, $iconOptions]; }
[ "protected", "function", "_setIconOptions", "(", "array", "$", "options", "=", "[", "]", ",", "array", "$", "iconOptions", "=", "[", "]", ")", "{", "$", "icon", "=", "$", "options", "[", "'icon'", "]", ";", "if", "(", "Arr", "::", "key", "(", "'iconInline'", ",", "$", "options", ")", ")", "{", "$", "iconPrefix", "=", "$", "this", "->", "_configRead", "(", "'iconPref'", ")", ";", "$", "options", "=", "$", "this", "->", "_addClass", "(", "$", "options", ",", "implode", "(", "' '", ",", "[", "$", "this", "->", "_class", "(", "'icon'", ")", ",", "$", "iconPrefix", ",", "$", "iconPrefix", ".", "'-'", ".", "$", "icon", "]", ")", ")", ";", "unset", "(", "$", "options", "[", "'icon'", "]", ")", ";", "}", "else", "{", "$", "options", "[", "'escape'", "]", "=", "false", ";", "$", "iconOptions", "[", "'createIcon'", "]", "=", "true", ";", "}", "return", "[", "$", "options", ",", "$", "iconOptions", "]", ";", "}" ]
Setup icon options. @param array $options @param array $iconOptions @return array
[ "Setup", "icon", "options", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L219-L237
CakeCMS/Core
src/View/Helper/Traits/HelperTrait.php
HelperTrait._setTooltipTitle
protected function _setTooltipTitle($tooltip, array $options = []) { if ($tooltip === true && !Arr::key('title', $options)) { $options['title'] = strip_tags($options['label']); } if (is_string($tooltip)) { $options['title'] = $tooltip; } return $options; }
php
protected function _setTooltipTitle($tooltip, array $options = []) { if ($tooltip === true && !Arr::key('title', $options)) { $options['title'] = strip_tags($options['label']); } if (is_string($tooltip)) { $options['title'] = $tooltip; } return $options; }
[ "protected", "function", "_setTooltipTitle", "(", "$", "tooltip", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "tooltip", "===", "true", "&&", "!", "Arr", "::", "key", "(", "'title'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'title'", "]", "=", "strip_tags", "(", "$", "options", "[", "'label'", "]", ")", ";", "}", "if", "(", "is_string", "(", "$", "tooltip", ")", ")", "{", "$", "options", "[", "'title'", "]", "=", "$", "tooltip", ";", "}", "return", "$", "options", ";", "}" ]
Setup tooltip title by options. @param string $tooltip @param array $options @return array
[ "Setup", "tooltip", "title", "by", "options", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/Traits/HelperTrait.php#L246-L257
aryelgois/yasql-php
src/Utils.php
Utils.arrayAppendLast
public static function arrayAppendLast( array $array, string $last, string $others = null ) { $count = count($array); foreach ($array as $key => $value) { $array[$key] = $value . (--$count > 0 ? $others : $last); } return $array; }
php
public static function arrayAppendLast( array $array, string $last, string $others = null ) { $count = count($array); foreach ($array as $key => $value) { $array[$key] = $value . (--$count > 0 ? $others : $last); } return $array; }
[ "public", "static", "function", "arrayAppendLast", "(", "array", "$", "array", ",", "string", "$", "last", ",", "string", "$", "others", "=", "null", ")", "{", "$", "count", "=", "count", "(", "$", "array", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "array", "[", "$", "key", "]", "=", "$", "value", ".", "(", "--", "$", "count", ">", "0", "?", "$", "others", ":", "$", "last", ")", ";", "}", "return", "$", "array", ";", "}" ]
Appends a string to the last item in an array Optionally, appends a string to the other items @param string[] $array Array to receive data @param string $last Appended to the last item @param string $others Appended to the other items
[ "Appends", "a", "string", "to", "the", "last", "item", "in", "an", "array" ]
train
https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Utils.php#L28-L38
maximebf/events
src/Events/ClassListener.php
ClassListener.handle
public function handle(Event $event) { $args = array(); $method = new \ReflectionMethod($this->object, $this->getMethodName($event)); if ($this->paramsAsArgs) { foreach ($method->getParameters() as $param) { if ($event->hasParam($param->getName())) { $args[] = $event->getParam($param->getName()); } else if (!$param->isOptional()) { throw new EventException("Missing parameter '" . $param->getName() . "' for '" . get_class($this->object) . "::" . $method->getName() . "'"); } else { $args[] = $param->getDefaultValue(); } } } $args[] = $event; $return = $method->invokeArgs($this->object, $args); if ($return !== null) { $event->setReturnValue($return); } }
php
public function handle(Event $event) { $args = array(); $method = new \ReflectionMethod($this->object, $this->getMethodName($event)); if ($this->paramsAsArgs) { foreach ($method->getParameters() as $param) { if ($event->hasParam($param->getName())) { $args[] = $event->getParam($param->getName()); } else if (!$param->isOptional()) { throw new EventException("Missing parameter '" . $param->getName() . "' for '" . get_class($this->object) . "::" . $method->getName() . "'"); } else { $args[] = $param->getDefaultValue(); } } } $args[] = $event; $return = $method->invokeArgs($this->object, $args); if ($return !== null) { $event->setReturnValue($return); } }
[ "public", "function", "handle", "(", "Event", "$", "event", ")", "{", "$", "args", "=", "array", "(", ")", ";", "$", "method", "=", "new", "\\", "ReflectionMethod", "(", "$", "this", "->", "object", ",", "$", "this", "->", "getMethodName", "(", "$", "event", ")", ")", ";", "if", "(", "$", "this", "->", "paramsAsArgs", ")", "{", "foreach", "(", "$", "method", "->", "getParameters", "(", ")", "as", "$", "param", ")", "{", "if", "(", "$", "event", "->", "hasParam", "(", "$", "param", "->", "getName", "(", ")", ")", ")", "{", "$", "args", "[", "]", "=", "$", "event", "->", "getParam", "(", "$", "param", "->", "getName", "(", ")", ")", ";", "}", "else", "if", "(", "!", "$", "param", "->", "isOptional", "(", ")", ")", "{", "throw", "new", "EventException", "(", "\"Missing parameter '\"", ".", "$", "param", "->", "getName", "(", ")", ".", "\"' for '\"", ".", "get_class", "(", "$", "this", "->", "object", ")", ".", "\"::\"", ".", "$", "method", "->", "getName", "(", ")", ".", "\"'\"", ")", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "param", "->", "getDefaultValue", "(", ")", ";", "}", "}", "}", "$", "args", "[", "]", "=", "$", "event", ";", "$", "return", "=", "$", "method", "->", "invokeArgs", "(", "$", "this", "->", "object", ",", "$", "args", ")", ";", "if", "(", "$", "return", "!==", "null", ")", "{", "$", "event", "->", "setReturnValue", "(", "$", "return", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/ClassListener.php#L63-L84
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Writer/Word2007/Rels.php
PHPWord_Writer_Word2007_Rels._writeRelationship
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if($pType != '' && $pTarget != '') { if(strpos($pId, 'rId') === false) { $pId = 'rId' . $pId; } // Write relationship $objWriter->startElement('Relationship'); $objWriter->writeAttribute('Id', $pId); $objWriter->writeAttribute('Type', $pType); $objWriter->writeAttribute('Target', $pTarget); if($pTargetMode != '') { $objWriter->writeAttribute('TargetMode', $pTargetMode); } $objWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } }
php
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if($pType != '' && $pTarget != '') { if(strpos($pId, 'rId') === false) { $pId = 'rId' . $pId; } // Write relationship $objWriter->startElement('Relationship'); $objWriter->writeAttribute('Id', $pId); $objWriter->writeAttribute('Type', $pType); $objWriter->writeAttribute('Target', $pTarget); if($pTargetMode != '') { $objWriter->writeAttribute('TargetMode', $pTargetMode); } $objWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } }
[ "private", "function", "_writeRelationship", "(", "PHPWord_Shared_XMLWriter", "$", "objWriter", "=", "null", ",", "$", "pId", "=", "1", ",", "$", "pType", "=", "''", ",", "$", "pTarget", "=", "''", ",", "$", "pTargetMode", "=", "''", ")", "{", "if", "(", "$", "pType", "!=", "''", "&&", "$", "pTarget", "!=", "''", ")", "{", "if", "(", "strpos", "(", "$", "pId", ",", "'rId'", ")", "===", "false", ")", "{", "$", "pId", "=", "'rId'", ".", "$", "pId", ";", "}", "// Write relationship\r", "$", "objWriter", "->", "startElement", "(", "'Relationship'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'Id'", ",", "$", "pId", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'Type'", ",", "$", "pType", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'Target'", ",", "$", "pTarget", ")", ";", "if", "(", "$", "pTargetMode", "!=", "''", ")", "{", "$", "objWriter", "->", "writeAttribute", "(", "'TargetMode'", ",", "$", "pTargetMode", ")", ";", "}", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"Invalid parameters passed.\"", ")", ";", "}", "}" ]
Write Override content type @param PHPWord_Shared_XMLWriter $objWriter XML Writer @param int $pId Relationship ID. rId will be prepended! @param string $pType Relationship type @param string $pTarget Relationship target @param string $pTargetMode Relationship target mode @throws Exception
[ "Write", "Override", "content", "type" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Writer/Word2007/Rels.php#L89-L109
yuncms/framework
src/helpers/Json.php
Json.decodeIfJson
public static function decodeIfJson(string $str, bool $asArray = true) { try { return static::decode($str, $asArray); } catch (InvalidArgumentException $e) { // Wasn't JSON return $str; } }
php
public static function decodeIfJson(string $str, bool $asArray = true) { try { return static::decode($str, $asArray); } catch (InvalidArgumentException $e) { // Wasn't JSON return $str; } }
[ "public", "static", "function", "decodeIfJson", "(", "string", "$", "str", ",", "bool", "$", "asArray", "=", "true", ")", "{", "try", "{", "return", "static", "::", "decode", "(", "$", "str", ",", "$", "asArray", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "// Wasn't JSON", "return", "$", "str", ";", "}", "}" ]
Decodes the given JSON string into a PHP data structure, only if the string is valid JSON. @param string $str The string to be decoded, if it's valid JSON. @param bool $asArray Whether to return objects in terms of associative arrays. @return mixed The PHP data, or the given string if it wasn’t valid JSON.
[ "Decodes", "the", "given", "JSON", "string", "into", "a", "PHP", "data", "structure", "only", "if", "the", "string", "is", "valid", "JSON", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/Json.php#L27-L35
barebone-php/barebone-core
lib/Request.php
Request.createFromGlobals
public static function createFromGlobals() { $server = Factory::normalizeServer($_SERVER); $files = Factory::normalizeFiles($_FILES); $headers = Factory::marshalHeaders($server); return new static( $server, $files, Factory::marshalUriFromServer($server, $headers), Factory::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers, $_COOKIE, $_GET, $_POST, static::_marshalProtocolVersion($server) ); }
php
public static function createFromGlobals() { $server = Factory::normalizeServer($_SERVER); $files = Factory::normalizeFiles($_FILES); $headers = Factory::marshalHeaders($server); return new static( $server, $files, Factory::marshalUriFromServer($server, $headers), Factory::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers, $_COOKIE, $_GET, $_POST, static::_marshalProtocolVersion($server) ); }
[ "public", "static", "function", "createFromGlobals", "(", ")", "{", "$", "server", "=", "Factory", "::", "normalizeServer", "(", "$", "_SERVER", ")", ";", "$", "files", "=", "Factory", "::", "normalizeFiles", "(", "$", "_FILES", ")", ";", "$", "headers", "=", "Factory", "::", "marshalHeaders", "(", "$", "server", ")", ";", "return", "new", "static", "(", "$", "server", ",", "$", "files", ",", "Factory", "::", "marshalUriFromServer", "(", "$", "server", ",", "$", "headers", ")", ",", "Factory", "::", "get", "(", "'REQUEST_METHOD'", ",", "$", "server", ",", "'GET'", ")", ",", "'php://input'", ",", "$", "headers", ",", "$", "_COOKIE", ",", "$", "_GET", ",", "$", "_POST", ",", "static", "::", "_marshalProtocolVersion", "(", "$", "server", ")", ")", ";", "}" ]
Create a request from the supplied superglobal values. If any argument is not supplied, the corresponding superglobal value will be used. The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers. @see ServerRequestFactory::fromServer() @throws InvalidArgumentException for invalid file values @return Request
[ "Create", "a", "request", "from", "the", "supplied", "superglobal", "values", "." ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Request.php#L54-L72
barebone-php/barebone-core
lib/Request.php
Request._marshalProtocolVersion
private static function _marshalProtocolVersion($server) { if (!isset($server['SERVER_PROTOCOL'])) { return '1.1'; } if (!preg_match( '#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches ) ) { throw new UnexpectedValueException( sprintf( 'Unrecognized protocol version (%s)', $server['SERVER_PROTOCOL'] ) ); } return $matches['version']; }
php
private static function _marshalProtocolVersion($server) { if (!isset($server['SERVER_PROTOCOL'])) { return '1.1'; } if (!preg_match( '#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches ) ) { throw new UnexpectedValueException( sprintf( 'Unrecognized protocol version (%s)', $server['SERVER_PROTOCOL'] ) ); } return $matches['version']; }
[ "private", "static", "function", "_marshalProtocolVersion", "(", "$", "server", ")", "{", "if", "(", "!", "isset", "(", "$", "server", "[", "'SERVER_PROTOCOL'", "]", ")", ")", "{", "return", "'1.1'", ";", "}", "if", "(", "!", "preg_match", "(", "'#^(HTTP/)?(?P<version>[1-9]\\d*(?:\\.\\d)?)$#'", ",", "$", "server", "[", "'SERVER_PROTOCOL'", "]", ",", "$", "matches", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'Unrecognized protocol version (%s)'", ",", "$", "server", "[", "'SERVER_PROTOCOL'", "]", ")", ")", ";", "}", "return", "$", "matches", "[", "'version'", "]", ";", "}" ]
Return HTTP protocol version (X.Y) @param array $server The SERVER environment variable @return string
[ "Return", "HTTP", "protocol", "version", "(", "X", ".", "Y", ")" ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Request.php#L81-L101
barebone-php/barebone-core
lib/Request.php
Request.getContentType
public function getContentType() { $contentType = null; $_contentType = $this->getHeader('Content-Type'); if (!empty($_contentType)) { $_contentType = explode(';', $_contentType[0]); $contentType = $_contentType[0]; } return $contentType; }
php
public function getContentType() { $contentType = null; $_contentType = $this->getHeader('Content-Type'); if (!empty($_contentType)) { $_contentType = explode(';', $_contentType[0]); $contentType = $_contentType[0]; } return $contentType; }
[ "public", "function", "getContentType", "(", ")", "{", "$", "contentType", "=", "null", ";", "$", "_contentType", "=", "$", "this", "->", "getHeader", "(", "'Content-Type'", ")", ";", "if", "(", "!", "empty", "(", "$", "_contentType", ")", ")", "{", "$", "_contentType", "=", "explode", "(", "';'", ",", "$", "_contentType", "[", "0", "]", ")", ";", "$", "contentType", "=", "$", "_contentType", "[", "0", "]", ";", "}", "return", "$", "contentType", ";", "}" ]
Get primary content-type header without encoding info @return string|null
[ "Get", "primary", "content", "-", "type", "header", "without", "encoding", "info" ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Request.php#L132-L142
barebone-php/barebone-core
lib/Request.php
Request.getParsedBody
public function getParsedBody() { $parsedBody = parent::getParsedBody(); if (empty($parsedBody)) { if ($this->getContentType() == 'application/json') { $input = file_get_contents("php://input"); $parsedBody = json_decode($input, true); } } return $parsedBody; }
php
public function getParsedBody() { $parsedBody = parent::getParsedBody(); if (empty($parsedBody)) { if ($this->getContentType() == 'application/json') { $input = file_get_contents("php://input"); $parsedBody = json_decode($input, true); } } return $parsedBody; }
[ "public", "function", "getParsedBody", "(", ")", "{", "$", "parsedBody", "=", "parent", "::", "getParsedBody", "(", ")", ";", "if", "(", "empty", "(", "$", "parsedBody", ")", ")", "{", "if", "(", "$", "this", "->", "getContentType", "(", ")", "==", "'application/json'", ")", "{", "$", "input", "=", "file_get_contents", "(", "\"php://input\"", ")", ";", "$", "parsedBody", "=", "json_decode", "(", "$", "input", ",", "true", ")", ";", "}", "}", "return", "$", "parsedBody", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/barebone-php/barebone-core/blob/7fda3a62d5fa103cdc4d2d34e1adf8f3ccbfe2bc/lib/Request.php#L147-L159
flextype-components/http
Http.php
Http.setResponseStatus
public static function setResponseStatus(int $status) : void { if (array_key_exists($status, Http::$http_status_messages)) { header('HTTP/1.1 ' . $status . ' ' . Http::$http_status_messages[$status]); } }
php
public static function setResponseStatus(int $status) : void { if (array_key_exists($status, Http::$http_status_messages)) { header('HTTP/1.1 ' . $status . ' ' . Http::$http_status_messages[$status]); } }
[ "public", "static", "function", "setResponseStatus", "(", "int", "$", "status", ")", ":", "void", "{", "if", "(", "array_key_exists", "(", "$", "status", ",", "Http", "::", "$", "http_status_messages", ")", ")", "{", "header", "(", "'HTTP/1.1 '", ".", "$", "status", ".", "' '", ".", "Http", "::", "$", "http_status_messages", "[", "$", "status", "]", ")", ";", "}", "}" ]
Set response header status Http::setResponseStatus(404); @param integer $status Status code @return void
[ "Set", "response", "header", "status" ]
train
https://github.com/flextype-components/http/blob/97c352f79b216355ba655a1cefcdbe69c134dee5/Http.php#L95-L100
flextype-components/http
Http.php
Http.redirect
public static function redirect(string $url, int $status = 302, int $delay = null) { // Status codes $messages = []; $messages[301] = '301 Moved Permanently'; $messages[302] = '302 Found'; // Is Headers sent ? if (headers_sent()) { echo "<script>document.location.href='" . $url . "';</script>\n"; } else { // Redirect headers Http::setRequestHeaders('HTTP/1.1 ' . $status . ' ' . Arr::get($messages, $status, 302)); // Delay execution if ($delay !== null) { sleep((int) $delay); } // Redirect Http::setRequestHeaders("Location: $url"); // Shutdown request Http::requestShutdown(); } }
php
public static function redirect(string $url, int $status = 302, int $delay = null) { // Status codes $messages = []; $messages[301] = '301 Moved Permanently'; $messages[302] = '302 Found'; // Is Headers sent ? if (headers_sent()) { echo "<script>document.location.href='" . $url . "';</script>\n"; } else { // Redirect headers Http::setRequestHeaders('HTTP/1.1 ' . $status . ' ' . Arr::get($messages, $status, 302)); // Delay execution if ($delay !== null) { sleep((int) $delay); } // Redirect Http::setRequestHeaders("Location: $url"); // Shutdown request Http::requestShutdown(); } }
[ "public", "static", "function", "redirect", "(", "string", "$", "url", ",", "int", "$", "status", "=", "302", ",", "int", "$", "delay", "=", "null", ")", "{", "// Status codes", "$", "messages", "=", "[", "]", ";", "$", "messages", "[", "301", "]", "=", "'301 Moved Permanently'", ";", "$", "messages", "[", "302", "]", "=", "'302 Found'", ";", "// Is Headers sent ?", "if", "(", "headers_sent", "(", ")", ")", "{", "echo", "\"<script>document.location.href='\"", ".", "$", "url", ".", "\"';</script>\\n\"", ";", "}", "else", "{", "// Redirect headers", "Http", "::", "setRequestHeaders", "(", "'HTTP/1.1 '", ".", "$", "status", ".", "' '", ".", "Arr", "::", "get", "(", "$", "messages", ",", "$", "status", ",", "302", ")", ")", ";", "// Delay execution", "if", "(", "$", "delay", "!==", "null", ")", "{", "sleep", "(", "(", "int", ")", "$", "delay", ")", ";", "}", "// Redirect", "Http", "::", "setRequestHeaders", "(", "\"Location: $url\"", ")", ";", "// Shutdown request", "Http", "::", "requestShutdown", "(", ")", ";", "}", "}" ]
Redirects the browser to a page specified by the $url argument. Http::redirect('test'); @param string $url The URL @param integer $status Status @param integer $delay Delay
[ "Redirects", "the", "browser", "to", "a", "page", "specified", "by", "the", "$url", "argument", "." ]
train
https://github.com/flextype-components/http/blob/97c352f79b216355ba655a1cefcdbe69c134dee5/Http.php#L111-L137
flextype-components/http
Http.php
Http.getBaseUrl
public static function getBaseUrl() : string { $https = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? 'https://' : 'http://'; return $https . rtrim(rtrim($_SERVER['HTTP_HOST'], '\\/') . dirname($_SERVER['PHP_SELF']), '\\/'); }
php
public static function getBaseUrl() : string { $https = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? 'https://' : 'http://'; return $https . rtrim(rtrim($_SERVER['HTTP_HOST'], '\\/') . dirname($_SERVER['PHP_SELF']), '\\/'); }
[ "public", "static", "function", "getBaseUrl", "(", ")", ":", "string", "{", "$", "https", "=", "(", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "&&", "strtolower", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "==", "'on'", ")", "?", "'https://'", ":", "'http://'", ";", "return", "$", "https", ".", "rtrim", "(", "rtrim", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ",", "'\\\\/'", ")", ".", "dirname", "(", "$", "_SERVER", "[", "'PHP_SELF'", "]", ")", ",", "'\\\\/'", ")", ";", "}" ]
Gets the base URL echo Http::getBaseUrl(); @return string
[ "Gets", "the", "base", "URL" ]
train
https://github.com/flextype-components/http/blob/97c352f79b216355ba655a1cefcdbe69c134dee5/Http.php#L189-L194
flextype-components/http
Http.php
Http.getUriString
public static function getUriString() : string { // Get request url and script url $url = ''; $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; // Get our url path and trim the / of the left and the right if ($request_url != $script_url) { $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/'); } $url = preg_replace('/\?.*/', '', $url); // Strip query string return $url; }
php
public static function getUriString() : string { // Get request url and script url $url = ''; $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; // Get our url path and trim the / of the left and the right if ($request_url != $script_url) { $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/'); } $url = preg_replace('/\?.*/', '', $url); // Strip query string return $url; }
[ "public", "static", "function", "getUriString", "(", ")", ":", "string", "{", "// Get request url and script url", "$", "url", "=", "''", ";", "$", "request_url", "=", "(", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", "?", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ":", "''", ";", "$", "script_url", "=", "(", "isset", "(", "$", "_SERVER", "[", "'PHP_SELF'", "]", ")", ")", "?", "$", "_SERVER", "[", "'PHP_SELF'", "]", ":", "''", ";", "// Get our url path and trim the / of the left and the right", "if", "(", "$", "request_url", "!=", "$", "script_url", ")", "{", "$", "url", "=", "trim", "(", "preg_replace", "(", "'/'", ".", "str_replace", "(", "'/'", ",", "'\\/'", ",", "str_replace", "(", "'index.php'", ",", "''", ",", "$", "script_url", ")", ")", ".", "'/'", ",", "''", ",", "$", "request_url", ",", "1", ")", ",", "'/'", ")", ";", "}", "$", "url", "=", "preg_replace", "(", "'/\\?.*/'", ",", "''", ",", "$", "url", ")", ";", "// Strip query string", "return", "$", "url", ";", "}" ]
Get Uri String $uri_string = Http::getUriString(); @access public @return string
[ "Get", "Uri", "String" ]
train
https://github.com/flextype-components/http/blob/97c352f79b216355ba655a1cefcdbe69c134dee5/Http.php#L216-L231
flextype-components/http
Http.php
Http.getUriSegment
public static function getUriSegment(int $segment) { $segments = self::getUriSegments(); return isset($segments[$segment]) ? $segments[$segment] : null; }
php
public static function getUriSegment(int $segment) { $segments = self::getUriSegments(); return isset($segments[$segment]) ? $segments[$segment] : null; }
[ "public", "static", "function", "getUriSegment", "(", "int", "$", "segment", ")", "{", "$", "segments", "=", "self", "::", "getUriSegments", "(", ")", ";", "return", "isset", "(", "$", "segments", "[", "$", "segment", "]", ")", "?", "$", "segments", "[", "$", "segment", "]", ":", "null", ";", "}" ]
Get Uri Segment $uri_segment = Http::getUriSegment(1); @access public @param int $segment segment @return string
[ "Get", "Uri", "Segment" ]
train
https://github.com/flextype-components/http/blob/97c352f79b216355ba655a1cefcdbe69c134dee5/Http.php#L255-L259
npbtrac/yii2-enpii-cms
libs/override/web/NpUrlManager.php
NpUrlManager.processLocaleUrl
protected function processLocaleUrl($request) { $this->_request = $request; $pathInfo = $request->getPathInfo(); $parts = []; foreach ($this->languages as $k => $v) { $value = is_string($k) ? $k : $v; if (substr($value, -2)==='-*') { $lng = substr($value, 0, -2); $parts[] = "$lng\-[a-z]{2,3}"; $parts[] = $lng; } else { $parts[] = $value; } } $pattern = implode('|', $parts); if (preg_match("#^($pattern)\b(/?)#i", $pathInfo, $m)) { $request->setPathInfo(mb_substr($pathInfo, mb_strlen($m[1].$m[2]))); $code = $m[1]; if (isset($this->languages[$code])) { // Replace alias with language code $language = $this->languages[$code]; } else { // lowercase language, uppercase country list($language,$country) = $this->matchCode($code); if ($country!==null) { if ($code==="$language-$country" && !$this->keepUppercaseLanguageCode) { $this->redirectToLanguage(strtolower($code)); // Redirect ll-CC to ll-cc } else { $language = "$language-$country"; } } if ($language===null) { $language = $code; } } Yii::$app->language = $language; Yii::trace("Language code found in URL. Setting application language to '$language'.", __METHOD__); if ($this->enableLanguagePersistence) { Yii::$app->session[$this->languageSessionKey] = $language; Yii::trace("Persisting language '$language' in session.", __METHOD__); if ($this->languageCookieDuration) { $cookie = new Cookie(array_merge( ['httpOnly' => true], $this->languageCookieOptions, [ 'name' => $this->languageCookieName, 'value' => $language, 'expire' => time() + (int) $this->languageCookieDuration, ] )); Yii::$app->getResponse()->getCookies()->add($cookie); Yii::trace("Persisting language '$language' in cookie.", __METHOD__); } } // "Reset" case: We called e.g. /fr/demo/page so the persisted language was set back to "fr". // Now we can redirect to the URL without language prefix, if default prefixes are disabled. if (!$this->enableDefaultLanguageUrlCode && $language===$this->_defaultLanguage) { $this->redirectToLanguage(''); } } else { $language = null; if ($this->enableLanguagePersistence) { $language = Yii::$app->session->get($this->languageSessionKey); $language!==null && Yii::trace("Found persisted language '$language' in session.", __METHOD__); if ($language===null) { $language = $request->getCookies()->getValue($this->languageCookieName); $language!==null && Yii::trace("Found persisted language '$language' in cookie.", __METHOD__); } } if ($language===null && $this->enableLanguageDetection) { foreach ($request->getAcceptableLanguages() as $acceptable) { list($language,$country) = $this->matchCode($acceptable); if ($language!==null) { $language = $country===null ? $language : "$language-$country"; Yii::trace("Detected browser language '$language'.", __METHOD__); break; } } } if ($language===null || $language===$this->_defaultLanguage) { if (!$this->enableDefaultLanguageUrlCode) { return; } else { $language = $this->_defaultLanguage; } } // #35: Only redirect if a valid language was found if ($this->matchCode($language)===[null, null]) { return; } $key = array_search($language, $this->languages); if ($key && is_string($key)) { $language = $key; } $this->redirectToLanguage($this->keepUppercaseLanguageCode ? $language : strtolower($language)); } }
php
protected function processLocaleUrl($request) { $this->_request = $request; $pathInfo = $request->getPathInfo(); $parts = []; foreach ($this->languages as $k => $v) { $value = is_string($k) ? $k : $v; if (substr($value, -2)==='-*') { $lng = substr($value, 0, -2); $parts[] = "$lng\-[a-z]{2,3}"; $parts[] = $lng; } else { $parts[] = $value; } } $pattern = implode('|', $parts); if (preg_match("#^($pattern)\b(/?)#i", $pathInfo, $m)) { $request->setPathInfo(mb_substr($pathInfo, mb_strlen($m[1].$m[2]))); $code = $m[1]; if (isset($this->languages[$code])) { // Replace alias with language code $language = $this->languages[$code]; } else { // lowercase language, uppercase country list($language,$country) = $this->matchCode($code); if ($country!==null) { if ($code==="$language-$country" && !$this->keepUppercaseLanguageCode) { $this->redirectToLanguage(strtolower($code)); // Redirect ll-CC to ll-cc } else { $language = "$language-$country"; } } if ($language===null) { $language = $code; } } Yii::$app->language = $language; Yii::trace("Language code found in URL. Setting application language to '$language'.", __METHOD__); if ($this->enableLanguagePersistence) { Yii::$app->session[$this->languageSessionKey] = $language; Yii::trace("Persisting language '$language' in session.", __METHOD__); if ($this->languageCookieDuration) { $cookie = new Cookie(array_merge( ['httpOnly' => true], $this->languageCookieOptions, [ 'name' => $this->languageCookieName, 'value' => $language, 'expire' => time() + (int) $this->languageCookieDuration, ] )); Yii::$app->getResponse()->getCookies()->add($cookie); Yii::trace("Persisting language '$language' in cookie.", __METHOD__); } } // "Reset" case: We called e.g. /fr/demo/page so the persisted language was set back to "fr". // Now we can redirect to the URL without language prefix, if default prefixes are disabled. if (!$this->enableDefaultLanguageUrlCode && $language===$this->_defaultLanguage) { $this->redirectToLanguage(''); } } else { $language = null; if ($this->enableLanguagePersistence) { $language = Yii::$app->session->get($this->languageSessionKey); $language!==null && Yii::trace("Found persisted language '$language' in session.", __METHOD__); if ($language===null) { $language = $request->getCookies()->getValue($this->languageCookieName); $language!==null && Yii::trace("Found persisted language '$language' in cookie.", __METHOD__); } } if ($language===null && $this->enableLanguageDetection) { foreach ($request->getAcceptableLanguages() as $acceptable) { list($language,$country) = $this->matchCode($acceptable); if ($language!==null) { $language = $country===null ? $language : "$language-$country"; Yii::trace("Detected browser language '$language'.", __METHOD__); break; } } } if ($language===null || $language===$this->_defaultLanguage) { if (!$this->enableDefaultLanguageUrlCode) { return; } else { $language = $this->_defaultLanguage; } } // #35: Only redirect if a valid language was found if ($this->matchCode($language)===[null, null]) { return; } $key = array_search($language, $this->languages); if ($key && is_string($key)) { $language = $key; } $this->redirectToLanguage($this->keepUppercaseLanguageCode ? $language : strtolower($language)); } }
[ "protected", "function", "processLocaleUrl", "(", "$", "request", ")", "{", "$", "this", "->", "_request", "=", "$", "request", ";", "$", "pathInfo", "=", "$", "request", "->", "getPathInfo", "(", ")", ";", "$", "parts", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "languages", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "value", "=", "is_string", "(", "$", "k", ")", "?", "$", "k", ":", "$", "v", ";", "if", "(", "substr", "(", "$", "value", ",", "-", "2", ")", "===", "'-*'", ")", "{", "$", "lng", "=", "substr", "(", "$", "value", ",", "0", ",", "-", "2", ")", ";", "$", "parts", "[", "]", "=", "\"$lng\\-[a-z]{2,3}\"", ";", "$", "parts", "[", "]", "=", "$", "lng", ";", "}", "else", "{", "$", "parts", "[", "]", "=", "$", "value", ";", "}", "}", "$", "pattern", "=", "implode", "(", "'|'", ",", "$", "parts", ")", ";", "if", "(", "preg_match", "(", "\"#^($pattern)\\b(/?)#i\"", ",", "$", "pathInfo", ",", "$", "m", ")", ")", "{", "$", "request", "->", "setPathInfo", "(", "mb_substr", "(", "$", "pathInfo", ",", "mb_strlen", "(", "$", "m", "[", "1", "]", ".", "$", "m", "[", "2", "]", ")", ")", ")", ";", "$", "code", "=", "$", "m", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "languages", "[", "$", "code", "]", ")", ")", "{", "// Replace alias with language code", "$", "language", "=", "$", "this", "->", "languages", "[", "$", "code", "]", ";", "}", "else", "{", "// lowercase language, uppercase country", "list", "(", "$", "language", ",", "$", "country", ")", "=", "$", "this", "->", "matchCode", "(", "$", "code", ")", ";", "if", "(", "$", "country", "!==", "null", ")", "{", "if", "(", "$", "code", "===", "\"$language-$country\"", "&&", "!", "$", "this", "->", "keepUppercaseLanguageCode", ")", "{", "$", "this", "->", "redirectToLanguage", "(", "strtolower", "(", "$", "code", ")", ")", ";", "// Redirect ll-CC to ll-cc", "}", "else", "{", "$", "language", "=", "\"$language-$country\"", ";", "}", "}", "if", "(", "$", "language", "===", "null", ")", "{", "$", "language", "=", "$", "code", ";", "}", "}", "Yii", "::", "$", "app", "->", "language", "=", "$", "language", ";", "Yii", "::", "trace", "(", "\"Language code found in URL. Setting application language to '$language'.\"", ",", "__METHOD__", ")", ";", "if", "(", "$", "this", "->", "enableLanguagePersistence", ")", "{", "Yii", "::", "$", "app", "->", "session", "[", "$", "this", "->", "languageSessionKey", "]", "=", "$", "language", ";", "Yii", "::", "trace", "(", "\"Persisting language '$language' in session.\"", ",", "__METHOD__", ")", ";", "if", "(", "$", "this", "->", "languageCookieDuration", ")", "{", "$", "cookie", "=", "new", "Cookie", "(", "array_merge", "(", "[", "'httpOnly'", "=>", "true", "]", ",", "$", "this", "->", "languageCookieOptions", ",", "[", "'name'", "=>", "$", "this", "->", "languageCookieName", ",", "'value'", "=>", "$", "language", ",", "'expire'", "=>", "time", "(", ")", "+", "(", "int", ")", "$", "this", "->", "languageCookieDuration", ",", "]", ")", ")", ";", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", "->", "getCookies", "(", ")", "->", "add", "(", "$", "cookie", ")", ";", "Yii", "::", "trace", "(", "\"Persisting language '$language' in cookie.\"", ",", "__METHOD__", ")", ";", "}", "}", "// \"Reset\" case: We called e.g. /fr/demo/page so the persisted language was set back to \"fr\".", "// Now we can redirect to the URL without language prefix, if default prefixes are disabled.", "if", "(", "!", "$", "this", "->", "enableDefaultLanguageUrlCode", "&&", "$", "language", "===", "$", "this", "->", "_defaultLanguage", ")", "{", "$", "this", "->", "redirectToLanguage", "(", "''", ")", ";", "}", "}", "else", "{", "$", "language", "=", "null", ";", "if", "(", "$", "this", "->", "enableLanguagePersistence", ")", "{", "$", "language", "=", "Yii", "::", "$", "app", "->", "session", "->", "get", "(", "$", "this", "->", "languageSessionKey", ")", ";", "$", "language", "!==", "null", "&&", "Yii", "::", "trace", "(", "\"Found persisted language '$language' in session.\"", ",", "__METHOD__", ")", ";", "if", "(", "$", "language", "===", "null", ")", "{", "$", "language", "=", "$", "request", "->", "getCookies", "(", ")", "->", "getValue", "(", "$", "this", "->", "languageCookieName", ")", ";", "$", "language", "!==", "null", "&&", "Yii", "::", "trace", "(", "\"Found persisted language '$language' in cookie.\"", ",", "__METHOD__", ")", ";", "}", "}", "if", "(", "$", "language", "===", "null", "&&", "$", "this", "->", "enableLanguageDetection", ")", "{", "foreach", "(", "$", "request", "->", "getAcceptableLanguages", "(", ")", "as", "$", "acceptable", ")", "{", "list", "(", "$", "language", ",", "$", "country", ")", "=", "$", "this", "->", "matchCode", "(", "$", "acceptable", ")", ";", "if", "(", "$", "language", "!==", "null", ")", "{", "$", "language", "=", "$", "country", "===", "null", "?", "$", "language", ":", "\"$language-$country\"", ";", "Yii", "::", "trace", "(", "\"Detected browser language '$language'.\"", ",", "__METHOD__", ")", ";", "break", ";", "}", "}", "}", "if", "(", "$", "language", "===", "null", "||", "$", "language", "===", "$", "this", "->", "_defaultLanguage", ")", "{", "if", "(", "!", "$", "this", "->", "enableDefaultLanguageUrlCode", ")", "{", "return", ";", "}", "else", "{", "$", "language", "=", "$", "this", "->", "_defaultLanguage", ";", "}", "}", "// #35: Only redirect if a valid language was found", "if", "(", "$", "this", "->", "matchCode", "(", "$", "language", ")", "===", "[", "null", ",", "null", "]", ")", "{", "return", ";", "}", "$", "key", "=", "array_search", "(", "$", "language", ",", "$", "this", "->", "languages", ")", ";", "if", "(", "$", "key", "&&", "is_string", "(", "$", "key", ")", ")", "{", "$", "language", "=", "$", "key", ";", "}", "$", "this", "->", "redirectToLanguage", "(", "$", "this", "->", "keepUppercaseLanguageCode", "?", "$", "language", ":", "strtolower", "(", "$", "language", ")", ")", ";", "}", "}" ]
Checks for a language or locale parameter in the URL and rewrites the pathInfo if found. If no parameter is found it will try to detect the language from persistent storage (session / cookie) or from browser settings. @var \yii\web\Request $request
[ "Checks", "for", "a", "language", "or", "locale", "parameter", "in", "the", "URL", "and", "rewrites", "the", "pathInfo", "if", "found", ".", "If", "no", "parameter", "is", "found", "it", "will", "try", "to", "detect", "the", "language", "from", "persistent", "storage", "(", "session", "/", "cookie", ")", "or", "from", "browser", "settings", "." ]
train
https://github.com/npbtrac/yii2-enpii-cms/blob/3495e697509a57a573983f552629ff9f707a63b9/libs/override/web/NpUrlManager.php#L244-L341
npbtrac/yii2-enpii-cms
libs/override/web/NpUrlManager.php
NpUrlManager.matchCode
protected function matchCode($code) { $language = $code; $country = null; $parts = explode('-', $code); if (count($parts)===2) { $language = $parts[0]; $country = strtoupper($parts[1]); } if (in_array($code, $this->languages)) { return [$language, $country]; } elseif ( $country && in_array("$language-$country", $this->languages) || in_array("$language-*", $this->languages) ) { return [$language, $country]; } elseif (in_array($language, $this->languages)) { return [$language, null]; } else { return [null, null]; } }
php
protected function matchCode($code) { $language = $code; $country = null; $parts = explode('-', $code); if (count($parts)===2) { $language = $parts[0]; $country = strtoupper($parts[1]); } if (in_array($code, $this->languages)) { return [$language, $country]; } elseif ( $country && in_array("$language-$country", $this->languages) || in_array("$language-*", $this->languages) ) { return [$language, $country]; } elseif (in_array($language, $this->languages)) { return [$language, null]; } else { return [null, null]; } }
[ "protected", "function", "matchCode", "(", "$", "code", ")", "{", "$", "language", "=", "$", "code", ";", "$", "country", "=", "null", ";", "$", "parts", "=", "explode", "(", "'-'", ",", "$", "code", ")", ";", "if", "(", "count", "(", "$", "parts", ")", "===", "2", ")", "{", "$", "language", "=", "$", "parts", "[", "0", "]", ";", "$", "country", "=", "strtoupper", "(", "$", "parts", "[", "1", "]", ")", ";", "}", "if", "(", "in_array", "(", "$", "code", ",", "$", "this", "->", "languages", ")", ")", "{", "return", "[", "$", "language", ",", "$", "country", "]", ";", "}", "elseif", "(", "$", "country", "&&", "in_array", "(", "\"$language-$country\"", ",", "$", "this", "->", "languages", ")", "||", "in_array", "(", "\"$language-*\"", ",", "$", "this", "->", "languages", ")", ")", "{", "return", "[", "$", "language", ",", "$", "country", "]", ";", "}", "elseif", "(", "in_array", "(", "$", "language", ",", "$", "this", "->", "languages", ")", ")", "{", "return", "[", "$", "language", ",", "null", "]", ";", "}", "else", "{", "return", "[", "null", ",", "null", "]", ";", "}", "}" ]
Tests whether the given code matches any of the configured languages. If the code is a single language code, and matches either - an exact language as configured (ll) - a language with a country wildcard (ll-*) this language code is returned. If the code also contains a country code, and matches either - an exact language/country code as configured (ll-CC) - a language with a country wildcard (ll-*) the code with uppercase country is returned. If only the language part matches a configured language, that language is returned. @param string $code the code to match @return array of [language, country], [language, null] or [null, null] if no match
[ "Tests", "whether", "the", "given", "code", "matches", "any", "of", "the", "configured", "languages", "." ]
train
https://github.com/npbtrac/yii2-enpii-cms/blob/3495e697509a57a573983f552629ff9f707a63b9/libs/override/web/NpUrlManager.php#L363-L384
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/AboutController.php
AboutController.aboutAction
public function aboutAction() { $oLicense = LicenseQuery::create()->findOne(); // include symfony requirements class require_once dirname(__FILE__) . '/../../../../app/SymfonyRequirements.php'; $symfonyRequirements = new \SymfonyRequirements(); // add additional requirement for mcrypt $symfonyRequirements->addRequirement(extension_loaded('mcrypt'), "Check if mcrypt ist loaded for RSA encryption", "Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>"); // fetch all data $aRequirements = $symfonyRequirements->getRequirements(); $aRecommendations = $symfonyRequirements->getRecommendations(); $aFailedRequirements = $symfonyRequirements->getFailedRequirements(); $aFailedRecommendations = $symfonyRequirements->getFailedRecommendations(); $iniPath = $symfonyRequirements->getPhpIniConfigPath(); $sVersion = file_get_contents(dirname(__FILE__) . '/../../../../version.txt'); return $this->render('SlashworksAppBundle:About:about.html.twig', array( "license" => $oLicense,"version" => $sVersion, "iniPath" => $iniPath, "requirements" => $aRequirements, "recommendations" => $aRecommendations, "failedrequirements" => $aFailedRequirements, "failedrecommendations" => $aFailedRecommendations )); }
php
public function aboutAction() { $oLicense = LicenseQuery::create()->findOne(); // include symfony requirements class require_once dirname(__FILE__) . '/../../../../app/SymfonyRequirements.php'; $symfonyRequirements = new \SymfonyRequirements(); // add additional requirement for mcrypt $symfonyRequirements->addRequirement(extension_loaded('mcrypt'), "Check if mcrypt ist loaded for RSA encryption", "Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>"); // fetch all data $aRequirements = $symfonyRequirements->getRequirements(); $aRecommendations = $symfonyRequirements->getRecommendations(); $aFailedRequirements = $symfonyRequirements->getFailedRequirements(); $aFailedRecommendations = $symfonyRequirements->getFailedRecommendations(); $iniPath = $symfonyRequirements->getPhpIniConfigPath(); $sVersion = file_get_contents(dirname(__FILE__) . '/../../../../version.txt'); return $this->render('SlashworksAppBundle:About:about.html.twig', array( "license" => $oLicense,"version" => $sVersion, "iniPath" => $iniPath, "requirements" => $aRequirements, "recommendations" => $aRecommendations, "failedrequirements" => $aFailedRequirements, "failedrecommendations" => $aFailedRecommendations )); }
[ "public", "function", "aboutAction", "(", ")", "{", "$", "oLicense", "=", "LicenseQuery", "::", "create", "(", ")", "->", "findOne", "(", ")", ";", "// include symfony requirements class", "require_once", "dirname", "(", "__FILE__", ")", ".", "'/../../../../app/SymfonyRequirements.php'", ";", "$", "symfonyRequirements", "=", "new", "\\", "SymfonyRequirements", "(", ")", ";", "// add additional requirement for mcrypt", "$", "symfonyRequirements", "->", "addRequirement", "(", "extension_loaded", "(", "'mcrypt'", ")", ",", "\"Check if mcrypt ist loaded for RSA encryption\"", ",", "\"Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>\"", ")", ";", "// fetch all data", "$", "aRequirements", "=", "$", "symfonyRequirements", "->", "getRequirements", "(", ")", ";", "$", "aRecommendations", "=", "$", "symfonyRequirements", "->", "getRecommendations", "(", ")", ";", "$", "aFailedRequirements", "=", "$", "symfonyRequirements", "->", "getFailedRequirements", "(", ")", ";", "$", "aFailedRecommendations", "=", "$", "symfonyRequirements", "->", "getFailedRecommendations", "(", ")", ";", "$", "iniPath", "=", "$", "symfonyRequirements", "->", "getPhpIniConfigPath", "(", ")", ";", "$", "sVersion", "=", "file_get_contents", "(", "dirname", "(", "__FILE__", ")", ".", "'/../../../../version.txt'", ")", ";", "return", "$", "this", "->", "render", "(", "'SlashworksAppBundle:About:about.html.twig'", ",", "array", "(", "\"license\"", "=>", "$", "oLicense", ",", "\"version\"", "=>", "$", "sVersion", ",", "\"iniPath\"", "=>", "$", "iniPath", ",", "\"requirements\"", "=>", "$", "aRequirements", ",", "\"recommendations\"", "=>", "$", "aRecommendations", ",", "\"failedrequirements\"", "=>", "$", "aFailedRequirements", ",", "\"failedrecommendations\"", "=>", "$", "aFailedRecommendations", ")", ")", ";", "}" ]
Display form for license activation @return \Symfony\Component\HttpFoundation\Response
[ "Display", "form", "for", "license", "activation" ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/AboutController.php#L44-L72
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.initialize
public function initialize(array $config) { $isMaterializeCss = $this->getConfig('materializeCss', false); if ($isMaterializeCss === true) { $this->_configWrite('prepareBtnClass', function (Helper $form, $options, $button) { return $this->_prepareBtn($form, $options, $button); }); $this->_configWrite('prepareTooltip', function (Helper $html, $options, $tooltip) { return $this->_prepareTooltip($html, $options, $tooltip); }); } parent::initialize($config); }
php
public function initialize(array $config) { $isMaterializeCss = $this->getConfig('materializeCss', false); if ($isMaterializeCss === true) { $this->_configWrite('prepareBtnClass', function (Helper $form, $options, $button) { return $this->_prepareBtn($form, $options, $button); }); $this->_configWrite('prepareTooltip', function (Helper $html, $options, $tooltip) { return $this->_prepareTooltip($html, $options, $tooltip); }); } parent::initialize($config); }
[ "public", "function", "initialize", "(", "array", "$", "config", ")", "{", "$", "isMaterializeCss", "=", "$", "this", "->", "getConfig", "(", "'materializeCss'", ",", "false", ")", ";", "if", "(", "$", "isMaterializeCss", "===", "true", ")", "{", "$", "this", "->", "_configWrite", "(", "'prepareBtnClass'", ",", "function", "(", "Helper", "$", "form", ",", "$", "options", ",", "$", "button", ")", "{", "return", "$", "this", "->", "_prepareBtn", "(", "$", "form", ",", "$", "options", ",", "$", "button", ")", ";", "}", ")", ";", "$", "this", "->", "_configWrite", "(", "'prepareTooltip'", ",", "function", "(", "Helper", "$", "html", ",", "$", "options", ",", "$", "tooltip", ")", "{", "return", "$", "this", "->", "_prepareTooltip", "(", "$", "html", ",", "$", "options", ",", "$", "tooltip", ")", ";", "}", ")", ";", "}", "parent", "::", "initialize", "(", "$", "config", ")", ";", "}" ]
Constructor hook method. Implement this method to avoid having to overwrite the constructor and call parent. @param array $config The configuration settings provided to this helper. @return void
[ "Constructor", "hook", "method", ".", "Implement", "this", "method", "to", "avoid", "having", "to", "overwrite", "the", "constructor", "and", "call", "parent", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L90-L105
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.getAssets
public function getAssets($key) { $value = Hash::get($this->_assets, $key); if (is_string($value)) { return $value; } return Hash::sort((array) $value, '{n}.weight', 'asc'); }
php
public function getAssets($key) { $value = Hash::get($this->_assets, $key); if (is_string($value)) { return $value; } return Hash::sort((array) $value, '{n}.weight', 'asc'); }
[ "public", "function", "getAssets", "(", "$", "key", ")", "{", "$", "value", "=", "Hash", "::", "get", "(", "$", "this", "->", "_assets", ",", "$", "key", ")", ";", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "return", "Hash", "::", "sort", "(", "(", "array", ")", "$", "value", ",", "'{n}.weight'", ",", "'asc'", ")", ";", "}" ]
Get sort assets included list. @param string $key @return array|null|string
[ "Get", "sort", "assets", "included", "list", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L126-L134
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.icon
public function icon($icon = 'home', array $options = []) { $iconPref = $this->_configRead('iconPref'); $_classes = [ $this->_class(__FUNCTION__), $iconPref, $iconPref . '-' . $icon, ]; $options = $this->_addClass($options, implode(' ', $_classes)); $classes = $options['class']; unset($options['class']); $templater = $this->templater(); return $templater->format(__FUNCTION__, [ 'class' => $classes, 'attrs' => $templater->formatAttributes($options), ]); }
php
public function icon($icon = 'home', array $options = []) { $iconPref = $this->_configRead('iconPref'); $_classes = [ $this->_class(__FUNCTION__), $iconPref, $iconPref . '-' . $icon, ]; $options = $this->_addClass($options, implode(' ', $_classes)); $classes = $options['class']; unset($options['class']); $templater = $this->templater(); return $templater->format(__FUNCTION__, [ 'class' => $classes, 'attrs' => $templater->formatAttributes($options), ]); }
[ "public", "function", "icon", "(", "$", "icon", "=", "'home'", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "iconPref", "=", "$", "this", "->", "_configRead", "(", "'iconPref'", ")", ";", "$", "_classes", "=", "[", "$", "this", "->", "_class", "(", "__FUNCTION__", ")", ",", "$", "iconPref", ",", "$", "iconPref", ".", "'-'", ".", "$", "icon", ",", "]", ";", "$", "options", "=", "$", "this", "->", "_addClass", "(", "$", "options", ",", "implode", "(", "' '", ",", "$", "_classes", ")", ")", ";", "$", "classes", "=", "$", "options", "[", "'class'", "]", ";", "unset", "(", "$", "options", "[", "'class'", "]", ")", ";", "$", "templater", "=", "$", "this", "->", "templater", "(", ")", ";", "return", "$", "templater", "->", "format", "(", "__FUNCTION__", ",", "[", "'class'", "=>", "$", "classes", ",", "'attrs'", "=>", "$", "templater", "->", "formatAttributes", "(", "$", "options", ")", ",", "]", ")", ";", "}" ]
Create icon element. @param string $icon @param array $options @return null|string
[ "Create", "icon", "element", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L143-L161
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.less
public function less($path, array $options = []) { $cssPath = []; if (!Arr::key('force', $options)) { $options['force'] = false; } if (is_array($path)) { foreach ($path as $i) { if ($result = $this->Less->process($i, $options['force'])) { $cssPath[] = $result; } } } if (is_string($path) && $result = $this->Less->process($path, $options['force'])) { $cssPath[] = $result; } return $this->css($cssPath, $options); }
php
public function less($path, array $options = []) { $cssPath = []; if (!Arr::key('force', $options)) { $options['force'] = false; } if (is_array($path)) { foreach ($path as $i) { if ($result = $this->Less->process($i, $options['force'])) { $cssPath[] = $result; } } } if (is_string($path) && $result = $this->Less->process($path, $options['force'])) { $cssPath[] = $result; } return $this->css($cssPath, $options); }
[ "public", "function", "less", "(", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "cssPath", "=", "[", "]", ";", "if", "(", "!", "Arr", "::", "key", "(", "'force'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'force'", "]", "=", "false", ";", "}", "if", "(", "is_array", "(", "$", "path", ")", ")", "{", "foreach", "(", "$", "path", "as", "$", "i", ")", "{", "if", "(", "$", "result", "=", "$", "this", "->", "Less", "->", "process", "(", "$", "i", ",", "$", "options", "[", "'force'", "]", ")", ")", "{", "$", "cssPath", "[", "]", "=", "$", "result", ";", "}", "}", "}", "if", "(", "is_string", "(", "$", "path", ")", "&&", "$", "result", "=", "$", "this", "->", "Less", "->", "process", "(", "$", "path", ",", "$", "options", "[", "'force'", "]", ")", ")", "{", "$", "cssPath", "[", "]", "=", "$", "result", ";", "}", "return", "$", "this", "->", "css", "(", "$", "cssPath", ",", "$", "options", ")", ";", "}" ]
Creates a CSS stylesheets from less. @param string|array $path @param array $options @return null|string @throws \JBZoo\Less\Exception
[ "Creates", "a", "CSS", "stylesheets", "from", "less", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L172-L193
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.link
public function link($title, $url = null, array $options = []) { $options = $this->addClass($options, $this->_class(__FUNCTION__)); $options = Hash::merge([ 'escapeTitle' => false, 'clear' => false, 'label' => $title, ], $options); $isClear = (bool) $options['clear']; unset($options['clear']); $options = $this->_setTitleAttr($title, $options); // Set title in html tag. if ($this->_isEscapeTitle($title, $isClear, $options)) { $title = $this->tag('span', $title, ['class' => $this->_class(__FUNCTION__) . '-title']); } $options = $this->_getBtnClass($options); $options = $this->_getToolTipAttr($options); list($title, $options) = $this->_createIcon($this, $title, $options); unset($options['label']); return parent::link($title, $url, $options); }
php
public function link($title, $url = null, array $options = []) { $options = $this->addClass($options, $this->_class(__FUNCTION__)); $options = Hash::merge([ 'escapeTitle' => false, 'clear' => false, 'label' => $title, ], $options); $isClear = (bool) $options['clear']; unset($options['clear']); $options = $this->_setTitleAttr($title, $options); // Set title in html tag. if ($this->_isEscapeTitle($title, $isClear, $options)) { $title = $this->tag('span', $title, ['class' => $this->_class(__FUNCTION__) . '-title']); } $options = $this->_getBtnClass($options); $options = $this->_getToolTipAttr($options); list($title, $options) = $this->_createIcon($this, $title, $options); unset($options['label']); return parent::link($title, $url, $options); }
[ "public", "function", "link", "(", "$", "title", ",", "$", "url", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "addClass", "(", "$", "options", ",", "$", "this", "->", "_class", "(", "__FUNCTION__", ")", ")", ";", "$", "options", "=", "Hash", "::", "merge", "(", "[", "'escapeTitle'", "=>", "false", ",", "'clear'", "=>", "false", ",", "'label'", "=>", "$", "title", ",", "]", ",", "$", "options", ")", ";", "$", "isClear", "=", "(", "bool", ")", "$", "options", "[", "'clear'", "]", ";", "unset", "(", "$", "options", "[", "'clear'", "]", ")", ";", "$", "options", "=", "$", "this", "->", "_setTitleAttr", "(", "$", "title", ",", "$", "options", ")", ";", "// Set title in html tag.", "if", "(", "$", "this", "->", "_isEscapeTitle", "(", "$", "title", ",", "$", "isClear", ",", "$", "options", ")", ")", "{", "$", "title", "=", "$", "this", "->", "tag", "(", "'span'", ",", "$", "title", ",", "[", "'class'", "=>", "$", "this", "->", "_class", "(", "__FUNCTION__", ")", ".", "'-title'", "]", ")", ";", "}", "$", "options", "=", "$", "this", "->", "_getBtnClass", "(", "$", "options", ")", ";", "$", "options", "=", "$", "this", "->", "_getToolTipAttr", "(", "$", "options", ")", ";", "list", "(", "$", "title", ",", "$", "options", ")", "=", "$", "this", "->", "_createIcon", "(", "$", "this", ",", "$", "title", ",", "$", "options", ")", ";", "unset", "(", "$", "options", "[", "'label'", "]", ")", ";", "return", "parent", "::", "link", "(", "$", "title", ",", "$", "url", ",", "$", "options", ")", ";", "}" ]
Create an html link. @param string $title @param null|string|array $url @param array $options @return string
[ "Create", "an", "html", "link", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L203-L229
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.status
public function status($status = 0, array $url = [], $icon = 'circle') { $class = (int) $status === 1 ? 'ck-green' : 'ck-red'; if (count($url) === 0) { return $this->icon($icon, ['class' => $class]); } return $this->link(null, 'javascript:void(0);', [ 'icon' => $icon, 'class' => $class, 'data-url' => $this->Url->build($url) ]); }
php
public function status($status = 0, array $url = [], $icon = 'circle') { $class = (int) $status === 1 ? 'ck-green' : 'ck-red'; if (count($url) === 0) { return $this->icon($icon, ['class' => $class]); } return $this->link(null, 'javascript:void(0);', [ 'icon' => $icon, 'class' => $class, 'data-url' => $this->Url->build($url) ]); }
[ "public", "function", "status", "(", "$", "status", "=", "0", ",", "array", "$", "url", "=", "[", "]", ",", "$", "icon", "=", "'circle'", ")", "{", "$", "class", "=", "(", "int", ")", "$", "status", "===", "1", "?", "'ck-green'", ":", "'ck-red'", ";", "if", "(", "count", "(", "$", "url", ")", "===", "0", ")", "{", "return", "$", "this", "->", "icon", "(", "$", "icon", ",", "[", "'class'", "=>", "$", "class", "]", ")", ";", "}", "return", "$", "this", "->", "link", "(", "null", ",", "'javascript:void(0);'", ",", "[", "'icon'", "=>", "$", "icon", ",", "'class'", "=>", "$", "class", ",", "'data-url'", "=>", "$", "this", "->", "Url", "->", "build", "(", "$", "url", ")", "]", ")", ";", "}" ]
Create status icon or link. @param int $status @param array $url @param string $icon @return null|string
[ "Create", "status", "icon", "or", "link", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L251-L263
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper.toggle
public function toggle(Entity $entity, array $url = [], array $data = []) { if (count($url) === 0) { $url = [ 'action' => 'toggle', 'prefix' => $this->request->getParam('prefix'), 'plugin' => $this->request->getParam('plugin'), 'controller' => $this->request->getParam('controller'), (int) $entity->get('id'), (int) $entity->get('status') ]; } $data = Hash::merge([ 'url' => $url, 'entity' => $entity, ], $data); return $this->_View->element('Core.' . __FUNCTION__, $data); }
php
public function toggle(Entity $entity, array $url = [], array $data = []) { if (count($url) === 0) { $url = [ 'action' => 'toggle', 'prefix' => $this->request->getParam('prefix'), 'plugin' => $this->request->getParam('plugin'), 'controller' => $this->request->getParam('controller'), (int) $entity->get('id'), (int) $entity->get('status') ]; } $data = Hash::merge([ 'url' => $url, 'entity' => $entity, ], $data); return $this->_View->element('Core.' . __FUNCTION__, $data); }
[ "public", "function", "toggle", "(", "Entity", "$", "entity", ",", "array", "$", "url", "=", "[", "]", ",", "array", "$", "data", "=", "[", "]", ")", "{", "if", "(", "count", "(", "$", "url", ")", "===", "0", ")", "{", "$", "url", "=", "[", "'action'", "=>", "'toggle'", ",", "'prefix'", "=>", "$", "this", "->", "request", "->", "getParam", "(", "'prefix'", ")", ",", "'plugin'", "=>", "$", "this", "->", "request", "->", "getParam", "(", "'plugin'", ")", ",", "'controller'", "=>", "$", "this", "->", "request", "->", "getParam", "(", "'controller'", ")", ",", "(", "int", ")", "$", "entity", "->", "get", "(", "'id'", ")", ",", "(", "int", ")", "$", "entity", "->", "get", "(", "'status'", ")", "]", ";", "}", "$", "data", "=", "Hash", "::", "merge", "(", "[", "'url'", "=>", "$", "url", ",", "'entity'", "=>", "$", "entity", ",", "]", ",", "$", "data", ")", ";", "return", "$", "this", "->", "_View", "->", "element", "(", "'Core.'", ".", "__FUNCTION__", ",", "$", "data", ")", ";", "}" ]
Create and render ajax toggle element. @param Entity $entity @param array $url @param array $data @return string
[ "Create", "and", "render", "ajax", "toggle", "element", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L273-L292
CakeCMS/Core
src/View/Helper/HtmlHelper.php
HtmlHelper._setTitleAttr
protected function _setTitleAttr($title, array $options = []) { if (!Arr::key('title', $options)) { $options['title'] = strip_tags($title); } return $options; }
php
protected function _setTitleAttr($title, array $options = []) { if (!Arr::key('title', $options)) { $options['title'] = strip_tags($title); } return $options; }
[ "protected", "function", "_setTitleAttr", "(", "$", "title", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "Arr", "::", "key", "(", "'title'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'title'", "]", "=", "strip_tags", "(", "$", "title", ")", ";", "}", "return", "$", "options", ";", "}" ]
Setup default title attr. @param string $title @param array $options @return array
[ "Setup", "default", "title", "attr", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/HtmlHelper.php#L314-L321
joomlatools/joomlatools-platform-legacy
code/utilities/xmlelement.php
JXMLElement.asFormattedXml
public function asFormattedXml($compressed = false, $indent = "\t", $level = 0) { JLog::add('JXMLElement::asFormattedXml() is deprecated, use SimpleXMLElement::asXml() instead.', JLog::WARNING, 'deprecated'); $out = ''; // Start a new line, indent by the number indicated in $level $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level); // Add a <, and add the name of the tag $out .= '<' . $this->getName(); // For each attribute, add attr="value" foreach ($this->attributes() as $attr) { $out .= ' ' . $attr->getName() . '="' . htmlspecialchars((string) $attr, ENT_COMPAT, 'UTF-8') . '"'; } // If there are no children and it contains no data, end it off with a /> if (!count($this->children()) && !(string) $this) { $out .= " />"; } else { // If there are children if (count($this->children())) { // Close off the start tag $out .= '>'; $level++; // For each child, call the asFormattedXML function (this will ensure that all children are added recursively) foreach ($this->children() as $child) { $out .= $child->asFormattedXml($compressed, $indent, $level); } $level--; // Add the newline and indentation to go along with the close tag $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level); } elseif ((string) $this) { // If there is data, close off the start tag and add the data $out .= '>' . htmlspecialchars((string) $this, ENT_COMPAT, 'UTF-8'); } // Add the end tag $out .= '</' . $this->getName() . '>'; } return $out; }
php
public function asFormattedXml($compressed = false, $indent = "\t", $level = 0) { JLog::add('JXMLElement::asFormattedXml() is deprecated, use SimpleXMLElement::asXml() instead.', JLog::WARNING, 'deprecated'); $out = ''; // Start a new line, indent by the number indicated in $level $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level); // Add a <, and add the name of the tag $out .= '<' . $this->getName(); // For each attribute, add attr="value" foreach ($this->attributes() as $attr) { $out .= ' ' . $attr->getName() . '="' . htmlspecialchars((string) $attr, ENT_COMPAT, 'UTF-8') . '"'; } // If there are no children and it contains no data, end it off with a /> if (!count($this->children()) && !(string) $this) { $out .= " />"; } else { // If there are children if (count($this->children())) { // Close off the start tag $out .= '>'; $level++; // For each child, call the asFormattedXML function (this will ensure that all children are added recursively) foreach ($this->children() as $child) { $out .= $child->asFormattedXml($compressed, $indent, $level); } $level--; // Add the newline and indentation to go along with the close tag $out .= ($compressed) ? '' : "\n" . str_repeat($indent, $level); } elseif ((string) $this) { // If there is data, close off the start tag and add the data $out .= '>' . htmlspecialchars((string) $this, ENT_COMPAT, 'UTF-8'); } // Add the end tag $out .= '</' . $this->getName() . '>'; } return $out; }
[ "public", "function", "asFormattedXml", "(", "$", "compressed", "=", "false", ",", "$", "indent", "=", "\"\\t\"", ",", "$", "level", "=", "0", ")", "{", "JLog", "::", "add", "(", "'JXMLElement::asFormattedXml() is deprecated, use SimpleXMLElement::asXml() instead.'", ",", "JLog", "::", "WARNING", ",", "'deprecated'", ")", ";", "$", "out", "=", "''", ";", "// Start a new line, indent by the number indicated in $level", "$", "out", ".=", "(", "$", "compressed", ")", "?", "''", ":", "\"\\n\"", ".", "str_repeat", "(", "$", "indent", ",", "$", "level", ")", ";", "// Add a <, and add the name of the tag", "$", "out", ".=", "'<'", ".", "$", "this", "->", "getName", "(", ")", ";", "// For each attribute, add attr=\"value\"", "foreach", "(", "$", "this", "->", "attributes", "(", ")", "as", "$", "attr", ")", "{", "$", "out", ".=", "' '", ".", "$", "attr", "->", "getName", "(", ")", ".", "'=\"'", ".", "htmlspecialchars", "(", "(", "string", ")", "$", "attr", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ".", "'\"'", ";", "}", "// If there are no children and it contains no data, end it off with a />", "if", "(", "!", "count", "(", "$", "this", "->", "children", "(", ")", ")", "&&", "!", "(", "string", ")", "$", "this", ")", "{", "$", "out", ".=", "\" />\"", ";", "}", "else", "{", "// If there are children", "if", "(", "count", "(", "$", "this", "->", "children", "(", ")", ")", ")", "{", "// Close off the start tag", "$", "out", ".=", "'>'", ";", "$", "level", "++", ";", "// For each child, call the asFormattedXML function (this will ensure that all children are added recursively)", "foreach", "(", "$", "this", "->", "children", "(", ")", "as", "$", "child", ")", "{", "$", "out", ".=", "$", "child", "->", "asFormattedXml", "(", "$", "compressed", ",", "$", "indent", ",", "$", "level", ")", ";", "}", "$", "level", "--", ";", "// Add the newline and indentation to go along with the close tag", "$", "out", ".=", "(", "$", "compressed", ")", "?", "''", ":", "\"\\n\"", ".", "str_repeat", "(", "$", "indent", ",", "$", "level", ")", ";", "}", "elseif", "(", "(", "string", ")", "$", "this", ")", "{", "// If there is data, close off the start tag and add the data", "$", "out", ".=", "'>'", ".", "htmlspecialchars", "(", "(", "string", ")", "$", "this", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "}", "// Add the end tag", "$", "out", ".=", "'</'", ".", "$", "this", "->", "getName", "(", ")", ".", "'>'", ";", "}", "return", "$", "out", ";", "}" ]
Return a well-formed XML string based on SimpleXML element @param boolean $compressed Should we use indentation and newlines ? @param string $indent Indention character. @param integer $level The level within the document which informs the indentation. @return string @since 11.1 @deprecated 13.3 Use SimpleXMLElement::asXml() instead.
[ "Return", "a", "well", "-", "formed", "XML", "string", "based", "on", "SimpleXML", "element" ]
train
https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/utilities/xmlelement.php#L49-L103
steeffeen/FancyManiaLinks
FML/Script/Features/ValuePickerFeature.php
ValuePickerFeature.setLabel
public function setLabel(Label $label) { $label->checkId(); $label->setScriptEvents(true); $this->label = $label; return $this; }
php
public function setLabel(Label $label) { $label->checkId(); $label->setScriptEvents(true); $this->label = $label; return $this; }
[ "public", "function", "setLabel", "(", "Label", "$", "label", ")", "{", "$", "label", "->", "checkId", "(", ")", ";", "$", "label", "->", "setScriptEvents", "(", "true", ")", ";", "$", "this", "->", "label", "=", "$", "label", ";", "return", "$", "this", ";", "}" ]
Set the Label @api @param Label $label Label @return static
[ "Set", "the", "Label" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ValuePickerFeature.php#L93-L99
steeffeen/FancyManiaLinks
FML/Script/Features/ValuePickerFeature.php
ValuePickerFeature.setValues
public function setValues(array $values) { $this->values = array(); foreach ($values as $value) { $this->addValue($value); } return $this; }
php
public function setValues(array $values) { $this->values = array(); foreach ($values as $value) { $this->addValue($value); } return $this; }
[ "public", "function", "setValues", "(", "array", "$", "values", ")", "{", "$", "this", "->", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "$", "this", "->", "addValue", "(", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the possible values @api @param string[] $values Possible values @return static
[ "Set", "the", "possible", "values" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ValuePickerFeature.php#L157-L164
steeffeen/FancyManiaLinks
FML/Script/Features/ValuePickerFeature.php
ValuePickerFeature.getDefault
public function getDefault() { if ($this->default) { return $this->default; } if (!empty($this->values)) { return reset($this->values); } return null; }
php
public function getDefault() { if ($this->default) { return $this->default; } if (!empty($this->values)) { return reset($this->values); } return null; }
[ "public", "function", "getDefault", "(", ")", "{", "if", "(", "$", "this", "->", "default", ")", "{", "return", "$", "this", "->", "default", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "values", ")", ")", "{", "return", "reset", "(", "$", "this", "->", "values", ")", ";", "}", "return", "null", ";", "}" ]
Get the default value @api @return string
[ "Get", "the", "default", "value" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ValuePickerFeature.php#L172-L181
steeffeen/FancyManiaLinks
FML/Script/Features/ValuePickerFeature.php
ValuePickerFeature.setDefault
public function setDefault($default) { $this->default = (string)$default; if ($this->default && !in_array($this->default, $this->values, true)) { $this->addValue($this->default); } return $this; }
php
public function setDefault($default) { $this->default = (string)$default; if ($this->default && !in_array($this->default, $this->values, true)) { $this->addValue($this->default); } return $this; }
[ "public", "function", "setDefault", "(", "$", "default", ")", "{", "$", "this", "->", "default", "=", "(", "string", ")", "$", "default", ";", "if", "(", "$", "this", "->", "default", "&&", "!", "in_array", "(", "$", "this", "->", "default", ",", "$", "this", "->", "values", ",", "true", ")", ")", "{", "$", "this", "->", "addValue", "(", "$", "this", "->", "default", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the default value @api @param string $default Default value @return static
[ "Set", "the", "default", "value" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ValuePickerFeature.php#L190-L197
steeffeen/FancyManiaLinks
FML/Script/Features/ValuePickerFeature.php
ValuePickerFeature.buildInitScriptText
protected function buildInitScriptText() { $labelId = Builder::getId($this->label); $entryId = Builder::EMPTY_STRING; if ($this->entry) { $entryId = Builder::getId($this->entry); } $values = Builder::getArray($this->values); $default = Builder::escapeText($this->getDefault()); return " declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel); declare " . self::VAR_PICKER_VALUES . " as Values for Label_Picker = Text[Integer]; Values = {$values}; declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker = \"\"; Default = {$default}; declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker = \"\"; EntryId = \"{$entryId}\"; " . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); "; }
php
protected function buildInitScriptText() { $labelId = Builder::getId($this->label); $entryId = Builder::EMPTY_STRING; if ($this->entry) { $entryId = Builder::getId($this->entry); } $values = Builder::getArray($this->values); $default = Builder::escapeText($this->getDefault()); return " declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel); declare " . self::VAR_PICKER_VALUES . " as Values for Label_Picker = Text[Integer]; Values = {$values}; declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker = \"\"; Default = {$default}; declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker = \"\"; EntryId = \"{$entryId}\"; " . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); "; }
[ "protected", "function", "buildInitScriptText", "(", ")", "{", "$", "labelId", "=", "Builder", "::", "getId", "(", "$", "this", "->", "label", ")", ";", "$", "entryId", "=", "Builder", "::", "EMPTY_STRING", ";", "if", "(", "$", "this", "->", "entry", ")", "{", "$", "entryId", "=", "Builder", "::", "getId", "(", "$", "this", "->", "entry", ")", ";", "}", "$", "values", "=", "Builder", "::", "getArray", "(", "$", "this", "->", "values", ")", ";", "$", "default", "=", "Builder", "::", "escapeText", "(", "$", "this", "->", "getDefault", "(", ")", ")", ";", "return", "\"\ndeclare Label_Picker <=> (Page.GetFirstChild(\\\"{$labelId}\\\") as CMlLabel);\ndeclare \"", ".", "self", "::", "VAR_PICKER_VALUES", ".", "\" as Values for Label_Picker = Text[Integer];\nValues = {$values};\ndeclare \"", ".", "self", "::", "VAR_PICKER_DEFAULT_VALUE", ".", "\" as Default for Label_Picker = \\\"\\\";\nDefault = {$default};\ndeclare \"", ".", "self", "::", "VAR_PICKER_ENTRY_ID", ".", "\" as EntryId for Label_Picker = \\\"\\\";\nEntryId = \\\"{$entryId}\\\";\n\"", ".", "self", "::", "FUNCTION_UPDATE_PICKER_VALUE", ".", "\"(Label_Picker);\n\"", ";", "}" ]
Build the init script text @return string
[ "Build", "the", "init", "script", "text" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ValuePickerFeature.php#L254-L275
krzysztofmazur/php-object-mapper
src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueWriter/PropertyValueWriter.php
PropertyValueWriter.writeValue
protected function writeValue($object, $value) { Reflection::getProperty(get_class($object), $this->propertyName)->setValue($object, $value); }
php
protected function writeValue($object, $value) { Reflection::getProperty(get_class($object), $this->propertyName)->setValue($object, $value); }
[ "protected", "function", "writeValue", "(", "$", "object", ",", "$", "value", ")", "{", "Reflection", "::", "getProperty", "(", "get_class", "(", "$", "object", ")", ",", "$", "this", "->", "propertyName", ")", "->", "setValue", "(", "$", "object", ",", "$", "value", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/krzysztofmazur/php-object-mapper/blob/2c22acad9634cfe8e9a75d72e665d450ada8d4e3/src/KrzysztofMazur/ObjectMapper/Mapping/Field/ValueWriter/PropertyValueWriter.php#L37-L40
Lansoweb/LosBase
src/LosBase/Controller/AbstractBaseController.php
AbstractBaseController.getActionRoute
public function getActionRoute($action = null) { if (null === $action) { $action = $this->getEvent() ->getRouteMatch() ->getParam('action'); } return $this->getRouteName().'/'.$action; }
php
public function getActionRoute($action = null) { if (null === $action) { $action = $this->getEvent() ->getRouteMatch() ->getParam('action'); } return $this->getRouteName().'/'.$action; }
[ "public", "function", "getActionRoute", "(", "$", "action", "=", "null", ")", "{", "if", "(", "null", "===", "$", "action", ")", "{", "$", "action", "=", "$", "this", "->", "getEvent", "(", ")", "->", "getRouteMatch", "(", ")", "->", "getParam", "(", "'action'", ")", ";", "}", "return", "$", "this", "->", "getRouteName", "(", ")", ".", "'/'", ".", "$", "action", ";", "}" ]
Retorna uma rota para a ação especificada ou a atual. @param string $action
[ "Retorna", "uma", "rota", "para", "a", "ação", "especificada", "ou", "a", "atual", "." ]
train
https://github.com/Lansoweb/LosBase/blob/90e18a53d29c1bd841c149dca43aa365eecc656d/src/LosBase/Controller/AbstractBaseController.php#L79-L88
VincentChalnot/SidusAdminBundle
Event/AdminControllerInjecter.php
AdminControllerInjecter.onKernelController
public function onKernelController(FilterControllerEvent $event): void { $controller = $event->getController(); if (\is_array($controller)) { [$controller] = $controller; // Ignoring action } if (!$controller instanceof AdminInjectableInterface && !$controller instanceof ActionInjectableInterface) { return; } $request = $event->getRequest(); if (!$request->attributes->has('_admin')) { $routeName = $request->attributes->get('_route'); $m = "Missing request attribute '_admin' for route {$routeName}, this means you declared"; $m .= ' this route outside the admin configuration, please use the admin configuration'; throw new \LogicException($m); } $admin = $request->attributes->get('_admin'); if (!$admin instanceof Admin) { throw new \UnexpectedValueException('_admin request attribute is not an Admin object'); } if ($controller instanceof AdminInjectableInterface) { $controller->setAdmin($admin); } if (!$request->attributes->has('_action')) { $routeName = $request->attributes->get('_route'); $m = "Missing request attribute '_action' for route {$routeName},"; $m .= 'this means you declared this route outside the admin configuration, please include the _action'; $m .= 'attribute in your route definition or use the admin configuration'; throw new \LogicException($m); } $admin->setCurrentAction($request->attributes->get('_action')); if ($controller instanceof ActionInjectableInterface) { $controller->setAction($admin->getCurrentAction()); } }
php
public function onKernelController(FilterControllerEvent $event): void { $controller = $event->getController(); if (\is_array($controller)) { [$controller] = $controller; // Ignoring action } if (!$controller instanceof AdminInjectableInterface && !$controller instanceof ActionInjectableInterface) { return; } $request = $event->getRequest(); if (!$request->attributes->has('_admin')) { $routeName = $request->attributes->get('_route'); $m = "Missing request attribute '_admin' for route {$routeName}, this means you declared"; $m .= ' this route outside the admin configuration, please use the admin configuration'; throw new \LogicException($m); } $admin = $request->attributes->get('_admin'); if (!$admin instanceof Admin) { throw new \UnexpectedValueException('_admin request attribute is not an Admin object'); } if ($controller instanceof AdminInjectableInterface) { $controller->setAdmin($admin); } if (!$request->attributes->has('_action')) { $routeName = $request->attributes->get('_route'); $m = "Missing request attribute '_action' for route {$routeName},"; $m .= 'this means you declared this route outside the admin configuration, please include the _action'; $m .= 'attribute in your route definition or use the admin configuration'; throw new \LogicException($m); } $admin->setCurrentAction($request->attributes->get('_action')); if ($controller instanceof ActionInjectableInterface) { $controller->setAction($admin->getCurrentAction()); } }
[ "public", "function", "onKernelController", "(", "FilterControllerEvent", "$", "event", ")", ":", "void", "{", "$", "controller", "=", "$", "event", "->", "getController", "(", ")", ";", "if", "(", "\\", "is_array", "(", "$", "controller", ")", ")", "{", "[", "$", "controller", "]", "=", "$", "controller", ";", "// Ignoring action", "}", "if", "(", "!", "$", "controller", "instanceof", "AdminInjectableInterface", "&&", "!", "$", "controller", "instanceof", "ActionInjectableInterface", ")", "{", "return", ";", "}", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "!", "$", "request", "->", "attributes", "->", "has", "(", "'_admin'", ")", ")", "{", "$", "routeName", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_route'", ")", ";", "$", "m", "=", "\"Missing request attribute '_admin' for route {$routeName}, this means you declared\"", ";", "$", "m", ".=", "' this route outside the admin configuration, please use the admin configuration'", ";", "throw", "new", "\\", "LogicException", "(", "$", "m", ")", ";", "}", "$", "admin", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_admin'", ")", ";", "if", "(", "!", "$", "admin", "instanceof", "Admin", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'_admin request attribute is not an Admin object'", ")", ";", "}", "if", "(", "$", "controller", "instanceof", "AdminInjectableInterface", ")", "{", "$", "controller", "->", "setAdmin", "(", "$", "admin", ")", ";", "}", "if", "(", "!", "$", "request", "->", "attributes", "->", "has", "(", "'_action'", ")", ")", "{", "$", "routeName", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_route'", ")", ";", "$", "m", "=", "\"Missing request attribute '_action' for route {$routeName},\"", ";", "$", "m", ".=", "'this means you declared this route outside the admin configuration, please include the _action'", ";", "$", "m", ".=", "'attribute in your route definition or use the admin configuration'", ";", "throw", "new", "\\", "LogicException", "(", "$", "m", ")", ";", "}", "$", "admin", "->", "setCurrentAction", "(", "$", "request", "->", "attributes", "->", "get", "(", "'_action'", ")", ")", ";", "if", "(", "$", "controller", "instanceof", "ActionInjectableInterface", ")", "{", "$", "controller", "->", "setAction", "(", "$", "admin", "->", "getCurrentAction", "(", ")", ")", ";", "}", "}" ]
@param FilterControllerEvent $event @throws \LogicException|\UnexpectedValueException|\InvalidArgumentException
[ "@param", "FilterControllerEvent", "$event" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Event/AdminControllerInjecter.php#L30-L68
alphayax/phpdoc_md
src/models/NamespaceMd.php
NamespaceMd.generateTree
public function generateTree( $pad = '', $relativePath = '') { $generatedMd = ''; /// SubPages if( ! empty( $this->subPages)){ foreach( $this->subPages as $subPageName => $subPage){ $subPageFile = './' . $relativePath . $subPageName . DIRECTORY_SEPARATOR . $subPage->getPageBfe(); $generatedMd .= "$pad- [$subPageName]($subPageFile)". PHP_EOL; $generatedMd .= $subPage->generateTree( $pad . ' ', $relativePath . $subPageName . DIRECTORY_SEPARATOR); } } /// Chapters if( ! empty( $this->classMds)){ foreach($this->classMds as $chapter){ $chapterName = $chapter->getReflexion()->getShortName(); $chapterFile = $relativePath . $this->getPageBfe(); $chapterAnchor = $chapterFile .'#'. $chapter->getReflexion()->getShortName(); $generatedMd .= "$pad- [$chapterName]($chapterAnchor)" . PHP_EOL; } } return $generatedMd; }
php
public function generateTree( $pad = '', $relativePath = '') { $generatedMd = ''; /// SubPages if( ! empty( $this->subPages)){ foreach( $this->subPages as $subPageName => $subPage){ $subPageFile = './' . $relativePath . $subPageName . DIRECTORY_SEPARATOR . $subPage->getPageBfe(); $generatedMd .= "$pad- [$subPageName]($subPageFile)". PHP_EOL; $generatedMd .= $subPage->generateTree( $pad . ' ', $relativePath . $subPageName . DIRECTORY_SEPARATOR); } } /// Chapters if( ! empty( $this->classMds)){ foreach($this->classMds as $chapter){ $chapterName = $chapter->getReflexion()->getShortName(); $chapterFile = $relativePath . $this->getPageBfe(); $chapterAnchor = $chapterFile .'#'. $chapter->getReflexion()->getShortName(); $generatedMd .= "$pad- [$chapterName]($chapterAnchor)" . PHP_EOL; } } return $generatedMd; }
[ "public", "function", "generateTree", "(", "$", "pad", "=", "''", ",", "$", "relativePath", "=", "''", ")", "{", "$", "generatedMd", "=", "''", ";", "/// SubPages", "if", "(", "!", "empty", "(", "$", "this", "->", "subPages", ")", ")", "{", "foreach", "(", "$", "this", "->", "subPages", "as", "$", "subPageName", "=>", "$", "subPage", ")", "{", "$", "subPageFile", "=", "'./'", ".", "$", "relativePath", ".", "$", "subPageName", ".", "DIRECTORY_SEPARATOR", ".", "$", "subPage", "->", "getPageBfe", "(", ")", ";", "$", "generatedMd", ".=", "\"$pad- [$subPageName]($subPageFile)\"", ".", "PHP_EOL", ";", "$", "generatedMd", ".=", "$", "subPage", "->", "generateTree", "(", "$", "pad", ".", "' '", ",", "$", "relativePath", ".", "$", "subPageName", ".", "DIRECTORY_SEPARATOR", ")", ";", "}", "}", "/// Chapters", "if", "(", "!", "empty", "(", "$", "this", "->", "classMds", ")", ")", "{", "foreach", "(", "$", "this", "->", "classMds", "as", "$", "chapter", ")", "{", "$", "chapterName", "=", "$", "chapter", "->", "getReflexion", "(", ")", "->", "getShortName", "(", ")", ";", "$", "chapterFile", "=", "$", "relativePath", ".", "$", "this", "->", "getPageBfe", "(", ")", ";", "$", "chapterAnchor", "=", "$", "chapterFile", ".", "'#'", ".", "$", "chapter", "->", "getReflexion", "(", ")", "->", "getShortName", "(", ")", ";", "$", "generatedMd", ".=", "\"$pad- [$chapterName]($chapterAnchor)\"", ".", "PHP_EOL", ";", "}", "}", "return", "$", "generatedMd", ";", "}" ]
Generate overview markdown tree @param string $pad @param string $relativePath @return string
[ "Generate", "overview", "markdown", "tree" ]
train
https://github.com/alphayax/phpdoc_md/blob/326da10b837161591a32ab4f36f9b2f4feabbe65/src/models/NamespaceMd.php#L73-L96
alphayax/phpdoc_md
src/models/NamespaceMd.php
NamespaceMd.write
public function write(){ $m = new \Mustache_Engine([ 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views') ]); $template = $m->loadTemplate('Page'); $generatedMd = $template->render( $this); $this->writeSubPages(); /// Write page @mkdir( $this->page_rd, 0777, true); file_put_contents( $this->page_rd . DIRECTORY_SEPARATOR . $this->page_bfe, $generatedMd); }
php
public function write(){ $m = new \Mustache_Engine([ 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views') ]); $template = $m->loadTemplate('Page'); $generatedMd = $template->render( $this); $this->writeSubPages(); /// Write page @mkdir( $this->page_rd, 0777, true); file_put_contents( $this->page_rd . DIRECTORY_SEPARATOR . $this->page_bfe, $generatedMd); }
[ "public", "function", "write", "(", ")", "{", "$", "m", "=", "new", "\\", "Mustache_Engine", "(", "[", "'loader'", "=>", "new", "\\", "Mustache_Loader_FilesystemLoader", "(", "__DIR__", ".", "'/../views'", ")", "]", ")", ";", "$", "template", "=", "$", "m", "->", "loadTemplate", "(", "'Page'", ")", ";", "$", "generatedMd", "=", "$", "template", "->", "render", "(", "$", "this", ")", ";", "$", "this", "->", "writeSubPages", "(", ")", ";", "/// Write page", "@", "mkdir", "(", "$", "this", "->", "page_rd", ",", "0777", ",", "true", ")", ";", "file_put_contents", "(", "$", "this", "->", "page_rd", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "page_bfe", ",", "$", "generatedMd", ")", ";", "}" ]
Write markdown file
[ "Write", "markdown", "file" ]
train
https://github.com/alphayax/phpdoc_md/blob/326da10b837161591a32ab4f36f9b2f4feabbe65/src/models/NamespaceMd.php#L101-L115
alphayax/phpdoc_md
src/models/NamespaceMd.php
NamespaceMd.writeSubPages
public function writeSubPages() { foreach( $this->subPages as $subPageName => $subPage) { $subPageDirectory = $this->page_rd . DIRECTORY_SEPARATOR . $subPageName; $subPage->setDirectory( $subPageDirectory); $subPage->write(); } }
php
public function writeSubPages() { foreach( $this->subPages as $subPageName => $subPage) { $subPageDirectory = $this->page_rd . DIRECTORY_SEPARATOR . $subPageName; $subPage->setDirectory( $subPageDirectory); $subPage->write(); } }
[ "public", "function", "writeSubPages", "(", ")", "{", "foreach", "(", "$", "this", "->", "subPages", "as", "$", "subPageName", "=>", "$", "subPage", ")", "{", "$", "subPageDirectory", "=", "$", "this", "->", "page_rd", ".", "DIRECTORY_SEPARATOR", ".", "$", "subPageName", ";", "$", "subPage", "->", "setDirectory", "(", "$", "subPageDirectory", ")", ";", "$", "subPage", "->", "write", "(", ")", ";", "}", "}" ]
Write sub pages of this page
[ "Write", "sub", "pages", "of", "this", "page" ]
train
https://github.com/alphayax/phpdoc_md/blob/326da10b837161591a32ab4f36f9b2f4feabbe65/src/models/NamespaceMd.php#L120-L126
JeanWolf/yii2-jrbac
src/JrbacMenuSearch.php
JrbacMenuSearch.search
public function search($params) { $query = static::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'pid' => $this->pid, 'sort_order' => $this->sort_order, 'status' => $this->status, ]); $query->andFilterWhere(['like', 'label', $this->label]) ->andFilterWhere(['like', 'url', $this->url]) ->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
php
public function search($params) { $query = static::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'pid' => $this->pid, 'sort_order' => $this->sort_order, 'status' => $this->status, ]); $query->andFilterWhere(['like', 'label', $this->label]) ->andFilterWhere(['like', 'url', $this->url]) ->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "static", "::", "find", "(", ")", ";", "// add conditions that should always apply here", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this", "->", "load", "(", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "// uncomment the following line if you do not want to return any records when validation fails", "// $query->where('0=1');", "return", "$", "dataProvider", ";", "}", "// grid filtering conditions", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'pid'", "=>", "$", "this", "->", "pid", ",", "'sort_order'", "=>", "$", "this", "->", "sort_order", ",", "'status'", "=>", "$", "this", "->", "status", ",", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'label'", ",", "$", "this", "->", "label", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'url'", ",", "$", "this", "->", "url", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'content'", ",", "$", "this", "->", "content", "]", ")", ";", "return", "$", "dataProvider", ";", "}" ]
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/src/JrbacMenuSearch.php#L26-L57
php-rise/rise
src/Middlewares/Locale.php
Locale.extractFromPath
public function extractFromPath(Closure $next) { $locale = $this->request->getUrlParam('locale'); if ($this->translation->hasLocale($locale)) { $this->translation->setLocale($locale); $next(); } else { $this->notFound(); } }
php
public function extractFromPath(Closure $next) { $locale = $this->request->getUrlParam('locale'); if ($this->translation->hasLocale($locale)) { $this->translation->setLocale($locale); $next(); } else { $this->notFound(); } }
[ "public", "function", "extractFromPath", "(", "Closure", "$", "next", ")", "{", "$", "locale", "=", "$", "this", "->", "request", "->", "getUrlParam", "(", "'locale'", ")", ";", "if", "(", "$", "this", "->", "translation", "->", "hasLocale", "(", "$", "locale", ")", ")", "{", "$", "this", "->", "translation", "->", "setLocale", "(", "$", "locale", ")", ";", "$", "next", "(", ")", ";", "}", "else", "{", "$", "this", "->", "notFound", "(", ")", ";", "}", "}" ]
Get locale from request url. To use it, you should put "{locale}" in the routes config. e.g.: $scope->get('/{locale}/products', 'App\Handlers\Handler'); or $scope->prefix('/{locale}'); @param \Closure $next
[ "Get", "locale", "from", "request", "url", ".", "To", "use", "it", "you", "should", "put", "{", "locale", "}", "in", "the", "routes", "config", "." ]
train
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Middlewares/Locale.php#L45-L53
userfriendly/SocialUserBundle
Model/UserIdentity.php
UserIdentity.setType
public function setType( $type ) { $this->type = is_int( $type ) ? $type : self::getStorableType( $type ); return $this; }
php
public function setType( $type ) { $this->type = is_int( $type ) ? $type : self::getStorableType( $type ); return $this; }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "$", "this", "->", "type", "=", "is_int", "(", "$", "type", ")", "?", "$", "type", ":", "self", "::", "getStorableType", "(", "$", "type", ")", ";", "return", "$", "this", ";", "}" ]
Set type @param integer $type @return \Userfriendly\Bundle\SocialUserBundle\Model\UserIdentity
[ "Set", "type" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/Model/UserIdentity.php#L80-L84
userfriendly/SocialUserBundle
Model/UserIdentity.php
UserIdentity.getReadableType
static public function getReadableType( $type ) { switch ( $type ) { case self::TYPE_GOOGLE: return 'google'; case self::TYPE_FACEBOOK: return 'facebook'; case self::TYPE_YAHOO: return 'yahoo'; case self::TYPE_TWITTER: return 'twitter'; } }
php
static public function getReadableType( $type ) { switch ( $type ) { case self::TYPE_GOOGLE: return 'google'; case self::TYPE_FACEBOOK: return 'facebook'; case self::TYPE_YAHOO: return 'yahoo'; case self::TYPE_TWITTER: return 'twitter'; } }
[ "static", "public", "function", "getReadableType", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "TYPE_GOOGLE", ":", "return", "'google'", ";", "case", "self", "::", "TYPE_FACEBOOK", ":", "return", "'facebook'", ";", "case", "self", "::", "TYPE_YAHOO", ":", "return", "'yahoo'", ";", "case", "self", "::", "TYPE_TWITTER", ":", "return", "'twitter'", ";", "}", "}" ]
Convert type to human-readable form @param integer $type @return string
[ "Convert", "type", "to", "human", "-", "readable", "form" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/Model/UserIdentity.php#L112-L121
userfriendly/SocialUserBundle
Model/UserIdentity.php
UserIdentity.getStorableType
static public function getStorableType( $type ) { switch ( $type ) { case 'google': return self::TYPE_GOOGLE; case 'facebook': return self::TYPE_FACEBOOK; case 'yahoo': return self::TYPE_YAHOO; case 'twitter': return self::TYPE_TWITTER; } }
php
static public function getStorableType( $type ) { switch ( $type ) { case 'google': return self::TYPE_GOOGLE; case 'facebook': return self::TYPE_FACEBOOK; case 'yahoo': return self::TYPE_YAHOO; case 'twitter': return self::TYPE_TWITTER; } }
[ "static", "public", "function", "getStorableType", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'google'", ":", "return", "self", "::", "TYPE_GOOGLE", ";", "case", "'facebook'", ":", "return", "self", "::", "TYPE_FACEBOOK", ";", "case", "'yahoo'", ":", "return", "self", "::", "TYPE_YAHOO", ";", "case", "'twitter'", ":", "return", "self", "::", "TYPE_TWITTER", ";", "}", "}" ]
Convert human-readable type to integer @param string $type @return integer
[ "Convert", "human", "-", "readable", "type", "to", "integer" ]
train
https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/Model/UserIdentity.php#L129-L138
aedart/laravel-helpers
src/Traits/Logging/PsrLogTrait.php
PsrLogTrait.getPsrLog
public function getPsrLog(): ?LoggerInterface { if (!$this->hasPsrLog()) { $this->setPsrLog($this->getDefaultPsrLog()); } return $this->psrLog; }
php
public function getPsrLog(): ?LoggerInterface { if (!$this->hasPsrLog()) { $this->setPsrLog($this->getDefaultPsrLog()); } return $this->psrLog; }
[ "public", "function", "getPsrLog", "(", ")", ":", "?", "LoggerInterface", "{", "if", "(", "!", "$", "this", "->", "hasPsrLog", "(", ")", ")", "{", "$", "this", "->", "setPsrLog", "(", "$", "this", "->", "getDefaultPsrLog", "(", ")", ")", ";", "}", "return", "$", "this", "->", "psrLog", ";", "}" ]
Get psr log If no psr log has been set, this method will set and return a default psr log, if any such value is available @see getDefaultPsrLog() @return LoggerInterface|null psr log or null if none psr log has been set
[ "Get", "psr", "log" ]
train
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Logging/PsrLogTrait.php#L53-L59
Double-Opt-in/php-client-api
src/Config/ClientConfig.php
ClientConfig.getAccessTokenCacheFile
public function getAccessTokenCacheFile() { if (empty($this->accessTokenCacheFile)) return null; return $this->accessTokenCacheFile . '_' . $this->siteToken() . '-' . $this->clientId(); }
php
public function getAccessTokenCacheFile() { if (empty($this->accessTokenCacheFile)) return null; return $this->accessTokenCacheFile . '_' . $this->siteToken() . '-' . $this->clientId(); }
[ "public", "function", "getAccessTokenCacheFile", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "accessTokenCacheFile", ")", ")", "return", "null", ";", "return", "$", "this", "->", "accessTokenCacheFile", ".", "'_'", ".", "$", "this", "->", "siteToken", "(", ")", ".", "'-'", ".", "$", "this", "->", "clientId", "(", ")", ";", "}" ]
returns AccessTokenCacheFile appended with site token and client id @return string
[ "returns", "AccessTokenCacheFile" ]
train
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Config/ClientConfig.php#L116-L122
Double-Opt-in/php-client-api
src/Config/ClientConfig.php
ClientConfig.setAccessTokenCacheFile
public function setAccessTokenCacheFile($accessTokenCacheFile) { if (is_dir($accessTokenCacheFile)) $accessTokenCacheFile .= DIRECTORY_SEPARATOR; $this->accessTokenCacheFile = $accessTokenCacheFile; return $this; }
php
public function setAccessTokenCacheFile($accessTokenCacheFile) { if (is_dir($accessTokenCacheFile)) $accessTokenCacheFile .= DIRECTORY_SEPARATOR; $this->accessTokenCacheFile = $accessTokenCacheFile; return $this; }
[ "public", "function", "setAccessTokenCacheFile", "(", "$", "accessTokenCacheFile", ")", "{", "if", "(", "is_dir", "(", "$", "accessTokenCacheFile", ")", ")", "$", "accessTokenCacheFile", ".=", "DIRECTORY_SEPARATOR", ";", "$", "this", "->", "accessTokenCacheFile", "=", "$", "accessTokenCacheFile", ";", "return", "$", "this", ";", "}" ]
sets accessTokenCacheFile @param string $accessTokenCacheFile @return $this
[ "sets", "accessTokenCacheFile" ]
train
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Config/ClientConfig.php#L131-L139
periaptio/empress-generator
src/Parser/FieldParser.php
FieldParser.generate
public function generate($table, $schema, $database) { $this->database = $database; $columns = $schema->listTableColumns($table); if (empty($columns)) { return false; } $indexParser = new IndexParser($table, $schema); $fields = $this->setEnum($this->getFields($columns, $indexParser), $table); $indexes = $this->getMultiFieldIndexes($indexParser); return array_merge($fields, $indexes); }
php
public function generate($table, $schema, $database) { $this->database = $database; $columns = $schema->listTableColumns($table); if (empty($columns)) { return false; } $indexParser = new IndexParser($table, $schema); $fields = $this->setEnum($this->getFields($columns, $indexParser), $table); $indexes = $this->getMultiFieldIndexes($indexParser); return array_merge($fields, $indexes); }
[ "public", "function", "generate", "(", "$", "table", ",", "$", "schema", ",", "$", "database", ")", "{", "$", "this", "->", "database", "=", "$", "database", ";", "$", "columns", "=", "$", "schema", "->", "listTableColumns", "(", "$", "table", ")", ";", "if", "(", "empty", "(", "$", "columns", ")", ")", "{", "return", "false", ";", "}", "$", "indexParser", "=", "new", "IndexParser", "(", "$", "table", ",", "$", "schema", ")", ";", "$", "fields", "=", "$", "this", "->", "setEnum", "(", "$", "this", "->", "getFields", "(", "$", "columns", ",", "$", "indexParser", ")", ",", "$", "table", ")", ";", "$", "indexes", "=", "$", "this", "->", "getMultiFieldIndexes", "(", "$", "indexParser", ")", ";", "return", "array_merge", "(", "$", "fields", ",", "$", "indexes", ")", ";", "}" ]
Create array of all the fields for a table @param string $table Table Name @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema @param string $database @return array|bool
[ "Create", "array", "of", "all", "the", "fields", "for", "a", "table" ]
train
https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Parser/FieldParser.php#L34-L46
SimonEast/Simple-Ansi-Colors
Ansi.php
Ansi.tagsToColors
public static function tagsToColors($string) { if (static::$enabled === null) { static::$enabled = !static::isWindows() || static::isAnsiCon(); } if (!static::$enabled) { // Strip tags (replace them with an empty string) return str_replace(array_keys(static::$tags), '', $string); } // We always add a <reset> at the end of each string so that any output following doesn't continue the same styling $string .= '<reset>'; return str_replace(array_keys(static::$tags), static::$tags, $string); }
php
public static function tagsToColors($string) { if (static::$enabled === null) { static::$enabled = !static::isWindows() || static::isAnsiCon(); } if (!static::$enabled) { // Strip tags (replace them with an empty string) return str_replace(array_keys(static::$tags), '', $string); } // We always add a <reset> at the end of each string so that any output following doesn't continue the same styling $string .= '<reset>'; return str_replace(array_keys(static::$tags), static::$tags, $string); }
[ "public", "static", "function", "tagsToColors", "(", "$", "string", ")", "{", "if", "(", "static", "::", "$", "enabled", "===", "null", ")", "{", "static", "::", "$", "enabled", "=", "!", "static", "::", "isWindows", "(", ")", "||", "static", "::", "isAnsiCon", "(", ")", ";", "}", "if", "(", "!", "static", "::", "$", "enabled", ")", "{", "// Strip tags (replace them with an empty string)", "return", "str_replace", "(", "array_keys", "(", "static", "::", "$", "tags", ")", ",", "''", ",", "$", "string", ")", ";", "}", "// We always add a <reset> at the end of each string so that any output following doesn't continue the same styling", "$", "string", ".=", "'<reset>'", ";", "return", "str_replace", "(", "array_keys", "(", "static", "::", "$", "tags", ")", ",", "static", "::", "$", "tags", ",", "$", "string", ")", ";", "}" ]
This is the primary function for converting tags to ANSI color codes (see the class description for the supported tags) For safety, this function always appends a <reset> at the end, otherwise the console may stick permanently in the colors you have used. @param string $string @return string
[ "This", "is", "the", "primary", "function", "for", "converting", "tags", "to", "ANSI", "color", "codes", "(", "see", "the", "class", "description", "for", "the", "supported", "tags", ")" ]
train
https://github.com/SimonEast/Simple-Ansi-Colors/blob/7b0abb5d779e25fffd26bcceb3d88278d1c064ed/Ansi.php#L97-L111
Lansoweb/LosReCaptcha
src/Captcha/Invisible.php
Invisible.isValid
public function isValid($value, $context = null) { if (empty($value)) { $this->error(self::MISSING_VALUE); return false; } $service = $this->getService(); $res = $service->verify($value); if (! $res) { $this->error(self::ERR_CAPTCHA); return false; } if (! $res->isSuccess()) { $this->error(self::BAD_CAPTCHA); return false; } return true; }
php
public function isValid($value, $context = null) { if (empty($value)) { $this->error(self::MISSING_VALUE); return false; } $service = $this->getService(); $res = $service->verify($value); if (! $res) { $this->error(self::ERR_CAPTCHA); return false; } if (! $res->isSuccess()) { $this->error(self::BAD_CAPTCHA); return false; } return true; }
[ "public", "function", "isValid", "(", "$", "value", ",", "$", "context", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "$", "this", "->", "error", "(", "self", "::", "MISSING_VALUE", ")", ";", "return", "false", ";", "}", "$", "service", "=", "$", "this", "->", "getService", "(", ")", ";", "$", "res", "=", "$", "service", "->", "verify", "(", "$", "value", ")", ";", "if", "(", "!", "$", "res", ")", "{", "$", "this", "->", "error", "(", "self", "::", "ERR_CAPTCHA", ")", ";", "return", "false", ";", "}", "if", "(", "!", "$", "res", "->", "isSuccess", "(", ")", ")", "{", "$", "this", "->", "error", "(", "self", "::", "BAD_CAPTCHA", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validate captcha @see \Zend\Validator\ValidatorInterface::isValid() @param mixed $value @param mixed $context @return bool
[ "Validate", "captcha" ]
train
https://github.com/Lansoweb/LosReCaptcha/blob/8df866995501db087c3850f97fd2b6547632e6ed/src/Captcha/Invisible.php#L117-L138
benmanu/silverstripe-knowledgebase
code/forms/KnowledgeBaseSearchForm.php
KnowledgeBaseSearchForm.doSearchKnowledgeBase
public function doSearchKnowledgeBase($data, $form) { if (!$this->kbPageId) { return $this->controller->redirectBack(); } $page = KnowledgebasePage::get()->byID($this->kbPageId); // just in case the page doesn't actually exist anymore if (!$page) { return $this->controller->redirectBack(); } // should either go to the results page or the landing page depending on if there is a query $link = (!empty($data['Query'])) ? sprintf('%s?q=%s', $page->AbsoluteLink(), strip_tags($data['Query'])) : $page->AbsoluteLink(); $this->extend('UpdateLink', $link, $data); return $this->controller->redirect($link); }
php
public function doSearchKnowledgeBase($data, $form) { if (!$this->kbPageId) { return $this->controller->redirectBack(); } $page = KnowledgebasePage::get()->byID($this->kbPageId); // just in case the page doesn't actually exist anymore if (!$page) { return $this->controller->redirectBack(); } // should either go to the results page or the landing page depending on if there is a query $link = (!empty($data['Query'])) ? sprintf('%s?q=%s', $page->AbsoluteLink(), strip_tags($data['Query'])) : $page->AbsoluteLink(); $this->extend('UpdateLink', $link, $data); return $this->controller->redirect($link); }
[ "public", "function", "doSearchKnowledgeBase", "(", "$", "data", ",", "$", "form", ")", "{", "if", "(", "!", "$", "this", "->", "kbPageId", ")", "{", "return", "$", "this", "->", "controller", "->", "redirectBack", "(", ")", ";", "}", "$", "page", "=", "KnowledgebasePage", "::", "get", "(", ")", "->", "byID", "(", "$", "this", "->", "kbPageId", ")", ";", "// just in case the page doesn't actually exist anymore", "if", "(", "!", "$", "page", ")", "{", "return", "$", "this", "->", "controller", "->", "redirectBack", "(", ")", ";", "}", "// should either go to the results page or the landing page depending on if there is a query", "$", "link", "=", "(", "!", "empty", "(", "$", "data", "[", "'Query'", "]", ")", ")", "?", "sprintf", "(", "'%s?q=%s'", ",", "$", "page", "->", "AbsoluteLink", "(", ")", ",", "strip_tags", "(", "$", "data", "[", "'Query'", "]", ")", ")", ":", "$", "page", "->", "AbsoluteLink", "(", ")", ";", "$", "this", "->", "extend", "(", "'UpdateLink'", ",", "$", "link", ",", "$", "data", ")", ";", "return", "$", "this", "->", "controller", "->", "redirect", "(", "$", "link", ")", ";", "}" ]
Handler for the form submission. @param array $data @param Form $form @return SS_HTTPResponse
[ "Handler", "for", "the", "form", "submission", "." ]
train
https://github.com/benmanu/silverstripe-knowledgebase/blob/db19bfd4836f43da17ab52e8b53e72a11be64210/code/forms/KnowledgeBaseSearchForm.php#L62-L83
2amigos/yiifoundation
helpers/Button.php
Button.button
public static function button($label = 'button', $htmlOptions = array()) { $htmlOptions = ArrayHelper::defaultValue('name', \CHtml::ID_PREFIX . \CHtml::$count++, $htmlOptions); Html::clientChange('click', $htmlOptions); return static::btn('button', $label, $htmlOptions); }
php
public static function button($label = 'button', $htmlOptions = array()) { $htmlOptions = ArrayHelper::defaultValue('name', \CHtml::ID_PREFIX . \CHtml::$count++, $htmlOptions); Html::clientChange('click', $htmlOptions); return static::btn('button', $label, $htmlOptions); }
[ "public", "static", "function", "button", "(", "$", "label", "=", "'button'", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "$", "htmlOptions", "=", "ArrayHelper", "::", "defaultValue", "(", "'name'", ",", "\\", "CHtml", "::", "ID_PREFIX", ".", "\\", "CHtml", "::", "$", "count", "++", ",", "$", "htmlOptions", ")", ";", "Html", "::", "clientChange", "(", "'click'", ",", "$", "htmlOptions", ")", ";", "return", "static", "::", "btn", "(", "'button'", ",", "$", "label", ",", "$", "htmlOptions", ")", ";", "}" ]
Generates a button @param string $label @param array $htmlOptions @return string the generated button.
[ "Generates", "a", "button" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Button.php#L28-L33
2amigos/yiifoundation
helpers/Button.php
Button.group
public static function group($buttons, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button-group', $htmlOptions); ob_start(); echo \CHtml::openTag('ul', $htmlOptions); foreach ($buttons as $button) { echo $button; } echo \CHtml::closeTag('ul'); return ob_get_clean(); }
php
public static function group($buttons, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button-group', $htmlOptions); ob_start(); echo \CHtml::openTag('ul', $htmlOptions); foreach ($buttons as $button) { echo $button; } echo \CHtml::closeTag('ul'); return ob_get_clean(); }
[ "public", "static", "function", "group", "(", "$", "buttons", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "'button-group'", ",", "$", "htmlOptions", ")", ";", "ob_start", "(", ")", ";", "echo", "\\", "CHtml", "::", "openTag", "(", "'ul'", ",", "$", "htmlOptions", ")", ";", "foreach", "(", "$", "buttons", "as", "$", "button", ")", "{", "echo", "$", "button", ";", "}", "echo", "\\", "CHtml", "::", "closeTag", "(", "'ul'", ")", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Generates a group of link buttons @param array $buttons the link buttons to render in a group @param array $htmlOptions @return string @see http://foundation.zurb.com/docs/components/button-groups.html
[ "Generates", "a", "group", "of", "link", "buttons" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Button.php#L54-L66
2amigos/yiifoundation
helpers/Button.php
Button.bar
public static function bar($groups, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button-bar', $htmlOptions); ob_start(); echo \CHtml::openTag('div', $htmlOptions); foreach ($groups as $group) { echo $group; } echo \CHtml::closeTag('div'); return ob_get_clean(); }
php
public static function bar($groups, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button-bar', $htmlOptions); ob_start(); echo \CHtml::openTag('div', $htmlOptions); foreach ($groups as $group) { echo $group; } echo \CHtml::closeTag('div'); return ob_get_clean(); }
[ "public", "static", "function", "bar", "(", "$", "groups", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "'button-bar'", ",", "$", "htmlOptions", ")", ";", "ob_start", "(", ")", ";", "echo", "\\", "CHtml", "::", "openTag", "(", "'div'", ",", "$", "htmlOptions", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "echo", "$", "group", ";", "}", "echo", "\\", "CHtml", "::", "closeTag", "(", "'div'", ")", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Generates a button bar by wrapping multiple button groups into a button-bar @param array $groups the button group to wrap @param array $htmlOptions @return string
[ "Generates", "a", "button", "bar", "by", "wrapping", "multiple", "button", "groups", "into", "a", "button", "-", "bar" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Button.php#L74-L86
2amigos/yiifoundation
helpers/Button.php
Button.btn
public static function btn($tag, $label, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button', $htmlOptions); $icon = ArrayHelper::removeValue($htmlOptions, 'icon'); if (isset($icon)) $label = Icon::icon($icon) . '&nbsp;' . $label; return \CHtml::tag($tag, $htmlOptions, $label); }
php
public static function btn($tag, $label, $htmlOptions = array()) { ArrayHelper::addValue('class', 'button', $htmlOptions); $icon = ArrayHelper::removeValue($htmlOptions, 'icon'); if (isset($icon)) $label = Icon::icon($icon) . '&nbsp;' . $label; return \CHtml::tag($tag, $htmlOptions, $label); }
[ "public", "static", "function", "btn", "(", "$", "tag", ",", "$", "label", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "'button'", ",", "$", "htmlOptions", ")", ";", "$", "icon", "=", "ArrayHelper", "::", "removeValue", "(", "$", "htmlOptions", ",", "'icon'", ")", ";", "if", "(", "isset", "(", "$", "icon", ")", ")", "$", "label", "=", "Icon", "::", "icon", "(", "$", "icon", ")", ".", "'&nbsp;'", ".", "$", "label", ";", "return", "\\", "CHtml", "::", "tag", "(", "$", "tag", ",", "$", "htmlOptions", ",", "$", "label", ")", ";", "}" ]
Generates a button. @param string $tag the HTML tag. @param string $label the button label text. @param array $htmlOptions additional HTML attributes. @return string the generated button.
[ "Generates", "a", "button", "." ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Button.php#L95-L104
2amigos/yiifoundation
helpers/Button.php
Button.dropdown
public static function dropdown($label, $list, $htmlOptions = array()) { $id = Enum::ID_PREFIX . '-' . Html::$count++; ArrayHelper::addValue('data-dropdown', $id, $htmlOptions); ArrayHelper::addValue('class', Enum::DROPDOWN, $htmlOptions); $dropHtmlOptions = ArrayHelper::removeValue($htmlOptions, 'dropHtmlOptions', array()); $dropHtmlOptions['id'] = $id; $dropHtmlOptions['data-dropdown-content'] = ''; ArrayHelper::addValue('class', Enum::DROPDOWN_LIST, $dropHtmlOptions); ob_start(); echo static::link($label, $htmlOptions); echo Dropdown::display( array( 'items' => $list, 'htmlOptions' => $dropHtmlOptions ) ); return ob_get_clean(); }
php
public static function dropdown($label, $list, $htmlOptions = array()) { $id = Enum::ID_PREFIX . '-' . Html::$count++; ArrayHelper::addValue('data-dropdown', $id, $htmlOptions); ArrayHelper::addValue('class', Enum::DROPDOWN, $htmlOptions); $dropHtmlOptions = ArrayHelper::removeValue($htmlOptions, 'dropHtmlOptions', array()); $dropHtmlOptions['id'] = $id; $dropHtmlOptions['data-dropdown-content'] = ''; ArrayHelper::addValue('class', Enum::DROPDOWN_LIST, $dropHtmlOptions); ob_start(); echo static::link($label, $htmlOptions); echo Dropdown::display( array( 'items' => $list, 'htmlOptions' => $dropHtmlOptions ) ); return ob_get_clean(); }
[ "public", "static", "function", "dropdown", "(", "$", "label", ",", "$", "list", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "$", "id", "=", "Enum", "::", "ID_PREFIX", ".", "'-'", ".", "Html", "::", "$", "count", "++", ";", "ArrayHelper", "::", "addValue", "(", "'data-dropdown'", ",", "$", "id", ",", "$", "htmlOptions", ")", ";", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "Enum", "::", "DROPDOWN", ",", "$", "htmlOptions", ")", ";", "$", "dropHtmlOptions", "=", "ArrayHelper", "::", "removeValue", "(", "$", "htmlOptions", ",", "'dropHtmlOptions'", ",", "array", "(", ")", ")", ";", "$", "dropHtmlOptions", "[", "'id'", "]", "=", "$", "id", ";", "$", "dropHtmlOptions", "[", "'data-dropdown-content'", "]", "=", "''", ";", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "Enum", "::", "DROPDOWN_LIST", ",", "$", "dropHtmlOptions", ")", ";", "ob_start", "(", ")", ";", "echo", "static", "::", "link", "(", "$", "label", ",", "$", "htmlOptions", ")", ";", "echo", "Dropdown", "::", "display", "(", "array", "(", "'items'", "=>", "$", "list", ",", "'htmlOptions'", "=>", "$", "dropHtmlOptions", ")", ")", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Generates a dropdown button. Important: This method does not formats your list items into links, you have to pass them as link tags. For a more flexible solution use the widget. @param string $label @param array $list of link items to be displayed on the dropdown menu @param array $htmlOptions the HTML attributes. It allows a special attribute `dropHtmlOptions` to set your custom attributes to the dropdown list. @return string
[ "Generates", "a", "dropdown", "button", ".", "Important", ":", "This", "method", "does", "not", "formats", "your", "list", "items", "into", "links", "you", "have", "to", "pass", "them", "as", "link", "tags", ".", "For", "a", "more", "flexible", "solution", "use", "the", "widget", "." ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Button.php#L116-L138
alanpich/slender
src/App.php
App.loadConfigDefaults
protected function loadConfigDefaults($userSettings) { $parser = $this['config-parser']; $defaults = $parser->parseFile(__DIR__ . '/slender.yml'); $userSettings = array_merge_recursive($defaults, $userSettings); $this['settings']->setArray($userSettings); }
php
protected function loadConfigDefaults($userSettings) { $parser = $this['config-parser']; $defaults = $parser->parseFile(__DIR__ . '/slender.yml'); $userSettings = array_merge_recursive($defaults, $userSettings); $this['settings']->setArray($userSettings); }
[ "protected", "function", "loadConfigDefaults", "(", "$", "userSettings", ")", "{", "$", "parser", "=", "$", "this", "[", "'config-parser'", "]", ";", "$", "defaults", "=", "$", "parser", "->", "parseFile", "(", "__DIR__", ".", "'/slender.yml'", ")", ";", "$", "userSettings", "=", "array_merge_recursive", "(", "$", "defaults", ",", "$", "userSettings", ")", ";", "$", "this", "[", "'settings'", "]", "->", "setArray", "(", "$", "userSettings", ")", ";", "}" ]
Load up config defaults This is a hardcoded config file within Slender core that sets up sane default values for config @var ConfigFileParserInterface $parser
[ "Load", "up", "config", "defaults" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/App.php#L91-L97
alanpich/slender
src/App.php
App.loadApplicationConfigFiles
protected function loadApplicationConfigFiles($userSettings) { $parser = $this['config-parser']; $loader = $this['config-finder']; $userSettings = array(); foreach ($loader->findFiles() as $path) { if (is_readable($path)) { $parsedFile = $parser->parseFile($path); if ($parsedFile !== false) { $this->addConfig($parsedFile); } } else { echo "Invalid path $path\n"; } } }
php
protected function loadApplicationConfigFiles($userSettings) { $parser = $this['config-parser']; $loader = $this['config-finder']; $userSettings = array(); foreach ($loader->findFiles() as $path) { if (is_readable($path)) { $parsedFile = $parser->parseFile($path); if ($parsedFile !== false) { $this->addConfig($parsedFile); } } else { echo "Invalid path $path\n"; } } }
[ "protected", "function", "loadApplicationConfigFiles", "(", "$", "userSettings", ")", "{", "$", "parser", "=", "$", "this", "[", "'config-parser'", "]", ";", "$", "loader", "=", "$", "this", "[", "'config-finder'", "]", ";", "$", "userSettings", "=", "array", "(", ")", ";", "foreach", "(", "$", "loader", "->", "findFiles", "(", ")", "as", "$", "path", ")", "{", "if", "(", "is_readable", "(", "$", "path", ")", ")", "{", "$", "parsedFile", "=", "$", "parser", "->", "parseFile", "(", "$", "path", ")", ";", "if", "(", "$", "parsedFile", "!==", "false", ")", "{", "$", "this", "->", "addConfig", "(", "$", "parsedFile", ")", ";", "}", "}", "else", "{", "echo", "\"Invalid path $path\\n\"", ";", "}", "}", "}" ]
Load any application config files @var ConfigFileFinderInterface $loader
[ "Load", "any", "application", "config", "files" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/App.php#L104-L119
alanpich/slender
src/App.php
App.registerService
public function registerService($service, $class) { $this[$service] = function ($app) use ($class) { $inst = new $class; if ($inst instanceof FactoryInterface) { return $inst->create($app); } else { return $inst; } }; }
php
public function registerService($service, $class) { $this[$service] = function ($app) use ($class) { $inst = new $class; if ($inst instanceof FactoryInterface) { return $inst->create($app); } else { return $inst; } }; }
[ "public", "function", "registerService", "(", "$", "service", ",", "$", "class", ")", "{", "$", "this", "[", "$", "service", "]", "=", "function", "(", "$", "app", ")", "use", "(", "$", "class", ")", "{", "$", "inst", "=", "new", "$", "class", ";", "if", "(", "$", "inst", "instanceof", "FactoryInterface", ")", "{", "return", "$", "inst", "->", "create", "(", "$", "app", ")", ";", "}", "else", "{", "return", "$", "inst", ";", "}", "}", ";", "}" ]
Register a Service to the DI container. Services are singletons, and the same instance is returned every time the identifier is requested @param string $service identifier @param string $class Class to create
[ "Register", "a", "Service", "to", "the", "DI", "container", ".", "Services", "are", "singletons", "and", "the", "same", "instance", "is", "returned", "every", "time", "the", "identifier", "is", "requested" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/App.php#L129-L139
alanpich/slender
src/App.php
App.registerFactory
public function registerFactory($factory, $class) { $this[$factory] = $this->factory(function ($app) use ($class) { $obj = new $class; if ($obj instanceof FactoryInterface) { return $obj->create($app); } else { return $obj; } }); }
php
public function registerFactory($factory, $class) { $this[$factory] = $this->factory(function ($app) use ($class) { $obj = new $class; if ($obj instanceof FactoryInterface) { return $obj->create($app); } else { return $obj; } }); }
[ "public", "function", "registerFactory", "(", "$", "factory", ",", "$", "class", ")", "{", "$", "this", "[", "$", "factory", "]", "=", "$", "this", "->", "factory", "(", "function", "(", "$", "app", ")", "use", "(", "$", "class", ")", "{", "$", "obj", "=", "new", "$", "class", ";", "if", "(", "$", "obj", "instanceof", "FactoryInterface", ")", "{", "return", "$", "obj", "->", "create", "(", "$", "app", ")", ";", "}", "else", "{", "return", "$", "obj", ";", "}", "}", ")", ";", "}" ]
Register a Factory to the DI container. Factories return a new instance of a class each time they are called @param string $factory identifier @param string $class Class to create
[ "Register", "a", "Factory", "to", "the", "DI", "container", ".", "Factories", "return", "a", "new", "instance", "of", "a", "class", "each", "time", "they", "are", "called" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/App.php#L149-L159
alanpich/slender
src/App.php
App.registerCoreServices
protected function registerCoreServices() { $this['util'] = function ($app) { return new \Slender\Core\Util\Util(); }; $this->registerService('dependency-injector','Slender\Core\DependencyInjector\Factory'); $this->registerService('autoloader', 'Slender\Core\Autoloader\AutoloaderFactory'); $this->registerService('autoloader.psr4', 'Slender\Core\Autoloader\PSR4Factory'); /** * The configParser is used to translate various file * formats into PHP arrays * * @var ConfigFileParserInterface * @return \Slender\Core\ConfigParser\Stack */ $this['config-parser'] = function () { return new ConfigParser\Stack(array( 'yml' => new ConfigParser\YAML, 'php' => new ConfigParser\PHP, 'json' => new ConfigParser\JSON, )); }; /** * ConfigFinder is responsible for finding, loading and merging * configuration files * * @var ConfigFileFinderInterface * @return ConfigFileFinderInterface */ $this['config-finder'] = function ($app) { $configLoader = new \Slender\Core\ConfigFinder\ConfigFinder( $this['settings']['config']['autoload'], $this['settings']['config']['files'] ); return $configLoader; }; /** * ModuleResolver is used for tracking down a module's path * from it's name * * @var ModuleResolverInterface * @return \Slender\Core\ModuleResolver\ResolverStack */ $this['module-resolver'] = function ($app) { $stack = new ResolverStack(new NamespaceResolver); $stack->setConfigParser($app['config-parser']); foreach ($this['settings']['modulePaths'] as $path) { if (is_readable($path)) { $stack->prependResolver(new DirectoryResolver($path)); } } return $stack; }; /** * ModuleLoader is used to load modules & their dependencies, * registering services & routes etc along the way * * @var ModuleLoaderInterface * @param \Slender\App $app * @return ModuleLoaderInterface */ $this->registerService('module-loader', 'Slender\Core\ModuleLoader\Factory'); }
php
protected function registerCoreServices() { $this['util'] = function ($app) { return new \Slender\Core\Util\Util(); }; $this->registerService('dependency-injector','Slender\Core\DependencyInjector\Factory'); $this->registerService('autoloader', 'Slender\Core\Autoloader\AutoloaderFactory'); $this->registerService('autoloader.psr4', 'Slender\Core\Autoloader\PSR4Factory'); /** * The configParser is used to translate various file * formats into PHP arrays * * @var ConfigFileParserInterface * @return \Slender\Core\ConfigParser\Stack */ $this['config-parser'] = function () { return new ConfigParser\Stack(array( 'yml' => new ConfigParser\YAML, 'php' => new ConfigParser\PHP, 'json' => new ConfigParser\JSON, )); }; /** * ConfigFinder is responsible for finding, loading and merging * configuration files * * @var ConfigFileFinderInterface * @return ConfigFileFinderInterface */ $this['config-finder'] = function ($app) { $configLoader = new \Slender\Core\ConfigFinder\ConfigFinder( $this['settings']['config']['autoload'], $this['settings']['config']['files'] ); return $configLoader; }; /** * ModuleResolver is used for tracking down a module's path * from it's name * * @var ModuleResolverInterface * @return \Slender\Core\ModuleResolver\ResolverStack */ $this['module-resolver'] = function ($app) { $stack = new ResolverStack(new NamespaceResolver); $stack->setConfigParser($app['config-parser']); foreach ($this['settings']['modulePaths'] as $path) { if (is_readable($path)) { $stack->prependResolver(new DirectoryResolver($path)); } } return $stack; }; /** * ModuleLoader is used to load modules & their dependencies, * registering services & routes etc along the way * * @var ModuleLoaderInterface * @param \Slender\App $app * @return ModuleLoaderInterface */ $this->registerService('module-loader', 'Slender\Core\ModuleLoader\Factory'); }
[ "protected", "function", "registerCoreServices", "(", ")", "{", "$", "this", "[", "'util'", "]", "=", "function", "(", "$", "app", ")", "{", "return", "new", "\\", "Slender", "\\", "Core", "\\", "Util", "\\", "Util", "(", ")", ";", "}", ";", "$", "this", "->", "registerService", "(", "'dependency-injector'", ",", "'Slender\\Core\\DependencyInjector\\Factory'", ")", ";", "$", "this", "->", "registerService", "(", "'autoloader'", ",", "'Slender\\Core\\Autoloader\\AutoloaderFactory'", ")", ";", "$", "this", "->", "registerService", "(", "'autoloader.psr4'", ",", "'Slender\\Core\\Autoloader\\PSR4Factory'", ")", ";", "/**\n * The configParser is used to translate various file\n * formats into PHP arrays\n *\n * @var ConfigFileParserInterface\n * @return \\Slender\\Core\\ConfigParser\\Stack\n */", "$", "this", "[", "'config-parser'", "]", "=", "function", "(", ")", "{", "return", "new", "ConfigParser", "\\", "Stack", "(", "array", "(", "'yml'", "=>", "new", "ConfigParser", "\\", "YAML", ",", "'php'", "=>", "new", "ConfigParser", "\\", "PHP", ",", "'json'", "=>", "new", "ConfigParser", "\\", "JSON", ",", ")", ")", ";", "}", ";", "/**\n * ConfigFinder is responsible for finding, loading and merging\n * configuration files\n *\n * @var ConfigFileFinderInterface\n * @return ConfigFileFinderInterface\n */", "$", "this", "[", "'config-finder'", "]", "=", "function", "(", "$", "app", ")", "{", "$", "configLoader", "=", "new", "\\", "Slender", "\\", "Core", "\\", "ConfigFinder", "\\", "ConfigFinder", "(", "$", "this", "[", "'settings'", "]", "[", "'config'", "]", "[", "'autoload'", "]", ",", "$", "this", "[", "'settings'", "]", "[", "'config'", "]", "[", "'files'", "]", ")", ";", "return", "$", "configLoader", ";", "}", ";", "/**\n * ModuleResolver is used for tracking down a module's path\n * from it's name\n *\n * @var ModuleResolverInterface\n * @return \\Slender\\Core\\ModuleResolver\\ResolverStack\n */", "$", "this", "[", "'module-resolver'", "]", "=", "function", "(", "$", "app", ")", "{", "$", "stack", "=", "new", "ResolverStack", "(", "new", "NamespaceResolver", ")", ";", "$", "stack", "->", "setConfigParser", "(", "$", "app", "[", "'config-parser'", "]", ")", ";", "foreach", "(", "$", "this", "[", "'settings'", "]", "[", "'modulePaths'", "]", "as", "$", "path", ")", "{", "if", "(", "is_readable", "(", "$", "path", ")", ")", "{", "$", "stack", "->", "prependResolver", "(", "new", "DirectoryResolver", "(", "$", "path", ")", ")", ";", "}", "}", "return", "$", "stack", ";", "}", ";", "/**\n * ModuleLoader is used to load modules & their dependencies,\n * registering services & routes etc along the way\n *\n * @var ModuleLoaderInterface\n * @param \\Slender\\App $app\n * @return ModuleLoaderInterface\n */", "$", "this", "->", "registerService", "(", "'module-loader'", ",", "'Slender\\Core\\ModuleLoader\\Factory'", ")", ";", "}" ]
Registers core services to the IoC Container
[ "Registers", "core", "services", "to", "the", "IoC", "Container" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/App.php#L236-L311