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
zhouyl/mellivora
Mellivora/Database/Connection.php
Connection.getReadPdo
public function getReadPdo() { if ($this->transactions >= 1) { return $this->getPdo(); } if ($this->readPdo instanceof Closure) { return $this->readPdo = call_user_func($this->readPdo); } return $this->readPdo ?: $this->getPdo(); }
php
public function getReadPdo() { if ($this->transactions >= 1) { return $this->getPdo(); } if ($this->readPdo instanceof Closure) { return $this->readPdo = call_user_func($this->readPdo); } return $this->readPdo ?: $this->getPdo(); }
[ "public", "function", "getReadPdo", "(", ")", "{", "if", "(", "$", "this", "->", "transactions", ">=", "1", ")", "{", "return", "$", "this", "->", "getPdo", "(", ")", ";", "}", "if", "(", "$", "this", "->", "readPdo", "instanceof", "Closure", ")", "{", "return", "$", "this", "->", "readPdo", "=", "call_user_func", "(", "$", "this", "->", "readPdo", ")", ";", "}", "return", "$", "this", "->", "readPdo", "?", ":", "$", "this", "->", "getPdo", "(", ")", ";", "}" ]
Get the current PDO connection used for reading. @return \PDO
[ "Get", "the", "current", "PDO", "connection", "used", "for", "reading", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Connection.php#L938-L949
skmetaly/laravel-twitch-restful-api
src/API/Search.php
Search.searchChannels
public function searchChannels($options) { $availableOptions = ['query', 'limit', 'offset']; $parameters = []; // Filter the available options foreach ($availableOptions as $option) { if (isset($options[ $option ])) { $parameters[ $option ] = $options[ $option ]; } } $response = $this->client->get('/kraken/search/channels', ['query' => $parameters]); return $response->json(); }
php
public function searchChannels($options) { $availableOptions = ['query', 'limit', 'offset']; $parameters = []; // Filter the available options foreach ($availableOptions as $option) { if (isset($options[ $option ])) { $parameters[ $option ] = $options[ $option ]; } } $response = $this->client->get('/kraken/search/channels', ['query' => $parameters]); return $response->json(); }
[ "public", "function", "searchChannels", "(", "$", "options", ")", "{", "$", "availableOptions", "=", "[", "'query'", ",", "'limit'", ",", "'offset'", "]", ";", "$", "parameters", "=", "[", "]", ";", "// Filter the available options", "foreach", "(", "$", "availableOptions", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "option", "]", ")", ")", "{", "$", "parameters", "[", "$", "option", "]", "=", "$", "options", "[", "$", "option", "]", ";", "}", "}", "$", "response", "=", "$", "this", "->", "client", "->", "get", "(", "'/kraken/search/channels'", ",", "[", "'query'", "=>", "$", "parameters", "]", ")", ";", "return", "$", "response", "->", "json", "(", ")", ";", "}" ]
Returns a list of channel objects matching the search query. @param $options @return json
[ "Returns", "a", "list", "of", "channel", "objects", "matching", "the", "search", "query", "." ]
train
https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/Search.php#L22-L40
skmetaly/laravel-twitch-restful-api
src/API/Search.php
Search.streamsChannel
public function streamsChannel($channel) { $response = $this->client->get(config('twitch-api.api_url') . '/kraken/streams/' . $channel); return $response->json(); }
php
public function streamsChannel($channel) { $response = $this->client->get(config('twitch-api.api_url') . '/kraken/streams/' . $channel); return $response->json(); }
[ "public", "function", "streamsChannel", "(", "$", "channel", ")", "{", "$", "response", "=", "$", "this", "->", "client", "->", "get", "(", "config", "(", "'twitch-api.api_url'", ")", ".", "'/kraken/streams/'", ".", "$", "channel", ")", ";", "return", "$", "response", "->", "json", "(", ")", ";", "}" ]
Returns a stream object if live. @param $channel @return json
[ "Returns", "a", "stream", "object", "if", "live", "." ]
train
https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/Search.php#L109-L114
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/MethodDescriptor.php
MethodDescriptor.getResponse
public function getResponse() { /** @var Collection|null $returnTags */ $returnTags = $this->getReturn(); return $returnTags instanceof Collection && $returnTags->count() > 0 ? current($returnTags->getAll()) : null; }
php
public function getResponse() { /** @var Collection|null $returnTags */ $returnTags = $this->getReturn(); return $returnTags instanceof Collection && $returnTags->count() > 0 ? current($returnTags->getAll()) : null; }
[ "public", "function", "getResponse", "(", ")", "{", "/** @var Collection|null $returnTags */", "$", "returnTags", "=", "$", "this", "->", "getReturn", "(", ")", ";", "return", "$", "returnTags", "instanceof", "Collection", "&&", "$", "returnTags", "->", "count", "(", ")", ">", "0", "?", "current", "(", "$", "returnTags", "->", "getAll", "(", ")", ")", ":", "null", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/MethodDescriptor.php#L166-L174
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/MethodDescriptor.php
MethodDescriptor.getInheritedElement
public function getInheritedElement() { if ($this->inheritedElement !== null) { return $this->inheritedElement; } /** @var ClassDescriptor|InterfaceDescriptor|null $associatedClass */ $associatedClass = $this->getParent(); if (!$associatedClass instanceof ClassDescriptor && !$associatedClass instanceof InterfaceDescriptor) { return null; } /** @var ClassDescriptor|InterfaceDescriptor $parentClass|null */ $parentClass = $associatedClass->getParent(); if ($parentClass instanceof ClassDescriptor || $parentClass instanceof Collection) { // the parent of a class is always a class, but the parent of an interface is a collection of interfaces. $parents = $parentClass instanceof ClassDescriptor ? array($parentClass) : $parentClass->getAll(); foreach ($parents as $parent) { if ($parent instanceof ClassDescriptor || $parent instanceof InterfaceDescriptor) { $parentMethod = $parent->getMethods()->get($this->getName()); if ($parentMethod) { $this->inheritedElement = $parentMethod; return $this->inheritedElement; } } } } // also check all implemented interfaces next if the parent is a class and not an interface if ($associatedClass instanceof ClassDescriptor) { /** @var InterfaceDescriptor $interface */ foreach ($associatedClass->getInterfaces() as $interface) { if (!$interface instanceof InterfaceDescriptor) { continue; } $parentMethod = $interface->getMethods()->get($this->getName()); if ($parentMethod) { $this->inheritedElement = $parentMethod; return $this->inheritedElement; } } } return null; }
php
public function getInheritedElement() { if ($this->inheritedElement !== null) { return $this->inheritedElement; } /** @var ClassDescriptor|InterfaceDescriptor|null $associatedClass */ $associatedClass = $this->getParent(); if (!$associatedClass instanceof ClassDescriptor && !$associatedClass instanceof InterfaceDescriptor) { return null; } /** @var ClassDescriptor|InterfaceDescriptor $parentClass|null */ $parentClass = $associatedClass->getParent(); if ($parentClass instanceof ClassDescriptor || $parentClass instanceof Collection) { // the parent of a class is always a class, but the parent of an interface is a collection of interfaces. $parents = $parentClass instanceof ClassDescriptor ? array($parentClass) : $parentClass->getAll(); foreach ($parents as $parent) { if ($parent instanceof ClassDescriptor || $parent instanceof InterfaceDescriptor) { $parentMethod = $parent->getMethods()->get($this->getName()); if ($parentMethod) { $this->inheritedElement = $parentMethod; return $this->inheritedElement; } } } } // also check all implemented interfaces next if the parent is a class and not an interface if ($associatedClass instanceof ClassDescriptor) { /** @var InterfaceDescriptor $interface */ foreach ($associatedClass->getInterfaces() as $interface) { if (!$interface instanceof InterfaceDescriptor) { continue; } $parentMethod = $interface->getMethods()->get($this->getName()); if ($parentMethod) { $this->inheritedElement = $parentMethod; return $this->inheritedElement; } } } return null; }
[ "public", "function", "getInheritedElement", "(", ")", "{", "if", "(", "$", "this", "->", "inheritedElement", "!==", "null", ")", "{", "return", "$", "this", "->", "inheritedElement", ";", "}", "/** @var ClassDescriptor|InterfaceDescriptor|null $associatedClass */", "$", "associatedClass", "=", "$", "this", "->", "getParent", "(", ")", ";", "if", "(", "!", "$", "associatedClass", "instanceof", "ClassDescriptor", "&&", "!", "$", "associatedClass", "instanceof", "InterfaceDescriptor", ")", "{", "return", "null", ";", "}", "/** @var ClassDescriptor|InterfaceDescriptor $parentClass|null */", "$", "parentClass", "=", "$", "associatedClass", "->", "getParent", "(", ")", ";", "if", "(", "$", "parentClass", "instanceof", "ClassDescriptor", "||", "$", "parentClass", "instanceof", "Collection", ")", "{", "// the parent of a class is always a class, but the parent of an interface is a collection of interfaces.", "$", "parents", "=", "$", "parentClass", "instanceof", "ClassDescriptor", "?", "array", "(", "$", "parentClass", ")", ":", "$", "parentClass", "->", "getAll", "(", ")", ";", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "if", "(", "$", "parent", "instanceof", "ClassDescriptor", "||", "$", "parent", "instanceof", "InterfaceDescriptor", ")", "{", "$", "parentMethod", "=", "$", "parent", "->", "getMethods", "(", ")", "->", "get", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "parentMethod", ")", "{", "$", "this", "->", "inheritedElement", "=", "$", "parentMethod", ";", "return", "$", "this", "->", "inheritedElement", ";", "}", "}", "}", "}", "// also check all implemented interfaces next if the parent is a class and not an interface", "if", "(", "$", "associatedClass", "instanceof", "ClassDescriptor", ")", "{", "/** @var InterfaceDescriptor $interface */", "foreach", "(", "$", "associatedClass", "->", "getInterfaces", "(", ")", "as", "$", "interface", ")", "{", "if", "(", "!", "$", "interface", "instanceof", "InterfaceDescriptor", ")", "{", "continue", ";", "}", "$", "parentMethod", "=", "$", "interface", "->", "getMethods", "(", ")", "->", "get", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "parentMethod", ")", "{", "$", "this", "->", "inheritedElement", "=", "$", "parentMethod", ";", "return", "$", "this", "->", "inheritedElement", ";", "}", "}", "}", "return", "null", ";", "}" ]
Returns the Method from which this method should inherit its information, if any. The inheritance scheme for a method is more complicated than for most elements; the following business rules apply: 1. if the parent class/interface extends another class or other interfaces (interfaces have multiple inheritance!) then: 1. Check each parent class/interface's parent if they have a method with the exact same name 2. if a method is found with the same name; return the first one encountered. 2. if the parent is a class and implements interfaces, check each interface for a method with the exact same name. If such a method is found, return the first hit. @return MethodDescriptor|null
[ "Returns", "the", "Method", "from", "which", "this", "method", "should", "inherit", "its", "information", "if", "any", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/MethodDescriptor.php#L239-L286
GrupaZero/api
src/Gzero/Api/Transformer/ContentTranslationTransformer.php
ContentTranslationTransformer.transform
public function transform($translation) { $translation = $this->entityToArray(ContentTranslation::class, $translation); return [ 'id' => (int) $translation['id'], 'langCode' => $translation['lang_code'], 'title' => $translation['title'], 'teaser' => $translation['teaser'], 'body' => $translation['body'], 'seoTitle' => $translation['seo_title'], 'seoDescription' => $translation['seo_description'], 'isActive' => (bool) $translation['is_active'], 'createdAt' => $translation['created_at'], 'updatedAt' => $translation['updated_at'], ]; }
php
public function transform($translation) { $translation = $this->entityToArray(ContentTranslation::class, $translation); return [ 'id' => (int) $translation['id'], 'langCode' => $translation['lang_code'], 'title' => $translation['title'], 'teaser' => $translation['teaser'], 'body' => $translation['body'], 'seoTitle' => $translation['seo_title'], 'seoDescription' => $translation['seo_description'], 'isActive' => (bool) $translation['is_active'], 'createdAt' => $translation['created_at'], 'updatedAt' => $translation['updated_at'], ]; }
[ "public", "function", "transform", "(", "$", "translation", ")", "{", "$", "translation", "=", "$", "this", "->", "entityToArray", "(", "ContentTranslation", "::", "class", ",", "$", "translation", ")", ";", "return", "[", "'id'", "=>", "(", "int", ")", "$", "translation", "[", "'id'", "]", ",", "'langCode'", "=>", "$", "translation", "[", "'lang_code'", "]", ",", "'title'", "=>", "$", "translation", "[", "'title'", "]", ",", "'teaser'", "=>", "$", "translation", "[", "'teaser'", "]", ",", "'body'", "=>", "$", "translation", "[", "'body'", "]", ",", "'seoTitle'", "=>", "$", "translation", "[", "'seo_title'", "]", ",", "'seoDescription'", "=>", "$", "translation", "[", "'seo_description'", "]", ",", "'isActive'", "=>", "(", "bool", ")", "$", "translation", "[", "'is_active'", "]", ",", "'createdAt'", "=>", "$", "translation", "[", "'created_at'", "]", ",", "'updatedAt'", "=>", "$", "translation", "[", "'updated_at'", "]", ",", "]", ";", "}" ]
Transforms content translation entity @param ContentTranslation|array $translation ContentTranslation entity @return array
[ "Transforms", "content", "translation", "entity" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/ContentTranslationTransformer.php#L26-L41
GrupaZero/api
src/Gzero/Api/Controller/Admin/ContentTranslationController.php
ContentTranslationController.index
public function index($id) { $this->authorize('readList', Content::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $content = $this->repository->getById($id); if (!empty($content)) { $results = $this->repository->getTranslations( $content, $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new ContentTranslationTransformer); } else { return $this->respondNotFound(); } }
php
public function index($id) { $this->authorize('readList', Content::class); $input = $this->validator->validate('list'); $params = $this->processor->process($input)->getProcessedFields(); $content = $this->repository->getById($id); if (!empty($content)) { $results = $this->repository->getTranslations( $content, $params['filter'], $params['orderBy'], $params['page'], $params['perPage'] ); return $this->respondWithSuccess($results, new ContentTranslationTransformer); } else { return $this->respondNotFound(); } }
[ "public", "function", "index", "(", "$", "id", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "Content", "::", "class", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'list'", ")", ";", "$", "params", "=", "$", "this", "->", "processor", "->", "process", "(", "$", "input", ")", "->", "getProcessedFields", "(", ")", ";", "$", "content", "=", "$", "this", "->", "repository", "->", "getById", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "$", "results", "=", "$", "this", "->", "repository", "->", "getTranslations", "(", "$", "content", ",", "$", "params", "[", "'filter'", "]", ",", "$", "params", "[", "'orderBy'", "]", ",", "$", "params", "[", "'page'", "]", ",", "$", "params", "[", "'perPage'", "]", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "results", ",", "new", "ContentTranslationTransformer", ")", ";", "}", "else", "{", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}", "}" ]
Display a listing of the resource. @param int|null $id Id used for nested resources @return \Illuminate\Http\JsonResponse
[ "Display", "a", "listing", "of", "the", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/ContentTranslationController.php#L61-L79
GrupaZero/api
src/Gzero/Api/Controller/Admin/ContentTranslationController.php
ContentTranslationController.show
public function show($id, $translationId) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('read', $content); $translation = $this->repository->getContentTranslationById($content, $translationId); if (!empty($translation)) { return $this->respondWithSuccess($translation, new ContentTranslationTransformer); } } return $this->respondNotFound(); }
php
public function show($id, $translationId) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('read', $content); $translation = $this->repository->getContentTranslationById($content, $translationId); if (!empty($translation)) { return $this->respondWithSuccess($translation, new ContentTranslationTransformer); } } return $this->respondNotFound(); }
[ "public", "function", "show", "(", "$", "id", ",", "$", "translationId", ")", "{", "$", "content", "=", "$", "this", "->", "getContent", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "$", "this", "->", "authorize", "(", "'read'", ",", "$", "content", ")", ";", "$", "translation", "=", "$", "this", "->", "repository", "->", "getContentTranslationById", "(", "$", "content", ",", "$", "translationId", ")", ";", "if", "(", "!", "empty", "(", "$", "translation", ")", ")", "{", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "translation", ",", "new", "ContentTranslationTransformer", ")", ";", "}", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Display a specified resource. @param int $id Id of the content @param int $translationId Id of the content translation @return \Illuminate\Http\JsonResponse
[ "Display", "a", "specified", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/ContentTranslationController.php#L89-L100
GrupaZero/api
src/Gzero/Api/Controller/Admin/ContentTranslationController.php
ContentTranslationController.store
public function store($id) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('create', $content); $this->authorize('update', $content); $input = $this->validator->validate('create'); $translation = $this->repository->createTranslation($content, $input); return $this->respondWithSuccess($translation, new ContentTranslationTransformer); } return $this->respondNotFound(); }
php
public function store($id) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('create', $content); $this->authorize('update', $content); $input = $this->validator->validate('create'); $translation = $this->repository->createTranslation($content, $input); return $this->respondWithSuccess($translation, new ContentTranslationTransformer); } return $this->respondNotFound(); }
[ "public", "function", "store", "(", "$", "id", ")", "{", "$", "content", "=", "$", "this", "->", "getContent", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "$", "this", "->", "authorize", "(", "'create'", ",", "$", "content", ")", ";", "$", "this", "->", "authorize", "(", "'update'", ",", "$", "content", ")", ";", "$", "input", "=", "$", "this", "->", "validator", "->", "validate", "(", "'create'", ")", ";", "$", "translation", "=", "$", "this", "->", "repository", "->", "createTranslation", "(", "$", "content", ",", "$", "input", ")", ";", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "translation", ",", "new", "ContentTranslationTransformer", ")", ";", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Stores newly created translation for specified content entity in database. @param int $id Id of the content @return \Illuminate\Http\JsonResponse
[ "Stores", "newly", "created", "translation", "for", "specified", "content", "entity", "in", "database", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/ContentTranslationController.php#L109-L120
GrupaZero/api
src/Gzero/Api/Controller/Admin/ContentTranslationController.php
ContentTranslationController.destroy
public function destroy($id, $translationId) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('delete', $content); $translation = $this->repository->getContentTranslationById($content, $translationId); if (!empty($translation)) { $this->repository->deleteTranslation($translation); return $this->respondWithSimpleSuccess(['success' => true]); } } return $this->respondNotFound(); }
php
public function destroy($id, $translationId) { $content = $this->getContent($id); if (!empty($content)) { $this->authorize('delete', $content); $translation = $this->repository->getContentTranslationById($content, $translationId); if (!empty($translation)) { $this->repository->deleteTranslation($translation); return $this->respondWithSimpleSuccess(['success' => true]); } } return $this->respondNotFound(); }
[ "public", "function", "destroy", "(", "$", "id", ",", "$", "translationId", ")", "{", "$", "content", "=", "$", "this", "->", "getContent", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "$", "this", "->", "authorize", "(", "'delete'", ",", "$", "content", ")", ";", "$", "translation", "=", "$", "this", "->", "repository", "->", "getContentTranslationById", "(", "$", "content", ",", "$", "translationId", ")", ";", "if", "(", "!", "empty", "(", "$", "translation", ")", ")", "{", "$", "this", "->", "repository", "->", "deleteTranslation", "(", "$", "translation", ")", ";", "return", "$", "this", "->", "respondWithSimpleSuccess", "(", "[", "'success'", "=>", "true", "]", ")", ";", "}", "}", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}" ]
Remove the specified resource from database. @param int $id Id of the content @param int $translationId Id of the content translation @return \Illuminate\Http\JsonResponse
[ "Remove", "the", "specified", "resource", "from", "database", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/ContentTranslationController.php#L142-L154
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.add
public function add( $id, $parentId, $blockType, array $options = [], $siblingId = null, $prepend = null ) { $this->layoutManipulator->add($id, $parentId, $blockType, $options, $siblingId, $prepend); return $this; }
php
public function add( $id, $parentId, $blockType, array $options = [], $siblingId = null, $prepend = null ) { $this->layoutManipulator->add($id, $parentId, $blockType, $options, $siblingId, $prepend); return $this; }
[ "public", "function", "add", "(", "$", "id", ",", "$", "parentId", ",", "$", "blockType", ",", "array", "$", "options", "=", "[", "]", ",", "$", "siblingId", "=", "null", ",", "$", "prepend", "=", "null", ")", "{", "$", "this", "->", "layoutManipulator", "->", "add", "(", "$", "id", ",", "$", "parentId", ",", "$", "blockType", ",", "$", "options", ",", "$", "siblingId", ",", "$", "prepend", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L66-L77
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.move
public function move($id, $parentId = null, $siblingId = null, $prepend = null) { $this->layoutManipulator->move($id, $parentId, $siblingId, $prepend); return $this; }
php
public function move($id, $parentId = null, $siblingId = null, $prepend = null) { $this->layoutManipulator->move($id, $parentId, $siblingId, $prepend); return $this; }
[ "public", "function", "move", "(", "$", "id", ",", "$", "parentId", "=", "null", ",", "$", "siblingId", "=", "null", ",", "$", "prepend", "=", "null", ")", "{", "$", "this", "->", "layoutManipulator", "->", "move", "(", "$", "id", ",", "$", "parentId", ",", "$", "siblingId", ",", "$", "prepend", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L92-L97
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.setOption
public function setOption($id, $optionName, $optionValue) { $this->layoutManipulator->setOption($id, $optionName, $optionValue); return $this; }
php
public function setOption($id, $optionName, $optionValue) { $this->layoutManipulator->setOption($id, $optionName, $optionValue); return $this; }
[ "public", "function", "setOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", "{", "$", "this", "->", "layoutManipulator", "->", "setOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L122-L127
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.appendOption
public function appendOption($id, $optionName, $optionValue) { $this->layoutManipulator->appendOption($id, $optionName, $optionValue); return $this; }
php
public function appendOption($id, $optionName, $optionValue) { $this->layoutManipulator->appendOption($id, $optionName, $optionValue); return $this; }
[ "public", "function", "appendOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", "{", "$", "this", "->", "layoutManipulator", "->", "appendOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L132-L137
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.subtractOption
public function subtractOption($id, $optionName, $optionValue) { $this->layoutManipulator->subtractOption($id, $optionName, $optionValue); return $this; }
php
public function subtractOption($id, $optionName, $optionValue) { $this->layoutManipulator->subtractOption($id, $optionName, $optionValue); return $this; }
[ "public", "function", "subtractOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", "{", "$", "this", "->", "layoutManipulator", "->", "subtractOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "optionValue", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L142-L147
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.replaceOption
public function replaceOption($id, $optionName, $oldOptionValue, $newOptionValue) { $this->layoutManipulator->replaceOption($id, $optionName, $oldOptionValue, $newOptionValue); return $this; }
php
public function replaceOption($id, $optionName, $oldOptionValue, $newOptionValue) { $this->layoutManipulator->replaceOption($id, $optionName, $oldOptionValue, $newOptionValue); return $this; }
[ "public", "function", "replaceOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "oldOptionValue", ",", "$", "newOptionValue", ")", "{", "$", "this", "->", "layoutManipulator", "->", "replaceOption", "(", "$", "id", ",", "$", "optionName", ",", "$", "oldOptionValue", ",", "$", "newOptionValue", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L152-L157
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.changeBlockType
public function changeBlockType($id, $blockType, $optionsCallback = null) { $this->layoutManipulator->changeBlockType($id, $blockType, $optionsCallback); return $this; }
php
public function changeBlockType($id, $blockType, $optionsCallback = null) { $this->layoutManipulator->changeBlockType($id, $blockType, $optionsCallback); return $this; }
[ "public", "function", "changeBlockType", "(", "$", "id", ",", "$", "blockType", ",", "$", "optionsCallback", "=", "null", ")", "{", "$", "this", "->", "layoutManipulator", "->", "changeBlockType", "(", "$", "id", ",", "$", "blockType", ",", "$", "optionsCallback", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L172-L177
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.setBlockTheme
public function setBlockTheme($themes, $id = null) { $this->layoutManipulator->setBlockTheme($themes, $id); return $this; }
php
public function setBlockTheme($themes, $id = null) { $this->layoutManipulator->setBlockTheme($themes, $id); return $this; }
[ "public", "function", "setBlockTheme", "(", "$", "themes", ",", "$", "id", "=", "null", ")", "{", "$", "this", "->", "layoutManipulator", "->", "setBlockTheme", "(", "$", "themes", ",", "$", "id", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L182-L187
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.getLayout
public function getLayout(ContextInterface $context, $rootId = null) { if (!$context->isResolved()) { $this->registry->configureContext($context); $context->resolve(); } $this->layoutManipulator->applyChanges($context); $rawLayout = $this->rawLayoutBuilder->getRawLayout(); if ($this->blockViewCache) { $rootView = $this->blockViewCache->fetch($context); if ($rootView === null) { $rootView = $this->blockFactory->createBlockView($rawLayout, $context); $this->blockViewCache->save($context, $rootView); } } else { $rootView = $this->blockFactory->createBlockView($rawLayout, $context); } $rootView = $this->getRootView($rootView, $rootId); if ($context->getOr('expressions_evaluate')) { $deferred = $context->getOr('expressions_evaluate_deferred'); $encoding = $context->getOr('expressions_encoding'); $this->processBlockViewData( $rootView, $context, new DataAccessor($this->registry, $context), $deferred, $encoding ); } $layout = $this->createLayout($rootView); $rootBlockId = $rawLayout->getRootId(); $blockThemes = $rawLayout->getBlockThemes(); foreach ($blockThemes as $blockId => $themes) { $layout->setBlockTheme($themes, $blockId !== $rootBlockId ? $blockId : null); } $formThemes = $rawLayout->getFormThemes(); $layout->setFormTheme($formThemes); return $layout; }
php
public function getLayout(ContextInterface $context, $rootId = null) { if (!$context->isResolved()) { $this->registry->configureContext($context); $context->resolve(); } $this->layoutManipulator->applyChanges($context); $rawLayout = $this->rawLayoutBuilder->getRawLayout(); if ($this->blockViewCache) { $rootView = $this->blockViewCache->fetch($context); if ($rootView === null) { $rootView = $this->blockFactory->createBlockView($rawLayout, $context); $this->blockViewCache->save($context, $rootView); } } else { $rootView = $this->blockFactory->createBlockView($rawLayout, $context); } $rootView = $this->getRootView($rootView, $rootId); if ($context->getOr('expressions_evaluate')) { $deferred = $context->getOr('expressions_evaluate_deferred'); $encoding = $context->getOr('expressions_encoding'); $this->processBlockViewData( $rootView, $context, new DataAccessor($this->registry, $context), $deferred, $encoding ); } $layout = $this->createLayout($rootView); $rootBlockId = $rawLayout->getRootId(); $blockThemes = $rawLayout->getBlockThemes(); foreach ($blockThemes as $blockId => $themes) { $layout->setBlockTheme($themes, $blockId !== $rootBlockId ? $blockId : null); } $formThemes = $rawLayout->getFormThemes(); $layout->setFormTheme($formThemes); return $layout; }
[ "public", "function", "getLayout", "(", "ContextInterface", "$", "context", ",", "$", "rootId", "=", "null", ")", "{", "if", "(", "!", "$", "context", "->", "isResolved", "(", ")", ")", "{", "$", "this", "->", "registry", "->", "configureContext", "(", "$", "context", ")", ";", "$", "context", "->", "resolve", "(", ")", ";", "}", "$", "this", "->", "layoutManipulator", "->", "applyChanges", "(", "$", "context", ")", ";", "$", "rawLayout", "=", "$", "this", "->", "rawLayoutBuilder", "->", "getRawLayout", "(", ")", ";", "if", "(", "$", "this", "->", "blockViewCache", ")", "{", "$", "rootView", "=", "$", "this", "->", "blockViewCache", "->", "fetch", "(", "$", "context", ")", ";", "if", "(", "$", "rootView", "===", "null", ")", "{", "$", "rootView", "=", "$", "this", "->", "blockFactory", "->", "createBlockView", "(", "$", "rawLayout", ",", "$", "context", ")", ";", "$", "this", "->", "blockViewCache", "->", "save", "(", "$", "context", ",", "$", "rootView", ")", ";", "}", "}", "else", "{", "$", "rootView", "=", "$", "this", "->", "blockFactory", "->", "createBlockView", "(", "$", "rawLayout", ",", "$", "context", ")", ";", "}", "$", "rootView", "=", "$", "this", "->", "getRootView", "(", "$", "rootView", ",", "$", "rootId", ")", ";", "if", "(", "$", "context", "->", "getOr", "(", "'expressions_evaluate'", ")", ")", "{", "$", "deferred", "=", "$", "context", "->", "getOr", "(", "'expressions_evaluate_deferred'", ")", ";", "$", "encoding", "=", "$", "context", "->", "getOr", "(", "'expressions_encoding'", ")", ";", "$", "this", "->", "processBlockViewData", "(", "$", "rootView", ",", "$", "context", ",", "new", "DataAccessor", "(", "$", "this", "->", "registry", ",", "$", "context", ")", ",", "$", "deferred", ",", "$", "encoding", ")", ";", "}", "$", "layout", "=", "$", "this", "->", "createLayout", "(", "$", "rootView", ")", ";", "$", "rootBlockId", "=", "$", "rawLayout", "->", "getRootId", "(", ")", ";", "$", "blockThemes", "=", "$", "rawLayout", "->", "getBlockThemes", "(", ")", ";", "foreach", "(", "$", "blockThemes", "as", "$", "blockId", "=>", "$", "themes", ")", "{", "$", "layout", "->", "setBlockTheme", "(", "$", "themes", ",", "$", "blockId", "!==", "$", "rootBlockId", "?", "$", "blockId", ":", "null", ")", ";", "}", "$", "formThemes", "=", "$", "rawLayout", "->", "getFormThemes", "(", ")", ";", "$", "layout", "->", "setFormTheme", "(", "$", "formThemes", ")", ";", "return", "$", "layout", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L213-L261
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.processBlockViewData
protected function processBlockViewData( BlockView $blockView, ContextInterface $context, DataAccessor $data, $deferred, $encoding ) { if ($deferred) { $this->expressionProcessor->processExpressions($blockView->vars, $context, $data, true, $encoding); } $this->buildValueBags($blockView); foreach ($blockView->children as $key => $childView) { $this->processBlockViewData($childView, $context, $data, $deferred, $encoding); if (!$childView->isVisible()) { unset($blockView->children[$key]); } } }
php
protected function processBlockViewData( BlockView $blockView, ContextInterface $context, DataAccessor $data, $deferred, $encoding ) { if ($deferred) { $this->expressionProcessor->processExpressions($blockView->vars, $context, $data, true, $encoding); } $this->buildValueBags($blockView); foreach ($blockView->children as $key => $childView) { $this->processBlockViewData($childView, $context, $data, $deferred, $encoding); if (!$childView->isVisible()) { unset($blockView->children[$key]); } } }
[ "protected", "function", "processBlockViewData", "(", "BlockView", "$", "blockView", ",", "ContextInterface", "$", "context", ",", "DataAccessor", "$", "data", ",", "$", "deferred", ",", "$", "encoding", ")", "{", "if", "(", "$", "deferred", ")", "{", "$", "this", "->", "expressionProcessor", "->", "processExpressions", "(", "$", "blockView", "->", "vars", ",", "$", "context", ",", "$", "data", ",", "true", ",", "$", "encoding", ")", ";", "}", "$", "this", "->", "buildValueBags", "(", "$", "blockView", ")", ";", "foreach", "(", "$", "blockView", "->", "children", "as", "$", "key", "=>", "$", "childView", ")", "{", "$", "this", "->", "processBlockViewData", "(", "$", "childView", ",", "$", "context", ",", "$", "data", ",", "$", "deferred", ",", "$", "encoding", ")", ";", "if", "(", "!", "$", "childView", "->", "isVisible", "(", ")", ")", "{", "unset", "(", "$", "blockView", "->", "children", "[", "$", "key", "]", ")", ";", "}", "}", "}" ]
Processes expressions that work with data @param BlockView $blockView @param ContextInterface $context @param DataAccessor $data @param bool $deferred @param string $encoding
[ "Processes", "expressions", "that", "work", "with", "data" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L282-L302
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.getRootView
private function getRootView(BlockView $rootView, $rootId) { if ($rootId !== null) { $rootView = $this->findBlockById($rootView, $rootId); if ($rootView === null) { throw new BlockViewNotFoundException(sprintf("BlockView with id \"%s\" is not found.", $rootId)); } } return $rootView; }
php
private function getRootView(BlockView $rootView, $rootId) { if ($rootId !== null) { $rootView = $this->findBlockById($rootView, $rootId); if ($rootView === null) { throw new BlockViewNotFoundException(sprintf("BlockView with id \"%s\" is not found.", $rootId)); } } return $rootView; }
[ "private", "function", "getRootView", "(", "BlockView", "$", "rootView", ",", "$", "rootId", ")", "{", "if", "(", "$", "rootId", "!==", "null", ")", "{", "$", "rootView", "=", "$", "this", "->", "findBlockById", "(", "$", "rootView", ",", "$", "rootId", ")", ";", "if", "(", "$", "rootView", "===", "null", ")", "{", "throw", "new", "BlockViewNotFoundException", "(", "sprintf", "(", "\"BlockView with id \\\"%s\\\" is not found.\"", ",", "$", "rootId", ")", ")", ";", "}", "}", "return", "$", "rootView", ";", "}" ]
@param BlockView $rootView @param int|null $rootId @return BlockView @throws BlockViewNotFoundException
[ "@param", "BlockView", "$rootView", "@param", "int|null", "$rootId" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L326-L336
oroinc/OroLayoutComponent
LayoutBuilder.php
LayoutBuilder.findBlockById
private function findBlockById(BlockView $blockView, $id) { foreach ($blockView->children as $childView) { if ($childView->getId() === $id) { return $childView; } $childView = $this->findBlockById($childView, $id); if ($childView) { return $childView; } } return null; }
php
private function findBlockById(BlockView $blockView, $id) { foreach ($blockView->children as $childView) { if ($childView->getId() === $id) { return $childView; } $childView = $this->findBlockById($childView, $id); if ($childView) { return $childView; } } return null; }
[ "private", "function", "findBlockById", "(", "BlockView", "$", "blockView", ",", "$", "id", ")", "{", "foreach", "(", "$", "blockView", "->", "children", "as", "$", "childView", ")", "{", "if", "(", "$", "childView", "->", "getId", "(", ")", "===", "$", "id", ")", "{", "return", "$", "childView", ";", "}", "$", "childView", "=", "$", "this", "->", "findBlockById", "(", "$", "childView", ",", "$", "id", ")", ";", "if", "(", "$", "childView", ")", "{", "return", "$", "childView", ";", "}", "}", "return", "null", ";", "}" ]
@param BlockView $blockView @param int $id @return BlockView|null
[ "@param", "BlockView", "$blockView", "@param", "int", "$id" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutBuilder.php#L344-L358
ekuiter/feature-php
FeaturePhp/Specification/FileSpecification.php
FileSpecification.fromArrayAndSettings
public static function fromArrayAndSettings($cfg, $settings, $artifact = null) { $fileSpecification = new static($cfg, $settings->getDirectory(), $artifact); $fileSpecification->set("relativeSource", $fileSpecification->getSource()); $fileSpecification->set("source", $settings->getPath($fileSpecification->getSource())); $fileSpecification->set("target", fphp\Helper\Path::join( $settings->getOptional("target", null), $fileSpecification->getTarget())); if (!file_exists($fileSpecification->getSource())) throw new FileSpecificationException("file \"{$fileSpecification->getSource()}\" does not exist"); return $fileSpecification; }
php
public static function fromArrayAndSettings($cfg, $settings, $artifact = null) { $fileSpecification = new static($cfg, $settings->getDirectory(), $artifact); $fileSpecification->set("relativeSource", $fileSpecification->getSource()); $fileSpecification->set("source", $settings->getPath($fileSpecification->getSource())); $fileSpecification->set("target", fphp\Helper\Path::join( $settings->getOptional("target", null), $fileSpecification->getTarget())); if (!file_exists($fileSpecification->getSource())) throw new FileSpecificationException("file \"{$fileSpecification->getSource()}\" does not exist"); return $fileSpecification; }
[ "public", "static", "function", "fromArrayAndSettings", "(", "$", "cfg", ",", "$", "settings", ",", "$", "artifact", "=", "null", ")", "{", "$", "fileSpecification", "=", "new", "static", "(", "$", "cfg", ",", "$", "settings", "->", "getDirectory", "(", ")", ",", "$", "artifact", ")", ";", "$", "fileSpecification", "->", "set", "(", "\"relativeSource\"", ",", "$", "fileSpecification", "->", "getSource", "(", ")", ")", ";", "$", "fileSpecification", "->", "set", "(", "\"source\"", ",", "$", "settings", "->", "getPath", "(", "$", "fileSpecification", "->", "getSource", "(", ")", ")", ")", ";", "$", "fileSpecification", "->", "set", "(", "\"target\"", ",", "fphp", "\\", "Helper", "\\", "Path", "::", "join", "(", "$", "settings", "->", "getOptional", "(", "\"target\"", ",", "null", ")", ",", "$", "fileSpecification", "->", "getTarget", "(", ")", ")", ")", ";", "if", "(", "!", "file_exists", "(", "$", "fileSpecification", "->", "getSource", "(", ")", ")", ")", "throw", "new", "FileSpecificationException", "(", "\"file \\\"{$fileSpecification->getSource()}\\\" does not exist\"", ")", ";", "return", "$", "fileSpecification", ";", "}" ]
Creates a file specification from a plain settings array. The settings context is taken into consideration to generate paths relative to the settings. @param array $cfg a plain settings array @param \FeaturePhp\Settings $settings the settings context @param \FeaturePhp\Artifact\Artifact $artifact @return FileSpecification
[ "Creates", "a", "file", "specification", "from", "a", "plain", "settings", "array", ".", "The", "settings", "context", "is", "taken", "into", "consideration", "to", "generate", "paths", "relative", "to", "the", "settings", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Specification/FileSpecification.php#L56-L67
shawm11/iron-crypto-php
src/Iron.php
Iron.normalizePassword
protected function normalizePassword($password) { $obj = []; if (is_array($password)) { $obj['id'] = $password['id']; $obj['encryption'] = (isset($password['secret']) && $password['secret'] !== null) ? $password['secret'] : $password['encryption']; $obj['integrity'] = (isset($password['secret']) && $password['secret'] !== null) ? $password['secret'] : $password['integrity']; } else { // password is a string $obj['encryption'] = $password; $obj['integrity'] = $password; } return $obj; }
php
protected function normalizePassword($password) { $obj = []; if (is_array($password)) { $obj['id'] = $password['id']; $obj['encryption'] = (isset($password['secret']) && $password['secret'] !== null) ? $password['secret'] : $password['encryption']; $obj['integrity'] = (isset($password['secret']) && $password['secret'] !== null) ? $password['secret'] : $password['integrity']; } else { // password is a string $obj['encryption'] = $password; $obj['integrity'] = $password; } return $obj; }
[ "protected", "function", "normalizePassword", "(", "$", "password", ")", "{", "$", "obj", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "password", ")", ")", "{", "$", "obj", "[", "'id'", "]", "=", "$", "password", "[", "'id'", "]", ";", "$", "obj", "[", "'encryption'", "]", "=", "(", "isset", "(", "$", "password", "[", "'secret'", "]", ")", "&&", "$", "password", "[", "'secret'", "]", "!==", "null", ")", "?", "$", "password", "[", "'secret'", "]", ":", "$", "password", "[", "'encryption'", "]", ";", "$", "obj", "[", "'integrity'", "]", "=", "(", "isset", "(", "$", "password", "[", "'secret'", "]", ")", "&&", "$", "password", "[", "'secret'", "]", "!==", "null", ")", "?", "$", "password", "[", "'secret'", "]", ":", "$", "password", "[", "'integrity'", "]", ";", "}", "else", "{", "// password is a string", "$", "obj", "[", "'encryption'", "]", "=", "$", "password", ";", "$", "obj", "[", "'integrity'", "]", "=", "$", "password", ";", "}", "return", "$", "obj", ";", "}" ]
Normalizes a password parameter into a [ id, encryption, integrity ] object @param string|array $password String or object with [ id, secret ] or [ id, encryption, integrity ] @return array
[ "Normalizes", "a", "password", "parameter", "into", "a", "[", "id", "encryption", "integrity", "]", "object" ]
train
https://github.com/shawm11/iron-crypto-php/blob/854898f24ff4eed945247452f84e9c0636c20233/src/Iron.php#L386-L404
SporkCode/Spork
src/Mvc/Listener/Limit/Limit.php
Limit.setInterval
public function setInterval($interval) { $this->interval = $interval instanceof DateInterval ? $interval : new DateInterval($interval); return $this; }
php
public function setInterval($interval) { $this->interval = $interval instanceof DateInterval ? $interval : new DateInterval($interval); return $this; }
[ "public", "function", "setInterval", "(", "$", "interval", ")", "{", "$", "this", "->", "interval", "=", "$", "interval", "instanceof", "DateInterval", "?", "$", "interval", ":", "new", "DateInterval", "(", "$", "interval", ")", ";", "return", "$", "this", ";", "}" ]
Set the limit interval @param string|DateInterval $interval @return \Spork\Mvc\Listener\Limit\Limit
[ "Set", "the", "limit", "interval" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Limit.php#L115-L119
execut/yii2-base
Bootstrap.php
Bootstrap.bootstrap
public function bootstrap($app) { if ($this->isBootstrapI18n) { $this->bootstrapI18n($app); } $bootstraps = []; foreach ($this->getDepends() as $key => $depends) { foreach ($depends as $name => $depend) { switch ($key) { case 'bootstrap': $bootstraps[$name] = $depend; break; case 'modules': if (!$app->hasModule($name)) { $app->setModule($name, $depend); } break; case 'components': if (in_array($name, self::CORE_COMPONENTS) || !$app->has($name)) { if (in_array($name, self::CORE_COMPONENTS)) { if (!empty(self::$coreComponents[$name])) { break; } self::$coreComponents[$name] = true; } $app->set($name, $depend); } break; } } } foreach ($bootstraps as $bootstrapKey => $bootstrap) { if (is_string($bootstrap)) { $module = $app->getModule($bootstrap); if ($module instanceof BootstrapInterface) { $module->bootstrap($app); } } else if (is_callable($bootstrap)) { if (in_array($bootstrapKey, self::$boostrapped)) { continue; } $bootstrap(); self::$boostrapped[] = $key; } else { $bootstrapKey = $bootstrap['class']; if (array_key_exists('moduleId', $bootstrap)) { $bootstrapKey .= '-' . $bootstrap['moduleId']; } if (in_array($bootstrapKey, self::$boostrapped)) { continue; } self::$boostrapped[] = $bootstrap['class']; $bootstrap = \yii::createObject($bootstrap); $bootstrap->bootstrap($app); } } }
php
public function bootstrap($app) { if ($this->isBootstrapI18n) { $this->bootstrapI18n($app); } $bootstraps = []; foreach ($this->getDepends() as $key => $depends) { foreach ($depends as $name => $depend) { switch ($key) { case 'bootstrap': $bootstraps[$name] = $depend; break; case 'modules': if (!$app->hasModule($name)) { $app->setModule($name, $depend); } break; case 'components': if (in_array($name, self::CORE_COMPONENTS) || !$app->has($name)) { if (in_array($name, self::CORE_COMPONENTS)) { if (!empty(self::$coreComponents[$name])) { break; } self::$coreComponents[$name] = true; } $app->set($name, $depend); } break; } } } foreach ($bootstraps as $bootstrapKey => $bootstrap) { if (is_string($bootstrap)) { $module = $app->getModule($bootstrap); if ($module instanceof BootstrapInterface) { $module->bootstrap($app); } } else if (is_callable($bootstrap)) { if (in_array($bootstrapKey, self::$boostrapped)) { continue; } $bootstrap(); self::$boostrapped[] = $key; } else { $bootstrapKey = $bootstrap['class']; if (array_key_exists('moduleId', $bootstrap)) { $bootstrapKey .= '-' . $bootstrap['moduleId']; } if (in_array($bootstrapKey, self::$boostrapped)) { continue; } self::$boostrapped[] = $bootstrap['class']; $bootstrap = \yii::createObject($bootstrap); $bootstrap->bootstrap($app); } } }
[ "public", "function", "bootstrap", "(", "$", "app", ")", "{", "if", "(", "$", "this", "->", "isBootstrapI18n", ")", "{", "$", "this", "->", "bootstrapI18n", "(", "$", "app", ")", ";", "}", "$", "bootstraps", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getDepends", "(", ")", "as", "$", "key", "=>", "$", "depends", ")", "{", "foreach", "(", "$", "depends", "as", "$", "name", "=>", "$", "depend", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "'bootstrap'", ":", "$", "bootstraps", "[", "$", "name", "]", "=", "$", "depend", ";", "break", ";", "case", "'modules'", ":", "if", "(", "!", "$", "app", "->", "hasModule", "(", "$", "name", ")", ")", "{", "$", "app", "->", "setModule", "(", "$", "name", ",", "$", "depend", ")", ";", "}", "break", ";", "case", "'components'", ":", "if", "(", "in_array", "(", "$", "name", ",", "self", "::", "CORE_COMPONENTS", ")", "||", "!", "$", "app", "->", "has", "(", "$", "name", ")", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "self", "::", "CORE_COMPONENTS", ")", ")", "{", "if", "(", "!", "empty", "(", "self", "::", "$", "coreComponents", "[", "$", "name", "]", ")", ")", "{", "break", ";", "}", "self", "::", "$", "coreComponents", "[", "$", "name", "]", "=", "true", ";", "}", "$", "app", "->", "set", "(", "$", "name", ",", "$", "depend", ")", ";", "}", "break", ";", "}", "}", "}", "foreach", "(", "$", "bootstraps", "as", "$", "bootstrapKey", "=>", "$", "bootstrap", ")", "{", "if", "(", "is_string", "(", "$", "bootstrap", ")", ")", "{", "$", "module", "=", "$", "app", "->", "getModule", "(", "$", "bootstrap", ")", ";", "if", "(", "$", "module", "instanceof", "BootstrapInterface", ")", "{", "$", "module", "->", "bootstrap", "(", "$", "app", ")", ";", "}", "}", "else", "if", "(", "is_callable", "(", "$", "bootstrap", ")", ")", "{", "if", "(", "in_array", "(", "$", "bootstrapKey", ",", "self", "::", "$", "boostrapped", ")", ")", "{", "continue", ";", "}", "$", "bootstrap", "(", ")", ";", "self", "::", "$", "boostrapped", "[", "]", "=", "$", "key", ";", "}", "else", "{", "$", "bootstrapKey", "=", "$", "bootstrap", "[", "'class'", "]", ";", "if", "(", "array_key_exists", "(", "'moduleId'", ",", "$", "bootstrap", ")", ")", "{", "$", "bootstrapKey", ".=", "'-'", ".", "$", "bootstrap", "[", "'moduleId'", "]", ";", "}", "if", "(", "in_array", "(", "$", "bootstrapKey", ",", "self", "::", "$", "boostrapped", ")", ")", "{", "continue", ";", "}", "self", "::", "$", "boostrapped", "[", "]", "=", "$", "bootstrap", "[", "'class'", "]", ";", "$", "bootstrap", "=", "\\", "yii", "::", "createObject", "(", "$", "bootstrap", ")", ";", "$", "bootstrap", "->", "bootstrap", "(", "$", "app", ")", ";", "}", "}", "}" ]
Bootstrap method to be called during application bootstrap stage. @param Application $app the application currently running
[ "Bootstrap", "method", "to", "be", "called", "during", "application", "bootstrap", "stage", "." ]
train
https://github.com/execut/yii2-base/blob/e3634df539b94abb6751581c005a449e769845fa/Bootstrap.php#L59-L122
SporkCode/Spork
src/Mvc/Controller/Plugin/Back.php
Back.attach
public function attach(EventManagerInterface $events) { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array( $this, 'injectPlugin' ), 100); $this->listeners[] = $events->attach(MvcEvent::EVENT_FINISH, array( $this, 'storeRoute' ), - 100); }
php
public function attach(EventManagerInterface $events) { $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array( $this, 'injectPlugin' ), 100); $this->listeners[] = $events->attach(MvcEvent::EVENT_FINISH, array( $this, 'storeRoute' ), - 100); }
[ "public", "function", "attach", "(", "EventManagerInterface", "$", "events", ")", "{", "$", "this", "->", "listeners", "[", "]", "=", "$", "events", "->", "attach", "(", "MvcEvent", "::", "EVENT_DISPATCH", ",", "array", "(", "$", "this", ",", "'injectPlugin'", ")", ",", "100", ")", ";", "$", "this", "->", "listeners", "[", "]", "=", "$", "events", "->", "attach", "(", "MvcEvent", "::", "EVENT_FINISH", ",", "array", "(", "$", "this", ",", "'storeRoute'", ")", ",", "-", "100", ")", ";", "}" ]
Attach listeners @see \Zend\EventManager\ListenerAggregateInterface::attach() @param EventManagerInterface $events
[ "Attach", "listeners" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Controller/Plugin/Back.php#L53-L65
SporkCode/Spork
src/Mvc/Controller/Plugin/Back.php
Back.redirect
public function redirect($default = 'home') { $redirect = $this->getController()->plugin('redirect'); $route = $this->getSession()->route; if (null === $route) { return $redirect->toRoute($default); } return $redirect->toRoute($route->getMatchedRouteName(), $route->getParams()); }
php
public function redirect($default = 'home') { $redirect = $this->getController()->plugin('redirect'); $route = $this->getSession()->route; if (null === $route) { return $redirect->toRoute($default); } return $redirect->toRoute($route->getMatchedRouteName(), $route->getParams()); }
[ "public", "function", "redirect", "(", "$", "default", "=", "'home'", ")", "{", "$", "redirect", "=", "$", "this", "->", "getController", "(", ")", "->", "plugin", "(", "'redirect'", ")", ";", "$", "route", "=", "$", "this", "->", "getSession", "(", ")", "->", "route", ";", "if", "(", "null", "===", "$", "route", ")", "{", "return", "$", "redirect", "->", "toRoute", "(", "$", "default", ")", ";", "}", "return", "$", "redirect", "->", "toRoute", "(", "$", "route", "->", "getMatchedRouteName", "(", ")", ",", "$", "route", "->", "getParams", "(", ")", ")", ";", "}" ]
Redirect to last route @param string $default Default route to use if previous route not found
[ "Redirect", "to", "last", "route" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Controller/Plugin/Back.php#L116-L125
SporkCode/Spork
src/Mvc/Controller/Plugin/Back.php
Back.url
public function url($default = 'home') { $url = $this->getController()->plugin('url'); $route = $this->getSession()->route; if (null === $route) { return $url->fromRoute($default); } return $url->fromRoute($route->getMatchedRouteName(), $route->getParams()); }
php
public function url($default = 'home') { $url = $this->getController()->plugin('url'); $route = $this->getSession()->route; if (null === $route) { return $url->fromRoute($default); } return $url->fromRoute($route->getMatchedRouteName(), $route->getParams()); }
[ "public", "function", "url", "(", "$", "default", "=", "'home'", ")", "{", "$", "url", "=", "$", "this", "->", "getController", "(", ")", "->", "plugin", "(", "'url'", ")", ";", "$", "route", "=", "$", "this", "->", "getSession", "(", ")", "->", "route", ";", "if", "(", "null", "===", "$", "route", ")", "{", "return", "$", "url", "->", "fromRoute", "(", "$", "default", ")", ";", "}", "return", "$", "url", "->", "fromRoute", "(", "$", "route", "->", "getMatchedRouteName", "(", ")", ",", "$", "route", "->", "getParams", "(", ")", ")", ";", "}" ]
Get last route URL @param string $default
[ "Get", "last", "route", "URL" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Controller/Plugin/Back.php#L132-L141
SporkCode/Spork
src/Mvc/Controller/Plugin/Back.php
Back.storeRoute
public function storeRoute(MvcEvent $event) { if ($this->ignore) { return; } $request = $event->getRequest(); if ($request->isXmlHttpRequest()) { return; } $appConfig = $event->getApplication() ->getServiceManager() ->get('config'); $config = array_key_exists(self::CONFIG_KEY, $appConfig) ? $appConfig[self::CONFIG_KEY] : array(); if (array_key_exists('blacklist', $config)) { $this->setBlacklist($config['blacklist']); } $routeMatch = $event->getRouteMatch(); if (null === $routeMatch || in_array($routeMatch->getMatchedRouteName(), $this->blacklist)) { return; } $this->getSession()->route = $routeMatch; }
php
public function storeRoute(MvcEvent $event) { if ($this->ignore) { return; } $request = $event->getRequest(); if ($request->isXmlHttpRequest()) { return; } $appConfig = $event->getApplication() ->getServiceManager() ->get('config'); $config = array_key_exists(self::CONFIG_KEY, $appConfig) ? $appConfig[self::CONFIG_KEY] : array(); if (array_key_exists('blacklist', $config)) { $this->setBlacklist($config['blacklist']); } $routeMatch = $event->getRouteMatch(); if (null === $routeMatch || in_array($routeMatch->getMatchedRouteName(), $this->blacklist)) { return; } $this->getSession()->route = $routeMatch; }
[ "public", "function", "storeRoute", "(", "MvcEvent", "$", "event", ")", "{", "if", "(", "$", "this", "->", "ignore", ")", "{", "return", ";", "}", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "$", "request", "->", "isXmlHttpRequest", "(", ")", ")", "{", "return", ";", "}", "$", "appConfig", "=", "$", "event", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", "->", "get", "(", "'config'", ")", ";", "$", "config", "=", "array_key_exists", "(", "self", "::", "CONFIG_KEY", ",", "$", "appConfig", ")", "?", "$", "appConfig", "[", "self", "::", "CONFIG_KEY", "]", ":", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "'blacklist'", ",", "$", "config", ")", ")", "{", "$", "this", "->", "setBlacklist", "(", "$", "config", "[", "'blacklist'", "]", ")", ";", "}", "$", "routeMatch", "=", "$", "event", "->", "getRouteMatch", "(", ")", ";", "if", "(", "null", "===", "$", "routeMatch", "||", "in_array", "(", "$", "routeMatch", "->", "getMatchedRouteName", "(", ")", ",", "$", "this", "->", "blacklist", ")", ")", "{", "return", ";", "}", "$", "this", "->", "getSession", "(", ")", "->", "route", "=", "$", "routeMatch", ";", "}" ]
Store route in session so it can be returned to later. @param MvcEvent $event
[ "Store", "route", "in", "session", "so", "it", "can", "be", "returned", "to", "later", "." ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Controller/Plugin/Back.php#L162-L188
HedronDev/hedron
src/Parser/Rsync.php
Rsync.parse
public function parse(GitPostReceiveHandler $handler, CommandStackInterface $commandStack) { $config = $this->getConfiguration(); $environment = $this->getEnvironment(); $commandStack->addCommand("rsync -av --exclude=docker --exclude=.git {$environment->getGitDirectory()}/{$config->getBranch()}/ {$this->getDataDirectoryPath()}"); $commandStack->execute(); }
php
public function parse(GitPostReceiveHandler $handler, CommandStackInterface $commandStack) { $config = $this->getConfiguration(); $environment = $this->getEnvironment(); $commandStack->addCommand("rsync -av --exclude=docker --exclude=.git {$environment->getGitDirectory()}/{$config->getBranch()}/ {$this->getDataDirectoryPath()}"); $commandStack->execute(); }
[ "public", "function", "parse", "(", "GitPostReceiveHandler", "$", "handler", ",", "CommandStackInterface", "$", "commandStack", ")", "{", "$", "config", "=", "$", "this", "->", "getConfiguration", "(", ")", ";", "$", "environment", "=", "$", "this", "->", "getEnvironment", "(", ")", ";", "$", "commandStack", "->", "addCommand", "(", "\"rsync -av --exclude=docker --exclude=.git {$environment->getGitDirectory()}/{$config->getBranch()}/ {$this->getDataDirectoryPath()}\"", ")", ";", "$", "commandStack", "->", "execute", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Parser/Rsync.php#L18-L23
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.commit
public function commit() { if ($this->rollbackAgain) { throw new \wf\db\Exception('Please throw exception after rollback in last catch block'); } --$this->transactions; if($this->transactions == 0 && false === $this->dbh->commit()) { throw new \wf\db\Exception('transaction commit error: ' . $this->getLastErr()); } if ($this->transactions < 0) { $this->transactions = 0; } }
php
public function commit() { if ($this->rollbackAgain) { throw new \wf\db\Exception('Please throw exception after rollback in last catch block'); } --$this->transactions; if($this->transactions == 0 && false === $this->dbh->commit()) { throw new \wf\db\Exception('transaction commit error: ' . $this->getLastErr()); } if ($this->transactions < 0) { $this->transactions = 0; } }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "$", "this", "->", "rollbackAgain", ")", "{", "throw", "new", "\\", "wf", "\\", "db", "\\", "Exception", "(", "'Please throw exception after rollback in last catch block'", ")", ";", "}", "--", "$", "this", "->", "transactions", ";", "if", "(", "$", "this", "->", "transactions", "==", "0", "&&", "false", "===", "$", "this", "->", "dbh", "->", "commit", "(", ")", ")", "{", "throw", "new", "\\", "wf", "\\", "db", "\\", "Exception", "(", "'transaction commit error: '", ".", "$", "this", "->", "getLastErr", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "transactions", "<", "0", ")", "{", "$", "this", "->", "transactions", "=", "0", ";", "}", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::commit()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L73-L88
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.query
public function query($sql, array $args = []) { if ($args) { $sql = \wf\db\QueryBuilder::format($sql, $args); } $sql = \wf\db\QueryBuilder::tablePrefix($sql, $this->cfg['tablePrefix']); // 记录数据库查询次数 $this->execTimes ++; $this->log[] = $sql; $query = $this->dbh->query($sql); if(false === $query) { $this->log[] = $this->getLastErr(); throw new \wf\db\Exception($this->getLastErr()); } return $query; }
php
public function query($sql, array $args = []) { if ($args) { $sql = \wf\db\QueryBuilder::format($sql, $args); } $sql = \wf\db\QueryBuilder::tablePrefix($sql, $this->cfg['tablePrefix']); // 记录数据库查询次数 $this->execTimes ++; $this->log[] = $sql; $query = $this->dbh->query($sql); if(false === $query) { $this->log[] = $this->getLastErr(); throw new \wf\db\Exception($this->getLastErr()); } return $query; }
[ "public", "function", "query", "(", "$", "sql", ",", "array", "$", "args", "=", "[", "]", ")", "{", "if", "(", "$", "args", ")", "{", "$", "sql", "=", "\\", "wf", "\\", "db", "\\", "QueryBuilder", "::", "format", "(", "$", "sql", ",", "$", "args", ")", ";", "}", "$", "sql", "=", "\\", "wf", "\\", "db", "\\", "QueryBuilder", "::", "tablePrefix", "(", "$", "sql", ",", "$", "this", "->", "cfg", "[", "'tablePrefix'", "]", ")", ";", "// 记录数据库查询次数", "$", "this", "->", "execTimes", "++", ";", "$", "this", "->", "log", "[", "]", "=", "$", "sql", ";", "$", "query", "=", "$", "this", "->", "dbh", "->", "query", "(", "$", "sql", ")", ";", "if", "(", "false", "===", "$", "query", ")", "{", "$", "this", "->", "log", "[", "]", "=", "$", "this", "->", "getLastErr", "(", ")", ";", "throw", "new", "\\", "wf", "\\", "db", "\\", "Exception", "(", "$", "this", "->", "getLastErr", "(", ")", ")", ";", "}", "return", "$", "query", ";", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::query()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L104-L122
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.getAll
public function getAll($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return []; } $rs = $query->fetchAll(\PDO::FETCH_ASSOC); return $rs; }
php
public function getAll($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return []; } $rs = $query->fetchAll(\PDO::FETCH_ASSOC); return $rs; }
[ "public", "function", "getAll", "(", "$", "sql", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "query", "(", "$", "sql", ",", "$", "args", ")", ";", "if", "(", "!", "$", "query", ")", "{", "return", "[", "]", ";", "}", "$", "rs", "=", "$", "query", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "rs", ";", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::getAll()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L154-L163
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.getRow
public function getRow($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return []; } $rs = $query->fetch(\PDO::FETCH_ASSOC); return $rs; }
php
public function getRow($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return []; } $rs = $query->fetch(\PDO::FETCH_ASSOC); return $rs; }
[ "public", "function", "getRow", "(", "$", "sql", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "query", "(", "$", "sql", ",", "$", "args", ")", ";", "if", "(", "!", "$", "query", ")", "{", "return", "[", "]", ";", "}", "$", "rs", "=", "$", "query", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "rs", ";", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::getRow()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L169-L178
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.getColumn
public function getColumn($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return null; } $value = $query->fetchColumn(); return $value; }
php
public function getColumn($sql, array $args = []) { $query = $this->query($sql, $args); if (!$query) { return null; } $value = $query->fetchColumn(); return $value; }
[ "public", "function", "getColumn", "(", "$", "sql", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "query", "(", "$", "sql", ",", "$", "args", ")", ";", "if", "(", "!", "$", "query", ")", "{", "return", "null", ";", "}", "$", "value", "=", "$", "query", "->", "fetchColumn", "(", ")", ";", "return", "$", "value", ";", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::getColumn()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L184-L194
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.setAutoCommit
public function setAutoCommit($isAutoCommit = false) { $this->dbh->setAttribute(\PDO::ATTR_AUTOCOMMIT, $isAutoCommit); return $this; }
php
public function setAutoCommit($isAutoCommit = false) { $this->dbh->setAttribute(\PDO::ATTR_AUTOCOMMIT, $isAutoCommit); return $this; }
[ "public", "function", "setAutoCommit", "(", "$", "isAutoCommit", "=", "false", ")", "{", "$", "this", "->", "dbh", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_AUTOCOMMIT", ",", "$", "isAutoCommit", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::setAutoCommit()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L209-L214
windwork/wf-db
lib/adapter/PDOMySQL.php
PDOMySQL.rollback
public function rollback() { // 事务链中一旦出现异常,为避免事务链中异常后面的SQL还执行,应返回到第一个事务再回滚 if ($this->transactions -- > 1) { $this->rollbackAgain = true; return; } $this->rollbackAgain = false; // 出现异常立即回滚,回滚后再出现commit则应该抛出异常 if (false === $this->dbh->rollback()) { throw new \wf\db\Exception('transaction rollback error: ' . $this->getLastErr()); } }
php
public function rollback() { // 事务链中一旦出现异常,为避免事务链中异常后面的SQL还执行,应返回到第一个事务再回滚 if ($this->transactions -- > 1) { $this->rollbackAgain = true; return; } $this->rollbackAgain = false; // 出现异常立即回滚,回滚后再出现commit则应该抛出异常 if (false === $this->dbh->rollback()) { throw new \wf\db\Exception('transaction rollback error: ' . $this->getLastErr()); } }
[ "public", "function", "rollback", "(", ")", "{", "// 事务链中一旦出现异常,为避免事务链中异常后面的SQL还执行,应返回到第一个事务再回滚", "if", "(", "$", "this", "->", "transactions", "--", ">", "1", ")", "{", "$", "this", "->", "rollbackAgain", "=", "true", ";", "return", ";", "}", "$", "this", "->", "rollbackAgain", "=", "false", ";", "// 出现异常立即回滚,回滚后再出现commit则应该抛出异常", "if", "(", "false", "===", "$", "this", "->", "dbh", "->", "rollback", "(", ")", ")", "{", "throw", "new", "\\", "wf", "\\", "db", "\\", "Exception", "(", "'transaction rollback error: '", ".", "$", "this", "->", "getLastErr", "(", ")", ")", ";", "}", "}" ]
{@inheritDoc} @see \wf\db\DBInterface::rollback()
[ "{" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/adapter/PDOMySQL.php#L220-L234
brightmarch/rest-easy
src/Brightmarch/RestEasy/Controller/Controller.php
Controller.resourceSupports
public function resourceSupports() { $this->supportedTypes = array_merge(func_get_args(), $this->supportedTypes); $this->canClientAcceptThisResponse(); return $this; }
php
public function resourceSupports() { $this->supportedTypes = array_merge(func_get_args(), $this->supportedTypes); $this->canClientAcceptThisResponse(); return $this; }
[ "public", "function", "resourceSupports", "(", ")", "{", "$", "this", "->", "supportedTypes", "=", "array_merge", "(", "func_get_args", "(", ")", ",", "$", "this", "->", "supportedTypes", ")", ";", "$", "this", "->", "canClientAcceptThisResponse", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set a list of content types that this resource supports. @param [string, string, ...] @return Controller
[ "Set", "a", "list", "of", "content", "types", "that", "this", "resource", "supports", "." ]
train
https://github.com/brightmarch/rest-easy/blob/a6903cdff0a5de2e4466d3e3438c59b9903049f4/src/Brightmarch/RestEasy/Controller/Controller.php#L42-L48
brightmarch/rest-easy
src/Brightmarch/RestEasy/Controller/Controller.php
Controller.resourceRequires
public function resourceRequires() { $this->requiredTypes = array_merge(func_get_args(), $this->requiredTypes); $this->canServerSupportThisRequest(); return $this; }
php
public function resourceRequires() { $this->requiredTypes = array_merge(func_get_args(), $this->requiredTypes); $this->canServerSupportThisRequest(); return $this; }
[ "public", "function", "resourceRequires", "(", ")", "{", "$", "this", "->", "requiredTypes", "=", "array_merge", "(", "func_get_args", "(", ")", ",", "$", "this", "->", "requiredTypes", ")", ";", "$", "this", "->", "canServerSupportThisRequest", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set a list of content types this resource requires. @param [string, string, ...] @return Controller
[ "Set", "a", "list", "of", "content", "types", "this", "resource", "requires", "." ]
train
https://github.com/brightmarch/rest-easy/blob/a6903cdff0a5de2e4466d3e3438c59b9903049f4/src/Brightmarch/RestEasy/Controller/Controller.php#L56-L62
brightmarch/rest-easy
src/Brightmarch/RestEasy/Controller/Controller.php
Controller.renderResource
public function renderResource($view, array $parameters=[], $statusCode=200) { $this->findContentType() ->findViewType() ->buildViewTemplate($view) ->checkViewTemplateExists(); $response = $this->createResponse($statusCode); $response->headers ->set('Content-Type', $this->contentType); return $this->render($this->viewTemplateName, $parameters, $response); }
php
public function renderResource($view, array $parameters=[], $statusCode=200) { $this->findContentType() ->findViewType() ->buildViewTemplate($view) ->checkViewTemplateExists(); $response = $this->createResponse($statusCode); $response->headers ->set('Content-Type', $this->contentType); return $this->render($this->viewTemplateName, $parameters, $response); }
[ "public", "function", "renderResource", "(", "$", "view", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "statusCode", "=", "200", ")", "{", "$", "this", "->", "findContentType", "(", ")", "->", "findViewType", "(", ")", "->", "buildViewTemplate", "(", "$", "view", ")", "->", "checkViewTemplateExists", "(", ")", ";", "$", "response", "=", "$", "this", "->", "createResponse", "(", "$", "statusCode", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "$", "this", "->", "contentType", ")", ";", "return", "$", "this", "->", "render", "(", "$", "this", "->", "viewTemplateName", ",", "$", "parameters", ",", "$", "response", ")", ";", "}" ]
Creates a Response object and returns it. @param string $view @param array $parameters @param integer $statusCode @return Symfony\Component\HttpFoundation\Response
[ "Creates", "a", "Response", "object", "and", "returns", "it", "." ]
train
https://github.com/brightmarch/rest-easy/blob/a6903cdff0a5de2e4466d3e3438c59b9903049f4/src/Brightmarch/RestEasy/Controller/Controller.php#L72-L84
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
TypeCollectionAssembler.create
public function create($data) { $collection = new DescriptorCollection(); foreach ($data as $type) { $collection->add($this->createDescriptorForType($type)); } return $collection; }
php
public function create($data) { $collection = new DescriptorCollection(); foreach ($data as $type) { $collection->add($this->createDescriptorForType($type)); } return $collection; }
[ "public", "function", "create", "(", "$", "data", ")", "{", "$", "collection", "=", "new", "DescriptorCollection", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "type", ")", "{", "$", "collection", "->", "add", "(", "$", "this", "->", "createDescriptorForType", "(", "$", "type", ")", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Creates a Descriptor from the provided data. @param Collection $data @return DescriptorCollection
[ "Creates", "a", "Descriptor", "from", "the", "provided", "data", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L34-L43
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
TypeCollectionAssembler.createDescriptorForType
protected function createDescriptorForType($type) { if (!$this->isArrayNotation($type)) { $className = $this->findClassNameForType($type); return $className ? new $className() : new UnknownTypeDescriptor($type); } $type = $this->extractTypeFromArrayNotation($type); $className = $this->findClassNameForType($type); $descriptor = $className ? new $className() : new UnknownTypeDescriptor($type); $descriptor = $this->convertToArrayDescriptor($descriptor); return $descriptor; }
php
protected function createDescriptorForType($type) { if (!$this->isArrayNotation($type)) { $className = $this->findClassNameForType($type); return $className ? new $className() : new UnknownTypeDescriptor($type); } $type = $this->extractTypeFromArrayNotation($type); $className = $this->findClassNameForType($type); $descriptor = $className ? new $className() : new UnknownTypeDescriptor($type); $descriptor = $this->convertToArrayDescriptor($descriptor); return $descriptor; }
[ "protected", "function", "createDescriptorForType", "(", "$", "type", ")", "{", "if", "(", "!", "$", "this", "->", "isArrayNotation", "(", "$", "type", ")", ")", "{", "$", "className", "=", "$", "this", "->", "findClassNameForType", "(", "$", "type", ")", ";", "return", "$", "className", "?", "new", "$", "className", "(", ")", ":", "new", "UnknownTypeDescriptor", "(", "$", "type", ")", ";", "}", "$", "type", "=", "$", "this", "->", "extractTypeFromArrayNotation", "(", "$", "type", ")", ";", "$", "className", "=", "$", "this", "->", "findClassNameForType", "(", "$", "type", ")", ";", "$", "descriptor", "=", "$", "className", "?", "new", "$", "className", "(", ")", ":", "new", "UnknownTypeDescriptor", "(", "$", "type", ")", ";", "$", "descriptor", "=", "$", "this", "->", "convertToArrayDescriptor", "(", "$", "descriptor", ")", ";", "return", "$", "descriptor", ";", "}" ]
Creates a Type ValueObject (Descriptor) for the provided type string. @param string $type @return DescriptorAbstract
[ "Creates", "a", "Type", "ValueObject", "(", "Descriptor", ")", "for", "the", "provided", "type", "string", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L52-L66
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
TypeCollectionAssembler.convertToArrayDescriptor
protected function convertToArrayDescriptor($descriptor) { $arrayDescriptor = new CollectionDescriptor('array'); $arrayDescriptor->setTypes(array($descriptor)); $arrayDescriptor->setKeyTypes(array('mixed')); return $arrayDescriptor; }
php
protected function convertToArrayDescriptor($descriptor) { $arrayDescriptor = new CollectionDescriptor('array'); $arrayDescriptor->setTypes(array($descriptor)); $arrayDescriptor->setKeyTypes(array('mixed')); return $arrayDescriptor; }
[ "protected", "function", "convertToArrayDescriptor", "(", "$", "descriptor", ")", "{", "$", "arrayDescriptor", "=", "new", "CollectionDescriptor", "(", "'array'", ")", ";", "$", "arrayDescriptor", "->", "setTypes", "(", "array", "(", "$", "descriptor", ")", ")", ";", "$", "arrayDescriptor", "->", "setKeyTypes", "(", "array", "(", "'mixed'", ")", ")", ";", "return", "$", "arrayDescriptor", ";", "}" ]
Wraps the given Descriptor inside a Collection Descriptor of type array and returns that. @param DescriptorAbstract $descriptor @return CollectionDescriptor
[ "Wraps", "the", "given", "Descriptor", "inside", "a", "Collection", "Descriptor", "of", "type", "array", "and", "returns", "that", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L99-L106
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
TypeCollectionAssembler.findClassNameForType
protected function findClassNameForType($type) { $className = (isset($this->typeToValueObjectClassName[$type])) ? $this->typeToValueObjectClassName[$type] : false; return $className; }
php
protected function findClassNameForType($type) { $className = (isset($this->typeToValueObjectClassName[$type])) ? $this->typeToValueObjectClassName[$type] : false; return $className; }
[ "protected", "function", "findClassNameForType", "(", "$", "type", ")", "{", "$", "className", "=", "(", "isset", "(", "$", "this", "->", "typeToValueObjectClassName", "[", "$", "type", "]", ")", ")", "?", "$", "this", "->", "typeToValueObjectClassName", "[", "$", "type", "]", ":", "false", ";", "return", "$", "className", ";", "}" ]
Returns the class name of the Value Object class associated with a given type or false if the type is unknown. @param string $type @return string|boolean
[ "Returns", "the", "class", "name", "of", "the", "Value", "Object", "class", "associated", "with", "a", "given", "type", "or", "false", "if", "the", "type", "is", "unknown", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L115-L122
tequila/mongodb-odm
src/Metadata/Field/AbstractFieldMetadata.php
AbstractFieldMetadata.generateSetterProxy
protected function generateSetterProxy(AbstractGenerator $proxyGenerator) { $methodName = 'set'.StringUtil::camelize($this->propertyName); if (!$proxyGenerator->getReflection()->hasMethod($methodName)) { $proxyGenerator->addError( sprintf( 'Document class %s does not contain method %s, therefore it had not been generated in proxy.', $proxyGenerator->getDocumentClass(), $methodName ) ); return; } $methodReflection = $proxyGenerator->getReflection()->getMethod($methodName); if (1 !== count($methodReflection->getParameters())) { $proxyGenerator->addError( sprintf( 'Method %s::%s() must have 1 argument, but has %d arguments, therefore it had not been generated in proxy.', $proxyGenerator->getDocumentClass(), $methodName, count($methodReflection->getParameters()) ) ); return; } $method = MethodGenerator::fromReflection($methodReflection); $paramName = current($method->getParameters())->getName(); $code = <<<'EOT' parent::{{methodName}}(${{paramName}}); %s $this->getRootProxy()->set($this->getPathInDocument('{{dbFieldName}}'), $dbValue); return $this; EOT; $paramToDbValueConversionCode = strtr( $this->getSerializationCode(), [ '$dbData' => '$dbValue', '$objectData' => '$'.$paramName, ] ); $code = sprintf($code, $paramToDbValueConversionCode); $code = self::compileCode($code, [ 'methodName' => $methodName, 'paramName' => $paramName, 'dbFieldName' => $this->dbFieldName, ]); $method->setBody($code); $proxyGenerator->addMethod($method); }
php
protected function generateSetterProxy(AbstractGenerator $proxyGenerator) { $methodName = 'set'.StringUtil::camelize($this->propertyName); if (!$proxyGenerator->getReflection()->hasMethod($methodName)) { $proxyGenerator->addError( sprintf( 'Document class %s does not contain method %s, therefore it had not been generated in proxy.', $proxyGenerator->getDocumentClass(), $methodName ) ); return; } $methodReflection = $proxyGenerator->getReflection()->getMethod($methodName); if (1 !== count($methodReflection->getParameters())) { $proxyGenerator->addError( sprintf( 'Method %s::%s() must have 1 argument, but has %d arguments, therefore it had not been generated in proxy.', $proxyGenerator->getDocumentClass(), $methodName, count($methodReflection->getParameters()) ) ); return; } $method = MethodGenerator::fromReflection($methodReflection); $paramName = current($method->getParameters())->getName(); $code = <<<'EOT' parent::{{methodName}}(${{paramName}}); %s $this->getRootProxy()->set($this->getPathInDocument('{{dbFieldName}}'), $dbValue); return $this; EOT; $paramToDbValueConversionCode = strtr( $this->getSerializationCode(), [ '$dbData' => '$dbValue', '$objectData' => '$'.$paramName, ] ); $code = sprintf($code, $paramToDbValueConversionCode); $code = self::compileCode($code, [ 'methodName' => $methodName, 'paramName' => $paramName, 'dbFieldName' => $this->dbFieldName, ]); $method->setBody($code); $proxyGenerator->addMethod($method); }
[ "protected", "function", "generateSetterProxy", "(", "AbstractGenerator", "$", "proxyGenerator", ")", "{", "$", "methodName", "=", "'set'", ".", "StringUtil", "::", "camelize", "(", "$", "this", "->", "propertyName", ")", ";", "if", "(", "!", "$", "proxyGenerator", "->", "getReflection", "(", ")", "->", "hasMethod", "(", "$", "methodName", ")", ")", "{", "$", "proxyGenerator", "->", "addError", "(", "sprintf", "(", "'Document class %s does not contain method %s, therefore it had not been generated in proxy.'", ",", "$", "proxyGenerator", "->", "getDocumentClass", "(", ")", ",", "$", "methodName", ")", ")", ";", "return", ";", "}", "$", "methodReflection", "=", "$", "proxyGenerator", "->", "getReflection", "(", ")", "->", "getMethod", "(", "$", "methodName", ")", ";", "if", "(", "1", "!==", "count", "(", "$", "methodReflection", "->", "getParameters", "(", ")", ")", ")", "{", "$", "proxyGenerator", "->", "addError", "(", "sprintf", "(", "'Method %s::%s() must have 1 argument, but has %d arguments, therefore it had not been generated in proxy.'", ",", "$", "proxyGenerator", "->", "getDocumentClass", "(", ")", ",", "$", "methodName", ",", "count", "(", "$", "methodReflection", "->", "getParameters", "(", ")", ")", ")", ")", ";", "return", ";", "}", "$", "method", "=", "MethodGenerator", "::", "fromReflection", "(", "$", "methodReflection", ")", ";", "$", "paramName", "=", "current", "(", "$", "method", "->", "getParameters", "(", ")", ")", "->", "getName", "(", ")", ";", "$", "code", "=", " <<<'EOT'\nparent::{{methodName}}(${{paramName}});\n%s\n$this->getRootProxy()->set($this->getPathInDocument('{{dbFieldName}}'), $dbValue);\n\nreturn $this;\nEOT", ";", "$", "paramToDbValueConversionCode", "=", "strtr", "(", "$", "this", "->", "getSerializationCode", "(", ")", ",", "[", "'$dbData'", "=>", "'$dbValue'", ",", "'$objectData'", "=>", "'$'", ".", "$", "paramName", ",", "]", ")", ";", "$", "code", "=", "sprintf", "(", "$", "code", ",", "$", "paramToDbValueConversionCode", ")", ";", "$", "code", "=", "self", "::", "compileCode", "(", "$", "code", ",", "[", "'methodName'", "=>", "$", "methodName", ",", "'paramName'", "=>", "$", "paramName", ",", "'dbFieldName'", "=>", "$", "this", "->", "dbFieldName", ",", "]", ")", ";", "$", "method", "->", "setBody", "(", "$", "code", ")", ";", "$", "proxyGenerator", "->", "addMethod", "(", "$", "method", ")", ";", "}" ]
@param AbstractGenerator $proxyGenerator @throws \ReflectionException
[ "@param", "AbstractGenerator", "$proxyGenerator" ]
train
https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Metadata/Field/AbstractFieldMetadata.php#L137-L193
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php
ezcDbFactory.getImplementations
static public function getImplementations() { $list = array(); foreach ( self::$implementations as $name => $className ) { $list[] = $name; } return $list; }
php
static public function getImplementations() { $list = array(); foreach ( self::$implementations as $name => $className ) { $list[] = $name; } return $list; }
[ "static", "public", "function", "getImplementations", "(", ")", "{", "$", "list", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "implementations", "as", "$", "name", "=>", "$", "className", ")", "{", "$", "list", "[", "]", "=", "$", "name", ";", "}", "return", "$", "list", ";", "}" ]
Returns a list with supported database implementations. Example: <code> ezcDbFactory::getImplementations(); </code> @return array(string)
[ "Returns", "a", "list", "with", "supported", "database", "implementations", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php#L101-L109
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php
ezcDbFactory.create
static public function create( $dbParams ) { if ( is_string( $dbParams ) ) { $dbParams = self::parseDSN( $dbParams ); } else if ( !is_array( $dbParams ) ) { throw new ezcBaseValueException( 'dbParams', $dbParams, 'string or array', 'parameter' ); } $impName = null; // implementation name foreach ( $dbParams as $key => $val ) { if ( in_array( $key, array( 'phptype', 'type', 'handler', 'driver' ) ) ) { $impName = $val; break; } } if ( $impName === null || !array_key_exists( $impName, self::$implementations ) ) { throw new ezcDbHandlerNotFoundException( $impName, array_keys( self::$implementations ) ); } $className = self::$implementations[$impName]; $instance = new $className( $dbParams ); return $instance; }
php
static public function create( $dbParams ) { if ( is_string( $dbParams ) ) { $dbParams = self::parseDSN( $dbParams ); } else if ( !is_array( $dbParams ) ) { throw new ezcBaseValueException( 'dbParams', $dbParams, 'string or array', 'parameter' ); } $impName = null; // implementation name foreach ( $dbParams as $key => $val ) { if ( in_array( $key, array( 'phptype', 'type', 'handler', 'driver' ) ) ) { $impName = $val; break; } } if ( $impName === null || !array_key_exists( $impName, self::$implementations ) ) { throw new ezcDbHandlerNotFoundException( $impName, array_keys( self::$implementations ) ); } $className = self::$implementations[$impName]; $instance = new $className( $dbParams ); return $instance; }
[ "static", "public", "function", "create", "(", "$", "dbParams", ")", "{", "if", "(", "is_string", "(", "$", "dbParams", ")", ")", "{", "$", "dbParams", "=", "self", "::", "parseDSN", "(", "$", "dbParams", ")", ";", "}", "else", "if", "(", "!", "is_array", "(", "$", "dbParams", ")", ")", "{", "throw", "new", "ezcBaseValueException", "(", "'dbParams'", ",", "$", "dbParams", ",", "'string or array'", ",", "'parameter'", ")", ";", "}", "$", "impName", "=", "null", ";", "// implementation name", "foreach", "(", "$", "dbParams", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "array", "(", "'phptype'", ",", "'type'", ",", "'handler'", ",", "'driver'", ")", ")", ")", "{", "$", "impName", "=", "$", "val", ";", "break", ";", "}", "}", "if", "(", "$", "impName", "===", "null", "||", "!", "array_key_exists", "(", "$", "impName", ",", "self", "::", "$", "implementations", ")", ")", "{", "throw", "new", "ezcDbHandlerNotFoundException", "(", "$", "impName", ",", "array_keys", "(", "self", "::", "$", "implementations", ")", ")", ";", "}", "$", "className", "=", "self", "::", "$", "implementations", "[", "$", "impName", "]", ";", "$", "instance", "=", "new", "$", "className", "(", "$", "dbParams", ")", ";", "return", "$", "instance", ";", "}" ]
Creates and returns an instance of the specified ezcDbHandler implementation. Supported database parameters are: - phptype|type|handler|driver: Database implementation - user|username: Database user name - pass|password: Database user password - dbname|database: Database name - host|hostspec: Name of the host database is running on - port: TCP port - charset: Client character set - socket: UNIX socket path The list above is actually driver-dependent and may be extended in the future. You can specify any parameters your database handler supports. @throws ezcDbHandlerNotFoundException if the requested database handler could not be found. @param mixed $dbParams Database parameters (driver, host, port, user, pass, etc). May be specified either as array (key => val ....) or as DSN string. Format of the DSN is the same as accepted by PEAR::DB::parseDSN(). @return ezcDbHandler
[ "Creates", "and", "returns", "an", "instance", "of", "the", "specified", "ezcDbHandler", "implementation", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php#L134-L165
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php
ezcDbFactory.parseDSN
public static function parseDSN( $dsn ) { $parsed = array( 'phptype' => false, 'dbsyntax' => false, 'username' => false, 'password' => false, 'protocol' => false, 'hostspec' => false, 'port' => false, 'socket' => false, 'database' => false, ); if ( is_array( $dsn ) ) { $dsn = array_merge( $parsed, $dsn ); if ( !$dsn['dbsyntax'] ) { $dsn['dbsyntax'] = $dsn['phptype']; } return $dsn; } // Find phptype and dbsyntax if ( ( $pos = strpos( $dsn, '://' ) ) !== false ) { $str = substr( $dsn, 0, $pos ); $dsn = substr( $dsn, $pos + 3 ); } else { $str = $dsn; $dsn = null; } // Get phptype and dbsyntax // $str => phptype(dbsyntax) if ( preg_match( '|^(.+?)\((.*?)\)$|', $str, $arr ) ) { $parsed['phptype'] = $arr[1]; $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2]; } else { $parsed['phptype'] = $str; $parsed['dbsyntax'] = $str; } if ( !count( $dsn ) ) { return $parsed; } // Get (if found): username and password // $dsn => username:password@protocol+hostspec/database if ( ( $at = strrpos( (string) $dsn, '@' ) ) !== false ) { $str = substr( $dsn, 0, $at ); $dsn = substr( $dsn, $at + 1 ); if ( ( $pos = strpos( $str, ':' ) ) !== false ) { $parsed['username'] = rawurldecode( substr( $str, 0, $pos ) ); $parsed['password'] = rawurldecode( substr( $str, $pos + 1 ) ); } else { $parsed['username'] = rawurldecode( $str ); } } // Find protocol and hostspec if ( preg_match( '|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match ) ) { // $dsn => proto(proto_opts)/database $proto = $match[1]; $proto_opts = $match[2] ? $match[2] : false; $dsn = $match[3]; } else { // $dsn => protocol+hostspec/database (old format) if ( strpos( $dsn, '+' ) !== false ) { list( $proto, $dsn ) = explode( '+', $dsn, 2 ); } if ( strpos( $dsn, '/' ) !== false ) { list( $proto_opts, $dsn ) = explode( '/', $dsn, 2 ); } else { $proto_opts = $dsn; $dsn = null; } } // process the different protocol options $parsed['protocol'] = ( !empty( $proto ) ) ? $proto : 'tcp'; $proto_opts = rawurldecode( $proto_opts ); if ( $parsed['protocol'] == 'tcp' ) { if ( strpos( $proto_opts, ':' ) !== false ) { list( $parsed['hostspec'], $parsed['port'] ) = explode( ':', $proto_opts ); } else { $parsed['hostspec'] = $proto_opts; } } elseif ( $parsed['protocol'] == 'unix' ) { $parsed['socket'] = $proto_opts; } // Get dabase if any // $dsn => database if ( $dsn ) { if ( ( $pos = strpos( $dsn, '?' ) ) === false ) { // /database $parsed['database'] = rawurldecode( $dsn ); } else { // /database?param1=value1&param2=value2 $parsed['database'] = rawurldecode( substr( $dsn, 0, $pos ) ); $dsn = substr( $dsn, $pos + 1 ); if ( strpos( $dsn, '&') !== false ) { $opts = explode( '&', $dsn ); } else { // database?param1=value1 $opts = array( $dsn ); } foreach ( $opts as $opt ) { list( $key, $value ) = explode( '=', $opt ); if ( !isset( $parsed[$key] ) ) { // don't allow params overwrite $parsed[$key] = rawurldecode( $value ); } } } } return $parsed; }
php
public static function parseDSN( $dsn ) { $parsed = array( 'phptype' => false, 'dbsyntax' => false, 'username' => false, 'password' => false, 'protocol' => false, 'hostspec' => false, 'port' => false, 'socket' => false, 'database' => false, ); if ( is_array( $dsn ) ) { $dsn = array_merge( $parsed, $dsn ); if ( !$dsn['dbsyntax'] ) { $dsn['dbsyntax'] = $dsn['phptype']; } return $dsn; } // Find phptype and dbsyntax if ( ( $pos = strpos( $dsn, '://' ) ) !== false ) { $str = substr( $dsn, 0, $pos ); $dsn = substr( $dsn, $pos + 3 ); } else { $str = $dsn; $dsn = null; } // Get phptype and dbsyntax // $str => phptype(dbsyntax) if ( preg_match( '|^(.+?)\((.*?)\)$|', $str, $arr ) ) { $parsed['phptype'] = $arr[1]; $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2]; } else { $parsed['phptype'] = $str; $parsed['dbsyntax'] = $str; } if ( !count( $dsn ) ) { return $parsed; } // Get (if found): username and password // $dsn => username:password@protocol+hostspec/database if ( ( $at = strrpos( (string) $dsn, '@' ) ) !== false ) { $str = substr( $dsn, 0, $at ); $dsn = substr( $dsn, $at + 1 ); if ( ( $pos = strpos( $str, ':' ) ) !== false ) { $parsed['username'] = rawurldecode( substr( $str, 0, $pos ) ); $parsed['password'] = rawurldecode( substr( $str, $pos + 1 ) ); } else { $parsed['username'] = rawurldecode( $str ); } } // Find protocol and hostspec if ( preg_match( '|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match ) ) { // $dsn => proto(proto_opts)/database $proto = $match[1]; $proto_opts = $match[2] ? $match[2] : false; $dsn = $match[3]; } else { // $dsn => protocol+hostspec/database (old format) if ( strpos( $dsn, '+' ) !== false ) { list( $proto, $dsn ) = explode( '+', $dsn, 2 ); } if ( strpos( $dsn, '/' ) !== false ) { list( $proto_opts, $dsn ) = explode( '/', $dsn, 2 ); } else { $proto_opts = $dsn; $dsn = null; } } // process the different protocol options $parsed['protocol'] = ( !empty( $proto ) ) ? $proto : 'tcp'; $proto_opts = rawurldecode( $proto_opts ); if ( $parsed['protocol'] == 'tcp' ) { if ( strpos( $proto_opts, ':' ) !== false ) { list( $parsed['hostspec'], $parsed['port'] ) = explode( ':', $proto_opts ); } else { $parsed['hostspec'] = $proto_opts; } } elseif ( $parsed['protocol'] == 'unix' ) { $parsed['socket'] = $proto_opts; } // Get dabase if any // $dsn => database if ( $dsn ) { if ( ( $pos = strpos( $dsn, '?' ) ) === false ) { // /database $parsed['database'] = rawurldecode( $dsn ); } else { // /database?param1=value1&param2=value2 $parsed['database'] = rawurldecode( substr( $dsn, 0, $pos ) ); $dsn = substr( $dsn, $pos + 1 ); if ( strpos( $dsn, '&') !== false ) { $opts = explode( '&', $dsn ); } else { // database?param1=value1 $opts = array( $dsn ); } foreach ( $opts as $opt ) { list( $key, $value ) = explode( '=', $opt ); if ( !isset( $parsed[$key] ) ) { // don't allow params overwrite $parsed[$key] = rawurldecode( $value ); } } } } return $parsed; }
[ "public", "static", "function", "parseDSN", "(", "$", "dsn", ")", "{", "$", "parsed", "=", "array", "(", "'phptype'", "=>", "false", ",", "'dbsyntax'", "=>", "false", ",", "'username'", "=>", "false", ",", "'password'", "=>", "false", ",", "'protocol'", "=>", "false", ",", "'hostspec'", "=>", "false", ",", "'port'", "=>", "false", ",", "'socket'", "=>", "false", ",", "'database'", "=>", "false", ",", ")", ";", "if", "(", "is_array", "(", "$", "dsn", ")", ")", "{", "$", "dsn", "=", "array_merge", "(", "$", "parsed", ",", "$", "dsn", ")", ";", "if", "(", "!", "$", "dsn", "[", "'dbsyntax'", "]", ")", "{", "$", "dsn", "[", "'dbsyntax'", "]", "=", "$", "dsn", "[", "'phptype'", "]", ";", "}", "return", "$", "dsn", ";", "}", "// Find phptype and dbsyntax", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "dsn", ",", "'://'", ")", ")", "!==", "false", ")", "{", "$", "str", "=", "substr", "(", "$", "dsn", ",", "0", ",", "$", "pos", ")", ";", "$", "dsn", "=", "substr", "(", "$", "dsn", ",", "$", "pos", "+", "3", ")", ";", "}", "else", "{", "$", "str", "=", "$", "dsn", ";", "$", "dsn", "=", "null", ";", "}", "// Get phptype and dbsyntax", "// $str => phptype(dbsyntax)", "if", "(", "preg_match", "(", "'|^(.+?)\\((.*?)\\)$|'", ",", "$", "str", ",", "$", "arr", ")", ")", "{", "$", "parsed", "[", "'phptype'", "]", "=", "$", "arr", "[", "1", "]", ";", "$", "parsed", "[", "'dbsyntax'", "]", "=", "!", "$", "arr", "[", "2", "]", "?", "$", "arr", "[", "1", "]", ":", "$", "arr", "[", "2", "]", ";", "}", "else", "{", "$", "parsed", "[", "'phptype'", "]", "=", "$", "str", ";", "$", "parsed", "[", "'dbsyntax'", "]", "=", "$", "str", ";", "}", "if", "(", "!", "count", "(", "$", "dsn", ")", ")", "{", "return", "$", "parsed", ";", "}", "// Get (if found): username and password", "// $dsn => username:password@protocol+hostspec/database", "if", "(", "(", "$", "at", "=", "strrpos", "(", "(", "string", ")", "$", "dsn", ",", "'@'", ")", ")", "!==", "false", ")", "{", "$", "str", "=", "substr", "(", "$", "dsn", ",", "0", ",", "$", "at", ")", ";", "$", "dsn", "=", "substr", "(", "$", "dsn", ",", "$", "at", "+", "1", ")", ";", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "str", ",", "':'", ")", ")", "!==", "false", ")", "{", "$", "parsed", "[", "'username'", "]", "=", "rawurldecode", "(", "substr", "(", "$", "str", ",", "0", ",", "$", "pos", ")", ")", ";", "$", "parsed", "[", "'password'", "]", "=", "rawurldecode", "(", "substr", "(", "$", "str", ",", "$", "pos", "+", "1", ")", ")", ";", "}", "else", "{", "$", "parsed", "[", "'username'", "]", "=", "rawurldecode", "(", "$", "str", ")", ";", "}", "}", "// Find protocol and hostspec", "if", "(", "preg_match", "(", "'|^([^(]+)\\((.*?)\\)/?(.*?)$|'", ",", "$", "dsn", ",", "$", "match", ")", ")", "{", "// $dsn => proto(proto_opts)/database", "$", "proto", "=", "$", "match", "[", "1", "]", ";", "$", "proto_opts", "=", "$", "match", "[", "2", "]", "?", "$", "match", "[", "2", "]", ":", "false", ";", "$", "dsn", "=", "$", "match", "[", "3", "]", ";", "}", "else", "{", "// $dsn => protocol+hostspec/database (old format)", "if", "(", "strpos", "(", "$", "dsn", ",", "'+'", ")", "!==", "false", ")", "{", "list", "(", "$", "proto", ",", "$", "dsn", ")", "=", "explode", "(", "'+'", ",", "$", "dsn", ",", "2", ")", ";", "}", "if", "(", "strpos", "(", "$", "dsn", ",", "'/'", ")", "!==", "false", ")", "{", "list", "(", "$", "proto_opts", ",", "$", "dsn", ")", "=", "explode", "(", "'/'", ",", "$", "dsn", ",", "2", ")", ";", "}", "else", "{", "$", "proto_opts", "=", "$", "dsn", ";", "$", "dsn", "=", "null", ";", "}", "}", "// process the different protocol options", "$", "parsed", "[", "'protocol'", "]", "=", "(", "!", "empty", "(", "$", "proto", ")", ")", "?", "$", "proto", ":", "'tcp'", ";", "$", "proto_opts", "=", "rawurldecode", "(", "$", "proto_opts", ")", ";", "if", "(", "$", "parsed", "[", "'protocol'", "]", "==", "'tcp'", ")", "{", "if", "(", "strpos", "(", "$", "proto_opts", ",", "':'", ")", "!==", "false", ")", "{", "list", "(", "$", "parsed", "[", "'hostspec'", "]", ",", "$", "parsed", "[", "'port'", "]", ")", "=", "explode", "(", "':'", ",", "$", "proto_opts", ")", ";", "}", "else", "{", "$", "parsed", "[", "'hostspec'", "]", "=", "$", "proto_opts", ";", "}", "}", "elseif", "(", "$", "parsed", "[", "'protocol'", "]", "==", "'unix'", ")", "{", "$", "parsed", "[", "'socket'", "]", "=", "$", "proto_opts", ";", "}", "// Get dabase if any", "// $dsn => database", "if", "(", "$", "dsn", ")", "{", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "dsn", ",", "'?'", ")", ")", "===", "false", ")", "{", "// /database", "$", "parsed", "[", "'database'", "]", "=", "rawurldecode", "(", "$", "dsn", ")", ";", "}", "else", "{", "// /database?param1=value1&param2=value2", "$", "parsed", "[", "'database'", "]", "=", "rawurldecode", "(", "substr", "(", "$", "dsn", ",", "0", ",", "$", "pos", ")", ")", ";", "$", "dsn", "=", "substr", "(", "$", "dsn", ",", "$", "pos", "+", "1", ")", ";", "if", "(", "strpos", "(", "$", "dsn", ",", "'&'", ")", "!==", "false", ")", "{", "$", "opts", "=", "explode", "(", "'&'", ",", "$", "dsn", ")", ";", "}", "else", "{", "// database?param1=value1", "$", "opts", "=", "array", "(", "$", "dsn", ")", ";", "}", "foreach", "(", "$", "opts", "as", "$", "opt", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "'='", ",", "$", "opt", ")", ";", "if", "(", "!", "isset", "(", "$", "parsed", "[", "$", "key", "]", ")", ")", "{", "// don't allow params overwrite", "$", "parsed", "[", "$", "key", "]", "=", "rawurldecode", "(", "$", "value", ")", ";", "}", "}", "}", "}", "return", "$", "parsed", ";", "}" ]
Returns the Data Source Name as a structure containing the various parts of the DSN. Additional keys can be added by appending a URI query string to the end of the DSN. The format of the supplied DSN is in its fullest form: <code> phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true </code> Most variations are allowed: <code> phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644 phptype://username:password@hostspec/database_name phptype://username:password@hostspec phptype://username@hostspec phptype://hostspec/database phptype://hostspec phptype(dbsyntax) phptype </code> This function is 'borrowed' from PEAR /DB.php . @param string $dsn Data Source Name to be parsed @return array an associative array with the following keys: + phptype: Database backend used in PHP (mysql, odbc etc.) + dbsyntax: Database used with regards to SQL syntax etc. + protocol: Communication protocol to use (tcp, unix etc.) + hostspec: Host specification (hostname[:port]) + database: Database to use on the DBMS server + username: User name for login + password: Password for login
[ "Returns", "the", "Data", "Source", "Name", "as", "a", "structure", "containing", "the", "various", "parts", "of", "the", "DSN", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php#L203-L354
gregorybesson/PlaygroundCms
src/Mapper/PageHydrator.php
PageHydrator.extract
public function extract($object) { if (!$object instanceof PageEntityInterface) { throw new Exception\InvalidArgumentException( '$object must be an instance of PlaygroundCms\Entity\PageInterface' ); } /* @var $object PageInterface*/ $data = parent::extract($object); $data = $this->mapField('id', 'page_id', $data); return $data; }
php
public function extract($object) { if (!$object instanceof PageEntityInterface) { throw new Exception\InvalidArgumentException( '$object must be an instance of PlaygroundCms\Entity\PageInterface' ); } /* @var $object PageInterface*/ $data = parent::extract($object); $data = $this->mapField('id', 'page_id', $data); return $data; }
[ "public", "function", "extract", "(", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "PageEntityInterface", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "'$object must be an instance of PlaygroundCms\\Entity\\PageInterface'", ")", ";", "}", "/* @var $object PageInterface*/", "$", "data", "=", "parent", "::", "extract", "(", "$", "object", ")", ";", "$", "data", "=", "$", "this", "->", "mapField", "(", "'id'", ",", "'page_id'", ",", "$", "data", ")", ";", "return", "$", "data", ";", "}" ]
Extract values from an object @param object $object @return array @throws Exception\InvalidArgumentException
[ "Extract", "values", "from", "an", "object" ]
train
https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Mapper/PageHydrator.php#L17-L30
EloGank/lol-replay
src/EloGank/Replay/Crypt/ReplayCrypt.php
ReplayCrypt.getBinary
public function getBinary(ReplayInterface $replay, $pathFolder, $fileId, $saveFile = false) { $path = $pathFolder . '/' . $fileId; if (!is_file($path)) { return false; } $decodedKey = base64_decode($replay->getEncryptionKey()); $decodedKey = $this->decrypt($replay->getGameId(), $decodedKey); $keyframeBinary = file_get_contents($path); $decodedKeyframeBinary = gzdecode($this->decrypt($decodedKey, $keyframeBinary)); // File should saved only in development environment. // If parsing is needed, you have to do it in the ReplayDownloader::onReplayFileDecrypted() method if ($saveFile) { file_put_contents($pathFolder . '.decoded/' . $fileId, $decodedKeyframeBinary); } return $decodedKeyframeBinary; }
php
public function getBinary(ReplayInterface $replay, $pathFolder, $fileId, $saveFile = false) { $path = $pathFolder . '/' . $fileId; if (!is_file($path)) { return false; } $decodedKey = base64_decode($replay->getEncryptionKey()); $decodedKey = $this->decrypt($replay->getGameId(), $decodedKey); $keyframeBinary = file_get_contents($path); $decodedKeyframeBinary = gzdecode($this->decrypt($decodedKey, $keyframeBinary)); // File should saved only in development environment. // If parsing is needed, you have to do it in the ReplayDownloader::onReplayFileDecrypted() method if ($saveFile) { file_put_contents($pathFolder . '.decoded/' . $fileId, $decodedKeyframeBinary); } return $decodedKeyframeBinary; }
[ "public", "function", "getBinary", "(", "ReplayInterface", "$", "replay", ",", "$", "pathFolder", ",", "$", "fileId", ",", "$", "saveFile", "=", "false", ")", "{", "$", "path", "=", "$", "pathFolder", ".", "'/'", ".", "$", "fileId", ";", "if", "(", "!", "is_file", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", "$", "decodedKey", "=", "base64_decode", "(", "$", "replay", "->", "getEncryptionKey", "(", ")", ")", ";", "$", "decodedKey", "=", "$", "this", "->", "decrypt", "(", "$", "replay", "->", "getGameId", "(", ")", ",", "$", "decodedKey", ")", ";", "$", "keyframeBinary", "=", "file_get_contents", "(", "$", "path", ")", ";", "$", "decodedKeyframeBinary", "=", "gzdecode", "(", "$", "this", "->", "decrypt", "(", "$", "decodedKey", ",", "$", "keyframeBinary", ")", ")", ";", "// File should saved only in development environment.", "// If parsing is needed, you have to do it in the ReplayDownloader::onReplayFileDecrypted() method", "if", "(", "$", "saveFile", ")", "{", "file_put_contents", "(", "$", "pathFolder", ".", "'.decoded/'", ".", "$", "fileId", ",", "$", "decodedKeyframeBinary", ")", ";", "}", "return", "$", "decodedKeyframeBinary", ";", "}" ]
@param ReplayInterface $replay @param string $pathFolder @param int $fileId @param bool $saveFile @return string
[ "@param", "ReplayInterface", "$replay", "@param", "string", "$pathFolder", "@param", "int", "$fileId", "@param", "bool", "$saveFile" ]
train
https://github.com/EloGank/lol-replay/blob/cddfded8a71fe9e24e13624d4eae97e087c7b380/src/EloGank/Replay/Crypt/ReplayCrypt.php#L43-L63
EloGank/lol-replay
src/EloGank/Replay/Crypt/ReplayCrypt.php
ReplayCrypt.encrypt
protected function encrypt($key, $text) { $size = mcrypt_get_block_size('blowfish', 'ecb'); $input = $this->pkcs5_pad($text, $size); $td = mcrypt_module_open('blowfish', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key , $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); return bin2hex($data); }
php
protected function encrypt($key, $text) { $size = mcrypt_get_block_size('blowfish', 'ecb'); $input = $this->pkcs5_pad($text, $size); $td = mcrypt_module_open('blowfish', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key , $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); return bin2hex($data); }
[ "protected", "function", "encrypt", "(", "$", "key", ",", "$", "text", ")", "{", "$", "size", "=", "mcrypt_get_block_size", "(", "'blowfish'", ",", "'ecb'", ")", ";", "$", "input", "=", "$", "this", "->", "pkcs5_pad", "(", "$", "text", ",", "$", "size", ")", ";", "$", "td", "=", "mcrypt_module_open", "(", "'blowfish'", ",", "''", ",", "'ecb'", ",", "''", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_enc_get_iv_size", "(", "$", "td", ")", ",", "MCRYPT_RAND", ")", ";", "mcrypt_generic_init", "(", "$", "td", ",", "$", "key", ",", "$", "iv", ")", ";", "$", "data", "=", "mcrypt_generic", "(", "$", "td", ",", "$", "input", ")", ";", "mcrypt_generic_deinit", "(", "$", "td", ")", ";", "mcrypt_module_close", "(", "$", "td", ")", ";", "return", "bin2hex", "(", "$", "data", ")", ";", "}" ]
@param string $key @param string $text @return string
[ "@param", "string", "$key", "@param", "string", "$text" ]
train
https://github.com/EloGank/lol-replay/blob/cddfded8a71fe9e24e13624d4eae97e087c7b380/src/EloGank/Replay/Crypt/ReplayCrypt.php#L71-L84
EloGank/lol-replay
src/EloGank/Replay/Crypt/ReplayCrypt.php
ReplayCrypt.decrypt
protected function decrypt($key, $text) { $td = mcrypt_module_open('blowfish', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key , $iv); $data = mdecrypt_generic($td, $text); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = $this->pkcs5_unpad($data); return $data; }
php
protected function decrypt($key, $text) { $td = mcrypt_module_open('blowfish', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key , $iv); $data = mdecrypt_generic($td, $text); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = $this->pkcs5_unpad($data); return $data; }
[ "protected", "function", "decrypt", "(", "$", "key", ",", "$", "text", ")", "{", "$", "td", "=", "mcrypt_module_open", "(", "'blowfish'", ",", "''", ",", "'ecb'", ",", "''", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_enc_get_iv_size", "(", "$", "td", ")", ",", "MCRYPT_RAND", ")", ";", "mcrypt_generic_init", "(", "$", "td", ",", "$", "key", ",", "$", "iv", ")", ";", "$", "data", "=", "mdecrypt_generic", "(", "$", "td", ",", "$", "text", ")", ";", "mcrypt_generic_deinit", "(", "$", "td", ")", ";", "mcrypt_module_close", "(", "$", "td", ")", ";", "$", "data", "=", "$", "this", "->", "pkcs5_unpad", "(", "$", "data", ")", ";", "return", "$", "data", ";", "}" ]
@param string $key @param string $text @return bool|string
[ "@param", "string", "$key", "@param", "string", "$text" ]
train
https://github.com/EloGank/lol-replay/blob/cddfded8a71fe9e24e13624d4eae97e087c7b380/src/EloGank/Replay/Crypt/ReplayCrypt.php#L92-L105
EloGank/lol-replay
src/EloGank/Replay/Crypt/ReplayCrypt.php
ReplayCrypt.pkcs5_pad
protected function pkcs5_pad($string) { $blocksize = mcrypt_get_block_size('blowfish', 'ecb'); $pad = $blocksize - (mb_strlen($string) % $blocksize); return $string . str_repeat(chr($pad), $pad); }
php
protected function pkcs5_pad($string) { $blocksize = mcrypt_get_block_size('blowfish', 'ecb'); $pad = $blocksize - (mb_strlen($string) % $blocksize); return $string . str_repeat(chr($pad), $pad); }
[ "protected", "function", "pkcs5_pad", "(", "$", "string", ")", "{", "$", "blocksize", "=", "mcrypt_get_block_size", "(", "'blowfish'", ",", "'ecb'", ")", ";", "$", "pad", "=", "$", "blocksize", "-", "(", "mb_strlen", "(", "$", "string", ")", "%", "$", "blocksize", ")", ";", "return", "$", "string", ".", "str_repeat", "(", "chr", "(", "$", "pad", ")", ",", "$", "pad", ")", ";", "}" ]
@param string $string @return string
[ "@param", "string", "$string" ]
train
https://github.com/EloGank/lol-replay/blob/cddfded8a71fe9e24e13624d4eae97e087c7b380/src/EloGank/Replay/Crypt/ReplayCrypt.php#L112-L118
EloGank/lol-replay
src/EloGank/Replay/Crypt/ReplayCrypt.php
ReplayCrypt.pkcs5_unpad
protected function pkcs5_unpad($string) { $pad = ord($string{strlen($string)-1}); if ($pad > strlen($string)) { return false; } if (strspn($string, chr($pad), strlen($string) - $pad) != $pad) { return false; } return substr($string, 0, -1 * $pad); }
php
protected function pkcs5_unpad($string) { $pad = ord($string{strlen($string)-1}); if ($pad > strlen($string)) { return false; } if (strspn($string, chr($pad), strlen($string) - $pad) != $pad) { return false; } return substr($string, 0, -1 * $pad); }
[ "protected", "function", "pkcs5_unpad", "(", "$", "string", ")", "{", "$", "pad", "=", "ord", "(", "$", "string", "{", "strlen", "(", "$", "string", ")", "-", "1", "}", ")", ";", "if", "(", "$", "pad", ">", "strlen", "(", "$", "string", ")", ")", "{", "return", "false", ";", "}", "if", "(", "strspn", "(", "$", "string", ",", "chr", "(", "$", "pad", ")", ",", "strlen", "(", "$", "string", ")", "-", "$", "pad", ")", "!=", "$", "pad", ")", "{", "return", "false", ";", "}", "return", "substr", "(", "$", "string", ",", "0", ",", "-", "1", "*", "$", "pad", ")", ";", "}" ]
@param string $string @return bool|string
[ "@param", "string", "$string" ]
train
https://github.com/EloGank/lol-replay/blob/cddfded8a71fe9e24e13624d4eae97e087c7b380/src/EloGank/Replay/Crypt/ReplayCrypt.php#L125-L137
php-lug/lug
src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php
Repository.findForIndex
public function findForIndex(array $criteria, array $orderBy = []) { return new Pagerfanta(new DoctrineODMMongoDBAdapter($this->buildQueryBuilder($criteria, $orderBy, true))); }
php
public function findForIndex(array $criteria, array $orderBy = []) { return new Pagerfanta(new DoctrineODMMongoDBAdapter($this->buildQueryBuilder($criteria, $orderBy, true))); }
[ "public", "function", "findForIndex", "(", "array", "$", "criteria", ",", "array", "$", "orderBy", "=", "[", "]", ")", "{", "return", "new", "Pagerfanta", "(", "new", "DoctrineODMMongoDBAdapter", "(", "$", "this", "->", "buildQueryBuilder", "(", "$", "criteria", ",", "$", "orderBy", ",", "true", ")", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php#L55-L58
php-lug/lug
src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php
Repository.findBy
public function findBy(array $criteria, array $orderBy = [], $limit = null, $offset = null) { $queryBuilder = $this->buildQueryBuilder($criteria, $orderBy); if ($limit !== null) { $queryBuilder->limit($limit); } if ($offset !== null) { $queryBuilder->skip($offset); } return $queryBuilder->getQuery()->getIterator()->toArray(); }
php
public function findBy(array $criteria, array $orderBy = [], $limit = null, $offset = null) { $queryBuilder = $this->buildQueryBuilder($criteria, $orderBy); if ($limit !== null) { $queryBuilder->limit($limit); } if ($offset !== null) { $queryBuilder->skip($offset); } return $queryBuilder->getQuery()->getIterator()->toArray(); }
[ "public", "function", "findBy", "(", "array", "$", "criteria", ",", "array", "$", "orderBy", "=", "[", "]", ",", "$", "limit", "=", "null", ",", "$", "offset", "=", "null", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "buildQueryBuilder", "(", "$", "criteria", ",", "$", "orderBy", ")", ";", "if", "(", "$", "limit", "!==", "null", ")", "{", "$", "queryBuilder", "->", "limit", "(", "$", "limit", ")", ";", "}", "if", "(", "$", "offset", "!==", "null", ")", "{", "$", "queryBuilder", "->", "skip", "(", "$", "offset", ")", ";", "}", "return", "$", "queryBuilder", "->", "getQuery", "(", ")", "->", "getIterator", "(", ")", "->", "toArray", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php#L95-L108
php-lug/lug
src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php
Repository.getProperty
public function getProperty($property, $root = null) { if (is_string($root) && !empty($root)) { return $root.'.'.$property; } return $property; }
php
public function getProperty($property, $root = null) { if (is_string($root) && !empty($root)) { return $root.'.'.$property; } return $property; }
[ "public", "function", "getProperty", "(", "$", "property", ",", "$", "root", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "root", ")", "&&", "!", "empty", "(", "$", "root", ")", ")", "{", "return", "$", "root", ".", "'.'", ".", "$", "property", ";", "}", "return", "$", "property", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php#L129-L136
php-lug/lug
src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php
Repository.buildQueryBuilder
protected function buildQueryBuilder(array $criteria, array $orderBy, $collection = false) { $queryBuilder = $collection ? $this->createQueryBuilderForCollection() : $this->createQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, $orderBy); return $queryBuilder; }
php
protected function buildQueryBuilder(array $criteria, array $orderBy, $collection = false) { $queryBuilder = $collection ? $this->createQueryBuilderForCollection() : $this->createQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, $orderBy); return $queryBuilder; }
[ "protected", "function", "buildQueryBuilder", "(", "array", "$", "criteria", ",", "array", "$", "orderBy", ",", "$", "collection", "=", "false", ")", "{", "$", "queryBuilder", "=", "$", "collection", "?", "$", "this", "->", "createQueryBuilderForCollection", "(", ")", ":", "$", "this", "->", "createQueryBuilder", "(", ")", ";", "$", "this", "->", "applyCriteria", "(", "$", "queryBuilder", ",", "$", "criteria", ")", ";", "$", "this", "->", "applySorting", "(", "$", "queryBuilder", ",", "$", "orderBy", ")", ";", "return", "$", "queryBuilder", ";", "}" ]
@param mixed[] $criteria @param string[] $orderBy @param bool $collection @return Builder
[ "@param", "mixed", "[]", "$criteria", "@param", "string", "[]", "$orderBy", "@param", "bool", "$collection" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Repository/Doctrine/MongoDB/Repository.php#L145-L153
sergmoro1/yii2-lookup
src/migrations/m180709_092055_update_lookup.php
m180709_092055_update_lookup.up
public function up() { $this->addColumn(self::TABLE, 'property_id', $this->integer()); $property = null; foreach(Lookup::find()->all() as $item) { if(!($property && $property->name == $item->type)) { if(!($property = Property::findOne(['name' => $item->type]))) { $property = new Property([ 'name' => $item->type, ]); $property->save(); } } $item->property_id = $property->id; $item->save(); } $this->createIndex('property_code', self::TABLE, ['property_id', 'code']); $this->addForeignKey ('FK_lookup_property', self::TABLE, 'property_id', '{{%property}}', 'id', 'CASCADE'); $this->dropColumn(self::TABLE, 'type'); }
php
public function up() { $this->addColumn(self::TABLE, 'property_id', $this->integer()); $property = null; foreach(Lookup::find()->all() as $item) { if(!($property && $property->name == $item->type)) { if(!($property = Property::findOne(['name' => $item->type]))) { $property = new Property([ 'name' => $item->type, ]); $property->save(); } } $item->property_id = $property->id; $item->save(); } $this->createIndex('property_code', self::TABLE, ['property_id', 'code']); $this->addForeignKey ('FK_lookup_property', self::TABLE, 'property_id', '{{%property}}', 'id', 'CASCADE'); $this->dropColumn(self::TABLE, 'type'); }
[ "public", "function", "up", "(", ")", "{", "$", "this", "->", "addColumn", "(", "self", "::", "TABLE", ",", "'property_id'", ",", "$", "this", "->", "integer", "(", ")", ")", ";", "$", "property", "=", "null", ";", "foreach", "(", "Lookup", "::", "find", "(", ")", "->", "all", "(", ")", "as", "$", "item", ")", "{", "if", "(", "!", "(", "$", "property", "&&", "$", "property", "->", "name", "==", "$", "item", "->", "type", ")", ")", "{", "if", "(", "!", "(", "$", "property", "=", "Property", "::", "findOne", "(", "[", "'name'", "=>", "$", "item", "->", "type", "]", ")", ")", ")", "{", "$", "property", "=", "new", "Property", "(", "[", "'name'", "=>", "$", "item", "->", "type", ",", "]", ")", ";", "$", "property", "->", "save", "(", ")", ";", "}", "}", "$", "item", "->", "property_id", "=", "$", "property", "->", "id", ";", "$", "item", "->", "save", "(", ")", ";", "}", "$", "this", "->", "createIndex", "(", "'property_code'", ",", "self", "::", "TABLE", ",", "[", "'property_id'", ",", "'code'", "]", ")", ";", "$", "this", "->", "addForeignKey", "(", "'FK_lookup_property'", ",", "self", "::", "TABLE", ",", "'property_id'", ",", "'{{%property}}'", ",", "'id'", ",", "'CASCADE'", ")", ";", "$", "this", "->", "dropColumn", "(", "self", "::", "TABLE", ",", "'type'", ")", ";", "}" ]
Use up()/down() to run migration code without a transaction.
[ "Use", "up", "()", "/", "down", "()", "to", "run", "migration", "code", "without", "a", "transaction", "." ]
train
https://github.com/sergmoro1/yii2-lookup/blob/deff08a2612b3c54d313a6c60a74fcaae1193b21/src/migrations/m180709_092055_update_lookup.php#L16-L35
frdl/webfan
.ApplicationComposer/lib/webdof/Text/diff/Compare.php
Compare.minimize
public function minimize($diff) { foreach($diff as $step => $d) { if($diff[$step][0] !== self::DEL)$diff[$step][1] = NULL; } return $diff; }
php
public function minimize($diff) { foreach($diff as $step => $d) { if($diff[$step][0] !== self::DEL)$diff[$step][1] = NULL; } return $diff; }
[ "public", "function", "minimize", "(", "$", "diff", ")", "{", "foreach", "(", "$", "diff", "as", "$", "step", "=>", "$", "d", ")", "{", "if", "(", "$", "diff", "[", "$", "step", "]", "[", "0", "]", "!==", "self", "::", "DEL", ")", "$", "diff", "[", "$", "step", "]", "[", "1", "]", "=", "NULL", ";", "}", "return", "$", "diff", ";", "}" ]
/* minimize compress the diff data, we only need the the added and equal strings position and length and the value of the deleted strings
[ "/", "*" ]
train
https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/webdof/Text/diff/Compare.php#L173-L180
frdl/webfan
.ApplicationComposer/lib/webdof/Text/diff/Compare.php
Compare.calcdiffer
public function calcdiffer($a, $b) { $alen = strlen($a); $blen = strlen($b); $aptr = 0; $bptr = 0; $ops = array(); while($aptr < $alen && $bptr < $blen) { $matchlen = $this->matchlen(substr($a, $aptr), substr($b, $bptr)); if($matchlen) { $str = substr($a, $aptr, $matchlen); $ops[] = array(self::EQUAL, $str, strlen($str) ); $aptr += $matchlen; $bptr += $matchlen; continue; } /* Difference found */ $bestlen=0; $bestpos=array(0,0); for($atmp = $aptr; $atmp < $alen; $atmp++) { for($btmp = $bptr; $btmp < $blen; $btmp++) { $matchlen = $this->matchlen(substr($a, $atmp), substr($b, $btmp)); if($matchlen>$bestlen) { $bestlen=$matchlen; $bestpos=array($atmp,$btmp); } if($matchlen >= $blen-$btmp)break; } } if(!$bestlen)break; $adifflen = $bestpos[0] - $aptr; $bdifflen = $bestpos[1] - $bptr; if($adifflen) { $str = substr($a, $aptr, $adifflen); $ops[] = array(self::DEL, $str, strlen($str) ); $aptr += $adifflen; } if($bdifflen) { $str = substr($b, $bptr, $bdifflen); $ops[] = array(self::ADD, $str, strlen($str) ); $bptr += $bdifflen; } $str = substr($a, $aptr, $bestlen); $ops[] = array(self::EQUAL, $str, strlen($str) ); $aptr += $bestlen; $bptr += $bestlen; } if($aptr < $alen) { /* b has too much stuff */ $str = substr($a, $aptr); $ops[] = array(self::DEL, $str, strlen($str) ); } if($bptr < $blen) { /* a has too little stuff */ $str = substr($b, $bptr); $ops[] = array(self::ADD, $str, strlen($str) ); } return $ops; }
php
public function calcdiffer($a, $b) { $alen = strlen($a); $blen = strlen($b); $aptr = 0; $bptr = 0; $ops = array(); while($aptr < $alen && $bptr < $blen) { $matchlen = $this->matchlen(substr($a, $aptr), substr($b, $bptr)); if($matchlen) { $str = substr($a, $aptr, $matchlen); $ops[] = array(self::EQUAL, $str, strlen($str) ); $aptr += $matchlen; $bptr += $matchlen; continue; } /* Difference found */ $bestlen=0; $bestpos=array(0,0); for($atmp = $aptr; $atmp < $alen; $atmp++) { for($btmp = $bptr; $btmp < $blen; $btmp++) { $matchlen = $this->matchlen(substr($a, $atmp), substr($b, $btmp)); if($matchlen>$bestlen) { $bestlen=$matchlen; $bestpos=array($atmp,$btmp); } if($matchlen >= $blen-$btmp)break; } } if(!$bestlen)break; $adifflen = $bestpos[0] - $aptr; $bdifflen = $bestpos[1] - $bptr; if($adifflen) { $str = substr($a, $aptr, $adifflen); $ops[] = array(self::DEL, $str, strlen($str) ); $aptr += $adifflen; } if($bdifflen) { $str = substr($b, $bptr, $bdifflen); $ops[] = array(self::ADD, $str, strlen($str) ); $bptr += $bdifflen; } $str = substr($a, $aptr, $bestlen); $ops[] = array(self::EQUAL, $str, strlen($str) ); $aptr += $bestlen; $bptr += $bestlen; } if($aptr < $alen) { /* b has too much stuff */ $str = substr($a, $aptr); $ops[] = array(self::DEL, $str, strlen($str) ); } if($bptr < $blen) { /* a has too little stuff */ $str = substr($b, $bptr); $ops[] = array(self::ADD, $str, strlen($str) ); } return $ops; }
[ "public", "function", "calcdiffer", "(", "$", "a", ",", "$", "b", ")", "{", "$", "alen", "=", "strlen", "(", "$", "a", ")", ";", "$", "blen", "=", "strlen", "(", "$", "b", ")", ";", "$", "aptr", "=", "0", ";", "$", "bptr", "=", "0", ";", "$", "ops", "=", "array", "(", ")", ";", "while", "(", "$", "aptr", "<", "$", "alen", "&&", "$", "bptr", "<", "$", "blen", ")", "{", "$", "matchlen", "=", "$", "this", "->", "matchlen", "(", "substr", "(", "$", "a", ",", "$", "aptr", ")", ",", "substr", "(", "$", "b", ",", "$", "bptr", ")", ")", ";", "if", "(", "$", "matchlen", ")", "{", "$", "str", "=", "substr", "(", "$", "a", ",", "$", "aptr", ",", "$", "matchlen", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "EQUAL", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "$", "aptr", "+=", "$", "matchlen", ";", "$", "bptr", "+=", "$", "matchlen", ";", "continue", ";", "}", "/* Difference found */", "$", "bestlen", "=", "0", ";", "$", "bestpos", "=", "array", "(", "0", ",", "0", ")", ";", "for", "(", "$", "atmp", "=", "$", "aptr", ";", "$", "atmp", "<", "$", "alen", ";", "$", "atmp", "++", ")", "{", "for", "(", "$", "btmp", "=", "$", "bptr", ";", "$", "btmp", "<", "$", "blen", ";", "$", "btmp", "++", ")", "{", "$", "matchlen", "=", "$", "this", "->", "matchlen", "(", "substr", "(", "$", "a", ",", "$", "atmp", ")", ",", "substr", "(", "$", "b", ",", "$", "btmp", ")", ")", ";", "if", "(", "$", "matchlen", ">", "$", "bestlen", ")", "{", "$", "bestlen", "=", "$", "matchlen", ";", "$", "bestpos", "=", "array", "(", "$", "atmp", ",", "$", "btmp", ")", ";", "}", "if", "(", "$", "matchlen", ">=", "$", "blen", "-", "$", "btmp", ")", "break", ";", "}", "}", "if", "(", "!", "$", "bestlen", ")", "break", ";", "$", "adifflen", "=", "$", "bestpos", "[", "0", "]", "-", "$", "aptr", ";", "$", "bdifflen", "=", "$", "bestpos", "[", "1", "]", "-", "$", "bptr", ";", "if", "(", "$", "adifflen", ")", "{", "$", "str", "=", "substr", "(", "$", "a", ",", "$", "aptr", ",", "$", "adifflen", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "DEL", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "$", "aptr", "+=", "$", "adifflen", ";", "}", "if", "(", "$", "bdifflen", ")", "{", "$", "str", "=", "substr", "(", "$", "b", ",", "$", "bptr", ",", "$", "bdifflen", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "ADD", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "$", "bptr", "+=", "$", "bdifflen", ";", "}", "$", "str", "=", "substr", "(", "$", "a", ",", "$", "aptr", ",", "$", "bestlen", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "EQUAL", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "$", "aptr", "+=", "$", "bestlen", ";", "$", "bptr", "+=", "$", "bestlen", ";", "}", "if", "(", "$", "aptr", "<", "$", "alen", ")", "{", "/* b has too much stuff */", "$", "str", "=", "substr", "(", "$", "a", ",", "$", "aptr", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "DEL", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "}", "if", "(", "$", "bptr", "<", "$", "blen", ")", "{", "/* a has too little stuff */", "$", "str", "=", "substr", "(", "$", "b", ",", "$", "bptr", ")", ";", "$", "ops", "[", "]", "=", "array", "(", "self", "::", "ADD", ",", "$", "str", ",", "strlen", "(", "$", "str", ")", ")", ";", "}", "return", "$", "ops", ";", "}" ]
/* Returns the differences of $a and $b
[ "/", "*", "Returns", "the", "differences", "of", "$a", "and", "$b" ]
train
https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/webdof/Text/diff/Compare.php#L186-L258
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.get
public function get($remotepath, $localfile = '.') { $remotepath = self::winslashes($remotepath); $this->execute('get "'.$remotepath.'" "'.$localfile.'"', $output); return $output; }
php
public function get($remotepath, $localfile = '.') { $remotepath = self::winslashes($remotepath); $this->execute('get "'.$remotepath.'" "'.$localfile.'"', $output); return $output; }
[ "public", "function", "get", "(", "$", "remotepath", ",", "$", "localfile", "=", "'.'", ")", "{", "$", "remotepath", "=", "self", "::", "winslashes", "(", "$", "remotepath", ")", ";", "$", "this", "->", "execute", "(", "'get \"'", ".", "$", "remotepath", ".", "'\" \"'", ".", "$", "localfile", ".", "'\"'", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
gets files from the windows machine to the linux machine @param $remotepath the file path at the windows machine @param $localfile the file path on the local linux box where the file will be placed @return array $output the raw command line output for smbclient
[ "gets", "files", "from", "the", "windows", "machine", "to", "the", "linux", "machine", "@param", "$remotepath", "the", "file", "path", "at", "the", "windows", "machine", "@param", "$localfile", "the", "file", "path", "on", "the", "local", "linux", "box", "where", "the", "file", "will", "be", "placed" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L92-L98
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.put
public function put($localfile, $remotepath = ".") { $remotepath = self::winslashes($remotepath); $command = 'put "'.$localfile.'" "'.$remotepath.'"'; $this->execute($command, $output); return $output; }
php
public function put($localfile, $remotepath = ".") { $remotepath = self::winslashes($remotepath); $command = 'put "'.$localfile.'" "'.$remotepath.'"'; $this->execute($command, $output); return $output; }
[ "public", "function", "put", "(", "$", "localfile", ",", "$", "remotepath", "=", "\".\"", ")", "{", "$", "remotepath", "=", "self", "::", "winslashes", "(", "$", "remotepath", ")", ";", "$", "command", "=", "'put \"'", ".", "$", "localfile", ".", "'\" \"'", ".", "$", "remotepath", ".", "'\"'", ";", "$", "this", "->", "execute", "(", "$", "command", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
Allows the placent of files from the local system to the remote windows system @param $localfile The local file on the linux server @param $remotepath The remote path to use @return array $output
[ "Allows", "the", "placent", "of", "files", "from", "the", "local", "system", "to", "the", "remote", "windows", "system", "@param", "$localfile", "The", "local", "file", "on", "the", "linux", "server", "@param", "$remotepath", "The", "remote", "path", "to", "use" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L107-L114
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.rename
public function rename($remote_file_path, $new_remote_file_path) { //get file string massage $remote_file_path = self::winslashes($remote_file_path); $new_remote_file_path = self::winslashes($new_remote_file_path); $this->execute('rename "'.$remote_file_path.'" "'.$new_remote_file_path.'"', $output); return $output; }
php
public function rename($remote_file_path, $new_remote_file_path) { //get file string massage $remote_file_path = self::winslashes($remote_file_path); $new_remote_file_path = self::winslashes($new_remote_file_path); $this->execute('rename "'.$remote_file_path.'" "'.$new_remote_file_path.'"', $output); return $output; }
[ "public", "function", "rename", "(", "$", "remote_file_path", ",", "$", "new_remote_file_path", ")", "{", "//get file string massage", "$", "remote_file_path", "=", "self", "::", "winslashes", "(", "$", "remote_file_path", ")", ";", "$", "new_remote_file_path", "=", "self", "::", "winslashes", "(", "$", "new_remote_file_path", ")", ";", "$", "this", "->", "execute", "(", "'rename \"'", ".", "$", "remote_file_path", ".", "'\" \"'", ".", "$", "new_remote_file_path", ".", "'\"'", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
rename a remote file @param string $remote_file_path The original file path/name @param string $new_remote_file_path The new file path/name @return array $output
[ "rename", "a", "remote", "file", "@param", "string", "$remote_file_path", "The", "original", "file", "path", "/", "name", "@param", "string", "$new_remote_file_path", "The", "new", "file", "path", "/", "name" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L123-L130
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.delete
public function delete($remote_file_path) { //get file string massage $remote_file_path = self::winslashes($remote_file_path); $this->execute('del "' . $remote_file_path . '"', $output); return $output; }
php
public function delete($remote_file_path) { //get file string massage $remote_file_path = self::winslashes($remote_file_path); $this->execute('del "' . $remote_file_path . '"', $output); return $output; }
[ "public", "function", "delete", "(", "$", "remote_file_path", ")", "{", "//get file string massage", "$", "remote_file_path", "=", "self", "::", "winslashes", "(", "$", "remote_file_path", ")", ";", "$", "this", "->", "execute", "(", "'del \"'", ".", "$", "remote_file_path", ".", "'\"'", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
delete a remote file @param string $remote_file_path The original file path/name @return array $output
[ "delete", "a", "remote", "file", "@param", "string", "$remote_file_path", "The", "original", "file", "path", "/", "name" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L138-L143
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.execute
public function execute($command, &$output = null) { $cmd = "smbclient '\\\\{$this->host}\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1"; exec($cmd, $output, $return); if($return === 1){ $errmsg = sprintf("Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s", $this->host, $this->share, $this->username, $this->domain, implode(" ", $output) ); throw new \Exception($errmsg); } if($this->debug == true){ file_put_contents("php://stdout", "\n".$cmd); file_put_contents("php://stdout", "\n".print_r($output, 1)); } //LOG: Transaction if(self::$log) { self::$log->samba("Command: $cmd \n Output:" . print_r($output, 1) . "\n Return: " . print_r($return, 1) . "\n\n\n"); } return $return; }
php
public function execute($command, &$output = null) { $cmd = "smbclient '\\\\{$this->host}\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1"; exec($cmd, $output, $return); if($return === 1){ $errmsg = sprintf("Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s", $this->host, $this->share, $this->username, $this->domain, implode(" ", $output) ); throw new \Exception($errmsg); } if($this->debug == true){ file_put_contents("php://stdout", "\n".$cmd); file_put_contents("php://stdout", "\n".print_r($output, 1)); } //LOG: Transaction if(self::$log) { self::$log->samba("Command: $cmd \n Output:" . print_r($output, 1) . "\n Return: " . print_r($return, 1) . "\n\n\n"); } return $return; }
[ "public", "function", "execute", "(", "$", "command", ",", "&", "$", "output", "=", "null", ")", "{", "$", "cmd", "=", "\"smbclient '\\\\\\\\{$this->host}\\\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1\"", ";", "exec", "(", "$", "cmd", ",", "$", "output", ",", "$", "return", ")", ";", "if", "(", "$", "return", "===", "1", ")", "{", "$", "errmsg", "=", "sprintf", "(", "\"Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s\"", ",", "$", "this", "->", "host", ",", "$", "this", "->", "share", ",", "$", "this", "->", "username", ",", "$", "this", "->", "domain", ",", "implode", "(", "\" \"", ",", "$", "output", ")", ")", ";", "throw", "new", "\\", "Exception", "(", "$", "errmsg", ")", ";", "}", "if", "(", "$", "this", "->", "debug", "==", "true", ")", "{", "file_put_contents", "(", "\"php://stdout\"", ",", "\"\\n\"", ".", "$", "cmd", ")", ";", "file_put_contents", "(", "\"php://stdout\"", ",", "\"\\n\"", ".", "print_r", "(", "$", "output", ",", "1", ")", ")", ";", "}", "//LOG: Transaction", "if", "(", "self", "::", "$", "log", ")", "{", "self", "::", "$", "log", "->", "samba", "(", "\"Command: $cmd \\n Output:\"", ".", "print_r", "(", "$", "output", ",", "1", ")", ".", "\"\\n Return: \"", ".", "print_r", "(", "$", "return", ",", "1", ")", ".", "\"\\n\\n\\n\"", ")", ";", "}", "return", "$", "return", ";", "}" ]
Executes the command line function that completes the remote windows operations @param $command string the command to issue to the smbclient @param $output array what the command line returns @param $log boolean whether to log this transaction @return int Exit code for smbclient: 0 for success, 1 for error
[ "Executes", "the", "command", "line", "function", "that", "completes", "the", "remote", "windows", "operations" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L152-L180
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.ls
public function ls($subdir = '', &$raw = NULL) { $teststr = str_replace('\\', '-', $subdir); $nub = (preg_match('/[-?|\/?]*([\w \-]+\.\w{1,4})/', $teststr))?'':'\*'; $this->execute("ls $subdir".$nub, $raw_ls); $raw = $raw_ls; $ret = ($raw_ls)? $this->processLS($raw_ls, $subdir):0; return $ret; }
php
public function ls($subdir = '', &$raw = NULL) { $teststr = str_replace('\\', '-', $subdir); $nub = (preg_match('/[-?|\/?]*([\w \-]+\.\w{1,4})/', $teststr))?'':'\*'; $this->execute("ls $subdir".$nub, $raw_ls); $raw = $raw_ls; $ret = ($raw_ls)? $this->processLS($raw_ls, $subdir):0; return $ret; }
[ "public", "function", "ls", "(", "$", "subdir", "=", "''", ",", "&", "$", "raw", "=", "NULL", ")", "{", "$", "teststr", "=", "str_replace", "(", "'\\\\'", ",", "'-'", ",", "$", "subdir", ")", ";", "$", "nub", "=", "(", "preg_match", "(", "'/[-?|\\/?]*([\\w \\-]+\\.\\w{1,4})/'", ",", "$", "teststr", ")", ")", "?", "''", ":", "'\\*'", ";", "$", "this", "->", "execute", "(", "\"ls $subdir\"", ".", "$", "nub", ",", "$", "raw_ls", ")", ";", "$", "raw", "=", "$", "raw_ls", ";", "$", "ret", "=", "(", "$", "raw_ls", ")", "?", "$", "this", "->", "processLS", "(", "$", "raw_ls", ",", "$", "subdir", ")", ":", "0", ";", "return", "$", "ret", ";", "}" ]
Returns a list of the contents of the root of the share, or what ever directory is requested in $subdir @param $subdir @return unknown_type
[ "Returns", "a", "list", "of", "the", "contents", "of", "the", "root", "of", "the", "share", "or", "what", "ever", "directory", "is", "requested", "in", "$subdir" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L187-L198
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.processLS
private function processLS($raw_ls, $subdir = '') { $ret = array(); foreach($raw_ls as $listing) { $temp = $this->parseListing($listing, $subdir); if($temp) { $ret[] = $temp; } } return $ret; }
php
private function processLS($raw_ls, $subdir = '') { $ret = array(); foreach($raw_ls as $listing) { $temp = $this->parseListing($listing, $subdir); if($temp) { $ret[] = $temp; } } return $ret; }
[ "private", "function", "processLS", "(", "$", "raw_ls", ",", "$", "subdir", "=", "''", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "raw_ls", "as", "$", "listing", ")", "{", "$", "temp", "=", "$", "this", "->", "parseListing", "(", "$", "listing", ",", "$", "subdir", ")", ";", "if", "(", "$", "temp", ")", "{", "$", "ret", "[", "]", "=", "$", "temp", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Internal operation: converts raw commanline ls returns into an array of samba share listing objects @private
[ "Internal", "operation", ":", "converts", "raw", "commanline", "ls", "returns", "into", "an", "array", "of", "samba", "share", "listing", "objects" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L215-L227
surebert/surebert-framework
src/sb/Samba/Connection.php
Connection.parseListing
private function parseListing($listing, $subdir = '') { $ret = new \sb\Samba\Listing(); $exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/'; preg_match_all($exp, $listing, $matches); if($matches[0]) { $ret->name = $matches[1][0]; $ret->type = $matches[2][0]; $ret->size = $matches[3][0]; $ret->path = $subdir; $ret->datemodified = $matches[4][0]; return $ret; } return 0; }
php
private function parseListing($listing, $subdir = '') { $ret = new \sb\Samba\Listing(); $exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/'; preg_match_all($exp, $listing, $matches); if($matches[0]) { $ret->name = $matches[1][0]; $ret->type = $matches[2][0]; $ret->size = $matches[3][0]; $ret->path = $subdir; $ret->datemodified = $matches[4][0]; return $ret; } return 0; }
[ "private", "function", "parseListing", "(", "$", "listing", ",", "$", "subdir", "=", "''", ")", "{", "$", "ret", "=", "new", "\\", "sb", "\\", "Samba", "\\", "Listing", "(", ")", ";", "$", "exp", "=", "'/^\\s{2}([\\w \\-]+\\.?\\w{3,4})\\s+([A-Z]?)\\s+(\\d+)\\s+(\\w{3}.+)$/'", ";", "preg_match_all", "(", "$", "exp", ",", "$", "listing", ",", "$", "matches", ")", ";", "if", "(", "$", "matches", "[", "0", "]", ")", "{", "$", "ret", "->", "name", "=", "$", "matches", "[", "1", "]", "[", "0", "]", ";", "$", "ret", "->", "type", "=", "$", "matches", "[", "2", "]", "[", "0", "]", ";", "$", "ret", "->", "size", "=", "$", "matches", "[", "3", "]", "[", "0", "]", ";", "$", "ret", "->", "path", "=", "$", "subdir", ";", "$", "ret", "->", "datemodified", "=", "$", "matches", "[", "4", "]", "[", "0", "]", ";", "return", "$", "ret", ";", "}", "return", "0", ";", "}" ]
Converts a line of returned output into a \sb\Samba_Listing object @param $listing @param $subdir @return \sb\Samba\Listing
[ "Converts", "a", "line", "of", "returned", "output", "into", "a", "\\", "sb", "\\", "Samba_Listing", "object" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L235-L253
willhoffmann/domuserp-php
src/Resources/Companies/Secondary/Branches.php
Branches.get
public function get($id) { $data = $this->execute( self::HTTP_GET, self::DOMUSERP_API_PEDIDOVENDA . '/empresas/' . $this->companyId . '/filiais/' . $id ); return $data; }
php
public function get($id) { $data = $this->execute( self::HTTP_GET, self::DOMUSERP_API_PEDIDOVENDA . '/empresas/' . $this->companyId . '/filiais/' . $id ); return $data; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "$", "data", "=", "$", "this", "->", "execute", "(", "self", "::", "HTTP_GET", ",", "self", "::", "DOMUSERP_API_PEDIDOVENDA", ".", "'/empresas/'", ".", "$", "this", "->", "companyId", ".", "'/filiais/'", ".", "$", "id", ")", ";", "return", "$", "data", ";", "}" ]
Gets the branch data according to the id parameter @param int $id @return array|string @throws \GuzzleHttp\Exception\GuzzleException
[ "Gets", "the", "branch", "data", "according", "to", "the", "id", "parameter" ]
train
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Companies/Secondary/Branches.php#L52-L60
BugBuster1701/contao-botdetection-bundle
src/Resources/contao/classes/CheckBotReferrer.php
CheckBotReferrer.checkReferrer
public static function checkReferrer($Referrer = false, $Bot_Referrer_List = false, $Bot_Provider_List = false) { $checkOwn = false; $checkLocal = false; $cachePath = false; $rootDir = \System::getContainer()->getParameter('kernel.project_dir'); if (false !== $Referrer) { $_SERVER['HTTP_REFERER'] = $Referrer; } $referrer_DNS = self::getReferrerDns($Referrer); if ('unknown' == $referrer_DNS) { return false; // ein Referrer du haben musst } //returns true when a blocked referrer is detected //zuerst die mitgelieferte Provider Liste durchsuchen $blocker = new Blocker($referrer_DNS, $rootDir . '/vendor/bugbuster/contao-botdetection-bundle/src/Resources/contao/config'); if ($blocker->isReferrerSpam()) { return true; } unset($blocker); //zweiter Versuch, aktuelle Liste generieren und darin suchen if (false !== $Bot_Provider_List) { $referrerProvider = array(); include_once($Bot_Provider_List); $proCom = new ProviderCommunication($referrerProvider, false, $rootDir); if (true === $proCom->loadProviderFiles()) { $cachePath = $proCom->getCachePath(); } if (false !== $cachePath) { $proPar = new ProviderParser($referrerProvider, $cachePath); if (true === $proPar->isUpdateProviderListNecessary() && true === $proPar->generateProviderList() ) { $proPar->cleanProviderList(); $proPar->writeProviderList(); } $blocker = new Blocker($referrer_DNS, $cachePath); if ($blocker->isReferrerSpam()) { return true; } } } //dritter Versuch, eigene lokale Liste $botreferrerlist = false; $botreferrerlist = static::getReferrerOwnList($Bot_Referrer_List); if ($botreferrerlist !== false) { $checkOwn = static::checkReferrerList($botreferrerlist, $referrer_DNS); } //vierter Versuch (localconfig) $botreferrerlist = static::getReferrerLocalList(); if ($botreferrerlist !== false) { $checkLocal = static::checkReferrerList($botreferrerlist, $referrer_DNS); } if ($checkOwn === true || $checkLocal === true) { return true; } return false; }
php
public static function checkReferrer($Referrer = false, $Bot_Referrer_List = false, $Bot_Provider_List = false) { $checkOwn = false; $checkLocal = false; $cachePath = false; $rootDir = \System::getContainer()->getParameter('kernel.project_dir'); if (false !== $Referrer) { $_SERVER['HTTP_REFERER'] = $Referrer; } $referrer_DNS = self::getReferrerDns($Referrer); if ('unknown' == $referrer_DNS) { return false; // ein Referrer du haben musst } //returns true when a blocked referrer is detected //zuerst die mitgelieferte Provider Liste durchsuchen $blocker = new Blocker($referrer_DNS, $rootDir . '/vendor/bugbuster/contao-botdetection-bundle/src/Resources/contao/config'); if ($blocker->isReferrerSpam()) { return true; } unset($blocker); //zweiter Versuch, aktuelle Liste generieren und darin suchen if (false !== $Bot_Provider_List) { $referrerProvider = array(); include_once($Bot_Provider_List); $proCom = new ProviderCommunication($referrerProvider, false, $rootDir); if (true === $proCom->loadProviderFiles()) { $cachePath = $proCom->getCachePath(); } if (false !== $cachePath) { $proPar = new ProviderParser($referrerProvider, $cachePath); if (true === $proPar->isUpdateProviderListNecessary() && true === $proPar->generateProviderList() ) { $proPar->cleanProviderList(); $proPar->writeProviderList(); } $blocker = new Blocker($referrer_DNS, $cachePath); if ($blocker->isReferrerSpam()) { return true; } } } //dritter Versuch, eigene lokale Liste $botreferrerlist = false; $botreferrerlist = static::getReferrerOwnList($Bot_Referrer_List); if ($botreferrerlist !== false) { $checkOwn = static::checkReferrerList($botreferrerlist, $referrer_DNS); } //vierter Versuch (localconfig) $botreferrerlist = static::getReferrerLocalList(); if ($botreferrerlist !== false) { $checkLocal = static::checkReferrerList($botreferrerlist, $referrer_DNS); } if ($checkOwn === true || $checkLocal === true) { return true; } return false; }
[ "public", "static", "function", "checkReferrer", "(", "$", "Referrer", "=", "false", ",", "$", "Bot_Referrer_List", "=", "false", ",", "$", "Bot_Provider_List", "=", "false", ")", "{", "$", "checkOwn", "=", "false", ";", "$", "checkLocal", "=", "false", ";", "$", "cachePath", "=", "false", ";", "$", "rootDir", "=", "\\", "System", "::", "getContainer", "(", ")", "->", "getParameter", "(", "'kernel.project_dir'", ")", ";", "if", "(", "false", "!==", "$", "Referrer", ")", "{", "$", "_SERVER", "[", "'HTTP_REFERER'", "]", "=", "$", "Referrer", ";", "}", "$", "referrer_DNS", "=", "self", "::", "getReferrerDns", "(", "$", "Referrer", ")", ";", "if", "(", "'unknown'", "==", "$", "referrer_DNS", ")", "{", "return", "false", ";", "// ein Referrer du haben musst", "}", "//returns true when a blocked referrer is detected", "//zuerst die mitgelieferte Provider Liste durchsuchen", "$", "blocker", "=", "new", "Blocker", "(", "$", "referrer_DNS", ",", "$", "rootDir", ".", "'/vendor/bugbuster/contao-botdetection-bundle/src/Resources/contao/config'", ")", ";", "if", "(", "$", "blocker", "->", "isReferrerSpam", "(", ")", ")", "{", "return", "true", ";", "}", "unset", "(", "$", "blocker", ")", ";", "//zweiter Versuch, aktuelle Liste generieren und darin suchen", "if", "(", "false", "!==", "$", "Bot_Provider_List", ")", "{", "$", "referrerProvider", "=", "array", "(", ")", ";", "include_once", "(", "$", "Bot_Provider_List", ")", ";", "$", "proCom", "=", "new", "ProviderCommunication", "(", "$", "referrerProvider", ",", "false", ",", "$", "rootDir", ")", ";", "if", "(", "true", "===", "$", "proCom", "->", "loadProviderFiles", "(", ")", ")", "{", "$", "cachePath", "=", "$", "proCom", "->", "getCachePath", "(", ")", ";", "}", "if", "(", "false", "!==", "$", "cachePath", ")", "{", "$", "proPar", "=", "new", "ProviderParser", "(", "$", "referrerProvider", ",", "$", "cachePath", ")", ";", "if", "(", "true", "===", "$", "proPar", "->", "isUpdateProviderListNecessary", "(", ")", "&&", "true", "===", "$", "proPar", "->", "generateProviderList", "(", ")", ")", "{", "$", "proPar", "->", "cleanProviderList", "(", ")", ";", "$", "proPar", "->", "writeProviderList", "(", ")", ";", "}", "$", "blocker", "=", "new", "Blocker", "(", "$", "referrer_DNS", ",", "$", "cachePath", ")", ";", "if", "(", "$", "blocker", "->", "isReferrerSpam", "(", ")", ")", "{", "return", "true", ";", "}", "}", "}", "//dritter Versuch, eigene lokale Liste", "$", "botreferrerlist", "=", "false", ";", "$", "botreferrerlist", "=", "static", "::", "getReferrerOwnList", "(", "$", "Bot_Referrer_List", ")", ";", "if", "(", "$", "botreferrerlist", "!==", "false", ")", "{", "$", "checkOwn", "=", "static", "::", "checkReferrerList", "(", "$", "botreferrerlist", ",", "$", "referrer_DNS", ")", ";", "}", "//vierter Versuch (localconfig)", "$", "botreferrerlist", "=", "static", "::", "getReferrerLocalList", "(", ")", ";", "if", "(", "$", "botreferrerlist", "!==", "false", ")", "{", "$", "checkLocal", "=", "static", "::", "checkReferrerList", "(", "$", "botreferrerlist", ",", "$", "referrer_DNS", ")", ";", "}", "if", "(", "$", "checkOwn", "===", "true", "||", "$", "checkLocal", "===", "true", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
checkReferrer @param string $Referrer Referrer of Request @param string $Bot_Referrer_List Bot Referrer List, absolute Path+Filename including TL_ROOT @param array $Bot_Provider_List Referrer Provider List, Name + URL @return boolean true: found, false: not found
[ "checkReferrer" ]
train
https://github.com/BugBuster1701/contao-botdetection-bundle/blob/50c964acc354aa9116fae0e509cd7d075bd52f55/src/Resources/contao/classes/CheckBotReferrer.php#L37-L117
BugBuster1701/contao-botdetection-bundle
src/Resources/contao/classes/CheckBotReferrer.php
CheckBotReferrer.getReferrerLocalList
protected static function getReferrerLocalList() { $botreferrerlist = array(); if (isset($GLOBALS['BOTDETECTION']['BOT_REFERRER']) && \is_array($GLOBALS['BOTDETECTION']['BOT_REFERRER']) ) { foreach ($GLOBALS['BOTDETECTION']['BOT_REFERRER'] as $search) { $botreferrerlist[] = $search; } return $botreferrerlist; } return false; }
php
protected static function getReferrerLocalList() { $botreferrerlist = array(); if (isset($GLOBALS['BOTDETECTION']['BOT_REFERRER']) && \is_array($GLOBALS['BOTDETECTION']['BOT_REFERRER']) ) { foreach ($GLOBALS['BOTDETECTION']['BOT_REFERRER'] as $search) { $botreferrerlist[] = $search; } return $botreferrerlist; } return false; }
[ "protected", "static", "function", "getReferrerLocalList", "(", ")", "{", "$", "botreferrerlist", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'BOTDETECTION'", "]", "[", "'BOT_REFERRER'", "]", ")", "&&", "\\", "is_array", "(", "$", "GLOBALS", "[", "'BOTDETECTION'", "]", "[", "'BOT_REFERRER'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'BOTDETECTION'", "]", "[", "'BOT_REFERRER'", "]", "as", "$", "search", ")", "{", "$", "botreferrerlist", "[", "]", "=", "$", "search", ";", "}", "return", "$", "botreferrerlist", ";", "}", "return", "false", ";", "}" ]
Get Referrer List, self defined over localconfig @param string $Bot_Referrer_List @return boolean|array: false: no list, array: Referrer List
[ "Get", "Referrer", "List", "self", "defined", "over", "localconfig" ]
train
https://github.com/BugBuster1701/contao-botdetection-bundle/blob/50c964acc354aa9116fae0e509cd7d075bd52f55/src/Resources/contao/classes/CheckBotReferrer.php#L159-L175
resume-php/cli
app/Commands/ServeCommand.php
ServeCommand.handle
public function handle(): void { $directory = $this->argument('directory'); if (!is_dir($directory)) { $this->error( sprintf('The directory "%1$s" does not exist. Run `resume make --output=%1$s`.', $directory) ); exit(1); } chdir($directory); $this->info( sprintf('Resume preview started: http://%s:%s', $this->host(), $this->port()) ); $this->info('Stop the server with CTRL+C.'); passthru($this->command($this->host(), $this->port()), $exitCode); exit($exitCode); }
php
public function handle(): void { $directory = $this->argument('directory'); if (!is_dir($directory)) { $this->error( sprintf('The directory "%1$s" does not exist. Run `resume make --output=%1$s`.', $directory) ); exit(1); } chdir($directory); $this->info( sprintf('Resume preview started: http://%s:%s', $this->host(), $this->port()) ); $this->info('Stop the server with CTRL+C.'); passthru($this->command($this->host(), $this->port()), $exitCode); exit($exitCode); }
[ "public", "function", "handle", "(", ")", ":", "void", "{", "$", "directory", "=", "$", "this", "->", "argument", "(", "'directory'", ")", ";", "if", "(", "!", "is_dir", "(", "$", "directory", ")", ")", "{", "$", "this", "->", "error", "(", "sprintf", "(", "'The directory \"%1$s\" does not exist. Run `resume make --output=%1$s`.'", ",", "$", "directory", ")", ")", ";", "exit", "(", "1", ")", ";", "}", "chdir", "(", "$", "directory", ")", ";", "$", "this", "->", "info", "(", "sprintf", "(", "'Resume preview started: http://%s:%s'", ",", "$", "this", "->", "host", "(", ")", ",", "$", "this", "->", "port", "(", ")", ")", ")", ";", "$", "this", "->", "info", "(", "'Stop the server with CTRL+C.'", ")", ";", "passthru", "(", "$", "this", "->", "command", "(", "$", "this", "->", "host", "(", ")", ",", "$", "this", "->", "port", "(", ")", ")", ",", "$", "exitCode", ")", ";", "exit", "(", "$", "exitCode", ")", ";", "}" ]
Execute the console command. @return mixed @throws \InvalidArgumentException
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/resume-php/cli/blob/c85b622378c4b8fdb08839e0cc0ebe5031b05390/app/Commands/ServeCommand.php#L32-L54
resume-php/cli
app/Commands/ServeCommand.php
ServeCommand.command
protected function command($host, $port): string { $php = (new PhpExecutableFinder)->find(false); return vsprintf('%s -S %s:%s index.html', [ $php, $host, $port, ]); }
php
protected function command($host, $port): string { $php = (new PhpExecutableFinder)->find(false); return vsprintf('%s -S %s:%s index.html', [ $php, $host, $port, ]); }
[ "protected", "function", "command", "(", "$", "host", ",", "$", "port", ")", ":", "string", "{", "$", "php", "=", "(", "new", "PhpExecutableFinder", ")", "->", "find", "(", "false", ")", ";", "return", "vsprintf", "(", "'%s -S %s:%s index.html'", ",", "[", "$", "php", ",", "$", "host", ",", "$", "port", ",", "]", ")", ";", "}" ]
@param string $host @param int $port @return string
[ "@param", "string", "$host", "@param", "int", "$port" ]
train
https://github.com/resume-php/cli/blob/c85b622378c4b8fdb08839e0cc0ebe5031b05390/app/Commands/ServeCommand.php#L62-L69
windwork/wf-db
lib/DBAbstract.php
DBAbstract.getTableSchema
public function getTableSchema($table) { static $tableSchemaList = []; if((!$tableSchemaList || empty($tableSchemaList[$table]))) { $rows = $this->getAll("SHOW COLUMNS FROM %t", [$table]); $tableSchema = array( 'pk' => '', 'ai' => false, 'field' => [] ); foreach ($rows as $row) { $tableSchema['field'][$row['Field']] = $row; if ($row['Key'] == 'PRI') { if($tableSchema['pk']) { $tableSchema['pk'] = (array)$tableSchema['pk']; $tableSchema['pk'][] = $row['Field']; } else { $tableSchema['ai'] = $row['Extra'] == 'auto_increment'; $tableSchema['pk'] = $row['Field']; } } } $tableSchemaList[$table] = $tableSchema; } return $tableSchemaList[$table]; }
php
public function getTableSchema($table) { static $tableSchemaList = []; if((!$tableSchemaList || empty($tableSchemaList[$table]))) { $rows = $this->getAll("SHOW COLUMNS FROM %t", [$table]); $tableSchema = array( 'pk' => '', 'ai' => false, 'field' => [] ); foreach ($rows as $row) { $tableSchema['field'][$row['Field']] = $row; if ($row['Key'] == 'PRI') { if($tableSchema['pk']) { $tableSchema['pk'] = (array)$tableSchema['pk']; $tableSchema['pk'][] = $row['Field']; } else { $tableSchema['ai'] = $row['Extra'] == 'auto_increment'; $tableSchema['pk'] = $row['Field']; } } } $tableSchemaList[$table] = $tableSchema; } return $tableSchemaList[$table]; }
[ "public", "function", "getTableSchema", "(", "$", "table", ")", "{", "static", "$", "tableSchemaList", "=", "[", "]", ";", "if", "(", "(", "!", "$", "tableSchemaList", "||", "empty", "(", "$", "tableSchemaList", "[", "$", "table", "]", ")", ")", ")", "{", "$", "rows", "=", "$", "this", "->", "getAll", "(", "\"SHOW COLUMNS FROM %t\"", ",", "[", "$", "table", "]", ")", ";", "$", "tableSchema", "=", "array", "(", "'pk'", "=>", "''", ",", "'ai'", "=>", "false", ",", "'field'", "=>", "[", "]", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "tableSchema", "[", "'field'", "]", "[", "$", "row", "[", "'Field'", "]", "]", "=", "$", "row", ";", "if", "(", "$", "row", "[", "'Key'", "]", "==", "'PRI'", ")", "{", "if", "(", "$", "tableSchema", "[", "'pk'", "]", ")", "{", "$", "tableSchema", "[", "'pk'", "]", "=", "(", "array", ")", "$", "tableSchema", "[", "'pk'", "]", ";", "$", "tableSchema", "[", "'pk'", "]", "[", "]", "=", "$", "row", "[", "'Field'", "]", ";", "}", "else", "{", "$", "tableSchema", "[", "'ai'", "]", "=", "$", "row", "[", "'Extra'", "]", "==", "'auto_increment'", ";", "$", "tableSchema", "[", "'pk'", "]", "=", "$", "row", "[", "'Field'", "]", ";", "}", "}", "}", "$", "tableSchemaList", "[", "$", "table", "]", "=", "$", "tableSchema", ";", "}", "return", "$", "tableSchemaList", "[", "$", "table", "]", ";", "}" ]
获取模型数据表信息 <pre> arry( 'pk' => '主键', 'ai' => true/false, //主键是否是自动增长 'field' => array( '字段1名' => array( 'field' => '字段1名', 'type' => '字段类型', 'key' => '索引类型', //PKI/MUL/UNI 'default' => '默认值', 'ai' => '是否是自动增长的', ), '字段2' => array( 'field' => $row['Field'], 'type' => $row['Type'], 'key' => $row['Key'], 'default' => $row['Default'], 'ai' => $row['Extra'] == 'auto_increment', ), ... ) ) </pre> @param string $table 表名 @return array
[ "获取模型数据表信息" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/DBAbstract.php#L83-L112
windwork/wf-db
lib/DBAbstract.php
DBAbstract.insertRows
public function insertRows(array $rows, $table, $fieldArr = [], $isReplace = false) { $type = $isReplace ? 'REPLACE' : 'INSERT'; // 数据中允许插入的字段 $allowFields = $fieldArr ? $fieldArr : array_keys(current($rows)); $allowFields = QueryBuilder::quoteFieldNames(implode(',', $allowFields)); // $valueArr = []; foreach ($rows as $row) { $rowStr = ''; foreach ($row as $key => $val) { // 去掉不允许写入的属性 if ($fieldArr && !in_array($key, $fieldArr)) { unset($row[$key]); } } $rowStr = implode(',', array_map('\wf\db\QueryBuilder::quoteInputVar', $row)); $valueArr[] = "({$rowStr})"; } $values = $rowStr = implode(',', $valueArr); return $this->exec("%x INTO %t (%x) VALUES %x", array($type, $table, $allowFields, $values)); }
php
public function insertRows(array $rows, $table, $fieldArr = [], $isReplace = false) { $type = $isReplace ? 'REPLACE' : 'INSERT'; // 数据中允许插入的字段 $allowFields = $fieldArr ? $fieldArr : array_keys(current($rows)); $allowFields = QueryBuilder::quoteFieldNames(implode(',', $allowFields)); // $valueArr = []; foreach ($rows as $row) { $rowStr = ''; foreach ($row as $key => $val) { // 去掉不允许写入的属性 if ($fieldArr && !in_array($key, $fieldArr)) { unset($row[$key]); } } $rowStr = implode(',', array_map('\wf\db\QueryBuilder::quoteInputVar', $row)); $valueArr[] = "({$rowStr})"; } $values = $rowStr = implode(',', $valueArr); return $this->exec("%x INTO %t (%x) VALUES %x", array($type, $table, $allowFields, $values)); }
[ "public", "function", "insertRows", "(", "array", "$", "rows", ",", "$", "table", ",", "$", "fieldArr", "=", "[", "]", ",", "$", "isReplace", "=", "false", ")", "{", "$", "type", "=", "$", "isReplace", "?", "'REPLACE'", ":", "'INSERT'", ";", "// 数据中允许插入的字段", "$", "allowFields", "=", "$", "fieldArr", "?", "$", "fieldArr", ":", "array_keys", "(", "current", "(", "$", "rows", ")", ")", ";", "$", "allowFields", "=", "QueryBuilder", "::", "quoteFieldNames", "(", "implode", "(", "','", ",", "$", "allowFields", ")", ")", ";", "//", "$", "valueArr", "=", "[", "]", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "rowStr", "=", "''", ";", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "val", ")", "{", "// 去掉不允许写入的属性", "if", "(", "$", "fieldArr", "&&", "!", "in_array", "(", "$", "key", ",", "$", "fieldArr", ")", ")", "{", "unset", "(", "$", "row", "[", "$", "key", "]", ")", ";", "}", "}", "$", "rowStr", "=", "implode", "(", "','", ",", "array_map", "(", "'\\wf\\db\\QueryBuilder::quoteInputVar'", ",", "$", "row", ")", ")", ";", "$", "valueArr", "[", "]", "=", "\"({$rowStr})\"", ";", "}", "$", "values", "=", "$", "rowStr", "=", "implode", "(", "','", ",", "$", "valueArr", ")", ";", "return", "$", "this", "->", "exec", "(", "\"%x INTO %t (%x) VALUES %x\"", ",", "array", "(", "$", "type", ",", "$", "table", ",", "$", "allowFields", ",", "$", "values", ")", ")", ";", "}" ]
插入多行数据 过滤掉没有的字段 @param array $rows @param string $table 插入表 @param array $field 允许插入的字段名 @param string $isReplace = false 是否使用 REPLACE INTO插入数据,false为使用 INSERT INTO @return PDOStatement
[ "插入多行数据", "过滤掉没有的字段" ]
train
https://github.com/windwork/wf-db/blob/b9ee5740a42d572ce728907ea24ba22c158863f5/lib/DBAbstract.php#L124-L149
gruzilla/hydra
src/Hydra/OAuth/YamlTokenStorage.php
YamlTokenStorage.storeAccessToken
public function storeAccessToken($serviceName, TokenInterface $token) { // normalize service name $serviceName = ucfirst($serviceName); parent::storeAccessToken($serviceName, $token); $this->configs[$serviceName][self::ACCES_TOKEN_KEY] = serialize($token); $this->save($serviceName); // allow chaining return $this; }
php
public function storeAccessToken($serviceName, TokenInterface $token) { // normalize service name $serviceName = ucfirst($serviceName); parent::storeAccessToken($serviceName, $token); $this->configs[$serviceName][self::ACCES_TOKEN_KEY] = serialize($token); $this->save($serviceName); // allow chaining return $this; }
[ "public", "function", "storeAccessToken", "(", "$", "serviceName", ",", "TokenInterface", "$", "token", ")", "{", "// normalize service name", "$", "serviceName", "=", "ucfirst", "(", "$", "serviceName", ")", ";", "parent", "::", "storeAccessToken", "(", "$", "serviceName", ",", "$", "token", ")", ";", "$", "this", "->", "configs", "[", "$", "serviceName", "]", "[", "self", "::", "ACCES_TOKEN_KEY", "]", "=", "serialize", "(", "$", "token", ")", ";", "$", "this", "->", "save", "(", "$", "serviceName", ")", ";", "// allow chaining", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/gruzilla/hydra/blob/47f381cc48e1a26bfe2e211d8dcb54c787ea0478/src/Hydra/OAuth/YamlTokenStorage.php#L74-L86
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.channelFileList
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE) { $files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray(); $count = count($files); for($i = 0; $i < $count; $i++) { $files[$i]["sid"] = $this->getId(); $files[$i]["cid"] = $files[0]["cid"]; $files[$i]["path"] = $files[0]["path"]; $files[$i]["src"] = new Str($cid ? $files[$i]["path"] : "/"); if(!$files[$i]["src"]->endsWith("/")) { $files[$i]["src"]->append("/"); } $files[$i]["src"]->append($files[$i]["name"]); if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY) { $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive)); } } uasort($files, array(__CLASS__, "sortFileList")); return $files; }
php
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE) { $files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray(); $count = count($files); for($i = 0; $i < $count; $i++) { $files[$i]["sid"] = $this->getId(); $files[$i]["cid"] = $files[0]["cid"]; $files[$i]["path"] = $files[0]["path"]; $files[$i]["src"] = new Str($cid ? $files[$i]["path"] : "/"); if(!$files[$i]["src"]->endsWith("/")) { $files[$i]["src"]->append("/"); } $files[$i]["src"]->append($files[$i]["name"]); if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY) { $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive)); } } uasort($files, array(__CLASS__, "sortFileList")); return $files; }
[ "public", "function", "channelFileList", "(", "$", "cid", ",", "$", "cpw", "=", "\"\"", ",", "$", "path", "=", "\"/\"", ",", "$", "recursive", "=", "FALSE", ")", "{", "$", "files", "=", "$", "this", "->", "execute", "(", "\"ftgetfilelist\"", ",", "array", "(", "\"cid\"", "=>", "$", "cid", ",", "\"cpw\"", "=>", "$", "cpw", ",", "\"path\"", "=>", "$", "path", ")", ")", "->", "toArray", "(", ")", ";", "$", "count", "=", "count", "(", "$", "files", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "files", "[", "$", "i", "]", "[", "\"sid\"", "]", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "files", "[", "$", "i", "]", "[", "\"cid\"", "]", "=", "$", "files", "[", "0", "]", "[", "\"cid\"", "]", ";", "$", "files", "[", "$", "i", "]", "[", "\"path\"", "]", "=", "$", "files", "[", "0", "]", "[", "\"path\"", "]", ";", "$", "files", "[", "$", "i", "]", "[", "\"src\"", "]", "=", "new", "Str", "(", "$", "cid", "?", "$", "files", "[", "$", "i", "]", "[", "\"path\"", "]", ":", "\"/\"", ")", ";", "if", "(", "!", "$", "files", "[", "$", "i", "]", "[", "\"src\"", "]", "->", "endsWith", "(", "\"/\"", ")", ")", "{", "$", "files", "[", "$", "i", "]", "[", "\"src\"", "]", "->", "append", "(", "\"/\"", ")", ";", "}", "$", "files", "[", "$", "i", "]", "[", "\"src\"", "]", "->", "append", "(", "$", "files", "[", "$", "i", "]", "[", "\"name\"", "]", ")", ";", "if", "(", "$", "recursive", "&&", "$", "files", "[", "$", "i", "]", "[", "\"type\"", "]", "==", "TeamSpeak3", "::", "FILE_TYPE_DIRECTORY", ")", "{", "$", "files", "=", "array_merge", "(", "$", "files", ",", "$", "this", "->", "channelFileList", "(", "$", "cid", ",", "$", "cpw", ",", "$", "path", ".", "$", "files", "[", "$", "i", "]", "[", "\"name\"", "]", ",", "$", "recursive", ")", ")", ";", "}", "}", "uasort", "(", "$", "files", ",", "array", "(", "__CLASS__", ",", "\"sortFileList\"", ")", ")", ";", "return", "$", "files", ";", "}" ]
Returns a list of files and directories stored in the specified channels file repository. @param integer $cid @param string $cpw @param string $path @param boolean $recursive @return array
[ "Returns", "a", "list", "of", "files", "and", "directories", "stored", "in", "the", "specified", "channels", "file", "repository", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L491-L519
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.channelGetById
public function channelGetById($cid) { if(!array_key_exists((string) $cid, $this->channelList())) { throw new Exception("invalid channelID", 0x300); } return $this->channelList[intval((string) $cid)]; }
php
public function channelGetById($cid) { if(!array_key_exists((string) $cid, $this->channelList())) { throw new Exception("invalid channelID", 0x300); } return $this->channelList[intval((string) $cid)]; }
[ "public", "function", "channelGetById", "(", "$", "cid", ")", "{", "if", "(", "!", "array_key_exists", "(", "(", "string", ")", "$", "cid", ",", "$", "this", "->", "channelList", "(", ")", ")", ")", "{", "throw", "new", "Exception", "(", "\"invalid channelID\"", ",", "0x300", ")", ";", "}", "return", "$", "this", "->", "channelList", "[", "intval", "(", "(", "string", ")", "$", "cid", ")", "]", ";", "}" ]
Returns the Channel object matching the given ID. @param integer $cid @throws Exception @return Channel
[ "Returns", "the", "Channel", "object", "matching", "the", "given", "ID", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L624-L632
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.channelGetByName
public function channelGetByName($name) { foreach($this->channelList() as $channel) { if($channel["channel_name"] == $name) return $channel; } throw new Exception("invalid channelID", 0x300); }
php
public function channelGetByName($name) { foreach($this->channelList() as $channel) { if($channel["channel_name"] == $name) return $channel; } throw new Exception("invalid channelID", 0x300); }
[ "public", "function", "channelGetByName", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "channelList", "(", ")", "as", "$", "channel", ")", "{", "if", "(", "$", "channel", "[", "\"channel_name\"", "]", "==", "$", "name", ")", "return", "$", "channel", ";", "}", "throw", "new", "Exception", "(", "\"invalid channelID\"", ",", "0x300", ")", ";", "}" ]
Returns the Channel object matching the given name. @param string $name @throws Exception @return Channel
[ "Returns", "the", "Channel", "object", "matching", "the", "given", "name", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L641-L649
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.clientList
public function clientList(array $filter = array()) { if($this->clientList === null) { $clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid"); $this->clientList = array(); foreach($clients as $clid => $client) { if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue; $this->clientList[$clid] = new Client($this, $client); } uasort($this->clientList, array(__CLASS__, "sortClientList")); $this->resetNodeList(); } return $this->filterList($this->clientList, $filter); }
php
public function clientList(array $filter = array()) { if($this->clientList === null) { $clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid"); $this->clientList = array(); foreach($clients as $clid => $client) { if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue; $this->clientList[$clid] = new Client($this, $client); } uasort($this->clientList, array(__CLASS__, "sortClientList")); $this->resetNodeList(); } return $this->filterList($this->clientList, $filter); }
[ "public", "function", "clientList", "(", "array", "$", "filter", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "clientList", "===", "null", ")", "{", "$", "clients", "=", "$", "this", "->", "request", "(", "\"clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip\"", ")", "->", "toAssocArray", "(", "\"clid\"", ")", ";", "$", "this", "->", "clientList", "=", "array", "(", ")", ";", "foreach", "(", "$", "clients", "as", "$", "clid", "=>", "$", "client", ")", "{", "if", "(", "$", "this", "->", "getParent", "(", ")", "->", "getExcludeQueryClients", "(", ")", "&&", "$", "client", "[", "\"client_type\"", "]", ")", "continue", ";", "$", "this", "->", "clientList", "[", "$", "clid", "]", "=", "new", "Client", "(", "$", "this", ",", "$", "client", ")", ";", "}", "uasort", "(", "$", "this", "->", "clientList", ",", "array", "(", "__CLASS__", ",", "\"sortClientList\"", ")", ")", ";", "$", "this", "->", "resetNodeList", "(", ")", ";", "}", "return", "$", "this", "->", "filterList", "(", "$", "this", "->", "clientList", ",", "$", "filter", ")", ";", "}" ]
Returns an array filled with Client objects. @param array $filter @return array|Client[]
[ "Returns", "an", "array", "filled", "with", "Client", "objects", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L657-L678
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.clientGetByName
public function clientGetByName($name) { foreach($this->clientList() as $client) { if($client["client_nickname"] == $name) return $client; } throw new Exception("invalid clientID", 0x200); }
php
public function clientGetByName($name) { foreach($this->clientList() as $client) { if($client["client_nickname"] == $name) return $client; } throw new Exception("invalid clientID", 0x200); }
[ "public", "function", "clientGetByName", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "clientList", "(", ")", "as", "$", "client", ")", "{", "if", "(", "$", "client", "[", "\"client_nickname\"", "]", "==", "$", "name", ")", "return", "$", "client", ";", "}", "throw", "new", "Exception", "(", "\"invalid clientID\"", ",", "0x200", ")", ";", "}" ]
Returns the Client object matching the given name. @param string $name @throws Exception @return Client
[ "Returns", "the", "Client", "object", "matching", "the", "given", "name", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L785-L793
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.clientGetByUid
public function clientGetByUid($uid) { foreach($this->clientList() as $client) { if($client["client_unique_identifier"] == $uid) return $client; } throw new Exception("invalid clientID", 0x200); }
php
public function clientGetByUid($uid) { foreach($this->clientList() as $client) { if($client["client_unique_identifier"] == $uid) return $client; } throw new Exception("invalid clientID", 0x200); }
[ "public", "function", "clientGetByUid", "(", "$", "uid", ")", "{", "foreach", "(", "$", "this", "->", "clientList", "(", ")", "as", "$", "client", ")", "{", "if", "(", "$", "client", "[", "\"client_unique_identifier\"", "]", "==", "$", "uid", ")", "return", "$", "client", ";", "}", "throw", "new", "Exception", "(", "\"invalid clientID\"", ",", "0x200", ")", ";", "}" ]
Returns the Client object matching the given unique identifier. @param string $uid @throws Exception @return Client
[ "Returns", "the", "Client", "object", "matching", "the", "given", "unique", "identifier", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L802-L810
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.clientGetByDbid
public function clientGetByDbid($dbid) { foreach($this->clientList() as $client) { if($client["client_database_id"] == $dbid) return $client; } throw new Exception("invalid clientID", 0x200); }
php
public function clientGetByDbid($dbid) { foreach($this->clientList() as $client) { if($client["client_database_id"] == $dbid) return $client; } throw new Exception("invalid clientID", 0x200); }
[ "public", "function", "clientGetByDbid", "(", "$", "dbid", ")", "{", "foreach", "(", "$", "this", "->", "clientList", "(", ")", "as", "$", "client", ")", "{", "if", "(", "$", "client", "[", "\"client_database_id\"", "]", "==", "$", "dbid", ")", "return", "$", "client", ";", "}", "throw", "new", "Exception", "(", "\"invalid clientID\"", ",", "0x200", ")", ";", "}" ]
Returns the Client object matching the given database ID. @param integer $dbid @throws Exception @return Client
[ "Returns", "the", "Client", "object", "matching", "the", "given", "database", "ID", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L819-L827
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.clientMove
public function clientMove($clid, $cid, $cpw = null) { $this->clientListReset(); $this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw)); if($clid instanceof Node) { $clid = $clid->getId(); } if($cid instanceof Node) { $cid = $cid->getId(); } if(!is_array($clid) && $clid == $this->whoamiGet("client_id")) { $this->getParent()->whoamiSet("client_channel_id", $cid); } }
php
public function clientMove($clid, $cid, $cpw = null) { $this->clientListReset(); $this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw)); if($clid instanceof Node) { $clid = $clid->getId(); } if($cid instanceof Node) { $cid = $cid->getId(); } if(!is_array($clid) && $clid == $this->whoamiGet("client_id")) { $this->getParent()->whoamiSet("client_channel_id", $cid); } }
[ "public", "function", "clientMove", "(", "$", "clid", ",", "$", "cid", ",", "$", "cpw", "=", "null", ")", "{", "$", "this", "->", "clientListReset", "(", ")", ";", "$", "this", "->", "execute", "(", "\"clientmove\"", ",", "array", "(", "\"clid\"", "=>", "$", "clid", ",", "\"cid\"", "=>", "$", "cid", ",", "\"cpw\"", "=>", "$", "cpw", ")", ")", ";", "if", "(", "$", "clid", "instanceof", "Node", ")", "{", "$", "clid", "=", "$", "clid", "->", "getId", "(", ")", ";", "}", "if", "(", "$", "cid", "instanceof", "Node", ")", "{", "$", "cid", "=", "$", "cid", "->", "getId", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "clid", ")", "&&", "$", "clid", "==", "$", "this", "->", "whoamiGet", "(", "\"client_id\"", ")", ")", "{", "$", "this", "->", "getParent", "(", ")", "->", "whoamiSet", "(", "\"client_channel_id\"", ",", "$", "cid", ")", ";", "}", "}" ]
Moves a client to another channel. @param integer $clid @param integer $cid @param string $cpw @return void
[ "Moves", "a", "client", "to", "another", "channel", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L885-L905
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.serverGroupGetById
public function serverGroupGetById($sgid) { if(!array_key_exists((string) $sgid, $this->serverGroupList())) { throw new Exception("invalid groupID", 0xA00); } return $this->sgroupList[intval((string) $sgid)]; }
php
public function serverGroupGetById($sgid) { if(!array_key_exists((string) $sgid, $this->serverGroupList())) { throw new Exception("invalid groupID", 0xA00); } return $this->sgroupList[intval((string) $sgid)]; }
[ "public", "function", "serverGroupGetById", "(", "$", "sgid", ")", "{", "if", "(", "!", "array_key_exists", "(", "(", "string", ")", "$", "sgid", ",", "$", "this", "->", "serverGroupList", "(", ")", ")", ")", "{", "throw", "new", "Exception", "(", "\"invalid groupID\"", ",", "0xA00", ")", ";", "}", "return", "$", "this", "->", "sgroupList", "[", "intval", "(", "(", "string", ")", "$", "sgid", ")", "]", ";", "}" ]
Returns the Servergroup object matching the given ID. @param integer $sgid @throws Exception @return ServerGroup
[ "Returns", "the", "Servergroup", "object", "matching", "the", "given", "ID", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L1157-L1165
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.permRemoveAny
public function permRemoveAny($permid) { $assignments = $this->permissionFind($permid); foreach($assignments as $assignment) { switch($assignment["t"]) { case TeamSpeak3::PERM_TYPE_SERVERGROUP: $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CLIENT: $this->clientPermRemove($assignment["id2"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNEL: $this->channelPermRemove($assignment["id2"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNELGROUP: $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNELCLIENT: $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]); break; default: throw new Exception("convert error", 0x604); } } return count($assignments); }
php
public function permRemoveAny($permid) { $assignments = $this->permissionFind($permid); foreach($assignments as $assignment) { switch($assignment["t"]) { case TeamSpeak3::PERM_TYPE_SERVERGROUP: $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CLIENT: $this->clientPermRemove($assignment["id2"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNEL: $this->channelPermRemove($assignment["id2"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNELGROUP: $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]); break; case TeamSpeak3::PERM_TYPE_CHANNELCLIENT: $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]); break; default: throw new Exception("convert error", 0x604); } } return count($assignments); }
[ "public", "function", "permRemoveAny", "(", "$", "permid", ")", "{", "$", "assignments", "=", "$", "this", "->", "permissionFind", "(", "$", "permid", ")", ";", "foreach", "(", "$", "assignments", "as", "$", "assignment", ")", "{", "switch", "(", "$", "assignment", "[", "\"t\"", "]", ")", "{", "case", "TeamSpeak3", "::", "PERM_TYPE_SERVERGROUP", ":", "$", "this", "->", "serverGroupPermRemove", "(", "$", "assignment", "[", "\"id1\"", "]", ",", "$", "assignment", "[", "\"p\"", "]", ")", ";", "break", ";", "case", "TeamSpeak3", "::", "PERM_TYPE_CLIENT", ":", "$", "this", "->", "clientPermRemove", "(", "$", "assignment", "[", "\"id2\"", "]", ",", "$", "assignment", "[", "\"p\"", "]", ")", ";", "break", ";", "case", "TeamSpeak3", "::", "PERM_TYPE_CHANNEL", ":", "$", "this", "->", "channelPermRemove", "(", "$", "assignment", "[", "\"id2\"", "]", ",", "$", "assignment", "[", "\"p\"", "]", ")", ";", "break", ";", "case", "TeamSpeak3", "::", "PERM_TYPE_CHANNELGROUP", ":", "$", "this", "->", "channelGroupPermRemove", "(", "$", "assignment", "[", "\"id1\"", "]", ",", "$", "assignment", "[", "\"p\"", "]", ")", ";", "break", ";", "case", "TeamSpeak3", "::", "PERM_TYPE_CHANNELCLIENT", ":", "$", "this", "->", "channelClientPermRemove", "(", "$", "assignment", "[", "\"id2\"", "]", ",", "$", "assignment", "[", "\"id1\"", "]", ",", "$", "assignment", "[", "\"p\"", "]", ")", ";", "break", ";", "default", ":", "throw", "new", "Exception", "(", "\"convert error\"", ",", "0x604", ")", ";", "}", "}", "return", "count", "(", "$", "assignments", ")", ";", "}" ]
Removes any assignment of the permission specified with $permid on the selected virtual server and returns the number of removed assignments on success. @param integer $permid @return integer
[ "Removes", "any", "assignment", "of", "the", "permission", "specified", "with", "$permid", "on", "the", "selected", "virtual", "server", "and", "returns", "the", "number", "of", "removed", "assignments", "on", "success", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L1633-L1667
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.transferInitUpload
public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE) { $upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList(); if(array_key_exists("status", $upload) && $upload["status"] != 0x00) { throw new Exception($upload["msg"], $upload["status"]); } $upload["cid"] = $cid; $upload["file"] = $name; if(!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0")) { $upload["ip"] = $this->getParent()->getAdapterHost(); $upload["host"] = $upload["ip"]; } else { $upload["ip"] = $upload["ip"]->section(","); $upload["host"] = $upload["ip"]; } Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload); return $upload; }
php
public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE) { $upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList(); if(array_key_exists("status", $upload) && $upload["status"] != 0x00) { throw new Exception($upload["msg"], $upload["status"]); } $upload["cid"] = $cid; $upload["file"] = $name; if(!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0")) { $upload["ip"] = $this->getParent()->getAdapterHost(); $upload["host"] = $upload["ip"]; } else { $upload["ip"] = $upload["ip"]->section(","); $upload["host"] = $upload["ip"]; } Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload); return $upload; }
[ "public", "function", "transferInitUpload", "(", "$", "clientftfid", ",", "$", "cid", ",", "$", "name", ",", "$", "size", ",", "$", "cpw", "=", "\"\"", ",", "$", "overwrite", "=", "FALSE", ",", "$", "resume", "=", "FALSE", ")", "{", "$", "upload", "=", "$", "this", "->", "execute", "(", "\"ftinitupload\"", ",", "array", "(", "\"clientftfid\"", "=>", "$", "clientftfid", ",", "\"cid\"", "=>", "$", "cid", ",", "\"name\"", "=>", "$", "name", ",", "\"cpw\"", "=>", "$", "cpw", ",", "\"size\"", "=>", "$", "size", ",", "\"overwrite\"", "=>", "$", "overwrite", ",", "\"resume\"", "=>", "$", "resume", ")", ")", "->", "toList", "(", ")", ";", "if", "(", "array_key_exists", "(", "\"status\"", ",", "$", "upload", ")", "&&", "$", "upload", "[", "\"status\"", "]", "!=", "0x00", ")", "{", "throw", "new", "Exception", "(", "$", "upload", "[", "\"msg\"", "]", ",", "$", "upload", "[", "\"status\"", "]", ")", ";", "}", "$", "upload", "[", "\"cid\"", "]", "=", "$", "cid", ";", "$", "upload", "[", "\"file\"", "]", "=", "$", "name", ";", "if", "(", "!", "array_key_exists", "(", "\"ip\"", ",", "$", "upload", ")", "||", "$", "upload", "[", "\"ip\"", "]", "->", "startsWith", "(", "\"0.0.0.0\"", ")", ")", "{", "$", "upload", "[", "\"ip\"", "]", "=", "$", "this", "->", "getParent", "(", ")", "->", "getAdapterHost", "(", ")", ";", "$", "upload", "[", "\"host\"", "]", "=", "$", "upload", "[", "\"ip\"", "]", ";", "}", "else", "{", "$", "upload", "[", "\"ip\"", "]", "=", "$", "upload", "[", "\"ip\"", "]", "->", "section", "(", "\",\"", ")", ";", "$", "upload", "[", "\"host\"", "]", "=", "$", "upload", "[", "\"ip\"", "]", ";", "}", "Signal", "::", "getInstance", "(", ")", "->", "emit", "(", "\"filetransferUploadInit\"", ",", "$", "upload", "[", "\"ftkey\"", "]", ",", "$", "upload", ")", ";", "return", "$", "upload", ";", "}" ]
Initializes a file transfer upload. $clientftfid is an arbitrary ID to identify the file transfer on client-side. @param integer $clientftfid @param integer $cid @param string $name @param integer $size @param string $cpw @param boolean $overwrite @param boolean $resume @throws Exception @return array
[ "Initializes", "a", "file", "transfer", "upload", ".", "$clientftfid", "is", "an", "arbitrary", "ID", "to", "identify", "the", "file", "transfer", "on", "client", "-", "side", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L1682-L1708
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.sortClientList
protected static function sortClientList(Client $a, Client $b) { if(get_class($a) != get_class($b)) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("invalid parameter", 0x602); } if(!$a instanceof Client) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("convert error", 0x604); } if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0)) { return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1; } if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0)) { return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1; } return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"])); }
php
protected static function sortClientList(Client $a, Client $b) { if(get_class($a) != get_class($b)) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("invalid parameter", 0x602); } if(!$a instanceof Client) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("convert error", 0x604); } if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0)) { return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1; } if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0)) { return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1; } return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"])); }
[ "protected", "static", "function", "sortClientList", "(", "Client", "$", "a", ",", "Client", "$", "b", ")", "{", "if", "(", "get_class", "(", "$", "a", ")", "!=", "get_class", "(", "$", "b", ")", ")", "{", "return", "0", ";", "/* workaround for PHP bug #50688 */", "throw", "new", "Exception", "(", "\"invalid parameter\"", ",", "0x602", ")", ";", "}", "if", "(", "!", "$", "a", "instanceof", "Client", ")", "{", "return", "0", ";", "/* workaround for PHP bug #50688 */", "throw", "new", "Exception", "(", "\"convert error\"", ",", "0x604", ")", ";", "}", "if", "(", "$", "a", "->", "getProperty", "(", "\"client_talk_power\"", ",", "0", ")", "!=", "$", "b", "->", "getProperty", "(", "\"client_talk_power\"", ",", "0", ")", ")", "{", "return", "(", "$", "a", "->", "getProperty", "(", "\"client_talk_power\"", ",", "0", ")", ">", "$", "b", "->", "getProperty", "(", "\"client_talk_power\"", ",", "0", ")", ")", "?", "-", "1", ":", "1", ";", "}", "if", "(", "$", "a", "->", "getProperty", "(", "\"client_is_talker\"", ",", "0", ")", "!=", "$", "b", "->", "getProperty", "(", "\"client_is_talker\"", ",", "0", ")", ")", "{", "return", "(", "$", "a", "->", "getProperty", "(", "\"client_is_talker\"", ",", "0", ")", ">", "$", "b", "->", "getProperty", "(", "\"client_is_talker\"", ",", "0", ")", ")", "?", "-", "1", ":", "1", ";", "}", "return", "strcmp", "(", "strtolower", "(", "$", "a", "[", "\"client_nickname\"", "]", ")", ",", "strtolower", "(", "$", "b", "[", "\"client_nickname\"", "]", ")", ")", ";", "}" ]
Internal callback funtion for sorting of client objects. @param Client $a @param Client $b @return integer
[ "Internal", "callback", "funtion", "for", "sorting", "of", "client", "objects", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L2458-L2487
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.sortGroupList
protected static function sortGroupList(Node $a, Node $b) { if(get_class($a) != get_class($b)) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("invalid parameter", 0x602); } if(!$a instanceof Servergroup && !$a instanceof Channelgroup) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("convert error", 0x604); } if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0) { return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1; } return ($a->getId() < $b->getId()) ? -1 : 1; }
php
protected static function sortGroupList(Node $a, Node $b) { if(get_class($a) != get_class($b)) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("invalid parameter", 0x602); } if(!$a instanceof Servergroup && !$a instanceof Channelgroup) { return 0; /* workaround for PHP bug #50688 */ throw new Exception("convert error", 0x604); } if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0) { return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1; } return ($a->getId() < $b->getId()) ? -1 : 1; }
[ "protected", "static", "function", "sortGroupList", "(", "Node", "$", "a", ",", "Node", "$", "b", ")", "{", "if", "(", "get_class", "(", "$", "a", ")", "!=", "get_class", "(", "$", "b", ")", ")", "{", "return", "0", ";", "/* workaround for PHP bug #50688 */", "throw", "new", "Exception", "(", "\"invalid parameter\"", ",", "0x602", ")", ";", "}", "if", "(", "!", "$", "a", "instanceof", "Servergroup", "&&", "!", "$", "a", "instanceof", "Channelgroup", ")", "{", "return", "0", ";", "/* workaround for PHP bug #50688 */", "throw", "new", "Exception", "(", "\"convert error\"", ",", "0x604", ")", ";", "}", "if", "(", "$", "a", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", "!=", "$", "b", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", "&&", "$", "a", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", "!=", "0", "&&", "$", "b", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", "!=", "0", ")", "{", "return", "(", "$", "a", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", "<", "$", "b", "->", "getProperty", "(", "\"sortid\"", ",", "0", ")", ")", "?", "-", "1", ":", "1", ";", "}", "return", "(", "$", "a", "->", "getId", "(", ")", "<", "$", "b", "->", "getId", "(", ")", ")", "?", "-", "1", ":", "1", ";", "}" ]
Internal callback funtion for sorting of group objects. @param Node $a @param Node $b @return integer
[ "Internal", "callback", "funtion", "for", "sorting", "of", "group", "objects", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L2496-L2520
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Node/Server.php
Server.sortFileList
protected static function sortFileList(array $a, array $b) { if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b)) { return 0; throw new Exception("invalid parameter", 0x602); } if($a["type"] != $b["type"]) { return ($a["type"] < $b["type"]) ? -1 : 1; } return strcmp(strtolower($a["src"]), strtolower($b["src"])); }
php
protected static function sortFileList(array $a, array $b) { if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b)) { return 0; throw new Exception("invalid parameter", 0x602); } if($a["type"] != $b["type"]) { return ($a["type"] < $b["type"]) ? -1 : 1; } return strcmp(strtolower($a["src"]), strtolower($b["src"])); }
[ "protected", "static", "function", "sortFileList", "(", "array", "$", "a", ",", "array", "$", "b", ")", "{", "if", "(", "!", "array_key_exists", "(", "\"src\"", ",", "$", "a", ")", "||", "!", "array_key_exists", "(", "\"src\"", ",", "$", "b", ")", "||", "!", "array_key_exists", "(", "\"type\"", ",", "$", "a", ")", "||", "!", "array_key_exists", "(", "\"type\"", ",", "$", "b", ")", ")", "{", "return", "0", ";", "throw", "new", "Exception", "(", "\"invalid parameter\"", ",", "0x602", ")", ";", "}", "if", "(", "$", "a", "[", "\"type\"", "]", "!=", "$", "b", "[", "\"type\"", "]", ")", "{", "return", "(", "$", "a", "[", "\"type\"", "]", "<", "$", "b", "[", "\"type\"", "]", ")", "?", "-", "1", ":", "1", ";", "}", "return", "strcmp", "(", "strtolower", "(", "$", "a", "[", "\"src\"", "]", ")", ",", "strtolower", "(", "$", "b", "[", "\"src\"", "]", ")", ")", ";", "}" ]
Internal callback funtion for sorting of file list items. @param array $a @param array $b @return integer
[ "Internal", "callback", "funtion", "for", "sorting", "of", "file", "list", "items", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L2529-L2544
surebert/surebert-framework
src/sb/Memory.php
Memory.getUsage
public static function getUsage($system=false, $peak = true) { if ($peak) { $mem = memory_get_peak_usage($system); } else { $mem = memory_get_usage($system); } $unit=array('b','kb','mb','gb','tb','pb'); return round($mem/pow(1024,($i=floor(log($mem,1024)))),2).' '.$unit[$i]; }
php
public static function getUsage($system=false, $peak = true) { if ($peak) { $mem = memory_get_peak_usage($system); } else { $mem = memory_get_usage($system); } $unit=array('b','kb','mb','gb','tb','pb'); return round($mem/pow(1024,($i=floor(log($mem,1024)))),2).' '.$unit[$i]; }
[ "public", "static", "function", "getUsage", "(", "$", "system", "=", "false", ",", "$", "peak", "=", "true", ")", "{", "if", "(", "$", "peak", ")", "{", "$", "mem", "=", "memory_get_peak_usage", "(", "$", "system", ")", ";", "}", "else", "{", "$", "mem", "=", "memory_get_usage", "(", "$", "system", ")", ";", "}", "$", "unit", "=", "array", "(", "'b'", ",", "'kb'", ",", "'mb'", ",", "'gb'", ",", "'tb'", ",", "'pb'", ")", ";", "return", "round", "(", "$", "mem", "/", "pow", "(", "1024", ",", "(", "$", "i", "=", "floor", "(", "log", "(", "$", "mem", ",", "1024", ")", ")", ")", ")", ",", "2", ")", ".", "' '", ".", "$", "unit", "[", "$", "i", "]", ";", "}" ]
Determines the peak memory usage @param boolean $system Set this to TRUE to get the real size of memory allocated from system @param boolean $peak Get peak memory if true, otherwise current memory @return string The value in b, KB, or MB depending on size
[ "Determines", "the", "peak", "memory", "usage" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Memory.php#L15-L24
thienhungho/yii2-product-management
src/modules/ProductManage/search/ProductUnitEquivalentSearch.php
ProductUnitEquivalentSearch.search
public function search($params) { $query = ProductUnitEquivalent::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'product_unit_1' => $this->product_unit_1, 'product_unit_1_value' => $this->product_unit_1_value, 'product_unit_2' => $this->product_unit_2, 'product_unit_2_value' => $this->product_unit_2_value, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]); return $dataProvider; }
php
public function search($params) { $query = ProductUnitEquivalent::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'product_unit_1' => $this->product_unit_1, 'product_unit_1_value' => $this->product_unit_1_value, 'product_unit_2' => $this->product_unit_2, 'product_unit_2_value' => $this->product_unit_2_value, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "ProductUnitEquivalent", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this", "->", "load", "(", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "// uncomment the following line if you do not want to return any records when validation fails\r", "// $query->where('0=1');\r", "return", "$", "dataProvider", ";", "}", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'product_unit_1'", "=>", "$", "this", "->", "product_unit_1", ",", "'product_unit_1_value'", "=>", "$", "this", "->", "product_unit_1_value", ",", "'product_unit_2'", "=>", "$", "this", "->", "product_unit_2", ",", "'product_unit_2_value'", "=>", "$", "this", "->", "product_unit_2_value", ",", "'created_at'", "=>", "$", "this", "->", "created_at", ",", "'updated_at'", "=>", "$", "this", "->", "updated_at", ",", "'created_by'", "=>", "$", "this", "->", "created_by", ",", "'updated_by'", "=>", "$", "this", "->", "updated_by", ",", "]", ")", ";", "return", "$", "dataProvider", ";", "}" ]
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/search/ProductUnitEquivalentSearch.php#L42-L71
shabbyrobe/amiss
src/Sql/Manager.php
Manager.selectList
public function selectList($meta, ...$args) { if (!$args) { throw new \InvalidArgumentException(); } $fields = null; $query = null; if (!isset($args[1]) && $args[0] instanceof Query\Select) { $query = $args[0]; } elseif ((is_array($args[0]) || is_string($args[0])) && !isset($args[2])) { $fields = $args[0]; $query = isset($args[1]) ? $args[1] : null; } else { throw new \InvalidArgumentException(); } $query = $query instanceof Query\Select ? $query : Query\Select::fromParamArgs([$query]); if ($fields) { $query->fields = $fields; } if (!$query->fields) { throw new \InvalidArgumentException(); } $singleMode = false; if (is_string($query->fields)) { $singleMode = true; $query->fields = [$query->fields]; } $mapper = $this->mapper; $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; list ($sql, $params, $props) = $query->buildQuery($meta); if ($props) { $params = $this->mapper->formatParams($meta, $props, $params); } $stmt = $this->getConnector()->prepare($sql)->execute($params); $mappedRows = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $mappedRow = $mapper->mapRowToProperties($meta, $row); if ($singleMode) { $mappedRows[] = current($mappedRow); } else { $mappedRows[] = $mappedRow; } } return $mappedRows; }
php
public function selectList($meta, ...$args) { if (!$args) { throw new \InvalidArgumentException(); } $fields = null; $query = null; if (!isset($args[1]) && $args[0] instanceof Query\Select) { $query = $args[0]; } elseif ((is_array($args[0]) || is_string($args[0])) && !isset($args[2])) { $fields = $args[0]; $query = isset($args[1]) ? $args[1] : null; } else { throw new \InvalidArgumentException(); } $query = $query instanceof Query\Select ? $query : Query\Select::fromParamArgs([$query]); if ($fields) { $query->fields = $fields; } if (!$query->fields) { throw new \InvalidArgumentException(); } $singleMode = false; if (is_string($query->fields)) { $singleMode = true; $query->fields = [$query->fields]; } $mapper = $this->mapper; $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; list ($sql, $params, $props) = $query->buildQuery($meta); if ($props) { $params = $this->mapper->formatParams($meta, $props, $params); } $stmt = $this->getConnector()->prepare($sql)->execute($params); $mappedRows = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $mappedRow = $mapper->mapRowToProperties($meta, $row); if ($singleMode) { $mappedRows[] = current($mappedRow); } else { $mappedRows[] = $mappedRow; } } return $mappedRows; }
[ "public", "function", "selectList", "(", "$", "meta", ",", "...", "$", "args", ")", "{", "if", "(", "!", "$", "args", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "$", "fields", "=", "null", ";", "$", "query", "=", "null", ";", "if", "(", "!", "isset", "(", "$", "args", "[", "1", "]", ")", "&&", "$", "args", "[", "0", "]", "instanceof", "Query", "\\", "Select", ")", "{", "$", "query", "=", "$", "args", "[", "0", "]", ";", "}", "elseif", "(", "(", "is_array", "(", "$", "args", "[", "0", "]", ")", "||", "is_string", "(", "$", "args", "[", "0", "]", ")", ")", "&&", "!", "isset", "(", "$", "args", "[", "2", "]", ")", ")", "{", "$", "fields", "=", "$", "args", "[", "0", "]", ";", "$", "query", "=", "isset", "(", "$", "args", "[", "1", "]", ")", "?", "$", "args", "[", "1", "]", ":", "null", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "$", "query", "=", "$", "query", "instanceof", "Query", "\\", "Select", "?", "$", "query", ":", "Query", "\\", "Select", "::", "fromParamArgs", "(", "[", "$", "query", "]", ")", ";", "if", "(", "$", "fields", ")", "{", "$", "query", "->", "fields", "=", "$", "fields", ";", "}", "if", "(", "!", "$", "query", "->", "fields", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "$", "singleMode", "=", "false", ";", "if", "(", "is_string", "(", "$", "query", "->", "fields", ")", ")", "{", "$", "singleMode", "=", "true", ";", "$", "query", "->", "fields", "=", "[", "$", "query", "->", "fields", "]", ";", "}", "$", "mapper", "=", "$", "this", "->", "mapper", ";", "$", "meta", "=", "!", "$", "meta", "instanceof", "Meta", "?", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ":", "$", "meta", ";", "list", "(", "$", "sql", ",", "$", "params", ",", "$", "props", ")", "=", "$", "query", "->", "buildQuery", "(", "$", "meta", ")", ";", "if", "(", "$", "props", ")", "{", "$", "params", "=", "$", "this", "->", "mapper", "->", "formatParams", "(", "$", "meta", ",", "$", "props", ",", "$", "params", ")", ";", "}", "$", "stmt", "=", "$", "this", "->", "getConnector", "(", ")", "->", "prepare", "(", "$", "sql", ")", "->", "execute", "(", "$", "params", ")", ";", "$", "mappedRows", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "mappedRow", "=", "$", "mapper", "->", "mapRowToProperties", "(", "$", "meta", ",", "$", "row", ")", ";", "if", "(", "$", "singleMode", ")", "{", "$", "mappedRows", "[", "]", "=", "current", "(", "$", "mappedRow", ")", ";", "}", "else", "{", "$", "mappedRows", "[", "]", "=", "$", "mappedRow", ";", "}", "}", "return", "$", "mappedRows", ";", "}" ]
Dunno about this. Consider it unstable, don't count on it still being here in v6
[ "Dunno", "about", "this", ".", "Consider", "it", "unstable", "don", "t", "count", "on", "it", "still", "being", "here", "in", "v6" ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L217-L270
shabbyrobe/amiss
src/Sql/Manager.php
Manager.count
public function count($meta, ...$args) { $query = $args && $args[0] instanceof Query\Select ? $args[0] : Query\Select::fromParamArgs($args); $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; $table = $query->table ?: $meta->table; list ($where, $params, $props) = $query->buildClause($meta); if ($props) { $params = $this->mapper->formatParams($meta, $props, $params); } $t = ($meta->schema ? "`{$meta->schema}`." : null)."`{$table}`"; $query = "SELECT COUNT(1) FROM $t " .($where ? "WHERE $where" : ''); $stmt = $this->getConnector()->prepare($query)->execute($params); return (int)$stmt->fetchColumn(); }
php
public function count($meta, ...$args) { $query = $args && $args[0] instanceof Query\Select ? $args[0] : Query\Select::fromParamArgs($args); $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; $table = $query->table ?: $meta->table; list ($where, $params, $props) = $query->buildClause($meta); if ($props) { $params = $this->mapper->formatParams($meta, $props, $params); } $t = ($meta->schema ? "`{$meta->schema}`." : null)."`{$table}`"; $query = "SELECT COUNT(1) FROM $t " .($where ? "WHERE $where" : ''); $stmt = $this->getConnector()->prepare($query)->execute($params); return (int)$stmt->fetchColumn(); }
[ "public", "function", "count", "(", "$", "meta", ",", "...", "$", "args", ")", "{", "$", "query", "=", "$", "args", "&&", "$", "args", "[", "0", "]", "instanceof", "Query", "\\", "Select", "?", "$", "args", "[", "0", "]", ":", "Query", "\\", "Select", "::", "fromParamArgs", "(", "$", "args", ")", ";", "$", "meta", "=", "!", "$", "meta", "instanceof", "Meta", "?", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ":", "$", "meta", ";", "$", "table", "=", "$", "query", "->", "table", "?", ":", "$", "meta", "->", "table", ";", "list", "(", "$", "where", ",", "$", "params", ",", "$", "props", ")", "=", "$", "query", "->", "buildClause", "(", "$", "meta", ")", ";", "if", "(", "$", "props", ")", "{", "$", "params", "=", "$", "this", "->", "mapper", "->", "formatParams", "(", "$", "meta", ",", "$", "props", ",", "$", "params", ")", ";", "}", "$", "t", "=", "(", "$", "meta", "->", "schema", "?", "\"`{$meta->schema}`.\"", ":", "null", ")", ".", "\"`{$table}`\"", ";", "$", "query", "=", "\"SELECT COUNT(1) FROM $t \"", ".", "(", "$", "where", "?", "\"WHERE $where\"", ":", "''", ")", ";", "$", "stmt", "=", "$", "this", "->", "getConnector", "(", ")", "->", "prepare", "(", "$", "query", ")", "->", "execute", "(", "$", "params", ")", ";", "return", "(", "int", ")", "$", "stmt", "->", "fetchColumn", "(", ")", ";", "}" ]
count ( $meta ) count ( $meta , string $where [ , array $params ] ) count ( $meta , array $query ) count ( $meta , \Amiss\Sql\Query\Select $query ) @param $meta string|Amiss\Meta @return int
[ "count", "(", "$meta", ")", "count", "(", "$meta", "string", "$where", "[", "array", "$params", "]", ")", "count", "(", "$meta", "array", "$query", ")", "count", "(", "$meta", "\\", "Amiss", "\\", "Sql", "\\", "Query", "\\", "Select", "$query", ")" ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L293-L311
shabbyrobe/amiss
src/Sql/Manager.php
Manager.assignRelated
public function assignRelated($source, $relationNames=null, $meta=null) { if (!$source) { return; } $stack = []; $sourceIsArray = is_array($source) || $source instanceof \Traversable; if (!$sourceIsArray) { $source = array($source); } if ($meta !== null) { $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; } else { $meta = $this->mapper->getMeta(get_class($source[0])); } if (!$relationNames) { if ($meta->autoRelations) { $relationNames = $meta->autoRelations; } else { throw new Exception("relationNames not passed, class {$meta->class} does not define autoRelations"); } } $relationMap = []; foreach ((array)$relationNames as $relationName) { if (!isset($meta->relations[$relationName])) { throw new Exception("Unknown relation $relationName on {$meta->class}"); } $relationMap[$relationName] = $rel = $meta->relations[$relationName]; if ($rel['mode'] == 'class') { throw new Exception("Relation $relationName is not assignable for class {$meta->class}"); } } $done = []; foreach ($relationMap as $relationName=>$relation) { if (isset($done[$relationName])) { continue; } $done[$relationName] = true; $missing = []; foreach ($source as $idx=>$item) { // we have to assume it's missing if we see a getter as there // may be serious unintended side effects from calling a getter // that may be unpopulated. it might lazy load if it's an active // record, or it might throw an exception because the 'set' hasn't // been called. // check for isset as well as falsey for the situation where we're using // stdClasses as the response object if (isset($relation['getter']) || !isset($item->{$relationName}) || !$item->{$relationName}) { $missing[$idx] = $item; } } if ($missing) { $result = $this->getRelated($missing, $relationName, ['stack'=>$stack], $meta); $relator = $this->getRelator($meta, $relationName); $this->populateObjectsWithRelated($missing, $result, $relation); } } }
php
public function assignRelated($source, $relationNames=null, $meta=null) { if (!$source) { return; } $stack = []; $sourceIsArray = is_array($source) || $source instanceof \Traversable; if (!$sourceIsArray) { $source = array($source); } if ($meta !== null) { $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; } else { $meta = $this->mapper->getMeta(get_class($source[0])); } if (!$relationNames) { if ($meta->autoRelations) { $relationNames = $meta->autoRelations; } else { throw new Exception("relationNames not passed, class {$meta->class} does not define autoRelations"); } } $relationMap = []; foreach ((array)$relationNames as $relationName) { if (!isset($meta->relations[$relationName])) { throw new Exception("Unknown relation $relationName on {$meta->class}"); } $relationMap[$relationName] = $rel = $meta->relations[$relationName]; if ($rel['mode'] == 'class') { throw new Exception("Relation $relationName is not assignable for class {$meta->class}"); } } $done = []; foreach ($relationMap as $relationName=>$relation) { if (isset($done[$relationName])) { continue; } $done[$relationName] = true; $missing = []; foreach ($source as $idx=>$item) { // we have to assume it's missing if we see a getter as there // may be serious unintended side effects from calling a getter // that may be unpopulated. it might lazy load if it's an active // record, or it might throw an exception because the 'set' hasn't // been called. // check for isset as well as falsey for the situation where we're using // stdClasses as the response object if (isset($relation['getter']) || !isset($item->{$relationName}) || !$item->{$relationName}) { $missing[$idx] = $item; } } if ($missing) { $result = $this->getRelated($missing, $relationName, ['stack'=>$stack], $meta); $relator = $this->getRelator($meta, $relationName); $this->populateObjectsWithRelated($missing, $result, $relation); } } }
[ "public", "function", "assignRelated", "(", "$", "source", ",", "$", "relationNames", "=", "null", ",", "$", "meta", "=", "null", ")", "{", "if", "(", "!", "$", "source", ")", "{", "return", ";", "}", "$", "stack", "=", "[", "]", ";", "$", "sourceIsArray", "=", "is_array", "(", "$", "source", ")", "||", "$", "source", "instanceof", "\\", "Traversable", ";", "if", "(", "!", "$", "sourceIsArray", ")", "{", "$", "source", "=", "array", "(", "$", "source", ")", ";", "}", "if", "(", "$", "meta", "!==", "null", ")", "{", "$", "meta", "=", "!", "$", "meta", "instanceof", "Meta", "?", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ":", "$", "meta", ";", "}", "else", "{", "$", "meta", "=", "$", "this", "->", "mapper", "->", "getMeta", "(", "get_class", "(", "$", "source", "[", "0", "]", ")", ")", ";", "}", "if", "(", "!", "$", "relationNames", ")", "{", "if", "(", "$", "meta", "->", "autoRelations", ")", "{", "$", "relationNames", "=", "$", "meta", "->", "autoRelations", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"relationNames not passed, class {$meta->class} does not define autoRelations\"", ")", ";", "}", "}", "$", "relationMap", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "relationNames", "as", "$", "relationName", ")", "{", "if", "(", "!", "isset", "(", "$", "meta", "->", "relations", "[", "$", "relationName", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unknown relation $relationName on {$meta->class}\"", ")", ";", "}", "$", "relationMap", "[", "$", "relationName", "]", "=", "$", "rel", "=", "$", "meta", "->", "relations", "[", "$", "relationName", "]", ";", "if", "(", "$", "rel", "[", "'mode'", "]", "==", "'class'", ")", "{", "throw", "new", "Exception", "(", "\"Relation $relationName is not assignable for class {$meta->class}\"", ")", ";", "}", "}", "$", "done", "=", "[", "]", ";", "foreach", "(", "$", "relationMap", "as", "$", "relationName", "=>", "$", "relation", ")", "{", "if", "(", "isset", "(", "$", "done", "[", "$", "relationName", "]", ")", ")", "{", "continue", ";", "}", "$", "done", "[", "$", "relationName", "]", "=", "true", ";", "$", "missing", "=", "[", "]", ";", "foreach", "(", "$", "source", "as", "$", "idx", "=>", "$", "item", ")", "{", "// we have to assume it's missing if we see a getter as there", "// may be serious unintended side effects from calling a getter", "// that may be unpopulated. it might lazy load if it's an active", "// record, or it might throw an exception because the 'set' hasn't", "// been called.", "// check for isset as well as falsey for the situation where we're using", "// stdClasses as the response object", "if", "(", "isset", "(", "$", "relation", "[", "'getter'", "]", ")", "||", "!", "isset", "(", "$", "item", "->", "{", "$", "relationName", "}", ")", "||", "!", "$", "item", "->", "{", "$", "relationName", "}", ")", "{", "$", "missing", "[", "$", "idx", "]", "=", "$", "item", ";", "}", "}", "if", "(", "$", "missing", ")", "{", "$", "result", "=", "$", "this", "->", "getRelated", "(", "$", "missing", ",", "$", "relationName", ",", "[", "'stack'", "=>", "$", "stack", "]", ",", "$", "meta", ")", ";", "$", "relator", "=", "$", "this", "->", "getRelator", "(", "$", "meta", ",", "$", "relationName", ")", ";", "$", "this", "->", "populateObjectsWithRelated", "(", "$", "missing", ",", "$", "result", ",", "$", "relation", ")", ";", "}", "}", "}" ]
Retrieve related objects from the database and assign them to the source if the source field is not yet populated. @param object|array Source objects to assign relations for @param string|array The name of the relation(s) to assign @return void
[ "Retrieve", "related", "objects", "from", "the", "database", "and", "assign", "them", "to", "the", "source", "if", "the", "source", "field", "is", "not", "yet", "populated", "." ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L330-L393
shabbyrobe/amiss
src/Sql/Manager.php
Manager.getRelated
public function getRelated($source, $relationName, $query=null, $meta=null) { if (!$source) { return; } $sourceIsArray = false; $test = $source; if (is_array($test) || $test instanceof \Traversable) { $sourceIsArray = true; $test = $test[0]; } if (!$meta) { if ($query instanceof Meta) { list ($meta, $query) = [$query, null]; } else { $meta = $this->mapper->getMeta(get_class($test)); } } else { $meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta); } if (!isset($meta->relations[$relationName])) { throw new Exception("Unknown relation $relationName on {$meta->class}"); } $relation = $meta->relations[$relationName]; $relator = $this->getRelator($relation); if ($query) { // need to support both Query\Criteria and Query\Select // this is a cheeky hack - the API doesn't declare support for // Select in Relators because it carries promises of things like // 'fields' and whatnot that we'll never be able to satisfy. // That whole hierarchy needs to be cleaned // up into a bunch of traits so we can have RelatorCriteria or something. $query = $query instanceof Query\Criteria ? $query : Query\Select::fromParamArgs([$query]); $stack = $query->stack; } else { $stack = []; } $stack[$meta->class] = true; if ($sourceIsArray) { return $relator->getRelatedForList($meta, $source, $relation, $query ?: null, $stack); } else { return $relator->getRelated($meta, $source, $relation, $query ?: null, $stack); } }
php
public function getRelated($source, $relationName, $query=null, $meta=null) { if (!$source) { return; } $sourceIsArray = false; $test = $source; if (is_array($test) || $test instanceof \Traversable) { $sourceIsArray = true; $test = $test[0]; } if (!$meta) { if ($query instanceof Meta) { list ($meta, $query) = [$query, null]; } else { $meta = $this->mapper->getMeta(get_class($test)); } } else { $meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta); } if (!isset($meta->relations[$relationName])) { throw new Exception("Unknown relation $relationName on {$meta->class}"); } $relation = $meta->relations[$relationName]; $relator = $this->getRelator($relation); if ($query) { // need to support both Query\Criteria and Query\Select // this is a cheeky hack - the API doesn't declare support for // Select in Relators because it carries promises of things like // 'fields' and whatnot that we'll never be able to satisfy. // That whole hierarchy needs to be cleaned // up into a bunch of traits so we can have RelatorCriteria or something. $query = $query instanceof Query\Criteria ? $query : Query\Select::fromParamArgs([$query]); $stack = $query->stack; } else { $stack = []; } $stack[$meta->class] = true; if ($sourceIsArray) { return $relator->getRelatedForList($meta, $source, $relation, $query ?: null, $stack); } else { return $relator->getRelated($meta, $source, $relation, $query ?: null, $stack); } }
[ "public", "function", "getRelated", "(", "$", "source", ",", "$", "relationName", ",", "$", "query", "=", "null", ",", "$", "meta", "=", "null", ")", "{", "if", "(", "!", "$", "source", ")", "{", "return", ";", "}", "$", "sourceIsArray", "=", "false", ";", "$", "test", "=", "$", "source", ";", "if", "(", "is_array", "(", "$", "test", ")", "||", "$", "test", "instanceof", "\\", "Traversable", ")", "{", "$", "sourceIsArray", "=", "true", ";", "$", "test", "=", "$", "test", "[", "0", "]", ";", "}", "if", "(", "!", "$", "meta", ")", "{", "if", "(", "$", "query", "instanceof", "Meta", ")", "{", "list", "(", "$", "meta", ",", "$", "query", ")", "=", "[", "$", "query", ",", "null", "]", ";", "}", "else", "{", "$", "meta", "=", "$", "this", "->", "mapper", "->", "getMeta", "(", "get_class", "(", "$", "test", ")", ")", ";", "}", "}", "else", "{", "$", "meta", "=", "$", "meta", "instanceof", "Meta", "?", "$", "meta", ":", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "meta", "->", "relations", "[", "$", "relationName", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unknown relation $relationName on {$meta->class}\"", ")", ";", "}", "$", "relation", "=", "$", "meta", "->", "relations", "[", "$", "relationName", "]", ";", "$", "relator", "=", "$", "this", "->", "getRelator", "(", "$", "relation", ")", ";", "if", "(", "$", "query", ")", "{", "// need to support both Query\\Criteria and Query\\Select", "// this is a cheeky hack - the API doesn't declare support for", "// Select in Relators because it carries promises of things like ", "// 'fields' and whatnot that we'll never be able to satisfy. ", "// That whole hierarchy needs to be cleaned", "// up into a bunch of traits so we can have RelatorCriteria or something.", "$", "query", "=", "$", "query", "instanceof", "Query", "\\", "Criteria", "?", "$", "query", ":", "Query", "\\", "Select", "::", "fromParamArgs", "(", "[", "$", "query", "]", ")", ";", "$", "stack", "=", "$", "query", "->", "stack", ";", "}", "else", "{", "$", "stack", "=", "[", "]", ";", "}", "$", "stack", "[", "$", "meta", "->", "class", "]", "=", "true", ";", "if", "(", "$", "sourceIsArray", ")", "{", "return", "$", "relator", "->", "getRelatedForList", "(", "$", "meta", ",", "$", "source", ",", "$", "relation", ",", "$", "query", "?", ":", "null", ",", "$", "stack", ")", ";", "}", "else", "{", "return", "$", "relator", "->", "getRelated", "(", "$", "meta", ",", "$", "source", ",", "$", "relation", ",", "$", "query", "?", ":", "null", ",", "$", "stack", ")", ";", "}", "}" ]
Get related objects from the database Supports the following signatures: - getRelated( object|array $source , string $relationName ) - getRelated( object|array $source , string $relationName , $query ) - getRelated( object|array $source , string $relationName , Meta $meta ) - getRelated( object|array $source , string $relationName , $query, Meta $meta ) @return object[]
[ "Get", "related", "objects", "from", "the", "database" ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L478-L528
shabbyrobe/amiss
src/Sql/Manager.php
Manager.insertTable
public function insertTable($meta, $query) { $meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta); if (!$meta->canInsert) { throw new Exception("Class {$meta->class} prohibits insert"); } $query = $query instanceof Query\Insert ? $query : new Query\Insert(['values'=>$query]); $query->values = $this->mapper->mapPropertiesToRow($meta, $query->values); if (!$query->table) { $query->table = $meta->table; } list ($sql, $params) = $query->buildQuery($meta); // no need to formatParams here - they're already field names $stmt = $this->getConnector()->prepare($sql); $stmt->execute($params); $lastInsertId = $this->getConnector()->lastInsertId(); return $lastInsertId; }
php
public function insertTable($meta, $query) { $meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta); if (!$meta->canInsert) { throw new Exception("Class {$meta->class} prohibits insert"); } $query = $query instanceof Query\Insert ? $query : new Query\Insert(['values'=>$query]); $query->values = $this->mapper->mapPropertiesToRow($meta, $query->values); if (!$query->table) { $query->table = $meta->table; } list ($sql, $params) = $query->buildQuery($meta); // no need to formatParams here - they're already field names $stmt = $this->getConnector()->prepare($sql); $stmt->execute($params); $lastInsertId = $this->getConnector()->lastInsertId(); return $lastInsertId; }
[ "public", "function", "insertTable", "(", "$", "meta", ",", "$", "query", ")", "{", "$", "meta", "=", "$", "meta", "instanceof", "Meta", "?", "$", "meta", ":", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ";", "if", "(", "!", "$", "meta", "->", "canInsert", ")", "{", "throw", "new", "Exception", "(", "\"Class {$meta->class} prohibits insert\"", ")", ";", "}", "$", "query", "=", "$", "query", "instanceof", "Query", "\\", "Insert", "?", "$", "query", ":", "new", "Query", "\\", "Insert", "(", "[", "'values'", "=>", "$", "query", "]", ")", ";", "$", "query", "->", "values", "=", "$", "this", "->", "mapper", "->", "mapPropertiesToRow", "(", "$", "meta", ",", "$", "query", "->", "values", ")", ";", "if", "(", "!", "$", "query", "->", "table", ")", "{", "$", "query", "->", "table", "=", "$", "meta", "->", "table", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "query", "->", "buildQuery", "(", "$", "meta", ")", ";", "// no need to formatParams here - they're already field names", "$", "stmt", "=", "$", "this", "->", "getConnector", "(", ")", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "$", "lastInsertId", "=", "$", "this", "->", "getConnector", "(", ")", "->", "lastInsertId", "(", ")", ";", "return", "$", "lastInsertId", ";", "}" ]
Insert values into a table insertTable ( $meta , array $propertyValues ); insertTable ( $meta , Query\Insert $query ); - $meta can be an instance of Amiss\Meta or a class name. - $propertyValues keys must exist in the corresponding Meta. @return int|null
[ "Insert", "values", "into", "a", "table" ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L541-L561
shabbyrobe/amiss
src/Sql/Manager.php
Manager.insert
public function insert($object, $meta=null) { $query = new Query\Insert; if (is_array($meta)) { throw new \BadMethodCallException("Please use insertTable()"); } if ($meta) { $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; } else { $meta = $this->mapper->getMeta(get_class($object)); } if (!$meta->canInsert) { throw new Exception("Meta {$meta->id} prohibits insert"); } event_before: { if (isset($meta->on['beforeInsert'])) { foreach ($meta->on['beforeInsert'] as $cb) { $cb = [$object, $cb]; $cb(); } } if (isset($this->on['beforeInsert'])) { foreach ($this->on['beforeInsert'] as $cb) { $cb($object, $meta); } } } query: { $query->values = $this->mapper->mapObjectToRow($object, $meta, 'insert'); if (!$query->table) { $query->table = $meta->table; } list ($sql, $params, $props) = $query->buildQuery($meta); $stmt = $this->getConnector()->prepare($sql); $stmt->execute($params); } $lastInsertId = null; // we need to be careful with "lastInsertId": SQLite generates one even without a PRIMARY if ($object && $meta->primary) { $lastInsertId = $this->getConnector()->lastInsertId(); if ($lastInsertId && $meta->autoinc) { $field = $meta->fields[$meta->autoinc]; $handler = $this->mapper->determineTypeHandler(Mapper::AUTOINC_TYPE); if (!$handler) { throw new \UnexpectedValueException(); } $meta->setValue($object, $meta->autoinc, $lastInsertId); } } event_after: { if (isset($meta->on['afterInsert'])) { foreach ($meta->on['afterInsert'] as $cb) { $cb = [$object, $cb]; $cb(); } } if (isset($this->on['afterInsert'])) { foreach ($this->on['afterInsert'] as $cb) { $cb($object, $meta); } } } return $lastInsertId; }
php
public function insert($object, $meta=null) { $query = new Query\Insert; if (is_array($meta)) { throw new \BadMethodCallException("Please use insertTable()"); } if ($meta) { $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta; } else { $meta = $this->mapper->getMeta(get_class($object)); } if (!$meta->canInsert) { throw new Exception("Meta {$meta->id} prohibits insert"); } event_before: { if (isset($meta->on['beforeInsert'])) { foreach ($meta->on['beforeInsert'] as $cb) { $cb = [$object, $cb]; $cb(); } } if (isset($this->on['beforeInsert'])) { foreach ($this->on['beforeInsert'] as $cb) { $cb($object, $meta); } } } query: { $query->values = $this->mapper->mapObjectToRow($object, $meta, 'insert'); if (!$query->table) { $query->table = $meta->table; } list ($sql, $params, $props) = $query->buildQuery($meta); $stmt = $this->getConnector()->prepare($sql); $stmt->execute($params); } $lastInsertId = null; // we need to be careful with "lastInsertId": SQLite generates one even without a PRIMARY if ($object && $meta->primary) { $lastInsertId = $this->getConnector()->lastInsertId(); if ($lastInsertId && $meta->autoinc) { $field = $meta->fields[$meta->autoinc]; $handler = $this->mapper->determineTypeHandler(Mapper::AUTOINC_TYPE); if (!$handler) { throw new \UnexpectedValueException(); } $meta->setValue($object, $meta->autoinc, $lastInsertId); } } event_after: { if (isset($meta->on['afterInsert'])) { foreach ($meta->on['afterInsert'] as $cb) { $cb = [$object, $cb]; $cb(); } } if (isset($this->on['afterInsert'])) { foreach ($this->on['afterInsert'] as $cb) { $cb($object, $meta); } } } return $lastInsertId; }
[ "public", "function", "insert", "(", "$", "object", ",", "$", "meta", "=", "null", ")", "{", "$", "query", "=", "new", "Query", "\\", "Insert", ";", "if", "(", "is_array", "(", "$", "meta", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "\"Please use insertTable()\"", ")", ";", "}", "if", "(", "$", "meta", ")", "{", "$", "meta", "=", "!", "$", "meta", "instanceof", "Meta", "?", "$", "this", "->", "mapper", "->", "getMeta", "(", "$", "meta", ")", ":", "$", "meta", ";", "}", "else", "{", "$", "meta", "=", "$", "this", "->", "mapper", "->", "getMeta", "(", "get_class", "(", "$", "object", ")", ")", ";", "}", "if", "(", "!", "$", "meta", "->", "canInsert", ")", "{", "throw", "new", "Exception", "(", "\"Meta {$meta->id} prohibits insert\"", ")", ";", "}", "event_before", ":", "{", "if", "(", "isset", "(", "$", "meta", "->", "on", "[", "'beforeInsert'", "]", ")", ")", "{", "foreach", "(", "$", "meta", "->", "on", "[", "'beforeInsert'", "]", "as", "$", "cb", ")", "{", "$", "cb", "=", "[", "$", "object", ",", "$", "cb", "]", ";", "$", "cb", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "on", "[", "'beforeInsert'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "on", "[", "'beforeInsert'", "]", "as", "$", "cb", ")", "{", "$", "cb", "(", "$", "object", ",", "$", "meta", ")", ";", "}", "}", "}", "query", ":", "{", "$", "query", "->", "values", "=", "$", "this", "->", "mapper", "->", "mapObjectToRow", "(", "$", "object", ",", "$", "meta", ",", "'insert'", ")", ";", "if", "(", "!", "$", "query", "->", "table", ")", "{", "$", "query", "->", "table", "=", "$", "meta", "->", "table", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ",", "$", "props", ")", "=", "$", "query", "->", "buildQuery", "(", "$", "meta", ")", ";", "$", "stmt", "=", "$", "this", "->", "getConnector", "(", ")", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "}", "$", "lastInsertId", "=", "null", ";", "// we need to be careful with \"lastInsertId\": SQLite generates one even without a PRIMARY", "if", "(", "$", "object", "&&", "$", "meta", "->", "primary", ")", "{", "$", "lastInsertId", "=", "$", "this", "->", "getConnector", "(", ")", "->", "lastInsertId", "(", ")", ";", "if", "(", "$", "lastInsertId", "&&", "$", "meta", "->", "autoinc", ")", "{", "$", "field", "=", "$", "meta", "->", "fields", "[", "$", "meta", "->", "autoinc", "]", ";", "$", "handler", "=", "$", "this", "->", "mapper", "->", "determineTypeHandler", "(", "Mapper", "::", "AUTOINC_TYPE", ")", ";", "if", "(", "!", "$", "handler", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", ")", ";", "}", "$", "meta", "->", "setValue", "(", "$", "object", ",", "$", "meta", "->", "autoinc", ",", "$", "lastInsertId", ")", ";", "}", "}", "event_after", ":", "{", "if", "(", "isset", "(", "$", "meta", "->", "on", "[", "'afterInsert'", "]", ")", ")", "{", "foreach", "(", "$", "meta", "->", "on", "[", "'afterInsert'", "]", "as", "$", "cb", ")", "{", "$", "cb", "=", "[", "$", "object", ",", "$", "cb", "]", ";", "$", "cb", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "on", "[", "'afterInsert'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "on", "[", "'afterInsert'", "]", "as", "$", "cb", ")", "{", "$", "cb", "(", "$", "object", ",", "$", "meta", ")", ";", "}", "}", "}", "return", "$", "lastInsertId", ";", "}" ]
Insert an object into the database, or values into a table insert($object) insert($object, Meta $meta) @return int|null
[ "Insert", "an", "object", "into", "the", "database", "or", "values", "into", "a", "table" ]
train
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L571-L634