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
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/FeaturedImageProcessing/FeaturedImageProcessing.php
FeaturedImageProcessing.validateFeaturedImageServer
public function validateFeaturedImageServer($featuredImageServer) { // if there is no featured_image_server, then there is no featured image -- which is ok if ((!$featuredImageServer) || ($featuredImageServer == "") ) { return "passed"; } // not acceptable file extension if (!$this->isImageFileExtensionKosher($featuredImageServer)) { return "The image file you selected on your server, ".$featuredImageServer.", is not an accepted image file type."; } // file NOT already exists on the server if (!$this->doesImageFileExistOnServer($featuredImageServer)) { return "The image file you selected on your server, ".$featuredImageServer.", does NOT actually exist on the server."; } return "passed"; }
php
public function validateFeaturedImageServer($featuredImageServer) { // if there is no featured_image_server, then there is no featured image -- which is ok if ((!$featuredImageServer) || ($featuredImageServer == "") ) { return "passed"; } // not acceptable file extension if (!$this->isImageFileExtensionKosher($featuredImageServer)) { return "The image file you selected on your server, ".$featuredImageServer.", is not an accepted image file type."; } // file NOT already exists on the server if (!$this->doesImageFileExistOnServer($featuredImageServer)) { return "The image file you selected on your server, ".$featuredImageServer.", does NOT actually exist on the server."; } return "passed"; }
[ "public", "function", "validateFeaturedImageServer", "(", "$", "featuredImageServer", ")", "{", "// if there is no featured_image_server, then there is no featured image -- which is ok", "if", "(", "(", "!", "$", "featuredImageServer", ")", "||", "(", "$", "featuredImageServer", "==", "\"\"", ")", ")", "{", "return", "\"passed\"", ";", "}", "// not acceptable file extension", "if", "(", "!", "$", "this", "->", "isImageFileExtensionKosher", "(", "$", "featuredImageServer", ")", ")", "{", "return", "\"The image file you selected on your server, \"", ".", "$", "featuredImageServer", ".", "\", is not an accepted image file type.\"", ";", "}", "// file NOT already exists on the server", "if", "(", "!", "$", "this", "->", "doesImageFileExistOnServer", "(", "$", "featuredImageServer", ")", ")", "{", "return", "\"The image file you selected on your server, \"", ".", "$", "featuredImageServer", ".", "\", does NOT actually exist on the server.\"", ";", "}", "return", "\"passed\"", ";", "}" ]
Validate the featured_image_server field's data @param string $featuredImageServer The featured_image_server form field's value @return string "passed", or an error message
[ "Validate", "the", "featured_image_server", "field", "s", "data" ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/FeaturedImageProcessing/FeaturedImageProcessing.php#L201-L219
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/FeaturedImageProcessing/FeaturedImageProcessing.php
FeaturedImageProcessing.isImageFileExtensionKosher
public function isImageFileExtensionKosher($filename) { // must have acceptable file extension $imageFileExtension = $this->ImagesHelper->filenameWithExtensionOnly($filename); $haystack = Config::get('lasallecmsfrontend.acceptable_image_extensions_for_uploading'); if (in_array(strtolower($imageFileExtension), $haystack)) { return true; } return false; }
php
public function isImageFileExtensionKosher($filename) { // must have acceptable file extension $imageFileExtension = $this->ImagesHelper->filenameWithExtensionOnly($filename); $haystack = Config::get('lasallecmsfrontend.acceptable_image_extensions_for_uploading'); if (in_array(strtolower($imageFileExtension), $haystack)) { return true; } return false; }
[ "public", "function", "isImageFileExtensionKosher", "(", "$", "filename", ")", "{", "// must have acceptable file extension", "$", "imageFileExtension", "=", "$", "this", "->", "ImagesHelper", "->", "filenameWithExtensionOnly", "(", "$", "filename", ")", ";", "$", "haystack", "=", "Config", "::", "get", "(", "'lasallecmsfrontend.acceptable_image_extensions_for_uploading'", ")", ";", "if", "(", "in_array", "(", "strtolower", "(", "$", "imageFileExtension", ")", ",", "$", "haystack", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Is the image's extension allowed? @param string $filename The image's filename @return bool
[ "Is", "the", "image", "s", "extension", "allowed?" ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/FeaturedImageProcessing/FeaturedImageProcessing.php#L238-L250
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/FeaturedImageProcessing/FeaturedImageProcessing.php
FeaturedImageProcessing.doesImageFileExistOnServer
public function doesImageFileExistOnServer($filename) { if (\File::exists($this->ImagesHelper->pathOfImagesUploadParentFolder() . "/" . Config::get('lasallecmsfrontend.images_folder_uploaded'). '/'. $filename)) { return true; } return false; }
php
public function doesImageFileExistOnServer($filename) { if (\File::exists($this->ImagesHelper->pathOfImagesUploadParentFolder() . "/" . Config::get('lasallecmsfrontend.images_folder_uploaded'). '/'. $filename)) { return true; } return false; }
[ "public", "function", "doesImageFileExistOnServer", "(", "$", "filename", ")", "{", "if", "(", "\\", "File", "::", "exists", "(", "$", "this", "->", "ImagesHelper", "->", "pathOfImagesUploadParentFolder", "(", ")", ".", "\"/\"", ".", "Config", "::", "get", "(", "'lasallecmsfrontend.images_folder_uploaded'", ")", ".", "'/'", ".", "$", "filename", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Does the iamge file exist already on the server? @param string $filename The image's filename @return bool
[ "Does", "the", "iamge", "file", "exist", "already", "on", "the", "server?" ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/FeaturedImageProcessing/FeaturedImageProcessing.php#L258-L264
lasallecms/lasallecms-l5-lasallecmsapi-pkg
src/FeaturedImageProcessing/FeaturedImageProcessing.php
FeaturedImageProcessing.moveFile
public function moveFile($filename) { $destinationPath = $this->ImagesHelper->pathOfImagesUploadParentFolder() . "/" . Config::get('lasallecmsfrontend.images_folder_uploaded'); \Input::file('featured_image_upload')->move($destinationPath, $filename); }
php
public function moveFile($filename) { $destinationPath = $this->ImagesHelper->pathOfImagesUploadParentFolder() . "/" . Config::get('lasallecmsfrontend.images_folder_uploaded'); \Input::file('featured_image_upload')->move($destinationPath, $filename); }
[ "public", "function", "moveFile", "(", "$", "filename", ")", "{", "$", "destinationPath", "=", "$", "this", "->", "ImagesHelper", "->", "pathOfImagesUploadParentFolder", "(", ")", ".", "\"/\"", ".", "Config", "::", "get", "(", "'lasallecmsfrontend.images_folder_uploaded'", ")", ";", "\\", "Input", "::", "file", "(", "'featured_image_upload'", ")", "->", "move", "(", "$", "destinationPath", ",", "$", "filename", ")", ";", "}" ]
Move the uploaded file from the tmp folder to its proper destination folder @param string $filename The image's filename @return null
[ "Move", "the", "uploaded", "file", "from", "the", "tmp", "folder", "to", "its", "proper", "destination", "folder" ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/FeaturedImageProcessing/FeaturedImageProcessing.php#L277-L282
itiqiti/dev-lib
src/Extension/Core/Command/InfoCommand.php
InfoCommand.execute
public function execute(array $args = [], array $options = []) { $path = getcwd().'/README.md'; $this->writeln($this->replaceVars("Project <info>{{project_name}}</info> <comment>({{project_group}})</comment>", $this->getConfig())); $this->writeln(); if (is_file($path)) { readfile($path); } }
php
public function execute(array $args = [], array $options = []) { $path = getcwd().'/README.md'; $this->writeln($this->replaceVars("Project <info>{{project_name}}</info> <comment>({{project_group}})</comment>", $this->getConfig())); $this->writeln(); if (is_file($path)) { readfile($path); } }
[ "public", "function", "execute", "(", "array", "$", "args", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "path", "=", "getcwd", "(", ")", ".", "'/README.md'", ";", "$", "this", "->", "writeln", "(", "$", "this", "->", "replaceVars", "(", "\"Project <info>{{project_name}}</info> <comment>({{project_group}})</comment>\"", ",", "$", "this", "->", "getConfig", "(", ")", ")", ")", ";", "$", "this", "->", "writeln", "(", ")", ";", "if", "(", "is_file", "(", "$", "path", ")", ")", "{", "readfile", "(", "$", "path", ")", ";", "}", "}" ]
@param array $args @param array $options @return void
[ "@param", "array", "$args", "@param", "array", "$options" ]
train
https://github.com/itiqiti/dev-lib/blob/6f99f9332270095e072e75fd9f3a6c7e1d2cb7d8/src/Extension/Core/Command/InfoCommand.php#L25-L35
Ydle/HubBundle
Entity/RoomType.php
RoomType.addRoom
public function addRoom(\Ydle\HubBundle\Entity\Room $rooms) { $this->rooms[] = $rooms; return $this; }
php
public function addRoom(\Ydle\HubBundle\Entity\Room $rooms) { $this->rooms[] = $rooms; return $this; }
[ "public", "function", "addRoom", "(", "\\", "Ydle", "\\", "HubBundle", "\\", "Entity", "\\", "Room", "$", "rooms", ")", "{", "$", "this", "->", "rooms", "[", "]", "=", "$", "rooms", ";", "return", "$", "this", ";", "}" ]
Add rooms @param \Ydle\HubBundle\Entity\Room $rooms @return RoomType
[ "Add", "rooms" ]
train
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Entity/RoomType.php#L187-L192
Ydle/HubBundle
Entity/RoomType.php
RoomType.removeRoom
public function removeRoom(\Ydle\HubBundle\Entity\Room $rooms) { $this->rooms->removeElement($rooms); }
php
public function removeRoom(\Ydle\HubBundle\Entity\Room $rooms) { $this->rooms->removeElement($rooms); }
[ "public", "function", "removeRoom", "(", "\\", "Ydle", "\\", "HubBundle", "\\", "Entity", "\\", "Room", "$", "rooms", ")", "{", "$", "this", "->", "rooms", "->", "removeElement", "(", "$", "rooms", ")", ";", "}" ]
Remove rooms @param \Ydle\HubBundle\Entity\Room $rooms
[ "Remove", "rooms" ]
train
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Entity/RoomType.php#L199-L202
Ydle/HubBundle
Entity/RoomType.php
RoomType.toArray
public function toArray() { return array( 'id' => $this->getId(), 'name' => $this->getName(), 'description' => $this->getDescription(), 'is_active' => $this->getIsActive(), 'nb_rooms' => $this->getRooms()->count() ); }
php
public function toArray() { return array( 'id' => $this->getId(), 'name' => $this->getName(), 'description' => $this->getDescription(), 'is_active' => $this->getIsActive(), 'nb_rooms' => $this->getRooms()->count() ); }
[ "public", "function", "toArray", "(", ")", "{", "return", "array", "(", "'id'", "=>", "$", "this", "->", "getId", "(", ")", ",", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'description'", "=>", "$", "this", "->", "getDescription", "(", ")", ",", "'is_active'", "=>", "$", "this", "->", "getIsActive", "(", ")", ",", "'nb_rooms'", "=>", "$", "this", "->", "getRooms", "(", ")", "->", "count", "(", ")", ")", ";", "}" ]
Custom toArray classe @return array
[ "Custom", "toArray", "classe" ]
train
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Entity/RoomType.php#L275-L284
xmlscript/srv
api.php
api.query2parameters
final private function query2parameters(string $method, array $args):\Generator{#{{{ if($method && $args && method_exists($this,$method)) foreach((new \ReflectionMethod($this,$method))->getParameters() as $param){ $name = strtolower($param->name); if(isset($args[$name])){ [$type,$allowsNull] = [(string)$param->getType(), $param->allowsNull()]; if($param->isVariadic()){ if(is_array($args[$name])) foreach($args[$name] as $v) yield from $this->check($type, $v, $name, $allowsNull); else//可变长参数,变通一下,允许不使用数组形式,而直接临时使用标量 yield from $this->check($type, $args[$name], $name, $allowsNull); }else{//必然string yield from $this->check($type, $args[$name], $name, $allowsNull); } }elseif($param->isOptional() && $param->isDefaultValueAvailable()) yield $param->getDefaultValue(); else throw new \InvalidArgumentException("缺少必要的查询参数{$name}",400); } }
php
final private function query2parameters(string $method, array $args):\Generator{#{{{ if($method && $args && method_exists($this,$method)) foreach((new \ReflectionMethod($this,$method))->getParameters() as $param){ $name = strtolower($param->name); if(isset($args[$name])){ [$type,$allowsNull] = [(string)$param->getType(), $param->allowsNull()]; if($param->isVariadic()){ if(is_array($args[$name])) foreach($args[$name] as $v) yield from $this->check($type, $v, $name, $allowsNull); else//可变长参数,变通一下,允许不使用数组形式,而直接临时使用标量 yield from $this->check($type, $args[$name], $name, $allowsNull); }else{//必然string yield from $this->check($type, $args[$name], $name, $allowsNull); } }elseif($param->isOptional() && $param->isDefaultValueAvailable()) yield $param->getDefaultValue(); else throw new \InvalidArgumentException("缺少必要的查询参数{$name}",400); } }
[ "final", "private", "function", "query2parameters", "(", "string", "$", "method", ",", "array", "$", "args", ")", ":", "\\", "Generator", "{", "#{{{", "if", "(", "$", "method", "&&", "$", "args", "&&", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "foreach", "(", "(", "new", "\\", "ReflectionMethod", "(", "$", "this", ",", "$", "method", ")", ")", "->", "getParameters", "(", ")", "as", "$", "param", ")", "{", "$", "name", "=", "strtolower", "(", "$", "param", "->", "name", ")", ";", "if", "(", "isset", "(", "$", "args", "[", "$", "name", "]", ")", ")", "{", "[", "$", "type", ",", "$", "allowsNull", "]", "=", "[", "(", "string", ")", "$", "param", "->", "getType", "(", ")", ",", "$", "param", "->", "allowsNull", "(", ")", "]", ";", "if", "(", "$", "param", "->", "isVariadic", "(", ")", ")", "{", "if", "(", "is_array", "(", "$", "args", "[", "$", "name", "]", ")", ")", "foreach", "(", "$", "args", "[", "$", "name", "]", "as", "$", "v", ")", "yield", "from", "$", "this", "->", "check", "(", "$", "type", ",", "$", "v", ",", "$", "name", ",", "$", "allowsNull", ")", ";", "else", "//可变长参数,变通一下,允许不使用数组形式,而直接临时使用标量", "yield", "from", "$", "this", "->", "check", "(", "$", "type", ",", "$", "args", "[", "$", "name", "]", ",", "$", "name", ",", "$", "allowsNull", ")", ";", "}", "else", "{", "//必然string", "yield", "from", "$", "this", "->", "check", "(", "$", "type", ",", "$", "args", "[", "$", "name", "]", ",", "$", "name", ",", "$", "allowsNull", ")", ";", "}", "}", "elseif", "(", "$", "param", "->", "isOptional", "(", ")", "&&", "$", "param", "->", "isDefaultValueAvailable", "(", ")", ")", "yield", "$", "param", "->", "getDefaultValue", "(", ")", ";", "else", "throw", "new", "\\", "InvalidArgumentException", "(", "\"缺少必要的查询参数{$name}\",400);", "", "", "", "", "}", "}" ]
#}}}
[ "#", "}}}" ]
train
https://github.com/xmlscript/srv/blob/64e28952d95b16b8ba43809a5593023b0ca81ace/api.php#L72-L92
xmlscript/srv
api.php
api.&
final private function &parse(string $doc):array{#{{{ //header('Content-Type: text/html;charset=utf-8'); preg_match_all('#@([a-zA-Z]+)\s*([a-zA-Z0-9, ()_].*)#', $doc, $matches, PREG_SET_ORDER); $arr = []; foreach($matches as $item){ } array_walk($matches, function(&$v){ $v = ['tag'=>$v[1],'value'=>$v[2]]; }); return $matches; }
php
final private function &parse(string $doc):array{#{{{ //header('Content-Type: text/html;charset=utf-8'); preg_match_all('#@([a-zA-Z]+)\s*([a-zA-Z0-9, ()_].*)#', $doc, $matches, PREG_SET_ORDER); $arr = []; foreach($matches as $item){ } array_walk($matches, function(&$v){ $v = ['tag'=>$v[1],'value'=>$v[2]]; }); return $matches; }
[ "final", "private", "function", "&", "parse", "(", "string", "$", "doc", ")", ":", "array", "{", "#{{{", "//header('Content-Type: text/html;charset=utf-8');", "preg_match_all", "(", "'#@([a-zA-Z]+)\\s*([a-zA-Z0-9, ()_].*)#'", ",", "$", "doc", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ";", "$", "arr", "=", "[", "]", ";", "foreach", "(", "$", "matches", "as", "$", "item", ")", "{", "}", "array_walk", "(", "$", "matches", ",", "function", "(", "&", "$", "v", ")", "{", "$", "v", "=", "[", "'tag'", "=>", "$", "v", "[", "1", "]", ",", "'value'", "=>", "$", "v", "[", "2", "]", "]", ";", "}", ")", ";", "return", "$", "matches", ";", "}" ]
#}}}
[ "#", "}}}" ]
train
https://github.com/xmlscript/srv/blob/64e28952d95b16b8ba43809a5593023b0ca81ace/api.php#L126-L137
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.move
public function move(FileUpload $file) : ?string { if ($file->isOk()) { $this->privateFileName = (new DateTime())->getTimestamp() . '-' . $file->getSanitizedName(); $length = strlen($this->privateFileName); if ($length > self::MAX_FILE_NAME_LENGTH) { $maxLength = self::MAX_FILE_NAME_LENGTH; throw new ProtectedFileException("Maximal length of file name is '{$maxLength}' chars. File name: '{$file->getSanitizedName()}' have {$length} chars."); } $privateFilePath = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; if (file_exists($privateFilePath)) { throw new ProtectedFileException("File '{$this->privateFileName}' already exists. Maybe anyone upload same file at same time."); } FileSystem::createDir(self::PRIVATE_ABSOLUTE_PATH . $this->destination); $file->move($privateFilePath); } return $this->privateFileName; }
php
public function move(FileUpload $file) : ?string { if ($file->isOk()) { $this->privateFileName = (new DateTime())->getTimestamp() . '-' . $file->getSanitizedName(); $length = strlen($this->privateFileName); if ($length > self::MAX_FILE_NAME_LENGTH) { $maxLength = self::MAX_FILE_NAME_LENGTH; throw new ProtectedFileException("Maximal length of file name is '{$maxLength}' chars. File name: '{$file->getSanitizedName()}' have {$length} chars."); } $privateFilePath = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; if (file_exists($privateFilePath)) { throw new ProtectedFileException("File '{$this->privateFileName}' already exists. Maybe anyone upload same file at same time."); } FileSystem::createDir(self::PRIVATE_ABSOLUTE_PATH . $this->destination); $file->move($privateFilePath); } return $this->privateFileName; }
[ "public", "function", "move", "(", "FileUpload", "$", "file", ")", ":", "?", "string", "{", "if", "(", "$", "file", "->", "isOk", "(", ")", ")", "{", "$", "this", "->", "privateFileName", "=", "(", "new", "DateTime", "(", ")", ")", "->", "getTimestamp", "(", ")", ".", "'-'", ".", "$", "file", "->", "getSanitizedName", "(", ")", ";", "$", "length", "=", "strlen", "(", "$", "this", "->", "privateFileName", ")", ";", "if", "(", "$", "length", ">", "self", "::", "MAX_FILE_NAME_LENGTH", ")", "{", "$", "maxLength", "=", "self", "::", "MAX_FILE_NAME_LENGTH", ";", "throw", "new", "ProtectedFileException", "(", "\"Maximal length of file name is '{$maxLength}' chars. File name: '{$file->getSanitizedName()}' have {$length} chars.\"", ")", ";", "}", "$", "privateFilePath", "=", "self", "::", "PRIVATE_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ".", "$", "this", "->", "privateFileName", ";", "if", "(", "file_exists", "(", "$", "privateFilePath", ")", ")", "{", "throw", "new", "ProtectedFileException", "(", "\"File '{$this->privateFileName}' already exists. Maybe anyone upload same file at same time.\"", ")", ";", "}", "FileSystem", "::", "createDir", "(", "self", "::", "PRIVATE_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ")", ";", "$", "file", "->", "move", "(", "$", "privateFilePath", ")", ";", "}", "return", "$", "this", "->", "privateFileName", ";", "}" ]
Uloží soubor na disk a vrátí jeho nový název @param FileUpload $file @return string @throws ProtectedFileException
[ "Uloží", "soubor", "na", "disk", "a", "vrátí", "jeho", "nový", "název" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L105-L132
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.getAttr
public function getAttr(string $name) { if (!isset($this->attr[$name])) { return NULL; } return $this->attr[$name]; }
php
public function getAttr(string $name) { if (!isset($this->attr[$name])) { return NULL; } return $this->attr[$name]; }
[ "public", "function", "getAttr", "(", "string", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attr", "[", "$", "name", "]", ")", ")", "{", "return", "NULL", ";", "}", "return", "$", "this", "->", "attr", "[", "$", "name", "]", ";", "}" ]
Vrací atribut podle jeho názvu @param string $name @throws InvalidArgumentException @return mixed
[ "Vrací", "atribut", "podle", "jeho", "názvu" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L141-L149
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.getPrivateFile
public function getPrivateFile() : ?\SplFileInfo { $path = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; if (!$this->privateFileName || !file_exists($path)) { return NULL; } return new \SplFileInfo($path); }
php
public function getPrivateFile() : ?\SplFileInfo { $path = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; if (!$this->privateFileName || !file_exists($path)) { return NULL; } return new \SplFileInfo($path); }
[ "public", "function", "getPrivateFile", "(", ")", ":", "?", "\\", "SplFileInfo", "{", "$", "path", "=", "self", "::", "PRIVATE_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ".", "$", "this", "->", "privateFileName", ";", "if", "(", "!", "$", "this", "->", "privateFileName", "||", "!", "file_exists", "(", "$", "path", ")", ")", "{", "return", "NULL", ";", "}", "return", "new", "\\", "SplFileInfo", "(", "$", "path", ")", ";", "}" ]
Vrací SplInfo o privátním souboru @return \SplFileInfo|NULL
[ "Vrací", "SplInfo", "o", "privátním", "souboru" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L156-L166
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.remove
public function remove() : bool { $private = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; $public = self::PUBLIC_ABSOLUTE_PATH . $this->destination; if (file_exists($private) || file_exists($public)) { FileSystem::delete($private); FileSystem::delete($public); return TRUE; } return FALSE; }
php
public function remove() : bool { $private = self::PRIVATE_ABSOLUTE_PATH . $this->destination . $this->privateFileName; $public = self::PUBLIC_ABSOLUTE_PATH . $this->destination; if (file_exists($private) || file_exists($public)) { FileSystem::delete($private); FileSystem::delete($public); return TRUE; } return FALSE; }
[ "public", "function", "remove", "(", ")", ":", "bool", "{", "$", "private", "=", "self", "::", "PRIVATE_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ".", "$", "this", "->", "privateFileName", ";", "$", "public", "=", "self", "::", "PUBLIC_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ";", "if", "(", "file_exists", "(", "$", "private", ")", "||", "file_exists", "(", "$", "public", ")", ")", "{", "FileSystem", "::", "delete", "(", "$", "private", ")", ";", "FileSystem", "::", "delete", "(", "$", "public", ")", ";", "return", "TRUE", ";", "}", "return", "FALSE", ";", "}" ]
Odstraní privátní soubor a jeho veřejné kopie či thumbnaily @return bool
[ "Odstraní", "privátní", "soubor", "a", "jeho", "veřejné", "kopie", "či", "thumbnaily" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L173-L187
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.getPublicFile
public function getPublicFile() : ?string { $publicDestination = self::PUBLIC_ABSOLUTE_PATH . $this->destination; $privateFile = $this->getPrivateFile(); if (!$this->privateFileName || !file_exists($privateFile->getPathname())) { return NULL; } $name = $privateFile->getFilename(); if (!file_exists($publicDestination . $name)) { FileSystem::copy($privateFile->getPathname(), $publicDestination . $name); } return self::PUBLIC_RELATIVE_PATH . $this->destination . $name; }
php
public function getPublicFile() : ?string { $publicDestination = self::PUBLIC_ABSOLUTE_PATH . $this->destination; $privateFile = $this->getPrivateFile(); if (!$this->privateFileName || !file_exists($privateFile->getPathname())) { return NULL; } $name = $privateFile->getFilename(); if (!file_exists($publicDestination . $name)) { FileSystem::copy($privateFile->getPathname(), $publicDestination . $name); } return self::PUBLIC_RELATIVE_PATH . $this->destination . $name; }
[ "public", "function", "getPublicFile", "(", ")", ":", "?", "string", "{", "$", "publicDestination", "=", "self", "::", "PUBLIC_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ";", "$", "privateFile", "=", "$", "this", "->", "getPrivateFile", "(", ")", ";", "if", "(", "!", "$", "this", "->", "privateFileName", "||", "!", "file_exists", "(", "$", "privateFile", "->", "getPathname", "(", ")", ")", ")", "{", "return", "NULL", ";", "}", "$", "name", "=", "$", "privateFile", "->", "getFilename", "(", ")", ";", "if", "(", "!", "file_exists", "(", "$", "publicDestination", ".", "$", "name", ")", ")", "{", "FileSystem", "::", "copy", "(", "$", "privateFile", "->", "getPathname", "(", ")", ",", "$", "publicDestination", ".", "$", "name", ")", ";", "}", "return", "self", "::", "PUBLIC_RELATIVE_PATH", ".", "$", "this", "->", "destination", ".", "$", "name", ";", "}" ]
Generuje či Vrací kopii souboru @return string|NULL
[ "Generuje", "či", "Vrací", "kopii", "souboru" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L194-L212
wakerscz/cms-base-module
src/Util/ProtectedFile.php
ProtectedFile.getPublicImage
public function getPublicImage(string $size, string $cropType) : string { $size = strtolower($size); $cropType = strtolower($cropType); list ($width, $height) = explode('x', $size); $width = $width === 'null' ? NULL : $width; $height = $height === 'null' ? NULL : $height; if (!$width && !$height) { throw new InvalidArgumentException("One of this parameters: 'size-width' or 'size-height' is required."); } if (!in_array($cropType, self::CROP_TYPES)) { $allowedArguments = implode(', ', self::CROP_TYPES); throw new InvalidArgumentException("Argument \$cropType '{$cropType}' is invalid. Allowed arguments are '{$allowedArguments}'"); } $privateFile = $this->getPrivateFile(); if ($privateFile) { $name = basename($privateFile->getFilename(), '.' . $privateFile->getExtension()); $name .= "---{$width}x{$height}-{$cropType}." . $privateFile->getExtension(); } else { $this->destination = 'no-image/'; $name = "no-image---{$width}x{$height}-{$cropType}.jpg"; } $publicFilePath = self::PUBLIC_ABSOLUTE_PATH . $this->destination; if (!file_exists($publicFilePath . $name)) { if (!is_dir($publicFilePath)) { FileSystem::createDir($publicFilePath); } if ($privateFile) { $image = Image::fromFile($privateFile->getPathname()); } else { $width = (!$width) ? $height / 2 : $width; $height = (!$height) ? $width / 2 : $height; $image = Image::fromBlank($width, $height, Image::rgb(204,204,204)); } $image->resize($width, $height, array_search($cropType, self::CROP_TYPES)); $image->save($publicFilePath . $name, self::IMAGE_QUALITY); } return self::PUBLIC_RELATIVE_PATH . $this->destination . $name; }
php
public function getPublicImage(string $size, string $cropType) : string { $size = strtolower($size); $cropType = strtolower($cropType); list ($width, $height) = explode('x', $size); $width = $width === 'null' ? NULL : $width; $height = $height === 'null' ? NULL : $height; if (!$width && !$height) { throw new InvalidArgumentException("One of this parameters: 'size-width' or 'size-height' is required."); } if (!in_array($cropType, self::CROP_TYPES)) { $allowedArguments = implode(', ', self::CROP_TYPES); throw new InvalidArgumentException("Argument \$cropType '{$cropType}' is invalid. Allowed arguments are '{$allowedArguments}'"); } $privateFile = $this->getPrivateFile(); if ($privateFile) { $name = basename($privateFile->getFilename(), '.' . $privateFile->getExtension()); $name .= "---{$width}x{$height}-{$cropType}." . $privateFile->getExtension(); } else { $this->destination = 'no-image/'; $name = "no-image---{$width}x{$height}-{$cropType}.jpg"; } $publicFilePath = self::PUBLIC_ABSOLUTE_PATH . $this->destination; if (!file_exists($publicFilePath . $name)) { if (!is_dir($publicFilePath)) { FileSystem::createDir($publicFilePath); } if ($privateFile) { $image = Image::fromFile($privateFile->getPathname()); } else { $width = (!$width) ? $height / 2 : $width; $height = (!$height) ? $width / 2 : $height; $image = Image::fromBlank($width, $height, Image::rgb(204,204,204)); } $image->resize($width, $height, array_search($cropType, self::CROP_TYPES)); $image->save($publicFilePath . $name, self::IMAGE_QUALITY); } return self::PUBLIC_RELATIVE_PATH . $this->destination . $name; }
[ "public", "function", "getPublicImage", "(", "string", "$", "size", ",", "string", "$", "cropType", ")", ":", "string", "{", "$", "size", "=", "strtolower", "(", "$", "size", ")", ";", "$", "cropType", "=", "strtolower", "(", "$", "cropType", ")", ";", "list", "(", "$", "width", ",", "$", "height", ")", "=", "explode", "(", "'x'", ",", "$", "size", ")", ";", "$", "width", "=", "$", "width", "===", "'null'", "?", "NULL", ":", "$", "width", ";", "$", "height", "=", "$", "height", "===", "'null'", "?", "NULL", ":", "$", "height", ";", "if", "(", "!", "$", "width", "&&", "!", "$", "height", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"One of this parameters: 'size-width' or 'size-height' is required.\"", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "cropType", ",", "self", "::", "CROP_TYPES", ")", ")", "{", "$", "allowedArguments", "=", "implode", "(", "', '", ",", "self", "::", "CROP_TYPES", ")", ";", "throw", "new", "InvalidArgumentException", "(", "\"Argument \\$cropType '{$cropType}' is invalid. Allowed arguments are '{$allowedArguments}'\"", ")", ";", "}", "$", "privateFile", "=", "$", "this", "->", "getPrivateFile", "(", ")", ";", "if", "(", "$", "privateFile", ")", "{", "$", "name", "=", "basename", "(", "$", "privateFile", "->", "getFilename", "(", ")", ",", "'.'", ".", "$", "privateFile", "->", "getExtension", "(", ")", ")", ";", "$", "name", ".=", "\"---{$width}x{$height}-{$cropType}.\"", ".", "$", "privateFile", "->", "getExtension", "(", ")", ";", "}", "else", "{", "$", "this", "->", "destination", "=", "'no-image/'", ";", "$", "name", "=", "\"no-image---{$width}x{$height}-{$cropType}.jpg\"", ";", "}", "$", "publicFilePath", "=", "self", "::", "PUBLIC_ABSOLUTE_PATH", ".", "$", "this", "->", "destination", ";", "if", "(", "!", "file_exists", "(", "$", "publicFilePath", ".", "$", "name", ")", ")", "{", "if", "(", "!", "is_dir", "(", "$", "publicFilePath", ")", ")", "{", "FileSystem", "::", "createDir", "(", "$", "publicFilePath", ")", ";", "}", "if", "(", "$", "privateFile", ")", "{", "$", "image", "=", "Image", "::", "fromFile", "(", "$", "privateFile", "->", "getPathname", "(", ")", ")", ";", "}", "else", "{", "$", "width", "=", "(", "!", "$", "width", ")", "?", "$", "height", "/", "2", ":", "$", "width", ";", "$", "height", "=", "(", "!", "$", "height", ")", "?", "$", "width", "/", "2", ":", "$", "height", ";", "$", "image", "=", "Image", "::", "fromBlank", "(", "$", "width", ",", "$", "height", ",", "Image", "::", "rgb", "(", "204", ",", "204", ",", "204", ")", ")", ";", "}", "$", "image", "->", "resize", "(", "$", "width", ",", "$", "height", ",", "array_search", "(", "$", "cropType", ",", "self", "::", "CROP_TYPES", ")", ")", ";", "$", "image", "->", "save", "(", "$", "publicFilePath", ".", "$", "name", ",", "self", "::", "IMAGE_QUALITY", ")", ";", "}", "return", "self", "::", "PUBLIC_RELATIVE_PATH", ".", "$", "this", "->", "destination", ".", "$", "name", ";", "}" ]
Generuje či Vrací kopii zmenšeného obrázku @param string $size @param string $cropType @return string @throws \Nette\Utils\UnknownImageFileException
[ "Generuje", "či", "Vrací", "kopii", "zmenšeného", "obrázku" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/ProtectedFile.php#L222-L281
agentmedia/phine-builtin
src/BuiltIn/Modules/Backend/ContainerForm.php
ContainerForm.InitForm
protected function InitForm() { $this->container = $this->LoadElement(); $this->AddContainerField(); $this->AddCssClassField(); $this->AddCssIDField(); $this->AddSubmit(); }
php
protected function InitForm() { $this->container = $this->LoadElement(); $this->AddContainerField(); $this->AddCssClassField(); $this->AddCssIDField(); $this->AddSubmit(); }
[ "protected", "function", "InitForm", "(", ")", "{", "$", "this", "->", "container", "=", "$", "this", "->", "LoadElement", "(", ")", ";", "$", "this", "->", "AddContainerField", "(", ")", ";", "$", "this", "->", "AddCssClassField", "(", ")", ";", "$", "this", "->", "AddCssIDField", "(", ")", ";", "$", "this", "->", "AddSubmit", "(", ")", ";", "}" ]
Initializes the form
[ "Initializes", "the", "form" ]
train
https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Backend/ContainerForm.php#L47-L54
reliv/rcm-config
src/Entity/RcmConfig.php
RcmConfig.getValue
public function getValue() { $value = json_decode($this->value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidJsonException("Invalid JSON config value for id: " . $this->getId()); } return $value; }
php
public function getValue() { $value = json_decode($this->value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidJsonException("Invalid JSON config value for id: " . $this->getId()); } return $value; }
[ "public", "function", "getValue", "(", ")", "{", "$", "value", "=", "json_decode", "(", "$", "this", "->", "value", ",", "true", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")", "{", "throw", "new", "InvalidJsonException", "(", "\"Invalid JSON config value for id: \"", ".", "$", "this", "->", "getId", "(", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
getValue @return mixed @throws InvalidJsonException
[ "getValue" ]
train
https://github.com/reliv/rcm-config/blob/3e8cdea57a8688b06997ce1b167b8410bccac09e/src/Entity/RcmConfig.php#L152-L160
n2n/n2n-io
src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php
FileSourceAdapter.buildHash
public function buildHash(): string { $this->ensureValid(); $fs = IoUtils::stat($this->fileFsPath); return sprintf('%x-%x-%s', $fs['ino'], $fs['size'], base_convert(str_pad($fs['mtime'], 16, '0'), 10, 16)); }
php
public function buildHash(): string { $this->ensureValid(); $fs = IoUtils::stat($this->fileFsPath); return sprintf('%x-%x-%s', $fs['ino'], $fs['size'], base_convert(str_pad($fs['mtime'], 16, '0'), 10, 16)); }
[ "public", "function", "buildHash", "(", ")", ":", "string", "{", "$", "this", "->", "ensureValid", "(", ")", ";", "$", "fs", "=", "IoUtils", "::", "stat", "(", "$", "this", "->", "fileFsPath", ")", ";", "return", "sprintf", "(", "'%x-%x-%s'", ",", "$", "fs", "[", "'ino'", "]", ",", "$", "fs", "[", "'size'", "]", ",", "base_convert", "(", "str_pad", "(", "$", "fs", "[", "'mtime'", "]", ",", "16", ",", "'0'", ")", ",", "10", ",", "16", ")", ")", ";", "}" ]
{@inheritDoc} @see \n2n\io\managed\FileSource::buildHash()
[ "{" ]
train
https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php#L97-L101
n2n/n2n-io
src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php
FileSourceAdapter.move
public function move(FsPath $fsPath, $filePerm, $overwrite = false) { $this->ensureValid(); $this->valid = false; $this->fileFsPath->moveFile($fsPath, $filePerm, $overwrite); if ($this->infoFsPath !== null) { $this->infoFsPath->delete(); } }
php
public function move(FsPath $fsPath, $filePerm, $overwrite = false) { $this->ensureValid(); $this->valid = false; $this->fileFsPath->moveFile($fsPath, $filePerm, $overwrite); if ($this->infoFsPath !== null) { $this->infoFsPath->delete(); } }
[ "public", "function", "move", "(", "FsPath", "$", "fsPath", ",", "$", "filePerm", ",", "$", "overwrite", "=", "false", ")", "{", "$", "this", "->", "ensureValid", "(", ")", ";", "$", "this", "->", "valid", "=", "false", ";", "$", "this", "->", "fileFsPath", "->", "moveFile", "(", "$", "fsPath", ",", "$", "filePerm", ",", "$", "overwrite", ")", ";", "if", "(", "$", "this", "->", "infoFsPath", "!==", "null", ")", "{", "$", "this", "->", "infoFsPath", "->", "delete", "(", ")", ";", "}", "}" ]
/* (non-PHPdoc) @see \n2n\io\managed\FileSource::move()
[ "/", "*", "(", "non", "-", "PHPdoc", ")" ]
train
https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php#L147-L155
n2n/n2n-io
src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php
FileSourceAdapter.copy
public function copy(FsPath $fsPath, $filePerm, $overwrite = false) { $this->ensureValid(); $this->fileFsPath->copyFile($fsPath, $filePerm, $overwrite); }
php
public function copy(FsPath $fsPath, $filePerm, $overwrite = false) { $this->ensureValid(); $this->fileFsPath->copyFile($fsPath, $filePerm, $overwrite); }
[ "public", "function", "copy", "(", "FsPath", "$", "fsPath", ",", "$", "filePerm", ",", "$", "overwrite", "=", "false", ")", "{", "$", "this", "->", "ensureValid", "(", ")", ";", "$", "this", "->", "fileFsPath", "->", "copyFile", "(", "$", "fsPath", ",", "$", "filePerm", ",", "$", "overwrite", ")", ";", "}" ]
/* (non-PHPdoc) @see \n2n\io\managed\FileSource::copy()
[ "/", "*", "(", "non", "-", "PHPdoc", ")" ]
train
https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php#L160-L164
n2n/n2n-io
src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php
FileSourceAdapter.delete
public function delete() { $this->ensureValid(); $this->valid = false; $this->fileFsPath->delete(); if ($this->infoFsPath !== null) { $this->infoFsPath->delete(); } }
php
public function delete() { $this->ensureValid(); $this->valid = false; $this->fileFsPath->delete(); if ($this->infoFsPath !== null) { $this->infoFsPath->delete(); } }
[ "public", "function", "delete", "(", ")", "{", "$", "this", "->", "ensureValid", "(", ")", ";", "$", "this", "->", "valid", "=", "false", ";", "$", "this", "->", "fileFsPath", "->", "delete", "(", ")", ";", "if", "(", "$", "this", "->", "infoFsPath", "!==", "null", ")", "{", "$", "this", "->", "infoFsPath", "->", "delete", "(", ")", ";", "}", "}" ]
/* (non-PHPdoc) @see \n2n\io\managed\FileSource::delete()
[ "/", "*", "(", "non", "-", "PHPdoc", ")" ]
train
https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/managed/impl/engine/FileSourceAdapter.php#L170-L178
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.doSearch
protected static function doSearch($id = null) { $model = self::createModelInstance(); $tableName = $model->getTableName($model->className); return $id ? self::selectOne($model, $tableName, $id) : self::selectAll($model, $tableName); }
php
protected static function doSearch($id = null) { $model = self::createModelInstance(); $tableName = $model->getTableName($model->className); return $id ? self::selectOne($model, $tableName, $id) : self::selectAll($model, $tableName); }
[ "protected", "static", "function", "doSearch", "(", "$", "id", "=", "null", ")", "{", "$", "model", "=", "self", "::", "createModelInstance", "(", ")", ";", "$", "tableName", "=", "$", "model", "->", "getTableName", "(", "$", "model", "->", "className", ")", ";", "return", "$", "id", "?", "self", "::", "selectOne", "(", "$", "model", ",", "$", "tableName", ",", "$", "id", ")", ":", "self", "::", "selectAll", "(", "$", "model", ",", "$", "tableName", ")", ";", "}" ]
Choose to either search database for one row or all rows depending on whether the $id argument is passed @param int $id @return mixed
[ "Choose", "to", "either", "search", "database", "for", "one", "row", "or", "all", "rows", "depending", "on", "whether", "the", "$id", "argument", "is", "passed" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L53-L59
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.where
public function where($table, $column, $keyword) { $connection = Connection::connect(); $selectValue = $connection->prepare('select * from '.$table.' where '.$column.' = \''.$keyword.'\''); $selectValue->execute(); return $selectValue->fetch(PDO::FETCH_ASSOC); }
php
public function where($table, $column, $keyword) { $connection = Connection::connect(); $selectValue = $connection->prepare('select * from '.$table.' where '.$column.' = \''.$keyword.'\''); $selectValue->execute(); return $selectValue->fetch(PDO::FETCH_ASSOC); }
[ "public", "function", "where", "(", "$", "table", ",", "$", "column", ",", "$", "keyword", ")", "{", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "selectValue", "=", "$", "connection", "->", "prepare", "(", "'select * from '", ".", "$", "table", ".", "' where '", ".", "$", "column", ".", "' = \\''", ".", "$", "keyword", ".", "'\\''", ")", ";", "$", "selectValue", "->", "execute", "(", ")", ";", "return", "$", "selectValue", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "}" ]
Return details where a column is matched by the given keyword @param string $table @param string $column @param string $keyword @return array
[ "Return", "details", "where", "a", "column", "is", "matched", "by", "the", "given", "keyword" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L70-L78
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.selectAll
protected static function selectAll($model, $tableName) { $connection = Connection::connect(); $getAll = $connection->prepare('select * from '.$tableName); $getAll->execute(); while ($allRows = $getAll->fetch(PDO::FETCH_ASSOC)) { array_push($model->resultRows, $allRows); } return $model; }
php
protected static function selectAll($model, $tableName) { $connection = Connection::connect(); $getAll = $connection->prepare('select * from '.$tableName); $getAll->execute(); while ($allRows = $getAll->fetch(PDO::FETCH_ASSOC)) { array_push($model->resultRows, $allRows); } return $model; }
[ "protected", "static", "function", "selectAll", "(", "$", "model", ",", "$", "tableName", ")", "{", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "getAll", "=", "$", "connection", "->", "prepare", "(", "'select * from '", ".", "$", "tableName", ")", ";", "$", "getAll", "->", "execute", "(", ")", ";", "while", "(", "$", "allRows", "=", "$", "getAll", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "array_push", "(", "$", "model", "->", "resultRows", ",", "$", "allRows", ")", ";", "}", "return", "$", "model", ";", "}" ]
Search database for all rows @param $model @param $tableName @return mixed
[ "Search", "database", "for", "all", "rows" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L88-L100
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.selectOne
protected static function selectOne($model, $tableName, $id) { $connection = Connection::connect(); $getAll = $connection->prepare('select * from '.$tableName.' where id='.$id); $getAll->execute(); $row = $getAll->fetch(PDO::FETCH_ASSOC); array_push($model->resultRows, $row); return $model; }
php
protected static function selectOne($model, $tableName, $id) { $connection = Connection::connect(); $getAll = $connection->prepare('select * from '.$tableName.' where id='.$id); $getAll->execute(); $row = $getAll->fetch(PDO::FETCH_ASSOC); array_push($model->resultRows, $row); return $model; }
[ "protected", "static", "function", "selectOne", "(", "$", "model", ",", "$", "tableName", ",", "$", "id", ")", "{", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "getAll", "=", "$", "connection", "->", "prepare", "(", "'select * from '", ".", "$", "tableName", ".", "' where id='", ".", "$", "id", ")", ";", "$", "getAll", "->", "execute", "(", ")", ";", "$", "row", "=", "$", "getAll", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "array_push", "(", "$", "model", "->", "resultRows", ",", "$", "row", ")", ";", "return", "$", "model", ";", "}" ]
Search database for one row @param $model @param $tableName @param $id @return mixed
[ "Search", "database", "for", "one", "row" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L111-L122
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.insertRow
protected function insertRow() { $assignedValues = $this->getAssignedValues(); $columns = implode(', ', $assignedValues['columns']); $values = '\''.implode('\', \'', $assignedValues['values']).'\''; $tableName = $this->getTableName($this->className); $connection = Connection::connect(); $insert = $connection->prepare('insert into '.$tableName.'('.$columns.') values ('.$values.')'); var_dump($insert); if ($insert->execute()) { return 'Row inserted successfully'; } else { var_dump($insert->errorInfo()); } }
php
protected function insertRow() { $assignedValues = $this->getAssignedValues(); $columns = implode(', ', $assignedValues['columns']); $values = '\''.implode('\', \'', $assignedValues['values']).'\''; $tableName = $this->getTableName($this->className); $connection = Connection::connect(); $insert = $connection->prepare('insert into '.$tableName.'('.$columns.') values ('.$values.')'); var_dump($insert); if ($insert->execute()) { return 'Row inserted successfully'; } else { var_dump($insert->errorInfo()); } }
[ "protected", "function", "insertRow", "(", ")", "{", "$", "assignedValues", "=", "$", "this", "->", "getAssignedValues", "(", ")", ";", "$", "columns", "=", "implode", "(", "', '", ",", "$", "assignedValues", "[", "'columns'", "]", ")", ";", "$", "values", "=", "'\\''", ".", "implode", "(", "'\\', \\''", ",", "$", "assignedValues", "[", "'values'", "]", ")", ".", "'\\''", ";", "$", "tableName", "=", "$", "this", "->", "getTableName", "(", "$", "this", "->", "className", ")", ";", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "insert", "=", "$", "connection", "->", "prepare", "(", "'insert into '", ".", "$", "tableName", ".", "'('", ".", "$", "columns", ".", "') values ('", ".", "$", "values", ".", "')'", ")", ";", "var_dump", "(", "$", "insert", ")", ";", "if", "(", "$", "insert", "->", "execute", "(", ")", ")", "{", "return", "'Row inserted successfully'", ";", "}", "else", "{", "var_dump", "(", "$", "insert", "->", "errorInfo", "(", ")", ")", ";", "}", "}" ]
Insert a new row @return string
[ "Insert", "a", "new", "row" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L153-L171
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.updateRow
protected function updateRow() { $tableName = $this->getTableName($this->className); $assignedValues = $this->getAssignedValues(); $updateDetails = []; for ($i = 0; $i < count($assignedValues['columns']); $i++) { array_push($updateDetails, $assignedValues['columns'][$i] .' =\''. $assignedValues['values'][$i].'\''); } $connection = Connection::connect(); $allUpdates = implode(', ' , $updateDetails); $update = $connection->prepare('update '.$tableName.' set '. $allUpdates.' where id='.$this->resultRows[0]['id']); if ($update->execute()) { return 'Row updated'; } else { throw new Exception("Unable to update row"); } }
php
protected function updateRow() { $tableName = $this->getTableName($this->className); $assignedValues = $this->getAssignedValues(); $updateDetails = []; for ($i = 0; $i < count($assignedValues['columns']); $i++) { array_push($updateDetails, $assignedValues['columns'][$i] .' =\''. $assignedValues['values'][$i].'\''); } $connection = Connection::connect(); $allUpdates = implode(', ' , $updateDetails); $update = $connection->prepare('update '.$tableName.' set '. $allUpdates.' where id='.$this->resultRows[0]['id']); if ($update->execute()) { return 'Row updated'; } else { throw new Exception("Unable to update row"); } }
[ "protected", "function", "updateRow", "(", ")", "{", "$", "tableName", "=", "$", "this", "->", "getTableName", "(", "$", "this", "->", "className", ")", ";", "$", "assignedValues", "=", "$", "this", "->", "getAssignedValues", "(", ")", ";", "$", "updateDetails", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "assignedValues", "[", "'columns'", "]", ")", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "updateDetails", ",", "$", "assignedValues", "[", "'columns'", "]", "[", "$", "i", "]", ".", "' =\\''", ".", "$", "assignedValues", "[", "'values'", "]", "[", "$", "i", "]", ".", "'\\''", ")", ";", "}", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "allUpdates", "=", "implode", "(", "', '", ",", "$", "updateDetails", ")", ";", "$", "update", "=", "$", "connection", "->", "prepare", "(", "'update '", ".", "$", "tableName", ".", "' set '", ".", "$", "allUpdates", ".", "' where id='", ".", "$", "this", "->", "resultRows", "[", "0", "]", "[", "'id'", "]", ")", ";", "if", "(", "$", "update", "->", "execute", "(", ")", ")", "{", "return", "'Row updated'", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"Unable to update row\"", ")", ";", "}", "}" ]
Edit an existing row @return bool
[ "Edit", "an", "existing", "row" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L178-L198
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.destroy
public static function destroy($id) { if (self::confirmIdExists($id)) { return self::doDelete($id); } else { throw new Exception('Now rows found with ID '.$id.' in the database, it may have been already deleted'); } }
php
public static function destroy($id) { if (self::confirmIdExists($id)) { return self::doDelete($id); } else { throw new Exception('Now rows found with ID '.$id.' in the database, it may have been already deleted'); } }
[ "public", "static", "function", "destroy", "(", "$", "id", ")", "{", "if", "(", "self", "::", "confirmIdExists", "(", "$", "id", ")", ")", "{", "return", "self", "::", "doDelete", "(", "$", "id", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'Now rows found with ID '", ".", "$", "id", ".", "' in the database, it may have been already deleted'", ")", ";", "}", "}" ]
Call doDelete function if the specified id exists @param $id @return string
[ "Call", "doDelete", "function", "if", "the", "specified", "id", "exists" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L207-L214
andela-doladosu/liteorm
src/Origins/BaseModel.php
BaseModel.doDelete
protected static function doDelete($id) { $model = self::createModelInstance(); $tableName = $model->getTableName($model->className); $connection = Connection::connect(); $delete = $connection->prepare('delete from '.$tableName.' where id ='.$id); return $delete->execute() ? 'deleted successfully' : 'Row not deleted'; }
php
protected static function doDelete($id) { $model = self::createModelInstance(); $tableName = $model->getTableName($model->className); $connection = Connection::connect(); $delete = $connection->prepare('delete from '.$tableName.' where id ='.$id); return $delete->execute() ? 'deleted successfully' : 'Row not deleted'; }
[ "protected", "static", "function", "doDelete", "(", "$", "id", ")", "{", "$", "model", "=", "self", "::", "createModelInstance", "(", ")", ";", "$", "tableName", "=", "$", "model", "->", "getTableName", "(", "$", "model", "->", "className", ")", ";", "$", "connection", "=", "Connection", "::", "connect", "(", ")", ";", "$", "delete", "=", "$", "connection", "->", "prepare", "(", "'delete from '", ".", "$", "tableName", ".", "' where id ='", ".", "$", "id", ")", ";", "return", "$", "delete", "->", "execute", "(", ")", "?", "'deleted successfully'", ":", "'Row not deleted'", ";", "}" ]
Delete an existing row from the database @param $id @return string
[ "Delete", "an", "existing", "row", "from", "the", "database" ]
train
https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Origins/BaseModel.php#L222-L233
alphalemon/BootstrapBundle
Core/ActionManager/ActionManagerGenerator.php
ActionManagerGenerator.generate
public function generate($actionManager) { if ($actionManager instanceof ActionManagerInterface) { $this->actionManager = $actionManager; $this->actionManagerClass = get_class($this->actionManager); } if (is_string($actionManager) && class_exists($actionManager)) { $this->actionManager = new $actionManager(); $this->actionManagerClass = $actionManager; } }
php
public function generate($actionManager) { if ($actionManager instanceof ActionManagerInterface) { $this->actionManager = $actionManager; $this->actionManagerClass = get_class($this->actionManager); } if (is_string($actionManager) && class_exists($actionManager)) { $this->actionManager = new $actionManager(); $this->actionManagerClass = $actionManager; } }
[ "public", "function", "generate", "(", "$", "actionManager", ")", "{", "if", "(", "$", "actionManager", "instanceof", "ActionManagerInterface", ")", "{", "$", "this", "->", "actionManager", "=", "$", "actionManager", ";", "$", "this", "->", "actionManagerClass", "=", "get_class", "(", "$", "this", "->", "actionManager", ")", ";", "}", "if", "(", "is_string", "(", "$", "actionManager", ")", "&&", "class_exists", "(", "$", "actionManager", ")", ")", "{", "$", "this", "->", "actionManager", "=", "new", "$", "actionManager", "(", ")", ";", "$", "this", "->", "actionManagerClass", "=", "$", "actionManager", ";", "}", "}" ]
Generates the ActionManager object @param mixed ActionManagerInterface|string $actionManager
[ "Generates", "the", "ActionManager", "object" ]
train
https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/ActionManager/ActionManagerGenerator.php#L48-L59
ColibriPlatform/base
Env.php
Env.load
public static function load($file) { if (file_exists($file)) { $env = \M1\Env\Parser::parse(file_get_contents($file)); foreach ($env as $key => $value) { putenv("{$key}={$value}"); } } }
php
public static function load($file) { if (file_exists($file)) { $env = \M1\Env\Parser::parse(file_get_contents($file)); foreach ($env as $key => $value) { putenv("{$key}={$value}"); } } }
[ "public", "static", "function", "load", "(", "$", "file", ")", "{", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "env", "=", "\\", "M1", "\\", "Env", "\\", "Parser", "::", "parse", "(", "file_get_contents", "(", "$", "file", ")", ")", ";", "foreach", "(", "$", "env", "as", "$", "key", "=>", "$", "value", ")", "{", "putenv", "(", "\"{$key}={$value}\"", ")", ";", "}", "}", "}" ]
Load file containing environment variables and setup environment with these variables @param string $file @return void
[ "Load", "file", "containing", "environment", "variables", "and", "setup", "environment", "with", "these", "variables" ]
train
https://github.com/ColibriPlatform/base/blob/b45db9c88317e28acc5b024ac98f8428685179aa/Env.php#L27-L35
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.addForeignKey
function addForeignKey($table, $pkname, $tables) { if ( is_string($tables) ) $tables = array($tables); $this->_foreignKeys[$table] = array( 'primaryKey' => $pkname, 'tables' => $tables ); }
php
function addForeignKey($table, $pkname, $tables) { if ( is_string($tables) ) $tables = array($tables); $this->_foreignKeys[$table] = array( 'primaryKey' => $pkname, 'tables' => $tables ); }
[ "function", "addForeignKey", "(", "$", "table", ",", "$", "pkname", ",", "$", "tables", ")", "{", "if", "(", "is_string", "(", "$", "tables", ")", ")", "$", "tables", "=", "array", "(", "$", "tables", ")", ";", "$", "this", "->", "_foreignKeys", "[", "$", "table", "]", "=", "array", "(", "'primaryKey'", "=>", "$", "pkname", ",", "'tables'", "=>", "$", "tables", ")", ";", "}" ]
Add some config data for a new foreign key @param string $table Name of the foreign key table @param string $pkname Name of its primary key @param string[] $tables Array of tables referencing $table parameter
[ "Add", "some", "config", "data", "for", "a", "new", "foreign", "key" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L59-L69
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_query
function pdo_query($query, $values = NULL) { if ( !is_null($values) && !is_array($values) ) $values = array($values); return $this->prepare($query)->execute($values); }
php
function pdo_query($query, $values = NULL) { if ( !is_null($values) && !is_array($values) ) $values = array($values); return $this->prepare($query)->execute($values); }
[ "function", "pdo_query", "(", "$", "query", ",", "$", "values", "=", "NULL", ")", "{", "if", "(", "!", "is_null", "(", "$", "values", ")", "&&", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "return", "$", "this", "->", "prepare", "(", "$", "query", ")", "->", "execute", "(", "$", "values", ")", ";", "}" ]
Helper query method to prepare and execute a sql request (DELETE, INSERT, UPDATE) @param string $query The SQL query @param string[] $values An array of parameters for the query (? and :xxx placeholders concrete values) @return bool Returns true if query OK @throws \PDOException If an error occured, a exception is thrown
[ "Helper", "query", "method", "to", "prepare", "and", "execute", "a", "sql", "request", "(", "DELETE", "INSERT", "UPDATE", ")" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L103-L109
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_query_select
function pdo_query_select($query, $values = NULL) { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st = $this->prepare($query); $st->execute($values); return $st; }
php
function pdo_query_select($query, $values = NULL) { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st = $this->prepare($query); $st->execute($values); return $st; }
[ "function", "pdo_query_select", "(", "$", "query", ",", "$", "values", "=", "NULL", ")", "{", "if", "(", "!", "is_null", "(", "$", "values", ")", "&&", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "$", "st", "=", "$", "this", "->", "prepare", "(", "$", "query", ")", ";", "$", "st", "->", "execute", "(", "$", "values", ")", ";", "return", "$", "st", ";", "}" ]
Helper query method for a SQL SELECT request @param string $query The SQL query @param string[] $values An array of parameters for the query (? and :xxx placeholders concrete values) @return \PDOStatement A PDOStatement object with rows to fetch @throws \PDOException If an error occured, a exception is thrown
[ "Helper", "query", "method", "for", "a", "SQL", "SELECT", "request" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L120-L129
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_dbexists
function pdo_dbexists($query, $values = NULL) { try { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st = $this->prepare($query); $st->execute($values); $r = $st->fetch(\PDO::FETCH_COLUMN, 0); $st->closeCursor(); return $r; } catch ( \PDOException $e ) { return FALSE; } }
php
function pdo_dbexists($query, $values = NULL) { try { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st = $this->prepare($query); $st->execute($values); $r = $st->fetch(\PDO::FETCH_COLUMN, 0); $st->closeCursor(); return $r; } catch ( \PDOException $e ) { return FALSE; } }
[ "function", "pdo_dbexists", "(", "$", "query", ",", "$", "values", "=", "NULL", ")", "{", "try", "{", "if", "(", "!", "is_null", "(", "$", "values", ")", "&&", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "$", "st", "=", "$", "this", "->", "prepare", "(", "$", "query", ")", ";", "$", "st", "->", "execute", "(", "$", "values", ")", ";", "$", "r", "=", "$", "st", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_COLUMN", ",", "0", ")", ";", "$", "st", "->", "closeCursor", "(", ")", ";", "return", "$", "r", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "return", "FALSE", ";", "}", "}" ]
Get a single value fetched with a SELECT query (first column) If more than one line is returned by the request, only the first one is used ; If an exception is thrown by PDO, it is intercepted and false is returned @param string $query The SQL query @param string[] $values An array of parameters for the query (? and :xxx placeholders concrete values) @return int|float|string|bool The value selected by the SQL $query or FALSE if an error occured
[ "Get", "a", "single", "value", "fetched", "with", "a", "SELECT", "query", "(", "first", "column", ")" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L142-L159
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_value
static function pdo_value(\PDOStatement $st, $values = NULL) { try { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st->execute($values); $r = $st->fetch(\PDO::FETCH_COLUMN, 0); $st->closeCursor(); return $r; } catch ( \PDOException $e ) { return FALSE; } }
php
static function pdo_value(\PDOStatement $st, $values = NULL) { try { if ( !is_null($values) && !is_array($values) ) $values = array($values); $st->execute($values); $r = $st->fetch(\PDO::FETCH_COLUMN, 0); $st->closeCursor(); return $r; } catch ( \PDOException $e ) { return FALSE; } }
[ "static", "function", "pdo_value", "(", "\\", "PDOStatement", "$", "st", ",", "$", "values", "=", "NULL", ")", "{", "try", "{", "if", "(", "!", "is_null", "(", "$", "values", ")", "&&", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "$", "st", "->", "execute", "(", "$", "values", ")", ";", "$", "r", "=", "$", "st", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_COLUMN", ",", "0", ")", ";", "$", "st", "->", "closeCursor", "(", ")", ";", "return", "$", "r", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "return", "FALSE", ";", "}", "}" ]
Get a value (first column of row) from a PDO Statement (to be executed with values, if given) If more than one line is returned by the request, only the first one is used ; If an exception is thrown by PDO, it is intercepted and false is returned @param \PDOStatement $st The PDO statement, already prepared @param string[] $values An array of parameters for the query (? and :xxx placeholders concrete values) @return mixed|bool The value selected by the SQL $query or FALSE if an error occured
[ "Get", "a", "value", "(", "first", "column", "of", "row", ")", "from", "a", "PDO", "Statement", "(", "to", "be", "executed", "with", "values", "if", "given", ")" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L172-L188
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_dbsum
static function pdo_dbsum(\PDOStatement $result, $col, $values = NULL) { $tot = 0.0; $result->execute($values); if ( $result->rowCount() ) { $fetch = is_string($col) ? \PDO::FETCH_ASSOC : \PDO::FETCH_NUM; while ( $row = $result->fetch($fetch) ) $tot += $row[$col]; } $result->closeCursor(); return $tot; }
php
static function pdo_dbsum(\PDOStatement $result, $col, $values = NULL) { $tot = 0.0; $result->execute($values); if ( $result->rowCount() ) { $fetch = is_string($col) ? \PDO::FETCH_ASSOC : \PDO::FETCH_NUM; while ( $row = $result->fetch($fetch) ) $tot += $row[$col]; } $result->closeCursor(); return $tot; }
[ "static", "function", "pdo_dbsum", "(", "\\", "PDOStatement", "$", "result", ",", "$", "col", ",", "$", "values", "=", "NULL", ")", "{", "$", "tot", "=", "0.0", ";", "$", "result", "->", "execute", "(", "$", "values", ")", ";", "if", "(", "$", "result", "->", "rowCount", "(", ")", ")", "{", "$", "fetch", "=", "is_string", "(", "$", "col", ")", "?", "\\", "PDO", "::", "FETCH_ASSOC", ":", "\\", "PDO", "::", "FETCH_NUM", ";", "while", "(", "$", "row", "=", "$", "result", "->", "fetch", "(", "$", "fetch", ")", ")", "$", "tot", "+=", "$", "row", "[", "$", "col", "]", ";", "}", "$", "result", "->", "closeCursor", "(", ")", ";", "return", "$", "tot", ";", "}" ]
Sum rows on one column from a PDO statement (to be executed with parametered values, if given) @param \PDOStatement $result SQL statement, already prepared @param int|string $col The column to sum (a column name or a column index) @param string[] $values An array of parameters for the query (? and :xxx placeholders concrete values)
[ "Sum", "rows", "on", "one", "column", "from", "a", "PDO", "statement", "(", "to", "be", "executed", "with", "parametered", "values", "if", "given", ")" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L217-L231
net-tools/core
src/Helpers/PdoHelper.php
PdoHelper.pdo_foreignkeys
function pdo_foreignkeys($tablefk, $keyvalue) { $fk_tables = $this->_foreignKeys; try { // if we have no data about this table in the foreign key config, we are fine if ( !$fk_tables[$tablefk] ) return array('statut'=>true); // get the list of tables having $TABLEFK as a foreign key $tablesfk = $fk_tables[$tablefk]['tables']; // get the primary key name for $TABLEFK $pk = $fk_tables[$tablefk]['primaryKey']; $foreignkeys = array(); // for all tables having $TABLEFK as a foreign key foreach ( $tablesfk as $row ) { // get table name ; if we have an array instead of a string, the foreign key is valid with an additionnal SQL condition $tname = is_array($row) ? $row['table'] : $row; // are there rows in this table having a column referencing $TABLEFK with $KEYVALUE ? $query = "SELECT `$pk` FROM $tname WHERE `$pk` = :keyvalue"; // if SQL condition is provided, use it if ( is_array($row) ) $query .= " AND " . $row['sqlcond']; // execute request $result2 = $this->pdo_query_select($query, array(':keyvalue'=>$keyvalue)); // if at least on line matching, the foreign key is used if ( $result2->rowCount() ) $foreignkeys[] = $tname; $result2->closeCursor(); } // we now have a list of tables referencing our foreign key $TABLEFK if ( count($foreignkeys) ) return array( 'statut'=>false, 'cause'=>array( 'message'=>"Foreign key '$keyvalue' exists in table(s) : " . implode(", ", $foreignkeys), 'tables'=>$foreignkeys )); else return array('statut'=>true); } catch (\PDOException $e) { return array('statut'=>false, "cause"=>array("message"=>$e->getMessage())); } }
php
function pdo_foreignkeys($tablefk, $keyvalue) { $fk_tables = $this->_foreignKeys; try { // if we have no data about this table in the foreign key config, we are fine if ( !$fk_tables[$tablefk] ) return array('statut'=>true); // get the list of tables having $TABLEFK as a foreign key $tablesfk = $fk_tables[$tablefk]['tables']; // get the primary key name for $TABLEFK $pk = $fk_tables[$tablefk]['primaryKey']; $foreignkeys = array(); // for all tables having $TABLEFK as a foreign key foreach ( $tablesfk as $row ) { // get table name ; if we have an array instead of a string, the foreign key is valid with an additionnal SQL condition $tname = is_array($row) ? $row['table'] : $row; // are there rows in this table having a column referencing $TABLEFK with $KEYVALUE ? $query = "SELECT `$pk` FROM $tname WHERE `$pk` = :keyvalue"; // if SQL condition is provided, use it if ( is_array($row) ) $query .= " AND " . $row['sqlcond']; // execute request $result2 = $this->pdo_query_select($query, array(':keyvalue'=>$keyvalue)); // if at least on line matching, the foreign key is used if ( $result2->rowCount() ) $foreignkeys[] = $tname; $result2->closeCursor(); } // we now have a list of tables referencing our foreign key $TABLEFK if ( count($foreignkeys) ) return array( 'statut'=>false, 'cause'=>array( 'message'=>"Foreign key '$keyvalue' exists in table(s) : " . implode(", ", $foreignkeys), 'tables'=>$foreignkeys )); else return array('statut'=>true); } catch (\PDOException $e) { return array('statut'=>false, "cause"=>array("message"=>$e->getMessage())); } }
[ "function", "pdo_foreignkeys", "(", "$", "tablefk", ",", "$", "keyvalue", ")", "{", "$", "fk_tables", "=", "$", "this", "->", "_foreignKeys", ";", "try", "{", "// if we have no data about this table in the foreign key config, we are fine", "if", "(", "!", "$", "fk_tables", "[", "$", "tablefk", "]", ")", "return", "array", "(", "'statut'", "=>", "true", ")", ";", "// get the list of tables having $TABLEFK as a foreign key", "$", "tablesfk", "=", "$", "fk_tables", "[", "$", "tablefk", "]", "[", "'tables'", "]", ";", "// get the primary key name for $TABLEFK", "$", "pk", "=", "$", "fk_tables", "[", "$", "tablefk", "]", "[", "'primaryKey'", "]", ";", "$", "foreignkeys", "=", "array", "(", ")", ";", "// for all tables having $TABLEFK as a foreign key", "foreach", "(", "$", "tablesfk", "as", "$", "row", ")", "{", "// get table name ; if we have an array instead of a string, the foreign key is valid with an additionnal SQL condition", "$", "tname", "=", "is_array", "(", "$", "row", ")", "?", "$", "row", "[", "'table'", "]", ":", "$", "row", ";", "// are there rows in this table having a column referencing $TABLEFK with $KEYVALUE ?", "$", "query", "=", "\"SELECT `$pk` FROM $tname WHERE `$pk` = :keyvalue\"", ";", "// if SQL condition is provided, use it", "if", "(", "is_array", "(", "$", "row", ")", ")", "$", "query", ".=", "\" AND \"", ".", "$", "row", "[", "'sqlcond'", "]", ";", "// execute request", "$", "result2", "=", "$", "this", "->", "pdo_query_select", "(", "$", "query", ",", "array", "(", "':keyvalue'", "=>", "$", "keyvalue", ")", ")", ";", "// if at least on line matching, the foreign key is used", "if", "(", "$", "result2", "->", "rowCount", "(", ")", ")", "$", "foreignkeys", "[", "]", "=", "$", "tname", ";", "$", "result2", "->", "closeCursor", "(", ")", ";", "}", "// we now have a list of tables referencing our foreign key $TABLEFK", "if", "(", "count", "(", "$", "foreignkeys", ")", ")", "return", "array", "(", "'statut'", "=>", "false", ",", "'cause'", "=>", "array", "(", "'message'", "=>", "\"Foreign key '$keyvalue' exists in table(s) : \"", ".", "implode", "(", "\", \"", ",", "$", "foreignkeys", ")", ",", "'tables'", "=>", "$", "foreignkeys", ")", ")", ";", "else", "return", "array", "(", "'statut'", "=>", "true", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "return", "array", "(", "'statut'", "=>", "false", ",", "\"cause\"", "=>", "array", "(", "\"message\"", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "}" ]
Test if a given primary key value from a table is referenced by other tables (foreign key is used) @param string $tablefk Table name of the table being foreign key @param string $keyvalue Value of the primary key to look for @return string[] Array describing the result `['statut'=>true]` if the foreign key is not used, `['statut'=>false]` otherwise In the latter case, the array will contain additionnal data : `['cause'=> ['message'=>'error message', 'tables'=>[...table names...]]`
[ "Test", "if", "a", "given", "primary", "key", "value", "from", "a", "table", "is", "referenced", "by", "other", "tables", "(", "foreign", "key", "is", "used", ")" ]
train
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/PdoHelper.php#L242-L302
MindyPHP/Pagination
BasePagination.php
BasePagination.paginate
public function paginate() { $this->total = $this->dataSource->getTotal($this->source); if ( ($this->getPagesCount() > 0 && $this->getPage() > $this->getPagesCount()) || $this->getPage() <= 0 ) { $this->handler->wrongPageCallback(); } $this->data = $this->dataSource->applyLimit( $this->source, $this->getPage(), $this->getPageSize() ); return $this->data; }
php
public function paginate() { $this->total = $this->dataSource->getTotal($this->source); if ( ($this->getPagesCount() > 0 && $this->getPage() > $this->getPagesCount()) || $this->getPage() <= 0 ) { $this->handler->wrongPageCallback(); } $this->data = $this->dataSource->applyLimit( $this->source, $this->getPage(), $this->getPageSize() ); return $this->data; }
[ "public", "function", "paginate", "(", ")", "{", "$", "this", "->", "total", "=", "$", "this", "->", "dataSource", "->", "getTotal", "(", "$", "this", "->", "source", ")", ";", "if", "(", "(", "$", "this", "->", "getPagesCount", "(", ")", ">", "0", "&&", "$", "this", "->", "getPage", "(", ")", ">", "$", "this", "->", "getPagesCount", "(", ")", ")", "||", "$", "this", "->", "getPage", "(", ")", "<=", "0", ")", "{", "$", "this", "->", "handler", "->", "wrongPageCallback", "(", ")", ";", "}", "$", "this", "->", "data", "=", "$", "this", "->", "dataSource", "->", "applyLimit", "(", "$", "this", "->", "source", ",", "$", "this", "->", "getPage", "(", ")", ",", "$", "this", "->", "getPageSize", "(", ")", ")", ";", "return", "$", "this", "->", "data", ";", "}" ]
Apply limits to source. @throws \Exception @return array
[ "Apply", "limits", "to", "source", "." ]
train
https://github.com/MindyPHP/Pagination/blob/9f38cc7ac219ea2639b88d9f45351c7b24ea8322/BasePagination.php#L204-L222
ZendExperts/phpids
lib/IDS/Filter/Storage.php
IDS_Filter_Storage._isCached
private function _isCached() { $filters = false; if ($this->cacheSettings) { if ($this->cache) { $filters = $this->cache->getCache(); } } return $filters; }
php
private function _isCached() { $filters = false; if ($this->cacheSettings) { if ($this->cache) { $filters = $this->cache->getCache(); } } return $filters; }
[ "private", "function", "_isCached", "(", ")", "{", "$", "filters", "=", "false", ";", "if", "(", "$", "this", "->", "cacheSettings", ")", "{", "if", "(", "$", "this", "->", "cache", ")", "{", "$", "filters", "=", "$", "this", "->", "cache", "->", "getCache", "(", ")", ";", "}", "}", "return", "$", "filters", ";", "}" ]
Checks if any filters are cached @return mixed $filters cached filters or false
[ "Checks", "if", "any", "filters", "are", "cached" ]
train
https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Filter/Storage.php#L166-L178
ZendExperts/phpids
lib/IDS/Filter/Storage.php
IDS_Filter_Storage.getFilterFromXML
public function getFilterFromXML() { if (extension_loaded('SimpleXML')) { /* * See if filters are already available in the cache */ $filters = $this->_isCached(); /* * If they aren't, parse the source file */ if (!$filters) { if (file_exists($this->source)) { if (LIBXML_VERSION >= 20621) { $filters = simplexml_load_file($this->source, null, LIBXML_COMPACT); } else { $filters = simplexml_load_file($this->source); } } } /* * In case we still don't have any filters loaded and exception * will be thrown */ if (empty($filters)) { throw new Exception( 'XML data could not be loaded.' . ' Make sure you specified the correct path.' ); } /* * Now the storage will be filled with IDS_Filter objects */ $data = array(); $nocache = $filters instanceof SimpleXMLElement; $filters = $nocache ? $filters->filter : $filters; include_once 'IDS/Filter.php'; foreach ($filters as $filter) { $id = $nocache ? (string) $filter->id : $filter['id']; $rule = $nocache ? (string) $filter->rule : $filter['rule']; $impact = $nocache ? (string) $filter->impact : $filter['impact']; $tags = $nocache ? array_values((array) $filter->tags) : $filter['tags']; $description = $nocache ? (string) $filter->description : $filter['description']; $this->addFilter(new IDS_Filter($id, $rule, $description, (array) $tags[0], (int) $impact)); $data[] = array( 'id' => $id, 'rule' => $rule, 'impact' => $impact, 'tags' => $tags, 'description' => $description ); } /* * If caching is enabled, the fetched data will be cached */ if ($this->cacheSettings) { $this->cache->setCache($data); } } else { throw new Exception( 'SimpleXML not loaded.' ); } return $this; }
php
public function getFilterFromXML() { if (extension_loaded('SimpleXML')) { /* * See if filters are already available in the cache */ $filters = $this->_isCached(); /* * If they aren't, parse the source file */ if (!$filters) { if (file_exists($this->source)) { if (LIBXML_VERSION >= 20621) { $filters = simplexml_load_file($this->source, null, LIBXML_COMPACT); } else { $filters = simplexml_load_file($this->source); } } } /* * In case we still don't have any filters loaded and exception * will be thrown */ if (empty($filters)) { throw new Exception( 'XML data could not be loaded.' . ' Make sure you specified the correct path.' ); } /* * Now the storage will be filled with IDS_Filter objects */ $data = array(); $nocache = $filters instanceof SimpleXMLElement; $filters = $nocache ? $filters->filter : $filters; include_once 'IDS/Filter.php'; foreach ($filters as $filter) { $id = $nocache ? (string) $filter->id : $filter['id']; $rule = $nocache ? (string) $filter->rule : $filter['rule']; $impact = $nocache ? (string) $filter->impact : $filter['impact']; $tags = $nocache ? array_values((array) $filter->tags) : $filter['tags']; $description = $nocache ? (string) $filter->description : $filter['description']; $this->addFilter(new IDS_Filter($id, $rule, $description, (array) $tags[0], (int) $impact)); $data[] = array( 'id' => $id, 'rule' => $rule, 'impact' => $impact, 'tags' => $tags, 'description' => $description ); } /* * If caching is enabled, the fetched data will be cached */ if ($this->cacheSettings) { $this->cache->setCache($data); } } else { throw new Exception( 'SimpleXML not loaded.' ); } return $this; }
[ "public", "function", "getFilterFromXML", "(", ")", "{", "if", "(", "extension_loaded", "(", "'SimpleXML'", ")", ")", "{", "/*\n * See if filters are already available in the cache\n */", "$", "filters", "=", "$", "this", "->", "_isCached", "(", ")", ";", "/*\n * If they aren't, parse the source file\n */", "if", "(", "!", "$", "filters", ")", "{", "if", "(", "file_exists", "(", "$", "this", "->", "source", ")", ")", "{", "if", "(", "LIBXML_VERSION", ">=", "20621", ")", "{", "$", "filters", "=", "simplexml_load_file", "(", "$", "this", "->", "source", ",", "null", ",", "LIBXML_COMPACT", ")", ";", "}", "else", "{", "$", "filters", "=", "simplexml_load_file", "(", "$", "this", "->", "source", ")", ";", "}", "}", "}", "/*\n * In case we still don't have any filters loaded and exception\n * will be thrown\n */", "if", "(", "empty", "(", "$", "filters", ")", ")", "{", "throw", "new", "Exception", "(", "'XML data could not be loaded.'", ".", "' Make sure you specified the correct path.'", ")", ";", "}", "/*\n * Now the storage will be filled with IDS_Filter objects\n */", "$", "data", "=", "array", "(", ")", ";", "$", "nocache", "=", "$", "filters", "instanceof", "SimpleXMLElement", ";", "$", "filters", "=", "$", "nocache", "?", "$", "filters", "->", "filter", ":", "$", "filters", ";", "include_once", "'IDS/Filter.php'", ";", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "id", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "id", ":", "$", "filter", "[", "'id'", "]", ";", "$", "rule", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "rule", ":", "$", "filter", "[", "'rule'", "]", ";", "$", "impact", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "impact", ":", "$", "filter", "[", "'impact'", "]", ";", "$", "tags", "=", "$", "nocache", "?", "array_values", "(", "(", "array", ")", "$", "filter", "->", "tags", ")", ":", "$", "filter", "[", "'tags'", "]", ";", "$", "description", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "description", ":", "$", "filter", "[", "'description'", "]", ";", "$", "this", "->", "addFilter", "(", "new", "IDS_Filter", "(", "$", "id", ",", "$", "rule", ",", "$", "description", ",", "(", "array", ")", "$", "tags", "[", "0", "]", ",", "(", "int", ")", "$", "impact", ")", ")", ";", "$", "data", "[", "]", "=", "array", "(", "'id'", "=>", "$", "id", ",", "'rule'", "=>", "$", "rule", ",", "'impact'", "=>", "$", "impact", ",", "'tags'", "=>", "$", "tags", ",", "'description'", "=>", "$", "description", ")", ";", "}", "/*\n * If caching is enabled, the fetched data will be cached\n */", "if", "(", "$", "this", "->", "cacheSettings", ")", "{", "$", "this", "->", "cache", "->", "setCache", "(", "$", "data", ")", ";", "}", "}", "else", "{", "throw", "new", "Exception", "(", "'SimpleXML not loaded.'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Loads filters from XML using SimpleXML This function parses the provided source file and stores the result. If caching mode is enabled the result will be cached to increase the performance. @throws Exception if problems with fetching the XML data occur @return object $this
[ "Loads", "filters", "from", "XML", "using", "SimpleXML" ]
train
https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Filter/Storage.php#L190-L278
ZendExperts/phpids
lib/IDS/Filter/Storage.php
IDS_Filter_Storage.getFilterFromJson
public function getFilterFromJson() { if (extension_loaded('Json')) { /* * See if filters are already available in the cache */ $filters = $this->_isCached(); /* * If they aren't, parse the source file */ if (!$filters) { if (file_exists($this->source)) { $filters = json_decode(file_get_contents($this->source)); } else { throw new Exception( 'JSON data could not be loaded.' . ' Make sure you specified the correct path.' ); } } if (!$filters) { throw new Exception( 'JSON data could not be loaded.' . ' Make sure you specified the correct path.' ); } /* * Now the storage will be filled with IDS_Filter objects */ $data = array(); $nocache = !is_array($filters); $filters = $nocache ? $filters->filters->filter : $filters; include_once 'IDS/Filter.php'; foreach ($filters as $filter) { $id = $nocache ? (string) $filter->id : $filter['id']; $rule = $nocache ? (string) $filter->rule : $filter['rule']; $impact = $nocache ? (string) $filter->impact : $filter['impact']; $tags = $nocache ? array_values((array) $filter->tags) : $filter['tags']; $description = $nocache ? (string) $filter->description : $filter['description']; $this->addFilter(new IDS_Filter($id, $rule, $description, (array) $tags[0], (int) $impact)); $data[] = array( 'id' => $id, 'rule' => $rule, 'impact' => $impact, 'tags' => $tags, 'description' => $description ); } /* * If caching is enabled, the fetched data will be cached */ if ($this->cacheSettings) { $this->cache->setCache($data); } } else { throw new Exception( 'ext/json not loaded.' ); } return $this; }
php
public function getFilterFromJson() { if (extension_loaded('Json')) { /* * See if filters are already available in the cache */ $filters = $this->_isCached(); /* * If they aren't, parse the source file */ if (!$filters) { if (file_exists($this->source)) { $filters = json_decode(file_get_contents($this->source)); } else { throw new Exception( 'JSON data could not be loaded.' . ' Make sure you specified the correct path.' ); } } if (!$filters) { throw new Exception( 'JSON data could not be loaded.' . ' Make sure you specified the correct path.' ); } /* * Now the storage will be filled with IDS_Filter objects */ $data = array(); $nocache = !is_array($filters); $filters = $nocache ? $filters->filters->filter : $filters; include_once 'IDS/Filter.php'; foreach ($filters as $filter) { $id = $nocache ? (string) $filter->id : $filter['id']; $rule = $nocache ? (string) $filter->rule : $filter['rule']; $impact = $nocache ? (string) $filter->impact : $filter['impact']; $tags = $nocache ? array_values((array) $filter->tags) : $filter['tags']; $description = $nocache ? (string) $filter->description : $filter['description']; $this->addFilter(new IDS_Filter($id, $rule, $description, (array) $tags[0], (int) $impact)); $data[] = array( 'id' => $id, 'rule' => $rule, 'impact' => $impact, 'tags' => $tags, 'description' => $description ); } /* * If caching is enabled, the fetched data will be cached */ if ($this->cacheSettings) { $this->cache->setCache($data); } } else { throw new Exception( 'ext/json not loaded.' ); } return $this; }
[ "public", "function", "getFilterFromJson", "(", ")", "{", "if", "(", "extension_loaded", "(", "'Json'", ")", ")", "{", "/*\n * See if filters are already available in the cache\n */", "$", "filters", "=", "$", "this", "->", "_isCached", "(", ")", ";", "/*\n * If they aren't, parse the source file\n */", "if", "(", "!", "$", "filters", ")", "{", "if", "(", "file_exists", "(", "$", "this", "->", "source", ")", ")", "{", "$", "filters", "=", "json_decode", "(", "file_get_contents", "(", "$", "this", "->", "source", ")", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'JSON data could not be loaded.'", ".", "' Make sure you specified the correct path.'", ")", ";", "}", "}", "if", "(", "!", "$", "filters", ")", "{", "throw", "new", "Exception", "(", "'JSON data could not be loaded.'", ".", "' Make sure you specified the correct path.'", ")", ";", "}", "/*\n * Now the storage will be filled with IDS_Filter objects\n */", "$", "data", "=", "array", "(", ")", ";", "$", "nocache", "=", "!", "is_array", "(", "$", "filters", ")", ";", "$", "filters", "=", "$", "nocache", "?", "$", "filters", "->", "filters", "->", "filter", ":", "$", "filters", ";", "include_once", "'IDS/Filter.php'", ";", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "id", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "id", ":", "$", "filter", "[", "'id'", "]", ";", "$", "rule", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "rule", ":", "$", "filter", "[", "'rule'", "]", ";", "$", "impact", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "impact", ":", "$", "filter", "[", "'impact'", "]", ";", "$", "tags", "=", "$", "nocache", "?", "array_values", "(", "(", "array", ")", "$", "filter", "->", "tags", ")", ":", "$", "filter", "[", "'tags'", "]", ";", "$", "description", "=", "$", "nocache", "?", "(", "string", ")", "$", "filter", "->", "description", ":", "$", "filter", "[", "'description'", "]", ";", "$", "this", "->", "addFilter", "(", "new", "IDS_Filter", "(", "$", "id", ",", "$", "rule", ",", "$", "description", ",", "(", "array", ")", "$", "tags", "[", "0", "]", ",", "(", "int", ")", "$", "impact", ")", ")", ";", "$", "data", "[", "]", "=", "array", "(", "'id'", "=>", "$", "id", ",", "'rule'", "=>", "$", "rule", ",", "'impact'", "=>", "$", "impact", ",", "'tags'", "=>", "$", "tags", ",", "'description'", "=>", "$", "description", ")", ";", "}", "/*\n * If caching is enabled, the fetched data will be cached\n */", "if", "(", "$", "this", "->", "cacheSettings", ")", "{", "$", "this", "->", "cache", "->", "setCache", "(", "$", "data", ")", ";", "}", "}", "else", "{", "throw", "new", "Exception", "(", "'ext/json not loaded.'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Loads filters from Json file using ext/Json This function parses the provided source file and stores the result. If caching mode is enabled the result will be cached to increase the performance. @throws Exception if problems with fetching the JSON data occur @return object $this
[ "Loads", "filters", "from", "Json", "file", "using", "ext", "/", "Json" ]
train
https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Filter/Storage.php#L290-L372
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.initialize
public function initialize ($routepath) { // Set path $this->routepath = $routepath; // Add templates Template::addPath (__DIR__ . '/templates/', 'CatLab/Accounts/'); // Add locales Text::getInstance ()->addPath ('catlab.accounts', __DIR__ . '/locales/'); // Set session variable Application::getInstance ()->on ('dispatch:before', array ($this, 'setRequestUser')); // Set the global user mapper, unless one is set already Application::getInstance ()->on ('dispatch:first', array ($this, 'setUserMapper')); // Add helper methods $helper = new LoginForm ($this); Template::addHelper ('CatLab.Accounts.LoginForm', $helper); }
php
public function initialize ($routepath) { // Set path $this->routepath = $routepath; // Add templates Template::addPath (__DIR__ . '/templates/', 'CatLab/Accounts/'); // Add locales Text::getInstance ()->addPath ('catlab.accounts', __DIR__ . '/locales/'); // Set session variable Application::getInstance ()->on ('dispatch:before', array ($this, 'setRequestUser')); // Set the global user mapper, unless one is set already Application::getInstance ()->on ('dispatch:first', array ($this, 'setUserMapper')); // Add helper methods $helper = new LoginForm ($this); Template::addHelper ('CatLab.Accounts.LoginForm', $helper); }
[ "public", "function", "initialize", "(", "$", "routepath", ")", "{", "// Set path", "$", "this", "->", "routepath", "=", "$", "routepath", ";", "// Add templates", "Template", "::", "addPath", "(", "__DIR__", ".", "'/templates/'", ",", "'CatLab/Accounts/'", ")", ";", "// Add locales", "Text", "::", "getInstance", "(", ")", "->", "addPath", "(", "'catlab.accounts'", ",", "__DIR__", ".", "'/locales/'", ")", ";", "// Set session variable", "Application", "::", "getInstance", "(", ")", "->", "on", "(", "'dispatch:before'", ",", "array", "(", "$", "this", ",", "'setRequestUser'", ")", ")", ";", "// Set the global user mapper, unless one is set already", "Application", "::", "getInstance", "(", ")", "->", "on", "(", "'dispatch:first'", ",", "array", "(", "$", "this", ",", "'setUserMapper'", ")", ")", ";", "// Add helper methods", "$", "helper", "=", "new", "LoginForm", "(", "$", "this", ")", ";", "Template", "::", "addHelper", "(", "'CatLab.Accounts.LoginForm'", ",", "$", "helper", ")", ";", "}" ]
Set template paths, config vars, etc @param string $routepath The prefix that should be added to all route paths. @return void
[ "Set", "template", "paths", "config", "vars", "etc" ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L56-L77
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.setRequestUser
public function setRequestUser (Request $request) { $request->addUserCallback ('accounts', function (Request $request) { $userid = $request->getSession ()->get ('catlab-user-id'); if ($userid) { $user = MapperFactory::getUserMapper ()->getFromId ($userid); if ($user) return $user; } return null; }); }
php
public function setRequestUser (Request $request) { $request->addUserCallback ('accounts', function (Request $request) { $userid = $request->getSession ()->get ('catlab-user-id'); if ($userid) { $user = MapperFactory::getUserMapper ()->getFromId ($userid); if ($user) return $user; } return null; }); }
[ "public", "function", "setRequestUser", "(", "Request", "$", "request", ")", "{", "$", "request", "->", "addUserCallback", "(", "'accounts'", ",", "function", "(", "Request", "$", "request", ")", "{", "$", "userid", "=", "$", "request", "->", "getSession", "(", ")", "->", "get", "(", "'catlab-user-id'", ")", ";", "if", "(", "$", "userid", ")", "{", "$", "user", "=", "MapperFactory", "::", "getUserMapper", "(", ")", "->", "getFromId", "(", "$", "userid", ")", ";", "if", "(", "$", "user", ")", "return", "$", "user", ";", "}", "return", "null", ";", "}", ")", ";", "}" ]
Set user from session @param Request $request @throws \Neuron\Exceptions\InvalidParameter
[ "Set", "user", "from", "session" ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L84-L99
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.login
public function login (Request $request, User $user, $registration = false) { // Check for email validation if ($this->requiresEmailValidation()) { if (!$user->isEmailVerified()) { $request->getSession()->set ('catlab-non-verified-user-id', $user->getId()); return Response::redirect(URLBuilder::getURL($this->routepath . '/notverified')); } } $request->getSession()->set('catlab-user-id', $user->getId()); return $this->postLogin($request, $user, $registration); }
php
public function login (Request $request, User $user, $registration = false) { // Check for email validation if ($this->requiresEmailValidation()) { if (!$user->isEmailVerified()) { $request->getSession()->set ('catlab-non-verified-user-id', $user->getId()); return Response::redirect(URLBuilder::getURL($this->routepath . '/notverified')); } } $request->getSession()->set('catlab-user-id', $user->getId()); return $this->postLogin($request, $user, $registration); }
[ "public", "function", "login", "(", "Request", "$", "request", ",", "User", "$", "user", ",", "$", "registration", "=", "false", ")", "{", "// Check for email validation", "if", "(", "$", "this", "->", "requiresEmailValidation", "(", ")", ")", "{", "if", "(", "!", "$", "user", "->", "isEmailVerified", "(", ")", ")", "{", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'catlab-non-verified-user-id'", ",", "$", "user", "->", "getId", "(", ")", ")", ";", "return", "Response", "::", "redirect", "(", "URLBuilder", "::", "getURL", "(", "$", "this", "->", "routepath", ".", "'/notverified'", ")", ")", ";", "}", "}", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'catlab-user-id'", ",", "$", "user", "->", "getId", "(", ")", ")", ";", "return", "$", "this", "->", "postLogin", "(", "$", "request", ",", "$", "user", ",", "$", "registration", ")", ";", "}" ]
Login a specific user @param Request $request @param User $user @param bool $registration @return \Neuron\Net\Response @throws DataNotSet
[ "Login", "a", "specific", "user" ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L141-L153
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.logout
public function logout (Request $request) { $request->getSession ()->set ('catlab-user-id', null); $request->getSession ()->set ('catlab-non-verified-user-id', null); return $this->postLogout ($request); }
php
public function logout (Request $request) { $request->getSession ()->set ('catlab-user-id', null); $request->getSession ()->set ('catlab-non-verified-user-id', null); return $this->postLogout ($request); }
[ "public", "function", "logout", "(", "Request", "$", "request", ")", "{", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'catlab-user-id'", ",", "null", ")", ";", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'catlab-non-verified-user-id'", ",", "null", ")", ";", "return", "$", "this", "->", "postLogout", "(", "$", "request", ")", ";", "}" ]
Logout user @param Request $request @throws \Neuron\Exceptions\DataNotSet @return \Neuron\Net\Response
[ "Logout", "user" ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L161-L166
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.postLogin
public function postLogin (Request $request, \Neuron\Interfaces\Models\User $user, $registered = false) { $parameters = array(); if ($registered) { $parameters['registered'] = 1; } // Also set in session... why wouldn't this be in session? :D $request->getSession()->set('userJustRegistered', $registered); $this->trigger('user:login', [ 'request' => $request, 'user' => $user, 'registered' => $registered ]); // Should skip welcome screen? if ($request->getSession()->get('skip-welcome-redirect')) { $redirectUrl = $this->getAndClearPostLoginRedirect($request); return Response::redirect($redirectUrl); } return $this->redirectToWelcome ([]); }
php
public function postLogin (Request $request, \Neuron\Interfaces\Models\User $user, $registered = false) { $parameters = array(); if ($registered) { $parameters['registered'] = 1; } // Also set in session... why wouldn't this be in session? :D $request->getSession()->set('userJustRegistered', $registered); $this->trigger('user:login', [ 'request' => $request, 'user' => $user, 'registered' => $registered ]); // Should skip welcome screen? if ($request->getSession()->get('skip-welcome-redirect')) { $redirectUrl = $this->getAndClearPostLoginRedirect($request); return Response::redirect($redirectUrl); } return $this->redirectToWelcome ([]); }
[ "public", "function", "postLogin", "(", "Request", "$", "request", ",", "\\", "Neuron", "\\", "Interfaces", "\\", "Models", "\\", "User", "$", "user", ",", "$", "registered", "=", "false", ")", "{", "$", "parameters", "=", "array", "(", ")", ";", "if", "(", "$", "registered", ")", "{", "$", "parameters", "[", "'registered'", "]", "=", "1", ";", "}", "// Also set in session... why wouldn't this be in session? :D", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'userJustRegistered'", ",", "$", "registered", ")", ";", "$", "this", "->", "trigger", "(", "'user:login'", ",", "[", "'request'", "=>", "$", "request", ",", "'user'", "=>", "$", "user", ",", "'registered'", "=>", "$", "registered", "]", ")", ";", "// Should skip welcome screen?", "if", "(", "$", "request", "->", "getSession", "(", ")", "->", "get", "(", "'skip-welcome-redirect'", ")", ")", "{", "$", "redirectUrl", "=", "$", "this", "->", "getAndClearPostLoginRedirect", "(", "$", "request", ")", ";", "return", "Response", "::", "redirect", "(", "$", "redirectUrl", ")", ";", "}", "return", "$", "this", "->", "redirectToWelcome", "(", "[", "]", ")", ";", "}" ]
Called right after a user is logged in. Should be a redirect. @param Request $request @param \Neuron\Interfaces\Models\User $user @param boolean $registered @return \Neuron\Net\Response @throws DataNotSet
[ "Called", "right", "after", "a", "user", "is", "logged", "in", ".", "Should", "be", "a", "redirect", "." ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L177-L200
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.postLogout
public function postLogout (Request $request) { if ($redirect = $request->getSession ()->get ('post-login-redirect')) { $request->getSession ()->set ('post-login-redirect', null); $request->getSession ()->set ('cancel-login-redirect', null); return Response::redirect ($redirect); } return Response::redirect (URLBuilder::getURL ('/')); }
php
public function postLogout (Request $request) { if ($redirect = $request->getSession ()->get ('post-login-redirect')) { $request->getSession ()->set ('post-login-redirect', null); $request->getSession ()->set ('cancel-login-redirect', null); return Response::redirect ($redirect); } return Response::redirect (URLBuilder::getURL ('/')); }
[ "public", "function", "postLogout", "(", "Request", "$", "request", ")", "{", "if", "(", "$", "redirect", "=", "$", "request", "->", "getSession", "(", ")", "->", "get", "(", "'post-login-redirect'", ")", ")", "{", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'post-login-redirect'", ",", "null", ")", ";", "$", "request", "->", "getSession", "(", ")", "->", "set", "(", "'cancel-login-redirect'", ",", "null", ")", ";", "return", "Response", "::", "redirect", "(", "$", "redirect", ")", ";", "}", "return", "Response", "::", "redirect", "(", "URLBuilder", "::", "getURL", "(", "'/'", ")", ")", ";", "}" ]
Called after a redirect @param Request $request @return Response @throws DataNotSet
[ "Called", "after", "a", "redirect" ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L223-L234
CatLabInteractive/Accounts
src/CatLab/Accounts/Module.php
Module.setRoutes
public function setRoutes (Router $router) { // Filter $router->addFilter ('authenticated', array ($this, 'routerVerifier')); // Routes $router->match ('GET|POST', $this->routepath . '/login/{authenticator}', '\CatLab\Accounts\Controllers\LoginController@authenticator'); $router->match ('GET', $this->routepath . '/login', '\CatLab\Accounts\Controllers\LoginController@login'); $router->match ('GET', $this->routepath . '/welcome', '\CatLab\Accounts\Controllers\LoginController@welcome')->filter('authenticated'); $router->match ('GET|POST', $this->routepath . '/notverified', '\CatLab\Accounts\Controllers\LoginController@requiresVerification'); $router->match ('GET', $this->routepath . '/logout', '\CatLab\Accounts\Controllers\LoginController@logout'); $router->match ('GET', $this->routepath . '/cancel', '\CatLab\Accounts\Controllers\LoginController@cancel'); $router->match ('GET|POST', $this->routepath . '/register/{authenticator}', '\CatLab\Accounts\Controllers\RegistrationController@authenticator'); $router->match ('GET|POST', $this->routepath . '/register', '\CatLab\Accounts\Controllers\RegistrationController@register'); $router->get ($this->routepath . '/verify/{id}', '\CatLab\Accounts\Controllers\LoginController@verify'); }
php
public function setRoutes (Router $router) { // Filter $router->addFilter ('authenticated', array ($this, 'routerVerifier')); // Routes $router->match ('GET|POST', $this->routepath . '/login/{authenticator}', '\CatLab\Accounts\Controllers\LoginController@authenticator'); $router->match ('GET', $this->routepath . '/login', '\CatLab\Accounts\Controllers\LoginController@login'); $router->match ('GET', $this->routepath . '/welcome', '\CatLab\Accounts\Controllers\LoginController@welcome')->filter('authenticated'); $router->match ('GET|POST', $this->routepath . '/notverified', '\CatLab\Accounts\Controllers\LoginController@requiresVerification'); $router->match ('GET', $this->routepath . '/logout', '\CatLab\Accounts\Controllers\LoginController@logout'); $router->match ('GET', $this->routepath . '/cancel', '\CatLab\Accounts\Controllers\LoginController@cancel'); $router->match ('GET|POST', $this->routepath . '/register/{authenticator}', '\CatLab\Accounts\Controllers\RegistrationController@authenticator'); $router->match ('GET|POST', $this->routepath . '/register', '\CatLab\Accounts\Controllers\RegistrationController@register'); $router->get ($this->routepath . '/verify/{id}', '\CatLab\Accounts\Controllers\LoginController@verify'); }
[ "public", "function", "setRoutes", "(", "Router", "$", "router", ")", "{", "// Filter", "$", "router", "->", "addFilter", "(", "'authenticated'", ",", "array", "(", "$", "this", ",", "'routerVerifier'", ")", ")", ";", "// Routes", "$", "router", "->", "match", "(", "'GET|POST'", ",", "$", "this", "->", "routepath", ".", "'/login/{authenticator}'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@authenticator'", ")", ";", "$", "router", "->", "match", "(", "'GET'", ",", "$", "this", "->", "routepath", ".", "'/login'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@login'", ")", ";", "$", "router", "->", "match", "(", "'GET'", ",", "$", "this", "->", "routepath", ".", "'/welcome'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@welcome'", ")", "->", "filter", "(", "'authenticated'", ")", ";", "$", "router", "->", "match", "(", "'GET|POST'", ",", "$", "this", "->", "routepath", ".", "'/notverified'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@requiresVerification'", ")", ";", "$", "router", "->", "match", "(", "'GET'", ",", "$", "this", "->", "routepath", ".", "'/logout'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@logout'", ")", ";", "$", "router", "->", "match", "(", "'GET'", ",", "$", "this", "->", "routepath", ".", "'/cancel'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@cancel'", ")", ";", "$", "router", "->", "match", "(", "'GET|POST'", ",", "$", "this", "->", "routepath", ".", "'/register/{authenticator}'", ",", "'\\CatLab\\Accounts\\Controllers\\RegistrationController@authenticator'", ")", ";", "$", "router", "->", "match", "(", "'GET|POST'", ",", "$", "this", "->", "routepath", ".", "'/register'", ",", "'\\CatLab\\Accounts\\Controllers\\RegistrationController@register'", ")", ";", "$", "router", "->", "get", "(", "$", "this", "->", "routepath", ".", "'/verify/{id}'", ",", "'\\CatLab\\Accounts\\Controllers\\LoginController@verify'", ")", ";", "}" ]
Register the routes required for this module. @param Router $router @return mixed
[ "Register", "the", "routes", "required", "for", "this", "module", "." ]
train
https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Module.php#L249-L269
aloframework/common
src/Alo.php
Alo.asciiRand
public static function asciiRand($length, $subset = self::ASCII_ALL) { switch ($subset) { case self::ASCII_ALPHANUM: $subset = self::$asciiAlphanum; break; case self::ASCII_NONALPHANUM: $subset = self::$asciNonAlphanum; break; default: $subset = array_merge(self::$asciiAlphanum, self::$asciNonAlphanum); } $count = count($subset) - 1; $r = ''; for ($i = 0; $i < $length; $i++) { $r .= $subset[mt_rand(0, $count)]; } return $r; }
php
public static function asciiRand($length, $subset = self::ASCII_ALL) { switch ($subset) { case self::ASCII_ALPHANUM: $subset = self::$asciiAlphanum; break; case self::ASCII_NONALPHANUM: $subset = self::$asciNonAlphanum; break; default: $subset = array_merge(self::$asciiAlphanum, self::$asciNonAlphanum); } $count = count($subset) - 1; $r = ''; for ($i = 0; $i < $length; $i++) { $r .= $subset[mt_rand(0, $count)]; } return $r; }
[ "public", "static", "function", "asciiRand", "(", "$", "length", ",", "$", "subset", "=", "self", "::", "ASCII_ALL", ")", "{", "switch", "(", "$", "subset", ")", "{", "case", "self", "::", "ASCII_ALPHANUM", ":", "$", "subset", "=", "self", "::", "$", "asciiAlphanum", ";", "break", ";", "case", "self", "::", "ASCII_NONALPHANUM", ":", "$", "subset", "=", "self", "::", "$", "asciNonAlphanum", ";", "break", ";", "default", ":", "$", "subset", "=", "array_merge", "(", "self", "::", "$", "asciiAlphanum", ",", "self", "::", "$", "asciNonAlphanum", ")", ";", "}", "$", "count", "=", "count", "(", "$", "subset", ")", "-", "1", ";", "$", "r", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "r", ".=", "$", "subset", "[", "mt_rand", "(", "0", ",", "$", "count", ")", "]", ";", "}", "return", "$", "r", ";", "}" ]
Generates a string of random ASCII characters @author Art <[email protected]> @param int $length The length of the string @param int $subset Which subset to use - see class' ASCII_* constants @return string @since 1.3
[ "Generates", "a", "string", "of", "random", "ASCII", "characters" ]
train
https://github.com/aloframework/common/blob/484ef76ea5e1b99b2758e5c35c76229572dc27cb/src/Alo.php#L189-L210
aloframework/common
src/Alo.php
Alo.getUniqid
public static function getUniqid($hash = 'sha256', $prefix = '', $entropy = 10000, $rawOutput = false) { $str = mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . json_encode([$_COOKIE, $_REQUEST, $_FILES, $_ENV, $_GET, $_POST, $_SERVER]) . uniqid($prefix, true) . self::asciiRand($entropy, self::ASCII_ALL); if (function_exists('\openssl_random_pseudo_bytes')) { $algoStrong = null; $str .= \openssl_random_pseudo_bytes($entropy, $algoStrong); if ($algoStrong !== true) { trigger_error('Please update your openssl & PHP libraries. openssl_random_pseudo_bytes was unable' . ' to locate a cryptographically strong algorithm.', E_USER_WARNING); } } else { trigger_error('The openssl extension is not enabled, therefore the unique ID is not ' . 'cryptographically secure.', E_USER_WARNING); } return hash($hash, $str, $rawOutput); }
php
public static function getUniqid($hash = 'sha256', $prefix = '', $entropy = 10000, $rawOutput = false) { $str = mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . json_encode([$_COOKIE, $_REQUEST, $_FILES, $_ENV, $_GET, $_POST, $_SERVER]) . uniqid($prefix, true) . self::asciiRand($entropy, self::ASCII_ALL); if (function_exists('\openssl_random_pseudo_bytes')) { $algoStrong = null; $str .= \openssl_random_pseudo_bytes($entropy, $algoStrong); if ($algoStrong !== true) { trigger_error('Please update your openssl & PHP libraries. openssl_random_pseudo_bytes was unable' . ' to locate a cryptographically strong algorithm.', E_USER_WARNING); } } else { trigger_error('The openssl extension is not enabled, therefore the unique ID is not ' . 'cryptographically secure.', E_USER_WARNING); } return hash($hash, $str, $rawOutput); }
[ "public", "static", "function", "getUniqid", "(", "$", "hash", "=", "'sha256'", ",", "$", "prefix", "=", "''", ",", "$", "entropy", "=", "10000", ",", "$", "rawOutput", "=", "false", ")", "{", "$", "str", "=", "mt_rand", "(", "~", "PHP_INT_MAX", ",", "PHP_INT_MAX", ")", ".", "json_encode", "(", "[", "$", "_COOKIE", ",", "$", "_REQUEST", ",", "$", "_FILES", ",", "$", "_ENV", ",", "$", "_GET", ",", "$", "_POST", ",", "$", "_SERVER", "]", ")", ".", "uniqid", "(", "$", "prefix", ",", "true", ")", ".", "self", "::", "asciiRand", "(", "$", "entropy", ",", "self", "::", "ASCII_ALL", ")", ";", "if", "(", "function_exists", "(", "'\\openssl_random_pseudo_bytes'", ")", ")", "{", "$", "algoStrong", "=", "null", ";", "$", "str", ".=", "\\", "openssl_random_pseudo_bytes", "(", "$", "entropy", ",", "$", "algoStrong", ")", ";", "if", "(", "$", "algoStrong", "!==", "true", ")", "{", "trigger_error", "(", "'Please update your openssl & PHP libraries. openssl_random_pseudo_bytes was unable'", ".", "' to locate a cryptographically strong algorithm.'", ",", "E_USER_WARNING", ")", ";", "}", "}", "else", "{", "trigger_error", "(", "'The openssl extension is not enabled, therefore the unique ID is not '", ".", "'cryptographically secure.'", ",", "E_USER_WARNING", ")", ";", "}", "return", "hash", "(", "$", "hash", ",", "$", "str", ",", "$", "rawOutput", ")", ";", "}" ]
Generates a unique identifier @author Art <[email protected]> @param string $hash Hash algorithm @param string $prefix Prefix for the identifier @param int $entropy Number of pseudo bytes used in entropy @param bool $rawOutput When set to true, outputs raw binary data. false outputs lowercase hexits. @return string @see https://secure.php.net/manual/en/function.hash.php @see https://secure.php.net/manual/en/function.openssl-random-pseudo-bytes.php @since 1.3.3 Default $entropy value set to 10000, a warning is triggered if openssl_random_pseudo_bytes is unable to locate a cryptographically strong algorithm.<br/> 1.3 @codeCoverageIgnore
[ "Generates", "a", "unique", "identifier" ]
train
https://github.com/aloframework/common/blob/484ef76ea5e1b99b2758e5c35c76229572dc27cb/src/Alo.php#L230-L256
aloframework/common
src/Alo.php
Alo.ifnull
public static function ifnull(&$var, $planB, $useNullget = false) { $v = $useNullget ? self::nullget($var) : self::get($var); return $v !== null ? $v : $planB; }
php
public static function ifnull(&$var, $planB, $useNullget = false) { $v = $useNullget ? self::nullget($var) : self::get($var); return $v !== null ? $v : $planB; }
[ "public", "static", "function", "ifnull", "(", "&", "$", "var", ",", "$", "planB", ",", "$", "useNullget", "=", "false", ")", "{", "$", "v", "=", "$", "useNullget", "?", "self", "::", "nullget", "(", "$", "var", ")", ":", "self", "::", "get", "(", "$", "var", ")", ";", "return", "$", "v", "!==", "null", "?", "$", "v", ":", "$", "planB", ";", "}" ]
Returns $var if it's set $planB if it's not @author Art <[email protected]> @param mixed $var Reference to the main variable @param mixed $planB What to return if $var isn't available @param bool $useNullget If set to true, will use self::nullget(), otherwise will use self::get() to determinewhether $var is set @return mixed $var if available, $planB if not
[ "Returns", "$var", "if", "it", "s", "set", "$planB", "if", "it", "s", "not" ]
train
https://github.com/aloframework/common/blob/484ef76ea5e1b99b2758e5c35c76229572dc27cb/src/Alo.php#L347-L351
aloframework/common
src/Alo.php
Alo.getFingerprint
public static function getFingerprint($hashAlgo = 'sha256') { return hash($hashAlgo, '#QramRAN7*s%6n%@x*53jVVPsnrz@5MY$49o^mhJ8HqY%3a09yJnSWg9lBl$O4CKUb&&S%EgYBjhUZEbhquw$keCjR6I%zMcA!Qr' . self::get($_SERVER['HTTP_USER_AGENT']) . 'OE2%fWaZh4jfZPiNXKmHfUw6ok6Z0s#PInaFa8&o#xh#nVyaFaXHPUcv^2y579PnYr5AOs6Zqb!QTAZCgRR968*%QxKc^XNuYYM8' . self::get($_SERVER['HTTP_DNT']) . '%CwyJJ^GAooDl&o0mc%7zbWlD^6tWoNSN&m3cKxWLP8kiBqO!j2PM5wACzyOoa^t7AEJ#FlDT!BMtD$luy%2iZejMVzktaiftpg*' . self::get($_SERVER['HTTP_ACCEPT_LANGUAGE']) . 'tep!uTwVXk1CedJq0osEI7p&XCxnC3ipGDWEpTXULEg8J!K1NJSxe4GPor$R3OOb**ZjzPN$$SOHe4ZDcQWQULdtT&XxP2!YYxZy'); }
php
public static function getFingerprint($hashAlgo = 'sha256') { return hash($hashAlgo, '#QramRAN7*s%6n%@x*53jVVPsnrz@5MY$49o^mhJ8HqY%3a09yJnSWg9lBl$O4CKUb&&S%EgYBjhUZEbhquw$keCjR6I%zMcA!Qr' . self::get($_SERVER['HTTP_USER_AGENT']) . 'OE2%fWaZh4jfZPiNXKmHfUw6ok6Z0s#PInaFa8&o#xh#nVyaFaXHPUcv^2y579PnYr5AOs6Zqb!QTAZCgRR968*%QxKc^XNuYYM8' . self::get($_SERVER['HTTP_DNT']) . '%CwyJJ^GAooDl&o0mc%7zbWlD^6tWoNSN&m3cKxWLP8kiBqO!j2PM5wACzyOoa^t7AEJ#FlDT!BMtD$luy%2iZejMVzktaiftpg*' . self::get($_SERVER['HTTP_ACCEPT_LANGUAGE']) . 'tep!uTwVXk1CedJq0osEI7p&XCxnC3ipGDWEpTXULEg8J!K1NJSxe4GPor$R3OOb**ZjzPN$$SOHe4ZDcQWQULdtT&XxP2!YYxZy'); }
[ "public", "static", "function", "getFingerprint", "(", "$", "hashAlgo", "=", "'sha256'", ")", "{", "return", "hash", "(", "$", "hashAlgo", ",", "'#QramRAN7*s%6n%@x*53jVVPsnrz@5MY$49o^mhJ8HqY%3a09yJnSWg9lBl$O4CKUb&&S%EgYBjhUZEbhquw$keCjR6I%zMcA!Qr'", ".", "self", "::", "get", "(", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", ".", "'OE2%fWaZh4jfZPiNXKmHfUw6ok6Z0s#PInaFa8&o#xh#nVyaFaXHPUcv^2y579PnYr5AOs6Zqb!QTAZCgRR968*%QxKc^XNuYYM8'", ".", "self", "::", "get", "(", "$", "_SERVER", "[", "'HTTP_DNT'", "]", ")", ".", "'%CwyJJ^GAooDl&o0mc%7zbWlD^6tWoNSN&m3cKxWLP8kiBqO!j2PM5wACzyOoa^t7AEJ#FlDT!BMtD$luy%2iZejMVzktaiftpg*'", ".", "self", "::", "get", "(", "$", "_SERVER", "[", "'HTTP_ACCEPT_LANGUAGE'", "]", ")", ".", "'tep!uTwVXk1CedJq0osEI7p&XCxnC3ipGDWEpTXULEg8J!K1NJSxe4GPor$R3OOb**ZjzPN$$SOHe4ZDcQWQULdtT&XxP2!YYxZy'", ")", ";", "}" ]
Returns a hashed browser fingerprint @author Art <[email protected]> @param string $hashAlgo Hash algorithm to use @return string @since 1.2
[ "Returns", "a", "hashed", "browser", "fingerprint" ]
train
https://github.com/aloframework/common/blob/484ef76ea5e1b99b2758e5c35c76229572dc27cb/src/Alo.php#L388-L397
aloframework/common
src/Alo.php
Alo.unXss
public static function unXss($input) { if (self::isTraversable($input)) { foreach ($input as &$i) { $i = self::unXss($i); } } elseif (is_scalar($input)) { $input = htmlspecialchars($input, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE); } return $input; }
php
public static function unXss($input) { if (self::isTraversable($input)) { foreach ($input as &$i) { $i = self::unXss($i); } } elseif (is_scalar($input)) { $input = htmlspecialchars($input, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE); } return $input; }
[ "public", "static", "function", "unXss", "(", "$", "input", ")", "{", "if", "(", "self", "::", "isTraversable", "(", "$", "input", ")", ")", "{", "foreach", "(", "$", "input", "as", "&", "$", "i", ")", "{", "$", "i", "=", "self", "::", "unXss", "(", "$", "i", ")", ";", "}", "}", "elseif", "(", "is_scalar", "(", "$", "input", ")", ")", "{", "$", "input", "=", "htmlspecialchars", "(", "$", "input", ",", "ENT_QUOTES", "|", "ENT_HTML5", "|", "ENT_SUBSTITUTE", ")", ";", "}", "return", "$", "input", ";", "}" ]
Protects the input from cross-site scripting attacks @author Art <[email protected]> @param string|array|Traversable $input The scalar input, or an array/Traversable @return string|array|Traversable The escaped string. If an array or traversable was passed on, the input withall its applicable values escaped. @since 1.3.2 ENT_SUBSTITUTE added<br/> 1.2
[ "Protects", "the", "input", "from", "cross", "-", "site", "scripting", "attacks" ]
train
https://github.com/aloframework/common/blob/484ef76ea5e1b99b2758e5c35c76229572dc27cb/src/Alo.php#L425-L435
irfantoor/engine
src/Http/Uri.php
Uri.withUserInfo
public function withUserInfo($user, $password = null) { $clone = clone $this; $clone->user = $user; $clone->pass = $password; $clone->_process(); return $clone; }
php
public function withUserInfo($user, $password = null) { $clone = clone $this; $clone->user = $user; $clone->pass = $password; $clone->_process(); return $clone; }
[ "public", "function", "withUserInfo", "(", "$", "user", ",", "$", "password", "=", "null", ")", "{", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "user", "=", "$", "user", ";", "$", "clone", "->", "pass", "=", "$", "password", ";", "$", "clone", "->", "_process", "(", ")", ";", "return", "$", "clone", ";", "}" ]
Return an instance with the specified user information. This method MUST retain the state of the current instance, and return an instance that contains the specified user information. Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information. @param string $user The user name to use for authority. @param null|string $password The password associated with $user. @return static A new instance with the specified user information.
[ "Return", "an", "instance", "with", "the", "specified", "user", "information", "." ]
train
https://github.com/irfantoor/engine/blob/4d2d221add749f75100d0b4ffe1488cdbf7af5d3/src/Http/Uri.php#L356-L364
mpf-soft/admin-widgets
jqueryfileupload/Uploader.php
Uploader.init
protected function init($config) { parent::init($config); if (!$this->dataUrl) { $this->dataUrl = WebApp::get()->request()->getCurrentURL(); // if dataUrl is not set then current URL will be used; } if ($this->handleRequest) { $this->_handle(); die(); } return true; }
php
protected function init($config) { parent::init($config); if (!$this->dataUrl) { $this->dataUrl = WebApp::get()->request()->getCurrentURL(); // if dataUrl is not set then current URL will be used; } if ($this->handleRequest) { $this->_handle(); die(); } return true; }
[ "protected", "function", "init", "(", "$", "config", ")", "{", "parent", "::", "init", "(", "$", "config", ")", ";", "if", "(", "!", "$", "this", "->", "dataUrl", ")", "{", "$", "this", "->", "dataUrl", "=", "WebApp", "::", "get", "(", ")", "->", "request", "(", ")", "->", "getCurrentURL", "(", ")", ";", "// if dataUrl is not set then current URL will be used;", "}", "if", "(", "$", "this", "->", "handleRequest", ")", "{", "$", "this", "->", "_handle", "(", ")", ";", "die", "(", ")", ";", "}", "return", "true", ";", "}" ]
It will take care of upload and delete requests; @param array $config @return bool @throws \Exception
[ "It", "will", "take", "care", "of", "upload", "and", "delete", "requests", ";" ]
train
https://github.com/mpf-soft/admin-widgets/blob/92597f9a09d086664268d6b7e0111d5a5586d8c7/jqueryfileupload/Uploader.php#L127-L138
mpf-soft/admin-widgets
jqueryfileupload/Uploader.php
Uploader.display
public function display() { $source = str_replace(['{VENDOR}', '{APP_ROOT}'], [LIBS_FOLDER, APP_ROOT], $this->jsSource); $url = AssetsPublisher::get()->publishFolder($source); $events = $this->getJSEvents(); $r = Form::get()->input($this->name . '[]', 'file', null, [ 'id' => $this->id, 'data-url' => $this->dataUrl, 'multiple' => 'multiple', ]) . Html::get()->scriptFile($url . "js/vendor/jquery.ui.widget.js") . Html::get()->scriptFile($url . "js/jquery.iframe-transport.js") . Html::get()->scriptFile($url . "js/jquery.fileupload.js") . Html::get()->script("\$(function () { \$('#{$this->id}').fileupload({ dataType: 'json' " . (isset($this->jsEventsHandlers['fileuploaddone'])?'': ", done: function (e, data) { $.each(data.result.files, function (index, file) { $('<p/>').text(file.name).appendTo($(\"#{$this->resultsId}\")); }); }") . " })$events; });"); if ($this->generateResultsDiv) { $r .= Html::get()->tag("div", "", ["id" => $this->resultsId]); } return $r; }
php
public function display() { $source = str_replace(['{VENDOR}', '{APP_ROOT}'], [LIBS_FOLDER, APP_ROOT], $this->jsSource); $url = AssetsPublisher::get()->publishFolder($source); $events = $this->getJSEvents(); $r = Form::get()->input($this->name . '[]', 'file', null, [ 'id' => $this->id, 'data-url' => $this->dataUrl, 'multiple' => 'multiple', ]) . Html::get()->scriptFile($url . "js/vendor/jquery.ui.widget.js") . Html::get()->scriptFile($url . "js/jquery.iframe-transport.js") . Html::get()->scriptFile($url . "js/jquery.fileupload.js") . Html::get()->script("\$(function () { \$('#{$this->id}').fileupload({ dataType: 'json' " . (isset($this->jsEventsHandlers['fileuploaddone'])?'': ", done: function (e, data) { $.each(data.result.files, function (index, file) { $('<p/>').text(file.name).appendTo($(\"#{$this->resultsId}\")); }); }") . " })$events; });"); if ($this->generateResultsDiv) { $r .= Html::get()->tag("div", "", ["id" => $this->resultsId]); } return $r; }
[ "public", "function", "display", "(", ")", "{", "$", "source", "=", "str_replace", "(", "[", "'{VENDOR}'", ",", "'{APP_ROOT}'", "]", ",", "[", "LIBS_FOLDER", ",", "APP_ROOT", "]", ",", "$", "this", "->", "jsSource", ")", ";", "$", "url", "=", "AssetsPublisher", "::", "get", "(", ")", "->", "publishFolder", "(", "$", "source", ")", ";", "$", "events", "=", "$", "this", "->", "getJSEvents", "(", ")", ";", "$", "r", "=", "Form", "::", "get", "(", ")", "->", "input", "(", "$", "this", "->", "name", ".", "'[]'", ",", "'file'", ",", "null", ",", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'data-url'", "=>", "$", "this", "->", "dataUrl", ",", "'multiple'", "=>", "'multiple'", ",", "]", ")", ".", "Html", "::", "get", "(", ")", "->", "scriptFile", "(", "$", "url", ".", "\"js/vendor/jquery.ui.widget.js\"", ")", ".", "Html", "::", "get", "(", ")", "->", "scriptFile", "(", "$", "url", ".", "\"js/jquery.iframe-transport.js\"", ")", ".", "Html", "::", "get", "(", ")", "->", "scriptFile", "(", "$", "url", ".", "\"js/jquery.fileupload.js\"", ")", ".", "Html", "::", "get", "(", ")", "->", "script", "(", "\"\\$(function () {\n \\$('#{$this->id}').fileupload({\n dataType: 'json' \"", ".", "(", "isset", "(", "$", "this", "->", "jsEventsHandlers", "[", "'fileuploaddone'", "]", ")", "?", "''", ":", "\",\n done: function (e, data) {\n $.each(data.result.files, function (index, file) {\n $('<p/>').text(file.name).appendTo($(\\\"#{$this->resultsId}\\\"));\n });\n }\"", ")", ".", "\"\n })$events;\n});\"", ")", ";", "if", "(", "$", "this", "->", "generateResultsDiv", ")", "{", "$", "r", ".=", "Html", "::", "get", "(", ")", "->", "tag", "(", "\"div\"", ",", "\"\"", ",", "[", "\"id\"", "=>", "$", "this", "->", "resultsId", "]", ")", ";", "}", "return", "$", "r", ";", "}" ]
Returns the HTML code for the element. @return string
[ "Returns", "the", "HTML", "code", "for", "the", "element", "." ]
train
https://github.com/mpf-soft/admin-widgets/blob/92597f9a09d086664268d6b7e0111d5a5586d8c7/jqueryfileupload/Uploader.php#L183-L209
stellaqua/Waltz.Stagehand
src/Waltz/Stagehand/ClassUtility/ClassObject/PhpClassObject.php
PhpClassObject.getName
public function getName ( $withoutNamespace = false ) { $className = $this->_reflectionClass->getName(); if ( $withoutNamespace === true ) { $tokens = explode('\\', $className); $className = end($tokens); } return $className; }
php
public function getName ( $withoutNamespace = false ) { $className = $this->_reflectionClass->getName(); if ( $withoutNamespace === true ) { $tokens = explode('\\', $className); $className = end($tokens); } return $className; }
[ "public", "function", "getName", "(", "$", "withoutNamespace", "=", "false", ")", "{", "$", "className", "=", "$", "this", "->", "_reflectionClass", "->", "getName", "(", ")", ";", "if", "(", "$", "withoutNamespace", "===", "true", ")", "{", "$", "tokens", "=", "explode", "(", "'\\\\'", ",", "$", "className", ")", ";", "$", "className", "=", "end", "(", "$", "tokens", ")", ";", "}", "return", "$", "className", ";", "}" ]
Get class name @param bool $withoutNamespace @return string Class name
[ "Get", "class", "name" ]
train
https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/ClassUtility/ClassObject/PhpClassObject.php#L61-L69
stellaqua/Waltz.Stagehand
src/Waltz/Stagehand/ClassUtility/ClassObject/PhpClassObject.php
PhpClassObject.getDocComment
public function getDocComment ( $withCommentMark = false ) { $docComment = $this->_reflectionClass->getDocComment(); if ( $withCommentMark === false ) { $docComment = PhpDocCommentObject::stripCommentMarks($docComment); } return $docComment; }
php
public function getDocComment ( $withCommentMark = false ) { $docComment = $this->_reflectionClass->getDocComment(); if ( $withCommentMark === false ) { $docComment = PhpDocCommentObject::stripCommentMarks($docComment); } return $docComment; }
[ "public", "function", "getDocComment", "(", "$", "withCommentMark", "=", "false", ")", "{", "$", "docComment", "=", "$", "this", "->", "_reflectionClass", "->", "getDocComment", "(", ")", ";", "if", "(", "$", "withCommentMark", "===", "false", ")", "{", "$", "docComment", "=", "PhpDocCommentObject", "::", "stripCommentMarks", "(", "$", "docComment", ")", ";", "}", "return", "$", "docComment", ";", "}" ]
Get DocComment of class @param bool $withCommentMark @return string DocComment
[ "Get", "DocComment", "of", "class" ]
train
https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/ClassUtility/ClassObject/PhpClassObject.php#L77-L83
975L/ConfigBundle
Service/ConfigService.php
ConfigService.convertToArray
public function convertToArray(Config $config) { $values = get_object_vars($config); unset($values['configDataReserved']); //Converts yaml array to php array foreach ($values as $key => $value) { if (is_string($value) && ('[' == substr($value, 0, 1) || '{' == substr($value, 0, 1))) { $values[$key] = explode(',', trim($value, '[]{}')); } } return $values; }
php
public function convertToArray(Config $config) { $values = get_object_vars($config); unset($values['configDataReserved']); //Converts yaml array to php array foreach ($values as $key => $value) { if (is_string($value) && ('[' == substr($value, 0, 1) || '{' == substr($value, 0, 1))) { $values[$key] = explode(',', trim($value, '[]{}')); } } return $values; }
[ "public", "function", "convertToArray", "(", "Config", "$", "config", ")", "{", "$", "values", "=", "get_object_vars", "(", "$", "config", ")", ";", "unset", "(", "$", "values", "[", "'configDataReserved'", "]", ")", ";", "//Converts yaml array to php array", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", "&&", "(", "'['", "==", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "||", "'{'", "==", "substr", "(", "$", "value", ",", "0", ",", "1", ")", ")", ")", "{", "$", "values", "[", "$", "key", "]", "=", "explode", "(", "','", ",", "trim", "(", "$", "value", ",", "'[]{}'", ")", ")", ";", "}", "}", "return", "$", "values", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L74-L87
975L/ConfigBundle
Service/ConfigService.php
ConfigService.createForm
public function createForm(string $bundle) { $config = $this->getConfig($bundle); return $this->configFormFactory->create($config); }
php
public function createForm(string $bundle) { $config = $this->getConfig($bundle); return $this->configFormFactory->create($config); }
[ "public", "function", "createForm", "(", "string", "$", "bundle", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", "$", "bundle", ")", ";", "return", "$", "this", "->", "configFormFactory", "->", "create", "(", "$", "config", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L92-L97
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getBundleConfig
public function getBundleConfig(string $bundle) { $file = $this->container->getParameter('kernel.root_dir') . '/../vendor/' . $bundle . '/Resources/config/bundle.yaml'; if (is_file($file)) { $yamlBundleConfig = Yaml::parseFile($file); if (is_array($yamlBundleConfig)) { $config = new Config(); $parameters = array(); $roots = array(); //Parses the yaml content foreach ($yamlBundleConfig as $rootKey => $rootValue) { foreach ($rootValue as $key => $value) { $config->$key = $value; $config->$key['data'] = $value['default']; $config->$key['root'] = $rootKey; $parameters[$rootKey][] = $key; } $roots[] = $rootKey; } //Adds data used when writing file $config->configDataReserved = array( 'bundle' => $bundle, 'parameters' => $parameters, 'roots' => $roots, ); return $config; } } throw new LogicException('The bundle "' . $bundle . '" has not been defined. Check its name'); }
php
public function getBundleConfig(string $bundle) { $file = $this->container->getParameter('kernel.root_dir') . '/../vendor/' . $bundle . '/Resources/config/bundle.yaml'; if (is_file($file)) { $yamlBundleConfig = Yaml::parseFile($file); if (is_array($yamlBundleConfig)) { $config = new Config(); $parameters = array(); $roots = array(); //Parses the yaml content foreach ($yamlBundleConfig as $rootKey => $rootValue) { foreach ($rootValue as $key => $value) { $config->$key = $value; $config->$key['data'] = $value['default']; $config->$key['root'] = $rootKey; $parameters[$rootKey][] = $key; } $roots[] = $rootKey; } //Adds data used when writing file $config->configDataReserved = array( 'bundle' => $bundle, 'parameters' => $parameters, 'roots' => $roots, ); return $config; } } throw new LogicException('The bundle "' . $bundle . '" has not been defined. Check its name'); }
[ "public", "function", "getBundleConfig", "(", "string", "$", "bundle", ")", "{", "$", "file", "=", "$", "this", "->", "container", "->", "getParameter", "(", "'kernel.root_dir'", ")", ".", "'/../vendor/'", ".", "$", "bundle", ".", "'/Resources/config/bundle.yaml'", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "$", "yamlBundleConfig", "=", "Yaml", "::", "parseFile", "(", "$", "file", ")", ";", "if", "(", "is_array", "(", "$", "yamlBundleConfig", ")", ")", "{", "$", "config", "=", "new", "Config", "(", ")", ";", "$", "parameters", "=", "array", "(", ")", ";", "$", "roots", "=", "array", "(", ")", ";", "//Parses the yaml content", "foreach", "(", "$", "yamlBundleConfig", "as", "$", "rootKey", "=>", "$", "rootValue", ")", "{", "foreach", "(", "$", "rootValue", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "config", "->", "$", "key", "=", "$", "value", ";", "$", "config", "->", "$", "key", "[", "'data'", "]", "=", "$", "value", "[", "'default'", "]", ";", "$", "config", "->", "$", "key", "[", "'root'", "]", "=", "$", "rootKey", ";", "$", "parameters", "[", "$", "rootKey", "]", "[", "]", "=", "$", "key", ";", "}", "$", "roots", "[", "]", "=", "$", "rootKey", ";", "}", "//Adds data used when writing file", "$", "config", "->", "configDataReserved", "=", "array", "(", "'bundle'", "=>", "$", "bundle", ",", "'parameters'", "=>", "$", "parameters", ",", "'roots'", "=>", "$", "roots", ",", ")", ";", "return", "$", "config", ";", "}", "}", "throw", "new", "LogicException", "(", "'The bundle \"'", ".", "$", "bundle", ".", "'\" has not been defined. Check its name'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L102-L136
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getBundles
public function getBundles() { $folder = $this->container->getParameter('kernel.root_dir') . '/../vendor/*/*/Resources'; $bundlesConfigFiles = new Finder(); $bundlesConfigFiles ->files() ->name('bundle.yaml') ->in($folder) ->sortByName() ; //Creates the bundles array $bundles = array(); foreach ($bundlesConfigFiles as $bundleConfigFile) { $filename = $bundleConfigFile->getRealPath(); $bundle = substr($filename, 0, strpos($filename, '/Resources')); $bundle = substr($bundle, strpos($bundle, 'vendor/') + 7); $bundles[$bundle] = $filename; } return $bundles; }
php
public function getBundles() { $folder = $this->container->getParameter('kernel.root_dir') . '/../vendor/*/*/Resources'; $bundlesConfigFiles = new Finder(); $bundlesConfigFiles ->files() ->name('bundle.yaml') ->in($folder) ->sortByName() ; //Creates the bundles array $bundles = array(); foreach ($bundlesConfigFiles as $bundleConfigFile) { $filename = $bundleConfigFile->getRealPath(); $bundle = substr($filename, 0, strpos($filename, '/Resources')); $bundle = substr($bundle, strpos($bundle, 'vendor/') + 7); $bundles[$bundle] = $filename; } return $bundles; }
[ "public", "function", "getBundles", "(", ")", "{", "$", "folder", "=", "$", "this", "->", "container", "->", "getParameter", "(", "'kernel.root_dir'", ")", ".", "'/../vendor/*/*/Resources'", ";", "$", "bundlesConfigFiles", "=", "new", "Finder", "(", ")", ";", "$", "bundlesConfigFiles", "->", "files", "(", ")", "->", "name", "(", "'bundle.yaml'", ")", "->", "in", "(", "$", "folder", ")", "->", "sortByName", "(", ")", ";", "//Creates the bundles array", "$", "bundles", "=", "array", "(", ")", ";", "foreach", "(", "$", "bundlesConfigFiles", "as", "$", "bundleConfigFile", ")", "{", "$", "filename", "=", "$", "bundleConfigFile", "->", "getRealPath", "(", ")", ";", "$", "bundle", "=", "substr", "(", "$", "filename", ",", "0", ",", "strpos", "(", "$", "filename", ",", "'/Resources'", ")", ")", ";", "$", "bundle", "=", "substr", "(", "$", "bundle", ",", "strpos", "(", "$", "bundle", ",", "'vendor/'", ")", "+", "7", ")", ";", "$", "bundles", "[", "$", "bundle", "]", "=", "$", "filename", ";", "}", "return", "$", "bundles", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L141-L164
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getConfig
public function getConfig(string $bundle) { //Initializes config with data defined in bundle.yaml $config = $this->getBundleConfig($bundle); //Updates config with data defined in config_bundles.yaml $roots = $config->configDataReserved['roots']; foreach ($roots as $root) { $definedConfig = $this->getDefinedConfig($root); if (null !== $definedConfig) { foreach ($definedConfig as $key => $value) { if (property_exists($config, $key)) { $config->$key['data'] = $value; } } } } return $config; }
php
public function getConfig(string $bundle) { //Initializes config with data defined in bundle.yaml $config = $this->getBundleConfig($bundle); //Updates config with data defined in config_bundles.yaml $roots = $config->configDataReserved['roots']; foreach ($roots as $root) { $definedConfig = $this->getDefinedConfig($root); if (null !== $definedConfig) { foreach ($definedConfig as $key => $value) { if (property_exists($config, $key)) { $config->$key['data'] = $value; } } } } return $config; }
[ "public", "function", "getConfig", "(", "string", "$", "bundle", ")", "{", "//Initializes config with data defined in bundle.yaml", "$", "config", "=", "$", "this", "->", "getBundleConfig", "(", "$", "bundle", ")", ";", "//Updates config with data defined in config_bundles.yaml", "$", "roots", "=", "$", "config", "->", "configDataReserved", "[", "'roots'", "]", ";", "foreach", "(", "$", "roots", "as", "$", "root", ")", "{", "$", "definedConfig", "=", "$", "this", "->", "getDefinedConfig", "(", "$", "root", ")", ";", "if", "(", "null", "!==", "$", "definedConfig", ")", "{", "foreach", "(", "$", "definedConfig", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "config", ",", "$", "key", ")", ")", "{", "$", "config", "->", "$", "key", "[", "'data'", "]", "=", "$", "value", ";", "}", "}", "}", "}", "return", "$", "config", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L169-L188
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getDefinedConfig
public function getDefinedConfig(string $root) { $globalConfig = $this->getGlobalConfig(); if (null !== $globalConfig && array_key_exists($root, $globalConfig)) { $definedConfig = $globalConfig[$root]; return $definedConfig; } return null; }
php
public function getDefinedConfig(string $root) { $globalConfig = $this->getGlobalConfig(); if (null !== $globalConfig && array_key_exists($root, $globalConfig)) { $definedConfig = $globalConfig[$root]; return $definedConfig; } return null; }
[ "public", "function", "getDefinedConfig", "(", "string", "$", "root", ")", "{", "$", "globalConfig", "=", "$", "this", "->", "getGlobalConfig", "(", ")", ";", "if", "(", "null", "!==", "$", "globalConfig", "&&", "array_key_exists", "(", "$", "root", ",", "$", "globalConfig", ")", ")", "{", "$", "definedConfig", "=", "$", "globalConfig", "[", "$", "root", "]", ";", "return", "$", "definedConfig", ";", "}", "return", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L193-L204
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getGlobalConfig
public function getGlobalConfig() { $file = $this->getConfigFolder() . self::CONFIG_FILE_YAML; if (is_file($file)) { $globalConfig = Yaml::parseFile($file, Yaml::PARSE_DATETIME); return $globalConfig; } return null; }
php
public function getGlobalConfig() { $file = $this->getConfigFolder() . self::CONFIG_FILE_YAML; if (is_file($file)) { $globalConfig = Yaml::parseFile($file, Yaml::PARSE_DATETIME); return $globalConfig; } return null; }
[ "public", "function", "getGlobalConfig", "(", ")", "{", "$", "file", "=", "$", "this", "->", "getConfigFolder", "(", ")", ".", "self", "::", "CONFIG_FILE_YAML", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "$", "globalConfig", "=", "Yaml", "::", "parseFile", "(", "$", "file", ",", "Yaml", "::", "PARSE_DATETIME", ")", ";", "return", "$", "globalConfig", ";", "}", "return", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L209-L219
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getConfigFolder
public function getConfigFolder() { $rootFolder = $this->container->getParameter('kernel.root_dir'); return '4' === substr(Kernel::VERSION, 0, 1) ? $rootFolder . '/../config/' : $rootFolder . '/../app/config/'; }
php
public function getConfigFolder() { $rootFolder = $this->container->getParameter('kernel.root_dir'); return '4' === substr(Kernel::VERSION, 0, 1) ? $rootFolder . '/../config/' : $rootFolder . '/../app/config/'; }
[ "public", "function", "getConfigFolder", "(", ")", "{", "$", "rootFolder", "=", "$", "this", "->", "container", "->", "getParameter", "(", "'kernel.root_dir'", ")", ";", "return", "'4'", "===", "substr", "(", "Kernel", "::", "VERSION", ",", "0", ",", "1", ")", "?", "$", "rootFolder", ".", "'/../config/'", ":", "$", "rootFolder", ".", "'/../app/config/'", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L232-L237
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getParameter
public function getParameter(string $parameter, string $bundle = null) { if (strpos($parameter, '.')) { $paramArray = explode('.', $parameter); $parameters = $this->getParametersCacheFile($paramArray[0], $bundle); if (null !== $parameters) { if (array_key_exists($paramArray[0], $parameters) && array_key_exists($paramArray[1], $parameters[$paramArray[0]])) { return $parameters[$paramArray[0]][$paramArray[1]]; } } } throw new LogicException('Parameter "' . $parameter . '" defined using c975L/ConfigBundle is not defined! Try to use the config Route'); }
php
public function getParameter(string $parameter, string $bundle = null) { if (strpos($parameter, '.')) { $paramArray = explode('.', $parameter); $parameters = $this->getParametersCacheFile($paramArray[0], $bundle); if (null !== $parameters) { if (array_key_exists($paramArray[0], $parameters) && array_key_exists($paramArray[1], $parameters[$paramArray[0]])) { return $parameters[$paramArray[0]][$paramArray[1]]; } } } throw new LogicException('Parameter "' . $parameter . '" defined using c975L/ConfigBundle is not defined! Try to use the config Route'); }
[ "public", "function", "getParameter", "(", "string", "$", "parameter", ",", "string", "$", "bundle", "=", "null", ")", "{", "if", "(", "strpos", "(", "$", "parameter", ",", "'.'", ")", ")", "{", "$", "paramArray", "=", "explode", "(", "'.'", ",", "$", "parameter", ")", ";", "$", "parameters", "=", "$", "this", "->", "getParametersCacheFile", "(", "$", "paramArray", "[", "0", "]", ",", "$", "bundle", ")", ";", "if", "(", "null", "!==", "$", "parameters", ")", "{", "if", "(", "array_key_exists", "(", "$", "paramArray", "[", "0", "]", ",", "$", "parameters", ")", "&&", "array_key_exists", "(", "$", "paramArray", "[", "1", "]", ",", "$", "parameters", "[", "$", "paramArray", "[", "0", "]", "]", ")", ")", "{", "return", "$", "parameters", "[", "$", "paramArray", "[", "0", "]", "]", "[", "$", "paramArray", "[", "1", "]", "]", ";", "}", "}", "}", "throw", "new", "LogicException", "(", "'Parameter \"'", ".", "$", "parameter", ".", "'\" defined using c975L/ConfigBundle is not defined! Try to use the config Route'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L250-L264
975L/ConfigBundle
Service/ConfigService.php
ConfigService.getParametersCacheFile
public function getParametersCacheFile(string $root, string $bundle = null) { static $parameters; if (null !== $parameters) { return $parameters; } //Creates cache file if not existing $file = $this->getCacheFolder() . self::CONFIG_FILE_PHP; if (!is_file($file)) { //Gets data from config_bundles.yaml $globalConfig = $this->getGlobalConfig(); if (is_array($globalConfig)) { $this->writePhpFile($globalConfig); $parameters = $globalConfig; return $parameters; //Gets data from bundle.yaml } elseif (null !== $bundle) { $bundleDefaultConfig = $this->convertToArray($this->getBundleConfig($bundle)); $defaultConfig = array(); foreach ($bundleDefaultConfig as $key => $value) { $defaultConfig[$key] = $value['default']; } $parameters = array($root => $defaultConfig); $this->writeYamlFile($parameters); $this->writePhpFile($parameters); return $parameters; //No bundle name provided } else { throw new LogicException("The config files are not created you should use `php bin/console config:create`"); } //Wrong bundle name throw new LogicException('The file ' . $bundle . '/Resources/config/bundle.yaml could not be found!'); } $parameters = include_once($file); return $parameters; }
php
public function getParametersCacheFile(string $root, string $bundle = null) { static $parameters; if (null !== $parameters) { return $parameters; } //Creates cache file if not existing $file = $this->getCacheFolder() . self::CONFIG_FILE_PHP; if (!is_file($file)) { //Gets data from config_bundles.yaml $globalConfig = $this->getGlobalConfig(); if (is_array($globalConfig)) { $this->writePhpFile($globalConfig); $parameters = $globalConfig; return $parameters; //Gets data from bundle.yaml } elseif (null !== $bundle) { $bundleDefaultConfig = $this->convertToArray($this->getBundleConfig($bundle)); $defaultConfig = array(); foreach ($bundleDefaultConfig as $key => $value) { $defaultConfig[$key] = $value['default']; } $parameters = array($root => $defaultConfig); $this->writeYamlFile($parameters); $this->writePhpFile($parameters); return $parameters; //No bundle name provided } else { throw new LogicException("The config files are not created you should use `php bin/console config:create`"); } //Wrong bundle name throw new LogicException('The file ' . $bundle . '/Resources/config/bundle.yaml could not be found!'); } $parameters = include_once($file); return $parameters; }
[ "public", "function", "getParametersCacheFile", "(", "string", "$", "root", ",", "string", "$", "bundle", "=", "null", ")", "{", "static", "$", "parameters", ";", "if", "(", "null", "!==", "$", "parameters", ")", "{", "return", "$", "parameters", ";", "}", "//Creates cache file if not existing", "$", "file", "=", "$", "this", "->", "getCacheFolder", "(", ")", ".", "self", "::", "CONFIG_FILE_PHP", ";", "if", "(", "!", "is_file", "(", "$", "file", ")", ")", "{", "//Gets data from config_bundles.yaml", "$", "globalConfig", "=", "$", "this", "->", "getGlobalConfig", "(", ")", ";", "if", "(", "is_array", "(", "$", "globalConfig", ")", ")", "{", "$", "this", "->", "writePhpFile", "(", "$", "globalConfig", ")", ";", "$", "parameters", "=", "$", "globalConfig", ";", "return", "$", "parameters", ";", "//Gets data from bundle.yaml", "}", "elseif", "(", "null", "!==", "$", "bundle", ")", "{", "$", "bundleDefaultConfig", "=", "$", "this", "->", "convertToArray", "(", "$", "this", "->", "getBundleConfig", "(", "$", "bundle", ")", ")", ";", "$", "defaultConfig", "=", "array", "(", ")", ";", "foreach", "(", "$", "bundleDefaultConfig", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "defaultConfig", "[", "$", "key", "]", "=", "$", "value", "[", "'default'", "]", ";", "}", "$", "parameters", "=", "array", "(", "$", "root", "=>", "$", "defaultConfig", ")", ";", "$", "this", "->", "writeYamlFile", "(", "$", "parameters", ")", ";", "$", "this", "->", "writePhpFile", "(", "$", "parameters", ")", ";", "return", "$", "parameters", ";", "//No bundle name provided", "}", "else", "{", "throw", "new", "LogicException", "(", "\"The config files are not created you should use `php bin/console config:create`\"", ")", ";", "}", "//Wrong bundle name", "throw", "new", "LogicException", "(", "'The file '", ".", "$", "bundle", ".", "'/Resources/config/bundle.yaml could not be found!'", ")", ";", "}", "$", "parameters", "=", "include_once", "(", "$", "file", ")", ";", "return", "$", "parameters", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L269-L312
975L/ConfigBundle
Service/ConfigService.php
ConfigService.hasParameter
public function hasParameter(string $parameter) { if (strpos($parameter, '.')) { $paramArray = explode('.', $parameter); $parameters = $this->getParametersCacheFile($paramArray[0]); if (null !== $parameters) { if (array_key_exists($paramArray[0], $parameters) && array_key_exists($paramArray[1], $parameters[$paramArray[0]])) { return true; } } } return false; }
php
public function hasParameter(string $parameter) { if (strpos($parameter, '.')) { $paramArray = explode('.', $parameter); $parameters = $this->getParametersCacheFile($paramArray[0]); if (null !== $parameters) { if (array_key_exists($paramArray[0], $parameters) && array_key_exists($paramArray[1], $parameters[$paramArray[0]])) { return true; } } } return false; }
[ "public", "function", "hasParameter", "(", "string", "$", "parameter", ")", "{", "if", "(", "strpos", "(", "$", "parameter", ",", "'.'", ")", ")", "{", "$", "paramArray", "=", "explode", "(", "'.'", ",", "$", "parameter", ")", ";", "$", "parameters", "=", "$", "this", "->", "getParametersCacheFile", "(", "$", "paramArray", "[", "0", "]", ")", ";", "if", "(", "null", "!==", "$", "parameters", ")", "{", "if", "(", "array_key_exists", "(", "$", "paramArray", "[", "0", "]", ",", "$", "parameters", ")", "&&", "array_key_exists", "(", "$", "paramArray", "[", "1", "]", ",", "$", "parameters", "[", "$", "paramArray", "[", "0", "]", "]", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L317-L331
975L/ConfigBundle
Service/ConfigService.php
ConfigService.setConfig
public function setConfig($data) { if ($data instanceof Form) { $data = $data->getData(); } //Adds new values $newDefinedValues = $this->convertToArray($data); $globalConfig = $this->getGlobalConfig(); $parameters = $data->configDataReserved['parameters']; foreach ($parameters as $key => $values) { if (is_array($values)) { foreach ($values as $value) { if (array_key_exists($value, $newDefinedValues)) { $globalConfig[$key][$value] = $newDefinedValues[$value]; } } } } //Writes files $this->writeYamlFile($globalConfig); $this->writePhpFile($globalConfig); //Creates flash $this->serviceTools->createFlash('config', 'text.config_updated'); }
php
public function setConfig($data) { if ($data instanceof Form) { $data = $data->getData(); } //Adds new values $newDefinedValues = $this->convertToArray($data); $globalConfig = $this->getGlobalConfig(); $parameters = $data->configDataReserved['parameters']; foreach ($parameters as $key => $values) { if (is_array($values)) { foreach ($values as $value) { if (array_key_exists($value, $newDefinedValues)) { $globalConfig[$key][$value] = $newDefinedValues[$value]; } } } } //Writes files $this->writeYamlFile($globalConfig); $this->writePhpFile($globalConfig); //Creates flash $this->serviceTools->createFlash('config', 'text.config_updated'); }
[ "public", "function", "setConfig", "(", "$", "data", ")", "{", "if", "(", "$", "data", "instanceof", "Form", ")", "{", "$", "data", "=", "$", "data", "->", "getData", "(", ")", ";", "}", "//Adds new values", "$", "newDefinedValues", "=", "$", "this", "->", "convertToArray", "(", "$", "data", ")", ";", "$", "globalConfig", "=", "$", "this", "->", "getGlobalConfig", "(", ")", ";", "$", "parameters", "=", "$", "data", "->", "configDataReserved", "[", "'parameters'", "]", ";", "foreach", "(", "$", "parameters", "as", "$", "key", "=>", "$", "values", ")", "{", "if", "(", "is_array", "(", "$", "values", ")", ")", "{", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "array_key_exists", "(", "$", "value", ",", "$", "newDefinedValues", ")", ")", "{", "$", "globalConfig", "[", "$", "key", "]", "[", "$", "value", "]", "=", "$", "newDefinedValues", "[", "$", "value", "]", ";", "}", "}", "}", "}", "//Writes files", "$", "this", "->", "writeYamlFile", "(", "$", "globalConfig", ")", ";", "$", "this", "->", "writePhpFile", "(", "$", "globalConfig", ")", ";", "//Creates flash", "$", "this", "->", "serviceTools", "->", "createFlash", "(", "'config'", ",", "'text.config_updated'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L336-L362
975L/ConfigBundle
Service/ConfigService.php
ConfigService.writeYamlFile
public function writeYamlFile(array $globalConfig) { $yamlContent = Yaml::dump($globalConfig, 2, 4, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE); //Removes quotes around array otherwise yaml will not see it as an array $yamlContent = preg_replace("/'({.*})'/", '$1', $yamlContent); $yamlContent = preg_replace("/'(\[.*\])'/", '$1', $yamlContent); $yamlContent = str_replace(array('\'"', '"\''), "'", $yamlContent); $fs = new Filesystem(); $file = $this->getConfigFolder() . self::CONFIG_FILE_YAML; $fs->remove($file . '.bak'); if ($fs->exists($file)) { $fs->rename($file, $file . '.bak'); } $fs->dumpFile($file, $yamlContent); }
php
public function writeYamlFile(array $globalConfig) { $yamlContent = Yaml::dump($globalConfig, 2, 4, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE); //Removes quotes around array otherwise yaml will not see it as an array $yamlContent = preg_replace("/'({.*})'/", '$1', $yamlContent); $yamlContent = preg_replace("/'(\[.*\])'/", '$1', $yamlContent); $yamlContent = str_replace(array('\'"', '"\''), "'", $yamlContent); $fs = new Filesystem(); $file = $this->getConfigFolder() . self::CONFIG_FILE_YAML; $fs->remove($file . '.bak'); if ($fs->exists($file)) { $fs->rename($file, $file . '.bak'); } $fs->dumpFile($file, $yamlContent); }
[ "public", "function", "writeYamlFile", "(", "array", "$", "globalConfig", ")", "{", "$", "yamlContent", "=", "Yaml", "::", "dump", "(", "$", "globalConfig", ",", "2", ",", "4", ",", "Yaml", "::", "DUMP_EXCEPTION_ON_INVALID_TYPE", ")", ";", "//Removes quotes around array otherwise yaml will not see it as an array", "$", "yamlContent", "=", "preg_replace", "(", "\"/'({.*})'/\"", ",", "'$1'", ",", "$", "yamlContent", ")", ";", "$", "yamlContent", "=", "preg_replace", "(", "\"/'(\\[.*\\])'/\"", ",", "'$1'", ",", "$", "yamlContent", ")", ";", "$", "yamlContent", "=", "str_replace", "(", "array", "(", "'\\'\"'", ",", "'\"\\''", ")", ",", "\"'\"", ",", "$", "yamlContent", ")", ";", "$", "fs", "=", "new", "Filesystem", "(", ")", ";", "$", "file", "=", "$", "this", "->", "getConfigFolder", "(", ")", ".", "self", "::", "CONFIG_FILE_YAML", ";", "$", "fs", "->", "remove", "(", "$", "file", ".", "'.bak'", ")", ";", "if", "(", "$", "fs", "->", "exists", "(", "$", "file", ")", ")", "{", "$", "fs", "->", "rename", "(", "$", "file", ",", "$", "file", ".", "'.bak'", ")", ";", "}", "$", "fs", "->", "dumpFile", "(", "$", "file", ",", "$", "yamlContent", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L367-L383
975L/ConfigBundle
Service/ConfigService.php
ConfigService.writePhpFile
public function writePhpFile(array $globalConfig) { $fs = new Filesystem(); $file = $this->getCacheFolder() . self::CONFIG_FILE_PHP; $phpContent = "<?php\nreturn " . var_export($globalConfig, true) . ';'; $phpContent = str_replace(array('\'"', '"\''), "'", $phpContent); $fs->dumpFile($file, $phpContent); }
php
public function writePhpFile(array $globalConfig) { $fs = new Filesystem(); $file = $this->getCacheFolder() . self::CONFIG_FILE_PHP; $phpContent = "<?php\nreturn " . var_export($globalConfig, true) . ';'; $phpContent = str_replace(array('\'"', '"\''), "'", $phpContent); $fs->dumpFile($file, $phpContent); }
[ "public", "function", "writePhpFile", "(", "array", "$", "globalConfig", ")", "{", "$", "fs", "=", "new", "Filesystem", "(", ")", ";", "$", "file", "=", "$", "this", "->", "getCacheFolder", "(", ")", ".", "self", "::", "CONFIG_FILE_PHP", ";", "$", "phpContent", "=", "\"<?php\\nreturn \"", ".", "var_export", "(", "$", "globalConfig", ",", "true", ")", ".", "';'", ";", "$", "phpContent", "=", "str_replace", "(", "array", "(", "'\\'\"'", ",", "'\"\\''", ")", ",", "\"'\"", ",", "$", "phpContent", ")", ";", "$", "fs", "->", "dumpFile", "(", "$", "file", ",", "$", "phpContent", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/975L/ConfigBundle/blob/1f9a9e937dbb79ad06fe5d456e7536d58bd56e19/Service/ConfigService.php#L388-L396
padosoft/HTTPClient
src/Multipart.php
Multipart.getMultipartArray
public function getMultipartArray() { $arrMultipart = array(); $arrMultipart[] = ['name' => $this->name, 'contents' => $this->contents, 'headers' => $this->headers, 'filename' => $this->filename ]; return $arrMultipart; }
php
public function getMultipartArray() { $arrMultipart = array(); $arrMultipart[] = ['name' => $this->name, 'contents' => $this->contents, 'headers' => $this->headers, 'filename' => $this->filename ]; return $arrMultipart; }
[ "public", "function", "getMultipartArray", "(", ")", "{", "$", "arrMultipart", "=", "array", "(", ")", ";", "$", "arrMultipart", "[", "]", "=", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'contents'", "=>", "$", "this", "->", "contents", ",", "'headers'", "=>", "$", "this", "->", "headers", ",", "'filename'", "=>", "$", "this", "->", "filename", "]", ";", "return", "$", "arrMultipart", ";", "}" ]
Return an associative array for RequestHelper::SetMultipart() @return array
[ "Return", "an", "associative", "array", "for", "RequestHelper", "::", "SetMultipart", "()" ]
train
https://github.com/padosoft/HTTPClient/blob/916f3832275bfcb5cc0691a7f39e4c74557dabc4/src/Multipart.php#L113-L124
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setLength
public function setLength($length) { if (($length !== null) && (!is_int($length) || ($length <= 0))) { throw SchemaException::invalidColumnLength($this->getName()); } $this->length = $length; }
php
public function setLength($length) { if (($length !== null) && (!is_int($length) || ($length <= 0))) { throw SchemaException::invalidColumnLength($this->getName()); } $this->length = $length; }
[ "public", "function", "setLength", "(", "$", "length", ")", "{", "if", "(", "(", "$", "length", "!==", "null", ")", "&&", "(", "!", "is_int", "(", "$", "length", ")", "||", "(", "$", "length", "<=", "0", ")", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnLength", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "length", "=", "$", "length", ";", "}" ]
Sets the column length. @param integer|null $length The column length. @throws \Fridge\DBAL\Exception\SchemaException If the length is not a positive integer.
[ "Sets", "the", "column", "length", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L117-L124
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setPrecision
public function setPrecision($precision) { if (($precision !== null) && (!is_int($precision) || ($precision <= 0))) { throw SchemaException::invalidColumnPrecision($this->getName()); } $this->precision = $precision; }
php
public function setPrecision($precision) { if (($precision !== null) && (!is_int($precision) || ($precision <= 0))) { throw SchemaException::invalidColumnPrecision($this->getName()); } $this->precision = $precision; }
[ "public", "function", "setPrecision", "(", "$", "precision", ")", "{", "if", "(", "(", "$", "precision", "!==", "null", ")", "&&", "(", "!", "is_int", "(", "$", "precision", ")", "||", "(", "$", "precision", "<=", "0", ")", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnPrecision", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "precision", "=", "$", "precision", ";", "}" ]
Sets the column precision. @param integer|null $precision The column precision. @throws \Fridge\DBAL\Exception\SchemaException If the precision is not a positive integer.
[ "Sets", "the", "column", "precision", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L143-L150
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setScale
public function setScale($scale) { if (($scale !== null) && (!is_int($scale) || ($scale < 0))) { throw SchemaException::invalidColumnScale($this->getName()); } $this->scale = $scale; }
php
public function setScale($scale) { if (($scale !== null) && (!is_int($scale) || ($scale < 0))) { throw SchemaException::invalidColumnScale($this->getName()); } $this->scale = $scale; }
[ "public", "function", "setScale", "(", "$", "scale", ")", "{", "if", "(", "(", "$", "scale", "!==", "null", ")", "&&", "(", "!", "is_int", "(", "$", "scale", ")", "||", "(", "$", "scale", "<", "0", ")", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnScale", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "scale", "=", "$", "scale", ";", "}" ]
Sets the column scale. @param integer|null $scale The column scale. @throws \Fridge\DBAL\Exception\SchemaException If the scale is not a positive integer.
[ "Sets", "the", "column", "scale", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L169-L176
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setUnsigned
public function setUnsigned($unsigned) { if (($unsigned !== null) && !is_bool($unsigned)) { throw SchemaException::invalidColumnUnsignedFlag($this->getName()); } $this->unsigned = $unsigned; }
php
public function setUnsigned($unsigned) { if (($unsigned !== null) && !is_bool($unsigned)) { throw SchemaException::invalidColumnUnsignedFlag($this->getName()); } $this->unsigned = $unsigned; }
[ "public", "function", "setUnsigned", "(", "$", "unsigned", ")", "{", "if", "(", "(", "$", "unsigned", "!==", "null", ")", "&&", "!", "is_bool", "(", "$", "unsigned", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnUnsignedFlag", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "unsigned", "=", "$", "unsigned", ";", "}" ]
Sets the column unsigned flag. @param boolean|null $unsigned The column unsigned flag. @throws \Fridge\DBAL\Exception\SchemaException If the unsigned flag is not a boolean.
[ "Sets", "the", "column", "unsigned", "flag", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L195-L202
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setFixed
public function setFixed($fixed) { if (($fixed !== null) && !is_bool($fixed)) { throw SchemaException::invalidColumnFixedFlag($this->getName()); } $this->fixed = $fixed; }
php
public function setFixed($fixed) { if (($fixed !== null) && !is_bool($fixed)) { throw SchemaException::invalidColumnFixedFlag($this->getName()); } $this->fixed = $fixed; }
[ "public", "function", "setFixed", "(", "$", "fixed", ")", "{", "if", "(", "(", "$", "fixed", "!==", "null", ")", "&&", "!", "is_bool", "(", "$", "fixed", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnFixedFlag", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "fixed", "=", "$", "fixed", ";", "}" ]
Sets the column fixed flag. @param boolean $fixed The column fixed flag. @throws \Fridge\DBAL\Exception\SchemaException If the fixed flag is not a boolean.
[ "Sets", "the", "column", "fixed", "flag", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L221-L228
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setNotNull
public function setNotNull($notNull) { if (($notNull !== null) && !is_bool($notNull)) { throw SchemaException::invalidColumnNotNullFlag($this->getName()); } $this->notNull = $notNull; }
php
public function setNotNull($notNull) { if (($notNull !== null) && !is_bool($notNull)) { throw SchemaException::invalidColumnNotNullFlag($this->getName()); } $this->notNull = $notNull; }
[ "public", "function", "setNotNull", "(", "$", "notNull", ")", "{", "if", "(", "(", "$", "notNull", "!==", "null", ")", "&&", "!", "is_bool", "(", "$", "notNull", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnNotNullFlag", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "notNull", "=", "$", "notNull", ";", "}" ]
Sets the column not null flag. @param boolean|null $notNull The column not null flag. @throws \Fridge\DBAL\Exception\SchemaException If the not null flag is not a boolean.
[ "Sets", "the", "column", "not", "null", "flag", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L247-L254
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setAutoIncrement
public function setAutoIncrement($autoIncrement) { if (($autoIncrement !== null) && !is_bool($autoIncrement)) { throw SchemaException::invalidColumnAutoIncrementFlag($this->getName()); } $this->autoIncrement = $autoIncrement; }
php
public function setAutoIncrement($autoIncrement) { if (($autoIncrement !== null) && !is_bool($autoIncrement)) { throw SchemaException::invalidColumnAutoIncrementFlag($this->getName()); } $this->autoIncrement = $autoIncrement; }
[ "public", "function", "setAutoIncrement", "(", "$", "autoIncrement", ")", "{", "if", "(", "(", "$", "autoIncrement", "!==", "null", ")", "&&", "!", "is_bool", "(", "$", "autoIncrement", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnAutoIncrementFlag", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "autoIncrement", "=", "$", "autoIncrement", ";", "}" ]
Sets the column auto increment flag. @param boolean|null $autoIncrement The column auto increment flag. @throws \Fridge\DBAL\Exception\SchemaException If the auto increment flag is not a boolean.
[ "Sets", "the", "column", "auto", "increment", "flag", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L293-L300
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setComment
public function setComment($comment) { if (($comment !== null) && !is_string($comment)) { throw SchemaException::invalidColumnComment($this->getName()); } $this->comment = $comment; }
php
public function setComment($comment) { if (($comment !== null) && !is_string($comment)) { throw SchemaException::invalidColumnComment($this->getName()); } $this->comment = $comment; }
[ "public", "function", "setComment", "(", "$", "comment", ")", "{", "if", "(", "(", "$", "comment", "!==", "null", ")", "&&", "!", "is_string", "(", "$", "comment", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnComment", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "comment", "=", "$", "comment", ";", "}" ]
Sets the column comment. @param string|null $comment The column comment. @throws \Fridge\DBAL\Exception\SchemaException If the comment is not a string.
[ "Sets", "the", "column", "comment", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L319-L326
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.setProperties
public function setProperties(array $properties) { foreach ($properties as $property => $value) { $method = sprintf('set%s', str_replace('_', '', $property)); if (!method_exists($this, $method)) { throw SchemaException::invalidColumnProperty($this->getName(), $property); } $this->$method($value); } }
php
public function setProperties(array $properties) { foreach ($properties as $property => $value) { $method = sprintf('set%s', str_replace('_', '', $property)); if (!method_exists($this, $method)) { throw SchemaException::invalidColumnProperty($this->getName(), $property); } $this->$method($value); } }
[ "public", "function", "setProperties", "(", "array", "$", "properties", ")", "{", "foreach", "(", "$", "properties", "as", "$", "property", "=>", "$", "value", ")", "{", "$", "method", "=", "sprintf", "(", "'set%s'", ",", "str_replace", "(", "'_'", ",", "''", ",", "$", "property", ")", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "throw", "SchemaException", "::", "invalidColumnProperty", "(", "$", "this", "->", "getName", "(", ")", ",", "$", "property", ")", ";", "}", "$", "this", "->", "$", "method", "(", "$", "value", ")", ";", "}", "}" ]
Sets the column options. @param array $properties Associative array that describes property => value pairs. @throws \Fridge\DBAL\Exception\SchemaException If the property does not exist.
[ "Sets", "the", "column", "options", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L335-L346
fridge-project/dbal
src/Fridge/DBAL/Schema/Column.php
Column.toArray
public function toArray() { return array( 'name' => $this->getName(), 'type' => $this->getType()->getName(), 'length' => $this->getLength(), 'precision' => $this->getPrecision(), 'scale' => $this->getScale(), 'unsigned' => $this->isUnsigned(), 'fixed' => $this->isFixed(), 'not_null' => $this->isNotNull(), 'default' => $this->getDefault(), 'auto_increment' => $this->isAutoIncrement(), 'comment' => $this->getComment(), ); }
php
public function toArray() { return array( 'name' => $this->getName(), 'type' => $this->getType()->getName(), 'length' => $this->getLength(), 'precision' => $this->getPrecision(), 'scale' => $this->getScale(), 'unsigned' => $this->isUnsigned(), 'fixed' => $this->isFixed(), 'not_null' => $this->isNotNull(), 'default' => $this->getDefault(), 'auto_increment' => $this->isAutoIncrement(), 'comment' => $this->getComment(), ); }
[ "public", "function", "toArray", "(", ")", "{", "return", "array", "(", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'type'", "=>", "$", "this", "->", "getType", "(", ")", "->", "getName", "(", ")", ",", "'length'", "=>", "$", "this", "->", "getLength", "(", ")", ",", "'precision'", "=>", "$", "this", "->", "getPrecision", "(", ")", ",", "'scale'", "=>", "$", "this", "->", "getScale", "(", ")", ",", "'unsigned'", "=>", "$", "this", "->", "isUnsigned", "(", ")", ",", "'fixed'", "=>", "$", "this", "->", "isFixed", "(", ")", ",", "'not_null'", "=>", "$", "this", "->", "isNotNull", "(", ")", ",", "'default'", "=>", "$", "this", "->", "getDefault", "(", ")", ",", "'auto_increment'", "=>", "$", "this", "->", "isAutoIncrement", "(", ")", ",", "'comment'", "=>", "$", "this", "->", "getComment", "(", ")", ",", ")", ";", "}" ]
Converts a column to an array. @return array The column converted to an array.
[ "Converts", "a", "column", "to", "an", "array", "." ]
train
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Column.php#L353-L368
eureka-framework/component-controller
src/Controller/DataCollection.php
DataCollection.add
public function add($key, $value) { $this->collection[$key] = $value; $this->indices[$this->length] = $key; $this->length++; return $this; }
php
public function add($key, $value) { $this->collection[$key] = $value; $this->indices[$this->length] = $key; $this->length++; return $this; }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "collection", "[", "$", "key", "]", "=", "$", "value", ";", "$", "this", "->", "indices", "[", "$", "this", "->", "length", "]", "=", "$", "key", ";", "$", "this", "->", "length", "++", ";", "return", "$", "this", ";", "}" ]
Add data to the collection. @param string $key @param mixed $value @return self
[ "Add", "data", "to", "the", "collection", "." ]
train
https://github.com/eureka-framework/component-controller/blob/368efb6fb9eece4f7f69233e6190e1fdbb0ace2c/src/Controller/DataCollection.php#L54-L61
SagittariusX/Beluga.Core
src/Beluga/Type.php
Type.getPhpCode
public final function getPhpCode() : string { $str = $this->stringValue; switch ( $this->typeName ) { case Type::PHP_BOOLEAN: case 'boolean': return ( $this->value ? 'true' : 'false' ); case Type::PHP_DOUBLE: case Type::PHP_FLOAT: case Type::PHP_INTEGER: case 'integer': return $str; case Type::PHP_STRING: if ( \preg_match( "~[\r\n\t]+~", $str ) ) { $str = \str_replace( array( '\\', "\r", "\n", "\t", "\0", '"', '$' ), array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ), $str ); return '"' . $str . '"'; } return "'" . \str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $str ) . "'"; case Type::PHP_RESOURCE: case Type::PHP_NULL: case Type::PHP_UNKNOWN: return 'null'; default: $str = \serialize( $this->value ); if ( \preg_match( "~[\r\n\t]+~", $str ) ) { $str = \str_replace( array( '\\', "\r", "\n", "\t", "\0", '"', '$' ), array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ), $str ); } else { $str = \str_replace( array('\\', '"', '$'), array('\\\\', '\\"', '\\$'), $str ); } return '\unserialize("' . $str . '")'; } }
php
public final function getPhpCode() : string { $str = $this->stringValue; switch ( $this->typeName ) { case Type::PHP_BOOLEAN: case 'boolean': return ( $this->value ? 'true' : 'false' ); case Type::PHP_DOUBLE: case Type::PHP_FLOAT: case Type::PHP_INTEGER: case 'integer': return $str; case Type::PHP_STRING: if ( \preg_match( "~[\r\n\t]+~", $str ) ) { $str = \str_replace( array( '\\', "\r", "\n", "\t", "\0", '"', '$' ), array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ), $str ); return '"' . $str . '"'; } return "'" . \str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $str ) . "'"; case Type::PHP_RESOURCE: case Type::PHP_NULL: case Type::PHP_UNKNOWN: return 'null'; default: $str = \serialize( $this->value ); if ( \preg_match( "~[\r\n\t]+~", $str ) ) { $str = \str_replace( array( '\\', "\r", "\n", "\t", "\0", '"', '$' ), array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ), $str ); } else { $str = \str_replace( array('\\', '"', '$'), array('\\\\', '\\"', '\\$'), $str ); } return '\unserialize("' . $str . '")'; } }
[ "public", "final", "function", "getPhpCode", "(", ")", ":", "string", "{", "$", "str", "=", "$", "this", "->", "stringValue", ";", "switch", "(", "$", "this", "->", "typeName", ")", "{", "case", "Type", "::", "PHP_BOOLEAN", ":", "case", "'boolean'", ":", "return", "(", "$", "this", "->", "value", "?", "'true'", ":", "'false'", ")", ";", "case", "Type", "::", "PHP_DOUBLE", ":", "case", "Type", "::", "PHP_FLOAT", ":", "case", "Type", "::", "PHP_INTEGER", ":", "case", "'integer'", ":", "return", "$", "str", ";", "case", "Type", "::", "PHP_STRING", ":", "if", "(", "\\", "preg_match", "(", "\"~[\\r\\n\\t]+~\"", ",", "$", "str", ")", ")", "{", "$", "str", "=", "\\", "str_replace", "(", "array", "(", "'\\\\'", ",", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ",", "\"\\0\"", ",", "'\"'", ",", "'$'", ")", ",", "array", "(", "'\\\\\\\\'", ",", "'\\\\r'", ",", "'\\\\n'", ",", "'\\\\t'", ",", "'\\\\0'", ",", "'\\\\\"'", ",", "'\\\\$'", ")", ",", "$", "str", ")", ";", "return", "'\"'", ".", "$", "str", ".", "'\"'", ";", "}", "return", "\"'\"", ".", "\\", "str_replace", "(", "array", "(", "'\\\\'", ",", "\"'\"", ")", ",", "array", "(", "'\\\\\\\\'", ",", "\"\\\\'\"", ")", ",", "$", "str", ")", ".", "\"'\"", ";", "case", "Type", "::", "PHP_RESOURCE", ":", "case", "Type", "::", "PHP_NULL", ":", "case", "Type", "::", "PHP_UNKNOWN", ":", "return", "'null'", ";", "default", ":", "$", "str", "=", "\\", "serialize", "(", "$", "this", "->", "value", ")", ";", "if", "(", "\\", "preg_match", "(", "\"~[\\r\\n\\t]+~\"", ",", "$", "str", ")", ")", "{", "$", "str", "=", "\\", "str_replace", "(", "array", "(", "'\\\\'", ",", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ",", "\"\\0\"", ",", "'\"'", ",", "'$'", ")", ",", "array", "(", "'\\\\\\\\'", ",", "'\\\\r'", ",", "'\\\\n'", ",", "'\\\\t'", ",", "'\\\\0'", ",", "'\\\\\"'", ",", "'\\\\$'", ")", ",", "$", "str", ")", ";", "}", "else", "{", "$", "str", "=", "\\", "str_replace", "(", "array", "(", "'\\\\'", ",", "'\"'", ",", "'$'", ")", ",", "array", "(", "'\\\\\\\\'", ",", "'\\\\\"'", ",", "'\\\\$'", ")", ",", "$", "str", ")", ";", "}", "return", "'\\unserialize(\"'", ".", "$", "str", ".", "'\")'", ";", "}", "}" ]
Returns the PHP code, defining the current base value. @return string
[ "Returns", "the", "PHP", "code", "defining", "the", "current", "base", "value", "." ]
train
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/Type.php#L298-L359
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.registerConnection
public function registerConnection($name, array $configuration) { $this->configurations->set($name, new OrientDbMetadata( $configuration['host'], $configuration['port'], $configuration['timeout'], $configuration['user'], $configuration['password'], $configuration['database'], $configuration['data_type'], $configuration['storage_type'] )); }
php
public function registerConnection($name, array $configuration) { $this->configurations->set($name, new OrientDbMetadata( $configuration['host'], $configuration['port'], $configuration['timeout'], $configuration['user'], $configuration['password'], $configuration['database'], $configuration['data_type'], $configuration['storage_type'] )); }
[ "public", "function", "registerConnection", "(", "$", "name", ",", "array", "$", "configuration", ")", "{", "$", "this", "->", "configurations", "->", "set", "(", "$", "name", ",", "new", "OrientDbMetadata", "(", "$", "configuration", "[", "'host'", "]", ",", "$", "configuration", "[", "'port'", "]", ",", "$", "configuration", "[", "'timeout'", "]", ",", "$", "configuration", "[", "'user'", "]", ",", "$", "configuration", "[", "'password'", "]", ",", "$", "configuration", "[", "'database'", "]", ",", "$", "configuration", "[", "'data_type'", "]", ",", "$", "configuration", "[", "'storage_type'", "]", ")", ")", ";", "}" ]
Register a new OrientDB connection under given name @param string $name
[ "Register", "a", "new", "OrientDB", "connection", "under", "given", "name" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L44-L56
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.getConfiguration
public function getConfiguration($connectionName = 'default') { if (!$this->configurations->containsKey($connectionName)) { throw new \InvalidArgumentException(sprintf('Any registered configuration under given key.')); } return $this->configurations->get($connectionName); }
php
public function getConfiguration($connectionName = 'default') { if (!$this->configurations->containsKey($connectionName)) { throw new \InvalidArgumentException(sprintf('Any registered configuration under given key.')); } return $this->configurations->get($connectionName); }
[ "public", "function", "getConfiguration", "(", "$", "connectionName", "=", "'default'", ")", "{", "if", "(", "!", "$", "this", "->", "configurations", "->", "containsKey", "(", "$", "connectionName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Any registered configuration under given key.'", ")", ")", ";", "}", "return", "$", "this", "->", "configurations", "->", "get", "(", "$", "connectionName", ")", ";", "}" ]
Return registered configuration under given connectionName @param string $connectionName @return OrientDbMetadata
[ "Return", "registered", "configuration", "under", "given", "connectionName" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L76-L83
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.getConnection
public function getConnection($connectionName = 'default') { if ($this->connections->containsKey($connectionName)) { return $this->connections->get($connectionName); } $configuration = $this->getConfiguration($connectionName); $this->connections->set($connectionName, $database = (new \OrientDB( $configuration->getHost(), $configuration->getPort(), $configuration->getTimeout() )) ); $database->connect( $configuration->getUser(), $configuration->getPassword() ); return $database; }
php
public function getConnection($connectionName = 'default') { if ($this->connections->containsKey($connectionName)) { return $this->connections->get($connectionName); } $configuration = $this->getConfiguration($connectionName); $this->connections->set($connectionName, $database = (new \OrientDB( $configuration->getHost(), $configuration->getPort(), $configuration->getTimeout() )) ); $database->connect( $configuration->getUser(), $configuration->getPassword() ); return $database; }
[ "public", "function", "getConnection", "(", "$", "connectionName", "=", "'default'", ")", "{", "if", "(", "$", "this", "->", "connections", "->", "containsKey", "(", "$", "connectionName", ")", ")", "{", "return", "$", "this", "->", "connections", "->", "get", "(", "$", "connectionName", ")", ";", "}", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "connectionName", ")", ";", "$", "this", "->", "connections", "->", "set", "(", "$", "connectionName", ",", "$", "database", "=", "(", "new", "\\", "OrientDB", "(", "$", "configuration", "->", "getHost", "(", ")", ",", "$", "configuration", "->", "getPort", "(", ")", ",", "$", "configuration", "->", "getTimeout", "(", ")", ")", ")", ")", ";", "$", "database", "->", "connect", "(", "$", "configuration", "->", "getUser", "(", ")", ",", "$", "configuration", "->", "getPassword", "(", ")", ")", ";", "return", "$", "database", ";", "}" ]
Return registered connection under given connectionName @param string $connectionName @return \OrientDB
[ "Return", "registered", "connection", "under", "given", "connectionName" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L92-L113
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.createDatabase
public function createDatabase($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBCreate( $configuration->getDatabase(), $configuration->getDataType(), $configuration->getStorageType() ); return $this->getDatabase($connectionName); }
php
public function createDatabase($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBCreate( $configuration->getDatabase(), $configuration->getDataType(), $configuration->getStorageType() ); return $this->getDatabase($connectionName); }
[ "public", "function", "createDatabase", "(", "$", "connectionName", ")", "{", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "connectionName", ")", ";", "$", "database", "=", "$", "this", "->", "getConnection", "(", "$", "connectionName", ")", ";", "$", "database", "->", "DBCreate", "(", "$", "configuration", "->", "getDatabase", "(", ")", ",", "$", "configuration", "->", "getDataType", "(", ")", ",", "$", "configuration", "->", "getStorageType", "(", ")", ")", ";", "return", "$", "this", "->", "getDatabase", "(", "$", "connectionName", ")", ";", "}" ]
Tries to create a database for given connection name @param string $name @return \OrientDB
[ "Tries", "to", "create", "a", "database", "for", "given", "connection", "name" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L122-L134
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.dropDatabase
public function dropDatabase($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBDelete( $configuration->getDatabase() ); }
php
public function dropDatabase($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBDelete( $configuration->getDatabase() ); }
[ "public", "function", "dropDatabase", "(", "$", "connectionName", ")", "{", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "connectionName", ")", ";", "$", "database", "=", "$", "this", "->", "getConnection", "(", "$", "connectionName", ")", ";", "$", "database", "->", "DBDelete", "(", "$", "configuration", "->", "getDatabase", "(", ")", ")", ";", "}" ]
Tries to drop a database for given connection name @param string $name @return \OrientDB
[ "Tries", "to", "drop", "a", "database", "for", "given", "connection", "name" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L143-L151
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.getDatabase
public function getDatabase($connectionName = 'default') { if ($this->databases->containsKey($connectionName)) { return $this->databases->get($connectionName); } $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBOpen( $configuration->getDatabase(), $configuration->getUser(), $configuration->getPassword() ); $this->databases->set($connectionName, $database); return $this->databases->get($connectionName); }
php
public function getDatabase($connectionName = 'default') { if ($this->databases->containsKey($connectionName)) { return $this->databases->get($connectionName); } $configuration = $this->getConfiguration($connectionName); $database = $this->getConnection($connectionName); $database->DBOpen( $configuration->getDatabase(), $configuration->getUser(), $configuration->getPassword() ); $this->databases->set($connectionName, $database); return $this->databases->get($connectionName); }
[ "public", "function", "getDatabase", "(", "$", "connectionName", "=", "'default'", ")", "{", "if", "(", "$", "this", "->", "databases", "->", "containsKey", "(", "$", "connectionName", ")", ")", "{", "return", "$", "this", "->", "databases", "->", "get", "(", "$", "connectionName", ")", ";", "}", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "connectionName", ")", ";", "$", "database", "=", "$", "this", "->", "getConnection", "(", "$", "connectionName", ")", ";", "$", "database", "->", "DBOpen", "(", "$", "configuration", "->", "getDatabase", "(", ")", ",", "$", "configuration", "->", "getUser", "(", ")", ",", "$", "configuration", "->", "getPassword", "(", ")", ")", ";", "$", "this", "->", "databases", "->", "set", "(", "$", "connectionName", ",", "$", "database", ")", ";", "return", "$", "this", "->", "databases", "->", "get", "(", "$", "connectionName", ")", ";", "}" ]
Return registered database under given name @param string $connectionName @return \OrientDB
[ "Return", "registered", "database", "under", "given", "name" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L160-L178
Linkvalue-Interne/MajoraOrientDBBundle
src/Majora/Component/Graph/Engine/OrientDbEngine.php
OrientDbEngine.synchronize
public function synchronize($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getDatabase($connectionName); foreach ($configuration->getVertexes() as $vertex) { try { $database->query(sprintf('CREATE CLASS %s EXTENDS V', $vertex->getName() )); $database->query(sprintf('DISPLAY RECORD 0', $vertex->getName() )); dump($res); die; } catch (\Exception $e) { if (preg_match(sprintf('/Class %s already exists in current database$/', $vertex->getName()), $e->getMessage())) { continue; } throw $e; } } }
php
public function synchronize($connectionName) { $configuration = $this->getConfiguration($connectionName); $database = $this->getDatabase($connectionName); foreach ($configuration->getVertexes() as $vertex) { try { $database->query(sprintf('CREATE CLASS %s EXTENDS V', $vertex->getName() )); $database->query(sprintf('DISPLAY RECORD 0', $vertex->getName() )); dump($res); die; } catch (\Exception $e) { if (preg_match(sprintf('/Class %s already exists in current database$/', $vertex->getName()), $e->getMessage())) { continue; } throw $e; } } }
[ "public", "function", "synchronize", "(", "$", "connectionName", ")", "{", "$", "configuration", "=", "$", "this", "->", "getConfiguration", "(", "$", "connectionName", ")", ";", "$", "database", "=", "$", "this", "->", "getDatabase", "(", "$", "connectionName", ")", ";", "foreach", "(", "$", "configuration", "->", "getVertexes", "(", ")", "as", "$", "vertex", ")", "{", "try", "{", "$", "database", "->", "query", "(", "sprintf", "(", "'CREATE CLASS %s EXTENDS V'", ",", "$", "vertex", "->", "getName", "(", ")", ")", ")", ";", "$", "database", "->", "query", "(", "sprintf", "(", "'DISPLAY RECORD 0'", ",", "$", "vertex", "->", "getName", "(", ")", ")", ")", ";", "dump", "(", "$", "res", ")", ";", "die", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "preg_match", "(", "sprintf", "(", "'/Class %s already exists in current database$/'", ",", "$", "vertex", "->", "getName", "(", ")", ")", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", "{", "continue", ";", "}", "throw", "$", "e", ";", "}", "}", "}" ]
Synchronize vertexes and edges with related OrientDb database @param string $connectionName
[ "Synchronize", "vertexes", "and", "edges", "with", "related", "OrientDb", "database" ]
train
https://github.com/Linkvalue-Interne/MajoraOrientDBBundle/blob/9fc9a409604472b558319c274442f75bbd055435/src/Majora/Component/Graph/Engine/OrientDbEngine.php#L185-L207
1HappyPlace/ansi-terminal
src/ANSI/EscapeSequenceGenerator.php
EscapeSequenceGenerator.generateTextColorSequence
public static function generateTextColorSequence(ColorInterface $textColor, $mode) { $code = $textColor->generateColorCoding($mode); // if a code came back if ($code !== "") { // return the full sequence return self::CSI . $code . self::CSE; // no valid color code } else { // return nothing return ""; } }
php
public static function generateTextColorSequence(ColorInterface $textColor, $mode) { $code = $textColor->generateColorCoding($mode); // if a code came back if ($code !== "") { // return the full sequence return self::CSI . $code . self::CSE; // no valid color code } else { // return nothing return ""; } }
[ "public", "static", "function", "generateTextColorSequence", "(", "ColorInterface", "$", "textColor", ",", "$", "mode", ")", "{", "$", "code", "=", "$", "textColor", "->", "generateColorCoding", "(", "$", "mode", ")", ";", "// if a code came back", "if", "(", "$", "code", "!==", "\"\"", ")", "{", "// return the full sequence", "return", "self", "::", "CSI", ".", "$", "code", ".", "self", "::", "CSE", ";", "// no valid color code", "}", "else", "{", "// return nothing", "return", "\"\"", ";", "}", "}" ]
Static helper function to generate a text color sequence @param ColorInterface $textColor - the color desired @param Mode $mode - the terminal mode @return string - the full escape sequence for the text color, or an empty string if color or mode is not valid
[ "Static", "helper", "function", "to", "generate", "a", "text", "color", "sequence", "@param", "ColorInterface", "$textColor", "-", "the", "color", "desired", "@param", "Mode", "$mode", "-", "the", "terminal", "mode" ]
train
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/EscapeSequenceGenerator.php#L136-L152
1HappyPlace/ansi-terminal
src/ANSI/EscapeSequenceGenerator.php
EscapeSequenceGenerator.generateFillColorSequence
public static function generateFillColorSequence(ColorInterface $fillColor, $mode) { $code = $fillColor->generateColorCoding($mode, true); // if a code came back if ($code !== "") { // return the full sequence return self::CSI . $code . self::CSE; // no valid color code } else { // return nothing return ""; } }
php
public static function generateFillColorSequence(ColorInterface $fillColor, $mode) { $code = $fillColor->generateColorCoding($mode, true); // if a code came back if ($code !== "") { // return the full sequence return self::CSI . $code . self::CSE; // no valid color code } else { // return nothing return ""; } }
[ "public", "static", "function", "generateFillColorSequence", "(", "ColorInterface", "$", "fillColor", ",", "$", "mode", ")", "{", "$", "code", "=", "$", "fillColor", "->", "generateColorCoding", "(", "$", "mode", ",", "true", ")", ";", "// if a code came back", "if", "(", "$", "code", "!==", "\"\"", ")", "{", "// return the full sequence", "return", "self", "::", "CSI", ".", "$", "code", ".", "self", "::", "CSE", ";", "// no valid color code", "}", "else", "{", "// return nothing", "return", "\"\"", ";", "}", "}" ]
Static helper function to generate a fill color sequence @param ColorInterface $fillColor - the color desired @param Mode $mode - the terminal mode @return string - the full escape sequence for the text color
[ "Static", "helper", "function", "to", "generate", "a", "fill", "color", "sequence", "@param", "ColorInterface", "$fillColor", "-", "the", "color", "desired", "@param", "Mode", "$mode", "-", "the", "terminal", "mode" ]
train
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/EscapeSequenceGenerator.php#L161-L177
1HappyPlace/ansi-terminal
src/ANSI/EscapeSequenceGenerator.php
EscapeSequenceGenerator.generateSequence
public function generateSequence(TerminalState $state, $reset) { // this will return null if there are no active styles $sequence = ""; // build an array of the currently active style codes $styles = []; if ($state->isBold()) {$styles[] = self::BOLD;} if ($state->isUnderscore()) {$styles[] = self::UNDERSCORE;} if ($state->getTextColor()->isValid()) {$styles[] = $state->getTextColor()->generateColorCoding($this->mode);} if ($state->getFillColor()->isValid()) {$styles[] = $state->getFillColor()->generateColorCoding($this->mode, true);} // if there is anything in the style array if (count($styles)) { // start the sequence with the control sequence introducer and a clear code $sequence = self::CSI; // if a reset was desired if ($reset) { // add the clear code $sequence .= self::CLEAR . ";"; } // go through the array of style codes for ($i = 0; $i < count($styles); ++$i) { // append the code $sequence .= $styles[$i]; // ensure this is not the last code if ($i < (count($styles) - 1)) { // add the semi-colon separator (but not after the last one) $sequence .= ";"; } } // append the closing sequence $sequence .= self::CSE; } else { // if nothing is changing, only need to send something if the reset was requested if ($reset) { // it may be that just one thing is turning off, send the clear code $sequence .= self::generateClearSequence(); } } return $sequence; }
php
public function generateSequence(TerminalState $state, $reset) { // this will return null if there are no active styles $sequence = ""; // build an array of the currently active style codes $styles = []; if ($state->isBold()) {$styles[] = self::BOLD;} if ($state->isUnderscore()) {$styles[] = self::UNDERSCORE;} if ($state->getTextColor()->isValid()) {$styles[] = $state->getTextColor()->generateColorCoding($this->mode);} if ($state->getFillColor()->isValid()) {$styles[] = $state->getFillColor()->generateColorCoding($this->mode, true);} // if there is anything in the style array if (count($styles)) { // start the sequence with the control sequence introducer and a clear code $sequence = self::CSI; // if a reset was desired if ($reset) { // add the clear code $sequence .= self::CLEAR . ";"; } // go through the array of style codes for ($i = 0; $i < count($styles); ++$i) { // append the code $sequence .= $styles[$i]; // ensure this is not the last code if ($i < (count($styles) - 1)) { // add the semi-colon separator (but not after the last one) $sequence .= ";"; } } // append the closing sequence $sequence .= self::CSE; } else { // if nothing is changing, only need to send something if the reset was requested if ($reset) { // it may be that just one thing is turning off, send the clear code $sequence .= self::generateClearSequence(); } } return $sequence; }
[ "public", "function", "generateSequence", "(", "TerminalState", "$", "state", ",", "$", "reset", ")", "{", "// this will return null if there are no active styles", "$", "sequence", "=", "\"\"", ";", "// build an array of the currently active style codes", "$", "styles", "=", "[", "]", ";", "if", "(", "$", "state", "->", "isBold", "(", ")", ")", "{", "$", "styles", "[", "]", "=", "self", "::", "BOLD", ";", "}", "if", "(", "$", "state", "->", "isUnderscore", "(", ")", ")", "{", "$", "styles", "[", "]", "=", "self", "::", "UNDERSCORE", ";", "}", "if", "(", "$", "state", "->", "getTextColor", "(", ")", "->", "isValid", "(", ")", ")", "{", "$", "styles", "[", "]", "=", "$", "state", "->", "getTextColor", "(", ")", "->", "generateColorCoding", "(", "$", "this", "->", "mode", ")", ";", "}", "if", "(", "$", "state", "->", "getFillColor", "(", ")", "->", "isValid", "(", ")", ")", "{", "$", "styles", "[", "]", "=", "$", "state", "->", "getFillColor", "(", ")", "->", "generateColorCoding", "(", "$", "this", "->", "mode", ",", "true", ")", ";", "}", "// if there is anything in the style array", "if", "(", "count", "(", "$", "styles", ")", ")", "{", "// start the sequence with the control sequence introducer and a clear code", "$", "sequence", "=", "self", "::", "CSI", ";", "// if a reset was desired", "if", "(", "$", "reset", ")", "{", "// add the clear code", "$", "sequence", ".=", "self", "::", "CLEAR", ".", "\";\"", ";", "}", "// go through the array of style codes", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "styles", ")", ";", "++", "$", "i", ")", "{", "// append the code", "$", "sequence", ".=", "$", "styles", "[", "$", "i", "]", ";", "// ensure this is not the last code", "if", "(", "$", "i", "<", "(", "count", "(", "$", "styles", ")", "-", "1", ")", ")", "{", "// add the semi-colon separator (but not after the last one)", "$", "sequence", ".=", "\";\"", ";", "}", "}", "// append the closing sequence", "$", "sequence", ".=", "self", "::", "CSE", ";", "}", "else", "{", "// if nothing is changing, only need to send something if the reset was requested", "if", "(", "$", "reset", ")", "{", "// it may be that just one thing is turning off, send the clear code", "$", "sequence", ".=", "self", "::", "generateClearSequence", "(", ")", ";", "}", "}", "return", "$", "sequence", ";", "}" ]
Generate the escape sequencing for a particular state @param TerminalState $state - the state to achieve @param boolean $reset - whether the zero reset code needs to start this sequence @return string
[ "Generate", "the", "escape", "sequencing", "for", "a", "particular", "state" ]
train
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/EscapeSequenceGenerator.php#L197-L253
1HappyPlace/ansi-terminal
src/ANSI/EscapeSequenceGenerator.php
EscapeSequenceGenerator.generate
public function generate(TerminalStateInterface $currentState, TerminalState $desiredState) { // get a state object with anything that is changing $changes = $currentState->findChanges($desiredState); // if an object is returned, then just positive changes are occurring if ($changes) { // if there are really no changes if ($changes->isClear()) { // return an empty string return ""; // there are some changes } else { // generate the sequence for the things that are actually changing return $this->generateSequence($changes, false); } // if null is returned, then something is getting turned off } else { // must generate a sequence with a clear return $this->generateSequence($desiredState, true); } }
php
public function generate(TerminalStateInterface $currentState, TerminalState $desiredState) { // get a state object with anything that is changing $changes = $currentState->findChanges($desiredState); // if an object is returned, then just positive changes are occurring if ($changes) { // if there are really no changes if ($changes->isClear()) { // return an empty string return ""; // there are some changes } else { // generate the sequence for the things that are actually changing return $this->generateSequence($changes, false); } // if null is returned, then something is getting turned off } else { // must generate a sequence with a clear return $this->generateSequence($desiredState, true); } }
[ "public", "function", "generate", "(", "TerminalStateInterface", "$", "currentState", ",", "TerminalState", "$", "desiredState", ")", "{", "// get a state object with anything that is changing", "$", "changes", "=", "$", "currentState", "->", "findChanges", "(", "$", "desiredState", ")", ";", "// if an object is returned, then just positive changes are occurring", "if", "(", "$", "changes", ")", "{", "// if there are really no changes", "if", "(", "$", "changes", "->", "isClear", "(", ")", ")", "{", "// return an empty string", "return", "\"\"", ";", "// there are some changes", "}", "else", "{", "// generate the sequence for the things that are actually changing", "return", "$", "this", "->", "generateSequence", "(", "$", "changes", ",", "false", ")", ";", "}", "// if null is returned, then something is getting turned off", "}", "else", "{", "// must generate a sequence with a clear", "return", "$", "this", "->", "generateSequence", "(", "$", "desiredState", ",", "true", ")", ";", "}", "}" ]
Generate an escape sequence based on the current state and the new desired state @param TerminalStateInterface $currentState @param TerminalState $desiredState @return string
[ "Generate", "an", "escape", "sequence", "based", "on", "the", "current", "state", "and", "the", "new", "desired", "state" ]
train
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/EscapeSequenceGenerator.php#L263-L295
geniv/nette-general-form
src/Events/ClearFormEvent.php
ClearFormEvent.update
public function update(IEventContainer $eventContainer, array $values) { $component = $eventContainer->getComponent(); if ($component->presenter->isAjax()) { // ajax reset form $component->redrawControl($this->snippetName); $eventContainer->getForm()->reset(); } else { // non ajax fallback $eventContainer->getForm()->reset(); } }
php
public function update(IEventContainer $eventContainer, array $values) { $component = $eventContainer->getComponent(); if ($component->presenter->isAjax()) { // ajax reset form $component->redrawControl($this->snippetName); $eventContainer->getForm()->reset(); } else { // non ajax fallback $eventContainer->getForm()->reset(); } }
[ "public", "function", "update", "(", "IEventContainer", "$", "eventContainer", ",", "array", "$", "values", ")", "{", "$", "component", "=", "$", "eventContainer", "->", "getComponent", "(", ")", ";", "if", "(", "$", "component", "->", "presenter", "->", "isAjax", "(", ")", ")", "{", "// ajax reset form", "$", "component", "->", "redrawControl", "(", "$", "this", "->", "snippetName", ")", ";", "$", "eventContainer", "->", "getForm", "(", ")", "->", "reset", "(", ")", ";", "}", "else", "{", "// non ajax fallback", "$", "eventContainer", "->", "getForm", "(", ")", "->", "reset", "(", ")", ";", "}", "}" ]
Update. @param IEventContainer $eventContainer @param array $values
[ "Update", "." ]
train
https://github.com/geniv/nette-general-form/blob/0d0548b63cf7db58c17ee12d6933f2dd995a64e6/src/Events/ClearFormEvent.php#L42-L53
netbull/CoreBundle
ORM/Subscribers/Sluggable/SluggableSubscriber.php
SluggableSubscriber.loadClassMetadata
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) { $classMetadata = $eventArgs->getClassMetadata(); if (null === $classMetadata->reflClass) { return; } if ($this->isSluggable($classMetadata)) { if (!$classMetadata->hasField('slug')) { $classMetadata->mapField([ 'fieldName' => 'slug', 'type' => 'string', 'nullable' => true ]); } } }
php
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) { $classMetadata = $eventArgs->getClassMetadata(); if (null === $classMetadata->reflClass) { return; } if ($this->isSluggable($classMetadata)) { if (!$classMetadata->hasField('slug')) { $classMetadata->mapField([ 'fieldName' => 'slug', 'type' => 'string', 'nullable' => true ]); } } }
[ "public", "function", "loadClassMetadata", "(", "LoadClassMetadataEventArgs", "$", "eventArgs", ")", "{", "$", "classMetadata", "=", "$", "eventArgs", "->", "getClassMetadata", "(", ")", ";", "if", "(", "null", "===", "$", "classMetadata", "->", "reflClass", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "isSluggable", "(", "$", "classMetadata", ")", ")", "{", "if", "(", "!", "$", "classMetadata", "->", "hasField", "(", "'slug'", ")", ")", "{", "$", "classMetadata", "->", "mapField", "(", "[", "'fieldName'", "=>", "'slug'", ",", "'type'", "=>", "'string'", ",", "'nullable'", "=>", "true", "]", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/ORM/Subscribers/Sluggable/SluggableSubscriber.php#L37-L54