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
Nicklas766/Comment
src/Comment/HTMLForm/User/UserLoginForm.php
UserLoginForm.callbackSubmit
public function callbackSubmit() { // Get values from the submitted form $name = $this->form->value("user"); $password = $this->form->value("password"); $user = new User(); $user->setDb($this->di->get("db")); $res = $user->verifyPassword($name, $password); if (!$res) { $this->form->rememberValues(); $this->form->addOutput("User or password did not match."); return false; } $this->di->get('session')->set("user", $name); # set user in session $this->di->get("response")->redirect("user/profile"); }
php
public function callbackSubmit() { // Get values from the submitted form $name = $this->form->value("user"); $password = $this->form->value("password"); $user = new User(); $user->setDb($this->di->get("db")); $res = $user->verifyPassword($name, $password); if (!$res) { $this->form->rememberValues(); $this->form->addOutput("User or password did not match."); return false; } $this->di->get('session')->set("user", $name); # set user in session $this->di->get("response")->redirect("user/profile"); }
[ "public", "function", "callbackSubmit", "(", ")", "{", "// Get values from the submitted form", "$", "name", "=", "$", "this", "->", "form", "->", "value", "(", "\"user\"", ")", ";", "$", "password", "=", "$", "this", "->", "form", "->", "value", "(", "\"password\"", ")", ";", "$", "user", "=", "new", "User", "(", ")", ";", "$", "user", "->", "setDb", "(", "$", "this", "->", "di", "->", "get", "(", "\"db\"", ")", ")", ";", "$", "res", "=", "$", "user", "->", "verifyPassword", "(", "$", "name", ",", "$", "password", ")", ";", "if", "(", "!", "$", "res", ")", "{", "$", "this", "->", "form", "->", "rememberValues", "(", ")", ";", "$", "this", "->", "form", "->", "addOutput", "(", "\"User or password did not match.\"", ")", ";", "return", "false", ";", "}", "$", "this", "->", "di", "->", "get", "(", "'session'", ")", "->", "set", "(", "\"user\"", ",", "$", "name", ")", ";", "# set user in session", "$", "this", "->", "di", "->", "get", "(", "\"response\"", ")", "->", "redirect", "(", "\"user/profile\"", ")", ";", "}" ]
Callback for submit-button which should return true if it could carry out its work and false if something failed. @return boolean true if okey, false if something went wrong.
[ "Callback", "for", "submit", "-", "button", "which", "should", "return", "true", "if", "it", "could", "carry", "out", "its", "work", "and", "false", "if", "something", "failed", "." ]
train
https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/HTMLForm/User/UserLoginForm.php#L63-L81
CampaignChain/security-authentication-client-oauth
Entity/Token.php
Token.setApplication
public function setApplication(\CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Application $application = null) { $this->application = $application; return $this; }
php
public function setApplication(\CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Application $application = null) { $this->application = $application; return $this; }
[ "public", "function", "setApplication", "(", "\\", "CampaignChain", "\\", "Security", "\\", "Authentication", "\\", "Client", "\\", "OAuthBundle", "\\", "Entity", "\\", "Application", "$", "application", "=", "null", ")", "{", "$", "this", "->", "application", "=", "$", "application", ";", "return", "$", "this", ";", "}" ]
Set application @param \CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Application $application @return Token
[ "Set", "application" ]
train
https://github.com/CampaignChain/security-authentication-client-oauth/blob/06800ccd0ee6b5ca9f53b85146228467ff6a7529/Entity/Token.php#L218-L223
CampaignChain/security-authentication-client-oauth
Entity/Token.php
Token.setLocation
public function setLocation(\CampaignChain\CoreBundle\Entity\Location $location = null) { $this->location = $location; return $this; }
php
public function setLocation(\CampaignChain\CoreBundle\Entity\Location $location = null) { $this->location = $location; return $this; }
[ "public", "function", "setLocation", "(", "\\", "CampaignChain", "\\", "CoreBundle", "\\", "Entity", "\\", "Location", "$", "location", "=", "null", ")", "{", "$", "this", "->", "location", "=", "$", "location", ";", "return", "$", "this", ";", "}" ]
Set location @param \CampaignChain\CoreBundle\Entity\Location $location @return Token
[ "Set", "location" ]
train
https://github.com/CampaignChain/security-authentication-client-oauth/blob/06800ccd0ee6b5ca9f53b85146228467ff6a7529/Entity/Token.php#L264-L269
CrunchPHP/fastcgi
src/Protocol/Record.php
Record.encode
public function encode() { return $this->header->encode() . $this->getContent() . \str_repeat("\0", $this->header->getPaddingLength()); }
php
public function encode() { return $this->header->encode() . $this->getContent() . \str_repeat("\0", $this->header->getPaddingLength()); }
[ "public", "function", "encode", "(", ")", "{", "return", "$", "this", "->", "header", "->", "encode", "(", ")", ".", "$", "this", "->", "getContent", "(", ")", ".", "\\", "str_repeat", "(", "\"\\0\"", ",", "$", "this", "->", "header", "->", "getPaddingLength", "(", ")", ")", ";", "}" ]
Compiles record into struct to send. @return string
[ "Compiles", "record", "into", "struct", "to", "send", "." ]
train
https://github.com/CrunchPHP/fastcgi/blob/102437193e67e5a841ec5a897549ec345788d1bd/src/Protocol/Record.php#L59-L62
horntell/php-sdk
lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php
MultiAdapter.throwMultiError
public static function throwMultiError($code) { $buffer = function_exists('curl_multi_strerror') ? curl_multi_strerror($code) : self::ERROR_STR; throw new AdapterException(sprintf('cURL error %s: %s', $code, $buffer)); }
php
public static function throwMultiError($code) { $buffer = function_exists('curl_multi_strerror') ? curl_multi_strerror($code) : self::ERROR_STR; throw new AdapterException(sprintf('cURL error %s: %s', $code, $buffer)); }
[ "public", "static", "function", "throwMultiError", "(", "$", "code", ")", "{", "$", "buffer", "=", "function_exists", "(", "'curl_multi_strerror'", ")", "?", "curl_multi_strerror", "(", "$", "code", ")", ":", "self", "::", "ERROR_STR", ";", "throw", "new", "AdapterException", "(", "sprintf", "(", "'cURL error %s: %s'", ",", "$", "code", ",", "$", "buffer", ")", ")", ";", "}" ]
Throw an exception for a cURL multi response @param int $code Curl response code @throws AdapterException
[ "Throw", "an", "exception", "for", "a", "cURL", "multi", "response" ]
train
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php#L98-L105
horntell/php-sdk
lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php
MultiAdapter.checkoutMultiHandle
private function checkoutMultiHandle() { // Find an unused handle in the cache $key = array_search(false, $this->multiOwned, true); if (false !== $key) { $this->multiOwned[$key] = true; return $this->multiHandles[$key]; } // Add a new handle $handle = curl_multi_init(); $id = (int) $handle; $this->multiHandles[$id] = $handle; $this->multiOwned[$id] = true; return $handle; }
php
private function checkoutMultiHandle() { // Find an unused handle in the cache $key = array_search(false, $this->multiOwned, true); if (false !== $key) { $this->multiOwned[$key] = true; return $this->multiHandles[$key]; } // Add a new handle $handle = curl_multi_init(); $id = (int) $handle; $this->multiHandles[$id] = $handle; $this->multiOwned[$id] = true; return $handle; }
[ "private", "function", "checkoutMultiHandle", "(", ")", "{", "// Find an unused handle in the cache", "$", "key", "=", "array_search", "(", "false", ",", "$", "this", "->", "multiOwned", ",", "true", ")", ";", "if", "(", "false", "!==", "$", "key", ")", "{", "$", "this", "->", "multiOwned", "[", "$", "key", "]", "=", "true", ";", "return", "$", "this", "->", "multiHandles", "[", "$", "key", "]", ";", "}", "// Add a new handle", "$", "handle", "=", "curl_multi_init", "(", ")", ";", "$", "id", "=", "(", "int", ")", "$", "handle", ";", "$", "this", "->", "multiHandles", "[", "$", "id", "]", "=", "$", "handle", ";", "$", "this", "->", "multiOwned", "[", "$", "id", "]", "=", "true", ";", "return", "$", "handle", ";", "}" ]
Returns a curl_multi handle from the cache or creates a new one @return resource
[ "Returns", "a", "curl_multi", "handle", "from", "the", "cache", "or", "creates", "a", "new", "one" ]
train
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php#L270-L286
horntell/php-sdk
lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php
MultiAdapter.releaseMultiHandle
private function releaseMultiHandle($handle, $maxHandles) { $id = (int) $handle; if (count($this->multiHandles) <= $maxHandles) { $this->multiOwned[$id] = false; } elseif (isset($this->multiHandles[$id], $this->multiOwned[$id])) { // Prune excessive handles curl_multi_close($this->multiHandles[$id]); unset($this->multiHandles[$id], $this->multiOwned[$id]); } }
php
private function releaseMultiHandle($handle, $maxHandles) { $id = (int) $handle; if (count($this->multiHandles) <= $maxHandles) { $this->multiOwned[$id] = false; } elseif (isset($this->multiHandles[$id], $this->multiOwned[$id])) { // Prune excessive handles curl_multi_close($this->multiHandles[$id]); unset($this->multiHandles[$id], $this->multiOwned[$id]); } }
[ "private", "function", "releaseMultiHandle", "(", "$", "handle", ",", "$", "maxHandles", ")", "{", "$", "id", "=", "(", "int", ")", "$", "handle", ";", "if", "(", "count", "(", "$", "this", "->", "multiHandles", ")", "<=", "$", "maxHandles", ")", "{", "$", "this", "->", "multiOwned", "[", "$", "id", "]", "=", "false", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "multiHandles", "[", "$", "id", "]", ",", "$", "this", "->", "multiOwned", "[", "$", "id", "]", ")", ")", "{", "// Prune excessive handles", "curl_multi_close", "(", "$", "this", "->", "multiHandles", "[", "$", "id", "]", ")", ";", "unset", "(", "$", "this", "->", "multiHandles", "[", "$", "id", "]", ",", "$", "this", "->", "multiOwned", "[", "$", "id", "]", ")", ";", "}", "}" ]
Releases a curl_multi handle back into the cache and removes excess cache @param resource $handle Curl multi handle to remove @param int $maxHandles (Optional) Maximum number of existing multiHandles to allow before pruning.
[ "Releases", "a", "curl_multi", "handle", "back", "into", "the", "cache", "and", "removes", "excess", "cache" ]
train
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php#L294-L305
horntell/php-sdk
lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php
MultiAdapter.validateResponseWasSet
private function validateResponseWasSet( TransactionInterface $transaction, BatchContext $context ) { if ($transaction->getResponse()) { return true; } $body = $transaction->getRequest()->getBody(); if (!$body) { // This is weird and should probably never happen. RequestEvents::emitError( $transaction, new RequestException( 'No response was received for a request with no body. This' . ' could mean that you are saturating your network.', $transaction->getRequest() ) ); } elseif (!$body->isSeekable() || !$body->seek(0)) { // Nothing we can do with this. Sorry! RequestEvents::emitError( $transaction, new RequestException( 'The connection was unexpectedly closed. The request would' . ' have been retried, but attempting to rewind the' . ' request body failed. Consider wrapping your request' . ' body in a CachingStream decorator to work around this' . ' issue if necessary.', $transaction->getRequest() ) ); } else { $this->retryFailedConnection($transaction, $context); } return false; }
php
private function validateResponseWasSet( TransactionInterface $transaction, BatchContext $context ) { if ($transaction->getResponse()) { return true; } $body = $transaction->getRequest()->getBody(); if (!$body) { // This is weird and should probably never happen. RequestEvents::emitError( $transaction, new RequestException( 'No response was received for a request with no body. This' . ' could mean that you are saturating your network.', $transaction->getRequest() ) ); } elseif (!$body->isSeekable() || !$body->seek(0)) { // Nothing we can do with this. Sorry! RequestEvents::emitError( $transaction, new RequestException( 'The connection was unexpectedly closed. The request would' . ' have been retried, but attempting to rewind the' . ' request body failed. Consider wrapping your request' . ' body in a CachingStream decorator to work around this' . ' issue if necessary.', $transaction->getRequest() ) ); } else { $this->retryFailedConnection($transaction, $context); } return false; }
[ "private", "function", "validateResponseWasSet", "(", "TransactionInterface", "$", "transaction", ",", "BatchContext", "$", "context", ")", "{", "if", "(", "$", "transaction", "->", "getResponse", "(", ")", ")", "{", "return", "true", ";", "}", "$", "body", "=", "$", "transaction", "->", "getRequest", "(", ")", "->", "getBody", "(", ")", ";", "if", "(", "!", "$", "body", ")", "{", "// This is weird and should probably never happen.", "RequestEvents", "::", "emitError", "(", "$", "transaction", ",", "new", "RequestException", "(", "'No response was received for a request with no body. This'", ".", "' could mean that you are saturating your network.'", ",", "$", "transaction", "->", "getRequest", "(", ")", ")", ")", ";", "}", "elseif", "(", "!", "$", "body", "->", "isSeekable", "(", ")", "||", "!", "$", "body", "->", "seek", "(", "0", ")", ")", "{", "// Nothing we can do with this. Sorry!", "RequestEvents", "::", "emitError", "(", "$", "transaction", ",", "new", "RequestException", "(", "'The connection was unexpectedly closed. The request would'", ".", "' have been retried, but attempting to rewind the'", ".", "' request body failed. Consider wrapping your request'", ".", "' body in a CachingStream decorator to work around this'", ".", "' issue if necessary.'", ",", "$", "transaction", "->", "getRequest", "(", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "retryFailedConnection", "(", "$", "transaction", ",", "$", "context", ")", ";", "}", "return", "false", ";", "}" ]
This function ensures that a response was set on a transaction. If one was not set, then the request is retried if possible. This error typically means you are sending a payload, curl encountered a "Connection died, retrying a fresh connect" error, tried to rewind the stream, and then encountered a "necessary data rewind wasn't possible" error, causing the request to be sent through curl_multi_info_read() without an error status. @param TransactionInterface $transaction @param BatchContext $context @return bool Returns true if it's OK, and false if it failed. @throws \GuzzleHttp\Exception\RequestException If it failed and cannot recover.
[ "This", "function", "ensures", "that", "a", "response", "was", "set", "on", "a", "transaction", ".", "If", "one", "was", "not", "set", "then", "the", "request", "is", "retried", "if", "possible", ".", "This", "error", "typically", "means", "you", "are", "sending", "a", "payload", "curl", "encountered", "a", "Connection", "died", "retrying", "a", "fresh", "connect", "error", "tried", "to", "rewind", "the", "stream", "and", "then", "encountered", "a", "necessary", "data", "rewind", "wasn", "t", "possible", "error", "causing", "the", "request", "to", "be", "sent", "through", "curl_multi_info_read", "()", "without", "an", "error", "status", "." ]
train
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/MultiAdapter.php#L323-L361
Vectrex/vxPHP
src/Http/AcceptHeader.php
AcceptHeader.get
public function get($value) { return isset($this->items[$value]) ? $this->items[$value] : NULL; }
php
public function get($value) { return isset($this->items[$value]) ? $this->items[$value] : NULL; }
[ "public", "function", "get", "(", "$", "value", ")", "{", "return", "isset", "(", "$", "this", "->", "items", "[", "$", "value", "]", ")", "?", "$", "this", "->", "items", "[", "$", "value", "]", ":", "NULL", ";", "}" ]
Returns given value's item, if exists. @param string $value @return AcceptHeaderItem|NULL
[ "Returns", "given", "value", "s", "item", "if", "exists", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/AcceptHeader.php#L108-L112
Vectrex/vxPHP
src/Http/AcceptHeader.php
AcceptHeader.add
public function add(AcceptHeaderItem $item) { $this->items[$item->getValue()] = $item; $this->sorted = FALSE; return $this; }
php
public function add(AcceptHeaderItem $item) { $this->items[$item->getValue()] = $item; $this->sorted = FALSE; return $this; }
[ "public", "function", "add", "(", "AcceptHeaderItem", "$", "item", ")", "{", "$", "this", "->", "items", "[", "$", "item", "->", "getValue", "(", ")", "]", "=", "$", "item", ";", "$", "this", "->", "sorted", "=", "FALSE", ";", "return", "$", "this", ";", "}" ]
Adds an item. @param AcceptHeaderItem $item @return AcceptHeader
[ "Adds", "an", "item", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/AcceptHeader.php#L121-L128
Vectrex/vxPHP
src/Http/AcceptHeader.php
AcceptHeader.first
public function first() { $this->sort(); return !empty($this->items) ? reset($this->items) : NULL; }
php
public function first() { $this->sort(); return !empty($this->items) ? reset($this->items) : NULL; }
[ "public", "function", "first", "(", ")", "{", "$", "this", "->", "sort", "(", ")", ";", "return", "!", "empty", "(", "$", "this", "->", "items", ")", "?", "reset", "(", "$", "this", "->", "items", ")", ":", "NULL", ";", "}" ]
Returns first item. @return AcceptHeaderItem|NULL
[ "Returns", "first", "item", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/AcceptHeader.php#L162-L168
DeimosProject/Helper
src/Helper/Helpers/Json.php
Json.options
protected function options($target) { $options = JSON_ERROR_NONE; if (isset($this->options[$target])) { foreach ($this->options[$target] as $option) { $options |= $option; } } return $options; }
php
protected function options($target) { $options = JSON_ERROR_NONE; if (isset($this->options[$target])) { foreach ($this->options[$target] as $option) { $options |= $option; } } return $options; }
[ "protected", "function", "options", "(", "$", "target", ")", "{", "$", "options", "=", "JSON_ERROR_NONE", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "target", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "options", "[", "$", "target", "]", "as", "$", "option", ")", "{", "$", "options", "|=", "$", "option", ";", "}", "}", "return", "$", "options", ";", "}" ]
@param int $target @return int
[ "@param", "int", "$target" ]
train
https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Helpers/Json.php#L70-L83
cmsgears/module-sns-connect
common/services/base/SnsProfileService.php
SnsProfileService.update
public function update( $model, $config = [] ) { $snsUser = $config[ 'snsUser' ]; $accessToken = $config[ 'accessToken' ]; // Copy Attributes $model->token = $accessToken; $model->data = json_encode( $snsUser ); // Return updated SnsProfile return parent::update( $model, [ 'attributes' => [ 'token', 'data' ] ]); }
php
public function update( $model, $config = [] ) { $snsUser = $config[ 'snsUser' ]; $accessToken = $config[ 'accessToken' ]; // Copy Attributes $model->token = $accessToken; $model->data = json_encode( $snsUser ); // Return updated SnsProfile return parent::update( $model, [ 'attributes' => [ 'token', 'data' ] ]); }
[ "public", "function", "update", "(", "$", "model", ",", "$", "config", "=", "[", "]", ")", "{", "$", "snsUser", "=", "$", "config", "[", "'snsUser'", "]", ";", "$", "accessToken", "=", "$", "config", "[", "'accessToken'", "]", ";", "// Copy Attributes", "$", "model", "->", "token", "=", "$", "accessToken", ";", "$", "model", "->", "data", "=", "json_encode", "(", "$", "snsUser", ")", ";", "// Return updated SnsProfile", "return", "parent", "::", "update", "(", "$", "model", ",", "[", "'attributes'", "=>", "[", "'token'", ",", "'data'", "]", "]", ")", ";", "}" ]
Update -------------
[ "Update", "-------------" ]
train
https://github.com/cmsgears/module-sns-connect/blob/753ee4157d41c81a701689624f4c44760a6cada3/common/services/base/SnsProfileService.php#L97-L110
fulgurio/LightCMSBundle
Form/Handler/AdminMediaHandler.php
AdminMediaHandler.process
public function process(Media $media) { if ($this->request->getMethod() == 'POST') { $this->form->handleRequest($this->request); if ($this->form->isValid()) { $file = $this->form->get('media')->getData(); if (!is_null($file)) { $media->setMediaType($file->getMimeType()); $media->setOriginalName($file->getClientOriginalName()); $filename = $this->mediaLibraryService->add($file, $media); if ($filename) { // New media if ($media->getId() == 0) { if (is_a($this->user, 'Symfony\Component\Security\Core\User\UserInterface') && method_exists($this->user, 'getId')) { $media->setOwnerId($this->user->getId()); } } else { // We remove old files $this->mediaLibraryService->remove($media); } // We set new file $media->setFullPath($filename); $em = $this->doctrine->getManager(); $em->persist($media); $em->flush(); return TRUE; } } } } return FALSE; }
php
public function process(Media $media) { if ($this->request->getMethod() == 'POST') { $this->form->handleRequest($this->request); if ($this->form->isValid()) { $file = $this->form->get('media')->getData(); if (!is_null($file)) { $media->setMediaType($file->getMimeType()); $media->setOriginalName($file->getClientOriginalName()); $filename = $this->mediaLibraryService->add($file, $media); if ($filename) { // New media if ($media->getId() == 0) { if (is_a($this->user, 'Symfony\Component\Security\Core\User\UserInterface') && method_exists($this->user, 'getId')) { $media->setOwnerId($this->user->getId()); } } else { // We remove old files $this->mediaLibraryService->remove($media); } // We set new file $media->setFullPath($filename); $em = $this->doctrine->getManager(); $em->persist($media); $em->flush(); return TRUE; } } } } return FALSE; }
[ "public", "function", "process", "(", "Media", "$", "media", ")", "{", "if", "(", "$", "this", "->", "request", "->", "getMethod", "(", ")", "==", "'POST'", ")", "{", "$", "this", "->", "form", "->", "handleRequest", "(", "$", "this", "->", "request", ")", ";", "if", "(", "$", "this", "->", "form", "->", "isValid", "(", ")", ")", "{", "$", "file", "=", "$", "this", "->", "form", "->", "get", "(", "'media'", ")", "->", "getData", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "file", ")", ")", "{", "$", "media", "->", "setMediaType", "(", "$", "file", "->", "getMimeType", "(", ")", ")", ";", "$", "media", "->", "setOriginalName", "(", "$", "file", "->", "getClientOriginalName", "(", ")", ")", ";", "$", "filename", "=", "$", "this", "->", "mediaLibraryService", "->", "add", "(", "$", "file", ",", "$", "media", ")", ";", "if", "(", "$", "filename", ")", "{", "// New media", "if", "(", "$", "media", "->", "getId", "(", ")", "==", "0", ")", "{", "if", "(", "is_a", "(", "$", "this", "->", "user", ",", "'Symfony\\Component\\Security\\Core\\User\\UserInterface'", ")", "&&", "method_exists", "(", "$", "this", "->", "user", ",", "'getId'", ")", ")", "{", "$", "media", "->", "setOwnerId", "(", "$", "this", "->", "user", "->", "getId", "(", ")", ")", ";", "}", "}", "else", "{", "// We remove old files", "$", "this", "->", "mediaLibraryService", "->", "remove", "(", "$", "media", ")", ";", "}", "// We set new file", "$", "media", "->", "setFullPath", "(", "$", "filename", ")", ";", "$", "em", "=", "$", "this", "->", "doctrine", "->", "getManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "media", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "return", "TRUE", ";", "}", "}", "}", "}", "return", "FALSE", ";", "}" ]
Processing form values @param Media $media @return boolean
[ "Processing", "form", "values" ]
train
https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Form/Handler/AdminMediaHandler.php#L25-L67
Wedeto/FileFormats
src/AbstractReader.php
AbstractReader.read
public function read($param) { if ($param instanceof File) return $this->readFile($param->getFullPath()); if (is_resource($param)) return $this->readFileHandle($param); if (!is_string($param)) throw new \InvalidArgumentException("Cannot read argument: " . WF::str($param)); if (strlen($param) < 1024 && file_exists($param)) return $this->readFile($param); return $this->readString($param); }
php
public function read($param) { if ($param instanceof File) return $this->readFile($param->getFullPath()); if (is_resource($param)) return $this->readFileHandle($param); if (!is_string($param)) throw new \InvalidArgumentException("Cannot read argument: " . WF::str($param)); if (strlen($param) < 1024 && file_exists($param)) return $this->readFile($param); return $this->readString($param); }
[ "public", "function", "read", "(", "$", "param", ")", "{", "if", "(", "$", "param", "instanceof", "File", ")", "return", "$", "this", "->", "readFile", "(", "$", "param", "->", "getFullPath", "(", ")", ")", ";", "if", "(", "is_resource", "(", "$", "param", ")", ")", "return", "$", "this", "->", "readFileHandle", "(", "$", "param", ")", ";", "if", "(", "!", "is_string", "(", "$", "param", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Cannot read argument: \"", ".", "WF", "::", "str", "(", "$", "param", ")", ")", ";", "if", "(", "strlen", "(", "$", "param", ")", "<", "1024", "&&", "file_exists", "(", "$", "param", ")", ")", "return", "$", "this", "->", "readFile", "(", "$", "param", ")", ";", "return", "$", "this", "->", "readString", "(", "$", "param", ")", ";", "}" ]
Read provided data. The method auto-detects if it is a file, a resource or a string that contains the formatted data. @param mixed $param The data to read @return array The read data @throws InvalidArgumentException When an unrecognized argument is provided @throws Wedeto\IO\IOException When reading fails
[ "Read", "provided", "data", ".", "The", "method", "auto", "-", "detects", "if", "it", "is", "a", "file", "a", "resource", "or", "a", "string", "that", "contains", "the", "formatted", "data", "." ]
train
https://github.com/Wedeto/FileFormats/blob/65b71fbd38a2ee6b504622aca4f4047ce9d31e9f/src/AbstractReader.php#L52-L67
Wedeto/FileFormats
src/AbstractReader.php
AbstractReader.readFile
public function readFile(string $file_name) { $contents = @file_get_contents($file_name); if ($contents === false) throw new IOException("Failed to read file contents"); $contents = Encoding::removeBOM($contents); return $this->readString(file_get_contents($file_name)); }
php
public function readFile(string $file_name) { $contents = @file_get_contents($file_name); if ($contents === false) throw new IOException("Failed to read file contents"); $contents = Encoding::removeBOM($contents); return $this->readString(file_get_contents($file_name)); }
[ "public", "function", "readFile", "(", "string", "$", "file_name", ")", "{", "$", "contents", "=", "@", "file_get_contents", "(", "$", "file_name", ")", ";", "if", "(", "$", "contents", "===", "false", ")", "throw", "new", "IOException", "(", "\"Failed to read file contents\"", ")", ";", "$", "contents", "=", "Encoding", "::", "removeBOM", "(", "$", "contents", ")", ";", "return", "$", "this", "->", "readString", "(", "file_get_contents", "(", "$", "file_name", ")", ")", ";", "}" ]
Read data from a file @param string $file_name The file to read @return array The read data @throws Wedeto\IO\IOException On read errors
[ "Read", "data", "from", "a", "file" ]
train
https://github.com/Wedeto/FileFormats/blob/65b71fbd38a2ee6b504622aca4f4047ce9d31e9f/src/AbstractReader.php#L75-L83
Wedeto/FileFormats
src/AbstractReader.php
AbstractReader.readFileHandle
public function readFileHandle($file_handle) { if (!is_resource($file_handle)) throw new \InvalidArgumentException("No file handle was provided"); $contents = stream_get_contents($file_handle); $contents = Encoding::removeBOM($contents); return $this->readString($contents); }
php
public function readFileHandle($file_handle) { if (!is_resource($file_handle)) throw new \InvalidArgumentException("No file handle was provided"); $contents = stream_get_contents($file_handle); $contents = Encoding::removeBOM($contents); return $this->readString($contents); }
[ "public", "function", "readFileHandle", "(", "$", "file_handle", ")", "{", "if", "(", "!", "is_resource", "(", "$", "file_handle", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"No file handle was provided\"", ")", ";", "$", "contents", "=", "stream_get_contents", "(", "$", "file_handle", ")", ";", "$", "contents", "=", "Encoding", "::", "removeBOM", "(", "$", "contents", ")", ";", "return", "$", "this", "->", "readString", "(", "$", "contents", ")", ";", "}" ]
Read from a file handle to an open file or resource @param resource $file_handle The resource to read @throws Wedeto\IO\IOException On read errors
[ "Read", "from", "a", "file", "handle", "to", "an", "open", "file", "or", "resource" ]
train
https://github.com/Wedeto/FileFormats/blob/65b71fbd38a2ee6b504622aca4f4047ce9d31e9f/src/AbstractReader.php#L90-L99
dms-org/common.structure
src/Table/TableData.php
TableData.hasColumn
public function hasColumn($columnKey) : bool { $this->validateColumnKey(__METHOD__, $columnKey); $this->loadColumns(); $columnHash = ValueHasher::hash($columnKey); return isset($this->columns[$columnHash]); }
php
public function hasColumn($columnKey) : bool { $this->validateColumnKey(__METHOD__, $columnKey); $this->loadColumns(); $columnHash = ValueHasher::hash($columnKey); return isset($this->columns[$columnHash]); }
[ "public", "function", "hasColumn", "(", "$", "columnKey", ")", ":", "bool", "{", "$", "this", "->", "validateColumnKey", "(", "__METHOD__", ",", "$", "columnKey", ")", ";", "$", "this", "->", "loadColumns", "(", ")", ";", "$", "columnHash", "=", "ValueHasher", "::", "hash", "(", "$", "columnKey", ")", ";", "return", "isset", "(", "$", "this", "->", "columns", "[", "$", "columnHash", "]", ")", ";", "}" ]
Returns whether the table data contains a column with the supplied key. @param mixed $columnKey @return bool @throws TypeMismatchException
[ "Returns", "whether", "the", "table", "data", "contains", "a", "column", "with", "the", "supplied", "key", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L230-L238
dms-org/common.structure
src/Table/TableData.php
TableData.getColumn
public function getColumn($columnKey) : TableDataColumn { $this->validateColumnKey(__METHOD__, $columnKey); $this->loadColumns(); $columnHash = ValueHasher::hash($columnKey); if (!isset($this->columns[$columnHash])) { throw InvalidArgumentException::format( 'Invalid column key supplied to %s: expecting one of hashes (%s), value with \'%s\' hash given', __METHOD__, Debug::formatValues(array_keys($this->columns)), $columnHash ); } return $this->columns[$columnHash]; }
php
public function getColumn($columnKey) : TableDataColumn { $this->validateColumnKey(__METHOD__, $columnKey); $this->loadColumns(); $columnHash = ValueHasher::hash($columnKey); if (!isset($this->columns[$columnHash])) { throw InvalidArgumentException::format( 'Invalid column key supplied to %s: expecting one of hashes (%s), value with \'%s\' hash given', __METHOD__, Debug::formatValues(array_keys($this->columns)), $columnHash ); } return $this->columns[$columnHash]; }
[ "public", "function", "getColumn", "(", "$", "columnKey", ")", ":", "TableDataColumn", "{", "$", "this", "->", "validateColumnKey", "(", "__METHOD__", ",", "$", "columnKey", ")", ";", "$", "this", "->", "loadColumns", "(", ")", ";", "$", "columnHash", "=", "ValueHasher", "::", "hash", "(", "$", "columnKey", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "columns", "[", "$", "columnHash", "]", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Invalid column key supplied to %s: expecting one of hashes (%s), value with \\'%s\\' hash given'", ",", "__METHOD__", ",", "Debug", "::", "formatValues", "(", "array_keys", "(", "$", "this", "->", "columns", ")", ")", ",", "$", "columnHash", ")", ";", "}", "return", "$", "this", "->", "columns", "[", "$", "columnHash", "]", ";", "}" ]
Gets the table column with the supplied key. @param mixed $columnKey @return TableDataColumn @throws InvalidArgumentException @throws TypeMismatchException
[ "Gets", "the", "table", "column", "with", "the", "supplied", "key", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L249-L264
dms-org/common.structure
src/Table/TableData.php
TableData.hasRow
public function hasRow($rowKey) : bool { $this->validateRowKey(__METHOD__, $rowKey); $this->loadRows(); $rowHash = ValueHasher::hash($rowKey); return isset($this->rows[$rowHash]); }
php
public function hasRow($rowKey) : bool { $this->validateRowKey(__METHOD__, $rowKey); $this->loadRows(); $rowHash = ValueHasher::hash($rowKey); return isset($this->rows[$rowHash]); }
[ "public", "function", "hasRow", "(", "$", "rowKey", ")", ":", "bool", "{", "$", "this", "->", "validateRowKey", "(", "__METHOD__", ",", "$", "rowKey", ")", ";", "$", "this", "->", "loadRows", "(", ")", ";", "$", "rowHash", "=", "ValueHasher", "::", "hash", "(", "$", "rowKey", ")", ";", "return", "isset", "(", "$", "this", "->", "rows", "[", "$", "rowHash", "]", ")", ";", "}" ]
Returns whether the table data contains a row with the supplied key. @param mixed $rowKey @return bool @throws TypeMismatchException
[ "Returns", "whether", "the", "table", "data", "contains", "a", "row", "with", "the", "supplied", "key", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L274-L282
dms-org/common.structure
src/Table/TableData.php
TableData.getRow
public function getRow($rowKey) : TableDataRow { $this->validateRowKey(__METHOD__, $rowKey); $this->loadRows(); $rowHash = ValueHasher::hash($rowKey); if (!isset($this->rows[$rowHash])) { throw InvalidArgumentException::format( 'Invalid row key supplied to %s: expecting one of hashes (%s), value with \'%s\' hash given', __METHOD__, Debug::formatValues(array_keys($this->rows)), $rowHash ); } return $this->rows[$rowHash]; }
php
public function getRow($rowKey) : TableDataRow { $this->validateRowKey(__METHOD__, $rowKey); $this->loadRows(); $rowHash = ValueHasher::hash($rowKey); if (!isset($this->rows[$rowHash])) { throw InvalidArgumentException::format( 'Invalid row key supplied to %s: expecting one of hashes (%s), value with \'%s\' hash given', __METHOD__, Debug::formatValues(array_keys($this->rows)), $rowHash ); } return $this->rows[$rowHash]; }
[ "public", "function", "getRow", "(", "$", "rowKey", ")", ":", "TableDataRow", "{", "$", "this", "->", "validateRowKey", "(", "__METHOD__", ",", "$", "rowKey", ")", ";", "$", "this", "->", "loadRows", "(", ")", ";", "$", "rowHash", "=", "ValueHasher", "::", "hash", "(", "$", "rowKey", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "rows", "[", "$", "rowHash", "]", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Invalid row key supplied to %s: expecting one of hashes (%s), value with \\'%s\\' hash given'", ",", "__METHOD__", ",", "Debug", "::", "formatValues", "(", "array_keys", "(", "$", "this", "->", "rows", ")", ")", ",", "$", "rowHash", ")", ";", "}", "return", "$", "this", "->", "rows", "[", "$", "rowHash", "]", ";", "}" ]
Gets the table row with the supplied key. @param mixed $rowKey @return TableDataRow @throws InvalidArgumentException @throws TypeMismatchException
[ "Gets", "the", "table", "row", "with", "the", "supplied", "key", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L293-L308
dms-org/common.structure
src/Table/TableData.php
TableData.hasCell
public function hasCell($columnKey, $rowKey) : bool { $this->validateColumnKey(__METHOD__, $columnKey); $this->validateRowKey(__METHOD__, $rowKey); $this->loadColumns(); $this->loadRows(); $columnHash = ValueHasher::hash($columnKey); if (!isset($this->columns[$columnHash])) { return false; } $rowHash = ValueHasher::hash($rowKey); if (!isset($this->rows[$rowHash])) { return false; } return true; }
php
public function hasCell($columnKey, $rowKey) : bool { $this->validateColumnKey(__METHOD__, $columnKey); $this->validateRowKey(__METHOD__, $rowKey); $this->loadColumns(); $this->loadRows(); $columnHash = ValueHasher::hash($columnKey); if (!isset($this->columns[$columnHash])) { return false; } $rowHash = ValueHasher::hash($rowKey); if (!isset($this->rows[$rowHash])) { return false; } return true; }
[ "public", "function", "hasCell", "(", "$", "columnKey", ",", "$", "rowKey", ")", ":", "bool", "{", "$", "this", "->", "validateColumnKey", "(", "__METHOD__", ",", "$", "columnKey", ")", ";", "$", "this", "->", "validateRowKey", "(", "__METHOD__", ",", "$", "rowKey", ")", ";", "$", "this", "->", "loadColumns", "(", ")", ";", "$", "this", "->", "loadRows", "(", ")", ";", "$", "columnHash", "=", "ValueHasher", "::", "hash", "(", "$", "columnKey", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "columns", "[", "$", "columnHash", "]", ")", ")", "{", "return", "false", ";", "}", "$", "rowHash", "=", "ValueHasher", "::", "hash", "(", "$", "rowKey", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "rows", "[", "$", "rowHash", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Returns whether their is a cell value at the supplied row and column. @param mixed $columnKey @param mixed $rowKey @return bool @throws TypeMismatchException
[ "Returns", "whether", "their", "is", "a", "cell", "value", "at", "the", "supplied", "row", "and", "column", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L319-L338
dms-org/common.structure
src/Table/TableData.php
TableData.getCell
public function getCell($columnKey, $rowKey) { $column = $this->getColumn($columnKey); $row = $this->getRow($rowKey); return $row[$column]; }
php
public function getCell($columnKey, $rowKey) { $column = $this->getColumn($columnKey); $row = $this->getRow($rowKey); return $row[$column]; }
[ "public", "function", "getCell", "(", "$", "columnKey", ",", "$", "rowKey", ")", "{", "$", "column", "=", "$", "this", "->", "getColumn", "(", "$", "columnKey", ")", ";", "$", "row", "=", "$", "this", "->", "getRow", "(", "$", "rowKey", ")", ";", "return", "$", "row", "[", "$", "column", "]", ";", "}" ]
Gets the value of the cell or NULL if the cell does not exist. @param mixed $columnKey @param mixed $rowKey @return mixed @throws TypeMismatchException
[ "Gets", "the", "value", "of", "the", "cell", "or", "NULL", "if", "the", "cell", "does", "not", "exist", "." ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/TableData.php#L349-L355
Dhii/regex-abstract
src/GetAllMatchesRegexCapablePcreTrait.php
GetAllMatchesRegexCapablePcreTrait._getAllMatchesRegex
protected function _getAllMatchesRegex($pattern, $subject) { $matches = []; $pattern = $this->_normalizeString($pattern); $subject = $this->_normalizeString($subject); try { $result = @preg_match_all($pattern, $subject, $matches); } catch (RootException $e) { // This will happen if a custom error handler is set and throws exceptions for regex errors throw $this->_createRuntimeException($this->__($e->getMessage()), null, $e); } if ($result === false) { $errorCode = preg_last_error(); throw $this->_createRuntimeException($this->__('RegEx error code "%1$s"', [$errorCode])); } return $matches; }
php
protected function _getAllMatchesRegex($pattern, $subject) { $matches = []; $pattern = $this->_normalizeString($pattern); $subject = $this->_normalizeString($subject); try { $result = @preg_match_all($pattern, $subject, $matches); } catch (RootException $e) { // This will happen if a custom error handler is set and throws exceptions for regex errors throw $this->_createRuntimeException($this->__($e->getMessage()), null, $e); } if ($result === false) { $errorCode = preg_last_error(); throw $this->_createRuntimeException($this->__('RegEx error code "%1$s"', [$errorCode])); } return $matches; }
[ "protected", "function", "_getAllMatchesRegex", "(", "$", "pattern", ",", "$", "subject", ")", "{", "$", "matches", "=", "[", "]", ";", "$", "pattern", "=", "$", "this", "->", "_normalizeString", "(", "$", "pattern", ")", ";", "$", "subject", "=", "$", "this", "->", "_normalizeString", "(", "$", "subject", ")", ";", "try", "{", "$", "result", "=", "@", "preg_match_all", "(", "$", "pattern", ",", "$", "subject", ",", "$", "matches", ")", ";", "}", "catch", "(", "RootException", "$", "e", ")", "{", "// This will happen if a custom error handler is set and throws exceptions for regex errors", "throw", "$", "this", "->", "_createRuntimeException", "(", "$", "this", "->", "__", "(", "$", "e", "->", "getMessage", "(", ")", ")", ",", "null", ",", "$", "e", ")", ";", "}", "if", "(", "$", "result", "===", "false", ")", "{", "$", "errorCode", "=", "preg_last_error", "(", ")", ";", "throw", "$", "this", "->", "_createRuntimeException", "(", "$", "this", "->", "__", "(", "'RegEx error code \"%1$s\"'", ",", "[", "$", "errorCode", "]", ")", ")", ";", "}", "return", "$", "matches", ";", "}" ]
Retrieves all matches that correspond to a RegEx pattern from a string. @since [*next-version*] @see preg_match_all() @param string|Stringable $pattern The RegEx pattern to use for matching. @param string|Stringable $subject The subject that will be searched for matches. @throw InvalidArgumentException If the pattern or the subject are of the wrong type. @throw RuntimeException If problem matching. @return array The array of matches. Format is same as the matches produced by `preg_match_all()`.
[ "Retrieves", "all", "matches", "that", "correspond", "to", "a", "RegEx", "pattern", "from", "a", "string", "." ]
train
https://github.com/Dhii/regex-abstract/blob/0751f9c91a6f86d5f901b6b7f3613dc80bb69a8a/src/GetAllMatchesRegexCapablePcreTrait.php#L35-L54
ARCANESOFT/Blog
database/migrations/2015_02_01_000004_create_blog_post_tag_pivot.php
CreateBlogPostTagPivot.up
public function up() { $this->createSchema(function(Blueprint $table) { $table->unsignedInteger('post_id'); $table->unsignedInteger('tag_id'); $table->primary(['post_id', 'tag_id']); }); }
php
public function up() { $this->createSchema(function(Blueprint $table) { $table->unsignedInteger('post_id'); $table->unsignedInteger('tag_id'); $table->primary(['post_id', 'tag_id']); }); }
[ "public", "function", "up", "(", ")", "{", "$", "this", "->", "createSchema", "(", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "unsignedInteger", "(", "'post_id'", ")", ";", "$", "table", "->", "unsignedInteger", "(", "'tag_id'", ")", ";", "$", "table", "->", "primary", "(", "[", "'post_id'", ",", "'tag_id'", "]", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/database/migrations/2015_02_01_000004_create_blog_post_tag_pivot.php#L36-L44
ARCANESOFT/Auth
src/Http/Controllers/Admin/PasswordResetsController.php
PasswordResetsController.index
public function index() { $this->authorize(PasswordResetsPolicy::PERMISSION_LIST); $resets = PasswordReset::with(['user']) ->orderBy('created_at', 'desc') ->paginate($this->perPage); $this->setTitle($title = trans('auth::password-resets.titles.password-resets-list')); $this->addBreadcrumb($title); return $this->view('admin.password-resets.index', compact('resets')); }
php
public function index() { $this->authorize(PasswordResetsPolicy::PERMISSION_LIST); $resets = PasswordReset::with(['user']) ->orderBy('created_at', 'desc') ->paginate($this->perPage); $this->setTitle($title = trans('auth::password-resets.titles.password-resets-list')); $this->addBreadcrumb($title); return $this->view('admin.password-resets.index', compact('resets')); }
[ "public", "function", "index", "(", ")", "{", "$", "this", "->", "authorize", "(", "PasswordResetsPolicy", "::", "PERMISSION_LIST", ")", ";", "$", "resets", "=", "PasswordReset", "::", "with", "(", "[", "'user'", "]", ")", "->", "orderBy", "(", "'created_at'", ",", "'desc'", ")", "->", "paginate", "(", "$", "this", "->", "perPage", ")", ";", "$", "this", "->", "setTitle", "(", "$", "title", "=", "trans", "(", "'auth::password-resets.titles.password-resets-list'", ")", ")", ";", "$", "this", "->", "addBreadcrumb", "(", "$", "title", ")", ";", "return", "$", "this", "->", "view", "(", "'admin.password-resets.index'", ",", "compact", "(", "'resets'", ")", ")", ";", "}" ]
/* ----------------------------------------------------------------- | Main Methods | -----------------------------------------------------------------
[ "/", "*", "-----------------------------------------------------------------", "|", "Main", "Methods", "|", "-----------------------------------------------------------------" ]
train
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/PasswordResetsController.php#L52-L64
PenoaksDev/Milky-Framework
src/Milky/Database/Migrations/Migrator.php
Migrator.reset
public function reset($pretend = false) { $this->notes = []; $migrations = array_reverse($this->repository->getRan()); $count = count($migrations); if ($count === 0) { $this->note('<info>Nothing to rollback.</info>'); } else { foreach ($migrations as $migration) { $this->runDown((object) ['migration' => $migration], $pretend); } } return $count; }
php
public function reset($pretend = false) { $this->notes = []; $migrations = array_reverse($this->repository->getRan()); $count = count($migrations); if ($count === 0) { $this->note('<info>Nothing to rollback.</info>'); } else { foreach ($migrations as $migration) { $this->runDown((object) ['migration' => $migration], $pretend); } } return $count; }
[ "public", "function", "reset", "(", "$", "pretend", "=", "false", ")", "{", "$", "this", "->", "notes", "=", "[", "]", ";", "$", "migrations", "=", "array_reverse", "(", "$", "this", "->", "repository", "->", "getRan", "(", ")", ")", ";", "$", "count", "=", "count", "(", "$", "migrations", ")", ";", "if", "(", "$", "count", "===", "0", ")", "{", "$", "this", "->", "note", "(", "'<info>Nothing to rollback.</info>'", ")", ";", "}", "else", "{", "foreach", "(", "$", "migrations", "as", "$", "migration", ")", "{", "$", "this", "->", "runDown", "(", "(", "object", ")", "[", "'migration'", "=>", "$", "migration", "]", ",", "$", "pretend", ")", ";", "}", "}", "return", "$", "count", ";", "}" ]
Rolls all of the currently applied migrations back. @param bool $pretend @return int
[ "Rolls", "all", "of", "the", "currently", "applied", "migrations", "back", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Migrations/Migrator.php#L192-L209
rawphp/RawCodeStandards
RawPHP/Sniffs/ControlStructures/SwitchDeclarationSniff.php
RawPHP_Sniffs_ControlStructures_SwitchDeclarationSniff.process
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); // We can't process SWITCH statements unless we know where they start and end. if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === FALSE || isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === FALSE ) { return; } $switch = $tokens[ $stackPtr ]; $nextCase = $stackPtr; $caseAlignment = ($switch[ 'column' ] + 4); $caseCount = 0; $foundDefault = FALSE; while ( ($nextCase = $phpcsFile->findNext( array( T_CASE, T_DEFAULT, T_SWITCH ), ($nextCase + 1 ), $switch[ 'scope_closer' ] )) !== FALSE ) { // Skip nested SWITCH statements; they are handled on their own. if ( $tokens[ $nextCase ][ 'code' ] === T_SWITCH ) { $nextCase = $tokens[ $nextCase ][ 'scope_closer' ]; continue; } if ( $tokens[ $nextCase ][ 'code' ] === T_DEFAULT ) { $type = 'Default'; $foundDefault = TRUE; } else { $type = 'Case'; $caseCount++; } if ( $tokens[ $nextCase ][ 'content' ] !== strtolower( $tokens[ $nextCase ][ 'content' ] ) ) { $expected = strtolower( $tokens[ $nextCase ][ 'content' ] ); $error = strtoupper( $type ) . ' keyword must be lowercase; expected "%s" but found "%s"'; $data = array( $expected, $tokens[ $nextCase ][ 'content' ], ); $phpcsFile->addError( $error, $nextCase, $type . 'NotLower', $data ); } if ( $tokens[ $nextCase ][ 'column' ] !== $caseAlignment ) { $error = strtoupper( $type ) . ' keyword must be indented 4 spaces from SWITCH keyword'; $phpcsFile->addError( $error, $nextCase, $type . 'Indent' ); } if ( $type === 'Case' && ($tokens[ ($nextCase + 1) ][ 'type' ] !== 'T_WHITESPACE' || $tokens[ ($nextCase + 1) ][ 'content' ] !== ' ') ) { $error = 'CASE keyword must be followed by a single space'; $phpcsFile->addError( $error, $nextCase, 'SpacingAfterCase' ); } $opener = $tokens[ $nextCase ][ 'scope_opener' ]; if ( $tokens[ ($opener - 1) ][ 'type' ] === 'T_WHITESPACE' ) { $error = 'There must be no space before the colon in a ' . strtoupper( $type ) . ' statement'; $phpcsFile->addError( $error, $nextCase, 'SpaceBeforeColon' . $type ); } $nextBreak = $tokens[ $nextCase ][ 'scope_closer' ]; if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK || $tokens[ $nextBreak ][ 'code' ] === T_RETURN ) { if ( $tokens[ $nextBreak ][ 'scope_condition' ] === $nextCase ) { // Only need to check a couple of things once, even if the // break is shared between multiple case statements, or even // the default case. $breakLine = $tokens[ $nextBreak ][ 'line' ]; $prevLine = 0; for ( $i = ($nextBreak - 1); $i > $stackPtr; $i-- ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $prevLine = $tokens[ $i ][ 'line' ]; break; } } $breakLine = $tokens[ $nextBreak ][ 'line' ]; $nextLine = $tokens[ $tokens[ $stackPtr ][ 'scope_closer' ] ][ 'line' ]; $semicolon = $phpcsFile->findNext( T_SEMICOLON, $nextBreak ); for ( $i = ($semicolon + 1); $i < $tokens[ $stackPtr ][ 'scope_closer' ]; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $nextLine = $tokens[ $i ][ 'line' ]; break; } } if ( $type === 'Case' ) { // Ensure the BREAK statement is followed by // a single blank line, or the end switch brace. if ( $nextLine !== ($breakLine + 2) && $i !== $tokens[ $stackPtr ][ 'scope_closer' ] ) { $error = 'Case breaking statements must be '; $error .= 'followed by a single blank line'; $phpcsFile->addError( $error, $nextBreak, 'SpacingAfterBreak' ); } } else { // Ensure the BREAK statement is not followed by a blank line. if ( $nextLine !== ($breakLine + 1) ) { $error = 'Blank lines are not allowed after the '; $error .= 'DEFAULT case\'s breaking statement'; $phpcsFile->addError( $error, $nextBreak, 'SpacingAfterDefaultBreak' ); } } $caseLine = $tokens[ $nextCase ][ 'line' ]; $nextLine = $tokens[ $nextBreak ][ 'line' ]; for ( $i = ($opener + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $nextLine = $tokens[ $i ][ 'line' ]; break; } } if ( $nextLine !== ($caseLine + 1) ) { $error = 'Blank lines are not allowed after ' . strtoupper( $type ) . ' statements'; $phpcsFile->addError( $error, $nextCase, 'SpacingAfter' . $type ); } } if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK ) { if ( $type === 'Case' ) { // Ensure empty CASE statements are not allowed. // They must have some code content in them. A comment is not enough. // But count RETURN statements as valid content if they also // happen to close the CASE statement. $foundContent = FALSE; for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'code' ] === T_CASE ) { $i = $tokens[ $i ][ 'scope_opener' ]; continue; } if ( in_array( $tokens[ $i ][ 'code' ], PHP_CodeSniffer_Tokens::$emptyTokens ) === FALSE ) { $foundContent = TRUE; break; } } if ( $foundContent === FALSE ) { $error = 'Empty CASE statements are not allowed'; $phpcsFile->addError( $error, $nextCase, 'EmptyCase' ); } } else { // Ensure empty DEFAULT statements are not allowed. // They must (at least) have a comment describing why // the default case is being ignored. $foundContent = FALSE; for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $foundContent = TRUE; break; } } if ( $foundContent === FALSE ) { $error = 'Comment required for empty DEFAULT case'; $phpcsFile->addError( $error, $nextCase, 'EmptyDefault' ); } } } } else if ( $type === 'Default' ) { $error = 'DEFAULT case must have a breaking statement'; $phpcsFile->addError( $error, $nextCase, 'DefaultNoBreak' ); } } if ( $foundDefault === FALSE ) { $error = 'All SWITCH statements must contain a DEFAULT case'; $phpcsFile->addError( $error, $stackPtr, 'MissingDefault' ); } if ( $tokens[ $switch[ 'scope_closer' ] ][ 'column' ] !== $switch[ 'column' ] ) { $error = 'Closing brace of SWITCH statement must be aligned with SWITCH keyword'; $phpcsFile->addError( $error, $switch[ 'scope_closer' ], 'CloseBraceAlign' ); } if ( $caseCount === 0 ) { $error = 'SWITCH statements must contain at least one CASE statement'; $phpcsFile->addError( $error, $stackPtr, 'MissingCase' ); } }
php
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); // We can't process SWITCH statements unless we know where they start and end. if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === FALSE || isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === FALSE ) { return; } $switch = $tokens[ $stackPtr ]; $nextCase = $stackPtr; $caseAlignment = ($switch[ 'column' ] + 4); $caseCount = 0; $foundDefault = FALSE; while ( ($nextCase = $phpcsFile->findNext( array( T_CASE, T_DEFAULT, T_SWITCH ), ($nextCase + 1 ), $switch[ 'scope_closer' ] )) !== FALSE ) { // Skip nested SWITCH statements; they are handled on their own. if ( $tokens[ $nextCase ][ 'code' ] === T_SWITCH ) { $nextCase = $tokens[ $nextCase ][ 'scope_closer' ]; continue; } if ( $tokens[ $nextCase ][ 'code' ] === T_DEFAULT ) { $type = 'Default'; $foundDefault = TRUE; } else { $type = 'Case'; $caseCount++; } if ( $tokens[ $nextCase ][ 'content' ] !== strtolower( $tokens[ $nextCase ][ 'content' ] ) ) { $expected = strtolower( $tokens[ $nextCase ][ 'content' ] ); $error = strtoupper( $type ) . ' keyword must be lowercase; expected "%s" but found "%s"'; $data = array( $expected, $tokens[ $nextCase ][ 'content' ], ); $phpcsFile->addError( $error, $nextCase, $type . 'NotLower', $data ); } if ( $tokens[ $nextCase ][ 'column' ] !== $caseAlignment ) { $error = strtoupper( $type ) . ' keyword must be indented 4 spaces from SWITCH keyword'; $phpcsFile->addError( $error, $nextCase, $type . 'Indent' ); } if ( $type === 'Case' && ($tokens[ ($nextCase + 1) ][ 'type' ] !== 'T_WHITESPACE' || $tokens[ ($nextCase + 1) ][ 'content' ] !== ' ') ) { $error = 'CASE keyword must be followed by a single space'; $phpcsFile->addError( $error, $nextCase, 'SpacingAfterCase' ); } $opener = $tokens[ $nextCase ][ 'scope_opener' ]; if ( $tokens[ ($opener - 1) ][ 'type' ] === 'T_WHITESPACE' ) { $error = 'There must be no space before the colon in a ' . strtoupper( $type ) . ' statement'; $phpcsFile->addError( $error, $nextCase, 'SpaceBeforeColon' . $type ); } $nextBreak = $tokens[ $nextCase ][ 'scope_closer' ]; if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK || $tokens[ $nextBreak ][ 'code' ] === T_RETURN ) { if ( $tokens[ $nextBreak ][ 'scope_condition' ] === $nextCase ) { // Only need to check a couple of things once, even if the // break is shared between multiple case statements, or even // the default case. $breakLine = $tokens[ $nextBreak ][ 'line' ]; $prevLine = 0; for ( $i = ($nextBreak - 1); $i > $stackPtr; $i-- ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $prevLine = $tokens[ $i ][ 'line' ]; break; } } $breakLine = $tokens[ $nextBreak ][ 'line' ]; $nextLine = $tokens[ $tokens[ $stackPtr ][ 'scope_closer' ] ][ 'line' ]; $semicolon = $phpcsFile->findNext( T_SEMICOLON, $nextBreak ); for ( $i = ($semicolon + 1); $i < $tokens[ $stackPtr ][ 'scope_closer' ]; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $nextLine = $tokens[ $i ][ 'line' ]; break; } } if ( $type === 'Case' ) { // Ensure the BREAK statement is followed by // a single blank line, or the end switch brace. if ( $nextLine !== ($breakLine + 2) && $i !== $tokens[ $stackPtr ][ 'scope_closer' ] ) { $error = 'Case breaking statements must be '; $error .= 'followed by a single blank line'; $phpcsFile->addError( $error, $nextBreak, 'SpacingAfterBreak' ); } } else { // Ensure the BREAK statement is not followed by a blank line. if ( $nextLine !== ($breakLine + 1) ) { $error = 'Blank lines are not allowed after the '; $error .= 'DEFAULT case\'s breaking statement'; $phpcsFile->addError( $error, $nextBreak, 'SpacingAfterDefaultBreak' ); } } $caseLine = $tokens[ $nextCase ][ 'line' ]; $nextLine = $tokens[ $nextBreak ][ 'line' ]; for ( $i = ($opener + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $nextLine = $tokens[ $i ][ 'line' ]; break; } } if ( $nextLine !== ($caseLine + 1) ) { $error = 'Blank lines are not allowed after ' . strtoupper( $type ) . ' statements'; $phpcsFile->addError( $error, $nextCase, 'SpacingAfter' . $type ); } } if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK ) { if ( $type === 'Case' ) { // Ensure empty CASE statements are not allowed. // They must have some code content in them. A comment is not enough. // But count RETURN statements as valid content if they also // happen to close the CASE statement. $foundContent = FALSE; for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'code' ] === T_CASE ) { $i = $tokens[ $i ][ 'scope_opener' ]; continue; } if ( in_array( $tokens[ $i ][ 'code' ], PHP_CodeSniffer_Tokens::$emptyTokens ) === FALSE ) { $foundContent = TRUE; break; } } if ( $foundContent === FALSE ) { $error = 'Empty CASE statements are not allowed'; $phpcsFile->addError( $error, $nextCase, 'EmptyCase' ); } } else { // Ensure empty DEFAULT statements are not allowed. // They must (at least) have a comment describing why // the default case is being ignored. $foundContent = FALSE; for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1); $i < $nextBreak; $i++ ) { if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' ) { $foundContent = TRUE; break; } } if ( $foundContent === FALSE ) { $error = 'Comment required for empty DEFAULT case'; $phpcsFile->addError( $error, $nextCase, 'EmptyDefault' ); } } } } else if ( $type === 'Default' ) { $error = 'DEFAULT case must have a breaking statement'; $phpcsFile->addError( $error, $nextCase, 'DefaultNoBreak' ); } } if ( $foundDefault === FALSE ) { $error = 'All SWITCH statements must contain a DEFAULT case'; $phpcsFile->addError( $error, $stackPtr, 'MissingDefault' ); } if ( $tokens[ $switch[ 'scope_closer' ] ][ 'column' ] !== $switch[ 'column' ] ) { $error = 'Closing brace of SWITCH statement must be aligned with SWITCH keyword'; $phpcsFile->addError( $error, $switch[ 'scope_closer' ], 'CloseBraceAlign' ); } if ( $caseCount === 0 ) { $error = 'SWITCH statements must contain at least one CASE statement'; $phpcsFile->addError( $error, $stackPtr, 'MissingCase' ); } }
[ "public", "function", "process", "(", "PHP_CodeSniffer_File", "$", "phpcsFile", ",", "$", "stackPtr", ")", "{", "$", "tokens", "=", "$", "phpcsFile", "->", "getTokens", "(", ")", ";", "// We can't process SWITCH statements unless we know where they start and end.", "if", "(", "isset", "(", "$", "tokens", "[", "$", "stackPtr", "]", "[", "'scope_opener'", "]", ")", "===", "FALSE", "||", "isset", "(", "$", "tokens", "[", "$", "stackPtr", "]", "[", "'scope_closer'", "]", ")", "===", "FALSE", ")", "{", "return", ";", "}", "$", "switch", "=", "$", "tokens", "[", "$", "stackPtr", "]", ";", "$", "nextCase", "=", "$", "stackPtr", ";", "$", "caseAlignment", "=", "(", "$", "switch", "[", "'column'", "]", "+", "4", ")", ";", "$", "caseCount", "=", "0", ";", "$", "foundDefault", "=", "FALSE", ";", "while", "(", "(", "$", "nextCase", "=", "$", "phpcsFile", "->", "findNext", "(", "array", "(", "T_CASE", ",", "T_DEFAULT", ",", "T_SWITCH", ")", ",", "(", "$", "nextCase", "+", "1", ")", ",", "$", "switch", "[", "'scope_closer'", "]", ")", ")", "!==", "FALSE", ")", "{", "// Skip nested SWITCH statements; they are handled on their own.", "if", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'code'", "]", "===", "T_SWITCH", ")", "{", "$", "nextCase", "=", "$", "tokens", "[", "$", "nextCase", "]", "[", "'scope_closer'", "]", ";", "continue", ";", "}", "if", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'code'", "]", "===", "T_DEFAULT", ")", "{", "$", "type", "=", "'Default'", ";", "$", "foundDefault", "=", "TRUE", ";", "}", "else", "{", "$", "type", "=", "'Case'", ";", "$", "caseCount", "++", ";", "}", "if", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'content'", "]", "!==", "strtolower", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'content'", "]", ")", ")", "{", "$", "expected", "=", "strtolower", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'content'", "]", ")", ";", "$", "error", "=", "strtoupper", "(", "$", "type", ")", ".", "' keyword must be lowercase; expected \"%s\" but found \"%s\"'", ";", "$", "data", "=", "array", "(", "$", "expected", ",", "$", "tokens", "[", "$", "nextCase", "]", "[", "'content'", "]", ",", ")", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "$", "type", ".", "'NotLower'", ",", "$", "data", ")", ";", "}", "if", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'column'", "]", "!==", "$", "caseAlignment", ")", "{", "$", "error", "=", "strtoupper", "(", "$", "type", ")", ".", "' keyword must be indented 4 spaces from SWITCH keyword'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "$", "type", ".", "'Indent'", ")", ";", "}", "if", "(", "$", "type", "===", "'Case'", "&&", "(", "$", "tokens", "[", "(", "$", "nextCase", "+", "1", ")", "]", "[", "'type'", "]", "!==", "'T_WHITESPACE'", "||", "$", "tokens", "[", "(", "$", "nextCase", "+", "1", ")", "]", "[", "'content'", "]", "!==", "' '", ")", ")", "{", "$", "error", "=", "'CASE keyword must be followed by a single space'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'SpacingAfterCase'", ")", ";", "}", "$", "opener", "=", "$", "tokens", "[", "$", "nextCase", "]", "[", "'scope_opener'", "]", ";", "if", "(", "$", "tokens", "[", "(", "$", "opener", "-", "1", ")", "]", "[", "'type'", "]", "===", "'T_WHITESPACE'", ")", "{", "$", "error", "=", "'There must be no space before the colon in a '", ".", "strtoupper", "(", "$", "type", ")", ".", "' statement'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'SpaceBeforeColon'", ".", "$", "type", ")", ";", "}", "$", "nextBreak", "=", "$", "tokens", "[", "$", "nextCase", "]", "[", "'scope_closer'", "]", ";", "if", "(", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'code'", "]", "===", "T_BREAK", "||", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'code'", "]", "===", "T_RETURN", ")", "{", "if", "(", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'scope_condition'", "]", "===", "$", "nextCase", ")", "{", "// Only need to check a couple of things once, even if the", "// break is shared between multiple case statements, or even", "// the default case.", "$", "breakLine", "=", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'line'", "]", ";", "$", "prevLine", "=", "0", ";", "for", "(", "$", "i", "=", "(", "$", "nextBreak", "-", "1", ")", ";", "$", "i", ">", "$", "stackPtr", ";", "$", "i", "--", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "[", "'type'", "]", "!==", "'T_WHITESPACE'", ")", "{", "$", "prevLine", "=", "$", "tokens", "[", "$", "i", "]", "[", "'line'", "]", ";", "break", ";", "}", "}", "$", "breakLine", "=", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'line'", "]", ";", "$", "nextLine", "=", "$", "tokens", "[", "$", "tokens", "[", "$", "stackPtr", "]", "[", "'scope_closer'", "]", "]", "[", "'line'", "]", ";", "$", "semicolon", "=", "$", "phpcsFile", "->", "findNext", "(", "T_SEMICOLON", ",", "$", "nextBreak", ")", ";", "for", "(", "$", "i", "=", "(", "$", "semicolon", "+", "1", ")", ";", "$", "i", "<", "$", "tokens", "[", "$", "stackPtr", "]", "[", "'scope_closer'", "]", ";", "$", "i", "++", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "[", "'type'", "]", "!==", "'T_WHITESPACE'", ")", "{", "$", "nextLine", "=", "$", "tokens", "[", "$", "i", "]", "[", "'line'", "]", ";", "break", ";", "}", "}", "if", "(", "$", "type", "===", "'Case'", ")", "{", "// Ensure the BREAK statement is followed by", "// a single blank line, or the end switch brace.", "if", "(", "$", "nextLine", "!==", "(", "$", "breakLine", "+", "2", ")", "&&", "$", "i", "!==", "$", "tokens", "[", "$", "stackPtr", "]", "[", "'scope_closer'", "]", ")", "{", "$", "error", "=", "'Case breaking statements must be '", ";", "$", "error", ".=", "'followed by a single blank line'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextBreak", ",", "'SpacingAfterBreak'", ")", ";", "}", "}", "else", "{", "// Ensure the BREAK statement is not followed by a blank line.", "if", "(", "$", "nextLine", "!==", "(", "$", "breakLine", "+", "1", ")", ")", "{", "$", "error", "=", "'Blank lines are not allowed after the '", ";", "$", "error", ".=", "'DEFAULT case\\'s breaking statement'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextBreak", ",", "'SpacingAfterDefaultBreak'", ")", ";", "}", "}", "$", "caseLine", "=", "$", "tokens", "[", "$", "nextCase", "]", "[", "'line'", "]", ";", "$", "nextLine", "=", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'line'", "]", ";", "for", "(", "$", "i", "=", "(", "$", "opener", "+", "1", ")", ";", "$", "i", "<", "$", "nextBreak", ";", "$", "i", "++", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "[", "'type'", "]", "!==", "'T_WHITESPACE'", ")", "{", "$", "nextLine", "=", "$", "tokens", "[", "$", "i", "]", "[", "'line'", "]", ";", "break", ";", "}", "}", "if", "(", "$", "nextLine", "!==", "(", "$", "caseLine", "+", "1", ")", ")", "{", "$", "error", "=", "'Blank lines are not allowed after '", ".", "strtoupper", "(", "$", "type", ")", ".", "' statements'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'SpacingAfter'", ".", "$", "type", ")", ";", "}", "}", "if", "(", "$", "tokens", "[", "$", "nextBreak", "]", "[", "'code'", "]", "===", "T_BREAK", ")", "{", "if", "(", "$", "type", "===", "'Case'", ")", "{", "// Ensure empty CASE statements are not allowed.", "// They must have some code content in them. A comment is not enough.", "// But count RETURN statements as valid content if they also", "// happen to close the CASE statement.", "$", "foundContent", "=", "FALSE", ";", "for", "(", "$", "i", "=", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'scope_opener'", "]", "+", "1", ")", ";", "$", "i", "<", "$", "nextBreak", ";", "$", "i", "++", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "[", "'code'", "]", "===", "T_CASE", ")", "{", "$", "i", "=", "$", "tokens", "[", "$", "i", "]", "[", "'scope_opener'", "]", ";", "continue", ";", "}", "if", "(", "in_array", "(", "$", "tokens", "[", "$", "i", "]", "[", "'code'", "]", ",", "PHP_CodeSniffer_Tokens", "::", "$", "emptyTokens", ")", "===", "FALSE", ")", "{", "$", "foundContent", "=", "TRUE", ";", "break", ";", "}", "}", "if", "(", "$", "foundContent", "===", "FALSE", ")", "{", "$", "error", "=", "'Empty CASE statements are not allowed'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'EmptyCase'", ")", ";", "}", "}", "else", "{", "// Ensure empty DEFAULT statements are not allowed.", "// They must (at least) have a comment describing why", "// the default case is being ignored.", "$", "foundContent", "=", "FALSE", ";", "for", "(", "$", "i", "=", "(", "$", "tokens", "[", "$", "nextCase", "]", "[", "'scope_opener'", "]", "+", "1", ")", ";", "$", "i", "<", "$", "nextBreak", ";", "$", "i", "++", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "[", "'type'", "]", "!==", "'T_WHITESPACE'", ")", "{", "$", "foundContent", "=", "TRUE", ";", "break", ";", "}", "}", "if", "(", "$", "foundContent", "===", "FALSE", ")", "{", "$", "error", "=", "'Comment required for empty DEFAULT case'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'EmptyDefault'", ")", ";", "}", "}", "}", "}", "else", "if", "(", "$", "type", "===", "'Default'", ")", "{", "$", "error", "=", "'DEFAULT case must have a breaking statement'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "nextCase", ",", "'DefaultNoBreak'", ")", ";", "}", "}", "if", "(", "$", "foundDefault", "===", "FALSE", ")", "{", "$", "error", "=", "'All SWITCH statements must contain a DEFAULT case'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "stackPtr", ",", "'MissingDefault'", ")", ";", "}", "if", "(", "$", "tokens", "[", "$", "switch", "[", "'scope_closer'", "]", "]", "[", "'column'", "]", "!==", "$", "switch", "[", "'column'", "]", ")", "{", "$", "error", "=", "'Closing brace of SWITCH statement must be aligned with SWITCH keyword'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "switch", "[", "'scope_closer'", "]", ",", "'CloseBraceAlign'", ")", ";", "}", "if", "(", "$", "caseCount", "===", "0", ")", "{", "$", "error", "=", "'SWITCH statements must contain at least one CASE statement'", ";", "$", "phpcsFile", "->", "addError", "(", "$", "error", ",", "$", "stackPtr", ",", "'MissingCase'", ")", ";", "}", "}" ]
Processes this test, when one of its tokens is encountered. @param PHP_CodeSniffer_File $phpcsFile The file being scanned. @param int $stackPtr The position of the current token in the stack passed in $tokens. @return void
[ "Processes", "this", "test", "when", "one", "of", "its", "tokens", "is", "encountered", "." ]
train
https://github.com/rawphp/RawCodeStandards/blob/aa40b4b085bfb3317843883124da246c32c4bb92/RawPHP/Sniffs/ControlStructures/SwitchDeclarationSniff.php#L65-L305
bkstg/schedule-bundle
Repository/EventRepository.php
EventRepository.searchEvents
public function searchEvents( Production $production, \DateTime $from, \DateTime $to, bool $active = true ) { $qb = $this->createQueryBuilder('e'); return $qb ->join('e.groups', 'g') // Add conditions. ->andWhere($qb->expr()->eq('g', ':group')) ->andWhere($qb->expr()->between('e.start', ':from', ':to')) ->andWhere($qb->expr()->eq('e.active', ':active')) // Add parameters. ->setParameter('group', $production) ->setParameter('from', $from) ->setParameter('to', $to) ->setParameter('active', $active) // Get results. ->getQuery() ->getResult(); }
php
public function searchEvents( Production $production, \DateTime $from, \DateTime $to, bool $active = true ) { $qb = $this->createQueryBuilder('e'); return $qb ->join('e.groups', 'g') // Add conditions. ->andWhere($qb->expr()->eq('g', ':group')) ->andWhere($qb->expr()->between('e.start', ':from', ':to')) ->andWhere($qb->expr()->eq('e.active', ':active')) // Add parameters. ->setParameter('group', $production) ->setParameter('from', $from) ->setParameter('to', $to) ->setParameter('active', $active) // Get results. ->getQuery() ->getResult(); }
[ "public", "function", "searchEvents", "(", "Production", "$", "production", ",", "\\", "DateTime", "$", "from", ",", "\\", "DateTime", "$", "to", ",", "bool", "$", "active", "=", "true", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'e'", ")", ";", "return", "$", "qb", "->", "join", "(", "'e.groups'", ",", "'g'", ")", "// Add conditions.", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'g'", ",", "':group'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "between", "(", "'e.start'", ",", "':from'", ",", "':to'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'e.active'", ",", "':active'", ")", ")", "// Add parameters.", "->", "setParameter", "(", "'group'", ",", "$", "production", ")", "->", "setParameter", "(", "'from'", ",", "$", "from", ")", "->", "setParameter", "(", "'to'", ",", "$", "to", ")", "->", "setParameter", "(", "'active'", ",", "$", "active", ")", "// Get results.", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "}" ]
Search for events within a production. @param Production $production The production to search in. @param \DateTime $from The time to start searching from. @param \DateTime $to The time to end searching from. @param bool $active The active state of the events. @return Event[]
[ "Search", "for", "events", "within", "a", "production", "." ]
train
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Repository/EventRepository.php#L32-L57
bkstg/schedule-bundle
Repository/EventRepository.php
EventRepository.searchEventsByUser
public function searchEventsByUser( UserInterface $user, \DateTime $from, \DateTime $to, bool $active = true ) { $qb = $this->createQueryBuilder('e'); return $qb ->join('e.invitations', 'i') // Add conditions. ->andWhere($qb->expr()->between('e.start', ':from', ':to')) ->andWhere($qb->expr()->eq('i.invitee', ':invitee')) ->andWhere($qb->expr()->eq('e.active', ':active')) ->andWhere($qb->expr()->orX( $qb->expr()->isNull('i.response'), $qb->expr()->neq('i.response', ':decline') )) // Add parameters. ->setParameter('from', $from) ->setParameter('to', $to) ->setParameter('invitee', $user->getUsername()) ->setParameter('decline', Invitation::RESPONSE_DECLINE) ->setParameter('active', $active) // Get results. ->getQuery() ->getResult(); }
php
public function searchEventsByUser( UserInterface $user, \DateTime $from, \DateTime $to, bool $active = true ) { $qb = $this->createQueryBuilder('e'); return $qb ->join('e.invitations', 'i') // Add conditions. ->andWhere($qb->expr()->between('e.start', ':from', ':to')) ->andWhere($qb->expr()->eq('i.invitee', ':invitee')) ->andWhere($qb->expr()->eq('e.active', ':active')) ->andWhere($qb->expr()->orX( $qb->expr()->isNull('i.response'), $qb->expr()->neq('i.response', ':decline') )) // Add parameters. ->setParameter('from', $from) ->setParameter('to', $to) ->setParameter('invitee', $user->getUsername()) ->setParameter('decline', Invitation::RESPONSE_DECLINE) ->setParameter('active', $active) // Get results. ->getQuery() ->getResult(); }
[ "public", "function", "searchEventsByUser", "(", "UserInterface", "$", "user", ",", "\\", "DateTime", "$", "from", ",", "\\", "DateTime", "$", "to", ",", "bool", "$", "active", "=", "true", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'e'", ")", ";", "return", "$", "qb", "->", "join", "(", "'e.invitations'", ",", "'i'", ")", "// Add conditions.", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "between", "(", "'e.start'", ",", "':from'", ",", "':to'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'i.invitee'", ",", "':invitee'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'e.active'", ",", "':active'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "orX", "(", "$", "qb", "->", "expr", "(", ")", "->", "isNull", "(", "'i.response'", ")", ",", "$", "qb", "->", "expr", "(", ")", "->", "neq", "(", "'i.response'", ",", "':decline'", ")", ")", ")", "// Add parameters.", "->", "setParameter", "(", "'from'", ",", "$", "from", ")", "->", "setParameter", "(", "'to'", ",", "$", "to", ")", "->", "setParameter", "(", "'invitee'", ",", "$", "user", "->", "getUsername", "(", ")", ")", "->", "setParameter", "(", "'decline'", ",", "Invitation", "::", "RESPONSE_DECLINE", ")", "->", "setParameter", "(", "'active'", ",", "$", "active", ")", "// Get results.", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "}" ]
Search for events for a user. @param UserInterface $user The production to search in. @param \DateTime $from The time to start searching from. @param \DateTime $to The time to end searching from. @param bool $active The active state of the events. @return Event[]
[ "Search", "for", "events", "for", "a", "user", "." ]
train
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Repository/EventRepository.php#L69-L99
bkstg/schedule-bundle
Repository/EventRepository.php
EventRepository.findArchivedEventsQuery
public function findArchivedEventsQuery(Production $production) { $qb = $this->createQueryBuilder('e'); return $qb // Add joins. ->join('e.groups', 'g') // Add conditions. ->andWhere($qb->expr()->eq('g', ':production')) ->andWhere($qb->expr()->eq('e.active', ':active')) ->andWhere($qb->expr()->isNull('e.schedule')) // Add parameters. ->setParameter('production', $production) ->setParameter('active', false) // Add ordering. ->addOrderBy('e.updated', 'DESC') // Get query. ->getQuery(); }
php
public function findArchivedEventsQuery(Production $production) { $qb = $this->createQueryBuilder('e'); return $qb // Add joins. ->join('e.groups', 'g') // Add conditions. ->andWhere($qb->expr()->eq('g', ':production')) ->andWhere($qb->expr()->eq('e.active', ':active')) ->andWhere($qb->expr()->isNull('e.schedule')) // Add parameters. ->setParameter('production', $production) ->setParameter('active', false) // Add ordering. ->addOrderBy('e.updated', 'DESC') // Get query. ->getQuery(); }
[ "public", "function", "findArchivedEventsQuery", "(", "Production", "$", "production", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'e'", ")", ";", "return", "$", "qb", "// Add joins.", "->", "join", "(", "'e.groups'", ",", "'g'", ")", "// Add conditions.", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'g'", ",", "':production'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'e.active'", ",", "':active'", ")", ")", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "isNull", "(", "'e.schedule'", ")", ")", "// Add parameters.", "->", "setParameter", "(", "'production'", ",", "$", "production", ")", "->", "setParameter", "(", "'active'", ",", "false", ")", "// Add ordering.", "->", "addOrderBy", "(", "'e.updated'", ",", "'DESC'", ")", "// Get query.", "->", "getQuery", "(", ")", ";", "}" ]
Helper function to search for events that are not active. @param Production $production The production to search in. @return Event[]
[ "Helper", "function", "to", "search", "for", "events", "that", "are", "not", "active", "." ]
train
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Repository/EventRepository.php#L108-L130
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Expression/Operand/Size.php
Size.isEquivalent
public function isEquivalent(OperandInterface $operand) { if (!$operand instanceof self) { return false; } return $this->path === $operand->path; }
php
public function isEquivalent(OperandInterface $operand) { if (!$operand instanceof self) { return false; } return $this->path === $operand->path; }
[ "public", "function", "isEquivalent", "(", "OperandInterface", "$", "operand", ")", "{", "if", "(", "!", "$", "operand", "instanceof", "self", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "path", "===", "$", "operand", "->", "path", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Expression/Operand/Size.php#L64-L71
togucms/ApplicationModelsBundle
Phpcr/DocumentRepository.php
DocumentRepository.constraintField
protected function constraintField(ConstraintFactory $where, $field, $value, $alias) { if(! is_array($value)) { /* $metadata = $this->getClassMetadata(); $fieldMapping = $metadata->getField($field); $value = array($fieldMapping['defaultConstraint'] => $value); */ $value = array('eq' => $value); } foreach ($value as $constraint => $fieldValue) { $method = 'constraintField'. ucfirst($constraint); if(! method_exists($this, $method)) { throw new \InvalidArgumentException(sprintf('The repository %s has not the method %s', get_class($this), $method)); } call_user_func_array(array($this, $method), array($where, $field, $fieldValue, $alias)); } }
php
protected function constraintField(ConstraintFactory $where, $field, $value, $alias) { if(! is_array($value)) { /* $metadata = $this->getClassMetadata(); $fieldMapping = $metadata->getField($field); $value = array($fieldMapping['defaultConstraint'] => $value); */ $value = array('eq' => $value); } foreach ($value as $constraint => $fieldValue) { $method = 'constraintField'. ucfirst($constraint); if(! method_exists($this, $method)) { throw new \InvalidArgumentException(sprintf('The repository %s has not the method %s', get_class($this), $method)); } call_user_func_array(array($this, $method), array($where, $field, $fieldValue, $alias)); } }
[ "protected", "function", "constraintField", "(", "ConstraintFactory", "$", "where", ",", "$", "field", ",", "$", "value", ",", "$", "alias", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "/*\t\t\t$metadata = $this->getClassMetadata();\n\t\t\t$fieldMapping = $metadata->getField($field);\n\t\t\t$value = array($fieldMapping['defaultConstraint'] => $value);\n*/", "$", "value", "=", "array", "(", "'eq'", "=>", "$", "value", ")", ";", "}", "foreach", "(", "$", "value", "as", "$", "constraint", "=>", "$", "fieldValue", ")", "{", "$", "method", "=", "'constraintField'", ".", "ucfirst", "(", "$", "constraint", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The repository %s has not the method %s'", ",", "get_class", "(", "$", "this", ")", ",", "$", "method", ")", ")", ";", "}", "call_user_func_array", "(", "array", "(", "$", "this", ",", "$", "method", ")", ",", "array", "(", "$", "where", ",", "$", "field", ",", "$", "fieldValue", ",", "$", "alias", ")", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/togucms/ApplicationModelsBundle/blob/125ab47e0327d17afdedb8db074c9d7e211e6417/Phpcr/DocumentRepository.php#L31-L45
kitpages/KitpagesSimpleCacheBundle
Model/CacheManager.php
CacheManager.clear
public function clear($id) { // check if $id exists in cache $query = $this->em->createQuery(" SELECT backend FROM Kitpages\SimpleCacheBundle\Entity\Backend backend WHERE backend.id like :backendId ")->setParameter('backendId', $id); $backendList = $query->getResult(); foreach ($backendList as $backend) { $this->em->remove($backend); } $this->em->flush(); }
php
public function clear($id) { // check if $id exists in cache $query = $this->em->createQuery(" SELECT backend FROM Kitpages\SimpleCacheBundle\Entity\Backend backend WHERE backend.id like :backendId ")->setParameter('backendId', $id); $backendList = $query->getResult(); foreach ($backendList as $backend) { $this->em->remove($backend); } $this->em->flush(); }
[ "public", "function", "clear", "(", "$", "id", ")", "{", "// check if $id exists in cache", "$", "query", "=", "$", "this", "->", "em", "->", "createQuery", "(", "\"\n SELECT backend FROM Kitpages\\SimpleCacheBundle\\Entity\\Backend backend\n WHERE backend.id like :backendId\n \"", ")", "->", "setParameter", "(", "'backendId'", ",", "$", "id", ")", ";", "$", "backendList", "=", "$", "query", "->", "getResult", "(", ")", ";", "foreach", "(", "$", "backendList", "as", "$", "backend", ")", "{", "$", "this", "->", "em", "->", "remove", "(", "$", "backend", ")", ";", "}", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}" ]
clear cache @param string $id cache id, comparison with like and % if you want
[ "clear", "cache" ]
train
https://github.com/kitpages/KitpagesSimpleCacheBundle/blob/bed7bd238dbbc54364ae7a9f5e1beb20b5444989/Model/CacheManager.php#L28-L40
bseddon/XPath20
SequenceType.php
SequenceType.WithTypeCodeAndCardinality
public static function WithTypeCodeAndCardinality( $typeCode, $cardinality ) { $result = SequenceType::WithTypeCodeWithQNameTest( $typeCode, XmlQualifiedNameTest::getWildcard() ); $result->Cardinality = $cardinality; return $result; }
php
public static function WithTypeCodeAndCardinality( $typeCode, $cardinality ) { $result = SequenceType::WithTypeCodeWithQNameTest( $typeCode, XmlQualifiedNameTest::getWildcard() ); $result->Cardinality = $cardinality; return $result; }
[ "public", "static", "function", "WithTypeCodeAndCardinality", "(", "$", "typeCode", ",", "$", "cardinality", ")", "{", "$", "result", "=", "SequenceType", "::", "WithTypeCodeWithQNameTest", "(", "$", "typeCode", ",", "XmlQualifiedNameTest", "::", "getWildcard", "(", ")", ")", ";", "$", "result", "->", "Cardinality", "=", "$", "cardinality", ";", "return", "$", "result", ";", "}" ]
WithTypeCodeAndCardinality @param XmlTypeCode $typeCode @param XmlTypeCardinality $cardinality @return SequenceType
[ "WithTypeCodeAndCardinality" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L150-L155
bseddon/XPath20
SequenceType.php
SequenceType.WithElement
public static function WithElement( $schemaElement ) { $result = new SequenceType(); $result->TypeCode = XmlTypeCode::Element; $result->SchemaElement = $schemaElement; $result->IsNode = true; $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
php
public static function WithElement( $schemaElement ) { $result = new SequenceType(); $result->TypeCode = XmlTypeCode::Element; $result->SchemaElement = $schemaElement; $result->IsNode = true; $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
[ "public", "static", "function", "WithElement", "(", "$", "schemaElement", ")", "{", "$", "result", "=", "new", "SequenceType", "(", ")", ";", "$", "result", "->", "TypeCode", "=", "XmlTypeCode", "::", "Element", ";", "$", "result", "->", "SchemaElement", "=", "$", "schemaElement", ";", "$", "result", "->", "IsNode", "=", "true", ";", "$", "result", "->", "ItemType", "=", "$", "result", "->", "TypeCodeToItemType", "(", "$", "result", "->", "TypeCode", ",", "$", "result", "->", "SchemaType", ")", ";", "return", "$", "result", ";", "}" ]
WithElement @param XmlSchemaElement $schemaElement @return SequenceType
[ "WithElement" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L217-L227
bseddon/XPath20
SequenceType.php
SequenceType.WithAttribute
public static function WithAttribute( $schemaAttribute ) { $result = new SequenceType(); $result->TypeCode = XmlTypeCode::Attribute; $result->SchemaAttribute = $schemaAttribute; $result->IsNode = true; $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
php
public static function WithAttribute( $schemaAttribute ) { $result = new SequenceType(); $result->TypeCode = XmlTypeCode::Attribute; $result->SchemaAttribute = $schemaAttribute; $result->IsNode = true; $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
[ "public", "static", "function", "WithAttribute", "(", "$", "schemaAttribute", ")", "{", "$", "result", "=", "new", "SequenceType", "(", ")", ";", "$", "result", "->", "TypeCode", "=", "XmlTypeCode", "::", "Attribute", ";", "$", "result", "->", "SchemaAttribute", "=", "$", "schemaAttribute", ";", "$", "result", "->", "IsNode", "=", "true", ";", "$", "result", "->", "ItemType", "=", "$", "result", "->", "TypeCodeToItemType", "(", "$", "result", "->", "TypeCode", ",", "$", "result", "->", "SchemaType", ")", ";", "return", "$", "result", ";", "}" ]
WithAttribute @param XmlSchemaAttribute $schemaAttribute @return SequenceType
[ "WithAttribute" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L234-L244
bseddon/XPath20
SequenceType.php
SequenceType.WithSchemaTypeWithCardinality
public static function WithSchemaTypeWithCardinality( $schemaType, $cardinality ) { $result = new SequenceType(); $result->TypeCode = $schemaType->TypeCode; $result->SchemaType = $schemaType; $result->Cardinality = $cardinality; $result->IsNode = $result->TypeCodeIsNodeType( $result->TypeCode ); $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
php
public static function WithSchemaTypeWithCardinality( $schemaType, $cardinality ) { $result = new SequenceType(); $result->TypeCode = $schemaType->TypeCode; $result->SchemaType = $schemaType; $result->Cardinality = $cardinality; $result->IsNode = $result->TypeCodeIsNodeType( $result->TypeCode ); $result->ItemType = $result->TypeCodeToItemType( $result->TypeCode, $result->SchemaType ); return $result; }
[ "public", "static", "function", "WithSchemaTypeWithCardinality", "(", "$", "schemaType", ",", "$", "cardinality", ")", "{", "$", "result", "=", "new", "SequenceType", "(", ")", ";", "$", "result", "->", "TypeCode", "=", "$", "schemaType", "->", "TypeCode", ";", "$", "result", "->", "SchemaType", "=", "$", "schemaType", ";", "$", "result", "->", "Cardinality", "=", "$", "cardinality", ";", "$", "result", "->", "IsNode", "=", "$", "result", "->", "TypeCodeIsNodeType", "(", "$", "result", "->", "TypeCode", ")", ";", "$", "result", "->", "ItemType", "=", "$", "result", "->", "TypeCodeToItemType", "(", "$", "result", "->", "TypeCode", ",", "$", "result", "->", "SchemaType", ")", ";", "return", "$", "result", ";", "}" ]
WithSchemaTypeWithCardinality @param XmlSchemaType $schemaType @param XmlTypeCardinality $cardinality @return SequenceType
[ "WithSchemaTypeWithCardinality" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L252-L263
bseddon/XPath20
SequenceType.php
SequenceType.FromSequenceType
public static function FromSequenceType( $src ) { $result = new SequenceType(); $result->TypeCode = $src->TypeCode; $result->NameTest = $src->NameTest; $result->Cardinality = $src->Cardinality; $result->SchemaType = $src->SchemaType; $result->SchemaElement = $src->SchemaElement; $result->SchemaAttribute = $src->SchemaAttribute; $result->Nillable = $src->Nillable; $result->IsNode = $src->IsNode; $result->ItemType = $src->ItemType; return result; }
php
public static function FromSequenceType( $src ) { $result = new SequenceType(); $result->TypeCode = $src->TypeCode; $result->NameTest = $src->NameTest; $result->Cardinality = $src->Cardinality; $result->SchemaType = $src->SchemaType; $result->SchemaElement = $src->SchemaElement; $result->SchemaAttribute = $src->SchemaAttribute; $result->Nillable = $src->Nillable; $result->IsNode = $src->IsNode; $result->ItemType = $src->ItemType; return result; }
[ "public", "static", "function", "FromSequenceType", "(", "$", "src", ")", "{", "$", "result", "=", "new", "SequenceType", "(", ")", ";", "$", "result", "->", "TypeCode", "=", "$", "src", "->", "TypeCode", ";", "$", "result", "->", "NameTest", "=", "$", "src", "->", "NameTest", ";", "$", "result", "->", "Cardinality", "=", "$", "src", "->", "Cardinality", ";", "$", "result", "->", "SchemaType", "=", "$", "src", "->", "SchemaType", ";", "$", "result", "->", "SchemaElement", "=", "$", "src", "->", "SchemaElement", ";", "$", "result", "->", "SchemaAttribute", "=", "$", "src", "->", "SchemaAttribute", ";", "$", "result", "->", "Nillable", "=", "$", "src", "->", "Nillable", ";", "$", "result", "->", "IsNode", "=", "$", "src", "->", "IsNode", ";", "$", "result", "->", "ItemType", "=", "$", "src", "->", "ItemType", ";", "return", "result", ";", "}" ]
FromSequenceType @param SequenceType $src @return SequenceType
[ "FromSequenceType" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L270-L285
bseddon/XPath20
SequenceType.php
SequenceType.getValueType
public function getValueType() { if ( $this->Cardinality == XmlTypeCardinality::ZeroOrMore || $this->Cardinality == XmlTypeCardinality::OneOrMore ) return "\lyquidity\XPath2\XPath2NodeIterator"; if ( $this->IsNode ) return "\lyquidity\xml\xpath\XPathNavigator"; if ($this->Cardinality == XmlTypeCardinality::One) return $this->ItemType; return "object"; }
php
public function getValueType() { if ( $this->Cardinality == XmlTypeCardinality::ZeroOrMore || $this->Cardinality == XmlTypeCardinality::OneOrMore ) return "\lyquidity\XPath2\XPath2NodeIterator"; if ( $this->IsNode ) return "\lyquidity\xml\xpath\XPathNavigator"; if ($this->Cardinality == XmlTypeCardinality::One) return $this->ItemType; return "object"; }
[ "public", "function", "getValueType", "(", ")", "{", "if", "(", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "ZeroOrMore", "||", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "OneOrMore", ")", "return", "\"\\lyquidity\\XPath2\\XPath2NodeIterator\"", ";", "if", "(", "$", "this", "->", "IsNode", ")", "return", "\"\\lyquidity\\xml\\xpath\\XPathNavigator\"", ";", "if", "(", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "One", ")", "return", "$", "this", "->", "ItemType", ";", "return", "\"object\"", ";", "}" ]
Get the type of the value @var Type $ValueType
[ "Get", "the", "type", "of", "the", "value" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L291-L304
bseddon/XPath20
SequenceType.php
SequenceType.getAtomizedValueType
public function getAtomizedValueType() { if ( $this->IsNode ) { switch ( $this->TypeCode ) { case XmlTypeCode::Text: case XmlTypeCode::ProcessingInstruction: case XmlTypeCode::Comment: case XmlTypeCode::UntypedAtomic: return Types::$UntypedAtomicType; default: if ( ! is_null( $this->SchemaType ) ) return $this->SchemaType->Datatype->ValueType; else if ( ! is_null( $this->SchemaElement ) ) { if ( ! is_null( $this->SchemaElement->ElementSchemaType ) && ! is_null( $this->SchemaElement->ElementSchemaType->Datatype ) ) return $this->SchemaElement->ElementSchemaType->Datatype->ValueType; } else if ( ! is_null( $this->SchemaAttribute ) ) { if ( ! is_null( $this->SchemaAttribute->AttributeSchemaType ) && ! is_null( $this->SchemaAttribute->AttributeSchemaType->Datatype ) ) return $this->SchemaAttribute->AttributeSchemaType->Datatype->ValueType; } return Types::$UntypedAtomicType; } } else return $this->ItemType; }
php
public function getAtomizedValueType() { if ( $this->IsNode ) { switch ( $this->TypeCode ) { case XmlTypeCode::Text: case XmlTypeCode::ProcessingInstruction: case XmlTypeCode::Comment: case XmlTypeCode::UntypedAtomic: return Types::$UntypedAtomicType; default: if ( ! is_null( $this->SchemaType ) ) return $this->SchemaType->Datatype->ValueType; else if ( ! is_null( $this->SchemaElement ) ) { if ( ! is_null( $this->SchemaElement->ElementSchemaType ) && ! is_null( $this->SchemaElement->ElementSchemaType->Datatype ) ) return $this->SchemaElement->ElementSchemaType->Datatype->ValueType; } else if ( ! is_null( $this->SchemaAttribute ) ) { if ( ! is_null( $this->SchemaAttribute->AttributeSchemaType ) && ! is_null( $this->SchemaAttribute->AttributeSchemaType->Datatype ) ) return $this->SchemaAttribute->AttributeSchemaType->Datatype->ValueType; } return Types::$UntypedAtomicType; } } else return $this->ItemType; }
[ "public", "function", "getAtomizedValueType", "(", ")", "{", "if", "(", "$", "this", "->", "IsNode", ")", "{", "switch", "(", "$", "this", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Text", ":", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "case", "XmlTypeCode", "::", "Comment", ":", "case", "XmlTypeCode", "::", "UntypedAtomic", ":", "return", "Types", "::", "$", "UntypedAtomicType", ";", "default", ":", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", ")", "return", "$", "this", "->", "SchemaType", "->", "Datatype", "->", "ValueType", ";", "else", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaElement", ")", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaElement", "->", "ElementSchemaType", ")", "&&", "!", "is_null", "(", "$", "this", "->", "SchemaElement", "->", "ElementSchemaType", "->", "Datatype", ")", ")", "return", "$", "this", "->", "SchemaElement", "->", "ElementSchemaType", "->", "Datatype", "->", "ValueType", ";", "}", "else", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaAttribute", ")", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaAttribute", "->", "AttributeSchemaType", ")", "&&", "!", "is_null", "(", "$", "this", "->", "SchemaAttribute", "->", "AttributeSchemaType", "->", "Datatype", ")", ")", "return", "$", "this", "->", "SchemaAttribute", "->", "AttributeSchemaType", "->", "Datatype", "->", "ValueType", ";", "}", "return", "Types", "::", "$", "UntypedAtomicType", ";", "}", "}", "else", "return", "$", "this", "->", "ItemType", ";", "}" ]
Get the type of the atomized value @return Type
[ "Get", "the", "type", "of", "the", "atomized", "value" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L310-L341
bseddon/XPath20
SequenceType.php
SequenceType.getIsNumeric
public function getIsNumeric() { switch ( $this->TypeCode ) { case XmlTypeCode::Decimal: case XmlTypeCode::Float: case XmlTypeCode::Double: case XmlTypeCode::Integer: case XmlTypeCode::NonPositiveInteger: case XmlTypeCode::NegativeInteger: case XmlTypeCode::Long: case XmlTypeCode::Int: case XmlTypeCode::Short: case XmlTypeCode::Byte: case XmlTypeCode::NonNegativeInteger: case XmlTypeCode::UnsignedLong: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedByte: case XmlTypeCode::PositiveInteger: return true; } return false; }
php
public function getIsNumeric() { switch ( $this->TypeCode ) { case XmlTypeCode::Decimal: case XmlTypeCode::Float: case XmlTypeCode::Double: case XmlTypeCode::Integer: case XmlTypeCode::NonPositiveInteger: case XmlTypeCode::NegativeInteger: case XmlTypeCode::Long: case XmlTypeCode::Int: case XmlTypeCode::Short: case XmlTypeCode::Byte: case XmlTypeCode::NonNegativeInteger: case XmlTypeCode::UnsignedLong: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedByte: case XmlTypeCode::PositiveInteger: return true; } return false; }
[ "public", "function", "getIsNumeric", "(", ")", "{", "switch", "(", "$", "this", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Decimal", ":", "case", "XmlTypeCode", "::", "Float", ":", "case", "XmlTypeCode", "::", "Double", ":", "case", "XmlTypeCode", "::", "Integer", ":", "case", "XmlTypeCode", "::", "NonPositiveInteger", ":", "case", "XmlTypeCode", "::", "NegativeInteger", ":", "case", "XmlTypeCode", "::", "Long", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "NonNegativeInteger", ":", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "case", "XmlTypeCode", "::", "PositiveInteger", ":", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true if the value is numeric @return bool
[ "Returns", "true", "if", "the", "value", "is", "numeric" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L347-L370
bseddon/XPath20
SequenceType.php
SequenceType.MatchName
private function MatchName( $nav, $context ) { return ( $this->NameTest->IsNamespaceWildcard() || $this->NameTest->namespaceURI == $nav->getNamespaceURI() ) && ($this->NameTest->IsNameWildcard() || $this->NameTest->localName == $nav->getLocalName() ); }
php
private function MatchName( $nav, $context ) { return ( $this->NameTest->IsNamespaceWildcard() || $this->NameTest->namespaceURI == $nav->getNamespaceURI() ) && ($this->NameTest->IsNameWildcard() || $this->NameTest->localName == $nav->getLocalName() ); }
[ "private", "function", "MatchName", "(", "$", "nav", ",", "$", "context", ")", "{", "return", "(", "$", "this", "->", "NameTest", "->", "IsNamespaceWildcard", "(", ")", "||", "$", "this", "->", "NameTest", "->", "namespaceURI", "==", "$", "nav", "->", "getNamespaceURI", "(", ")", ")", "&&", "(", "$", "this", "->", "NameTest", "->", "IsNameWildcard", "(", ")", "||", "$", "this", "->", "NameTest", "->", "localName", "==", "$", "nav", "->", "getLocalName", "(", ")", ")", ";", "}" ]
MatchName @param XPathNavigator $nav @param XPath2Context $context @return bool
[ "MatchName" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L387-L391
bseddon/XPath20
SequenceType.php
SequenceType.GetNodeKind
public function GetNodeKind() { switch ( $this->TypeCode ) { case XmlTypeCode::Item: return XPathNodeType::All; case XmlTypeCode::Document: return XPathNodeType::Root; case XmlTypeCode::Element: return XPathNodeType::Element; case XmlTypeCode::Attribute: return XPathNodeType::Attribute; case XmlTypeCode::Namespace_: return XPathNodeType::NamespaceURI; case XmlTypeCode::Text: return XPathNodeType::Text; case XmlTypeCode::Comment: return XPathNodeType::Comment; case XmlTypeCode::ProcessingInstruction: return XPathNodeType::ProcessingInstruction; default: throw new InvalidOperationException( "GetNodeKind()" ); } }
php
public function GetNodeKind() { switch ( $this->TypeCode ) { case XmlTypeCode::Item: return XPathNodeType::All; case XmlTypeCode::Document: return XPathNodeType::Root; case XmlTypeCode::Element: return XPathNodeType::Element; case XmlTypeCode::Attribute: return XPathNodeType::Attribute; case XmlTypeCode::Namespace_: return XPathNodeType::NamespaceURI; case XmlTypeCode::Text: return XPathNodeType::Text; case XmlTypeCode::Comment: return XPathNodeType::Comment; case XmlTypeCode::ProcessingInstruction: return XPathNodeType::ProcessingInstruction; default: throw new InvalidOperationException( "GetNodeKind()" ); } }
[ "public", "function", "GetNodeKind", "(", ")", "{", "switch", "(", "$", "this", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Item", ":", "return", "XPathNodeType", "::", "All", ";", "case", "XmlTypeCode", "::", "Document", ":", "return", "XPathNodeType", "::", "Root", ";", "case", "XmlTypeCode", "::", "Element", ":", "return", "XPathNodeType", "::", "Element", ";", "case", "XmlTypeCode", "::", "Attribute", ":", "return", "XPathNodeType", "::", "Attribute", ";", "case", "XmlTypeCode", "::", "Namespace_", ":", "return", "XPathNodeType", "::", "NamespaceURI", ";", "case", "XmlTypeCode", "::", "Text", ":", "return", "XPathNodeType", "::", "Text", ";", "case", "XmlTypeCode", "::", "Comment", ":", "return", "XPathNodeType", "::", "Comment", ";", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "return", "XPathNodeType", "::", "ProcessingInstruction", ";", "default", ":", "throw", "new", "InvalidOperationException", "(", "\"GetNodeKind()\"", ")", ";", "}", "}" ]
GetNodeKind @return XPathNodeType
[ "GetNodeKind" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L397-L420
bseddon/XPath20
SequenceType.php
SequenceType.Match
public function Match( $item, $context ) { if ( $this->TypeCode == $item->getSchemaType()->TypeCode ) return true; switch ( $this->TypeCode ) { case XmlTypeCode::None: return false; case XmlTypeCode::Item: return true; case XmlTypeCode::Node: return $item->getIsNode(); case XmlTypeCode::AnyAtomicType: return ! $item->getIsNode(); case XmlTypeCode::UntypedAtomic: return ! $item->getIsNode() && $item->GetSchemaType() == XmlSchema::$UntypedAtomic; case XmlTypeCode::Document: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Root) { /** * @var XPathNavigator $cur */ $cur = $nav->CloneInstance(); if ( is_null( $this->SchemaElement ) ) { if ( $cur->MoveToChild( XPathNodeType::Element ) && $this->MatchName( $cur, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $cur->getSchemaInfo(); if ( ! is_null( $this->schemaInfo ) ) { if ( DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) return ! $schemaInfo->getIsNil() || $this->Nillable; } else { return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } } else { if ( ! $cur->MoveToChild( XPathNodeType::Element ) ) { return false; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $cur->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) { return $schemaInfo->getSchemaElement()->QualifiedName->equals( $this->SchemaElement->QualifiedName ); } } } } break; case XmlTypeCode::Element: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Element ) { if ( is_null( $this->SchemaElement ) ) { if ( $this->MatchName( $nav, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( is_null( $schemaInfo ) ) { return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } else { if ( DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) { return ! $schemaInfo->getIsNil() || $this->Nillable; } } } } else { /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) return $schemaInfo->getSchemaElement()->QualifiedName->equals( $this->SchemaElement->QualifiedName ); } } } break; case XmlTypeCode::Attribute: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Attribute ) { if ( is_null( $this->SchemaAttribute ) ) { if ( $this->MatchName( $nav, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( is_null( $schemaInfo ) ) return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); else return DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } else { /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) return $schemaInfo->getSchemaAttribute()->QualifiedName->equals( $this->SchemaAttribute->QualifiedName ); } } } break; case XmlTypeCode::ProcessingInstruction: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return ( $nav->getNodeType() == XPathNodeType::ProcessingInstruction && ( $this->NameTest->IsNameWildcard() || $this->NameTest->localName == $nav->getLocalName() ) ); } break; case XmlTypeCode::Comment: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return $nav->getNodeType() == XPathNodeType::Comment; } break; case XmlTypeCode::Text: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return $nav->getNodeType() == XPathNodeType::Text || $nav->getNodeType() == XPathNodeType::SignificantWhitespace; } break; case XmlTypeCode::PositiveInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() >= 0; case XmlTypeCode::Long: return false; } break; case XmlTypeCode::NegativeInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() <= 0; case XmlTypeCode::Long: return false; } break; case XmlTypeCode::NonPositiveInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: return $item->getValueAsInt() <= 0; } break; case XmlTypeCode::NonNegativeInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() >= 0; case XmlTypeCode::Long: return $item->getValueAsLong() == 0; case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: return true; } break; case XmlTypeCode::Int: case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedLong: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: return true; case XmlTypeCode::Decimal: // BMS 2017-07-20 Changed result /** * @var DecimalValue $dec */ $dec = $item->getTypedValue(); return $dec->getIntegerPart() == $dec->getValue(); // BMS 2017-07-10 Changed result return false; return ! $item->ValueAs( Types::$DecimalType, $context->NamespaceManager )->getIsDecimal(); case XmlTypeCode::Double: // BMS 2017-07-10 Changed result return false; $value = $item->getTypedValue(); // ->ValueAs( Types::$DoubleType ); return $value == floor( $value ); } break; case XmlTypeCode::Entity: return ( $item->GetSchemaType()->TypeCode == XmlTypeCode::String ) || ( $item->GetSchemaType()->TypeCode == XmlTypeCode::Entity ); // In PHP these are synonymous // BMS 2017-07-10 Changed result case XmlTypeCode::Float: switch ( $item->GetSchemaType()->TypeCode ) { // Note the order of these cases is significant // If the order is different then float will be // reported as an instance of double and will fail // test instanceof49 in the exprSeqTypes test set. case XmlTypeCode::Float: return true; case XmlTypeCode::Double: if ( is_nan( $item->getTypedValue() ) ) { return true; } } break; // BMS 2017-07-10 Changed result case XmlTypeCode::Double: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Double: return true; } break; // BMS 2017-07-10 Changed result case XmlTypeCode::Decimal: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: case XmlTypeCode::Decimal: return true; } break; default: { $schemaType = $item->getSchemaType(); if ( ! is_null( $schemaType ) ) { // BMS 2017-09-03 Added this condition. The XPath documentation indicates that an // untyped type can be matched with any other type. // https://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive if ( $schemaType->TypeCode == XmlTypeCode::UntypedAtomic ) { return true; } return DOMSchemaType::IsDerivedFrom( $schemaType, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } break; } return false; }
php
public function Match( $item, $context ) { if ( $this->TypeCode == $item->getSchemaType()->TypeCode ) return true; switch ( $this->TypeCode ) { case XmlTypeCode::None: return false; case XmlTypeCode::Item: return true; case XmlTypeCode::Node: return $item->getIsNode(); case XmlTypeCode::AnyAtomicType: return ! $item->getIsNode(); case XmlTypeCode::UntypedAtomic: return ! $item->getIsNode() && $item->GetSchemaType() == XmlSchema::$UntypedAtomic; case XmlTypeCode::Document: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Root) { /** * @var XPathNavigator $cur */ $cur = $nav->CloneInstance(); if ( is_null( $this->SchemaElement ) ) { if ( $cur->MoveToChild( XPathNodeType::Element ) && $this->MatchName( $cur, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $cur->getSchemaInfo(); if ( ! is_null( $this->schemaInfo ) ) { if ( DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) return ! $schemaInfo->getIsNil() || $this->Nillable; } else { return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } } else { if ( ! $cur->MoveToChild( XPathNodeType::Element ) ) { return false; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $cur->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) { return $schemaInfo->getSchemaElement()->QualifiedName->equals( $this->SchemaElement->QualifiedName ); } } } } break; case XmlTypeCode::Element: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Element ) { if ( is_null( $this->SchemaElement ) ) { if ( $this->MatchName( $nav, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( is_null( $schemaInfo ) ) { return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } else { if ( DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) { return ! $schemaInfo->getIsNil() || $this->Nillable; } } } } else { /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) return $schemaInfo->getSchemaElement()->QualifiedName->equals( $this->SchemaElement->QualifiedName ); } } } break; case XmlTypeCode::Attribute: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; if ( $nav->getNodeType() == XPathNodeType::Attribute ) { if ( is_null( $this->SchemaAttribute ) ) { if ( $this->MatchName( $nav, $context ) ) { if ( is_null( $this->SchemaType ) || $this->SchemaType == XmlSchema::$UntypedAtomic ) { return true; } /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( is_null( $schemaInfo ) ) return DOMSchemaType::IsDerivedFrom( XmlSchema::$UntypedAtomic, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); else return DOMSchemaType::IsDerivedFrom( $schemaInfo->getSchemaType(), $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } else { /** * @var IXmlSchemaInfo $schemaInfo */ $schemaInfo = $nav->getSchemaInfo(); if ( ! is_null( $schemaInfo ) ) return $schemaInfo->getSchemaAttribute()->QualifiedName->equals( $this->SchemaAttribute->QualifiedName ); } } } break; case XmlTypeCode::ProcessingInstruction: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return ( $nav->getNodeType() == XPathNodeType::ProcessingInstruction && ( $this->NameTest->IsNameWildcard() || $this->NameTest->localName == $nav->getLocalName() ) ); } break; case XmlTypeCode::Comment: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return $nav->getNodeType() == XPathNodeType::Comment; } break; case XmlTypeCode::Text: if ( $item instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $item; return $nav->getNodeType() == XPathNodeType::Text || $nav->getNodeType() == XPathNodeType::SignificantWhitespace; } break; case XmlTypeCode::PositiveInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() >= 0; case XmlTypeCode::Long: return false; } break; case XmlTypeCode::NegativeInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() <= 0; case XmlTypeCode::Long: return false; } break; case XmlTypeCode::NonPositiveInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: return $item->getValueAsInt() <= 0; } break; case XmlTypeCode::NonNegativeInteger: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Integer: return $item->getValueAsInt() >= 0; case XmlTypeCode::Long: return $item->getValueAsLong() == 0; case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: return true; } break; case XmlTypeCode::Int: case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedLong: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: return true; case XmlTypeCode::Decimal: // BMS 2017-07-20 Changed result /** * @var DecimalValue $dec */ $dec = $item->getTypedValue(); return $dec->getIntegerPart() == $dec->getValue(); // BMS 2017-07-10 Changed result return false; return ! $item->ValueAs( Types::$DecimalType, $context->NamespaceManager )->getIsDecimal(); case XmlTypeCode::Double: // BMS 2017-07-10 Changed result return false; $value = $item->getTypedValue(); // ->ValueAs( Types::$DoubleType ); return $value == floor( $value ); } break; case XmlTypeCode::Entity: return ( $item->GetSchemaType()->TypeCode == XmlTypeCode::String ) || ( $item->GetSchemaType()->TypeCode == XmlTypeCode::Entity ); // In PHP these are synonymous // BMS 2017-07-10 Changed result case XmlTypeCode::Float: switch ( $item->GetSchemaType()->TypeCode ) { // Note the order of these cases is significant // If the order is different then float will be // reported as an instance of double and will fail // test instanceof49 in the exprSeqTypes test set. case XmlTypeCode::Float: return true; case XmlTypeCode::Double: if ( is_nan( $item->getTypedValue() ) ) { return true; } } break; // BMS 2017-07-10 Changed result case XmlTypeCode::Double: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Double: return true; } break; // BMS 2017-07-10 Changed result case XmlTypeCode::Decimal: switch ( $item->GetSchemaType()->TypeCode ) { case XmlTypeCode::Byte: case XmlTypeCode::Short: case XmlTypeCode::Int: case XmlTypeCode::Long: case XmlTypeCode::Integer: case XmlTypeCode::UnsignedByte: case XmlTypeCode::UnsignedShort: case XmlTypeCode::UnsignedInt: case XmlTypeCode::UnsignedLong: case XmlTypeCode::Decimal: return true; } break; default: { $schemaType = $item->getSchemaType(); if ( ! is_null( $schemaType ) ) { // BMS 2017-09-03 Added this condition. The XPath documentation indicates that an // untyped type can be matched with any other type. // https://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive if ( $schemaType->TypeCode == XmlTypeCode::UntypedAtomic ) { return true; } return DOMSchemaType::IsDerivedFrom( $schemaType, $this->SchemaType, XmlSchemaDerivationMethod::Empty_ ); } } break; } return false; }
[ "public", "function", "Match", "(", "$", "item", ",", "$", "context", ")", "{", "if", "(", "$", "this", "->", "TypeCode", "==", "$", "item", "->", "getSchemaType", "(", ")", "->", "TypeCode", ")", "return", "true", ";", "switch", "(", "$", "this", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "None", ":", "return", "false", ";", "case", "XmlTypeCode", "::", "Item", ":", "return", "true", ";", "case", "XmlTypeCode", "::", "Node", ":", "return", "$", "item", "->", "getIsNode", "(", ")", ";", "case", "XmlTypeCode", "::", "AnyAtomicType", ":", "return", "!", "$", "item", "->", "getIsNode", "(", ")", ";", "case", "XmlTypeCode", "::", "UntypedAtomic", ":", "return", "!", "$", "item", "->", "getIsNode", "(", ")", "&&", "$", "item", "->", "GetSchemaType", "(", ")", "==", "XmlSchema", "::", "$", "UntypedAtomic", ";", "case", "XmlTypeCode", "::", "Document", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t\t * @var XPathNavigator $nav\r\n\t\t\t\t\t */", "$", "nav", "=", "$", "item", ";", "if", "(", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "Root", ")", "{", "/**\r\n\t\t\t\t\t\t * @var XPathNavigator $cur\r\n\t\t\t\t\t\t */", "$", "cur", "=", "$", "nav", "->", "CloneInstance", "(", ")", ";", "if", "(", "is_null", "(", "$", "this", "->", "SchemaElement", ")", ")", "{", "if", "(", "$", "cur", "->", "MoveToChild", "(", "XPathNodeType", "::", "Element", ")", "&&", "$", "this", "->", "MatchName", "(", "$", "cur", ",", "$", "context", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "SchemaType", ")", "||", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "UntypedAtomic", ")", "{", "return", "true", ";", "}", "/**\r\n\t\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "cur", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "schemaInfo", ")", ")", "{", "if", "(", "DOMSchemaType", "::", "IsDerivedFrom", "(", "$", "schemaInfo", "->", "getSchemaType", "(", ")", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ")", "return", "!", "$", "schemaInfo", "->", "getIsNil", "(", ")", "||", "$", "this", "->", "Nillable", ";", "}", "else", "{", "return", "DOMSchemaType", "::", "IsDerivedFrom", "(", "XmlSchema", "::", "$", "UntypedAtomic", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ";", "}", "}", "}", "else", "{", "if", "(", "!", "$", "cur", "->", "MoveToChild", "(", "XPathNodeType", "::", "Element", ")", ")", "{", "return", "false", ";", "}", "/**\r\n\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "cur", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "schemaInfo", ")", ")", "{", "return", "$", "schemaInfo", "->", "getSchemaElement", "(", ")", "->", "QualifiedName", "->", "equals", "(", "$", "this", "->", "SchemaElement", "->", "QualifiedName", ")", ";", "}", "}", "}", "}", "break", ";", "case", "XmlTypeCode", "::", "Element", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t \t * @var XPathNavigator $nav\r\n\t\t\t\t \t */", "$", "nav", "=", "$", "item", ";", "if", "(", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "Element", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "SchemaElement", ")", ")", "{", "if", "(", "$", "this", "->", "MatchName", "(", "$", "nav", ",", "$", "context", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "SchemaType", ")", "||", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "UntypedAtomic", ")", "{", "return", "true", ";", "}", "/**\r\n\t\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "nav", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "is_null", "(", "$", "schemaInfo", ")", ")", "{", "return", "DOMSchemaType", "::", "IsDerivedFrom", "(", "XmlSchema", "::", "$", "UntypedAtomic", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ";", "}", "else", "{", "if", "(", "DOMSchemaType", "::", "IsDerivedFrom", "(", "$", "schemaInfo", "->", "getSchemaType", "(", ")", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ")", "{", "return", "!", "$", "schemaInfo", "->", "getIsNil", "(", ")", "||", "$", "this", "->", "Nillable", ";", "}", "}", "}", "}", "else", "{", "/**\r\n\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "nav", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "schemaInfo", ")", ")", "return", "$", "schemaInfo", "->", "getSchemaElement", "(", ")", "->", "QualifiedName", "->", "equals", "(", "$", "this", "->", "SchemaElement", "->", "QualifiedName", ")", ";", "}", "}", "}", "break", ";", "case", "XmlTypeCode", "::", "Attribute", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t\t * @var XPathNavigator $nav\r\n\t\t\t\t\t */", "$", "nav", "=", "$", "item", ";", "if", "(", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "Attribute", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "SchemaAttribute", ")", ")", "{", "if", "(", "$", "this", "->", "MatchName", "(", "$", "nav", ",", "$", "context", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "SchemaType", ")", "||", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "UntypedAtomic", ")", "{", "return", "true", ";", "}", "/**\r\n\t\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "nav", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "is_null", "(", "$", "schemaInfo", ")", ")", "return", "DOMSchemaType", "::", "IsDerivedFrom", "(", "XmlSchema", "::", "$", "UntypedAtomic", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ";", "else", "return", "DOMSchemaType", "::", "IsDerivedFrom", "(", "$", "schemaInfo", "->", "getSchemaType", "(", ")", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ";", "}", "}", "else", "{", "/**\r\n\t\t\t\t\t\t\t * @var IXmlSchemaInfo $schemaInfo\r\n\t\t\t\t\t\t\t */", "$", "schemaInfo", "=", "$", "nav", "->", "getSchemaInfo", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "schemaInfo", ")", ")", "return", "$", "schemaInfo", "->", "getSchemaAttribute", "(", ")", "->", "QualifiedName", "->", "equals", "(", "$", "this", "->", "SchemaAttribute", "->", "QualifiedName", ")", ";", "}", "}", "}", "break", ";", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t\t * @var XPathNavigator $nav\r\n\t\t\t\t\t */", "$", "nav", "=", "$", "item", ";", "return", "(", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "ProcessingInstruction", "&&", "(", "$", "this", "->", "NameTest", "->", "IsNameWildcard", "(", ")", "||", "$", "this", "->", "NameTest", "->", "localName", "==", "$", "nav", "->", "getLocalName", "(", ")", ")", ")", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "Comment", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t\t * @var XPathNavigator $nav\r\n\t\t\t\t\t */", "$", "nav", "=", "$", "item", ";", "return", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "Comment", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "Text", ":", "if", "(", "$", "item", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t\t\t * @var XPathNavigator $nav\r\n\t\t\t\t\t */", "$", "nav", "=", "$", "item", ";", "return", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "Text", "||", "$", "nav", "->", "getNodeType", "(", ")", "==", "XPathNodeType", "::", "SignificantWhitespace", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "PositiveInteger", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Integer", ":", "return", "$", "item", "->", "getValueAsInt", "(", ")", ">=", "0", ";", "case", "XmlTypeCode", "::", "Long", ":", "return", "false", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "NegativeInteger", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Integer", ":", "return", "$", "item", "->", "getValueAsInt", "(", ")", "<=", "0", ";", "case", "XmlTypeCode", "::", "Long", ":", "return", "false", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "NonPositiveInteger", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Long", ":", "case", "XmlTypeCode", "::", "Integer", ":", "return", "$", "item", "->", "getValueAsInt", "(", ")", "<=", "0", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "NonNegativeInteger", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Integer", ":", "return", "$", "item", "->", "getValueAsInt", "(", ")", ">=", "0", ";", "case", "XmlTypeCode", "::", "Long", ":", "return", "$", "item", "->", "getValueAsLong", "(", ")", "==", "0", ";", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "return", "true", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Long", ":", "case", "XmlTypeCode", "::", "Integer", ":", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Long", ":", "case", "XmlTypeCode", "::", "Integer", ":", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "return", "true", ";", "case", "XmlTypeCode", "::", "Decimal", ":", "// BMS 2017-07-20 Changed result\r", "/**\r\n\t\t\t\t\t\t * @var DecimalValue $dec\r\n\t\t\t\t\t\t */", "$", "dec", "=", "$", "item", "->", "getTypedValue", "(", ")", ";", "return", "$", "dec", "->", "getIntegerPart", "(", ")", "==", "$", "dec", "->", "getValue", "(", ")", ";", "// BMS 2017-07-10 Changed result\r", "return", "false", ";", "return", "!", "$", "item", "->", "ValueAs", "(", "Types", "::", "$", "DecimalType", ",", "$", "context", "->", "NamespaceManager", ")", "->", "getIsDecimal", "(", ")", ";", "case", "XmlTypeCode", "::", "Double", ":", "// BMS 2017-07-10 Changed result\r", "return", "false", ";", "$", "value", "=", "$", "item", "->", "getTypedValue", "(", ")", ";", "// ->ValueAs( Types::$DoubleType );\r", "return", "$", "value", "==", "floor", "(", "$", "value", ")", ";", "}", "break", ";", "case", "XmlTypeCode", "::", "Entity", ":", "return", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", "==", "XmlTypeCode", "::", "String", ")", "||", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", "==", "XmlTypeCode", "::", "Entity", ")", ";", "// In PHP these are synonymous\r", "// BMS 2017-07-10 Changed result\r", "case", "XmlTypeCode", "::", "Float", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "// Note the order of these cases is significant\r", "// If the order is different then float will be\r", "// reported as an instance of double and will fail\r", "// test instanceof49 in the exprSeqTypes test set.\r", "case", "XmlTypeCode", "::", "Float", ":", "return", "true", ";", "case", "XmlTypeCode", "::", "Double", ":", "if", "(", "is_nan", "(", "$", "item", "->", "getTypedValue", "(", ")", ")", ")", "{", "return", "true", ";", "}", "}", "break", ";", "// BMS 2017-07-10 Changed result\r", "case", "XmlTypeCode", "::", "Double", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Double", ":", "return", "true", ";", "}", "break", ";", "// BMS 2017-07-10 Changed result\r", "case", "XmlTypeCode", "::", "Decimal", ":", "switch", "(", "$", "item", "->", "GetSchemaType", "(", ")", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Byte", ":", "case", "XmlTypeCode", "::", "Short", ":", "case", "XmlTypeCode", "::", "Int", ":", "case", "XmlTypeCode", "::", "Long", ":", "case", "XmlTypeCode", "::", "Integer", ":", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "case", "XmlTypeCode", "::", "Decimal", ":", "return", "true", ";", "}", "break", ";", "default", ":", "{", "$", "schemaType", "=", "$", "item", "->", "getSchemaType", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "schemaType", ")", ")", "{", "// BMS 2017-09-03\tAdded this condition. The XPath documentation indicates that an\r", "//\t\t\t\t\tuntyped type can be matched with any other type.\r", "// https://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive\r", "if", "(", "$", "schemaType", "->", "TypeCode", "==", "XmlTypeCode", "::", "UntypedAtomic", ")", "{", "return", "true", ";", "}", "return", "DOMSchemaType", "::", "IsDerivedFrom", "(", "$", "schemaType", ",", "$", "this", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ";", "}", "}", "break", ";", "}", "return", "false", ";", "}" ]
Match @param XPathItem $item @param XPath2Context $context @return bool
[ "Match" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L428-L802
bseddon/XPath20
SequenceType.php
SequenceType.ToString
public function ToString() { $sb = array(); switch ( $this->TypeCode ) { case XmlTypeCode::AnyAtomicType: $sb[] = "AnyAtomicType"; break; case XmlTypeCode::UntypedAtomic: $sb[] = "UntypedAtomic"; break; case XmlTypeCode::None: $sb[] = "empty-sequence()"; break; case XmlTypeCode::Item: $sb[] = "item()"; break; case XmlTypeCode::Node: $sb[] = "node()"; break; case XmlTypeCode::Document: $sb[] = "document-node("; if ( is_null( $this->SchemaElement ) ) { if ( ! $this->NameTest->IsWildcard() || is_null( $this->SchemaType ) ) { $sb[] = "element("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); if ( $this->Nillable ) $sb[] = "?"; } else { $sb[] = ", xs:untyped"; } $sb[] = ")"; } } else { $sb[] = "schema-element("; $sb[] = $this->SchemaElement->QualifiedName->__toString(); $sb[] = ")"; } $sb[] = ")"; break; case XmlTypeCode::Element: if ( is_null( $this->SchemaElement ) ) { $sb[] = "element("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); if ( $this->Nillable ) { $sb[] = "?"; } } else { $sb[] = ", xs:untyped"; } } else { $sb[] = "schema-element("; $sb[] = $this->SchemaElement->QualifiedName->__toString(); } $sb[] = ")"; break; case XmlTypeCode::Attribute: if ( is_null( $this->SchemaAttribute ) ) { $sb[] = "attribute("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); } } else { $sb[] = "schema-attribute("; $sb[] = $this->SchemaAttribute->QualifiedName; } $sb[] = ")"; break; case XmlTypeCode::ProcessingInstruction: $sb[] = "processing-instruction("; break; case XmlTypeCode::Comment: $sb[] = "comment()"; break; case XmlTypeCode::Text: $sb[] = "text()"; break; case XmlTypeCode::String: $sb[] = "xs:string"; break; case XmlTypeCode::Boolean: $sb[] = "xs:boolean"; break; case XmlTypeCode::Decimal: $sb[] = "xs:decimal"; break; case XmlTypeCode::Float: $sb[] = "xs:float"; break; case XmlTypeCode::Double: $sb[] = "xs:double"; break; case XmlTypeCode::Duration: $sb[] = "xs:Duration"; break; case XmlTypeCode::DateTime: $sb[] = "xs:dateTime"; break; case XmlTypeCode::Time: $sb[] = "xs:time"; break; case XmlTypeCode::Date: $sb[] = "xs:date"; break; case XmlTypeCode::GYearMonth: $sb[] = "xs:gYearMonth"; break; case XmlTypeCode::GYear: $sb[] = "xs:gYear"; break; case XmlTypeCode::GMonthDay: $sb[] = "xs:gMonthDay"; break; case XmlTypeCode::GDay: $sb[] = "xs:gDay"; break; case XmlTypeCode::GMonth: $sb[] = "xs:gMonth"; break; case XmlTypeCode::HexBinary: $sb[] = "xs:hexBinary"; break; case XmlTypeCode::Base64Binary: $sb[] = "xs:base64Binary"; break; case XmlTypeCode::AnyUri: $sb[] = "xs:anyURI"; break; case XmlTypeCode::QName: $sb[] = "xs:QName"; break; case XmlTypeCode::Notation: $sb[] = "xs:NOTATION"; break; case XmlTypeCode::NormalizedString: $sb[] = "xs:normalizedString"; break; case XmlTypeCode::Token: $sb[] = "xs:token"; break; case XmlTypeCode::Language: $sb[] = "xs:language"; break; case XmlTypeCode::NmToken: if ( $this->SchemaType == XmlSchema::$NMTOKENS ) $sb[] = "xs:NMTOKENS"; else $sb[] = "xs:NMTOKEN"; break; case XmlTypeCode::Name: $sb[] = "xs:Name"; break; case XmlTypeCode::NCName: $sb[] = "xs:NCName"; break; case XmlTypeCode::Id: $sb[] = "xs:ID"; break; case XmlTypeCode::Idref: if ( $this->SchemaType == XmlSchema::$IDREFS ) $sb[] = "xs:IDREFS"; else $sb[] = "xs:IDREF"; break; case XmlTypeCode::Entity: if ( $this->SchemaType == XmlSchema::$ENTITIES ) $sb[] = "xs:ENTITYS"; else $sb[] = "xs:ENTITY"; break; case XmlTypeCode::Integer: $sb[] = "xs:integer"; break; case XmlTypeCode::NonPositiveInteger: $sb[] = "xs:nonPositiveInteger"; break; case XmlTypeCode::NegativeInteger: $sb[] = "xs:negativeInteger"; break; case XmlTypeCode::Long: $sb[] = "xs:long"; break; case XmlTypeCode::Int: $sb[] = "xs:int"; break; case XmlTypeCode::Short: $sb[] = "xs:short"; break; case XmlTypeCode::Byte: $sb[] = "xs:byte"; break; case XmlTypeCode::NonNegativeInteger: $sb[] = "xs:nonNegativeInteger"; break; case XmlTypeCode::UnsignedLong: $sb[] = "xs:unsignedLong"; break; case XmlTypeCode::UnsignedInt: $sb[] = "xs:unsignedInt"; break; case XmlTypeCode::UnsignedShort: $sb[] = "xs:unsignedShort"; break; case XmlTypeCode::UnsignedByte: $sb[] = "xs:unsignedByte"; break; case XmlTypeCode::PositiveInteger: $sb[] = "xs:positiveInteger"; break; case XmlTypeCode::DayTimeDuration: $sb[] = "xs:dayTimeDuration"; break; case XmlTypeCode::YearMonthDuration: $sb[] = "xs:yearMonthDuration"; break; default: $sb[] = "[]"; break; } switch ( $this->Cardinality ) { case XmlTypeCardinality::OneOrMore: $sb[] = "+"; break; case XmlTypeCardinality::ZeroOrMore: $sb[] = "*"; break; case XmlTypeCardinality::ZeroOrOne: $sb[] = "?"; break; } return implode( "", $sb ); }
php
public function ToString() { $sb = array(); switch ( $this->TypeCode ) { case XmlTypeCode::AnyAtomicType: $sb[] = "AnyAtomicType"; break; case XmlTypeCode::UntypedAtomic: $sb[] = "UntypedAtomic"; break; case XmlTypeCode::None: $sb[] = "empty-sequence()"; break; case XmlTypeCode::Item: $sb[] = "item()"; break; case XmlTypeCode::Node: $sb[] = "node()"; break; case XmlTypeCode::Document: $sb[] = "document-node("; if ( is_null( $this->SchemaElement ) ) { if ( ! $this->NameTest->IsWildcard() || is_null( $this->SchemaType ) ) { $sb[] = "element("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); if ( $this->Nillable ) $sb[] = "?"; } else { $sb[] = ", xs:untyped"; } $sb[] = ")"; } } else { $sb[] = "schema-element("; $sb[] = $this->SchemaElement->QualifiedName->__toString(); $sb[] = ")"; } $sb[] = ")"; break; case XmlTypeCode::Element: if ( is_null( $this->SchemaElement ) ) { $sb[] = "element("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); if ( $this->Nillable ) { $sb[] = "?"; } } else { $sb[] = ", xs:untyped"; } } else { $sb[] = "schema-element("; $sb[] = $this->SchemaElement->QualifiedName->__toString(); } $sb[] = ")"; break; case XmlTypeCode::Attribute: if ( is_null( $this->SchemaAttribute ) ) { $sb[] = "attribute("; $sb[] = $this->NameTest->ToString(); if ( ! is_null( $this->SchemaType ) ) { $sb[] = ","; $sb[] = get_class( $this->SchemaType ); } } else { $sb[] = "schema-attribute("; $sb[] = $this->SchemaAttribute->QualifiedName; } $sb[] = ")"; break; case XmlTypeCode::ProcessingInstruction: $sb[] = "processing-instruction("; break; case XmlTypeCode::Comment: $sb[] = "comment()"; break; case XmlTypeCode::Text: $sb[] = "text()"; break; case XmlTypeCode::String: $sb[] = "xs:string"; break; case XmlTypeCode::Boolean: $sb[] = "xs:boolean"; break; case XmlTypeCode::Decimal: $sb[] = "xs:decimal"; break; case XmlTypeCode::Float: $sb[] = "xs:float"; break; case XmlTypeCode::Double: $sb[] = "xs:double"; break; case XmlTypeCode::Duration: $sb[] = "xs:Duration"; break; case XmlTypeCode::DateTime: $sb[] = "xs:dateTime"; break; case XmlTypeCode::Time: $sb[] = "xs:time"; break; case XmlTypeCode::Date: $sb[] = "xs:date"; break; case XmlTypeCode::GYearMonth: $sb[] = "xs:gYearMonth"; break; case XmlTypeCode::GYear: $sb[] = "xs:gYear"; break; case XmlTypeCode::GMonthDay: $sb[] = "xs:gMonthDay"; break; case XmlTypeCode::GDay: $sb[] = "xs:gDay"; break; case XmlTypeCode::GMonth: $sb[] = "xs:gMonth"; break; case XmlTypeCode::HexBinary: $sb[] = "xs:hexBinary"; break; case XmlTypeCode::Base64Binary: $sb[] = "xs:base64Binary"; break; case XmlTypeCode::AnyUri: $sb[] = "xs:anyURI"; break; case XmlTypeCode::QName: $sb[] = "xs:QName"; break; case XmlTypeCode::Notation: $sb[] = "xs:NOTATION"; break; case XmlTypeCode::NormalizedString: $sb[] = "xs:normalizedString"; break; case XmlTypeCode::Token: $sb[] = "xs:token"; break; case XmlTypeCode::Language: $sb[] = "xs:language"; break; case XmlTypeCode::NmToken: if ( $this->SchemaType == XmlSchema::$NMTOKENS ) $sb[] = "xs:NMTOKENS"; else $sb[] = "xs:NMTOKEN"; break; case XmlTypeCode::Name: $sb[] = "xs:Name"; break; case XmlTypeCode::NCName: $sb[] = "xs:NCName"; break; case XmlTypeCode::Id: $sb[] = "xs:ID"; break; case XmlTypeCode::Idref: if ( $this->SchemaType == XmlSchema::$IDREFS ) $sb[] = "xs:IDREFS"; else $sb[] = "xs:IDREF"; break; case XmlTypeCode::Entity: if ( $this->SchemaType == XmlSchema::$ENTITIES ) $sb[] = "xs:ENTITYS"; else $sb[] = "xs:ENTITY"; break; case XmlTypeCode::Integer: $sb[] = "xs:integer"; break; case XmlTypeCode::NonPositiveInteger: $sb[] = "xs:nonPositiveInteger"; break; case XmlTypeCode::NegativeInteger: $sb[] = "xs:negativeInteger"; break; case XmlTypeCode::Long: $sb[] = "xs:long"; break; case XmlTypeCode::Int: $sb[] = "xs:int"; break; case XmlTypeCode::Short: $sb[] = "xs:short"; break; case XmlTypeCode::Byte: $sb[] = "xs:byte"; break; case XmlTypeCode::NonNegativeInteger: $sb[] = "xs:nonNegativeInteger"; break; case XmlTypeCode::UnsignedLong: $sb[] = "xs:unsignedLong"; break; case XmlTypeCode::UnsignedInt: $sb[] = "xs:unsignedInt"; break; case XmlTypeCode::UnsignedShort: $sb[] = "xs:unsignedShort"; break; case XmlTypeCode::UnsignedByte: $sb[] = "xs:unsignedByte"; break; case XmlTypeCode::PositiveInteger: $sb[] = "xs:positiveInteger"; break; case XmlTypeCode::DayTimeDuration: $sb[] = "xs:dayTimeDuration"; break; case XmlTypeCode::YearMonthDuration: $sb[] = "xs:yearMonthDuration"; break; default: $sb[] = "[]"; break; } switch ( $this->Cardinality ) { case XmlTypeCardinality::OneOrMore: $sb[] = "+"; break; case XmlTypeCardinality::ZeroOrMore: $sb[] = "*"; break; case XmlTypeCardinality::ZeroOrOne: $sb[] = "?"; break; } return implode( "", $sb ); }
[ "public", "function", "ToString", "(", ")", "{", "$", "sb", "=", "array", "(", ")", ";", "switch", "(", "$", "this", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "AnyAtomicType", ":", "$", "sb", "[", "]", "=", "\"AnyAtomicType\"", ";", "break", ";", "case", "XmlTypeCode", "::", "UntypedAtomic", ":", "$", "sb", "[", "]", "=", "\"UntypedAtomic\"", ";", "break", ";", "case", "XmlTypeCode", "::", "None", ":", "$", "sb", "[", "]", "=", "\"empty-sequence()\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Item", ":", "$", "sb", "[", "]", "=", "\"item()\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Node", ":", "$", "sb", "[", "]", "=", "\"node()\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Document", ":", "$", "sb", "[", "]", "=", "\"document-node(\"", ";", "if", "(", "is_null", "(", "$", "this", "->", "SchemaElement", ")", ")", "{", "if", "(", "!", "$", "this", "->", "NameTest", "->", "IsWildcard", "(", ")", "||", "is_null", "(", "$", "this", "->", "SchemaType", ")", ")", "{", "$", "sb", "[", "]", "=", "\"element(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "NameTest", "->", "ToString", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", ")", "{", "$", "sb", "[", "]", "=", "\",\"", ";", "$", "sb", "[", "]", "=", "get_class", "(", "$", "this", "->", "SchemaType", ")", ";", "if", "(", "$", "this", "->", "Nillable", ")", "$", "sb", "[", "]", "=", "\"?\"", ";", "}", "else", "{", "$", "sb", "[", "]", "=", "\", xs:untyped\"", ";", "}", "$", "sb", "[", "]", "=", "\")\"", ";", "}", "}", "else", "{", "$", "sb", "[", "]", "=", "\"schema-element(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "SchemaElement", "->", "QualifiedName", "->", "__toString", "(", ")", ";", "$", "sb", "[", "]", "=", "\")\"", ";", "}", "$", "sb", "[", "]", "=", "\")\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Element", ":", "if", "(", "is_null", "(", "$", "this", "->", "SchemaElement", ")", ")", "{", "$", "sb", "[", "]", "=", "\"element(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "NameTest", "->", "ToString", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", ")", "{", "$", "sb", "[", "]", "=", "\",\"", ";", "$", "sb", "[", "]", "=", "get_class", "(", "$", "this", "->", "SchemaType", ")", ";", "if", "(", "$", "this", "->", "Nillable", ")", "{", "$", "sb", "[", "]", "=", "\"?\"", ";", "}", "}", "else", "{", "$", "sb", "[", "]", "=", "\", xs:untyped\"", ";", "}", "}", "else", "{", "$", "sb", "[", "]", "=", "\"schema-element(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "SchemaElement", "->", "QualifiedName", "->", "__toString", "(", ")", ";", "}", "$", "sb", "[", "]", "=", "\")\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Attribute", ":", "if", "(", "is_null", "(", "$", "this", "->", "SchemaAttribute", ")", ")", "{", "$", "sb", "[", "]", "=", "\"attribute(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "NameTest", "->", "ToString", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", ")", "{", "$", "sb", "[", "]", "=", "\",\"", ";", "$", "sb", "[", "]", "=", "get_class", "(", "$", "this", "->", "SchemaType", ")", ";", "}", "}", "else", "{", "$", "sb", "[", "]", "=", "\"schema-attribute(\"", ";", "$", "sb", "[", "]", "=", "$", "this", "->", "SchemaAttribute", "->", "QualifiedName", ";", "}", "$", "sb", "[", "]", "=", "\")\"", ";", "break", ";", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "$", "sb", "[", "]", "=", "\"processing-instruction(\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Comment", ":", "$", "sb", "[", "]", "=", "\"comment()\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Text", ":", "$", "sb", "[", "]", "=", "\"text()\"", ";", "break", ";", "case", "XmlTypeCode", "::", "String", ":", "$", "sb", "[", "]", "=", "\"xs:string\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Boolean", ":", "$", "sb", "[", "]", "=", "\"xs:boolean\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Decimal", ":", "$", "sb", "[", "]", "=", "\"xs:decimal\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Float", ":", "$", "sb", "[", "]", "=", "\"xs:float\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Double", ":", "$", "sb", "[", "]", "=", "\"xs:double\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Duration", ":", "$", "sb", "[", "]", "=", "\"xs:Duration\"", ";", "break", ";", "case", "XmlTypeCode", "::", "DateTime", ":", "$", "sb", "[", "]", "=", "\"xs:dateTime\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Time", ":", "$", "sb", "[", "]", "=", "\"xs:time\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Date", ":", "$", "sb", "[", "]", "=", "\"xs:date\"", ";", "break", ";", "case", "XmlTypeCode", "::", "GYearMonth", ":", "$", "sb", "[", "]", "=", "\"xs:gYearMonth\"", ";", "break", ";", "case", "XmlTypeCode", "::", "GYear", ":", "$", "sb", "[", "]", "=", "\"xs:gYear\"", ";", "break", ";", "case", "XmlTypeCode", "::", "GMonthDay", ":", "$", "sb", "[", "]", "=", "\"xs:gMonthDay\"", ";", "break", ";", "case", "XmlTypeCode", "::", "GDay", ":", "$", "sb", "[", "]", "=", "\"xs:gDay\"", ";", "break", ";", "case", "XmlTypeCode", "::", "GMonth", ":", "$", "sb", "[", "]", "=", "\"xs:gMonth\"", ";", "break", ";", "case", "XmlTypeCode", "::", "HexBinary", ":", "$", "sb", "[", "]", "=", "\"xs:hexBinary\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Base64Binary", ":", "$", "sb", "[", "]", "=", "\"xs:base64Binary\"", ";", "break", ";", "case", "XmlTypeCode", "::", "AnyUri", ":", "$", "sb", "[", "]", "=", "\"xs:anyURI\"", ";", "break", ";", "case", "XmlTypeCode", "::", "QName", ":", "$", "sb", "[", "]", "=", "\"xs:QName\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Notation", ":", "$", "sb", "[", "]", "=", "\"xs:NOTATION\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NormalizedString", ":", "$", "sb", "[", "]", "=", "\"xs:normalizedString\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Token", ":", "$", "sb", "[", "]", "=", "\"xs:token\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Language", ":", "$", "sb", "[", "]", "=", "\"xs:language\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NmToken", ":", "if", "(", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "NMTOKENS", ")", "$", "sb", "[", "]", "=", "\"xs:NMTOKENS\"", ";", "else", "$", "sb", "[", "]", "=", "\"xs:NMTOKEN\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Name", ":", "$", "sb", "[", "]", "=", "\"xs:Name\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NCName", ":", "$", "sb", "[", "]", "=", "\"xs:NCName\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Id", ":", "$", "sb", "[", "]", "=", "\"xs:ID\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Idref", ":", "if", "(", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "IDREFS", ")", "$", "sb", "[", "]", "=", "\"xs:IDREFS\"", ";", "else", "$", "sb", "[", "]", "=", "\"xs:IDREF\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Entity", ":", "if", "(", "$", "this", "->", "SchemaType", "==", "XmlSchema", "::", "$", "ENTITIES", ")", "$", "sb", "[", "]", "=", "\"xs:ENTITYS\"", ";", "else", "$", "sb", "[", "]", "=", "\"xs:ENTITY\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Integer", ":", "$", "sb", "[", "]", "=", "\"xs:integer\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NonPositiveInteger", ":", "$", "sb", "[", "]", "=", "\"xs:nonPositiveInteger\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NegativeInteger", ":", "$", "sb", "[", "]", "=", "\"xs:negativeInteger\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Long", ":", "$", "sb", "[", "]", "=", "\"xs:long\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Int", ":", "$", "sb", "[", "]", "=", "\"xs:int\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Short", ":", "$", "sb", "[", "]", "=", "\"xs:short\"", ";", "break", ";", "case", "XmlTypeCode", "::", "Byte", ":", "$", "sb", "[", "]", "=", "\"xs:byte\"", ";", "break", ";", "case", "XmlTypeCode", "::", "NonNegativeInteger", ":", "$", "sb", "[", "]", "=", "\"xs:nonNegativeInteger\"", ";", "break", ";", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "$", "sb", "[", "]", "=", "\"xs:unsignedLong\"", ";", "break", ";", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "$", "sb", "[", "]", "=", "\"xs:unsignedInt\"", ";", "break", ";", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "$", "sb", "[", "]", "=", "\"xs:unsignedShort\"", ";", "break", ";", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "$", "sb", "[", "]", "=", "\"xs:unsignedByte\"", ";", "break", ";", "case", "XmlTypeCode", "::", "PositiveInteger", ":", "$", "sb", "[", "]", "=", "\"xs:positiveInteger\"", ";", "break", ";", "case", "XmlTypeCode", "::", "DayTimeDuration", ":", "$", "sb", "[", "]", "=", "\"xs:dayTimeDuration\"", ";", "break", ";", "case", "XmlTypeCode", "::", "YearMonthDuration", ":", "$", "sb", "[", "]", "=", "\"xs:yearMonthDuration\"", ";", "break", ";", "default", ":", "$", "sb", "[", "]", "=", "\"[]\"", ";", "break", ";", "}", "switch", "(", "$", "this", "->", "Cardinality", ")", "{", "case", "XmlTypeCardinality", "::", "OneOrMore", ":", "$", "sb", "[", "]", "=", "\"+\"", ";", "break", ";", "case", "XmlTypeCardinality", "::", "ZeroOrMore", ":", "$", "sb", "[", "]", "=", "\"*\"", ";", "break", ";", "case", "XmlTypeCardinality", "::", "ZeroOrOne", ":", "$", "sb", "[", "]", "=", "\"?\"", ";", "break", ";", "}", "return", "implode", "(", "\"\"", ",", "$", "sb", ")", ";", "}" ]
ToString @return string
[ "ToString" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L817-L1133
bseddon/XPath20
SequenceType.php
SequenceType.GetXmlTypeCodeFromObject
static public function GetXmlTypeCodeFromObject( $value ) { if ( $value instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $value; switch ( $nav->getNodeType() ) { case XPathNodeType::Attribute: return XmlTypeCode::Attribute; case XPathNodeType::Comment: return XmlTypeCode::Comment; case XPathNodeType::Element: return XmlTypeCode::Element; case XPathNodeType::NamespaceURI: return XmlTypeCode::Namespace_; case XPathNodeType::ProcessingInstruction: return XmlTypeCode::ProcessingInstruction; case XPathNodeType::Root: return XmlTypeCode::Document; case XPathNodeType::SignificantWhitespace: case XPathNodeType::Whitespace: case XPathNodeType::Text: return XmlTypeCode::Text; default: return XmlTypeCode::None; } } if ( $value instanceof XPathItem ) { /** * @var XPathItem $item */ $item = $value; if ( is_null( $item->getSchemaType() ) ) { return XmlTypeCode::UntypedAtomic; } return $item->getSchemaType()->TypeCode; } return SequenceType::GetXmlTypeCodeFromType( Type::FromValue( $value ) ); }
php
static public function GetXmlTypeCodeFromObject( $value ) { if ( $value instanceof XPathNavigator ) { /** * @var XPathNavigator $nav */ $nav = $value; switch ( $nav->getNodeType() ) { case XPathNodeType::Attribute: return XmlTypeCode::Attribute; case XPathNodeType::Comment: return XmlTypeCode::Comment; case XPathNodeType::Element: return XmlTypeCode::Element; case XPathNodeType::NamespaceURI: return XmlTypeCode::Namespace_; case XPathNodeType::ProcessingInstruction: return XmlTypeCode::ProcessingInstruction; case XPathNodeType::Root: return XmlTypeCode::Document; case XPathNodeType::SignificantWhitespace: case XPathNodeType::Whitespace: case XPathNodeType::Text: return XmlTypeCode::Text; default: return XmlTypeCode::None; } } if ( $value instanceof XPathItem ) { /** * @var XPathItem $item */ $item = $value; if ( is_null( $item->getSchemaType() ) ) { return XmlTypeCode::UntypedAtomic; } return $item->getSchemaType()->TypeCode; } return SequenceType::GetXmlTypeCodeFromType( Type::FromValue( $value ) ); }
[ "static", "public", "function", "GetXmlTypeCodeFromObject", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "XPathNavigator", ")", "{", "/**\r\n\t\t\t * @var XPathNavigator $nav\r\n\t\t\t */", "$", "nav", "=", "$", "value", ";", "switch", "(", "$", "nav", "->", "getNodeType", "(", ")", ")", "{", "case", "XPathNodeType", "::", "Attribute", ":", "return", "XmlTypeCode", "::", "Attribute", ";", "case", "XPathNodeType", "::", "Comment", ":", "return", "XmlTypeCode", "::", "Comment", ";", "case", "XPathNodeType", "::", "Element", ":", "return", "XmlTypeCode", "::", "Element", ";", "case", "XPathNodeType", "::", "NamespaceURI", ":", "return", "XmlTypeCode", "::", "Namespace_", ";", "case", "XPathNodeType", "::", "ProcessingInstruction", ":", "return", "XmlTypeCode", "::", "ProcessingInstruction", ";", "case", "XPathNodeType", "::", "Root", ":", "return", "XmlTypeCode", "::", "Document", ";", "case", "XPathNodeType", "::", "SignificantWhitespace", ":", "case", "XPathNodeType", "::", "Whitespace", ":", "case", "XPathNodeType", "::", "Text", ":", "return", "XmlTypeCode", "::", "Text", ";", "default", ":", "return", "XmlTypeCode", "::", "None", ";", "}", "}", "if", "(", "$", "value", "instanceof", "XPathItem", ")", "{", "/**\r\n\t\t\t * @var XPathItem $item\r\n\t\t\t */", "$", "item", "=", "$", "value", ";", "if", "(", "is_null", "(", "$", "item", "->", "getSchemaType", "(", ")", ")", ")", "{", "return", "XmlTypeCode", "::", "UntypedAtomic", ";", "}", "return", "$", "item", "->", "getSchemaType", "(", ")", "->", "TypeCode", ";", "}", "return", "SequenceType", "::", "GetXmlTypeCodeFromType", "(", "Type", "::", "FromValue", "(", "$", "value", ")", ")", ";", "}" ]
GetXmlTypeCode @param object $value @return XmlTypeCode
[ "GetXmlTypeCode" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1140-L1192
bseddon/XPath20
SequenceType.php
SequenceType.TypeCodeIsNodeType
public static function TypeCodeIsNodeType( $typeCode ) { switch ( $typeCode ) { case XmlTypeCode::Node: case XmlTypeCode::Element: case XmlTypeCode::Attribute: case XmlTypeCode::Document: case XmlTypeCode::Comment: case XmlTypeCode::Text: case XmlTypeCode::ProcessingInstruction: return true; } return false; }
php
public static function TypeCodeIsNodeType( $typeCode ) { switch ( $typeCode ) { case XmlTypeCode::Node: case XmlTypeCode::Element: case XmlTypeCode::Attribute: case XmlTypeCode::Document: case XmlTypeCode::Comment: case XmlTypeCode::Text: case XmlTypeCode::ProcessingInstruction: return true; } return false; }
[ "public", "static", "function", "TypeCodeIsNodeType", "(", "$", "typeCode", ")", "{", "switch", "(", "$", "typeCode", ")", "{", "case", "XmlTypeCode", "::", "Node", ":", "case", "XmlTypeCode", "::", "Element", ":", "case", "XmlTypeCode", "::", "Attribute", ":", "case", "XmlTypeCode", "::", "Document", ":", "case", "XmlTypeCode", "::", "Comment", ":", "case", "XmlTypeCode", "::", "Text", ":", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "return", "true", ";", "}", "return", "false", ";", "}" ]
TypeCodeIsNodeType @param XmlTypeCode $typeCode @return bool
[ "TypeCodeIsNodeType" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1199-L1213
bseddon/XPath20
SequenceType.php
SequenceType.TypeCodeToItemType
public static function TypeCodeToItemType( $typeCode, $schemaType ) { switch ($typeCode) { case XmlTypeCode::Boolean: return Types::$BooleanType; case XmlTypeCode::Short: return Types::$ShortType; case XmlTypeCode::Int: return Types::$IntType; case XmlTypeCode::Long: return Types::$LongType; case XmlTypeCode::UnsignedShort: return Types::$UInt16Type; case XmlTypeCode::UnsignedInt: return Types::$UInt32Type; case XmlTypeCode::UnsignedLong: return Types::$UInt64Type; case XmlTypeCode::Byte: return Types::$ByteType; case XmlTypeCode::UnsignedByte: return Types::$ByteType; case XmlTypeCode::Float: return Types::$FloatType; case XmlTypeCode::Decimal: return Types::$DecimalType; case XmlTypeCode::Integer: case XmlTypeCode::PositiveInteger: case XmlTypeCode::NegativeInteger: case XmlTypeCode::NonPositiveInteger: case XmlTypeCode::NonNegativeInteger: return Types::$IntType; case XmlTypeCode::Double: return Types::$DoubleType; case XmlTypeCode::DateTime: return Types::$DateTimeValueType; case XmlTypeCode::Date: return Types::$DateValueType; case XmlTypeCode::Time: return Types::$TimeValueType; case XmlTypeCode::AnyUri: return Types::$AnyUriValueType; case XmlTypeCode::String: case XmlTypeCode::NormalizedString: case XmlTypeCode::Token: case XmlTypeCode::Language: case XmlTypeCode::Name: case XmlTypeCode::NCName: case XmlTypeCode::Id: return Types::$StringType; case XmlTypeCode::Idref: if ($schemaType == XmlSchema::$IDREFS) return Types::$IDREFSValueType; else return Types::$StringType; case XmlTypeCode::NmToken: if ($schemaType == XmlSchema::$NMTOKENS) return Types::$NMTOKENSValueType; else return Types::$StringType; case XmlTypeCode::Entity: if ($schemaType == XmlSchema::$ENTITIES) return Types::$ENTITIESValueType; else return Types::$StringType; case XmlTypeCode::UntypedAtomic: return Types::$UntypedAtomicType; case XmlTypeCode::Duration: return Types::$DurationValueType; case XmlTypeCode::DayTimeDuration: return Types::$DayTimeDurationValueType; case XmlTypeCode::YearMonthDuration: return Types::$YearMonthDurationValueType; case XmlTypeCode::GYearMonth: return Types::$GYearMonthValueType; case XmlTypeCode::GYear: return Types::$GYearValueType; case XmlTypeCode::GMonth: return Types::$GMonthValueType; case XmlTypeCode::GMonthDay: return Types::$GMonthDayValueType; case XmlTypeCode::GDay: return Types::$GDayValueType; case XmlTypeCode::QName: return Types::$QNameValueType; case XmlTypeCode::HexBinary: return Types::$HexBinaryValueType; case XmlTypeCode::Base64Binary: return Types::$Base64BinaryValueType; default: return Types::$ObjectType; } }
php
public static function TypeCodeToItemType( $typeCode, $schemaType ) { switch ($typeCode) { case XmlTypeCode::Boolean: return Types::$BooleanType; case XmlTypeCode::Short: return Types::$ShortType; case XmlTypeCode::Int: return Types::$IntType; case XmlTypeCode::Long: return Types::$LongType; case XmlTypeCode::UnsignedShort: return Types::$UInt16Type; case XmlTypeCode::UnsignedInt: return Types::$UInt32Type; case XmlTypeCode::UnsignedLong: return Types::$UInt64Type; case XmlTypeCode::Byte: return Types::$ByteType; case XmlTypeCode::UnsignedByte: return Types::$ByteType; case XmlTypeCode::Float: return Types::$FloatType; case XmlTypeCode::Decimal: return Types::$DecimalType; case XmlTypeCode::Integer: case XmlTypeCode::PositiveInteger: case XmlTypeCode::NegativeInteger: case XmlTypeCode::NonPositiveInteger: case XmlTypeCode::NonNegativeInteger: return Types::$IntType; case XmlTypeCode::Double: return Types::$DoubleType; case XmlTypeCode::DateTime: return Types::$DateTimeValueType; case XmlTypeCode::Date: return Types::$DateValueType; case XmlTypeCode::Time: return Types::$TimeValueType; case XmlTypeCode::AnyUri: return Types::$AnyUriValueType; case XmlTypeCode::String: case XmlTypeCode::NormalizedString: case XmlTypeCode::Token: case XmlTypeCode::Language: case XmlTypeCode::Name: case XmlTypeCode::NCName: case XmlTypeCode::Id: return Types::$StringType; case XmlTypeCode::Idref: if ($schemaType == XmlSchema::$IDREFS) return Types::$IDREFSValueType; else return Types::$StringType; case XmlTypeCode::NmToken: if ($schemaType == XmlSchema::$NMTOKENS) return Types::$NMTOKENSValueType; else return Types::$StringType; case XmlTypeCode::Entity: if ($schemaType == XmlSchema::$ENTITIES) return Types::$ENTITIESValueType; else return Types::$StringType; case XmlTypeCode::UntypedAtomic: return Types::$UntypedAtomicType; case XmlTypeCode::Duration: return Types::$DurationValueType; case XmlTypeCode::DayTimeDuration: return Types::$DayTimeDurationValueType; case XmlTypeCode::YearMonthDuration: return Types::$YearMonthDurationValueType; case XmlTypeCode::GYearMonth: return Types::$GYearMonthValueType; case XmlTypeCode::GYear: return Types::$GYearValueType; case XmlTypeCode::GMonth: return Types::$GMonthValueType; case XmlTypeCode::GMonthDay: return Types::$GMonthDayValueType; case XmlTypeCode::GDay: return Types::$GDayValueType; case XmlTypeCode::QName: return Types::$QNameValueType; case XmlTypeCode::HexBinary: return Types::$HexBinaryValueType; case XmlTypeCode::Base64Binary: return Types::$Base64BinaryValueType; default: return Types::$ObjectType; } }
[ "public", "static", "function", "TypeCodeToItemType", "(", "$", "typeCode", ",", "$", "schemaType", ")", "{", "switch", "(", "$", "typeCode", ")", "{", "case", "XmlTypeCode", "::", "Boolean", ":", "return", "Types", "::", "$", "BooleanType", ";", "case", "XmlTypeCode", "::", "Short", ":", "return", "Types", "::", "$", "ShortType", ";", "case", "XmlTypeCode", "::", "Int", ":", "return", "Types", "::", "$", "IntType", ";", "case", "XmlTypeCode", "::", "Long", ":", "return", "Types", "::", "$", "LongType", ";", "case", "XmlTypeCode", "::", "UnsignedShort", ":", "return", "Types", "::", "$", "UInt16Type", ";", "case", "XmlTypeCode", "::", "UnsignedInt", ":", "return", "Types", "::", "$", "UInt32Type", ";", "case", "XmlTypeCode", "::", "UnsignedLong", ":", "return", "Types", "::", "$", "UInt64Type", ";", "case", "XmlTypeCode", "::", "Byte", ":", "return", "Types", "::", "$", "ByteType", ";", "case", "XmlTypeCode", "::", "UnsignedByte", ":", "return", "Types", "::", "$", "ByteType", ";", "case", "XmlTypeCode", "::", "Float", ":", "return", "Types", "::", "$", "FloatType", ";", "case", "XmlTypeCode", "::", "Decimal", ":", "return", "Types", "::", "$", "DecimalType", ";", "case", "XmlTypeCode", "::", "Integer", ":", "case", "XmlTypeCode", "::", "PositiveInteger", ":", "case", "XmlTypeCode", "::", "NegativeInteger", ":", "case", "XmlTypeCode", "::", "NonPositiveInteger", ":", "case", "XmlTypeCode", "::", "NonNegativeInteger", ":", "return", "Types", "::", "$", "IntType", ";", "case", "XmlTypeCode", "::", "Double", ":", "return", "Types", "::", "$", "DoubleType", ";", "case", "XmlTypeCode", "::", "DateTime", ":", "return", "Types", "::", "$", "DateTimeValueType", ";", "case", "XmlTypeCode", "::", "Date", ":", "return", "Types", "::", "$", "DateValueType", ";", "case", "XmlTypeCode", "::", "Time", ":", "return", "Types", "::", "$", "TimeValueType", ";", "case", "XmlTypeCode", "::", "AnyUri", ":", "return", "Types", "::", "$", "AnyUriValueType", ";", "case", "XmlTypeCode", "::", "String", ":", "case", "XmlTypeCode", "::", "NormalizedString", ":", "case", "XmlTypeCode", "::", "Token", ":", "case", "XmlTypeCode", "::", "Language", ":", "case", "XmlTypeCode", "::", "Name", ":", "case", "XmlTypeCode", "::", "NCName", ":", "case", "XmlTypeCode", "::", "Id", ":", "return", "Types", "::", "$", "StringType", ";", "case", "XmlTypeCode", "::", "Idref", ":", "if", "(", "$", "schemaType", "==", "XmlSchema", "::", "$", "IDREFS", ")", "return", "Types", "::", "$", "IDREFSValueType", ";", "else", "return", "Types", "::", "$", "StringType", ";", "case", "XmlTypeCode", "::", "NmToken", ":", "if", "(", "$", "schemaType", "==", "XmlSchema", "::", "$", "NMTOKENS", ")", "return", "Types", "::", "$", "NMTOKENSValueType", ";", "else", "return", "Types", "::", "$", "StringType", ";", "case", "XmlTypeCode", "::", "Entity", ":", "if", "(", "$", "schemaType", "==", "XmlSchema", "::", "$", "ENTITIES", ")", "return", "Types", "::", "$", "ENTITIESValueType", ";", "else", "return", "Types", "::", "$", "StringType", ";", "case", "XmlTypeCode", "::", "UntypedAtomic", ":", "return", "Types", "::", "$", "UntypedAtomicType", ";", "case", "XmlTypeCode", "::", "Duration", ":", "return", "Types", "::", "$", "DurationValueType", ";", "case", "XmlTypeCode", "::", "DayTimeDuration", ":", "return", "Types", "::", "$", "DayTimeDurationValueType", ";", "case", "XmlTypeCode", "::", "YearMonthDuration", ":", "return", "Types", "::", "$", "YearMonthDurationValueType", ";", "case", "XmlTypeCode", "::", "GYearMonth", ":", "return", "Types", "::", "$", "GYearMonthValueType", ";", "case", "XmlTypeCode", "::", "GYear", ":", "return", "Types", "::", "$", "GYearValueType", ";", "case", "XmlTypeCode", "::", "GMonth", ":", "return", "Types", "::", "$", "GMonthValueType", ";", "case", "XmlTypeCode", "::", "GMonthDay", ":", "return", "Types", "::", "$", "GMonthDayValueType", ";", "case", "XmlTypeCode", "::", "GDay", ":", "return", "Types", "::", "$", "GDayValueType", ";", "case", "XmlTypeCode", "::", "QName", ":", "return", "Types", "::", "$", "QNameValueType", ";", "case", "XmlTypeCode", "::", "HexBinary", ":", "return", "Types", "::", "$", "HexBinaryValueType", ";", "case", "XmlTypeCode", "::", "Base64Binary", ":", "return", "Types", "::", "$", "Base64BinaryValueType", ";", "default", ":", "return", "Types", "::", "$", "ObjectType", ";", "}", "}" ]
TypeCodeToItemType @param XmlTypeCode $typeCode @param XmlSchemaType $schemaType @return Type
[ "TypeCodeToItemType" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1221-L1331
bseddon/XPath20
SequenceType.php
SequenceType.GetXmlTypeCodeFromType
public static function GetXmlTypeCodeFromType( $type ) { /** * @var TypeCode */ switch ( $type->getTypeCode() ) { case TypeCode::Boolean: return XmlTypeCode::Boolean; case TypeCode::Int16: return XmlTypeCode::Short; case TypeCode::Int32: return XmlTypeCode::Int; case TypeCode::Int64: return XmlTypeCode::Long; case TypeCode::UInt16: return XmlTypeCode::UnsignedShort; case TypeCode::UInt32: return XmlTypeCode::UnsignedInt; case TypeCode::UInt64: return XmlTypeCode::UnsignedLong; case TypeCode::SByte: return XmlTypeCode::Byte; case TypeCode::Byte: return XmlTypeCode::UnsignedByte; case TypeCode::Single: return XmlTypeCode::Float; case TypeCode::Decimal: return XmlTypeCode::Decimal; case TypeCode::Double: return XmlTypeCode::Double; case TypeCode::Char: case TypeCode::String: return XmlTypeCode::String; default: $typeName = $type->getTypeName(); if ($typeName == DOMXPathNavigator::$CLASSNAME ) return XmlTypeCode::Node; if ($typeName == UntypedAtomic::$CLASSNAME ) return XmlTypeCode::UntypedAtomic; if ($typeName == Integer::$CLASSNAME ) return XmlTypeCode::Integer; if ($typeName == DateTimeValue::$CLASSNAME ) return XmlTypeCode::DateTime; if ($typeName == DateValue::$CLASSNAME ) return XmlTypeCode::Date; if ($typeName == TimeValue::$CLASSNAME ) return XmlTypeCode::Time; if ($typeName == DurationValue::$CLASSNAME ) return XmlTypeCode::Duration; if ($typeName == YearMonthDurationValue::$CLASSNAME) return XmlTypeCode::YearMonthDuration; if ($typeName == DayTimeDurationValue::$CLASSNAME ) return XmlTypeCode::DayTimeDuration; if ($typeName == GYearMonthValue::$CLASSNAME ) return XmlTypeCode::GYearMonth; if ($typeName == GYearValue::$CLASSNAME ) return XmlTypeCode::GYear; if ($typeName == GDayValue::$CLASSNAME ) return XmlTypeCode::GDay; if ($typeName == GMonthValue::$CLASSNAME ) return XmlTypeCode::GMonth; if ($typeName == GMonthDayValue::$CLASSNAME ) return XmlTypeCode::GMonthDay; if ($typeName == QNameValue::$CLASSNAME ) return XmlTypeCode::QName; if ($typeName == AnyUriValue::$CLASSNAME ) return XmlTypeCode::AnyUri; if ($typeName == HexBinaryValue::$CLASSNAME ) return XmlTypeCode::HexBinary; if ($typeName == Base64BinaryValue::$CLASSNAME ) return XmlTypeCode::Base64Binary; if ($typeName == IDREFSValue::$CLASSNAME ) return XmlTypeCode::Idref; if ($typeName == ENTITIESValue::$CLASSNAME ) return XmlTypeCode::Entity; if ($typeName == NMTOKENSValue::$CLASSNAME ) return XmlTypeCode::NmToken; return XmlTypeCode::Item; } }
php
public static function GetXmlTypeCodeFromType( $type ) { /** * @var TypeCode */ switch ( $type->getTypeCode() ) { case TypeCode::Boolean: return XmlTypeCode::Boolean; case TypeCode::Int16: return XmlTypeCode::Short; case TypeCode::Int32: return XmlTypeCode::Int; case TypeCode::Int64: return XmlTypeCode::Long; case TypeCode::UInt16: return XmlTypeCode::UnsignedShort; case TypeCode::UInt32: return XmlTypeCode::UnsignedInt; case TypeCode::UInt64: return XmlTypeCode::UnsignedLong; case TypeCode::SByte: return XmlTypeCode::Byte; case TypeCode::Byte: return XmlTypeCode::UnsignedByte; case TypeCode::Single: return XmlTypeCode::Float; case TypeCode::Decimal: return XmlTypeCode::Decimal; case TypeCode::Double: return XmlTypeCode::Double; case TypeCode::Char: case TypeCode::String: return XmlTypeCode::String; default: $typeName = $type->getTypeName(); if ($typeName == DOMXPathNavigator::$CLASSNAME ) return XmlTypeCode::Node; if ($typeName == UntypedAtomic::$CLASSNAME ) return XmlTypeCode::UntypedAtomic; if ($typeName == Integer::$CLASSNAME ) return XmlTypeCode::Integer; if ($typeName == DateTimeValue::$CLASSNAME ) return XmlTypeCode::DateTime; if ($typeName == DateValue::$CLASSNAME ) return XmlTypeCode::Date; if ($typeName == TimeValue::$CLASSNAME ) return XmlTypeCode::Time; if ($typeName == DurationValue::$CLASSNAME ) return XmlTypeCode::Duration; if ($typeName == YearMonthDurationValue::$CLASSNAME) return XmlTypeCode::YearMonthDuration; if ($typeName == DayTimeDurationValue::$CLASSNAME ) return XmlTypeCode::DayTimeDuration; if ($typeName == GYearMonthValue::$CLASSNAME ) return XmlTypeCode::GYearMonth; if ($typeName == GYearValue::$CLASSNAME ) return XmlTypeCode::GYear; if ($typeName == GDayValue::$CLASSNAME ) return XmlTypeCode::GDay; if ($typeName == GMonthValue::$CLASSNAME ) return XmlTypeCode::GMonth; if ($typeName == GMonthDayValue::$CLASSNAME ) return XmlTypeCode::GMonthDay; if ($typeName == QNameValue::$CLASSNAME ) return XmlTypeCode::QName; if ($typeName == AnyUriValue::$CLASSNAME ) return XmlTypeCode::AnyUri; if ($typeName == HexBinaryValue::$CLASSNAME ) return XmlTypeCode::HexBinary; if ($typeName == Base64BinaryValue::$CLASSNAME ) return XmlTypeCode::Base64Binary; if ($typeName == IDREFSValue::$CLASSNAME ) return XmlTypeCode::Idref; if ($typeName == ENTITIESValue::$CLASSNAME ) return XmlTypeCode::Entity; if ($typeName == NMTOKENSValue::$CLASSNAME ) return XmlTypeCode::NmToken; return XmlTypeCode::Item; } }
[ "public", "static", "function", "GetXmlTypeCodeFromType", "(", "$", "type", ")", "{", "/**\r\n\t\t * @var TypeCode\r\n\t\t */", "switch", "(", "$", "type", "->", "getTypeCode", "(", ")", ")", "{", "case", "TypeCode", "::", "Boolean", ":", "return", "XmlTypeCode", "::", "Boolean", ";", "case", "TypeCode", "::", "Int16", ":", "return", "XmlTypeCode", "::", "Short", ";", "case", "TypeCode", "::", "Int32", ":", "return", "XmlTypeCode", "::", "Int", ";", "case", "TypeCode", "::", "Int64", ":", "return", "XmlTypeCode", "::", "Long", ";", "case", "TypeCode", "::", "UInt16", ":", "return", "XmlTypeCode", "::", "UnsignedShort", ";", "case", "TypeCode", "::", "UInt32", ":", "return", "XmlTypeCode", "::", "UnsignedInt", ";", "case", "TypeCode", "::", "UInt64", ":", "return", "XmlTypeCode", "::", "UnsignedLong", ";", "case", "TypeCode", "::", "SByte", ":", "return", "XmlTypeCode", "::", "Byte", ";", "case", "TypeCode", "::", "Byte", ":", "return", "XmlTypeCode", "::", "UnsignedByte", ";", "case", "TypeCode", "::", "Single", ":", "return", "XmlTypeCode", "::", "Float", ";", "case", "TypeCode", "::", "Decimal", ":", "return", "XmlTypeCode", "::", "Decimal", ";", "case", "TypeCode", "::", "Double", ":", "return", "XmlTypeCode", "::", "Double", ";", "case", "TypeCode", "::", "Char", ":", "case", "TypeCode", "::", "String", ":", "return", "XmlTypeCode", "::", "String", ";", "default", ":", "$", "typeName", "=", "$", "type", "->", "getTypeName", "(", ")", ";", "if", "(", "$", "typeName", "==", "DOMXPathNavigator", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Node", ";", "if", "(", "$", "typeName", "==", "UntypedAtomic", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "UntypedAtomic", ";", "if", "(", "$", "typeName", "==", "Integer", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Integer", ";", "if", "(", "$", "typeName", "==", "DateTimeValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "DateTime", ";", "if", "(", "$", "typeName", "==", "DateValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Date", ";", "if", "(", "$", "typeName", "==", "TimeValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Time", ";", "if", "(", "$", "typeName", "==", "DurationValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Duration", ";", "if", "(", "$", "typeName", "==", "YearMonthDurationValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "YearMonthDuration", ";", "if", "(", "$", "typeName", "==", "DayTimeDurationValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "DayTimeDuration", ";", "if", "(", "$", "typeName", "==", "GYearMonthValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "GYearMonth", ";", "if", "(", "$", "typeName", "==", "GYearValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "GYear", ";", "if", "(", "$", "typeName", "==", "GDayValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "GDay", ";", "if", "(", "$", "typeName", "==", "GMonthValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "GMonth", ";", "if", "(", "$", "typeName", "==", "GMonthDayValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "GMonthDay", ";", "if", "(", "$", "typeName", "==", "QNameValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "QName", ";", "if", "(", "$", "typeName", "==", "AnyUriValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "AnyUri", ";", "if", "(", "$", "typeName", "==", "HexBinaryValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "HexBinary", ";", "if", "(", "$", "typeName", "==", "Base64BinaryValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Base64Binary", ";", "if", "(", "$", "typeName", "==", "IDREFSValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Idref", ";", "if", "(", "$", "typeName", "==", "ENTITIESValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "Entity", ";", "if", "(", "$", "typeName", "==", "NMTOKENSValue", "::", "$", "CLASSNAME", ")", "return", "XmlTypeCode", "::", "NmToken", ";", "return", "XmlTypeCode", "::", "Item", ";", "}", "}" ]
GetXmlTypeCode @param Type $type @return XmlTypeCode
[ "GetXmlTypeCode" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1338-L1418
bseddon/XPath20
SequenceType.php
SequenceType.IsDerivedFrom
public function IsDerivedFrom( $src ) { switch ( $src->TypeCode ) { case XmlTypeCode::Node: if ( ! $this->IsNode ) return false; break; case XmlTypeCode::AnyAtomicType: case XmlTypeCode::UntypedAtomic: if ( $this->IsNode ) return false; break; case XmlTypeCode::Document: if ( $this->TypeCode != XmlTypeCode::Document || $this->SchemaElement != $src->SchemaElement) return false; break; case XmlTypeCode::Element: if ( $this->TypeCode != XmlTypeCode::Element || $this->SchemaElement != $src->SchemaElement) return false; break; case XmlTypeCode::Attribute: if ($this->TypeCode != XmlTypeCode::Attribute || $this->SchemaAttribute != $src->SchemaAttribute) return false; break; case XmlTypeCode::ProcessingInstruction: if ($this->TypeCode != XmlTypeCode::ProcessingInstruction) return false; break; case XmlTypeCode::Comment: if ( $this->TypeCode != XmlTypeCode::Comment ) return false; break; case XmlTypeCode::Text: if ( $this->TypeCode != XmlTypeCode::Text ) return false; break; } if ( ! is_null( $this->SchemaType ) || ! is_null( $src->SchemaType ) ) { if ( ! is_null( $this->SchemaType ) && ! is_null( $src->SchemaType ) ) { if ( ! DOMSchemaType::IsDerivedFrom( $this->SchemaType, $src->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) return false; } else return false; } if ( $this->Cardinality != $src->Cardinality) { if ( ( $this->Cardinality == XmlTypeCardinality::ZeroOrOne || $this->Cardinality == XmlTypeCardinality::ZeroOrMore ) && ($src->Cardinality == XmlTypeCardinality::One || $src->Cardinality == XmlTypeCardinality::OneOrMore)) return false; if ( $this->Cardinality == XmlTypeCardinality::One && $src->Cardinality == XmlTypeCardinality::OneOrMore) return false; } return true; }
php
public function IsDerivedFrom( $src ) { switch ( $src->TypeCode ) { case XmlTypeCode::Node: if ( ! $this->IsNode ) return false; break; case XmlTypeCode::AnyAtomicType: case XmlTypeCode::UntypedAtomic: if ( $this->IsNode ) return false; break; case XmlTypeCode::Document: if ( $this->TypeCode != XmlTypeCode::Document || $this->SchemaElement != $src->SchemaElement) return false; break; case XmlTypeCode::Element: if ( $this->TypeCode != XmlTypeCode::Element || $this->SchemaElement != $src->SchemaElement) return false; break; case XmlTypeCode::Attribute: if ($this->TypeCode != XmlTypeCode::Attribute || $this->SchemaAttribute != $src->SchemaAttribute) return false; break; case XmlTypeCode::ProcessingInstruction: if ($this->TypeCode != XmlTypeCode::ProcessingInstruction) return false; break; case XmlTypeCode::Comment: if ( $this->TypeCode != XmlTypeCode::Comment ) return false; break; case XmlTypeCode::Text: if ( $this->TypeCode != XmlTypeCode::Text ) return false; break; } if ( ! is_null( $this->SchemaType ) || ! is_null( $src->SchemaType ) ) { if ( ! is_null( $this->SchemaType ) && ! is_null( $src->SchemaType ) ) { if ( ! DOMSchemaType::IsDerivedFrom( $this->SchemaType, $src->SchemaType, XmlSchemaDerivationMethod::Empty_ ) ) return false; } else return false; } if ( $this->Cardinality != $src->Cardinality) { if ( ( $this->Cardinality == XmlTypeCardinality::ZeroOrOne || $this->Cardinality == XmlTypeCardinality::ZeroOrMore ) && ($src->Cardinality == XmlTypeCardinality::One || $src->Cardinality == XmlTypeCardinality::OneOrMore)) return false; if ( $this->Cardinality == XmlTypeCardinality::One && $src->Cardinality == XmlTypeCardinality::OneOrMore) return false; } return true; }
[ "public", "function", "IsDerivedFrom", "(", "$", "src", ")", "{", "switch", "(", "$", "src", "->", "TypeCode", ")", "{", "case", "XmlTypeCode", "::", "Node", ":", "if", "(", "!", "$", "this", "->", "IsNode", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "AnyAtomicType", ":", "case", "XmlTypeCode", "::", "UntypedAtomic", ":", "if", "(", "$", "this", "->", "IsNode", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "Document", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "Document", "||", "$", "this", "->", "SchemaElement", "!=", "$", "src", "->", "SchemaElement", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "Element", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "Element", "||", "$", "this", "->", "SchemaElement", "!=", "$", "src", "->", "SchemaElement", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "Attribute", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "Attribute", "||", "$", "this", "->", "SchemaAttribute", "!=", "$", "src", "->", "SchemaAttribute", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "ProcessingInstruction", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "ProcessingInstruction", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "Comment", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "Comment", ")", "return", "false", ";", "break", ";", "case", "XmlTypeCode", "::", "Text", ":", "if", "(", "$", "this", "->", "TypeCode", "!=", "XmlTypeCode", "::", "Text", ")", "return", "false", ";", "break", ";", "}", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", "||", "!", "is_null", "(", "$", "src", "->", "SchemaType", ")", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "SchemaType", ")", "&&", "!", "is_null", "(", "$", "src", "->", "SchemaType", ")", ")", "{", "if", "(", "!", "DOMSchemaType", "::", "IsDerivedFrom", "(", "$", "this", "->", "SchemaType", ",", "$", "src", "->", "SchemaType", ",", "XmlSchemaDerivationMethod", "::", "Empty_", ")", ")", "return", "false", ";", "}", "else", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Cardinality", "!=", "$", "src", "->", "Cardinality", ")", "{", "if", "(", "(", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "ZeroOrOne", "||", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "ZeroOrMore", ")", "&&", "(", "$", "src", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "One", "||", "$", "src", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "OneOrMore", ")", ")", "return", "false", ";", "if", "(", "$", "this", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "One", "&&", "$", "src", "->", "Cardinality", "==", "XmlTypeCardinality", "::", "OneOrMore", ")", "return", "false", ";", "}", "return", "true", ";", "}" ]
IsDerivedFrom @param SequenceType $src @return bool
[ "IsDerivedFrom" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1425-L1491
bseddon/XPath20
SequenceType.php
SequenceType.Equals
public function Equals( $obj ) { /** * @var SequenceType $dest */ $dest = $obj; if ( ! is_null( $obj ) ) { return $this->TypeCode == $dest->TypeCode && $this->SchemaElement == $dest->SchemaElement && $this->SchemaAttribute == $dest->SchemaAttribute && $this->SchemaType == $dest->SchemaType && $this->Cardinality == $dest->Cardinality; } return false; }
php
public function Equals( $obj ) { /** * @var SequenceType $dest */ $dest = $obj; if ( ! is_null( $obj ) ) { return $this->TypeCode == $dest->TypeCode && $this->SchemaElement == $dest->SchemaElement && $this->SchemaAttribute == $dest->SchemaAttribute && $this->SchemaType == $dest->SchemaType && $this->Cardinality == $dest->Cardinality; } return false; }
[ "public", "function", "Equals", "(", "$", "obj", ")", "{", "/**\r\n\t\t * @var SequenceType $dest\r\n\t\t */", "$", "dest", "=", "$", "obj", ";", "if", "(", "!", "is_null", "(", "$", "obj", ")", ")", "{", "return", "$", "this", "->", "TypeCode", "==", "$", "dest", "->", "TypeCode", "&&", "$", "this", "->", "SchemaElement", "==", "$", "dest", "->", "SchemaElement", "&&", "$", "this", "->", "SchemaAttribute", "==", "$", "dest", "->", "SchemaAttribute", "&&", "$", "this", "->", "SchemaType", "==", "$", "dest", "->", "SchemaType", "&&", "$", "this", "->", "Cardinality", "==", "$", "dest", "->", "Cardinality", ";", "}", "return", "false", ";", "}" ]
Equals @param object $obj @return bool
[ "Equals" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1498-L1513
bseddon/XPath20
SequenceType.php
SequenceType.Create
public static function Create( $name ) { if ( $name == "" || $name == "empty-sequence()") return null; else { /** * @var XmlTypeCardinality $cardinality */ $cardinality = XmlTypeCardinality::One; if ( SchemaTypes::endsWith( $name, "?" ) ) { $cardinality = XmlTypeCardinality::ZeroOrOne; $name = substr( $name, 1, strlen( $name ) - 1 ); } else if ( SchemaTypes::endsWith( $name,"+") ) { $cardinality = XmlTypeCardinality::OneOrMore; $name = substr( $name, 1, strlen( $name ) - 1 ); } else if ( SchemaTypes::endsWith( $name, "*" ) ) { $cardinality = XmlTypeCardinality::ZeroOrMore; $name = substr( $name, 1, strlen( $name ) - 1 ); } if ( $name == "xs:AnyAtomicType" ) { return SequenceType::WithSchemaTypeWithCardinality( XmlSchema::$AnyAtomicType /* DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::AnyAtomicType ) */, $cardinality ); } else if ( $name == "item()" ) { return SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::Item, $cardinality); } else if ( $name == "node()" ) { return SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::Node, $cardinality ); } else { /** * @var QName $qname */ $qname = \lyquidity\xml\qname( $name, array( SCHEMA_PREFIX => SCHEMA_NAMESPACE ) + SchemaTypes::getInstance()->getProcessedSchemas() ); $prefix = $qname->prefix; $localName = $qname->localName; if ( $prefix != SCHEMA_PREFIX && $prefix != SCHEMA_PREFIX_ALTERNATIVE ) { throw new ArgumentException( "$name" ); } $schemaType = DOMSchemaType::GetBuiltInSimpleTypeByQName( $qname ); if ( is_null( $schemaType ) ) { throw new ArgumentException( "Failed to create a built-in schema type with name: $name" ); } return SequenceType::WithSchemaTypeWithCardinality( $schemaType, $cardinality ); } } }
php
public static function Create( $name ) { if ( $name == "" || $name == "empty-sequence()") return null; else { /** * @var XmlTypeCardinality $cardinality */ $cardinality = XmlTypeCardinality::One; if ( SchemaTypes::endsWith( $name, "?" ) ) { $cardinality = XmlTypeCardinality::ZeroOrOne; $name = substr( $name, 1, strlen( $name ) - 1 ); } else if ( SchemaTypes::endsWith( $name,"+") ) { $cardinality = XmlTypeCardinality::OneOrMore; $name = substr( $name, 1, strlen( $name ) - 1 ); } else if ( SchemaTypes::endsWith( $name, "*" ) ) { $cardinality = XmlTypeCardinality::ZeroOrMore; $name = substr( $name, 1, strlen( $name ) - 1 ); } if ( $name == "xs:AnyAtomicType" ) { return SequenceType::WithSchemaTypeWithCardinality( XmlSchema::$AnyAtomicType /* DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::AnyAtomicType ) */, $cardinality ); } else if ( $name == "item()" ) { return SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::Item, $cardinality); } else if ( $name == "node()" ) { return SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::Node, $cardinality ); } else { /** * @var QName $qname */ $qname = \lyquidity\xml\qname( $name, array( SCHEMA_PREFIX => SCHEMA_NAMESPACE ) + SchemaTypes::getInstance()->getProcessedSchemas() ); $prefix = $qname->prefix; $localName = $qname->localName; if ( $prefix != SCHEMA_PREFIX && $prefix != SCHEMA_PREFIX_ALTERNATIVE ) { throw new ArgumentException( "$name" ); } $schemaType = DOMSchemaType::GetBuiltInSimpleTypeByQName( $qname ); if ( is_null( $schemaType ) ) { throw new ArgumentException( "Failed to create a built-in schema type with name: $name" ); } return SequenceType::WithSchemaTypeWithCardinality( $schemaType, $cardinality ); } } }
[ "public", "static", "function", "Create", "(", "$", "name", ")", "{", "if", "(", "$", "name", "==", "\"\"", "||", "$", "name", "==", "\"empty-sequence()\"", ")", "return", "null", ";", "else", "{", "/**\r\n\t\t\t * @var XmlTypeCardinality $cardinality\r\n\t\t\t */", "$", "cardinality", "=", "XmlTypeCardinality", "::", "One", ";", "if", "(", "SchemaTypes", "::", "endsWith", "(", "$", "name", ",", "\"?\"", ")", ")", "{", "$", "cardinality", "=", "XmlTypeCardinality", "::", "ZeroOrOne", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "1", ",", "strlen", "(", "$", "name", ")", "-", "1", ")", ";", "}", "else", "if", "(", "SchemaTypes", "::", "endsWith", "(", "$", "name", ",", "\"+\"", ")", ")", "{", "$", "cardinality", "=", "XmlTypeCardinality", "::", "OneOrMore", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "1", ",", "strlen", "(", "$", "name", ")", "-", "1", ")", ";", "}", "else", "if", "(", "SchemaTypes", "::", "endsWith", "(", "$", "name", ",", "\"*\"", ")", ")", "{", "$", "cardinality", "=", "XmlTypeCardinality", "::", "ZeroOrMore", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "1", ",", "strlen", "(", "$", "name", ")", "-", "1", ")", ";", "}", "if", "(", "$", "name", "==", "\"xs:AnyAtomicType\"", ")", "{", "return", "SequenceType", "::", "WithSchemaTypeWithCardinality", "(", "XmlSchema", "::", "$", "AnyAtomicType", "/* DOMSchemaType::GetBuiltInSimpleTypeByTypecode( XmlTypeCode::AnyAtomicType ) */", ",", "$", "cardinality", ")", ";", "}", "else", "if", "(", "$", "name", "==", "\"item()\"", ")", "{", "return", "SequenceType", "::", "WithTypeCodeAndCardinality", "(", "XmlTypeCode", "::", "Item", ",", "$", "cardinality", ")", ";", "}", "else", "if", "(", "$", "name", "==", "\"node()\"", ")", "{", "return", "SequenceType", "::", "WithTypeCodeAndCardinality", "(", "XmlTypeCode", "::", "Node", ",", "$", "cardinality", ")", ";", "}", "else", "{", "/**\r\n\t\t\t\t * @var QName $qname\r\n\t\t\t\t */", "$", "qname", "=", "\\", "lyquidity", "\\", "xml", "\\", "qname", "(", "$", "name", ",", "array", "(", "SCHEMA_PREFIX", "=>", "SCHEMA_NAMESPACE", ")", "+", "SchemaTypes", "::", "getInstance", "(", ")", "->", "getProcessedSchemas", "(", ")", ")", ";", "$", "prefix", "=", "$", "qname", "->", "prefix", ";", "$", "localName", "=", "$", "qname", "->", "localName", ";", "if", "(", "$", "prefix", "!=", "SCHEMA_PREFIX", "&&", "$", "prefix", "!=", "SCHEMA_PREFIX_ALTERNATIVE", ")", "{", "throw", "new", "ArgumentException", "(", "\"$name\"", ")", ";", "}", "$", "schemaType", "=", "DOMSchemaType", "::", "GetBuiltInSimpleTypeByQName", "(", "$", "qname", ")", ";", "if", "(", "is_null", "(", "$", "schemaType", ")", ")", "{", "throw", "new", "ArgumentException", "(", "\"Failed to create a built-in schema type with name: $name\"", ")", ";", "}", "return", "SequenceType", "::", "WithSchemaTypeWithCardinality", "(", "$", "schemaType", ",", "$", "cardinality", ")", ";", "}", "}", "}" ]
Create @param string $name @return SequenceType
[ "Create" ]
train
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/SequenceType.php#L1520-L1580
vainproject/vain-user
src/User/Observers/UserObserver.php
UserObserver.deleting
public function deleting($model) { foreach ($this->relations as $relation) { if ($model->{$relation}()->count() > 0) { // Returning false from an Eloquent event listener will cancel the operation. return false; } } }
php
public function deleting($model) { foreach ($this->relations as $relation) { if ($model->{$relation}()->count() > 0) { // Returning false from an Eloquent event listener will cancel the operation. return false; } } }
[ "public", "function", "deleting", "(", "$", "model", ")", "{", "foreach", "(", "$", "this", "->", "relations", "as", "$", "relation", ")", "{", "if", "(", "$", "model", "->", "{", "$", "relation", "}", "(", ")", "->", "count", "(", ")", ">", "0", ")", "{", "// Returning false from an Eloquent event listener will cancel the operation.", "return", "false", ";", "}", "}", "}" ]
Post delete check if a user has any relevant relations, if so we cancel the deletion and ask the user to manually remove all relations for now. @param $model @return bool
[ "Post", "delete", "check", "if", "a", "user", "has", "any", "relevant", "relations", "if", "so", "we", "cancel", "the", "deletion", "and", "ask", "the", "user", "to", "manually", "remove", "all", "relations", "for", "now", "." ]
train
https://github.com/vainproject/vain-user/blob/1c059faa61ebf289fcaea39a90b4523cfc9d6efc/src/User/Observers/UserObserver.php#L22-L30
Wedeto/Util
src/ErrorInterceptor.php
ErrorInterceptor.execute
public function execute() { $registered = false; if (self::$interceptor_stack === null) { $registered = true; self::registerErrorHandler(); } array_push(self::$interceptor_stack, $this); $response = null; try { $response = call_user_func_array($this->func, func_get_args()); } finally { array_pop(self::$interceptor_stack); if ($registered) self::unregisterErrorHandler(); } return $response; }
php
public function execute() { $registered = false; if (self::$interceptor_stack === null) { $registered = true; self::registerErrorHandler(); } array_push(self::$interceptor_stack, $this); $response = null; try { $response = call_user_func_array($this->func, func_get_args()); } finally { array_pop(self::$interceptor_stack); if ($registered) self::unregisterErrorHandler(); } return $response; }
[ "public", "function", "execute", "(", ")", "{", "$", "registered", "=", "false", ";", "if", "(", "self", "::", "$", "interceptor_stack", "===", "null", ")", "{", "$", "registered", "=", "true", ";", "self", "::", "registerErrorHandler", "(", ")", ";", "}", "array_push", "(", "self", "::", "$", "interceptor_stack", ",", "$", "this", ")", ";", "$", "response", "=", "null", ";", "try", "{", "$", "response", "=", "call_user_func_array", "(", "$", "this", "->", "func", ",", "func_get_args", "(", ")", ")", ";", "}", "finally", "{", "array_pop", "(", "self", "::", "$", "interceptor_stack", ")", ";", "if", "(", "$", "registered", ")", "self", "::", "unregisterErrorHandler", "(", ")", ";", "}", "return", "$", "response", ";", "}" ]
Execute the configured callback @params Any parameters to pass to the callback @return mixed The return value of the callback
[ "Execute", "the", "configured", "callback" ]
train
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/ErrorInterceptor.php#L82-L105
Wedeto/Util
src/ErrorInterceptor.php
ErrorInterceptor.intercept
protected function intercept($errno, $errstr, $errfile, $errline, $errcontext) { foreach ($this->expected as $warning) { if ($errno & $warning[0] && strpos($errstr, $warning[1]) !== false) { $this->intercepted[] = new \ErrorException($errstr, 0, $errno, $errfile, $errline); return true; } } return false; }
php
protected function intercept($errno, $errstr, $errfile, $errline, $errcontext) { foreach ($this->expected as $warning) { if ($errno & $warning[0] && strpos($errstr, $warning[1]) !== false) { $this->intercepted[] = new \ErrorException($errstr, 0, $errno, $errfile, $errline); return true; } } return false; }
[ "protected", "function", "intercept", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ",", "$", "errcontext", ")", "{", "foreach", "(", "$", "this", "->", "expected", "as", "$", "warning", ")", "{", "if", "(", "$", "errno", "&", "$", "warning", "[", "0", "]", "&&", "strpos", "(", "$", "errstr", ",", "$", "warning", "[", "1", "]", ")", "!==", "false", ")", "{", "$", "this", "->", "intercepted", "[", "]", "=", "new", "\\", "ErrorException", "(", "$", "errstr", ",", "0", ",", "$", "errno", ",", "$", "errfile", ",", "$", "errline", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if the produced error should be intercepted by the interceptor, based on the defined expected errors. @param int $errno Error type @param string $errstr The error string @param string $errfile The file the error occured in @param int $errline The line the error occured on @param array $errcontext Local variables @return bool True if the message was intercepted, false if not
[ "Check", "if", "the", "produced", "error", "should", "be", "intercepted", "by", "the", "interceptor", "based", "on", "the", "defined", "expected", "errors", "." ]
train
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/ErrorInterceptor.php#L126-L137
Wedeto/Util
src/ErrorInterceptor.php
ErrorInterceptor.errorHandler
public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { if (count(self::$interceptor_stack) > 0) { $interceptor = end(self::$interceptor_stack); if ($interceptor->intercept($errno, $errstr, $errfile, $errline, $errcontext)) { return; } } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); }
php
public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { if (count(self::$interceptor_stack) > 0) { $interceptor = end(self::$interceptor_stack); if ($interceptor->intercept($errno, $errstr, $errfile, $errline, $errcontext)) { return; } } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); }
[ "public", "static", "function", "errorHandler", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ",", "$", "errcontext", ")", "{", "if", "(", "count", "(", "self", "::", "$", "interceptor_stack", ")", ">", "0", ")", "{", "$", "interceptor", "=", "end", "(", "self", "::", "$", "interceptor_stack", ")", ";", "if", "(", "$", "interceptor", "->", "intercept", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ",", "$", "errcontext", ")", ")", "{", "return", ";", "}", "}", "throw", "new", "ErrorException", "(", "$", "errstr", ",", "0", ",", "$", "errno", ",", "$", "errfile", ",", "$", "errline", ")", ";", "}" ]
Catch all PHP errors, notices and throw them as an exception instead. If an interceptor was registered, the message is passed to the interceptor instead. @param int $errno Error number @param string $errstr Error description @param string $errfile The file where the error occured @param int $errline The line where the error occured @param mixed $errcontext Erro context
[ "Catch", "all", "PHP", "errors", "notices", "and", "throw", "them", "as", "an", "exception", "instead", ".", "If", "an", "interceptor", "was", "registered", "the", "message", "is", "passed", "to", "the", "interceptor", "instead", "." ]
train
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/ErrorInterceptor.php#L154-L166
linpax/microphp-framework
src/auth/drivers/FileRbac.php
FileRbac.assign
public function assign($userId, $name) { if ($this->searchRoleRecursive($this->roles, $name)) { $exists = $this->db->exists('rbac_user', ['user' => $userId, 'role' => $name]); if (!$exists) { return $this->db->insert('rbac_user', ['role' => $name, 'user' => $userId]); } } return false; }
php
public function assign($userId, $name) { if ($this->searchRoleRecursive($this->roles, $name)) { $exists = $this->db->exists('rbac_user', ['user' => $userId, 'role' => $name]); if (!$exists) { return $this->db->insert('rbac_user', ['role' => $name, 'user' => $userId]); } } return false; }
[ "public", "function", "assign", "(", "$", "userId", ",", "$", "name", ")", "{", "if", "(", "$", "this", "->", "searchRoleRecursive", "(", "$", "this", "->", "roles", ",", "$", "name", ")", ")", "{", "$", "exists", "=", "$", "this", "->", "db", "->", "exists", "(", "'rbac_user'", ",", "[", "'user'", "=>", "$", "userId", ",", "'role'", "=>", "$", "name", "]", ")", ";", "if", "(", "!", "$", "exists", ")", "{", "return", "$", "this", "->", "db", "->", "insert", "(", "'rbac_user'", ",", "[", "'role'", "=>", "$", "name", ",", "'user'", "=>", "$", "userId", "]", ")", ";", "}", "}", "return", "false", ";", "}" ]
Assign RBAC element into user @access public @param integer $userId user id @param string $name element name @return bool
[ "Assign", "RBAC", "element", "into", "user" ]
train
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/auth/drivers/FileRbac.php#L55-L65
devlabmtl/haven-core
Twig/Extension/HavenRoutingExtension.php
HavenRoutingExtension.isUrlGenerationSafe
public function isUrlGenerationSafe(\Twig_Node $argsNode) { // support named arguments $paramsNode = $argsNode->hasNode('parameters') ? $argsNode->getNode('parameters') : ( $argsNode->hasNode(1) ? $argsNode->getNode(1) : null ); if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 && (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant) ) { return array('html'); } return array(); }
php
public function isUrlGenerationSafe(\Twig_Node $argsNode) { // support named arguments $paramsNode = $argsNode->hasNode('parameters') ? $argsNode->getNode('parameters') : ( $argsNode->hasNode(1) ? $argsNode->getNode(1) : null ); if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 && (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant) ) { return array('html'); } return array(); }
[ "public", "function", "isUrlGenerationSafe", "(", "\\", "Twig_Node", "$", "argsNode", ")", "{", "// support named arguments", "$", "paramsNode", "=", "$", "argsNode", "->", "hasNode", "(", "'parameters'", ")", "?", "$", "argsNode", "->", "getNode", "(", "'parameters'", ")", ":", "(", "$", "argsNode", "->", "hasNode", "(", "1", ")", "?", "$", "argsNode", "->", "getNode", "(", "1", ")", ":", "null", ")", ";", "if", "(", "null", "===", "$", "paramsNode", "||", "$", "paramsNode", "instanceof", "\\", "Twig_Node_Expression_Array", "&&", "count", "(", "$", "paramsNode", ")", "<=", "2", "&&", "(", "!", "$", "paramsNode", "->", "hasNode", "(", "1", ")", "||", "$", "paramsNode", "->", "getNode", "(", "1", ")", "instanceof", "\\", "Twig_Node_Expression_Constant", ")", ")", "{", "return", "array", "(", "'html'", ")", ";", "}", "return", "array", "(", ")", ";", "}" ]
Determines at compile time whether the generated URL will be safe and thus saving the unneeded automatic escaping for performance reasons. The URL generation process percent encodes non-alphanumeric characters. So there is no risk that malicious/invalid characters are part of the URL. The only character within an URL that must be escaped in html is the ampersand ("&") which separates query params. So we cannot mark the URL generation as always safe, but only when we are sure there won't be multiple query params. This is the case when there are none or only one constant parameter given. E.g. we know beforehand this will be safe: - path('route') - path('route', {'param': 'value'}) But the following may not: - path('route', var) - path('route', {'param': ['val1', 'val2'] }) // a sub-array - path('route', {'param1': 'value1', 'param2': 'value2'}) If param1 and param2 reference placeholder in the route, it would still be safe. But we don't know. @param \Twig_Node $argsNode The arguments of the path/url function @return array An array with the contexts the URL is safe
[ "Determines", "at", "compile", "time", "whether", "the", "generated", "URL", "will", "be", "safe", "and", "thus", "saving", "the", "unneeded", "automatic", "escaping", "for", "performance", "reasons", "." ]
train
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Twig/Extension/HavenRoutingExtension.php#L66-L80
jitesoft/php-exceptions
src/Json/JsonException.php
JsonException.toArray
public function toArray() { $arr = parent::toArray(); $arr['json'] = $this->json; $arr['file_name'] = $this->fileName; $arr['file_path'] = $this->path; return $arr; }
php
public function toArray() { $arr = parent::toArray(); $arr['json'] = $this->json; $arr['file_name'] = $this->fileName; $arr['file_path'] = $this->path; return $arr; }
[ "public", "function", "toArray", "(", ")", "{", "$", "arr", "=", "parent", "::", "toArray", "(", ")", ";", "$", "arr", "[", "'json'", "]", "=", "$", "this", "->", "json", ";", "$", "arr", "[", "'file_name'", "]", "=", "$", "this", "->", "fileName", ";", "$", "arr", "[", "'file_path'", "]", "=", "$", "this", "->", "path", ";", "return", "$", "arr", ";", "}" ]
Get the exception as an associative array. <pre> { 'type' => (string) 'error' => (string) 'code' => (int) 'file' => (string) 'line' => (int) 'trace' => (array) 'inner' => (array) 'json' => (string) } </pre> @return array
[ "Get", "the", "exception", "as", "an", "associative", "array", "." ]
train
https://github.com/jitesoft/php-exceptions/blob/f391c5afd75a08c65338ad874dd43c5ab69e061c/src/Json/JsonException.php#L81-L87
OxfordInfoLabs/kinikit-core
src/Util/Configuration/ConfigFile.php
ConfigFile.getParameter
public function getParameter($key) { if (array_key_exists ( $key, $this->parameters )) return $this->parameters [$key]; else return null; }
php
public function getParameter($key) { if (array_key_exists ( $key, $this->parameters )) return $this->parameters [$key]; else return null; }
[ "public", "function", "getParameter", "(", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "parameters", ")", ")", "return", "$", "this", "->", "parameters", "[", "$", "key", "]", ";", "else", "return", "null", ";", "}" ]
Get the parameter matching the passed key or null if non existent @param string $key
[ "Get", "the", "parameter", "matching", "the", "passed", "key", "or", "null", "if", "non", "existent" ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Configuration/ConfigFile.php#L37-L42
OxfordInfoLabs/kinikit-core
src/Util/Configuration/ConfigFile.php
ConfigFile.getConfigFileText
public function getConfigFileText() { $configFileText = ""; foreach ( $this->parameters as $key => $value ) { $configFileText .= $key . "=" . $value . "\n"; } return $configFileText; }
php
public function getConfigFileText() { $configFileText = ""; foreach ( $this->parameters as $key => $value ) { $configFileText .= $key . "=" . $value . "\n"; } return $configFileText; }
[ "public", "function", "getConfigFileText", "(", ")", "{", "$", "configFileText", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "parameters", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "configFileText", ".=", "$", "key", ".", "\"=\"", ".", "$", "value", ".", "\"\\n\"", ";", "}", "return", "$", "configFileText", ";", "}" ]
Return the actual text which would be written out by the save method. This is particularly useful in situations like the PropertiesResource where the output needs to be injected into a resource. @return string
[ "Return", "the", "actual", "text", "which", "would", "be", "written", "out", "by", "the", "save", "method", ".", "This", "is", "particularly", "useful", "in", "situations", "like", "the", "PropertiesResource", "where", "the", "output", "needs", "to", "be", "injected", "into", "a", "resource", "." ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Configuration/ConfigFile.php#L88-L94
OxfordInfoLabs/kinikit-core
src/Util/Configuration/ConfigFile.php
ConfigFile.save
public function save($filePath = null) { // Determine the correct file path. $filePath = ($filePath == null) ? $this->configFilePath : $filePath; // Store the file file_put_contents ( $filePath, $this->getConfigFileText () ); }
php
public function save($filePath = null) { // Determine the correct file path. $filePath = ($filePath == null) ? $this->configFilePath : $filePath; // Store the file file_put_contents ( $filePath, $this->getConfigFileText () ); }
[ "public", "function", "save", "(", "$", "filePath", "=", "null", ")", "{", "// Determine the correct file path.", "$", "filePath", "=", "(", "$", "filePath", "==", "null", ")", "?", "$", "this", "->", "configFilePath", ":", "$", "filePath", ";", "// Store the file", "file_put_contents", "(", "$", "filePath", ",", "$", "this", "->", "getConfigFileText", "(", ")", ")", ";", "}" ]
Save the config file back out. If null supplied for filepath, the constructed configFilePath is used
[ "Save", "the", "config", "file", "back", "out", ".", "If", "null", "supplied", "for", "filepath", "the", "constructed", "configFilePath", "is", "used" ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Configuration/ConfigFile.php#L100-L107
OxfordInfoLabs/kinikit-core
src/Util/Configuration/ConfigFile.php
ConfigFile.parseFile
private function parseFile($configFilePath) { $configFileText = file_get_contents ( $configFilePath ); // Now split each line on carriage return $lines = explode ( "\n", $configFileText ); // Now loop through each line, attempting a split by equals sign to get key value pairs out. foreach ( $lines as $line ) { // Firstly split lines on # to ensure that comments are ignored $splitComment = explode ( "#", $line ); $propertyLine = trim ( $splitComment [0] ); // if the first entry is zero length when trimmed we know the line is a comment so we ignore the whole line // Otherwise continue and use the bit before any potential comment if (strlen ( $propertyLine ) > 0) { // Now split into key, value on = $positionOfFirstEquals = strpos ( $propertyLine, "=" ); // If there are not 2 or more array entries at this point we should complain unless we meet a blank line. if ($positionOfFirstEquals) { $this->parameters [trim ( substr ( $propertyLine, 0, $positionOfFirstEquals ) )] = trim ( substr ( $propertyLine, $positionOfFirstEquals + 1 ) ); } else { throw new Exception ( "Error in config file: Parameter '" . $propertyLine . "' Does not have a value" ); } } } }
php
private function parseFile($configFilePath) { $configFileText = file_get_contents ( $configFilePath ); // Now split each line on carriage return $lines = explode ( "\n", $configFileText ); // Now loop through each line, attempting a split by equals sign to get key value pairs out. foreach ( $lines as $line ) { // Firstly split lines on # to ensure that comments are ignored $splitComment = explode ( "#", $line ); $propertyLine = trim ( $splitComment [0] ); // if the first entry is zero length when trimmed we know the line is a comment so we ignore the whole line // Otherwise continue and use the bit before any potential comment if (strlen ( $propertyLine ) > 0) { // Now split into key, value on = $positionOfFirstEquals = strpos ( $propertyLine, "=" ); // If there are not 2 or more array entries at this point we should complain unless we meet a blank line. if ($positionOfFirstEquals) { $this->parameters [trim ( substr ( $propertyLine, 0, $positionOfFirstEquals ) )] = trim ( substr ( $propertyLine, $positionOfFirstEquals + 1 ) ); } else { throw new Exception ( "Error in config file: Parameter '" . $propertyLine . "' Does not have a value" ); } } } }
[ "private", "function", "parseFile", "(", "$", "configFilePath", ")", "{", "$", "configFileText", "=", "file_get_contents", "(", "$", "configFilePath", ")", ";", "// Now split each line on carriage return", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "configFileText", ")", ";", "// Now loop through each line, attempting a split by equals sign to get key value pairs out.", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "// Firstly split lines on # to ensure that comments are ignored", "$", "splitComment", "=", "explode", "(", "\"#\"", ",", "$", "line", ")", ";", "$", "propertyLine", "=", "trim", "(", "$", "splitComment", "[", "0", "]", ")", ";", "// if the first entry is zero length when trimmed we know the line is a comment so we ignore the whole line", "// Otherwise continue and use the bit before any potential comment", "if", "(", "strlen", "(", "$", "propertyLine", ")", ">", "0", ")", "{", "// Now split into key, value on =", "$", "positionOfFirstEquals", "=", "strpos", "(", "$", "propertyLine", ",", "\"=\"", ")", ";", "// If there are not 2 or more array entries at this point we should complain unless we meet a blank line.", "if", "(", "$", "positionOfFirstEquals", ")", "{", "$", "this", "->", "parameters", "[", "trim", "(", "substr", "(", "$", "propertyLine", ",", "0", ",", "$", "positionOfFirstEquals", ")", ")", "]", "=", "trim", "(", "substr", "(", "$", "propertyLine", ",", "$", "positionOfFirstEquals", "+", "1", ")", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"Error in config file: Parameter '\"", ".", "$", "propertyLine", ".", "\"' Does not have a value\"", ")", ";", "}", "}", "}", "}" ]
Parse function. Splits the config file into lines and then looks for key value pairs of the form key=value
[ "Parse", "function", ".", "Splits", "the", "config", "file", "into", "lines", "and", "then", "looks", "for", "key", "value", "pairs", "of", "the", "form", "key", "=", "value" ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Configuration/ConfigFile.php#L113-L143
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.doTwoFactorAuthLogin
public function doTwoFactorAuthLogin($userId) { // Get the 2FA code $codeToInput = $this->getCodeToInput(); // Update the user's database record wtih the 2FA code & timestamp $this->updateUserRecordWithTwoFactorAuthCode($codeToInput, $userId); // Put together the SMS message $message = config('lasallecmsfrontend.site_name'); $message .= ". Your two factor authorization login code is "; $message .= $codeToInput; $this->shortMessageService->sendSMS($this->getUserPhoneCountryCode($userId), $this->getUserPhoneNumber($userId), $message); }
php
public function doTwoFactorAuthLogin($userId) { // Get the 2FA code $codeToInput = $this->getCodeToInput(); // Update the user's database record wtih the 2FA code & timestamp $this->updateUserRecordWithTwoFactorAuthCode($codeToInput, $userId); // Put together the SMS message $message = config('lasallecmsfrontend.site_name'); $message .= ". Your two factor authorization login code is "; $message .= $codeToInput; $this->shortMessageService->sendSMS($this->getUserPhoneCountryCode($userId), $this->getUserPhoneNumber($userId), $message); }
[ "public", "function", "doTwoFactorAuthLogin", "(", "$", "userId", ")", "{", "// Get the 2FA code", "$", "codeToInput", "=", "$", "this", "->", "getCodeToInput", "(", ")", ";", "// Update the user's database record wtih the 2FA code & timestamp", "$", "this", "->", "updateUserRecordWithTwoFactorAuthCode", "(", "$", "codeToInput", ",", "$", "userId", ")", ";", "// Put together the SMS message", "$", "message", "=", "config", "(", "'lasallecmsfrontend.site_name'", ")", ";", "$", "message", ".=", "\". Your two factor authorization login code is \"", ";", "$", "message", ".=", "$", "codeToInput", ";", "$", "this", "->", "shortMessageService", "->", "sendSMS", "(", "$", "this", "->", "getUserPhoneCountryCode", "(", "$", "userId", ")", ",", "$", "this", "->", "getUserPhoneNumber", "(", "$", "userId", ")", ",", "$", "message", ")", ";", "}" ]
Two Factor Authorization for the front-end LOGIN @param int $userId User ID @return void
[ "Two", "Factor", "Authorization", "for", "the", "front", "-", "end", "LOGIN" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L88-L102
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.doTwoFactorAuthRegistration
public function doTwoFactorAuthRegistration($data) { // Get the 2FA code $codeToInput = $this->getCodeToInput(); // Set this 2FA code into a session variable, since // this is the only opportunity to so save the ephemerally generated 2FA $this->request->session()->put('codeToInput', $codeToInput); // Put together the SMS message $message = config('lasallecmsfrontend.site_name'); $message .= ". Your two factor authorization login code is "; $message .= $codeToInput; $this->shortMessageService->sendSMS($data['phone_country_code'], $data['phone_number'], $message); }
php
public function doTwoFactorAuthRegistration($data) { // Get the 2FA code $codeToInput = $this->getCodeToInput(); // Set this 2FA code into a session variable, since // this is the only opportunity to so save the ephemerally generated 2FA $this->request->session()->put('codeToInput', $codeToInput); // Put together the SMS message $message = config('lasallecmsfrontend.site_name'); $message .= ". Your two factor authorization login code is "; $message .= $codeToInput; $this->shortMessageService->sendSMS($data['phone_country_code'], $data['phone_number'], $message); }
[ "public", "function", "doTwoFactorAuthRegistration", "(", "$", "data", ")", "{", "// Get the 2FA code", "$", "codeToInput", "=", "$", "this", "->", "getCodeToInput", "(", ")", ";", "// Set this 2FA code into a session variable, since", "// this is the only opportunity to so save the ephemerally generated 2FA", "$", "this", "->", "request", "->", "session", "(", ")", "->", "put", "(", "'codeToInput'", ",", "$", "codeToInput", ")", ";", "// Put together the SMS message", "$", "message", "=", "config", "(", "'lasallecmsfrontend.site_name'", ")", ";", "$", "message", ".=", "\". Your two factor authorization login code is \"", ";", "$", "message", ".=", "$", "codeToInput", ";", "$", "this", "->", "shortMessageService", "->", "sendSMS", "(", "$", "data", "[", "'phone_country_code'", "]", ",", "$", "data", "[", "'phone_number'", "]", ",", "$", "message", ")", ";", "}" ]
Two Factor Authorization for the front-end REGISTRATION @param array $data @return void
[ "Two", "Factor", "Authorization", "for", "the", "front", "-", "end", "REGISTRATION" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L110-L127
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.isTwoFactorAuthFormTimeout
public function isTwoFactorAuthFormTimeout($userId=null, $startTime=null ) { if (isset($userId)) { // User wants to login, performing 2FA for this login $startTime = strtotime($this->getUserSmsTokenCreatedAt($userId)); } else { // New front-end registration, performing 2FA for this registration $startTime = strtotime($startTime); } $now = strtotime(Carbon::now()); // The time difference is in seconds, we want in minutes $timeDiff = ($now - $startTime)/60; $minutes2faFormIsLive = config('lasallecmsusermanagement.auth_2fa_minutes_smscode_is_live'); if ($timeDiff > $minutes2faFormIsLive) { if (isset($userId)) { // clear out the user's 2FA sms code and timestamp $this->clearUserTwoFactorAuthFields($userId); // clear the user_id session variable $this->clearUserIdSessionVar(); } else { $this->clearTwoFactorAuthCodeToInput(); } return true; } return false; }
php
public function isTwoFactorAuthFormTimeout($userId=null, $startTime=null ) { if (isset($userId)) { // User wants to login, performing 2FA for this login $startTime = strtotime($this->getUserSmsTokenCreatedAt($userId)); } else { // New front-end registration, performing 2FA for this registration $startTime = strtotime($startTime); } $now = strtotime(Carbon::now()); // The time difference is in seconds, we want in minutes $timeDiff = ($now - $startTime)/60; $minutes2faFormIsLive = config('lasallecmsusermanagement.auth_2fa_minutes_smscode_is_live'); if ($timeDiff > $minutes2faFormIsLive) { if (isset($userId)) { // clear out the user's 2FA sms code and timestamp $this->clearUserTwoFactorAuthFields($userId); // clear the user_id session variable $this->clearUserIdSessionVar(); } else { $this->clearTwoFactorAuthCodeToInput(); } return true; } return false; }
[ "public", "function", "isTwoFactorAuthFormTimeout", "(", "$", "userId", "=", "null", ",", "$", "startTime", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "userId", ")", ")", "{", "// User wants to login, performing 2FA for this login", "$", "startTime", "=", "strtotime", "(", "$", "this", "->", "getUserSmsTokenCreatedAt", "(", "$", "userId", ")", ")", ";", "}", "else", "{", "// New front-end registration, performing 2FA for this registration", "$", "startTime", "=", "strtotime", "(", "$", "startTime", ")", ";", "}", "$", "now", "=", "strtotime", "(", "Carbon", "::", "now", "(", ")", ")", ";", "// The time difference is in seconds, we want in minutes", "$", "timeDiff", "=", "(", "$", "now", "-", "$", "startTime", ")", "/", "60", ";", "$", "minutes2faFormIsLive", "=", "config", "(", "'lasallecmsusermanagement.auth_2fa_minutes_smscode_is_live'", ")", ";", "if", "(", "$", "timeDiff", ">", "$", "minutes2faFormIsLive", ")", "{", "if", "(", "isset", "(", "$", "userId", ")", ")", "{", "// clear out the user's 2FA sms code and timestamp", "$", "this", "->", "clearUserTwoFactorAuthFields", "(", "$", "userId", ")", ";", "// clear the user_id session variable", "$", "this", "->", "clearUserIdSessionVar", "(", ")", ";", "}", "else", "{", "$", "this", "->", "clearTwoFactorAuthCodeToInput", "(", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Has too much time passed between issuing the 2FA code and this code being entered into the verification form? @param int $userId User ID --> if null, then called by 2FA registration @param datetime $startTime Time 2FA form created --> if null, then called by 2FA login @return bool
[ "Has", "too", "much", "time", "passed", "between", "issuing", "the", "2FA", "code", "and", "this", "code", "being", "entered", "into", "the", "verification", "form?" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L137-L172
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.isInputtedTwoFactorAuthCodeCorrect
public function isInputtedTwoFactorAuthCodeCorrect($userId=null) { $inputted2faCode = $this->request->input('2facode'); if (isset($userId)) { $sent2faCode = $this->getUserSmsToken($userId); } else { $sent2faCode = $this->request->session()->get('codeToInput'); } if ($inputted2faCode == $sent2faCode) { return true; } return false; }
php
public function isInputtedTwoFactorAuthCodeCorrect($userId=null) { $inputted2faCode = $this->request->input('2facode'); if (isset($userId)) { $sent2faCode = $this->getUserSmsToken($userId); } else { $sent2faCode = $this->request->session()->get('codeToInput'); } if ($inputted2faCode == $sent2faCode) { return true; } return false; }
[ "public", "function", "isInputtedTwoFactorAuthCodeCorrect", "(", "$", "userId", "=", "null", ")", "{", "$", "inputted2faCode", "=", "$", "this", "->", "request", "->", "input", "(", "'2facode'", ")", ";", "if", "(", "isset", "(", "$", "userId", ")", ")", "{", "$", "sent2faCode", "=", "$", "this", "->", "getUserSmsToken", "(", "$", "userId", ")", ";", "}", "else", "{", "$", "sent2faCode", "=", "$", "this", "->", "request", "->", "session", "(", ")", "->", "get", "(", "'codeToInput'", ")", ";", "}", "if", "(", "$", "inputted2faCode", "==", "$", "sent2faCode", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Did the user input the correct 2FA code? @param int $userId User ID --> if null, then called by 2FA registration; otherwise, called by 2FA login @return bool
[ "Did", "the", "user", "input", "the", "correct", "2FA", "code?" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L182-L197
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.isUserTwoFactorAuthEnabled
public function isUserTwoFactorAuthEnabled($userId) { $result = DB::table('users') ->where('id', '=', $userId) ->value('two_factor_auth_enabled') ; if ($result) { return true; } return false; }
php
public function isUserTwoFactorAuthEnabled($userId) { $result = DB::table('users') ->where('id', '=', $userId) ->value('two_factor_auth_enabled') ; if ($result) { return true; } return false; }
[ "public", "function", "isUserTwoFactorAuthEnabled", "(", "$", "userId", ")", "{", "$", "result", "=", "DB", "::", "table", "(", "'users'", ")", "->", "where", "(", "'id'", ",", "'='", ",", "$", "userId", ")", "->", "value", "(", "'two_factor_auth_enabled'", ")", ";", "if", "(", "$", "result", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Is user enabled for Two Factor Authorization @param int $userId User ID @return bool
[ "Is", "user", "enabled", "for", "Two", "Factor", "Authorization" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L253-L263
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.existstUserCountryCodeAndPhoneNumber
public function existstUserCountryCodeAndPhoneNumber($userId) { $countryCode = DB::table('users') ->where('id', '=', $userId) ->value('phone_country_code') ; $phoneNumber = DB::table('users') ->where('id', '=', $userId) ->value('phone_number') ; if ((!$countryCode) || (!$phoneNumber)) { return false; } return true; }
php
public function existstUserCountryCodeAndPhoneNumber($userId) { $countryCode = DB::table('users') ->where('id', '=', $userId) ->value('phone_country_code') ; $phoneNumber = DB::table('users') ->where('id', '=', $userId) ->value('phone_number') ; if ((!$countryCode) || (!$phoneNumber)) { return false; } return true; }
[ "public", "function", "existstUserCountryCodeAndPhoneNumber", "(", "$", "userId", ")", "{", "$", "countryCode", "=", "DB", "::", "table", "(", "'users'", ")", "->", "where", "(", "'id'", ",", "'='", ",", "$", "userId", ")", "->", "value", "(", "'phone_country_code'", ")", ";", "$", "phoneNumber", "=", "DB", "::", "table", "(", "'users'", ")", "->", "where", "(", "'id'", ",", "'='", ",", "$", "userId", ")", "->", "value", "(", "'phone_number'", ")", ";", "if", "(", "(", "!", "$", "countryCode", ")", "||", "(", "!", "$", "phoneNumber", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Does the user have a country code and phone number for 2FA? @param int $userId User ID
[ "Does", "the", "user", "have", "a", "country", "code", "and", "phone", "number", "for", "2FA?" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L270-L286
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.updateUserRecordWithTwoFactorAuthCode
public function updateUserRecordWithTwoFactorAuthCode($codeToInput, $userId) { $now = Carbon::now(); DB::table('users') ->where('id', $userId) ->update(['sms_token' => $codeToInput, 'sms_token_created_at' => $now] ) ; }
php
public function updateUserRecordWithTwoFactorAuthCode($codeToInput, $userId) { $now = Carbon::now(); DB::table('users') ->where('id', $userId) ->update(['sms_token' => $codeToInput, 'sms_token_created_at' => $now] ) ; }
[ "public", "function", "updateUserRecordWithTwoFactorAuthCode", "(", "$", "codeToInput", ",", "$", "userId", ")", "{", "$", "now", "=", "Carbon", "::", "now", "(", ")", ";", "DB", "::", "table", "(", "'users'", ")", "->", "where", "(", "'id'", ",", "$", "userId", ")", "->", "update", "(", "[", "'sms_token'", "=>", "$", "codeToInput", ",", "'sms_token_created_at'", "=>", "$", "now", "]", ")", ";", "}" ]
UPDATE the user record for fields "sms_token" and "sms_token_created_at" @param text $codeToInput The code sent to the user via sms that has to be entered into a form to allow login @param int $userId User ID @return void
[ "UPDATE", "the", "user", "record", "for", "fields", "sms_token", "and", "sms_token_created_at" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L344-L352
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.updateUserRecordWithLastlogin
public function updateUserRecordWithLastlogin($userId) { $now = Carbon::now(); $ip = $this->request->getClientIp(); DB::table('users') ->where('id', $userId) ->update(['last_login' => $now, 'last_login_ip' => $ip] ) ; }
php
public function updateUserRecordWithLastlogin($userId) { $now = Carbon::now(); $ip = $this->request->getClientIp(); DB::table('users') ->where('id', $userId) ->update(['last_login' => $now, 'last_login_ip' => $ip] ) ; }
[ "public", "function", "updateUserRecordWithLastlogin", "(", "$", "userId", ")", "{", "$", "now", "=", "Carbon", "::", "now", "(", ")", ";", "$", "ip", "=", "$", "this", "->", "request", "->", "getClientIp", "(", ")", ";", "DB", "::", "table", "(", "'users'", ")", "->", "where", "(", "'id'", ",", "$", "userId", ")", "->", "update", "(", "[", "'last_login'", "=>", "$", "now", ",", "'last_login_ip'", "=>", "$", "ip", "]", ")", ";", "}" ]
UPDATE the user record for fields "last_login" and "last_login_ip" This method is here because it is convenient, as this class is already injected in the auth classes @param int $userId User ID @return void
[ "UPDATE", "the", "user", "record", "for", "fields", "last_login", "and", "last_login_ip" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L386-L395
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.setCookie
public function setCookie($response) { if (!Cookie::has('successful_login')) { // what is the cookie's lifetime, in minutes $numberOfDays = config('lasallecmsusermanagement.auth_2fa_cookie_lifetime_days'); // the max number of days is 30, and the min is 1 if ($numberOfDays > 30) { $numberOfDays = 30; } if ($numberOfDays < 1) { $numberOfDays = 1; } // convert days to minutes -- there are 1,440 minutes in a day $numberOfMinutes = $numberOfDays * 1440; return $response->withCookie(cookie('successful_login', Carbon::now(), $numberOfMinutes)); } return $response; }
php
public function setCookie($response) { if (!Cookie::has('successful_login')) { // what is the cookie's lifetime, in minutes $numberOfDays = config('lasallecmsusermanagement.auth_2fa_cookie_lifetime_days'); // the max number of days is 30, and the min is 1 if ($numberOfDays > 30) { $numberOfDays = 30; } if ($numberOfDays < 1) { $numberOfDays = 1; } // convert days to minutes -- there are 1,440 minutes in a day $numberOfMinutes = $numberOfDays * 1440; return $response->withCookie(cookie('successful_login', Carbon::now(), $numberOfMinutes)); } return $response; }
[ "public", "function", "setCookie", "(", "$", "response", ")", "{", "if", "(", "!", "Cookie", "::", "has", "(", "'successful_login'", ")", ")", "{", "// what is the cookie's lifetime, in minutes", "$", "numberOfDays", "=", "config", "(", "'lasallecmsusermanagement.auth_2fa_cookie_lifetime_days'", ")", ";", "// the max number of days is 30, and the min is 1", "if", "(", "$", "numberOfDays", ">", "30", ")", "{", "$", "numberOfDays", "=", "30", ";", "}", "if", "(", "$", "numberOfDays", "<", "1", ")", "{", "$", "numberOfDays", "=", "1", ";", "}", "// convert days to minutes -- there are 1,440 minutes in a day", "$", "numberOfMinutes", "=", "$", "numberOfDays", "*", "1440", ";", "return", "$", "response", "->", "withCookie", "(", "cookie", "(", "'successful_login'", ",", "Carbon", "::", "now", "(", ")", ",", "$", "numberOfMinutes", ")", ")", ";", "}", "return", "$", "response", ";", "}" ]
Set (make) the 2FA cookie @param Illuminate\Http\Response $response @return Illuminate\Http\Response
[ "Set", "(", "make", ")", "the", "2FA", "cookie" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L409-L432
lasallecms/lasallecms-l5-usermanagement-pkg
src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php
TwoFactorAuthHelper.redirectPathUponSuccessfulFrontendLogin
public function redirectPathUponSuccessfulFrontendLogin() { if (property_exists($this, 'redirectPath')) { return $this->redirectPath; } if (property_exists($this, 'redirectPath')) { return $this->redirectTo; } if (config('lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end') != '') { return config('lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end'); } return '/home'; }
php
public function redirectPathUponSuccessfulFrontendLogin() { if (property_exists($this, 'redirectPath')) { return $this->redirectPath; } if (property_exists($this, 'redirectPath')) { return $this->redirectTo; } if (config('lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end') != '') { return config('lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end'); } return '/home'; }
[ "public", "function", "redirectPathUponSuccessfulFrontendLogin", "(", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "'redirectPath'", ")", ")", "{", "return", "$", "this", "->", "redirectPath", ";", "}", "if", "(", "property_exists", "(", "$", "this", ",", "'redirectPath'", ")", ")", "{", "return", "$", "this", "->", "redirectTo", ";", "}", "if", "(", "config", "(", "'lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end'", ")", "!=", "''", ")", "{", "return", "config", "(", "'lasasllecmsfrontend.frontend_redirect_to_this_view_when_user_successfully_logged_in_to_front_end'", ")", ";", "}", "return", "'/home'", ";", "}" ]
Upon successful front-end login, redirect to this path @return string
[ "Upon", "successful", "front", "-", "end", "login", "redirect", "to", "this", "path" ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/TwoFactorAuthorization/TwoFactorAuthHelper.php#L495-L510
Mandarin-Medien/MMCmfContentBundle
DependencyInjection/MMCmfContentExtension.php
MMCmfContentExtension.load
public function load(array $configs, ContainerBuilder $container) { $config = array(); foreach ($configs as $subConfig) { $config = array_merge_recursive($config, $subConfig); } $configuration = new Configuration(); $config = $this->processConfiguration($configuration, array($config)); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); $this->processConfig($container, $config); $this->configureContentNodes($container,$config); }
php
public function load(array $configs, ContainerBuilder $container) { $config = array(); foreach ($configs as $subConfig) { $config = array_merge_recursive($config, $subConfig); } $configuration = new Configuration(); $config = $this->processConfiguration($configuration, array($config)); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); $this->processConfig($container, $config); $this->configureContentNodes($container,$config); }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "config", "=", "array", "(", ")", ";", "foreach", "(", "$", "configs", "as", "$", "subConfig", ")", "{", "$", "config", "=", "array_merge_recursive", "(", "$", "config", ",", "$", "subConfig", ")", ";", "}", "$", "configuration", "=", "new", "Configuration", "(", ")", ";", "$", "config", "=", "$", "this", "->", "processConfiguration", "(", "$", "configuration", ",", "array", "(", "$", "config", ")", ")", ";", "$", "loader", "=", "new", "Loader", "\\", "YamlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.yml'", ")", ";", "$", "this", "->", "processConfig", "(", "$", "container", ",", "$", "config", ")", ";", "$", "this", "->", "configureContentNodes", "(", "$", "container", ",", "$", "config", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Mandarin-Medien/MMCmfContentBundle/blob/503ab31cef3ce068f767de5b72f833526355b726/DependencyInjection/MMCmfContentExtension.php#L20-L37
apioo/psx-validate
src/Validate.php
Validate.apply
public function apply($value, $type = self::TYPE_STRING, array $filters = array(), $title = null, $required = true) { $result = $this->validate($value, $type, $filters, $title, $required); if ($result->hasError()) { throw new ValidationException($result->getFirstError(), $title, $result); } elseif ($result->isSuccessful()) { return $result->getValue(); } return null; }
php
public function apply($value, $type = self::TYPE_STRING, array $filters = array(), $title = null, $required = true) { $result = $this->validate($value, $type, $filters, $title, $required); if ($result->hasError()) { throw new ValidationException($result->getFirstError(), $title, $result); } elseif ($result->isSuccessful()) { return $result->getValue(); } return null; }
[ "public", "function", "apply", "(", "$", "value", ",", "$", "type", "=", "self", "::", "TYPE_STRING", ",", "array", "$", "filters", "=", "array", "(", ")", ",", "$", "title", "=", "null", ",", "$", "required", "=", "true", ")", "{", "$", "result", "=", "$", "this", "->", "validate", "(", "$", "value", ",", "$", "type", ",", "$", "filters", ",", "$", "title", ",", "$", "required", ")", ";", "if", "(", "$", "result", "->", "hasError", "(", ")", ")", "{", "throw", "new", "ValidationException", "(", "$", "result", "->", "getFirstError", "(", ")", ",", "$", "title", ",", "$", "result", ")", ";", "}", "elseif", "(", "$", "result", "->", "isSuccessful", "(", ")", ")", "{", "return", "$", "result", "->", "getValue", "(", ")", ";", "}", "return", "null", ";", "}" ]
Applies filter on the given value and returns the value on success or throws an exception if an error occured @param string $value @param string $type @param \PSX\Validate\FilterInterface[]|callable $filters @param string $title @param boolean $required @return mixed
[ "Applies", "filter", "on", "the", "given", "value", "and", "returns", "the", "value", "on", "success", "or", "throws", "an", "exception", "if", "an", "error", "occured" ]
train
https://github.com/apioo/psx-validate/blob/4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d/src/Validate.php#L53-L64
apioo/psx-validate
src/Validate.php
Validate.validate
public function validate($value, $type = self::TYPE_STRING, array $filters = array(), $title = null, $required = true) { $result = new Result(); if ($title === null) { $title = 'Unknown'; } if ($value === null) { if ($required === true) { $result->addError(sprintf('%s is not set', $title)); return $result; } elseif ($required === false) { return $result; } } else { $value = $this->transformType($value, $type); } foreach ($filters as $filter) { $error = null; if ($filter instanceof FilterInterface) { $return = $filter->apply($value); $error = $filter->getErrorMessage(); } elseif (is_callable($filter)) { $return = call_user_func_array($filter, array($value)); } else { throw new InvalidArgumentException('Filter must be either a callable or instanceof PSX\Validate\FilterInterface'); } if ($return === false) { if ($error === null) { $error = '%s is not valid'; } $result->addError(sprintf($error, $title)); return $result; } elseif ($return === true) { // the filter returns true so the validation was successful } else { $value = $return; } } $result->setValue($value); return $result; }
php
public function validate($value, $type = self::TYPE_STRING, array $filters = array(), $title = null, $required = true) { $result = new Result(); if ($title === null) { $title = 'Unknown'; } if ($value === null) { if ($required === true) { $result->addError(sprintf('%s is not set', $title)); return $result; } elseif ($required === false) { return $result; } } else { $value = $this->transformType($value, $type); } foreach ($filters as $filter) { $error = null; if ($filter instanceof FilterInterface) { $return = $filter->apply($value); $error = $filter->getErrorMessage(); } elseif (is_callable($filter)) { $return = call_user_func_array($filter, array($value)); } else { throw new InvalidArgumentException('Filter must be either a callable or instanceof PSX\Validate\FilterInterface'); } if ($return === false) { if ($error === null) { $error = '%s is not valid'; } $result->addError(sprintf($error, $title)); return $result; } elseif ($return === true) { // the filter returns true so the validation was successful } else { $value = $return; } } $result->setValue($value); return $result; }
[ "public", "function", "validate", "(", "$", "value", ",", "$", "type", "=", "self", "::", "TYPE_STRING", ",", "array", "$", "filters", "=", "array", "(", ")", ",", "$", "title", "=", "null", ",", "$", "required", "=", "true", ")", "{", "$", "result", "=", "new", "Result", "(", ")", ";", "if", "(", "$", "title", "===", "null", ")", "{", "$", "title", "=", "'Unknown'", ";", "}", "if", "(", "$", "value", "===", "null", ")", "{", "if", "(", "$", "required", "===", "true", ")", "{", "$", "result", "->", "addError", "(", "sprintf", "(", "'%s is not set'", ",", "$", "title", ")", ")", ";", "return", "$", "result", ";", "}", "elseif", "(", "$", "required", "===", "false", ")", "{", "return", "$", "result", ";", "}", "}", "else", "{", "$", "value", "=", "$", "this", "->", "transformType", "(", "$", "value", ",", "$", "type", ")", ";", "}", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "error", "=", "null", ";", "if", "(", "$", "filter", "instanceof", "FilterInterface", ")", "{", "$", "return", "=", "$", "filter", "->", "apply", "(", "$", "value", ")", ";", "$", "error", "=", "$", "filter", "->", "getErrorMessage", "(", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "filter", ")", ")", "{", "$", "return", "=", "call_user_func_array", "(", "$", "filter", ",", "array", "(", "$", "value", ")", ")", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'Filter must be either a callable or instanceof PSX\\Validate\\FilterInterface'", ")", ";", "}", "if", "(", "$", "return", "===", "false", ")", "{", "if", "(", "$", "error", "===", "null", ")", "{", "$", "error", "=", "'%s is not valid'", ";", "}", "$", "result", "->", "addError", "(", "sprintf", "(", "$", "error", ",", "$", "title", ")", ")", ";", "return", "$", "result", ";", "}", "elseif", "(", "$", "return", "===", "true", ")", "{", "// the filter returns true so the validation was successful", "}", "else", "{", "$", "value", "=", "$", "return", ";", "}", "}", "$", "result", "->", "setValue", "(", "$", "value", ")", ";", "return", "$", "result", ";", "}" ]
Applies the $filter array containing PSX\Validate\FilterInterface on the $value. Returns a result object which contains the value and error messages from the filter. If $required is set to true an error will be added if the $value is null @param string $value @param string $type @param \PSX\Validate\FilterInterface[]|callable $filters @param string $title @param boolean $required @return \PSX\Validate\Result
[ "Applies", "the", "$filter", "array", "containing", "PSX", "\\", "Validate", "\\", "FilterInterface", "on", "the", "$value", ".", "Returns", "a", "result", "object", "which", "contains", "the", "value", "and", "error", "messages", "from", "the", "filter", ".", "If", "$required", "is", "set", "to", "true", "an", "error", "will", "be", "added", "if", "the", "$value", "is", "null" ]
train
https://github.com/apioo/psx-validate/blob/4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d/src/Validate.php#L79-L129
wakerscz/cms-base-module
src/Util/Validator.php
Validator.json
public static function json(IControl $field) : bool { try { Json::decode($field->getValue()); } catch (JsonException $exception) { return FALSE; } return TRUE; }
php
public static function json(IControl $field) : bool { try { Json::decode($field->getValue()); } catch (JsonException $exception) { return FALSE; } return TRUE; }
[ "public", "static", "function", "json", "(", "IControl", "$", "field", ")", ":", "bool", "{", "try", "{", "Json", "::", "decode", "(", "$", "field", "->", "getValue", "(", ")", ")", ";", "}", "catch", "(", "JsonException", "$", "exception", ")", "{", "return", "FALSE", ";", "}", "return", "TRUE", ";", "}" ]
Ověřuje JSON zda-li je obsah fieldu JSON Pokud chcete upravovat toto pravidlo, je potřeba upravit i JS pravidlo v souboru: Module ./assets/Common/validator/js/validator.js @param IControl $field @return bool
[ "Ověřuje", "JSON", "zda", "-", "li", "je", "obsah", "fieldu", "JSON", "Pokud", "chcete", "upravovat", "toto", "pravidlo", "je", "potřeba", "upravit", "i", "JS", "pravidlo", "v", "souboru", ":", "Module", ".", "/", "assets", "/", "Common", "/", "validator", "/", "js", "/", "validator", ".", "js" ]
train
https://github.com/wakerscz/cms-base-module/blob/3a14ea5d6a41999eb5b92fb956b55363806ff872/src/Util/Validator.php#L43-L55
LartTyler/PHP-DaybreakCommons
src/DaybreakStudios/Common/Utility/Counter.php
Counter.clear
public function clear($key = null) { if ($key === null) $this->counts->clear(); else $this->counts->remove($key); }
php
public function clear($key = null) { if ($key === null) $this->counts->clear(); else $this->counts->remove($key); }
[ "public", "function", "clear", "(", "$", "key", "=", "null", ")", "{", "if", "(", "$", "key", "===", "null", ")", "$", "this", "->", "counts", "->", "clear", "(", ")", ";", "else", "$", "this", "->", "counts", "->", "remove", "(", "$", "key", ")", ";", "}" ]
Clears the given key, or the entire counter if the key is not given. @param mixed $key the key to clear; pass null to clear the entire counter
[ "Clears", "the", "given", "key", "or", "the", "entire", "counter", "if", "the", "key", "is", "not", "given", "." ]
train
https://github.com/LartTyler/PHP-DaybreakCommons/blob/db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d/src/DaybreakStudios/Common/Utility/Counter.php#L61-L66
LartTyler/PHP-DaybreakCommons
src/DaybreakStudios/Common/Utility/Counter.php
Counter.add
public function add($key, $amount) { if (!$this->allowed($key)) throw new OutOfBoundsException(sprintf('"%s" is not an allowed key in strict mode', $key)); else if (!$this->has($key)) $this->counts->put($key, 0); $this->counts->put($key, $this->counts->get($key) + $amount); return $this->counts->get($key); }
php
public function add($key, $amount) { if (!$this->allowed($key)) throw new OutOfBoundsException(sprintf('"%s" is not an allowed key in strict mode', $key)); else if (!$this->has($key)) $this->counts->put($key, 0); $this->counts->put($key, $this->counts->get($key) + $amount); return $this->counts->get($key); }
[ "public", "function", "add", "(", "$", "key", ",", "$", "amount", ")", "{", "if", "(", "!", "$", "this", "->", "allowed", "(", "$", "key", ")", ")", "throw", "new", "OutOfBoundsException", "(", "sprintf", "(", "'\"%s\" is not an allowed key in strict mode'", ",", "$", "key", ")", ")", ";", "else", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "$", "this", "->", "counts", "->", "put", "(", "$", "key", ",", "0", ")", ";", "$", "this", "->", "counts", "->", "put", "(", "$", "key", ",", "$", "this", "->", "counts", "->", "get", "(", "$", "key", ")", "+", "$", "amount", ")", ";", "return", "$", "this", "->", "counts", "->", "get", "(", "$", "key", ")", ";", "}" ]
Adds the given amount to a key. If the key does not exist and the counter is not running in strict mode, it will be initialized to zero. @throws OutOfBoundsException if the counter is in strict mode and the key was not defined at construction @param mixed $key the key to add to @param int|float $amount the amount to add to the key @return int|float the new value of the key
[ "Adds", "the", "given", "amount", "to", "a", "key", ".", "If", "the", "key", "does", "not", "exist", "and", "the", "counter", "is", "not", "running", "in", "strict", "mode", "it", "will", "be", "initialized", "to", "zero", "." ]
train
https://github.com/LartTyler/PHP-DaybreakCommons/blob/db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d/src/DaybreakStudios/Common/Utility/Counter.php#L78-L87
staticka/staticka
src/Page.php
Page.uris
public function uris() { $uri = (string) $this->uri; $exists = isset($this->data['permalink']); $exists && $uri = $this->data['permalink']; $items = explode('/', (string) $uri); $items = array_filter((array) $items); return (array) array_values($items); }
php
public function uris() { $uri = (string) $this->uri; $exists = isset($this->data['permalink']); $exists && $uri = $this->data['permalink']; $items = explode('/', (string) $uri); $items = array_filter((array) $items); return (array) array_values($items); }
[ "public", "function", "uris", "(", ")", "{", "$", "uri", "=", "(", "string", ")", "$", "this", "->", "uri", ";", "$", "exists", "=", "isset", "(", "$", "this", "->", "data", "[", "'permalink'", "]", ")", ";", "$", "exists", "&&", "$", "uri", "=", "$", "this", "->", "data", "[", "'permalink'", "]", ";", "$", "items", "=", "explode", "(", "'/'", ",", "(", "string", ")", "$", "uri", ")", ";", "$", "items", "=", "array_filter", "(", "(", "array", ")", "$", "items", ")", ";", "return", "(", "array", ")", "array_values", "(", "$", "items", ")", ";", "}" ]
Returns an array of URI segments. @return array
[ "Returns", "an", "array", "of", "URI", "segments", "." ]
train
https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Page.php#L80-L93
staticka/staticka
src/Page.php
Page.layout
public function layout() { $exists = (boolean) isset($this->data['layout']); return $exists ? $this->data['layout'] : null; }
php
public function layout() { $exists = (boolean) isset($this->data['layout']); return $exists ? $this->data['layout'] : null; }
[ "public", "function", "layout", "(", ")", "{", "$", "exists", "=", "(", "boolean", ")", "isset", "(", "$", "this", "->", "data", "[", "'layout'", "]", ")", ";", "return", "$", "exists", "?", "$", "this", "->", "data", "[", "'layout'", "]", ":", "null", ";", "}" ]
Returns the layout of the page. @return string|null
[ "Returns", "the", "layout", "of", "the", "page", "." ]
train
https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Page.php#L100-L105
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/DoctrineMapper.php
DoctrineMapper.save
public function save($entity) { $this->checkIsEntity($entity); if (null !== $this->flushLock) { $this->flushLock->lock(); $this->entityManager->persist($entity); return $this->flushLock->unlock(); } $this->entityManager->persist($entity); $this->entityManager->flush(); return true; }
php
public function save($entity) { $this->checkIsEntity($entity); if (null !== $this->flushLock) { $this->flushLock->lock(); $this->entityManager->persist($entity); return $this->flushLock->unlock(); } $this->entityManager->persist($entity); $this->entityManager->flush(); return true; }
[ "public", "function", "save", "(", "$", "entity", ")", "{", "$", "this", "->", "checkIsEntity", "(", "$", "entity", ")", ";", "if", "(", "null", "!==", "$", "this", "->", "flushLock", ")", "{", "$", "this", "->", "flushLock", "->", "lock", "(", ")", ";", "$", "this", "->", "entityManager", "->", "persist", "(", "$", "entity", ")", ";", "return", "$", "this", "->", "flushLock", "->", "unlock", "(", ")", ";", "}", "$", "this", "->", "entityManager", "->", "persist", "(", "$", "entity", ")", ";", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/DoctrineMapper.php#L59-L76
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/DoctrineMapper.php
DoctrineMapper.remove
public function remove($entity) { $this->checkIsEntity($entity); if (null !== $this->flushLock) { $this->flushLock->lock(); $this->entityManager->remove($entity); return $this->flushLock->unlock(); } $this->entityManager->remove($entity); $this->entityManager->flush(); return true; }
php
public function remove($entity) { $this->checkIsEntity($entity); if (null !== $this->flushLock) { $this->flushLock->lock(); $this->entityManager->remove($entity); return $this->flushLock->unlock(); } $this->entityManager->remove($entity); $this->entityManager->flush(); return true; }
[ "public", "function", "remove", "(", "$", "entity", ")", "{", "$", "this", "->", "checkIsEntity", "(", "$", "entity", ")", ";", "if", "(", "null", "!==", "$", "this", "->", "flushLock", ")", "{", "$", "this", "->", "flushLock", "->", "lock", "(", ")", ";", "$", "this", "->", "entityManager", "->", "remove", "(", "$", "entity", ")", ";", "return", "$", "this", "->", "flushLock", "->", "unlock", "(", ")", ";", "}", "$", "this", "->", "entityManager", "->", "remove", "(", "$", "entity", ")", ";", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/DoctrineMapper.php#L105-L122
kaiohken1982/Neobazaar
src/Neobazaar/Entity/Repository/UserRepository.php
UserRepository.get
public function get($user, ServiceManager $sm) { if(!$user instanceof UserEntity) { if(is_numeric($user)) { $user = $this->find($user); } else { if(self::CURRENT_KEYWORD == $user) { // @todo Not a wok of the repo, do it in another place! $zfcUserAuth = $sm->get('ControllerPluginManager')->get('zfcUserAuthentication'); $user = $zfcUserAuth->hasIdentity() ? $zfcUserAuth->getIdentity() : null; //$user = null; } else { $user = $this->findByEncryptedId($user, 'userId'); } } } if(!$user instanceof UserEntity) { return null; } $userModel = $sm->get('user.model.user'); $userModel->init($user, $sm); return $userModel; }
php
public function get($user, ServiceManager $sm) { if(!$user instanceof UserEntity) { if(is_numeric($user)) { $user = $this->find($user); } else { if(self::CURRENT_KEYWORD == $user) { // @todo Not a wok of the repo, do it in another place! $zfcUserAuth = $sm->get('ControllerPluginManager')->get('zfcUserAuthentication'); $user = $zfcUserAuth->hasIdentity() ? $zfcUserAuth->getIdentity() : null; //$user = null; } else { $user = $this->findByEncryptedId($user, 'userId'); } } } if(!$user instanceof UserEntity) { return null; } $userModel = $sm->get('user.model.user'); $userModel->init($user, $sm); return $userModel; }
[ "public", "function", "get", "(", "$", "user", ",", "ServiceManager", "$", "sm", ")", "{", "if", "(", "!", "$", "user", "instanceof", "UserEntity", ")", "{", "if", "(", "is_numeric", "(", "$", "user", ")", ")", "{", "$", "user", "=", "$", "this", "->", "find", "(", "$", "user", ")", ";", "}", "else", "{", "if", "(", "self", "::", "CURRENT_KEYWORD", "==", "$", "user", ")", "{", "// @todo Not a wok of the repo, do it in another place!", "$", "zfcUserAuth", "=", "$", "sm", "->", "get", "(", "'ControllerPluginManager'", ")", "->", "get", "(", "'zfcUserAuthentication'", ")", ";", "$", "user", "=", "$", "zfcUserAuth", "->", "hasIdentity", "(", ")", "?", "$", "zfcUserAuth", "->", "getIdentity", "(", ")", ":", "null", ";", "//$user = null;", "}", "else", "{", "$", "user", "=", "$", "this", "->", "findByEncryptedId", "(", "$", "user", ",", "'userId'", ")", ";", "}", "}", "}", "if", "(", "!", "$", "user", "instanceof", "UserEntity", ")", "{", "return", "null", ";", "}", "$", "userModel", "=", "$", "sm", "->", "get", "(", "'user.model.user'", ")", ";", "$", "userModel", "->", "init", "(", "$", "user", ",", "$", "sm", ")", ";", "return", "$", "userModel", ";", "}" ]
Return a normalized representation of a document @param int|\Neobazaar\Entity\Document $id @return \stdClass
[ "Return", "a", "normalized", "representation", "of", "a", "document" ]
train
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Entity/Repository/UserRepository.php#L32-L57
kaiohken1982/Neobazaar
src/Neobazaar/Entity/Repository/UserRepository.php
UserRepository.getList
public function getList($params = array(), ServiceManager $sm) { $page = isset($params['page']) ? (int)$params['page'] : 1; unset($params['page']); $params['limit'] = isset($params['limit']) ? (int) $params['limit'] : 30; // The eventual presence of 'offset' key has priority over calculated 'page' value $params['offset'] = isset($params['offset']) ? (int) $params['offset'] : ($page * $params['limit'] - $params['limit']); $routeName = 'UserUser/page'; $routeParams = array('page' => $page); $paginator = $this->getPaginator($params); $data = array(); foreach($paginator as $user) { $data[] = $this->get($user, $sm); } unset($params['limit']); unset($params['offset']); $queryParams = $params; $mainService = $sm->get('neobazaar.service.main'); return array( 'data' => $data, 'paginationData' => Json::decode($mainService->getView()->paginationControl( $paginator, 'Sliding', array('pagination/paginatorjson', 'Document'), array( 'route' => $routeName, 'params' => $routeParams, 'query' => $queryParams ) )) ); }
php
public function getList($params = array(), ServiceManager $sm) { $page = isset($params['page']) ? (int)$params['page'] : 1; unset($params['page']); $params['limit'] = isset($params['limit']) ? (int) $params['limit'] : 30; // The eventual presence of 'offset' key has priority over calculated 'page' value $params['offset'] = isset($params['offset']) ? (int) $params['offset'] : ($page * $params['limit'] - $params['limit']); $routeName = 'UserUser/page'; $routeParams = array('page' => $page); $paginator = $this->getPaginator($params); $data = array(); foreach($paginator as $user) { $data[] = $this->get($user, $sm); } unset($params['limit']); unset($params['offset']); $queryParams = $params; $mainService = $sm->get('neobazaar.service.main'); return array( 'data' => $data, 'paginationData' => Json::decode($mainService->getView()->paginationControl( $paginator, 'Sliding', array('pagination/paginatorjson', 'Document'), array( 'route' => $routeName, 'params' => $routeParams, 'query' => $queryParams ) )) ); }
[ "public", "function", "getList", "(", "$", "params", "=", "array", "(", ")", ",", "ServiceManager", "$", "sm", ")", "{", "$", "page", "=", "isset", "(", "$", "params", "[", "'page'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'page'", "]", ":", "1", ";", "unset", "(", "$", "params", "[", "'page'", "]", ")", ";", "$", "params", "[", "'limit'", "]", "=", "isset", "(", "$", "params", "[", "'limit'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'limit'", "]", ":", "30", ";", "// The eventual presence of 'offset' key has priority over calculated 'page' value", "$", "params", "[", "'offset'", "]", "=", "isset", "(", "$", "params", "[", "'offset'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'offset'", "]", ":", "(", "$", "page", "*", "$", "params", "[", "'limit'", "]", "-", "$", "params", "[", "'limit'", "]", ")", ";", "$", "routeName", "=", "'UserUser/page'", ";", "$", "routeParams", "=", "array", "(", "'page'", "=>", "$", "page", ")", ";", "$", "paginator", "=", "$", "this", "->", "getPaginator", "(", "$", "params", ")", ";", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "paginator", "as", "$", "user", ")", "{", "$", "data", "[", "]", "=", "$", "this", "->", "get", "(", "$", "user", ",", "$", "sm", ")", ";", "}", "unset", "(", "$", "params", "[", "'limit'", "]", ")", ";", "unset", "(", "$", "params", "[", "'offset'", "]", ")", ";", "$", "queryParams", "=", "$", "params", ";", "$", "mainService", "=", "$", "sm", "->", "get", "(", "'neobazaar.service.main'", ")", ";", "return", "array", "(", "'data'", "=>", "$", "data", ",", "'paginationData'", "=>", "Json", "::", "decode", "(", "$", "mainService", "->", "getView", "(", ")", "->", "paginationControl", "(", "$", "paginator", ",", "'Sliding'", ",", "array", "(", "'pagination/paginatorjson'", ",", "'Document'", ")", ",", "array", "(", "'route'", "=>", "$", "routeName", ",", "'params'", "=>", "$", "routeParams", ",", "'query'", "=>", "$", "queryParams", ")", ")", ")", ")", ";", "}" ]
User list @param unknown $params @param ServiceLocatorAwareInterface $sm @throws \Exception @return array
[ "User", "list" ]
train
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Entity/Repository/UserRepository.php#L67-L104
kaiohken1982/Neobazaar
src/Neobazaar/Entity/Repository/UserRepository.php
UserRepository.getPaginator
public function getPaginator($params = array()) { $page = isset($params['page']) ? (int)$params['page'] : 1; $email = isset($params['email']) ? $params['email'] : null; $limit = isset($params['limit']) ? (int) $params['limit'] : 10; $offset = isset($params['offset']) ? (int) $params['offset'] : 0; $qb = $this->_em->createQueryBuilder(); $qb->select(array('a')); $qb->from($this->getEntityName(), 'a'); $qb->addOrderBy('a.dateInsert', 'DESC'); if(null !== $email) { $qb->andWhere($qb->expr()->eq('a.email', ':paramEmail')); $qb->setParameter('paramEmail', $email); } $query = $qb->getQuery(); $query->setFirstResult($offset); $query->setMaxResults($limit); // $paginator = new DoctrinePaginator($query, $fetchJoinCollection = true); // $result = array(); // foreach($paginator as $p) { // $result[] = $p->getUserId(); // } // $result = $query->getResult(); // $paginatorAdapter = new RazorPaginator( // $result, // count($paginator) // ); $paginatorAdapter = new DoctrinePaginatorAdapter(new DoctrinePaginator($query)); $paginator = new Paginator($paginatorAdapter); $paginator->setCurrentPageNumber($page); $paginator->setDefaultItemCountPerPage($limit); return $paginator; }
php
public function getPaginator($params = array()) { $page = isset($params['page']) ? (int)$params['page'] : 1; $email = isset($params['email']) ? $params['email'] : null; $limit = isset($params['limit']) ? (int) $params['limit'] : 10; $offset = isset($params['offset']) ? (int) $params['offset'] : 0; $qb = $this->_em->createQueryBuilder(); $qb->select(array('a')); $qb->from($this->getEntityName(), 'a'); $qb->addOrderBy('a.dateInsert', 'DESC'); if(null !== $email) { $qb->andWhere($qb->expr()->eq('a.email', ':paramEmail')); $qb->setParameter('paramEmail', $email); } $query = $qb->getQuery(); $query->setFirstResult($offset); $query->setMaxResults($limit); // $paginator = new DoctrinePaginator($query, $fetchJoinCollection = true); // $result = array(); // foreach($paginator as $p) { // $result[] = $p->getUserId(); // } // $result = $query->getResult(); // $paginatorAdapter = new RazorPaginator( // $result, // count($paginator) // ); $paginatorAdapter = new DoctrinePaginatorAdapter(new DoctrinePaginator($query)); $paginator = new Paginator($paginatorAdapter); $paginator->setCurrentPageNumber($page); $paginator->setDefaultItemCountPerPage($limit); return $paginator; }
[ "public", "function", "getPaginator", "(", "$", "params", "=", "array", "(", ")", ")", "{", "$", "page", "=", "isset", "(", "$", "params", "[", "'page'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'page'", "]", ":", "1", ";", "$", "email", "=", "isset", "(", "$", "params", "[", "'email'", "]", ")", "?", "$", "params", "[", "'email'", "]", ":", "null", ";", "$", "limit", "=", "isset", "(", "$", "params", "[", "'limit'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'limit'", "]", ":", "10", ";", "$", "offset", "=", "isset", "(", "$", "params", "[", "'offset'", "]", ")", "?", "(", "int", ")", "$", "params", "[", "'offset'", "]", ":", "0", ";", "$", "qb", "=", "$", "this", "->", "_em", "->", "createQueryBuilder", "(", ")", ";", "$", "qb", "->", "select", "(", "array", "(", "'a'", ")", ")", ";", "$", "qb", "->", "from", "(", "$", "this", "->", "getEntityName", "(", ")", ",", "'a'", ")", ";", "$", "qb", "->", "addOrderBy", "(", "'a.dateInsert'", ",", "'DESC'", ")", ";", "if", "(", "null", "!==", "$", "email", ")", "{", "$", "qb", "->", "andWhere", "(", "$", "qb", "->", "expr", "(", ")", "->", "eq", "(", "'a.email'", ",", "':paramEmail'", ")", ")", ";", "$", "qb", "->", "setParameter", "(", "'paramEmail'", ",", "$", "email", ")", ";", "}", "$", "query", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "$", "query", "->", "setFirstResult", "(", "$", "offset", ")", ";", "$", "query", "->", "setMaxResults", "(", "$", "limit", ")", ";", "// \t\t$paginator = new DoctrinePaginator($query, $fetchJoinCollection = true);", "// \t\t$result = array();", "// \t\tforeach($paginator as $p) {", "// \t\t\t$result[] = $p->getUserId();", "// \t\t}", "// \t\t$result = $query->getResult();", "// \t\t$paginatorAdapter = new RazorPaginator(", "// \t\t\t$result,", "// \t\t\tcount($paginator)", "// \t\t);", "$", "paginatorAdapter", "=", "new", "DoctrinePaginatorAdapter", "(", "new", "DoctrinePaginator", "(", "$", "query", ")", ")", ";", "$", "paginator", "=", "new", "Paginator", "(", "$", "paginatorAdapter", ")", ";", "$", "paginator", "->", "setCurrentPageNumber", "(", "$", "page", ")", ";", "$", "paginator", "->", "setDefaultItemCountPerPage", "(", "$", "limit", ")", ";", "return", "$", "paginator", ";", "}" ]
Return the paginator @param array $params @return \Zend\Paginator\Paginator
[ "Return", "the", "paginator" ]
train
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Entity/Repository/UserRepository.php#L112-L149
bytic/auth
src/Models/Users/Traits/Authentication/AuthenticationUserTrait.php
AuthenticationUserTrait.authenticate
public function authenticate($request = []) { if ($request) { $this->email = clean($request['email']); $this->password = $this->getPasswordHelper()->hash(clean($request['password'])); } else { $this->password = $this->getPasswordHelper()->hash(clean($this->password)); } $query = $this->getManager()->newQuery(); $query->where("email = ?", $this->email); $query->where("password = ?", $this->password); /** @var User $user */ $user = $this->getManager()->findOneByQuery($query); if ($user) { $this->writeData($user->toArray()); $this->doAuthentication(); } return $this->authenticated(); }
php
public function authenticate($request = []) { if ($request) { $this->email = clean($request['email']); $this->password = $this->getPasswordHelper()->hash(clean($request['password'])); } else { $this->password = $this->getPasswordHelper()->hash(clean($this->password)); } $query = $this->getManager()->newQuery(); $query->where("email = ?", $this->email); $query->where("password = ?", $this->password); /** @var User $user */ $user = $this->getManager()->findOneByQuery($query); if ($user) { $this->writeData($user->toArray()); $this->doAuthentication(); } return $this->authenticated(); }
[ "public", "function", "authenticate", "(", "$", "request", "=", "[", "]", ")", "{", "if", "(", "$", "request", ")", "{", "$", "this", "->", "email", "=", "clean", "(", "$", "request", "[", "'email'", "]", ")", ";", "$", "this", "->", "password", "=", "$", "this", "->", "getPasswordHelper", "(", ")", "->", "hash", "(", "clean", "(", "$", "request", "[", "'password'", "]", ")", ")", ";", "}", "else", "{", "$", "this", "->", "password", "=", "$", "this", "->", "getPasswordHelper", "(", ")", "->", "hash", "(", "clean", "(", "$", "this", "->", "password", ")", ")", ";", "}", "$", "query", "=", "$", "this", "->", "getManager", "(", ")", "->", "newQuery", "(", ")", ";", "$", "query", "->", "where", "(", "\"email = ?\"", ",", "$", "this", "->", "email", ")", ";", "$", "query", "->", "where", "(", "\"password = ?\"", ",", "$", "this", "->", "password", ")", ";", "/** @var User $user */", "$", "user", "=", "$", "this", "->", "getManager", "(", ")", "->", "findOneByQuery", "(", "$", "query", ")", ";", "if", "(", "$", "user", ")", "{", "$", "this", "->", "writeData", "(", "$", "user", "->", "toArray", "(", ")", ")", ";", "$", "this", "->", "doAuthentication", "(", ")", ";", "}", "return", "$", "this", "->", "authenticated", "(", ")", ";", "}" ]
Authenticate user from request @param array $request @return bool|null
[ "Authenticate", "user", "from", "request" ]
train
https://github.com/bytic/auth/blob/c155687840e9cd160e0c55a94f24a3608f72604c/src/Models/Users/Traits/Authentication/AuthenticationUserTrait.php#L36-L59
asen477/gaussian_blur
src/ImagesGaussianBlur.php
ImagesGaussianBlur.gaussian_blur
public function gaussian_blur($srcImg,$savepath=null,$savename=null,$blurFactor=3){ $is_img_files = @file_exists($srcImg); if(empty($is_img_files)) return '图片不存在'; //保存失败 $gdImageResource=$this->image_create_from_ext($srcImg); $srcImgObj=$this->blur($gdImageResource,$blurFactor); $temp = pathinfo($srcImg); $name = $temp['basename']; $path = $temp['dirname']; $exte = $temp['extension']; $savename = $savename ? $savename : $name; $savepath = $savepath ? $savepath : $path; $savefile = $savepath .'/'. $savename; $srcinfo = @getimagesize($srcImg); switch ($srcinfo[2]) { case 1: imagegif($srcImgObj, $savefile); break; case 2: imagejpeg($srcImgObj, $savefile); break; case 3: imagepng($srcImgObj, $savefile); break; default: return '保存失败'; //保存失败 } return $savefile; imagedestroy($srcImgObj); }
php
public function gaussian_blur($srcImg,$savepath=null,$savename=null,$blurFactor=3){ $is_img_files = @file_exists($srcImg); if(empty($is_img_files)) return '图片不存在'; //保存失败 $gdImageResource=$this->image_create_from_ext($srcImg); $srcImgObj=$this->blur($gdImageResource,$blurFactor); $temp = pathinfo($srcImg); $name = $temp['basename']; $path = $temp['dirname']; $exte = $temp['extension']; $savename = $savename ? $savename : $name; $savepath = $savepath ? $savepath : $path; $savefile = $savepath .'/'. $savename; $srcinfo = @getimagesize($srcImg); switch ($srcinfo[2]) { case 1: imagegif($srcImgObj, $savefile); break; case 2: imagejpeg($srcImgObj, $savefile); break; case 3: imagepng($srcImgObj, $savefile); break; default: return '保存失败'; //保存失败 } return $savefile; imagedestroy($srcImgObj); }
[ "public", "function", "gaussian_blur", "(", "$", "srcImg", ",", "$", "savepath", "=", "null", ",", "$", "savename", "=", "null", ",", "$", "blurFactor", "=", "3", ")", "{", "$", "is_img_files", "=", "@", "file_exists", "(", "$", "srcImg", ")", ";", "if", "(", "empty", "(", "$", "is_img_files", ")", ")", "return", "'图片不存在'; //保存失败", "", "", "$", "gdImageResource", "=", "$", "this", "->", "image_create_from_ext", "(", "$", "srcImg", ")", ";", "$", "srcImgObj", "=", "$", "this", "->", "blur", "(", "$", "gdImageResource", ",", "$", "blurFactor", ")", ";", "$", "temp", "=", "pathinfo", "(", "$", "srcImg", ")", ";", "$", "name", "=", "$", "temp", "[", "'basename'", "]", ";", "$", "path", "=", "$", "temp", "[", "'dirname'", "]", ";", "$", "exte", "=", "$", "temp", "[", "'extension'", "]", ";", "$", "savename", "=", "$", "savename", "?", "$", "savename", ":", "$", "name", ";", "$", "savepath", "=", "$", "savepath", "?", "$", "savepath", ":", "$", "path", ";", "$", "savefile", "=", "$", "savepath", ".", "'/'", ".", "$", "savename", ";", "$", "srcinfo", "=", "@", "getimagesize", "(", "$", "srcImg", ")", ";", "switch", "(", "$", "srcinfo", "[", "2", "]", ")", "{", "case", "1", ":", "imagegif", "(", "$", "srcImgObj", ",", "$", "savefile", ")", ";", "break", ";", "case", "2", ":", "imagejpeg", "(", "$", "srcImgObj", ",", "$", "savefile", ")", ";", "break", ";", "case", "3", ":", "imagepng", "(", "$", "srcImgObj", ",", "$", "savefile", ")", ";", "break", ";", "default", ":", "return", "'保存失败'; //保存失败", "", "", "}", "return", "$", "savefile", ";", "imagedestroy", "(", "$", "srcImgObj", ")", ";", "}" ]
图片高斯模糊(适用于png/jpg/gif格式) @param $srcImg 原图片 @param $savepath 保存路径 @param $savename 保存名字 @param $positon 模糊程度 基于Martijn Frazer代码的扩充, 感谢 Martijn Frazer
[ "图片高斯模糊(适用于png", "/", "jpg", "/", "gif格式)", "@param", "$srcImg", "原图片", "@param", "$savepath", "保存路径", "@param", "$savename", "保存名字", "@param", "$positon", "模糊程度" ]
train
https://github.com/asen477/gaussian_blur/blob/1d4ef3e317041b159ab288d17dddd3b6154043a5/src/ImagesGaussianBlur.php#L20-L43
asen477/gaussian_blur
src/ImagesGaussianBlur.php
ImagesGaussianBlur.blur
private function blur($gdImageResource, $blurFactor = 3) { // blurFactor has to be an integer $blurFactor = round($blurFactor); $originalWidth = imagesx($gdImageResource); $originalHeight = imagesy($gdImageResource); $smallestWidth = ceil($originalWidth * pow(0.5, $blurFactor)); $smallestHeight = ceil($originalHeight * pow(0.5, $blurFactor)); // for the first run, the previous image is the original input $prevImage = $gdImageResource; $prevWidth = $originalWidth; $prevHeight = $originalHeight; // scale way down and gradually scale back up, blurring all the way for($i = 0; $i < $blurFactor; $i += 1) { // determine dimensions of next image $nextWidth = $smallestWidth * pow(2, $i); $nextHeight = $smallestHeight * pow(2, $i); // resize previous image to next size $nextImage = imagecreatetruecolor($nextWidth, $nextHeight); imagecopyresized($nextImage, $prevImage, 0, 0, 0, 0, $nextWidth, $nextHeight, $prevWidth, $prevHeight); // apply blur filter imagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR); // now the new image becomes the previous image for the next step $prevImage = $nextImage; $prevWidth = $nextWidth; $prevHeight = $nextHeight; } // scale back to original size and blur one more time imagecopyresized($gdImageResource, $nextImage, 0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight); imagefilter($gdImageResource, IMG_FILTER_GAUSSIAN_BLUR); // clean up imagedestroy($prevImage); // return result return $gdImageResource; }
php
private function blur($gdImageResource, $blurFactor = 3) { // blurFactor has to be an integer $blurFactor = round($blurFactor); $originalWidth = imagesx($gdImageResource); $originalHeight = imagesy($gdImageResource); $smallestWidth = ceil($originalWidth * pow(0.5, $blurFactor)); $smallestHeight = ceil($originalHeight * pow(0.5, $blurFactor)); // for the first run, the previous image is the original input $prevImage = $gdImageResource; $prevWidth = $originalWidth; $prevHeight = $originalHeight; // scale way down and gradually scale back up, blurring all the way for($i = 0; $i < $blurFactor; $i += 1) { // determine dimensions of next image $nextWidth = $smallestWidth * pow(2, $i); $nextHeight = $smallestHeight * pow(2, $i); // resize previous image to next size $nextImage = imagecreatetruecolor($nextWidth, $nextHeight); imagecopyresized($nextImage, $prevImage, 0, 0, 0, 0, $nextWidth, $nextHeight, $prevWidth, $prevHeight); // apply blur filter imagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR); // now the new image becomes the previous image for the next step $prevImage = $nextImage; $prevWidth = $nextWidth; $prevHeight = $nextHeight; } // scale back to original size and blur one more time imagecopyresized($gdImageResource, $nextImage, 0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight); imagefilter($gdImageResource, IMG_FILTER_GAUSSIAN_BLUR); // clean up imagedestroy($prevImage); // return result return $gdImageResource; }
[ "private", "function", "blur", "(", "$", "gdImageResource", ",", "$", "blurFactor", "=", "3", ")", "{", "// blurFactor has to be an integer ", "$", "blurFactor", "=", "round", "(", "$", "blurFactor", ")", ";", "$", "originalWidth", "=", "imagesx", "(", "$", "gdImageResource", ")", ";", "$", "originalHeight", "=", "imagesy", "(", "$", "gdImageResource", ")", ";", "$", "smallestWidth", "=", "ceil", "(", "$", "originalWidth", "*", "pow", "(", "0.5", ",", "$", "blurFactor", ")", ")", ";", "$", "smallestHeight", "=", "ceil", "(", "$", "originalHeight", "*", "pow", "(", "0.5", ",", "$", "blurFactor", ")", ")", ";", "// for the first run, the previous image is the original input ", "$", "prevImage", "=", "$", "gdImageResource", ";", "$", "prevWidth", "=", "$", "originalWidth", ";", "$", "prevHeight", "=", "$", "originalHeight", ";", "// scale way down and gradually scale back up, blurring all the way ", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "blurFactor", ";", "$", "i", "+=", "1", ")", "{", "// determine dimensions of next image ", "$", "nextWidth", "=", "$", "smallestWidth", "*", "pow", "(", "2", ",", "$", "i", ")", ";", "$", "nextHeight", "=", "$", "smallestHeight", "*", "pow", "(", "2", ",", "$", "i", ")", ";", "// resize previous image to next size ", "$", "nextImage", "=", "imagecreatetruecolor", "(", "$", "nextWidth", ",", "$", "nextHeight", ")", ";", "imagecopyresized", "(", "$", "nextImage", ",", "$", "prevImage", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "nextWidth", ",", "$", "nextHeight", ",", "$", "prevWidth", ",", "$", "prevHeight", ")", ";", "// apply blur filter ", "imagefilter", "(", "$", "nextImage", ",", "IMG_FILTER_GAUSSIAN_BLUR", ")", ";", "// now the new image becomes the previous image for the next step ", "$", "prevImage", "=", "$", "nextImage", ";", "$", "prevWidth", "=", "$", "nextWidth", ";", "$", "prevHeight", "=", "$", "nextHeight", ";", "}", "// scale back to original size and blur one more time ", "imagecopyresized", "(", "$", "gdImageResource", ",", "$", "nextImage", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "originalWidth", ",", "$", "originalHeight", ",", "$", "nextWidth", ",", "$", "nextHeight", ")", ";", "imagefilter", "(", "$", "gdImageResource", ",", "IMG_FILTER_GAUSSIAN_BLUR", ")", ";", "// clean up ", "imagedestroy", "(", "$", "prevImage", ")", ";", "// return result ", "return", "$", "gdImageResource", ";", "}" ]
Strong Blur @param $gdImageResource 图片资源 @param $blurFactor 可选择的模糊程度 可选择的模糊程度 0使用 3默认 超过5时 极其模糊 @return GD image 图片资源类型 @author Martijn Frazer, idea based on http://stackoverflow.com/a/20264482
[ "Strong", "Blur" ]
train
https://github.com/asen477/gaussian_blur/blob/1d4ef3e317041b159ab288d17dddd3b6154043a5/src/ImagesGaussianBlur.php#L54-L101
OxfordInfoLabs/kinikit-core
src/Util/Multithreading/Thread.php
Thread.run
public function run($parameters = array()) { // Grab a process ID for a new forked process $this->pid = \pcntl_fork(); if (!$this->pid) { $this->process($parameters); posix_kill(getmypid(), 9); } return $this->pid; }
php
public function run($parameters = array()) { // Grab a process ID for a new forked process $this->pid = \pcntl_fork(); if (!$this->pid) { $this->process($parameters); posix_kill(getmypid(), 9); } return $this->pid; }
[ "public", "function", "run", "(", "$", "parameters", "=", "array", "(", ")", ")", "{", "// Grab a process ID for a new forked process", "$", "this", "->", "pid", "=", "\\", "pcntl_fork", "(", ")", ";", "if", "(", "!", "$", "this", "->", "pid", ")", "{", "$", "this", "->", "process", "(", "$", "parameters", ")", ";", "posix_kill", "(", "getmypid", "(", ")", ",", "9", ")", ";", "}", "return", "$", "this", "->", "pid", ";", "}" ]
Main run method called to start the thread.
[ "Main", "run", "method", "called", "to", "start", "the", "thread", "." ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Multithreading/Thread.php#L22-L33
OxfordInfoLabs/kinikit-core
src/Util/Multithreading/Thread.php
Thread.wait
public function wait() { if ($this->pid) { \pcntl_waitpid($this->pid, $status, WUNTRACED); return $status; } else { return false; } }
php
public function wait() { if ($this->pid) { \pcntl_waitpid($this->pid, $status, WUNTRACED); return $status; } else { return false; } }
[ "public", "function", "wait", "(", ")", "{", "if", "(", "$", "this", "->", "pid", ")", "{", "\\", "pcntl_waitpid", "(", "$", "this", "->", "pid", ",", "$", "status", ",", "WUNTRACED", ")", ";", "return", "$", "status", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Blocking method called by another thread which waits until this thread has completed.
[ "Blocking", "method", "called", "by", "another", "thread", "which", "waits", "until", "this", "thread", "has", "completed", "." ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Multithreading/Thread.php#L40-L47
OxfordInfoLabs/kinikit-core
src/Util/Multithreading/Thread.php
Thread.getStatus
public function getStatus() { if ($this->pid) { $waitPID = \pcntl_waitpid($this->pid, $status, WNOHANG); if ($waitPID == $this->pid) { return Thread::THREAD_EXITED; } else { return Thread::THREAD_RUNNING; } } }
php
public function getStatus() { if ($this->pid) { $waitPID = \pcntl_waitpid($this->pid, $status, WNOHANG); if ($waitPID == $this->pid) { return Thread::THREAD_EXITED; } else { return Thread::THREAD_RUNNING; } } }
[ "public", "function", "getStatus", "(", ")", "{", "if", "(", "$", "this", "->", "pid", ")", "{", "$", "waitPID", "=", "\\", "pcntl_waitpid", "(", "$", "this", "->", "pid", ",", "$", "status", ",", "WNOHANG", ")", ";", "if", "(", "$", "waitPID", "==", "$", "this", "->", "pid", ")", "{", "return", "Thread", "::", "THREAD_EXITED", ";", "}", "else", "{", "return", "Thread", "::", "THREAD_RUNNING", ";", "}", "}", "}" ]
Get the current status for this thread.
[ "Get", "the", "current", "status", "for", "this", "thread", "." ]
train
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Multithreading/Thread.php#L53-L63
miBadger/miBadger.Settings
src/Settings.php
Settings.load
public function load($path = self::DEFAULT_FILENAME) { $file = new File($path); if (($data = json_decode($file->read(), true)) === null) { throw new \UnexpectedValueException('Invalid JSON.'); } $this->data = (array) $data; return $this; }
php
public function load($path = self::DEFAULT_FILENAME) { $file = new File($path); if (($data = json_decode($file->read(), true)) === null) { throw new \UnexpectedValueException('Invalid JSON.'); } $this->data = (array) $data; return $this; }
[ "public", "function", "load", "(", "$", "path", "=", "self", "::", "DEFAULT_FILENAME", ")", "{", "$", "file", "=", "new", "File", "(", "$", "path", ")", ";", "if", "(", "(", "$", "data", "=", "json_decode", "(", "$", "file", "->", "read", "(", ")", ",", "true", ")", ")", "===", "null", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Invalid JSON.'", ")", ";", "}", "$", "this", "->", "data", "=", "(", "array", ")", "$", "data", ";", "return", "$", "this", ";", "}" ]
Load the settings file from the given location. @param $path = self::DEFAULT_FILENAME @return $this @throws FileException on failure. @throws \UnexpectedValueException on failure.
[ "Load", "the", "settings", "file", "from", "the", "given", "location", "." ]
train
https://github.com/miBadger/miBadger.Settings/blob/dc2be14d96e2db84acb9fba543099380b1f14bd8/src/Settings.php#L144-L155
miBadger/miBadger.Settings
src/Settings.php
Settings.save
public function save($path = self::DEFAULT_FILENAME) { $file = new File($path); $file->write(json_encode($this->data)); return $this; }
php
public function save($path = self::DEFAULT_FILENAME) { $file = new File($path); $file->write(json_encode($this->data)); return $this; }
[ "public", "function", "save", "(", "$", "path", "=", "self", "::", "DEFAULT_FILENAME", ")", "{", "$", "file", "=", "new", "File", "(", "$", "path", ")", ";", "$", "file", "->", "write", "(", "json_encode", "(", "$", "this", "->", "data", ")", ")", ";", "return", "$", "this", ";", "}" ]
Save the settings file at the given location. @param $path = self::DEFAULT_FILENAME @return $this @throws FileException on failure.
[ "Save", "the", "settings", "file", "at", "the", "given", "location", "." ]
train
https://github.com/miBadger/miBadger.Settings/blob/dc2be14d96e2db84acb9fba543099380b1f14bd8/src/Settings.php#L164-L171
WellCommerce/PaymentBundle
DataFixtures/ORM/LoadPaymentMethodData.php
LoadPaymentMethodData.load
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } $faker = $this->getFakerGenerator(); $shippingMethods = new ArrayCollection(); $shippingMethods->add($this->getReference('shipping_method_fedex')); $shippingMethods->add($this->getReference('shipping_method_ups')); $cod = new PaymentMethod(); $cod->setEnabled(1); $cod->setHierarchy(10); $cod->setProcessor('cash_on_delivery'); foreach($this->getLocales() as $locale){ $cod->translate($locale->getCode())->setName('Cash on delivery'); } $cod->setShippingMethods($shippingMethods); $cod->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $cod->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $cod->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $cod->setConfiguration([]); $cod->mergeNewTranslations(); $manager->persist($cod); $bankTransfer = new PaymentMethod(); $bankTransfer->setEnabled(1); $bankTransfer->setHierarchy(20); $bankTransfer->setProcessor('bank_transfer'); foreach($this->getLocales() as $locale){ $bankTransfer->translate($locale->getCode())->setName('Bank transfer'); } $bankTransfer->setShippingMethods($shippingMethods); $bankTransfer->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $bankTransfer->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $bankTransfer->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $bankTransfer->setConfiguration([ 'bank_transfer_account_number' => '1111 2222 3333 4444 5555 6666', 'bank_transfer_account_owner' => 'WellCommerce', 'bank_transfer_sort_number' => 'SORTCODE', ]); $bankTransfer->mergeNewTranslations(); $manager->persist($bankTransfer); $payPal = new PaymentMethod(); $payPal->setEnabled(1); $payPal->setHierarchy(30); $payPal->setProcessor('paypal'); foreach($this->getLocales() as $locale){ $payPal->translate($locale->getCode())->setName('PayPal'); } $payPal->setShippingMethods($shippingMethods); $payPal->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $payPal->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $payPal->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $payPal->setConfiguration([ 'paypal_client_id' => 'AQSJsBNhgVhtOd5t_KUp4hWEAUPRj6Xd3IRu3g_t08D0ZqFIRVrzhnJ0w9ktQMBeOFHfj-yWx78XsKiW', 'paypal_client_secret' => 'EFe3yJq23ebDCUDZtT3vD6GOg5JcDMbNgzDzuRZVsEPbBSfkYwFxYeK-qWJHSRasy4hL3h7Ucv9v3ghM', 'paypal_mode' => 'sandbox', ]); $payPal->mergeNewTranslations(); $manager->persist($payPal); $manager->flush(); $this->setReference('payment_method_cod', $cod); $this->setReference('payment_method_bank_transfer', $bankTransfer); }
php
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } $faker = $this->getFakerGenerator(); $shippingMethods = new ArrayCollection(); $shippingMethods->add($this->getReference('shipping_method_fedex')); $shippingMethods->add($this->getReference('shipping_method_ups')); $cod = new PaymentMethod(); $cod->setEnabled(1); $cod->setHierarchy(10); $cod->setProcessor('cash_on_delivery'); foreach($this->getLocales() as $locale){ $cod->translate($locale->getCode())->setName('Cash on delivery'); } $cod->setShippingMethods($shippingMethods); $cod->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $cod->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $cod->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $cod->setConfiguration([]); $cod->mergeNewTranslations(); $manager->persist($cod); $bankTransfer = new PaymentMethod(); $bankTransfer->setEnabled(1); $bankTransfer->setHierarchy(20); $bankTransfer->setProcessor('bank_transfer'); foreach($this->getLocales() as $locale){ $bankTransfer->translate($locale->getCode())->setName('Bank transfer'); } $bankTransfer->setShippingMethods($shippingMethods); $bankTransfer->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $bankTransfer->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $bankTransfer->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $bankTransfer->setConfiguration([ 'bank_transfer_account_number' => '1111 2222 3333 4444 5555 6666', 'bank_transfer_account_owner' => 'WellCommerce', 'bank_transfer_sort_number' => 'SORTCODE', ]); $bankTransfer->mergeNewTranslations(); $manager->persist($bankTransfer); $payPal = new PaymentMethod(); $payPal->setEnabled(1); $payPal->setHierarchy(30); $payPal->setProcessor('paypal'); foreach($this->getLocales() as $locale){ $payPal->translate($locale->getCode())->setName('PayPal'); } $payPal->setShippingMethods($shippingMethods); $payPal->setPaymentPendingOrderStatus($this->getReference('order_status_pending_payment')); $payPal->setPaymentFailureOrderStatus($this->getReference('order_status_payment_failed')); $payPal->setPaymentSuccessOrderStatus($this->getReference('order_status_paid')); $payPal->setConfiguration([ 'paypal_client_id' => 'AQSJsBNhgVhtOd5t_KUp4hWEAUPRj6Xd3IRu3g_t08D0ZqFIRVrzhnJ0w9ktQMBeOFHfj-yWx78XsKiW', 'paypal_client_secret' => 'EFe3yJq23ebDCUDZtT3vD6GOg5JcDMbNgzDzuRZVsEPbBSfkYwFxYeK-qWJHSRasy4hL3h7Ucv9v3ghM', 'paypal_mode' => 'sandbox', ]); $payPal->mergeNewTranslations(); $manager->persist($payPal); $manager->flush(); $this->setReference('payment_method_cod', $cod); $this->setReference('payment_method_bank_transfer', $bankTransfer); }
[ "public", "function", "load", "(", "ObjectManager", "$", "manager", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "$", "faker", "=", "$", "this", "->", "getFakerGenerator", "(", ")", ";", "$", "shippingMethods", "=", "new", "ArrayCollection", "(", ")", ";", "$", "shippingMethods", "->", "add", "(", "$", "this", "->", "getReference", "(", "'shipping_method_fedex'", ")", ")", ";", "$", "shippingMethods", "->", "add", "(", "$", "this", "->", "getReference", "(", "'shipping_method_ups'", ")", ")", ";", "$", "cod", "=", "new", "PaymentMethod", "(", ")", ";", "$", "cod", "->", "setEnabled", "(", "1", ")", ";", "$", "cod", "->", "setHierarchy", "(", "10", ")", ";", "$", "cod", "->", "setProcessor", "(", "'cash_on_delivery'", ")", ";", "foreach", "(", "$", "this", "->", "getLocales", "(", ")", "as", "$", "locale", ")", "{", "$", "cod", "->", "translate", "(", "$", "locale", "->", "getCode", "(", ")", ")", "->", "setName", "(", "'Cash on delivery'", ")", ";", "}", "$", "cod", "->", "setShippingMethods", "(", "$", "shippingMethods", ")", ";", "$", "cod", "->", "setPaymentPendingOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_pending_payment'", ")", ")", ";", "$", "cod", "->", "setPaymentFailureOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_payment_failed'", ")", ")", ";", "$", "cod", "->", "setPaymentSuccessOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_paid'", ")", ")", ";", "$", "cod", "->", "setConfiguration", "(", "[", "]", ")", ";", "$", "cod", "->", "mergeNewTranslations", "(", ")", ";", "$", "manager", "->", "persist", "(", "$", "cod", ")", ";", "$", "bankTransfer", "=", "new", "PaymentMethod", "(", ")", ";", "$", "bankTransfer", "->", "setEnabled", "(", "1", ")", ";", "$", "bankTransfer", "->", "setHierarchy", "(", "20", ")", ";", "$", "bankTransfer", "->", "setProcessor", "(", "'bank_transfer'", ")", ";", "foreach", "(", "$", "this", "->", "getLocales", "(", ")", "as", "$", "locale", ")", "{", "$", "bankTransfer", "->", "translate", "(", "$", "locale", "->", "getCode", "(", ")", ")", "->", "setName", "(", "'Bank transfer'", ")", ";", "}", "$", "bankTransfer", "->", "setShippingMethods", "(", "$", "shippingMethods", ")", ";", "$", "bankTransfer", "->", "setPaymentPendingOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_pending_payment'", ")", ")", ";", "$", "bankTransfer", "->", "setPaymentFailureOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_payment_failed'", ")", ")", ";", "$", "bankTransfer", "->", "setPaymentSuccessOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_paid'", ")", ")", ";", "$", "bankTransfer", "->", "setConfiguration", "(", "[", "'bank_transfer_account_number'", "=>", "'1111 2222 3333 4444 5555 6666'", ",", "'bank_transfer_account_owner'", "=>", "'WellCommerce'", ",", "'bank_transfer_sort_number'", "=>", "'SORTCODE'", ",", "]", ")", ";", "$", "bankTransfer", "->", "mergeNewTranslations", "(", ")", ";", "$", "manager", "->", "persist", "(", "$", "bankTransfer", ")", ";", "$", "payPal", "=", "new", "PaymentMethod", "(", ")", ";", "$", "payPal", "->", "setEnabled", "(", "1", ")", ";", "$", "payPal", "->", "setHierarchy", "(", "30", ")", ";", "$", "payPal", "->", "setProcessor", "(", "'paypal'", ")", ";", "foreach", "(", "$", "this", "->", "getLocales", "(", ")", "as", "$", "locale", ")", "{", "$", "payPal", "->", "translate", "(", "$", "locale", "->", "getCode", "(", ")", ")", "->", "setName", "(", "'PayPal'", ")", ";", "}", "$", "payPal", "->", "setShippingMethods", "(", "$", "shippingMethods", ")", ";", "$", "payPal", "->", "setPaymentPendingOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_pending_payment'", ")", ")", ";", "$", "payPal", "->", "setPaymentFailureOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_payment_failed'", ")", ")", ";", "$", "payPal", "->", "setPaymentSuccessOrderStatus", "(", "$", "this", "->", "getReference", "(", "'order_status_paid'", ")", ")", ";", "$", "payPal", "->", "setConfiguration", "(", "[", "'paypal_client_id'", "=>", "'AQSJsBNhgVhtOd5t_KUp4hWEAUPRj6Xd3IRu3g_t08D0ZqFIRVrzhnJ0w9ktQMBeOFHfj-yWx78XsKiW'", ",", "'paypal_client_secret'", "=>", "'EFe3yJq23ebDCUDZtT3vD6GOg5JcDMbNgzDzuRZVsEPbBSfkYwFxYeK-qWJHSRasy4hL3h7Ucv9v3ghM'", ",", "'paypal_mode'", "=>", "'sandbox'", ",", "]", ")", ";", "$", "payPal", "->", "mergeNewTranslations", "(", ")", ";", "$", "manager", "->", "persist", "(", "$", "payPal", ")", ";", "$", "manager", "->", "flush", "(", ")", ";", "$", "this", "->", "setReference", "(", "'payment_method_cod'", ",", "$", "cod", ")", ";", "$", "this", "->", "setReference", "(", "'payment_method_bank_transfer'", ",", "$", "bankTransfer", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/WellCommerce/PaymentBundle/blob/7fdeb0b5155646f2b638082d2135bec05eb8be98/DataFixtures/ORM/LoadPaymentMethodData.php#L30-L98
PenoaksDev/Milky-Framework
src/Milky/Queue/Console/TableCommand.php
TableCommand.fire
public function fire() { $table = $this->laravel['config']['queue.connections.database.table']; $tableClassName = Str::studly($table); $fullPath = $this->createBaseMigration($table); $stub = str_replace( ['{{table}}', '{{tableClassName}}'], [$table, $tableClassName], $this->files->get(__DIR__.'/stubs/jobs.stub') ); $this->files->put($fullPath, $stub); $this->info('Migration created successfully!'); $this->composer->dumpAutoloads(); }
php
public function fire() { $table = $this->laravel['config']['queue.connections.database.table']; $tableClassName = Str::studly($table); $fullPath = $this->createBaseMigration($table); $stub = str_replace( ['{{table}}', '{{tableClassName}}'], [$table, $tableClassName], $this->files->get(__DIR__.'/stubs/jobs.stub') ); $this->files->put($fullPath, $stub); $this->info('Migration created successfully!'); $this->composer->dumpAutoloads(); }
[ "public", "function", "fire", "(", ")", "{", "$", "table", "=", "$", "this", "->", "laravel", "[", "'config'", "]", "[", "'queue.connections.database.table'", "]", ";", "$", "tableClassName", "=", "Str", "::", "studly", "(", "$", "table", ")", ";", "$", "fullPath", "=", "$", "this", "->", "createBaseMigration", "(", "$", "table", ")", ";", "$", "stub", "=", "str_replace", "(", "[", "'{{table}}'", ",", "'{{tableClassName}}'", "]", ",", "[", "$", "table", ",", "$", "tableClassName", "]", ",", "$", "this", "->", "files", "->", "get", "(", "__DIR__", ".", "'/stubs/jobs.stub'", ")", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "fullPath", ",", "$", "stub", ")", ";", "$", "this", "->", "info", "(", "'Migration created successfully!'", ")", ";", "$", "this", "->", "composer", "->", "dumpAutoloads", "(", ")", ";", "}" ]
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Queue/Console/TableCommand.php#L56-L73
wearenolte/wp-endpoints-routes
src/Routes.php
Routes.endpoint_callback
public function endpoint_callback( \WP_REST_Request $request ) { $data = []; $home_url = home_url(); $page_on_front = get_option( 'page_on_front' ); $blog_page = get_option( 'page_for_posts' ); // Create a route for each page. $pages_query = new \WP_Query([ 'post_type' => 'page', // @codingStandardsIgnoreStart // We need all pages, we really don't want to paginate this query. 'posts_per_page' => -1, // codingStandardsIgnoreEnd ]); while ( $pages_query->have_posts() ) { $pages_query->the_post(); $page = $pages_query->post; if ( $page_on_front && $blog_page && (int) $blog_page === $page->ID ) { continue; } $url = str_replace( $home_url, '', get_permalink( $page ) ); $data[] = [ 'state' => $page->post_name, 'url' => '/' === $url ? $url : rtrim( $url, '/' ), 'template' => get_post_meta( $page->ID, '_wp_page_template', true ), 'endpoint' => $this->get_wp_endpoint_route( 'pages' ), 'params' => [ 'include' => $page->ID, ], ]; } wp_reset_postdata(); return $this->filter_data( array_merge( $data, self::get_blog_routes() ) ); }
php
public function endpoint_callback( \WP_REST_Request $request ) { $data = []; $home_url = home_url(); $page_on_front = get_option( 'page_on_front' ); $blog_page = get_option( 'page_for_posts' ); // Create a route for each page. $pages_query = new \WP_Query([ 'post_type' => 'page', // @codingStandardsIgnoreStart // We need all pages, we really don't want to paginate this query. 'posts_per_page' => -1, // codingStandardsIgnoreEnd ]); while ( $pages_query->have_posts() ) { $pages_query->the_post(); $page = $pages_query->post; if ( $page_on_front && $blog_page && (int) $blog_page === $page->ID ) { continue; } $url = str_replace( $home_url, '', get_permalink( $page ) ); $data[] = [ 'state' => $page->post_name, 'url' => '/' === $url ? $url : rtrim( $url, '/' ), 'template' => get_post_meta( $page->ID, '_wp_page_template', true ), 'endpoint' => $this->get_wp_endpoint_route( 'pages' ), 'params' => [ 'include' => $page->ID, ], ]; } wp_reset_postdata(); return $this->filter_data( array_merge( $data, self::get_blog_routes() ) ); }
[ "public", "function", "endpoint_callback", "(", "\\", "WP_REST_Request", "$", "request", ")", "{", "$", "data", "=", "[", "]", ";", "$", "home_url", "=", "home_url", "(", ")", ";", "$", "page_on_front", "=", "get_option", "(", "'page_on_front'", ")", ";", "$", "blog_page", "=", "get_option", "(", "'page_for_posts'", ")", ";", "// Create a route for each page.", "$", "pages_query", "=", "new", "\\", "WP_Query", "(", "[", "'post_type'", "=>", "'page'", ",", "// @codingStandardsIgnoreStart", "// We need all pages, we really don't want to paginate this query.", "'posts_per_page'", "=>", "-", "1", ",", "// codingStandardsIgnoreEnd", "]", ")", ";", "while", "(", "$", "pages_query", "->", "have_posts", "(", ")", ")", "{", "$", "pages_query", "->", "the_post", "(", ")", ";", "$", "page", "=", "$", "pages_query", "->", "post", ";", "if", "(", "$", "page_on_front", "&&", "$", "blog_page", "&&", "(", "int", ")", "$", "blog_page", "===", "$", "page", "->", "ID", ")", "{", "continue", ";", "}", "$", "url", "=", "str_replace", "(", "$", "home_url", ",", "''", ",", "get_permalink", "(", "$", "page", ")", ")", ";", "$", "data", "[", "]", "=", "[", "'state'", "=>", "$", "page", "->", "post_name", ",", "'url'", "=>", "'/'", "===", "$", "url", "?", "$", "url", ":", "rtrim", "(", "$", "url", ",", "'/'", ")", ",", "'template'", "=>", "get_post_meta", "(", "$", "page", "->", "ID", ",", "'_wp_page_template'", ",", "true", ")", ",", "'endpoint'", "=>", "$", "this", "->", "get_wp_endpoint_route", "(", "'pages'", ")", ",", "'params'", "=>", "[", "'include'", "=>", "$", "page", "->", "ID", ",", "]", ",", "]", ";", "}", "wp_reset_postdata", "(", ")", ";", "return", "$", "this", "->", "filter_data", "(", "array_merge", "(", "$", "data", ",", "self", "::", "get_blog_routes", "(", ")", ")", ")", ";", "}" ]
Get the data. @Override @param \WP_REST_Request $request The request. @return array|\WP_Error
[ "Get", "the", "data", "." ]
train
https://github.com/wearenolte/wp-endpoints-routes/blob/d86e77908f9d7ddc862d1a902cd8d2d7c0449473/src/Routes.php#L41-L84
wearenolte/wp-endpoints-routes
src/Routes.php
Routes.get_blog_routes
private function get_blog_routes() { $data = []; $blog_url = false; $home_url = home_url(); $page_on_front = get_option( 'page_on_front' ); $blog_page = get_option( 'page_for_posts' ); if ( ! $page_on_front ) { $blog_url = '/'; } elseif ( $blog_page ) { $blog_url = rtrim( str_replace( $home_url, '', get_permalink( $blog_page ) ), '/' ); } if ( $blog_url ) { $data[] = [ 'state' => 'blogIndex', 'url' => $blog_url, 'template' => 'blog', 'endpoint' => $this->get_wp_endpoint_route( 'posts' ), 'params' => apply_filters( self::FILTER_BLOG_PARAMS, [] ), ]; } // Create routes for single blog posts if active. $single_post_url = apply_filters( self::FILTER_SINGLE_POST_ROUTE, '/' === $blog_url ? '/blog' : $blog_url ); if ( $single_post_url ) { $data[] = [ 'state' => 'blogPost', 'url' => $single_post_url . '/:slug', 'template' => 'blog-single', 'endpoint' => $this->get_wp_endpoint_route( 'posts' ), ]; } return $data; }
php
private function get_blog_routes() { $data = []; $blog_url = false; $home_url = home_url(); $page_on_front = get_option( 'page_on_front' ); $blog_page = get_option( 'page_for_posts' ); if ( ! $page_on_front ) { $blog_url = '/'; } elseif ( $blog_page ) { $blog_url = rtrim( str_replace( $home_url, '', get_permalink( $blog_page ) ), '/' ); } if ( $blog_url ) { $data[] = [ 'state' => 'blogIndex', 'url' => $blog_url, 'template' => 'blog', 'endpoint' => $this->get_wp_endpoint_route( 'posts' ), 'params' => apply_filters( self::FILTER_BLOG_PARAMS, [] ), ]; } // Create routes for single blog posts if active. $single_post_url = apply_filters( self::FILTER_SINGLE_POST_ROUTE, '/' === $blog_url ? '/blog' : $blog_url ); if ( $single_post_url ) { $data[] = [ 'state' => 'blogPost', 'url' => $single_post_url . '/:slug', 'template' => 'blog-single', 'endpoint' => $this->get_wp_endpoint_route( 'posts' ), ]; } return $data; }
[ "private", "function", "get_blog_routes", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "blog_url", "=", "false", ";", "$", "home_url", "=", "home_url", "(", ")", ";", "$", "page_on_front", "=", "get_option", "(", "'page_on_front'", ")", ";", "$", "blog_page", "=", "get_option", "(", "'page_for_posts'", ")", ";", "if", "(", "!", "$", "page_on_front", ")", "{", "$", "blog_url", "=", "'/'", ";", "}", "elseif", "(", "$", "blog_page", ")", "{", "$", "blog_url", "=", "rtrim", "(", "str_replace", "(", "$", "home_url", ",", "''", ",", "get_permalink", "(", "$", "blog_page", ")", ")", ",", "'/'", ")", ";", "}", "if", "(", "$", "blog_url", ")", "{", "$", "data", "[", "]", "=", "[", "'state'", "=>", "'blogIndex'", ",", "'url'", "=>", "$", "blog_url", ",", "'template'", "=>", "'blog'", ",", "'endpoint'", "=>", "$", "this", "->", "get_wp_endpoint_route", "(", "'posts'", ")", ",", "'params'", "=>", "apply_filters", "(", "self", "::", "FILTER_BLOG_PARAMS", ",", "[", "]", ")", ",", "]", ";", "}", "// Create routes for single blog posts if active.", "$", "single_post_url", "=", "apply_filters", "(", "self", "::", "FILTER_SINGLE_POST_ROUTE", ",", "'/'", "===", "$", "blog_url", "?", "'/blog'", ":", "$", "blog_url", ")", ";", "if", "(", "$", "single_post_url", ")", "{", "$", "data", "[", "]", "=", "[", "'state'", "=>", "'blogPost'", ",", "'url'", "=>", "$", "single_post_url", ".", "'/:slug'", ",", "'template'", "=>", "'blog-single'", ",", "'endpoint'", "=>", "$", "this", "->", "get_wp_endpoint_route", "(", "'posts'", ")", ",", "]", ";", "}", "return", "$", "data", ";", "}" ]
Create routes for the blog page and single posts if active.. @return array
[ "Create", "routes", "for", "the", "blog", "page", "and", "single", "posts", "if", "active", ".." ]
train
https://github.com/wearenolte/wp-endpoints-routes/blob/d86e77908f9d7ddc862d1a902cd8d2d7c0449473/src/Routes.php#L91-L131
phpguard/plugin-behat
src/Session.php
Session.serialize
public function serialize() { $data = array( 'features' => $this->features, 'scenarios' => $this->scenarios, 'steps' => $this->steps, 'results' => $this->results, 'path' => $this->path, 'fs' => $this->fs, ); return serialize($data); }
php
public function serialize() { $data = array( 'features' => $this->features, 'scenarios' => $this->scenarios, 'steps' => $this->steps, 'results' => $this->results, 'path' => $this->path, 'fs' => $this->fs, ); return serialize($data); }
[ "public", "function", "serialize", "(", ")", "{", "$", "data", "=", "array", "(", "'features'", "=>", "$", "this", "->", "features", ",", "'scenarios'", "=>", "$", "this", "->", "scenarios", ",", "'steps'", "=>", "$", "this", "->", "steps", ",", "'results'", "=>", "$", "this", "->", "results", ",", "'path'", "=>", "$", "this", "->", "path", ",", "'fs'", "=>", "$", "this", "->", "fs", ",", ")", ";", "return", "serialize", "(", "$", "data", ")", ";", "}" ]
{inheritdoc}
[ "{", "inheritdoc", "}" ]
train
https://github.com/phpguard/plugin-behat/blob/9fa140c4355935196943d2bd8f84232cde1d7d15/src/Session.php#L84-L96