repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
freyo/flysystem-qcloud-cos-v3
src/Client/Auth.php
Auth.appSign
public static function appSign($expired, $bucketName) { $appId = Conf::getAppId(); $secretId = Conf::getSecretId(); $secretKey = Conf::getSecretKey(); if (empty($secretId) || empty($secretKey) || empty($appId)) { return self::AUTH_SECRET_ID_KEY_ERROR; } return self::appSignBase($appId, $secretId, $secretKey, $expired, null, $bucketName); }
php
public static function appSign($expired, $bucketName) { $appId = Conf::getAppId(); $secretId = Conf::getSecretId(); $secretKey = Conf::getSecretKey(); if (empty($secretId) || empty($secretKey) || empty($appId)) { return self::AUTH_SECRET_ID_KEY_ERROR; } return self::appSignBase($appId, $secretId, $secretKey, $expired, null, $bucketName); }
[ "public", "static", "function", "appSign", "(", "$", "expired", ",", "$", "bucketName", ")", "{", "$", "appId", "=", "Conf", "::", "getAppId", "(", ")", ";", "$", "secretId", "=", "Conf", "::", "getSecretId", "(", ")", ";", "$", "secretKey", "=", "Conf", "::", "getSecretKey", "(", ")", ";", "if", "(", "empty", "(", "$", "secretId", ")", "||", "empty", "(", "$", "secretKey", ")", "||", "empty", "(", "$", "appId", ")", ")", "{", "return", "self", "::", "AUTH_SECRET_ID_KEY_ERROR", ";", "}", "return", "self", "::", "appSignBase", "(", "$", "appId", ",", "$", "secretId", ",", "$", "secretKey", ",", "$", "expired", ",", "null", ",", "$", "bucketName", ")", ";", "}" ]
生成多次有效签名函数(用于上传和下载资源,有效期内可重复对不同资源使用). @param int $expired 过期时间,unix时间戳 @param string $bucketName 文件所在bucket @return string 签名
[ "生成多次有效签名函数(用于上传和下载资源,有效期内可重复对不同资源使用)", "." ]
train
https://github.com/freyo/flysystem-qcloud-cos-v3/blob/6bddbc22396aa1228942ec4c0ce46935d415f3b4/src/Client/Auth.php#L18-L29
freyo/flysystem-qcloud-cos-v3
src/Client/Auth.php
Auth.appSign_once
public static function appSign_once($path, $bucketName) { $appId = Conf::getAppId(); $secretId = Conf::getSecretId(); $secretKey = Conf::getSecretKey(); if (preg_match('/^\//', $path) == 0) { $path = '/'.$path; } $fileId = '/'.$appId.'/'.$bucketName.$path; if (empty($secretId) || empty($secretKey) || empty($appId)) { return self::AUTH_SECRET_ID_KEY_ERROR; } return self::appSignBase($appId, $secretId, $secretKey, 0, $fileId, $bucketName); }
php
public static function appSign_once($path, $bucketName) { $appId = Conf::getAppId(); $secretId = Conf::getSecretId(); $secretKey = Conf::getSecretKey(); if (preg_match('/^\//', $path) == 0) { $path = '/'.$path; } $fileId = '/'.$appId.'/'.$bucketName.$path; if (empty($secretId) || empty($secretKey) || empty($appId)) { return self::AUTH_SECRET_ID_KEY_ERROR; } return self::appSignBase($appId, $secretId, $secretKey, 0, $fileId, $bucketName); }
[ "public", "static", "function", "appSign_once", "(", "$", "path", ",", "$", "bucketName", ")", "{", "$", "appId", "=", "Conf", "::", "getAppId", "(", ")", ";", "$", "secretId", "=", "Conf", "::", "getSecretId", "(", ")", ";", "$", "secretKey", "=", "Conf", "::", "getSecretKey", "(", ")", ";", "if", "(", "preg_match", "(", "'/^\\//'", ",", "$", "path", ")", "==", "0", ")", "{", "$", "path", "=", "'/'", ".", "$", "path", ";", "}", "$", "fileId", "=", "'/'", ".", "$", "appId", ".", "'/'", ".", "$", "bucketName", ".", "$", "path", ";", "if", "(", "empty", "(", "$", "secretId", ")", "||", "empty", "(", "$", "secretKey", ")", "||", "empty", "(", "$", "appId", ")", ")", "{", "return", "self", "::", "AUTH_SECRET_ID_KEY_ERROR", ";", "}", "return", "self", "::", "appSignBase", "(", "$", "appId", ",", "$", "secretId", ",", "$", "secretKey", ",", "0", ",", "$", "fileId", ",", "$", "bucketName", ")", ";", "}" ]
生成单次有效签名函数(用于删除和更新指定fileId资源,使用一次即失效). @param string $bucketName 文件所在bucket @param string $path @return string 签名
[ "生成单次有效签名函数(用于删除和更新指定fileId资源,使用一次即失效)", "." ]
train
https://github.com/freyo/flysystem-qcloud-cos-v3/blob/6bddbc22396aa1228942ec4c0ce46935d415f3b4/src/Client/Auth.php#L39-L55
yuncms/framework
src/base/Collection.php
Collection.only
public function only(array $keys): array { $return = []; foreach ($keys as $key) { $value = $this->get($key); if (!is_null($value)) { $return[$key] = $value; } } return $return; }
php
public function only(array $keys): array { $return = []; foreach ($keys as $key) { $value = $this->get($key); if (!is_null($value)) { $return[$key] = $value; } } return $return; }
[ "public", "function", "only", "(", "array", "$", "keys", ")", ":", "array", "{", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "value", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "return", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "return", ";", "}" ]
Return specific items. @param array $keys @return array
[ "Return", "specific", "items", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/base/Collection.php#L86-L96
yuncms/framework
src/base/Collection.php
Collection.except
public function except($keys): Collection { $keys = is_array($keys) ? $keys : func_get_args(); return new static(ArrayHelper::except($this->items, $keys)); }
php
public function except($keys): Collection { $keys = is_array($keys) ? $keys : func_get_args(); return new static(ArrayHelper::except($this->items, $keys)); }
[ "public", "function", "except", "(", "$", "keys", ")", ":", "Collection", "{", "$", "keys", "=", "is_array", "(", "$", "keys", ")", "?", "$", "keys", ":", "func_get_args", "(", ")", ";", "return", "new", "static", "(", "ArrayHelper", "::", "except", "(", "$", "this", "->", "items", ",", "$", "keys", ")", ")", ";", "}" ]
Get all items except for those with the specified keys. @param mixed $keys @return Collection
[ "Get", "all", "items", "except", "for", "those", "with", "the", "specified", "keys", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/base/Collection.php#L104-L108
VincentChalnot/SidusAdminBundle
Routing/RoutingHelper.php
RoutingHelper.redirectToEntity
public function redirectToEntity( Action $action, $entity, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302 ): RedirectResponse { $url = $this->adminRouter->generateAdminEntityPath( $action->getAdmin(), $entity, $action->getCode(), $parameters, $referenceType ); return new RedirectResponse($url, $status); }
php
public function redirectToEntity( Action $action, $entity, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302 ): RedirectResponse { $url = $this->adminRouter->generateAdminEntityPath( $action->getAdmin(), $entity, $action->getCode(), $parameters, $referenceType ); return new RedirectResponse($url, $status); }
[ "public", "function", "redirectToEntity", "(", "Action", "$", "action", ",", "$", "entity", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ",", "$", "status", "=", "302", ")", ":", "RedirectResponse", "{", "$", "url", "=", "$", "this", "->", "adminRouter", "->", "generateAdminEntityPath", "(", "$", "action", "->", "getAdmin", "(", ")", ",", "$", "entity", ",", "$", "action", "->", "getCode", "(", ")", ",", "$", "parameters", ",", "$", "referenceType", ")", ";", "return", "new", "RedirectResponse", "(", "$", "url", ",", "$", "status", ")", ";", "}" ]
@param Action $action @param mixed $entity @param array $parameters @param int $referenceType @param int $status @return RedirectResponse
[ "@param", "Action", "$action", "@param", "mixed", "$entity", "@param", "array", "$parameters", "@param", "int", "$referenceType", "@param", "int", "$status" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Routing/RoutingHelper.php#L44-L60
VincentChalnot/SidusAdminBundle
Routing/RoutingHelper.php
RoutingHelper.redirectToAction
public function redirectToAction( Action $action, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302 ): RedirectResponse { $url = $this->adminRouter->generateAdminPath( $action->getAdmin(), $action->getCode(), $parameters, $referenceType ); return new RedirectResponse($url, $status); }
php
public function redirectToAction( Action $action, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302 ): RedirectResponse { $url = $this->adminRouter->generateAdminPath( $action->getAdmin(), $action->getCode(), $parameters, $referenceType ); return new RedirectResponse($url, $status); }
[ "public", "function", "redirectToAction", "(", "Action", "$", "action", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ",", "$", "status", "=", "302", ")", ":", "RedirectResponse", "{", "$", "url", "=", "$", "this", "->", "adminRouter", "->", "generateAdminPath", "(", "$", "action", "->", "getAdmin", "(", ")", ",", "$", "action", "->", "getCode", "(", ")", ",", "$", "parameters", ",", "$", "referenceType", ")", ";", "return", "new", "RedirectResponse", "(", "$", "url", ",", "$", "status", ")", ";", "}" ]
@param Action $action @param array $parameters @param int $referenceType @param int $status @return RedirectResponse
[ "@param", "Action", "$action", "@param", "array", "$parameters", "@param", "int", "$referenceType", "@param", "int", "$status" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Routing/RoutingHelper.php#L70-L84
VincentChalnot/SidusAdminBundle
Routing/RoutingHelper.php
RoutingHelper.getAdminListPath
public function getAdminListPath(Admin $admin, array $parameters = []): ?string { if (!$admin->hasAction('list')) { return null; } return $this->adminRouter->generateAdminPath($admin, 'list', $parameters); }
php
public function getAdminListPath(Admin $admin, array $parameters = []): ?string { if (!$admin->hasAction('list')) { return null; } return $this->adminRouter->generateAdminPath($admin, 'list', $parameters); }
[ "public", "function", "getAdminListPath", "(", "Admin", "$", "admin", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "?", "string", "{", "if", "(", "!", "$", "admin", "->", "hasAction", "(", "'list'", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "adminRouter", "->", "generateAdminPath", "(", "$", "admin", ",", "'list'", ",", "$", "parameters", ")", ";", "}" ]
@param Admin $admin @param array $parameters @return string|null
[ "@param", "Admin", "$admin", "@param", "array", "$parameters" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Routing/RoutingHelper.php#L92-L99
VincentChalnot/SidusAdminBundle
Routing/RoutingHelper.php
RoutingHelper.getCurrentUri
public function getCurrentUri(Action $action, Request $request, array $parameters = []): string { if ($request->attributes->get('_route') === $action->getRouteName()) { $parameters = array_merge( $request->attributes->get('_route_params'), $parameters ); } return $this->adminRouter->generateAdminPath($action->getAdmin(), $action->getCode(), $parameters); }
php
public function getCurrentUri(Action $action, Request $request, array $parameters = []): string { if ($request->attributes->get('_route') === $action->getRouteName()) { $parameters = array_merge( $request->attributes->get('_route_params'), $parameters ); } return $this->adminRouter->generateAdminPath($action->getAdmin(), $action->getCode(), $parameters); }
[ "public", "function", "getCurrentUri", "(", "Action", "$", "action", ",", "Request", "$", "request", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "string", "{", "if", "(", "$", "request", "->", "attributes", "->", "get", "(", "'_route'", ")", "===", "$", "action", "->", "getRouteName", "(", ")", ")", "{", "$", "parameters", "=", "array_merge", "(", "$", "request", "->", "attributes", "->", "get", "(", "'_route_params'", ")", ",", "$", "parameters", ")", ";", "}", "return", "$", "this", "->", "adminRouter", "->", "generateAdminPath", "(", "$", "action", "->", "getAdmin", "(", ")", ",", "$", "action", "->", "getCode", "(", ")", ",", "$", "parameters", ")", ";", "}" ]
@param Action $action @param Request $request @param array $parameters @return string
[ "@param", "Action", "$action", "@param", "Request", "$request", "@param", "array", "$parameters" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Routing/RoutingHelper.php#L108-L118
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Style/Paragraph.php
PHPWord_Style_Paragraph.setAlign
public function setAlign($pValue = null) { if(strtolower($pValue) == 'justify') { // justify becames both $pValue = 'both'; } $this->_align = $pValue; return $this; }
php
public function setAlign($pValue = null) { if(strtolower($pValue) == 'justify') { // justify becames both $pValue = 'both'; } $this->_align = $pValue; return $this; }
[ "public", "function", "setAlign", "(", "$", "pValue", "=", "null", ")", "{", "if", "(", "strtolower", "(", "$", "pValue", ")", "==", "'justify'", ")", "{", "// justify becames both\r", "$", "pValue", "=", "'both'", ";", "}", "$", "this", "->", "_align", "=", "$", "pValue", ";", "return", "$", "this", ";", "}" ]
Set Paragraph Alignment @param string $pValue @return PHPWord_Style_Paragraph
[ "Set", "Paragraph", "Alignment" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Style/Paragraph.php#L105-L112
krzysztofmazur/ntp-client
src/Impl/TcpNtpClient.php
TcpNtpClient.getUnixTime
public function getUnixTime(): int { $socket = $this->connect(); $response = $this->readResponse($socket, 4); $this->close($socket); return $this->bin2dec($response) - self::SINCE_1900_TO_UNIX; }
php
public function getUnixTime(): int { $socket = $this->connect(); $response = $this->readResponse($socket, 4); $this->close($socket); return $this->bin2dec($response) - self::SINCE_1900_TO_UNIX; }
[ "public", "function", "getUnixTime", "(", ")", ":", "int", "{", "$", "socket", "=", "$", "this", "->", "connect", "(", ")", ";", "$", "response", "=", "$", "this", "->", "readResponse", "(", "$", "socket", ",", "4", ")", ";", "$", "this", "->", "close", "(", "$", "socket", ")", ";", "return", "$", "this", "->", "bin2dec", "(", "$", "response", ")", "-", "self", "::", "SINCE_1900_TO_UNIX", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/krzysztofmazur/ntp-client/blob/3e15ce8ee26d6e2e57a8bdbdf67273762e3fbfd2/src/Impl/TcpNtpClient.php#L29-L36
redaigbaria/oauth2
src/AuthorizationServer.php
AuthorizationServer.addGrantType
public function addGrantType(GrantTypeInterface $grantType, $identifier = null) { if (is_null($identifier)) { $identifier = $grantType->getIdentifier(); } // Inject server into grant $grantType->setAuthorizationServer($this); $this->grantTypes[$identifier] = $grantType; if (!is_null($grantType->getResponseType())) { $this->responseTypes[] = $grantType->getResponseType(); } return $this; }
php
public function addGrantType(GrantTypeInterface $grantType, $identifier = null) { if (is_null($identifier)) { $identifier = $grantType->getIdentifier(); } // Inject server into grant $grantType->setAuthorizationServer($this); $this->grantTypes[$identifier] = $grantType; if (!is_null($grantType->getResponseType())) { $this->responseTypes[] = $grantType->getResponseType(); } return $this; }
[ "public", "function", "addGrantType", "(", "GrantTypeInterface", "$", "grantType", ",", "$", "identifier", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "identifier", ")", ")", "{", "$", "identifier", "=", "$", "grantType", "->", "getIdentifier", "(", ")", ";", "}", "// Inject server into grant", "$", "grantType", "->", "setAuthorizationServer", "(", "$", "this", ")", ";", "$", "this", "->", "grantTypes", "[", "$", "identifier", "]", "=", "$", "grantType", ";", "if", "(", "!", "is_null", "(", "$", "grantType", "->", "getResponseType", "(", ")", ")", ")", "{", "$", "this", "->", "responseTypes", "[", "]", "=", "$", "grantType", "->", "getResponseType", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Enable support for a grant @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface @param null|string $identifier An identifier for the grant (autodetected if not passed) @return self
[ "Enable", "support", "for", "a", "grant" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AuthorizationServer.php#L95-L111
redaigbaria/oauth2
src/AuthorizationServer.php
AuthorizationServer.issueAccessToken
public function issueAccessToken() { $grantType = $this->getRequest()->request->get('grant_type'); if (is_null($grantType)) { throw new Exception\InvalidRequestException('grant_type'); } // Ensure grant type is one that is recognised and is enabled if (!in_array($grantType, array_keys($this->grantTypes))) { throw new Exception\UnsupportedGrantTypeException($grantType); } // Complete the flow return $this->getGrantType($grantType)->completeFlow(); }
php
public function issueAccessToken() { $grantType = $this->getRequest()->request->get('grant_type'); if (is_null($grantType)) { throw new Exception\InvalidRequestException('grant_type'); } // Ensure grant type is one that is recognised and is enabled if (!in_array($grantType, array_keys($this->grantTypes))) { throw new Exception\UnsupportedGrantTypeException($grantType); } // Complete the flow return $this->getGrantType($grantType)->completeFlow(); }
[ "public", "function", "issueAccessToken", "(", ")", "{", "$", "grantType", "=", "$", "this", "->", "getRequest", "(", ")", "->", "request", "->", "get", "(", "'grant_type'", ")", ";", "if", "(", "is_null", "(", "$", "grantType", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidRequestException", "(", "'grant_type'", ")", ";", "}", "// Ensure grant type is one that is recognised and is enabled", "if", "(", "!", "in_array", "(", "$", "grantType", ",", "array_keys", "(", "$", "this", "->", "grantTypes", ")", ")", ")", "{", "throw", "new", "Exception", "\\", "UnsupportedGrantTypeException", "(", "$", "grantType", ")", ";", "}", "// Complete the flow", "return", "$", "this", "->", "getGrantType", "(", "$", "grantType", ")", "->", "completeFlow", "(", ")", ";", "}" ]
Issue an access token @return array Authorise request parameters @throws
[ "Issue", "an", "access", "token" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AuthorizationServer.php#L262-L276
redaigbaria/oauth2
src/AuthorizationServer.php
AuthorizationServer.getGrantType
public function getGrantType($grantType) { if (isset($this->grantTypes[$grantType])) { return $this->grantTypes[$grantType]; } throw new Exception\InvalidGrantException($grantType); }
php
public function getGrantType($grantType) { if (isset($this->grantTypes[$grantType])) { return $this->grantTypes[$grantType]; } throw new Exception\InvalidGrantException($grantType); }
[ "public", "function", "getGrantType", "(", "$", "grantType", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "grantTypes", "[", "$", "grantType", "]", ")", ")", "{", "return", "$", "this", "->", "grantTypes", "[", "$", "grantType", "]", ";", "}", "throw", "new", "Exception", "\\", "InvalidGrantException", "(", "$", "grantType", ")", ";", "}" ]
Return a grant type class @param string $grantType The grant type identifier @return Grant\GrantTypeInterface @throws
[ "Return", "a", "grant", "type", "class" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AuthorizationServer.php#L287-L294
alanpich/slender
src/Core/ModuleResolver/DirectoryResolver.php
DirectoryResolver.getPath
public function getPath($module) { $dir = $this->dir . DIRECTORY_SEPARATOR . $module; if (!is_dir($dir)) { return false; } $find = new Finder(); $files = $find->files() ->in($dir) ->name('slender.*'); if ($files->count() < 1) { return false; } $filesIterator = iterator_to_array($files->getIterator()); $iterator = array_shift($filesIterator); return $iterator->getPath(); }
php
public function getPath($module) { $dir = $this->dir . DIRECTORY_SEPARATOR . $module; if (!is_dir($dir)) { return false; } $find = new Finder(); $files = $find->files() ->in($dir) ->name('slender.*'); if ($files->count() < 1) { return false; } $filesIterator = iterator_to_array($files->getIterator()); $iterator = array_shift($filesIterator); return $iterator->getPath(); }
[ "public", "function", "getPath", "(", "$", "module", ")", "{", "$", "dir", "=", "$", "this", "->", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "module", ";", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "return", "false", ";", "}", "$", "find", "=", "new", "Finder", "(", ")", ";", "$", "files", "=", "$", "find", "->", "files", "(", ")", "->", "in", "(", "$", "dir", ")", "->", "name", "(", "'slender.*'", ")", ";", "if", "(", "$", "files", "->", "count", "(", ")", "<", "1", ")", "{", "return", "false", ";", "}", "$", "filesIterator", "=", "iterator_to_array", "(", "$", "files", "->", "getIterator", "(", ")", ")", ";", "$", "iterator", "=", "array_shift", "(", "$", "filesIterator", ")", ";", "return", "$", "iterator", "->", "getPath", "(", ")", ";", "}" ]
Return the path to Module $module, or false if not found @param string $module Module name or Namespace @return string|false
[ "Return", "the", "path", "to", "Module", "$module", "or", "false", "if", "not", "found" ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/Core/ModuleResolver/DirectoryResolver.php#L63-L84
matks/MarkdownBlogBundle
Blog/Library.php
Library.addPost
public function addPost(Post $post) { $postName = $post->getName(); if ($this->isPostRegistered($postName)) { throw new \InvalidArgumentException("Duplicate post $postName"); } $this->registerPost($post); }
php
public function addPost(Post $post) { $postName = $post->getName(); if ($this->isPostRegistered($postName)) { throw new \InvalidArgumentException("Duplicate post $postName"); } $this->registerPost($post); }
[ "public", "function", "addPost", "(", "Post", "$", "post", ")", "{", "$", "postName", "=", "$", "post", "->", "getName", "(", ")", ";", "if", "(", "$", "this", "->", "isPostRegistered", "(", "$", "postName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Duplicate post $postName\"", ")", ";", "}", "$", "this", "->", "registerPost", "(", "$", "post", ")", ";", "}" ]
@param Post $post @throws \InvalidArgumentException if post is already registerd in Library
[ "@param", "Post", "$post" ]
train
https://github.com/matks/MarkdownBlogBundle/blob/b3438f143ece5e926b891d8f481dba35948b05fb/Blog/Library.php#L62-L71
matks/MarkdownBlogBundle
Blog/Library.php
Library.getPostsByName
public function getPostsByName(array $postNames) { $posts = []; foreach ($postNames as $postName) { if (false === $this->isPostRegistered($postName)) { continue; } $posts[$postName] = $this->posts[$postName]; } return $posts; }
php
public function getPostsByName(array $postNames) { $posts = []; foreach ($postNames as $postName) { if (false === $this->isPostRegistered($postName)) { continue; } $posts[$postName] = $this->posts[$postName]; } return $posts; }
[ "public", "function", "getPostsByName", "(", "array", "$", "postNames", ")", "{", "$", "posts", "=", "[", "]", ";", "foreach", "(", "$", "postNames", "as", "$", "postName", ")", "{", "if", "(", "false", "===", "$", "this", "->", "isPostRegistered", "(", "$", "postName", ")", ")", "{", "continue", ";", "}", "$", "posts", "[", "$", "postName", "]", "=", "$", "this", "->", "posts", "[", "$", "postName", "]", ";", "}", "return", "$", "posts", ";", "}" ]
@param string[] $postNames @return Post[]
[ "@param", "string", "[]", "$postNames" ]
train
https://github.com/matks/MarkdownBlogBundle/blob/b3438f143ece5e926b891d8f481dba35948b05fb/Blog/Library.php#L92-L103
matks/MarkdownBlogBundle
Blog/Library.php
Library.getPostsByDate
public function getPostsByDate($date) { if (false === array_key_exists($date, $this->dateIndex)) { return []; } $postNames = $this->dateIndex[$date]; return $this->getPostsByName($postNames); }
php
public function getPostsByDate($date) { if (false === array_key_exists($date, $this->dateIndex)) { return []; } $postNames = $this->dateIndex[$date]; return $this->getPostsByName($postNames); }
[ "public", "function", "getPostsByDate", "(", "$", "date", ")", "{", "if", "(", "false", "===", "array_key_exists", "(", "$", "date", ",", "$", "this", "->", "dateIndex", ")", ")", "{", "return", "[", "]", ";", "}", "$", "postNames", "=", "$", "this", "->", "dateIndex", "[", "$", "date", "]", ";", "return", "$", "this", "->", "getPostsByName", "(", "$", "postNames", ")", ";", "}" ]
@param string $date expected format: YYYY-MM-DD @return Post[]
[ "@param", "string", "$date", "expected", "format", ":", "YYYY", "-", "MM", "-", "DD" ]
train
https://github.com/matks/MarkdownBlogBundle/blob/b3438f143ece5e926b891d8f481dba35948b05fb/Blog/Library.php#L110-L119
matks/MarkdownBlogBundle
Blog/Library.php
Library.getPostsByCategory
public function getPostsByCategory($category) { if (false === array_key_exists($category, $this->categoryIndex)) { return []; } $postNames = $this->categoryIndex[$category]; return $this->getPostsByName($postNames); }
php
public function getPostsByCategory($category) { if (false === array_key_exists($category, $this->categoryIndex)) { return []; } $postNames = $this->categoryIndex[$category]; return $this->getPostsByName($postNames); }
[ "public", "function", "getPostsByCategory", "(", "$", "category", ")", "{", "if", "(", "false", "===", "array_key_exists", "(", "$", "category", ",", "$", "this", "->", "categoryIndex", ")", ")", "{", "return", "[", "]", ";", "}", "$", "postNames", "=", "$", "this", "->", "categoryIndex", "[", "$", "category", "]", ";", "return", "$", "this", "->", "getPostsByName", "(", "$", "postNames", ")", ";", "}" ]
@param string $category @return Post[]
[ "@param", "string", "$category" ]
train
https://github.com/matks/MarkdownBlogBundle/blob/b3438f143ece5e926b891d8f481dba35948b05fb/Blog/Library.php#L126-L135
matks/MarkdownBlogBundle
Blog/Library.php
Library.getPostsByTag
public function getPostsByTag($tag) { if (false === array_key_exists($tag, $this->tagsIndex)) { return []; } $postNames = $this->tagsIndex[$tag]; return $this->getPostsByName($postNames); }
php
public function getPostsByTag($tag) { if (false === array_key_exists($tag, $this->tagsIndex)) { return []; } $postNames = $this->tagsIndex[$tag]; return $this->getPostsByName($postNames); }
[ "public", "function", "getPostsByTag", "(", "$", "tag", ")", "{", "if", "(", "false", "===", "array_key_exists", "(", "$", "tag", ",", "$", "this", "->", "tagsIndex", ")", ")", "{", "return", "[", "]", ";", "}", "$", "postNames", "=", "$", "this", "->", "tagsIndex", "[", "$", "tag", "]", ";", "return", "$", "this", "->", "getPostsByName", "(", "$", "postNames", ")", ";", "}" ]
@param string $tag @return Post[]
[ "@param", "string", "$tag" ]
train
https://github.com/matks/MarkdownBlogBundle/blob/b3438f143ece5e926b891d8f481dba35948b05fb/Blog/Library.php#L142-L151
2amigos/yiifoundation
widgets/SwitchButton.php
SwitchButton.init
public function init() { Html::addCssClass($this->htmlOptions, Enum::SWITCH_BUTTON); if ($this->size) { Html::addCssClass($this->htmlOptions, $this->size); } if ($this->radius) { Html::addCssClass($this->htmlOptions, $this->radius); } parent::init(); }
php
public function init() { Html::addCssClass($this->htmlOptions, Enum::SWITCH_BUTTON); if ($this->size) { Html::addCssClass($this->htmlOptions, $this->size); } if ($this->radius) { Html::addCssClass($this->htmlOptions, $this->radius); } parent::init(); }
[ "public", "function", "init", "(", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "htmlOptions", ",", "Enum", "::", "SWITCH_BUTTON", ")", ";", "if", "(", "$", "this", "->", "size", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "htmlOptions", ",", "$", "this", "->", "size", ")", ";", "}", "if", "(", "$", "this", "->", "radius", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "htmlOptions", ",", "$", "this", "->", "radius", ")", ";", "}", "parent", "::", "init", "(", ")", ";", "}" ]
Widget's initialization
[ "Widget", "s", "initialization" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/SwitchButton.php#L44-L54
2amigos/yiifoundation
widgets/SwitchButton.php
SwitchButton.renderButtons
public function renderButtons() { list($name, $id) = $this->resolveNameID(); $buttons = array(); $checked = $this->hasModel() ? (!$this->model->{$this->attribute}) : true; $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_on', 'value' => 1)); $buttons[] = \CHtml::label($this->offLabel, $id . '_on'); $checked = $checked ? false : true; $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_off', 'value' => 1)); $buttons[] = \CHtml::label($this->onLabel, $id . '_off'); $buttons[] = '<span></span>'; return \CHtml::tag('div', $this->htmlOptions, implode("\n", $buttons)); }
php
public function renderButtons() { list($name, $id) = $this->resolveNameID(); $buttons = array(); $checked = $this->hasModel() ? (!$this->model->{$this->attribute}) : true; $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_on', 'value' => 1)); $buttons[] = \CHtml::label($this->offLabel, $id . '_on'); $checked = $checked ? false : true; $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_off', 'value' => 1)); $buttons[] = \CHtml::label($this->onLabel, $id . '_off'); $buttons[] = '<span></span>'; return \CHtml::tag('div', $this->htmlOptions, implode("\n", $buttons)); }
[ "public", "function", "renderButtons", "(", ")", "{", "list", "(", "$", "name", ",", "$", "id", ")", "=", "$", "this", "->", "resolveNameID", "(", ")", ";", "$", "buttons", "=", "array", "(", ")", ";", "$", "checked", "=", "$", "this", "->", "hasModel", "(", ")", "?", "(", "!", "$", "this", "->", "model", "->", "{", "$", "this", "->", "attribute", "}", ")", ":", "true", ";", "$", "buttons", "[", "]", "=", "\\", "CHtml", "::", "radioButton", "(", "$", "name", ",", "$", "checked", ",", "array", "(", "'id'", "=>", "$", "id", ".", "'_on'", ",", "'value'", "=>", "1", ")", ")", ";", "$", "buttons", "[", "]", "=", "\\", "CHtml", "::", "label", "(", "$", "this", "->", "offLabel", ",", "$", "id", ".", "'_on'", ")", ";", "$", "checked", "=", "$", "checked", "?", "false", ":", "true", ";", "$", "buttons", "[", "]", "=", "\\", "CHtml", "::", "radioButton", "(", "$", "name", ",", "$", "checked", ",", "array", "(", "'id'", "=>", "$", "id", ".", "'_off'", ",", "'value'", "=>", "1", ")", ")", ";", "$", "buttons", "[", "]", "=", "\\", "CHtml", "::", "label", "(", "$", "this", "->", "onLabel", ",", "$", "id", ".", "'_off'", ")", ";", "$", "buttons", "[", "]", "=", "'<span></span>'", ";", "return", "\\", "CHtml", "::", "tag", "(", "'div'", ",", "$", "this", "->", "htmlOptions", ",", "implode", "(", "\"\\n\"", ",", "$", "buttons", ")", ")", ";", "}" ]
Returns the formatted button @return string the resulting HTML
[ "Returns", "the", "formatted", "button" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/SwitchButton.php#L68-L81
activecollab/templateengine
src/TemplateEngine/PhpTemplateEngine.php
PhpTemplateEngine.&
public function &display($template, array $data = []) { $this->protectedIncludeScope($this->getTemplatePath($template), array_merge($this->getAttributes(), $data)); return $this; }
php
public function &display($template, array $data = []) { $this->protectedIncludeScope($this->getTemplatePath($template), array_merge($this->getAttributes(), $data)); return $this; }
[ "public", "function", "&", "display", "(", "$", "template", ",", "array", "$", "data", "=", "[", "]", ")", "{", "$", "this", "->", "protectedIncludeScope", "(", "$", "this", "->", "getTemplatePath", "(", "$", "template", ")", ",", "array_merge", "(", "$", "this", "->", "getAttributes", "(", ")", ",", "$", "data", ")", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/activecollab/templateengine/blob/eff2de29428b9d649c6f6d8ba5eb52b46c6f27e8/src/TemplateEngine/PhpTemplateEngine.php#L21-L26
qcubed/orm
src/Query/Node/Association.php
Association.join
public function join( Builder $objBuilder, $blnExpandSelection = false, iCondition $objJoinCondition = null, Clause\Select $objSelect = null ) { $objParentNode = $this->objParentNode; $objParentNode->join($objBuilder, $blnExpandSelection, null, $objSelect); if ($objJoinCondition && !$objJoinCondition->equalTables($this->fullAlias())) { throw new Caller("The join condition on the \"" . $this->strTableName . "\" table must only contain conditions for that table."); } try { $strParentAlias = $objParentNode->fullAlias(); $strAlias = $this->fullAlias(); //$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName); $objBuilder->addJoinItem($this->strTableName, $strAlias, $strParentAlias, $objParentNode->_PrimaryKey, $this->strPrimaryKey, $objJoinCondition); if ($blnExpandSelection) { $this->putSelectFields($objBuilder, $strAlias, $objSelect); } } catch (Caller $objExc) { $objExc->incrementOffset(); throw $objExc; } }
php
public function join( Builder $objBuilder, $blnExpandSelection = false, iCondition $objJoinCondition = null, Clause\Select $objSelect = null ) { $objParentNode = $this->objParentNode; $objParentNode->join($objBuilder, $blnExpandSelection, null, $objSelect); if ($objJoinCondition && !$objJoinCondition->equalTables($this->fullAlias())) { throw new Caller("The join condition on the \"" . $this->strTableName . "\" table must only contain conditions for that table."); } try { $strParentAlias = $objParentNode->fullAlias(); $strAlias = $this->fullAlias(); //$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName); $objBuilder->addJoinItem($this->strTableName, $strAlias, $strParentAlias, $objParentNode->_PrimaryKey, $this->strPrimaryKey, $objJoinCondition); if ($blnExpandSelection) { $this->putSelectFields($objBuilder, $strAlias, $objSelect); } } catch (Caller $objExc) { $objExc->incrementOffset(); throw $objExc; } }
[ "public", "function", "join", "(", "Builder", "$", "objBuilder", ",", "$", "blnExpandSelection", "=", "false", ",", "iCondition", "$", "objJoinCondition", "=", "null", ",", "Clause", "\\", "Select", "$", "objSelect", "=", "null", ")", "{", "$", "objParentNode", "=", "$", "this", "->", "objParentNode", ";", "$", "objParentNode", "->", "join", "(", "$", "objBuilder", ",", "$", "blnExpandSelection", ",", "null", ",", "$", "objSelect", ")", ";", "if", "(", "$", "objJoinCondition", "&&", "!", "$", "objJoinCondition", "->", "equalTables", "(", "$", "this", "->", "fullAlias", "(", ")", ")", ")", "{", "throw", "new", "Caller", "(", "\"The join condition on the \\\"\"", ".", "$", "this", "->", "strTableName", ".", "\"\\\" table must only contain conditions for that table.\"", ")", ";", "}", "try", "{", "$", "strParentAlias", "=", "$", "objParentNode", "->", "fullAlias", "(", ")", ";", "$", "strAlias", "=", "$", "this", "->", "fullAlias", "(", ")", ";", "//$strJoinTableAlias = $strParentAlias . '__' . ($this->strAlias ? $this->strAlias : $this->strName);", "$", "objBuilder", "->", "addJoinItem", "(", "$", "this", "->", "strTableName", ",", "$", "strAlias", ",", "$", "strParentAlias", ",", "$", "objParentNode", "->", "_PrimaryKey", ",", "$", "this", "->", "strPrimaryKey", ",", "$", "objJoinCondition", ")", ";", "if", "(", "$", "blnExpandSelection", ")", "{", "$", "this", "->", "putSelectFields", "(", "$", "objBuilder", ",", "$", "strAlias", ",", "$", "objSelect", ")", ";", "}", "}", "catch", "(", "Caller", "$", "objExc", ")", "{", "$", "objExc", "->", "incrementOffset", "(", ")", ";", "throw", "$", "objExc", ";", "}", "}" ]
Join the node to the query. Join condition here gets applied to parent item. @param Builder $objBuilder @param bool $blnExpandSelection @param iCondition|null $objJoinCondition @param Clause\Select|null $objSelect @throws Caller
[ "Join", "the", "node", "to", "the", "query", ".", "Join", "condition", "here", "gets", "applied", "to", "parent", "item", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/Association.php#L50-L76
CakeCMS/Core
src/Event/EventManager.php
EventManager.loadListeners
public static function loadListeners() { $manager = self::instance(); $plugins = Plugin::loaded(); foreach ($plugins as $plugin) { $events = Plugin::getData($plugin, 'events')->getArrayCopy(); foreach ($events as $name => $config) { if (is_numeric($name)) { $name = $config; $config = []; } $class = App::className($name, 'Event'); $config = (array) $config; if ($class !== false) { $listener = new $class($config); $manager->on($listener, $config); } } } }
php
public static function loadListeners() { $manager = self::instance(); $plugins = Plugin::loaded(); foreach ($plugins as $plugin) { $events = Plugin::getData($plugin, 'events')->getArrayCopy(); foreach ($events as $name => $config) { if (is_numeric($name)) { $name = $config; $config = []; } $class = App::className($name, 'Event'); $config = (array) $config; if ($class !== false) { $listener = new $class($config); $manager->on($listener, $config); } } } }
[ "public", "static", "function", "loadListeners", "(", ")", "{", "$", "manager", "=", "self", "::", "instance", "(", ")", ";", "$", "plugins", "=", "Plugin", "::", "loaded", "(", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "events", "=", "Plugin", "::", "getData", "(", "$", "plugin", ",", "'events'", ")", "->", "getArrayCopy", "(", ")", ";", "foreach", "(", "$", "events", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "is_numeric", "(", "$", "name", ")", ")", "{", "$", "name", "=", "$", "config", ";", "$", "config", "=", "[", "]", ";", "}", "$", "class", "=", "App", "::", "className", "(", "$", "name", ",", "'Event'", ")", ";", "$", "config", "=", "(", "array", ")", "$", "config", ";", "if", "(", "$", "class", "!==", "false", ")", "{", "$", "listener", "=", "new", "$", "class", "(", "$", "config", ")", ";", "$", "manager", "->", "on", "(", "$", "listener", ",", "$", "config", ")", ";", "}", "}", "}", "}" ]
Load Event Handlers during bootstrap. Plugins can add their own custom EventHandler in Config/events.php with the following format: 'events' => [ 'Core.CoreEventHandler' => [ 'options' = [ 'callable' => '', 'priority' => '', ] ] ] @return void
[ "Load", "Event", "Handlers", "during", "bootstrap", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Event/EventManager.php#L48-L70
CakeCMS/Core
src/Event/EventManager.php
EventManager.trigger
public static function trigger($name, $subject = null, $data = null) { $event = new Event($name, $subject, $data); if (is_object($subject)) { return $subject->getEventManager()->dispatch($event); } return EventManager::instance()->dispatch($event); }
php
public static function trigger($name, $subject = null, $data = null) { $event = new Event($name, $subject, $data); if (is_object($subject)) { return $subject->getEventManager()->dispatch($event); } return EventManager::instance()->dispatch($event); }
[ "public", "static", "function", "trigger", "(", "$", "name", ",", "$", "subject", "=", "null", ",", "$", "data", "=", "null", ")", "{", "$", "event", "=", "new", "Event", "(", "$", "name", ",", "$", "subject", ",", "$", "data", ")", ";", "if", "(", "is_object", "(", "$", "subject", ")", ")", "{", "return", "$", "subject", "->", "getEventManager", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "}", "return", "EventManager", "::", "instance", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "}" ]
Emits an event. @param string $name @param object|null $subject @param array|null $data @return Event
[ "Emits", "an", "event", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Event/EventManager.php#L80-L88
GrahamDeprecated/CMS-Core
src/Seeds/PagesTableSeeder.php
PagesTableSeeder.run
public function run() { DB::table('pages')->delete(); $home = array( 'title' => 'Home', 'slug' => 'home', 'body' => Markdown::render(File::get(dirname(__FILE__).'/page-home.md')), 'show_title' => false, 'icon' => 'home', 'user_id' => 1, 'created_at' => new DateTime, 'updated_at' => new DateTime ); DB::table('pages')->insert($home); $about = array( 'title' => 'About', 'slug' => 'about', 'body' => '<div class="row"><div class="col-lg-8">'.Markdown::render(File::get(dirname(__FILE__).'/page-about.md')).'</div></div>', 'user_id' => 1, 'icon' => 'info-circle', 'created_at' => new DateTime, 'updated_at' => new DateTime ); DB::table('pages')->insert($about); }
php
public function run() { DB::table('pages')->delete(); $home = array( 'title' => 'Home', 'slug' => 'home', 'body' => Markdown::render(File::get(dirname(__FILE__).'/page-home.md')), 'show_title' => false, 'icon' => 'home', 'user_id' => 1, 'created_at' => new DateTime, 'updated_at' => new DateTime ); DB::table('pages')->insert($home); $about = array( 'title' => 'About', 'slug' => 'about', 'body' => '<div class="row"><div class="col-lg-8">'.Markdown::render(File::get(dirname(__FILE__).'/page-about.md')).'</div></div>', 'user_id' => 1, 'icon' => 'info-circle', 'created_at' => new DateTime, 'updated_at' => new DateTime ); DB::table('pages')->insert($about); }
[ "public", "function", "run", "(", ")", "{", "DB", "::", "table", "(", "'pages'", ")", "->", "delete", "(", ")", ";", "$", "home", "=", "array", "(", "'title'", "=>", "'Home'", ",", "'slug'", "=>", "'home'", ",", "'body'", "=>", "Markdown", "::", "render", "(", "File", "::", "get", "(", "dirname", "(", "__FILE__", ")", ".", "'/page-home.md'", ")", ")", ",", "'show_title'", "=>", "false", ",", "'icon'", "=>", "'home'", ",", "'user_id'", "=>", "1", ",", "'created_at'", "=>", "new", "DateTime", ",", "'updated_at'", "=>", "new", "DateTime", ")", ";", "DB", "::", "table", "(", "'pages'", ")", "->", "insert", "(", "$", "home", ")", ";", "$", "about", "=", "array", "(", "'title'", "=>", "'About'", ",", "'slug'", "=>", "'about'", ",", "'body'", "=>", "'<div class=\"row\"><div class=\"col-lg-8\">'", ".", "Markdown", "::", "render", "(", "File", "::", "get", "(", "dirname", "(", "__FILE__", ")", ".", "'/page-about.md'", ")", ")", ".", "'</div></div>'", ",", "'user_id'", "=>", "1", ",", "'icon'", "=>", "'info-circle'", ",", "'created_at'", "=>", "new", "DateTime", ",", "'updated_at'", "=>", "new", "DateTime", ")", ";", "DB", "::", "table", "(", "'pages'", ")", "->", "insert", "(", "$", "about", ")", ";", "}" ]
Run the database seeding. @return void
[ "Run", "the", "database", "seeding", "." ]
train
https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Seeds/PagesTableSeeder.php#L41-L69
simplisti/jasper-starter
src/OptionDbTrait.php
OptionDbTrait.getDatabase
public function getDatabase ($key) { if (array_key_exists($key, $this->database)) { return $this->database[$key]; } return false; }
php
public function getDatabase ($key) { if (array_key_exists($key, $this->database)) { return $this->database[$key]; } return false; }
[ "public", "function", "getDatabase", "(", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "database", ")", ")", "{", "return", "$", "this", "->", "database", "[", "$", "key", "]", ";", "}", "return", "false", ";", "}" ]
Get the database details or false on failure @return string
[ "Get", "the", "database", "details", "or", "false", "on", "failure" ]
train
https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/OptionDbTrait.php#L18-L25
simplisti/jasper-starter
src/OptionDbTrait.php
OptionDbTrait.setDatabase
public function setDatabase ($name, $user, $pass, $host = 'localhost', $port = 3306) { $this->database['name'] = $name; $this->database['user'] = $user; $this->database['pass'] = $pass; $this->database['host'] = $host; $this->database['port'] = $port; return $this; }
php
public function setDatabase ($name, $user, $pass, $host = 'localhost', $port = 3306) { $this->database['name'] = $name; $this->database['user'] = $user; $this->database['pass'] = $pass; $this->database['host'] = $host; $this->database['port'] = $port; return $this; }
[ "public", "function", "setDatabase", "(", "$", "name", ",", "$", "user", ",", "$", "pass", ",", "$", "host", "=", "'localhost'", ",", "$", "port", "=", "3306", ")", "{", "$", "this", "->", "database", "[", "'name'", "]", "=", "$", "name", ";", "$", "this", "->", "database", "[", "'user'", "]", "=", "$", "user", ";", "$", "this", "->", "database", "[", "'pass'", "]", "=", "$", "pass", ";", "$", "this", "->", "database", "[", "'host'", "]", "=", "$", "host", ";", "$", "this", "->", "database", "[", "'port'", "]", "=", "$", "port", ";", "return", "$", "this", ";", "}" ]
Set the database details @return $this
[ "Set", "the", "database", "details" ]
train
https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/OptionDbTrait.php#L32-L41
simplisti/jasper-starter
src/OptionDbTrait.php
OptionDbTrait.setDatabaseUrl
public function setDatabaseUrl ($url) { $parts = parse_url($url); $this->database['name'] = trim($parts['path'], '/'); $this->database['user'] = $parts['user']; $this->database['pass'] = $parts['pass']; $this->database['host'] = $parts['host']; $this->database['port'] = $parts['port']; return $this; }
php
public function setDatabaseUrl ($url) { $parts = parse_url($url); $this->database['name'] = trim($parts['path'], '/'); $this->database['user'] = $parts['user']; $this->database['pass'] = $parts['pass']; $this->database['host'] = $parts['host']; $this->database['port'] = $parts['port']; return $this; }
[ "public", "function", "setDatabaseUrl", "(", "$", "url", ")", "{", "$", "parts", "=", "parse_url", "(", "$", "url", ")", ";", "$", "this", "->", "database", "[", "'name'", "]", "=", "trim", "(", "$", "parts", "[", "'path'", "]", ",", "'/'", ")", ";", "$", "this", "->", "database", "[", "'user'", "]", "=", "$", "parts", "[", "'user'", "]", ";", "$", "this", "->", "database", "[", "'pass'", "]", "=", "$", "parts", "[", "'pass'", "]", ";", "$", "this", "->", "database", "[", "'host'", "]", "=", "$", "parts", "[", "'host'", "]", ";", "$", "this", "->", "database", "[", "'port'", "]", "=", "$", "parts", "[", "'port'", "]", ";", "return", "$", "this", ";", "}" ]
Set the database details via URL @return $this
[ "Set", "the", "database", "details", "via", "URL" ]
train
https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/OptionDbTrait.php#L48-L59
simplisti/jasper-starter
src/OptionDbTrait.php
OptionDbTrait.setDatabaseJdbc
public function setDatabaseJdbc ($url, $dir, $class) { $this->database['url'] = $url; $this->database['dir'] = $dir; $this->database['class'] = $class; return $this; }
php
public function setDatabaseJdbc ($url, $dir, $class) { $this->database['url'] = $url; $this->database['dir'] = $dir; $this->database['class'] = $class; return $this; }
[ "public", "function", "setDatabaseJdbc", "(", "$", "url", ",", "$", "dir", ",", "$", "class", ")", "{", "$", "this", "->", "database", "[", "'url'", "]", "=", "$", "url", ";", "$", "this", "->", "database", "[", "'dir'", "]", "=", "$", "dir", ";", "$", "this", "->", "database", "[", "'class'", "]", "=", "$", "class", ";", "return", "$", "this", ";", "}" ]
Set the database JDBC details @return $this
[ "Set", "the", "database", "JDBC", "details" ]
train
https://github.com/simplisti/jasper-starter/blob/e03e24663e983710fb4f1afad6c85bde8553de65/src/OptionDbTrait.php#L66-L73
PeekAndPoke/psi
src/Psi.php
Psi.filterBy
public function filterBy($mapper, $condition) { $this->operationChain->append(new FilterByPredicate($mapper, $condition)); return $this; }
php
public function filterBy($mapper, $condition) { $this->operationChain->append(new FilterByPredicate($mapper, $condition)); return $this; }
[ "public", "function", "filterBy", "(", "$", "mapper", ",", "$", "condition", ")", "{", "$", "this", "->", "operationChain", "->", "append", "(", "new", "FilterByPredicate", "(", "$", "mapper", ",", "$", "condition", ")", ")", ";", "return", "$", "this", ";", "}" ]
Filters the input stream by passing each element first through the mapper and the to the condition This is useful of one for example want to filter all items, that have a certain property starting with a certain string: <code> $result = Psi::it($input) ->filterBy( function (Person $p) { return $p->getName(); }, new Psi\Str\StartingWith('A') ) ->toArray() </code> @param callable|UnaryFunction|BinaryFunction $mapper @param callable|UnaryFunction|BinaryFunction $condition @return $this
[ "Filters", "the", "input", "stream", "by", "passing", "each", "element", "first", "through", "the", "mapper", "and", "the", "to", "the", "condition" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Psi.php#L203-L208
PeekAndPoke/psi
src/Psi.php
Psi.uniqueBy
public function uniqueBy($mapper, $compareStrict = true) { $this->operationChain->append(new UniqueByOperation($mapper, $compareStrict)); return $this; }
php
public function uniqueBy($mapper, $compareStrict = true) { $this->operationChain->append(new UniqueByOperation($mapper, $compareStrict)); return $this; }
[ "public", "function", "uniqueBy", "(", "$", "mapper", ",", "$", "compareStrict", "=", "true", ")", "{", "$", "this", "->", "operationChain", "->", "append", "(", "new", "UniqueByOperation", "(", "$", "mapper", ",", "$", "compareStrict", ")", ")", ";", "return", "$", "this", ";", "}" ]
@param callable|UnaryFunction|BinaryFunction $mapper Input mapper function @param bool $compareStrict Whether to do strict comparison @return $this
[ "@param", "callable|UnaryFunction|BinaryFunction", "$mapper", "Input", "mapper", "function", "@param", "bool", "$compareStrict", "Whether", "to", "do", "strict", "comparison" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Psi.php#L438-L443
PeekAndPoke/psi
src/Psi.php
Psi.any
public function any($condition) { $this->filter($condition); $tmp = new \stdClass(); return $this->getFirst($tmp) !== $tmp; }
php
public function any($condition) { $this->filter($condition); $tmp = new \stdClass(); return $this->getFirst($tmp) !== $tmp; }
[ "public", "function", "any", "(", "$", "condition", ")", "{", "$", "this", "->", "filter", "(", "$", "condition", ")", ";", "$", "tmp", "=", "new", "\\", "stdClass", "(", ")", ";", "return", "$", "this", "->", "getFirst", "(", "$", "tmp", ")", "!==", "$", "tmp", ";", "}" ]
Returns true if at least one element matches the condition @param callable|UnaryFunction|BinaryFunction $condition @return bool
[ "Returns", "true", "if", "at", "least", "one", "element", "matches", "the", "condition" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Psi.php#L613-L620
PeekAndPoke/psi
src/Psi.php
Psi.all
public function all($condition) { return ! $this->any( // TODO: create Not predicate class function ($elem, $idx) use ($condition) { return ! $condition($elem, $idx); } ); }
php
public function all($condition) { return ! $this->any( // TODO: create Not predicate class function ($elem, $idx) use ($condition) { return ! $condition($elem, $idx); } ); }
[ "public", "function", "all", "(", "$", "condition", ")", "{", "return", "!", "$", "this", "->", "any", "(", "// TODO: create Not predicate class", "function", "(", "$", "elem", ",", "$", "idx", ")", "use", "(", "$", "condition", ")", "{", "return", "!", "$", "condition", "(", "$", "elem", ",", "$", "idx", ")", ";", "}", ")", ";", "}" ]
Returns true if all elements match the condition @param callable|UnaryFunction|BinaryFunction $condition @return bool
[ "Returns", "true", "if", "all", "elements", "match", "the", "condition" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Psi.php#L629-L637
PeekAndPoke/psi
src/Psi.php
Psi.solveOperationsAndApplyTerminal
private function solveOperationsAndApplyTerminal(TerminalOperation $terminal) { // When we have not a single operation in the chain we add a dummy one, in order to map down multiple input // living inside the \AppendIterator (in case we have multiple inputs) if (count($this->operationChain) === 0) { $this->operationChain->append(new EmptyIntermediateOp()); } $factory = $this->options->getFactory(); /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $iterator = $factory->createIterator($this->inputs, $this->options); $solver = $factory->createSolver(); $result = $solver->solve($this->operationChain, $iterator); return $terminal->apply($result); }
php
private function solveOperationsAndApplyTerminal(TerminalOperation $terminal) { // When we have not a single operation in the chain we add a dummy one, in order to map down multiple input // living inside the \AppendIterator (in case we have multiple inputs) if (count($this->operationChain) === 0) { $this->operationChain->append(new EmptyIntermediateOp()); } $factory = $this->options->getFactory(); /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $iterator = $factory->createIterator($this->inputs, $this->options); $solver = $factory->createSolver(); $result = $solver->solve($this->operationChain, $iterator); return $terminal->apply($result); }
[ "private", "function", "solveOperationsAndApplyTerminal", "(", "TerminalOperation", "$", "terminal", ")", "{", "// When we have not a single operation in the chain we add a dummy one, in order to map down multiple input", "// living inside the \\AppendIterator (in case we have multiple inputs)", "if", "(", "count", "(", "$", "this", "->", "operationChain", ")", "===", "0", ")", "{", "$", "this", "->", "operationChain", "->", "append", "(", "new", "EmptyIntermediateOp", "(", ")", ")", ";", "}", "$", "factory", "=", "$", "this", "->", "options", "->", "getFactory", "(", ")", ";", "/** @noinspection ExceptionsAnnotatingAndHandlingInspection */", "$", "iterator", "=", "$", "factory", "->", "createIterator", "(", "$", "this", "->", "inputs", ",", "$", "this", "->", "options", ")", ";", "$", "solver", "=", "$", "factory", "->", "createSolver", "(", ")", ";", "$", "result", "=", "$", "solver", "->", "solve", "(", "$", "this", "->", "operationChain", ",", "$", "iterator", ")", ";", "return", "$", "terminal", "->", "apply", "(", "$", "result", ")", ";", "}" ]
@param TerminalOperation $terminal @return mixed
[ "@param", "TerminalOperation", "$terminal" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Psi.php#L646-L661
webforge-labs/psc-cms
lib/Psc/Code/Generate/GMethod.php
GMethod.php
public function php($baseIndent = 0) { $cr = "\n"; $php = $this->phpDocBlock($baseIndent); // vor die modifier muss das indent $php .= str_repeat(' ',$baseIndent); $ms = array(self::MODIFIER_ABSTRACT => 'abstract', self::MODIFIER_PUBLIC => 'public', self::MODIFIER_PRIVATE => 'private', self::MODIFIER_PROTECTED => 'protected', self::MODIFIER_STATIC => 'static', self::MODIFIER_FINAL => 'final' ); foreach ($ms as $const => $modifier) { if (($const & $this->modifiers) == $const) $php .= $modifier.' '; } $php .= parent::php($baseIndent); return $php; }
php
public function php($baseIndent = 0) { $cr = "\n"; $php = $this->phpDocBlock($baseIndent); // vor die modifier muss das indent $php .= str_repeat(' ',$baseIndent); $ms = array(self::MODIFIER_ABSTRACT => 'abstract', self::MODIFIER_PUBLIC => 'public', self::MODIFIER_PRIVATE => 'private', self::MODIFIER_PROTECTED => 'protected', self::MODIFIER_STATIC => 'static', self::MODIFIER_FINAL => 'final' ); foreach ($ms as $const => $modifier) { if (($const & $this->modifiers) == $const) $php .= $modifier.' '; } $php .= parent::php($baseIndent); return $php; }
[ "public", "function", "php", "(", "$", "baseIndent", "=", "0", ")", "{", "$", "cr", "=", "\"\\n\"", ";", "$", "php", "=", "$", "this", "->", "phpDocBlock", "(", "$", "baseIndent", ")", ";", "// vor die modifier muss das indent", "$", "php", ".=", "str_repeat", "(", "' '", ",", "$", "baseIndent", ")", ";", "$", "ms", "=", "array", "(", "self", "::", "MODIFIER_ABSTRACT", "=>", "'abstract'", ",", "self", "::", "MODIFIER_PUBLIC", "=>", "'public'", ",", "self", "::", "MODIFIER_PRIVATE", "=>", "'private'", ",", "self", "::", "MODIFIER_PROTECTED", "=>", "'protected'", ",", "self", "::", "MODIFIER_STATIC", "=>", "'static'", ",", "self", "::", "MODIFIER_FINAL", "=>", "'final'", ")", ";", "foreach", "(", "$", "ms", "as", "$", "const", "=>", "$", "modifier", ")", "{", "if", "(", "(", "$", "const", "&", "$", "this", "->", "modifiers", ")", "==", "$", "const", ")", "$", "php", ".=", "$", "modifier", ".", "' '", ";", "}", "$", "php", ".=", "parent", "::", "php", "(", "$", "baseIndent", ")", ";", "return", "$", "php", ";", "}" ]
Gibt den PHP Code für die Methode zurück Nach der } ist kein LF
[ "Gibt", "den", "PHP", "Code", "für", "die", "Methode", "zurück" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Generate/GMethod.php#L49-L73
PortaText/php-sdk
src/PortaText/Command/Api/MyPassword.php
MyPassword.getEndpoint
protected function getEndpoint($method) { $endpoint = 'me/password'; $reset = $this->getArgument('reset'); $nonce = $this->getArgument('nonce'); if (!is_null($reset)) { $endpoint .= '/reset'; $this->delArgument('reset'); } if (!is_null($nonce)) { $endpoint .= "/$nonce"; $this->delArgument('nonce'); } return $endpoint; }
php
protected function getEndpoint($method) { $endpoint = 'me/password'; $reset = $this->getArgument('reset'); $nonce = $this->getArgument('nonce'); if (!is_null($reset)) { $endpoint .= '/reset'; $this->delArgument('reset'); } if (!is_null($nonce)) { $endpoint .= "/$nonce"; $this->delArgument('nonce'); } return $endpoint; }
[ "protected", "function", "getEndpoint", "(", "$", "method", ")", "{", "$", "endpoint", "=", "'me/password'", ";", "$", "reset", "=", "$", "this", "->", "getArgument", "(", "'reset'", ")", ";", "$", "nonce", "=", "$", "this", "->", "getArgument", "(", "'nonce'", ")", ";", "if", "(", "!", "is_null", "(", "$", "reset", ")", ")", "{", "$", "endpoint", ".=", "'/reset'", ";", "$", "this", "->", "delArgument", "(", "'reset'", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "nonce", ")", ")", "{", "$", "endpoint", ".=", "\"/$nonce\"", ";", "$", "this", "->", "delArgument", "(", "'nonce'", ")", ";", "}", "return", "$", "endpoint", ";", "}" ]
Returns a string with the endpoint for the given command. @param string $method Method for this command. @return string
[ "Returns", "a", "string", "with", "the", "endpoint", "for", "the", "given", "command", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/MyPassword.php#L77-L91
fubhy/graphql-php
src/Type/Definition/Types/Scalars/FloatType.php
FloatType.coerceLiteral
public function coerceLiteral(Node $node) { if ($node instanceof IntValue || $node instanceof FloatValue) { $num = (float) $node->get('value'); if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) { return $num; } } return NULL; }
php
public function coerceLiteral(Node $node) { if ($node instanceof IntValue || $node instanceof FloatValue) { $num = (float) $node->get('value'); if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) { return $num; } } return NULL; }
[ "public", "function", "coerceLiteral", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "IntValue", "||", "$", "node", "instanceof", "FloatValue", ")", "{", "$", "num", "=", "(", "float", ")", "$", "node", "->", "get", "(", "'value'", ")", ";", "if", "(", "$", "num", "<=", "PHP_INT_MAX", "&&", "$", "num", ">=", "-", "PHP_INT_MAX", ")", "{", "return", "$", "num", ";", "}", "}", "return", "NULL", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Type/Definition/Types/Scalars/FloatType.php#L28-L39
limen/php-jobs
src/Helper.php
Helper.compareDatetime
public static function compareDatetime($a, $b) { $timea = strtotime($a); $timeb = strtotime($b); if ($timea === false || $timeb === false) { return false; } if ($timea > $timeb) { return 1; } elseif ($timea < $timeb) { return -1; } return 0; }
php
public static function compareDatetime($a, $b) { $timea = strtotime($a); $timeb = strtotime($b); if ($timea === false || $timeb === false) { return false; } if ($timea > $timeb) { return 1; } elseif ($timea < $timeb) { return -1; } return 0; }
[ "public", "static", "function", "compareDatetime", "(", "$", "a", ",", "$", "b", ")", "{", "$", "timea", "=", "strtotime", "(", "$", "a", ")", ";", "$", "timeb", "=", "strtotime", "(", "$", "b", ")", ";", "if", "(", "$", "timea", "===", "false", "||", "$", "timeb", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "$", "timea", ">", "$", "timeb", ")", "{", "return", "1", ";", "}", "elseif", "(", "$", "timea", "<", "$", "timeb", ")", "{", "return", "-", "1", ";", "}", "return", "0", ";", "}" ]
compare two datetime @param string $a yyyy-mm-dd hh:ii:ss e.g. @param string $b yyyy-mm-dd hh:ii:ss e.g. @return int|bool return false if $a or $b is not valid
[ "compare", "two", "datetime" ]
train
https://github.com/limen/php-jobs/blob/525f4082b49a7a3e69acb4cea3a622244f1616b9/src/Helper.php#L17-L33
joomla-framework/crypt
src/Cipher/Sodium.php
Sodium.decrypt
public function decrypt($data, Key $key) { // Validate key. if ($key->getType() !== 'sodium') { throw new InvalidKeyTypeException('sodium', $key->getType()); } if (!$this->nonce) { throw new \RuntimeException('Missing nonce to decrypt data'); } $decrypted = Compat::crypto_box_open( $data, $this->nonce, Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic()) ); if ($decrypted === false) { throw new \RuntimeException('Malformed message or invalid MAC'); } return $decrypted; }
php
public function decrypt($data, Key $key) { // Validate key. if ($key->getType() !== 'sodium') { throw new InvalidKeyTypeException('sodium', $key->getType()); } if (!$this->nonce) { throw new \RuntimeException('Missing nonce to decrypt data'); } $decrypted = Compat::crypto_box_open( $data, $this->nonce, Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic()) ); if ($decrypted === false) { throw new \RuntimeException('Malformed message or invalid MAC'); } return $decrypted; }
[ "public", "function", "decrypt", "(", "$", "data", ",", "Key", "$", "key", ")", "{", "// Validate key.", "if", "(", "$", "key", "->", "getType", "(", ")", "!==", "'sodium'", ")", "{", "throw", "new", "InvalidKeyTypeException", "(", "'sodium'", ",", "$", "key", "->", "getType", "(", ")", ")", ";", "}", "if", "(", "!", "$", "this", "->", "nonce", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Missing nonce to decrypt data'", ")", ";", "}", "$", "decrypted", "=", "Compat", "::", "crypto_box_open", "(", "$", "data", ",", "$", "this", "->", "nonce", ",", "Compat", "::", "crypto_box_keypair_from_secretkey_and_publickey", "(", "$", "key", "->", "getPrivate", "(", ")", ",", "$", "key", "->", "getPublic", "(", ")", ")", ")", ";", "if", "(", "$", "decrypted", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Malformed message or invalid MAC'", ")", ";", "}", "return", "$", "decrypted", ";", "}" ]
Method to decrypt a data string. @param string $data The encrypted string to decrypt. @param Key $key The key object to use for decryption. @return string The decrypted data string. @since 1.4.0 @throws \RuntimeException
[ "Method", "to", "decrypt", "a", "data", "string", "." ]
train
https://github.com/joomla-framework/crypt/blob/5b24370bd5f07d2b305f66e62294c6d10a3f619d/src/Cipher/Sodium.php#L42-L67
joomla-framework/crypt
src/Cipher/Sodium.php
Sodium.encrypt
public function encrypt($data, Key $key) { // Validate key. if ($key->getType() !== 'sodium') { throw new InvalidKeyTypeException('sodium', $key->getType()); } if (!$this->nonce) { throw new \RuntimeException('Missing nonce to decrypt data'); } return Compat::crypto_box( $data, $this->nonce, Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic()) ); }
php
public function encrypt($data, Key $key) { // Validate key. if ($key->getType() !== 'sodium') { throw new InvalidKeyTypeException('sodium', $key->getType()); } if (!$this->nonce) { throw new \RuntimeException('Missing nonce to decrypt data'); } return Compat::crypto_box( $data, $this->nonce, Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic()) ); }
[ "public", "function", "encrypt", "(", "$", "data", ",", "Key", "$", "key", ")", "{", "// Validate key.", "if", "(", "$", "key", "->", "getType", "(", ")", "!==", "'sodium'", ")", "{", "throw", "new", "InvalidKeyTypeException", "(", "'sodium'", ",", "$", "key", "->", "getType", "(", ")", ")", ";", "}", "if", "(", "!", "$", "this", "->", "nonce", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Missing nonce to decrypt data'", ")", ";", "}", "return", "Compat", "::", "crypto_box", "(", "$", "data", ",", "$", "this", "->", "nonce", ",", "Compat", "::", "crypto_box_keypair_from_secretkey_and_publickey", "(", "$", "key", "->", "getPrivate", "(", ")", ",", "$", "key", "->", "getPublic", "(", ")", ")", ")", ";", "}" ]
Method to encrypt a data string. @param string $data The data string to encrypt. @param Key $key The key object to use for encryption. @return string The encrypted data string. @since 1.4.0 @throws \RuntimeException
[ "Method", "to", "encrypt", "a", "data", "string", "." ]
train
https://github.com/joomla-framework/crypt/blob/5b24370bd5f07d2b305f66e62294c6d10a3f619d/src/Cipher/Sodium.php#L80-L98
joomla-framework/crypt
src/Cipher/Sodium.php
Sodium.generateKey
public function generateKey(array $options = []) { // Generate the encryption key. $pair = Compat::crypto_box_keypair(); return new Key('sodium', Compat::crypto_box_secretkey($pair), Compat::crypto_box_publickey($pair)); }
php
public function generateKey(array $options = []) { // Generate the encryption key. $pair = Compat::crypto_box_keypair(); return new Key('sodium', Compat::crypto_box_secretkey($pair), Compat::crypto_box_publickey($pair)); }
[ "public", "function", "generateKey", "(", "array", "$", "options", "=", "[", "]", ")", "{", "// Generate the encryption key.", "$", "pair", "=", "Compat", "::", "crypto_box_keypair", "(", ")", ";", "return", "new", "Key", "(", "'sodium'", ",", "Compat", "::", "crypto_box_secretkey", "(", "$", "pair", ")", ",", "Compat", "::", "crypto_box_publickey", "(", "$", "pair", ")", ")", ";", "}" ]
Method to generate a new encryption key object. @param array $options Key generation options. @return Key @since 1.4.0 @throws RuntimeException
[ "Method", "to", "generate", "a", "new", "encryption", "key", "object", "." ]
train
https://github.com/joomla-framework/crypt/blob/5b24370bd5f07d2b305f66e62294c6d10a3f619d/src/Cipher/Sodium.php#L110-L116
aedart/laravel-helpers
src/Traits/Hashing/HashTrait.php
HashTrait.getHash
public function getHash(): ?Hasher { if (!$this->hasHash()) { $this->setHash($this->getDefaultHash()); } return $this->hash; }
php
public function getHash(): ?Hasher { if (!$this->hasHash()) { $this->setHash($this->getDefaultHash()); } return $this->hash; }
[ "public", "function", "getHash", "(", ")", ":", "?", "Hasher", "{", "if", "(", "!", "$", "this", "->", "hasHash", "(", ")", ")", "{", "$", "this", "->", "setHash", "(", "$", "this", "->", "getDefaultHash", "(", ")", ")", ";", "}", "return", "$", "this", "->", "hash", ";", "}" ]
Get hash If no hash has been set, this method will set and return a default hash, if any such value is available @see getDefaultHash() @return Hasher|null hash or null if none hash has been set
[ "Get", "hash" ]
train
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Hashing/HashTrait.php#L53-L59
restruct/silverstripe-namedlinkfield
src/NamedLinkFormField.php
NamedLinkFormField.setForm
public function setForm($form) { foreach ($this->namedLinkCompositeField->compositeDatabaseFields() as $field => $spec) { $fieldHandle = 'field' . $field; $this->{$fieldHandle}->setForm($form); } // $this->fieldPageID->setForm($form); // $this->fieldPageAnchor->setForm($form); // $this->fieldFileID->setForm($form); // $this->fieldCustomURL->setForm($form); // $this->fieldShortcode->setForm($form); // $this->fieldTitle->setForm($form); // $this->fieldLinkmode->setForm($form); parent::setForm($form); return $this; }
php
public function setForm($form) { foreach ($this->namedLinkCompositeField->compositeDatabaseFields() as $field => $spec) { $fieldHandle = 'field' . $field; $this->{$fieldHandle}->setForm($form); } // $this->fieldPageID->setForm($form); // $this->fieldPageAnchor->setForm($form); // $this->fieldFileID->setForm($form); // $this->fieldCustomURL->setForm($form); // $this->fieldShortcode->setForm($form); // $this->fieldTitle->setForm($form); // $this->fieldLinkmode->setForm($form); parent::setForm($form); return $this; }
[ "public", "function", "setForm", "(", "$", "form", ")", "{", "foreach", "(", "$", "this", "->", "namedLinkCompositeField", "->", "compositeDatabaseFields", "(", ")", "as", "$", "field", "=>", "$", "spec", ")", "{", "$", "fieldHandle", "=", "'field'", ".", "$", "field", ";", "$", "this", "->", "{", "$", "fieldHandle", "}", "->", "setForm", "(", "$", "form", ")", ";", "}", "//\t\t$this->fieldPageID->setForm($form);", "//\t\t$this->fieldPageAnchor->setForm($form);", "//\t\t$this->fieldFileID->setForm($form);", "//\t\t$this->fieldCustomURL->setForm($form);", "//\t\t$this->fieldShortcode->setForm($form);", "//\t\t$this->fieldTitle->setForm($form);", "//\t\t$this->fieldLinkmode->setForm($form);", "parent", "::", "setForm", "(", "$", "form", ")", ";", "return", "$", "this", ";", "}" ]
Set the container form. This is called automatically when fields are added to forms. @param Form $form @return $this
[ "Set", "the", "container", "form", "." ]
train
https://github.com/restruct/silverstripe-namedlinkfield/blob/567c49fdc1b24c219dec2e989fc2013b1c7951af/src/NamedLinkFormField.php#L150-L167
arsengoian/viper-framework
src/Viper/Core/Model/Model.php
Model.all
public static function all(string $key = NULL, ?string $value = NULL): Collection { return static::attempt(function () use ($key, $value): Collection { $db = DB::instance(); if ($key === NULL) $dat = $db -> selectall(static::table()); else $dat = $db -> find(static::table(), implode(',', static::columns()), [$key => $value]); $objarr = new Collection(); foreach ($dat as $local_data) { $ld = new static(['id' => $local_data['id']], $local_data); $objarr[] = $ld; } return $objarr; }); }
php
public static function all(string $key = NULL, ?string $value = NULL): Collection { return static::attempt(function () use ($key, $value): Collection { $db = DB::instance(); if ($key === NULL) $dat = $db -> selectall(static::table()); else $dat = $db -> find(static::table(), implode(',', static::columns()), [$key => $value]); $objarr = new Collection(); foreach ($dat as $local_data) { $ld = new static(['id' => $local_data['id']], $local_data); $objarr[] = $ld; } return $objarr; }); }
[ "public", "static", "function", "all", "(", "string", "$", "key", "=", "NULL", ",", "?", "string", "$", "value", "=", "NULL", ")", ":", "Collection", "{", "return", "static", "::", "attempt", "(", "function", "(", ")", "use", "(", "$", "key", ",", "$", "value", ")", ":", "Collection", "{", "$", "db", "=", "DB", "::", "instance", "(", ")", ";", "if", "(", "$", "key", "===", "NULL", ")", "$", "dat", "=", "$", "db", "->", "selectall", "(", "static", "::", "table", "(", ")", ")", ";", "else", "$", "dat", "=", "$", "db", "->", "find", "(", "static", "::", "table", "(", ")", ",", "implode", "(", "','", ",", "static", "::", "columns", "(", ")", ")", ",", "[", "$", "key", "=>", "$", "value", "]", ")", ";", "$", "objarr", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "dat", "as", "$", "local_data", ")", "{", "$", "ld", "=", "new", "static", "(", "[", "'id'", "=>", "$", "local_data", "[", "'id'", "]", "]", ",", "$", "local_data", ")", ";", "$", "objarr", "[", "]", "=", "$", "ld", ";", "}", "return", "$", "objarr", ";", "}", ")", ";", "}" ]
TODO TODO add more of these: search
[ "TODO", "TODO", "add", "more", "of", "these", ":", "search" ]
train
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Core/Model/Model.php#L41-L54
arsengoian/viper-framework
src/Viper/Core/Model/Model.php
Model.get
public function get(string $fld) { return static::attempt(function() use ($fld) { return self::modelConfig() -> typeControl($fld, parent::get($fld)); }); }
php
public function get(string $fld) { return static::attempt(function() use ($fld) { return self::modelConfig() -> typeControl($fld, parent::get($fld)); }); }
[ "public", "function", "get", "(", "string", "$", "fld", ")", "{", "return", "static", "::", "attempt", "(", "function", "(", ")", "use", "(", "$", "fld", ")", "{", "return", "self", "::", "modelConfig", "(", ")", "->", "typeControl", "(", "$", "fld", ",", "parent", "::", "get", "(", "$", "fld", ")", ")", ";", "}", ")", ";", "}" ]
TODO find
[ "TODO", "find" ]
train
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Core/Model/Model.php#L60-L64
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/MorphedByMany.php
MorphedByMany.setDefaultOptions
protected function setDefaultOptions(array $options=[]) { $this->text['relation_name_text'] = $this->command->paintString('relation name', 'brown'); if (! isset($options['name'])) { $refModel = new ReflectionClass($this->model); $name = $this->getRelationName(strtolower($refModel->getShortName())); $name = $this->command->ask("What {$this->text['relation_name_text']} do you use?", $name); } else { $name = $options['name']; } $this->defaultOptions = [ 'name' => $name, 'pivot_table' => Str::plural($name), 'foreign_key' => $name.'_id', 'related_key' => $this->model->getForeignKey() ]; }
php
protected function setDefaultOptions(array $options=[]) { $this->text['relation_name_text'] = $this->command->paintString('relation name', 'brown'); if (! isset($options['name'])) { $refModel = new ReflectionClass($this->model); $name = $this->getRelationName(strtolower($refModel->getShortName())); $name = $this->command->ask("What {$this->text['relation_name_text']} do you use?", $name); } else { $name = $options['name']; } $this->defaultOptions = [ 'name' => $name, 'pivot_table' => Str::plural($name), 'foreign_key' => $name.'_id', 'related_key' => $this->model->getForeignKey() ]; }
[ "protected", "function", "setDefaultOptions", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "text", "[", "'relation_name_text'", "]", "=", "$", "this", "->", "command", "->", "paintString", "(", "'relation name'", ",", "'brown'", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'name'", "]", ")", ")", "{", "$", "refModel", "=", "new", "ReflectionClass", "(", "$", "this", "->", "model", ")", ";", "$", "name", "=", "$", "this", "->", "getRelationName", "(", "strtolower", "(", "$", "refModel", "->", "getShortName", "(", ")", ")", ")", ";", "$", "name", "=", "$", "this", "->", "command", "->", "ask", "(", "\"What {$this->text['relation_name_text']} do you use?\"", ",", "$", "name", ")", ";", "}", "else", "{", "$", "name", "=", "$", "options", "[", "'name'", "]", ";", "}", "$", "this", "->", "defaultOptions", "=", "[", "'name'", "=>", "$", "name", ",", "'pivot_table'", "=>", "Str", "::", "plural", "(", "$", "name", ")", ",", "'foreign_key'", "=>", "$", "name", ".", "'_id'", ",", "'related_key'", "=>", "$", "this", "->", "model", "->", "getForeignKey", "(", ")", "]", ";", "}" ]
set default options @param array $options @return void
[ "set", "default", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/MorphedByMany.php#L30-L48
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/MorphedByMany.php
MorphedByMany.setConnectedRelationOptions
protected function setConnectedRelationOptions() { $foreignKey = $this->defaultOptions['foreign_key']; if (! $this->db->isTableExists($table = $this->defaultOptions['pivot_table'])) { $table = $this->options['pivot_table'] = $this->command->choice( "Can't find table {$this->text['pivot_table']} as {$this->text['pivot_text']}, what are you using?", $this->getTables() ); $this->text['pivot_table'] = "[".$this->command->paintString($table, 'green')."]"; $name = Str::singular($table); $foreignKey = $name.'_id'; } if (! $this->db->isFieldExists($table, $foreignKey)) { $this->options['foreign_key'] = $this->command->choice( "Can't find field {$this->text['foreign_key']} in the table {$this->text['pivot_table']} as {$this->text['foreign_text']} of table {$this->text['to_table']}, choice one!", $this->getFields($table) ); } if (! $this->db->isFieldExists($table, $this->defaultOptions['related_key'])) { $this->options['related_key'] = $this->command->choice( "Can't find field {$this->text['related_key']} in the table {$this->text['pivot_table']} as {$this->text['related_text']} of table {$this->text['table']}, choice one!", $this->getFields($table) ); } }
php
protected function setConnectedRelationOptions() { $foreignKey = $this->defaultOptions['foreign_key']; if (! $this->db->isTableExists($table = $this->defaultOptions['pivot_table'])) { $table = $this->options['pivot_table'] = $this->command->choice( "Can't find table {$this->text['pivot_table']} as {$this->text['pivot_text']}, what are you using?", $this->getTables() ); $this->text['pivot_table'] = "[".$this->command->paintString($table, 'green')."]"; $name = Str::singular($table); $foreignKey = $name.'_id'; } if (! $this->db->isFieldExists($table, $foreignKey)) { $this->options['foreign_key'] = $this->command->choice( "Can't find field {$this->text['foreign_key']} in the table {$this->text['pivot_table']} as {$this->text['foreign_text']} of table {$this->text['to_table']}, choice one!", $this->getFields($table) ); } if (! $this->db->isFieldExists($table, $this->defaultOptions['related_key'])) { $this->options['related_key'] = $this->command->choice( "Can't find field {$this->text['related_key']} in the table {$this->text['pivot_table']} as {$this->text['related_text']} of table {$this->text['table']}, choice one!", $this->getFields($table) ); } }
[ "protected", "function", "setConnectedRelationOptions", "(", ")", "{", "$", "foreignKey", "=", "$", "this", "->", "defaultOptions", "[", "'foreign_key'", "]", ";", "if", "(", "!", "$", "this", "->", "db", "->", "isTableExists", "(", "$", "table", "=", "$", "this", "->", "defaultOptions", "[", "'pivot_table'", "]", ")", ")", "{", "$", "table", "=", "$", "this", "->", "options", "[", "'pivot_table'", "]", "=", "$", "this", "->", "command", "->", "choice", "(", "\"Can't find table {$this->text['pivot_table']} as {$this->text['pivot_text']}, what are you using?\"", ",", "$", "this", "->", "getTables", "(", ")", ")", ";", "$", "this", "->", "text", "[", "'pivot_table'", "]", "=", "\"[\"", ".", "$", "this", "->", "command", "->", "paintString", "(", "$", "table", ",", "'green'", ")", ".", "\"]\"", ";", "$", "name", "=", "Str", "::", "singular", "(", "$", "table", ")", ";", "$", "foreignKey", "=", "$", "name", ".", "'_id'", ";", "}", "if", "(", "!", "$", "this", "->", "db", "->", "isFieldExists", "(", "$", "table", ",", "$", "foreignKey", ")", ")", "{", "$", "this", "->", "options", "[", "'foreign_key'", "]", "=", "$", "this", "->", "command", "->", "choice", "(", "\"Can't find field {$this->text['foreign_key']} in the table {$this->text['pivot_table']} as {$this->text['foreign_text']} of table {$this->text['to_table']}, choice one!\"", ",", "$", "this", "->", "getFields", "(", "$", "table", ")", ")", ";", "}", "if", "(", "!", "$", "this", "->", "db", "->", "isFieldExists", "(", "$", "table", ",", "$", "this", "->", "defaultOptions", "[", "'related_key'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'related_key'", "]", "=", "$", "this", "->", "command", "->", "choice", "(", "\"Can't find field {$this->text['related_key']} in the table {$this->text['pivot_table']} as {$this->text['related_text']} of table {$this->text['table']}, choice one!\"", ",", "$", "this", "->", "getFields", "(", "$", "table", ")", ")", ";", "}", "}" ]
set connected db relation options @return void
[ "set", "connected", "db", "relation", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/MorphedByMany.php#L88-L116
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/MorphedByMany.php
MorphedByMany.askToUseCustomeOptions
protected function askToUseCustomeOptions() { $this->options['pivot_table'] = $this->command->ask( "The {$this->text['pivot_text']} of both relation will be?", $this->defaultOptions['pivot_table'] ); $name = Str::singular($this->options['pivot_table']); $foreignKey = $name.'_id'; $this->options['foreign_key'] = $this->command->ask( "The {$this->text['foreign_text']} of table {$this->text['to_table']} in the table {$this->text['pivot_table']} will be?", $foreignKey ); $this->options['related_key'] = $this->command->ask( "The {$this->text['related_text']} of table {$this->text['table']} in the table {$this->text['pivot_table']} will be?", $this->defaultOptions['related_key'] ); }
php
protected function askToUseCustomeOptions() { $this->options['pivot_table'] = $this->command->ask( "The {$this->text['pivot_text']} of both relation will be?", $this->defaultOptions['pivot_table'] ); $name = Str::singular($this->options['pivot_table']); $foreignKey = $name.'_id'; $this->options['foreign_key'] = $this->command->ask( "The {$this->text['foreign_text']} of table {$this->text['to_table']} in the table {$this->text['pivot_table']} will be?", $foreignKey ); $this->options['related_key'] = $this->command->ask( "The {$this->text['related_text']} of table {$this->text['table']} in the table {$this->text['pivot_table']} will be?", $this->defaultOptions['related_key'] ); }
[ "protected", "function", "askToUseCustomeOptions", "(", ")", "{", "$", "this", "->", "options", "[", "'pivot_table'", "]", "=", "$", "this", "->", "command", "->", "ask", "(", "\"The {$this->text['pivot_text']} of both relation will be?\"", ",", "$", "this", "->", "defaultOptions", "[", "'pivot_table'", "]", ")", ";", "$", "name", "=", "Str", "::", "singular", "(", "$", "this", "->", "options", "[", "'pivot_table'", "]", ")", ";", "$", "foreignKey", "=", "$", "name", ".", "'_id'", ";", "$", "this", "->", "options", "[", "'foreign_key'", "]", "=", "$", "this", "->", "command", "->", "ask", "(", "\"The {$this->text['foreign_text']} of table {$this->text['to_table']} in the table {$this->text['pivot_table']} will be?\"", ",", "$", "foreignKey", ")", ";", "$", "this", "->", "options", "[", "'related_key'", "]", "=", "$", "this", "->", "command", "->", "ask", "(", "\"The {$this->text['related_text']} of table {$this->text['table']} in the table {$this->text['pivot_table']} will be?\"", ",", "$", "this", "->", "defaultOptions", "[", "'related_key'", "]", ")", ";", "}" ]
ask to use custome options @return void
[ "ask", "to", "use", "custome", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/MorphedByMany.php#L137-L156
spiral-modules/auth
source/Auth/Traits/OperatorTrait.php
OperatorTrait.withOperator
public function withOperator(TokenOperatorInterface $operator): TokenInterface { $token = clone $this; $token->operator = $operator; /** @var TokenInterface $token */ return $token; }
php
public function withOperator(TokenOperatorInterface $operator): TokenInterface { $token = clone $this; $token->operator = $operator; /** @var TokenInterface $token */ return $token; }
[ "public", "function", "withOperator", "(", "TokenOperatorInterface", "$", "operator", ")", ":", "TokenInterface", "{", "$", "token", "=", "clone", "$", "this", ";", "$", "token", "->", "operator", "=", "$", "operator", ";", "/** @var TokenInterface $token */", "return", "$", "token", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Traits/OperatorTrait.php#L36-L43
phpmob/changmin
src/PhpMob/ChangMinBundle/Fixture/TaxonFactory.php
TaxonFactory.create
public function create(array $options = []) { $options = $this->optionsResolver->resolve($options); /** @var TaxonInterface $taxon */ $taxon = $this->taxonRepository->findOneBy(['code' => $options['code']]); if (null === $taxon) { $taxon = $this->taxonFactory->createNew(); } $taxon->setCode($options['code']); $this->setLocalizedData($taxon, ['name', 'slug', 'description'], $options); foreach ($options['children'] as $key => $childOptions) { $taxon->addChild($this->create($childOptions)); } return $taxon; }
php
public function create(array $options = []) { $options = $this->optionsResolver->resolve($options); /** @var TaxonInterface $taxon */ $taxon = $this->taxonRepository->findOneBy(['code' => $options['code']]); if (null === $taxon) { $taxon = $this->taxonFactory->createNew(); } $taxon->setCode($options['code']); $this->setLocalizedData($taxon, ['name', 'slug', 'description'], $options); foreach ($options['children'] as $key => $childOptions) { $taxon->addChild($this->create($childOptions)); } return $taxon; }
[ "public", "function", "create", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "optionsResolver", "->", "resolve", "(", "$", "options", ")", ";", "/** @var TaxonInterface $taxon */", "$", "taxon", "=", "$", "this", "->", "taxonRepository", "->", "findOneBy", "(", "[", "'code'", "=>", "$", "options", "[", "'code'", "]", "]", ")", ";", "if", "(", "null", "===", "$", "taxon", ")", "{", "$", "taxon", "=", "$", "this", "->", "taxonFactory", "->", "createNew", "(", ")", ";", "}", "$", "taxon", "->", "setCode", "(", "$", "options", "[", "'code'", "]", ")", ";", "$", "this", "->", "setLocalizedData", "(", "$", "taxon", ",", "[", "'name'", ",", "'slug'", ",", "'description'", "]", ",", "$", "options", ")", ";", "foreach", "(", "$", "options", "[", "'children'", "]", "as", "$", "key", "=>", "$", "childOptions", ")", "{", "$", "taxon", "->", "addChild", "(", "$", "this", "->", "create", "(", "$", "childOptions", ")", ")", ";", "}", "return", "$", "taxon", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Fixture/TaxonFactory.php#L70-L90
phpmob/changmin
src/PhpMob/ChangMinBundle/Fixture/TaxonFactory.php
TaxonFactory.configureOptions
protected function configureOptions(OptionsResolver $resolver) { $resolver ->setDefault('name', function (Options $options) { return $this->faker->words(3, true); }) ->setDefault('slug', function (Options $options) { return $options['name']; }) ->setDefault('code', function (Options $options) { return Inflector::ucwords($options['name']); }) ->setDefault('description', function (Options $options) { return $this->faker->paragraph; }) ->setDefault('children', []) ->setAllowedTypes('children', ['array']) ; }
php
protected function configureOptions(OptionsResolver $resolver) { $resolver ->setDefault('name', function (Options $options) { return $this->faker->words(3, true); }) ->setDefault('slug', function (Options $options) { return $options['name']; }) ->setDefault('code', function (Options $options) { return Inflector::ucwords($options['name']); }) ->setDefault('description', function (Options $options) { return $this->faker->paragraph; }) ->setDefault('children', []) ->setAllowedTypes('children', ['array']) ; }
[ "protected", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "$", "resolver", "->", "setDefault", "(", "'name'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "this", "->", "faker", "->", "words", "(", "3", ",", "true", ")", ";", "}", ")", "->", "setDefault", "(", "'slug'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "options", "[", "'name'", "]", ";", "}", ")", "->", "setDefault", "(", "'code'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "Inflector", "::", "ucwords", "(", "$", "options", "[", "'name'", "]", ")", ";", "}", ")", "->", "setDefault", "(", "'description'", ",", "function", "(", "Options", "$", "options", ")", "{", "return", "$", "this", "->", "faker", "->", "paragraph", ";", "}", ")", "->", "setDefault", "(", "'children'", ",", "[", "]", ")", "->", "setAllowedTypes", "(", "'children'", ",", "[", "'array'", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Fixture/TaxonFactory.php#L95-L113
Sedona-Solutions/sedona-sbo
src/Sedona/SBORuntimeBundle/Form/Type/ColorPickerType.php
ColorPickerType.buildView
public function buildView(FormView $view, FormInterface $form, array $options) { $optionsColorPicker = []; if (array_key_exists('color-format', $options) && empty($options['color-format']) == false) { $optionsColorPicker['format'] = $options['color-format']; } if (array_key_exists('color-horizontal', $options) && empty($options['color-horizontal']) == false) { $optionsColorPicker['horizontal'] = $options['color-horizontal']; } if (array_key_exists('color-template', $options) && empty($options['color-template']) == false) { $optionsColorPicker['template'] = $options['color-template']; } $view->vars['optionsColorPicker'] = json_encode($optionsColorPicker); $view->vars['withAddon'] = $options['color-withaddon'] == true; parent::buildView($view, $form, $options); }
php
public function buildView(FormView $view, FormInterface $form, array $options) { $optionsColorPicker = []; if (array_key_exists('color-format', $options) && empty($options['color-format']) == false) { $optionsColorPicker['format'] = $options['color-format']; } if (array_key_exists('color-horizontal', $options) && empty($options['color-horizontal']) == false) { $optionsColorPicker['horizontal'] = $options['color-horizontal']; } if (array_key_exists('color-template', $options) && empty($options['color-template']) == false) { $optionsColorPicker['template'] = $options['color-template']; } $view->vars['optionsColorPicker'] = json_encode($optionsColorPicker); $view->vars['withAddon'] = $options['color-withaddon'] == true; parent::buildView($view, $form, $options); }
[ "public", "function", "buildView", "(", "FormView", "$", "view", ",", "FormInterface", "$", "form", ",", "array", "$", "options", ")", "{", "$", "optionsColorPicker", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'color-format'", ",", "$", "options", ")", "&&", "empty", "(", "$", "options", "[", "'color-format'", "]", ")", "==", "false", ")", "{", "$", "optionsColorPicker", "[", "'format'", "]", "=", "$", "options", "[", "'color-format'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'color-horizontal'", ",", "$", "options", ")", "&&", "empty", "(", "$", "options", "[", "'color-horizontal'", "]", ")", "==", "false", ")", "{", "$", "optionsColorPicker", "[", "'horizontal'", "]", "=", "$", "options", "[", "'color-horizontal'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'color-template'", ",", "$", "options", ")", "&&", "empty", "(", "$", "options", "[", "'color-template'", "]", ")", "==", "false", ")", "{", "$", "optionsColorPicker", "[", "'template'", "]", "=", "$", "options", "[", "'color-template'", "]", ";", "}", "$", "view", "->", "vars", "[", "'optionsColorPicker'", "]", "=", "json_encode", "(", "$", "optionsColorPicker", ")", ";", "$", "view", "->", "vars", "[", "'withAddon'", "]", "=", "$", "options", "[", "'color-withaddon'", "]", "==", "true", ";", "parent", "::", "buildView", "(", "$", "view", ",", "$", "form", ",", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/Form/Type/ColorPickerType.php#L53-L69
PortaText/php-sdk
src/PortaText/Command/Result.php
Result.errors
public function errors() { if (isset($this->data) && isset($this->data["error_description"])) { return $this->data["error_description"]; } return null; }
php
public function errors() { if (isset($this->data) && isset($this->data["error_description"])) { return $this->data["error_description"]; } return null; }
[ "public", "function", "errors", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", ")", "&&", "isset", "(", "$", "this", "->", "data", "[", "\"error_description\"", "]", ")", ")", "{", "return", "$", "this", "->", "data", "[", "\"error_description\"", "]", ";", "}", "return", "null", ";", "}" ]
When the request was not successful, this will return all the errors. @return array|null
[ "When", "the", "request", "was", "not", "successful", "this", "will", "return", "all", "the", "errors", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Result.php#L49-L55
slashworks/control-bundle
src/Slashworks/BackendBundle/Model/SystemSettings.php
SystemSettings.set
public static function set($key, $value){ $oSystemSetting = SystemSettingsQuery::create()->findOneBy("key",$key); $oSystemSetting->setKey($key); $oSystemSetting->setValue($value); $oSystemSetting->save(); return $value; }
php
public static function set($key, $value){ $oSystemSetting = SystemSettingsQuery::create()->findOneBy("key",$key); $oSystemSetting->setKey($key); $oSystemSetting->setValue($value); $oSystemSetting->save(); return $value; }
[ "public", "static", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "oSystemSetting", "=", "SystemSettingsQuery", "::", "create", "(", ")", "->", "findOneBy", "(", "\"key\"", ",", "$", "key", ")", ";", "$", "oSystemSetting", "->", "setKey", "(", "$", "key", ")", ";", "$", "oSystemSetting", "->", "setValue", "(", "$", "value", ")", ";", "$", "oSystemSetting", "->", "save", "(", ")", ";", "return", "$", "value", ";", "}" ]
@param $key @param $value @return mixed @throws \Exception @throws \PropelException
[ "@param", "$key", "@param", "$value" ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Model/SystemSettings.php#L33-L39
photogabble/laravel-remember-uploads
src/Middleware/RememberFileUploads.php
RememberFileUploads.handle
public function handle($request, Closure $next, $fields = ['*']) { $this->session->flash('_remembered_files', new RememberedFileBag(array_merge($this->checkRequestForRemembered($request, $fields), $this->remember($request, $fields)))); return $next($request); }
php
public function handle($request, Closure $next, $fields = ['*']) { $this->session->flash('_remembered_files', new RememberedFileBag(array_merge($this->checkRequestForRemembered($request, $fields), $this->remember($request, $fields)))); return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ",", "$", "fields", "=", "[", "'*'", "]", ")", "{", "$", "this", "->", "session", "->", "flash", "(", "'_remembered_files'", ",", "new", "RememberedFileBag", "(", "array_merge", "(", "$", "this", "->", "checkRequestForRemembered", "(", "$", "request", ",", "$", "fields", ")", ",", "$", "this", "->", "remember", "(", "$", "request", ",", "$", "fields", ")", ")", ")", ")", ";", "return", "$", "next", "(", "$", "request", ")", ";", "}" ]
Handle an incoming request. @todo write a test to check that adding additional uploaded files to the same session doesn't break things @param \Illuminate\Http\Request $request @param \Closure $next @param array $fields @return mixed @throws \Exception
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/photogabble/laravel-remember-uploads/blob/28d0667d2de74e5cd4f1980920df828cc5f99514/src/Middleware/RememberFileUploads.php#L88-L92
photogabble/laravel-remember-uploads
src/Middleware/RememberFileUploads.php
RememberFileUploads.checkRequestForRemembered
private function checkRequestForRemembered($request, array $fields) { $remembered = $request->get('_rememberedFiles', []); $files = ($fields[0] === '*') ? $remembered : array_filter($remembered, function($k) use ($fields) { return in_array($k, $fields); }, ARRAY_FILTER_USE_KEY); return $this->rememberFilesFactory($files); }
php
private function checkRequestForRemembered($request, array $fields) { $remembered = $request->get('_rememberedFiles', []); $files = ($fields[0] === '*') ? $remembered : array_filter($remembered, function($k) use ($fields) { return in_array($k, $fields); }, ARRAY_FILTER_USE_KEY); return $this->rememberFilesFactory($files); }
[ "private", "function", "checkRequestForRemembered", "(", "$", "request", ",", "array", "$", "fields", ")", "{", "$", "remembered", "=", "$", "request", "->", "get", "(", "'_rememberedFiles'", ",", "[", "]", ")", ";", "$", "files", "=", "(", "$", "fields", "[", "0", "]", "===", "'*'", ")", "?", "$", "remembered", ":", "array_filter", "(", "$", "remembered", ",", "function", "(", "$", "k", ")", "use", "(", "$", "fields", ")", "{", "return", "in_array", "(", "$", "k", ",", "$", "fields", ")", ";", "}", ",", "ARRAY_FILTER_USE_KEY", ")", ";", "return", "$", "this", "->", "rememberFilesFactory", "(", "$", "files", ")", ";", "}" ]
Remember all files found in request. @param \Illuminate\Http\Request $request @param array $fields @return array|RememberedFile[]
[ "Remember", "all", "files", "found", "in", "request", "." ]
train
https://github.com/photogabble/laravel-remember-uploads/blob/28d0667d2de74e5cd4f1980920df828cc5f99514/src/Middleware/RememberFileUploads.php#L101-L106
photogabble/laravel-remember-uploads
src/Middleware/RememberFileUploads.php
RememberFileUploads.remember
private function remember($request, array $fields) { $files = ($fields[0] === '*') ? $request->files : $request->only($fields); return $this->rememberFilesFactory($files); }
php
private function remember($request, array $fields) { $files = ($fields[0] === '*') ? $request->files : $request->only($fields); return $this->rememberFilesFactory($files); }
[ "private", "function", "remember", "(", "$", "request", ",", "array", "$", "fields", ")", "{", "$", "files", "=", "(", "$", "fields", "[", "0", "]", "===", "'*'", ")", "?", "$", "request", "->", "files", ":", "$", "request", "->", "only", "(", "$", "fields", ")", ";", "return", "$", "this", "->", "rememberFilesFactory", "(", "$", "files", ")", ";", "}" ]
Remember all files found in request. @param \Illuminate\Http\Request $request @param array $fields @return array|RememberedFile[]
[ "Remember", "all", "files", "found", "in", "request", "." ]
train
https://github.com/photogabble/laravel-remember-uploads/blob/28d0667d2de74e5cd4f1980920df828cc5f99514/src/Middleware/RememberFileUploads.php#L115-L119
photogabble/laravel-remember-uploads
src/Middleware/RememberFileUploads.php
RememberFileUploads.rememberFilesFactory
private function rememberFilesFactory($files, $prefix = '') { $result = []; foreach ($files as $key => $file) { $cacheKey = $prefix . (empty($prefix) ? '' : '.') . $key; if (is_string($file)){ if (! $this->cache->has('_remembered_files.'.$cacheKey)){ continue; } /** @noinspection Annotator */ $cached = $this->cache->get('_remembered_files.'.$cacheKey); if ($cached instanceof RememberedFile){ $result[$key] = $cached; } unset($cached); continue; } if (is_array($file)) { $result[$key] = $this->rememberFilesFactory($file, $cacheKey); } else { $storagePathName = $this->storagePath . DIRECTORY_SEPARATOR . $file->getFilename(); copy($file->getPathname(), $storagePathName); $rememberedFile = new RememberedFile($storagePathName, $file); $this->cache->put('_remembered_files.'.$cacheKey, $rememberedFile, $this->cacheTimeout); $result[$key] = $rememberedFile; } } return $result; }
php
private function rememberFilesFactory($files, $prefix = '') { $result = []; foreach ($files as $key => $file) { $cacheKey = $prefix . (empty($prefix) ? '' : '.') . $key; if (is_string($file)){ if (! $this->cache->has('_remembered_files.'.$cacheKey)){ continue; } /** @noinspection Annotator */ $cached = $this->cache->get('_remembered_files.'.$cacheKey); if ($cached instanceof RememberedFile){ $result[$key] = $cached; } unset($cached); continue; } if (is_array($file)) { $result[$key] = $this->rememberFilesFactory($file, $cacheKey); } else { $storagePathName = $this->storagePath . DIRECTORY_SEPARATOR . $file->getFilename(); copy($file->getPathname(), $storagePathName); $rememberedFile = new RememberedFile($storagePathName, $file); $this->cache->put('_remembered_files.'.$cacheKey, $rememberedFile, $this->cacheTimeout); $result[$key] = $rememberedFile; } } return $result; }
[ "private", "function", "rememberFilesFactory", "(", "$", "files", ",", "$", "prefix", "=", "''", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "key", "=>", "$", "file", ")", "{", "$", "cacheKey", "=", "$", "prefix", ".", "(", "empty", "(", "$", "prefix", ")", "?", "''", ":", "'.'", ")", ".", "$", "key", ";", "if", "(", "is_string", "(", "$", "file", ")", ")", "{", "if", "(", "!", "$", "this", "->", "cache", "->", "has", "(", "'_remembered_files.'", ".", "$", "cacheKey", ")", ")", "{", "continue", ";", "}", "/** @noinspection Annotator */", "$", "cached", "=", "$", "this", "->", "cache", "->", "get", "(", "'_remembered_files.'", ".", "$", "cacheKey", ")", ";", "if", "(", "$", "cached", "instanceof", "RememberedFile", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "cached", ";", "}", "unset", "(", "$", "cached", ")", ";", "continue", ";", "}", "if", "(", "is_array", "(", "$", "file", ")", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "rememberFilesFactory", "(", "$", "file", ",", "$", "cacheKey", ")", ";", "}", "else", "{", "$", "storagePathName", "=", "$", "this", "->", "storagePath", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", "->", "getFilename", "(", ")", ";", "copy", "(", "$", "file", "->", "getPathname", "(", ")", ",", "$", "storagePathName", ")", ";", "$", "rememberedFile", "=", "new", "RememberedFile", "(", "$", "storagePathName", ",", "$", "file", ")", ";", "$", "this", "->", "cache", "->", "put", "(", "'_remembered_files.'", ".", "$", "cacheKey", ",", "$", "rememberedFile", ",", "$", "this", "->", "cacheTimeout", ")", ";", "$", "result", "[", "$", "key", "]", "=", "$", "rememberedFile", ";", "}", "}", "return", "$", "result", ";", "}" ]
Recursive factory method to create RememberedFile from UploadedFile. @param array|UploadedFile[] $files @param string $prefix @return array|RememberedFile[]
[ "Recursive", "factory", "method", "to", "create", "RememberedFile", "from", "UploadedFile", "." ]
train
https://github.com/photogabble/laravel-remember-uploads/blob/28d0667d2de74e5cd4f1980920df828cc5f99514/src/Middleware/RememberFileUploads.php#L128-L158
parsnick/steak
src/Console/PullCommand.php
PullCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $this->setIo($input, $output); /** @var Repository $config */ $config = $this->container['config']; $sourceRepoPath = $config['source.directory']; $sourceRepoUrl = $config['source.git.url']; $sourceRepoBranch = $config['source.git.branch']; $this->checkSourceRepoSettings($sourceRepoPath, $sourceRepoUrl); $output->writeln([ "<b>steak pull configuration:</b>", " Source repository remote is <path>{$sourceRepoUrl}</path>", " Source repository branch is <path>{$sourceRepoBranch}</path>", " Path to local repository is <path>{$sourceRepoPath}</path>", ], OutputInterface::VERBOSITY_VERBOSE); if ($this->files->exists($sourceRepoPath)) { $workingCopy = $this->git->workingCopy($sourceRepoPath); if ( ! $workingCopy->isCloned()) { throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but is not a git repository."); } if ($workingCopy->getBranches()->head() != $sourceRepoBranch) { throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch."); } $this->git->streamOutput(); $workingCopy->pull(); } else { $output->writeln([ "The source directory <path>$sourceRepoPath</path> does not exist.", " Attempting clone from {$sourceRepoUrl}", ]); $this->git->streamOutput(); $this->git->cloneRepository($sourceRepoUrl, $sourceRepoPath, [ 'single-branch' => true, 'branch' => $sourceRepoBranch ]); $output->writeln("<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>"); } $output->writeln("Try <comment>steak serve</comment> to fire up the local development server..."); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $this->setIo($input, $output); /** @var Repository $config */ $config = $this->container['config']; $sourceRepoPath = $config['source.directory']; $sourceRepoUrl = $config['source.git.url']; $sourceRepoBranch = $config['source.git.branch']; $this->checkSourceRepoSettings($sourceRepoPath, $sourceRepoUrl); $output->writeln([ "<b>steak pull configuration:</b>", " Source repository remote is <path>{$sourceRepoUrl}</path>", " Source repository branch is <path>{$sourceRepoBranch}</path>", " Path to local repository is <path>{$sourceRepoPath}</path>", ], OutputInterface::VERBOSITY_VERBOSE); if ($this->files->exists($sourceRepoPath)) { $workingCopy = $this->git->workingCopy($sourceRepoPath); if ( ! $workingCopy->isCloned()) { throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but is not a git repository."); } if ($workingCopy->getBranches()->head() != $sourceRepoBranch) { throw new RuntimeException("<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch."); } $this->git->streamOutput(); $workingCopy->pull(); } else { $output->writeln([ "The source directory <path>$sourceRepoPath</path> does not exist.", " Attempting clone from {$sourceRepoUrl}", ]); $this->git->streamOutput(); $this->git->cloneRepository($sourceRepoUrl, $sourceRepoPath, [ 'single-branch' => true, 'branch' => $sourceRepoBranch ]); $output->writeln("<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>"); } $output->writeln("Try <comment>steak serve</comment> to fire up the local development server..."); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "setIo", "(", "$", "input", ",", "$", "output", ")", ";", "/** @var Repository $config */", "$", "config", "=", "$", "this", "->", "container", "[", "'config'", "]", ";", "$", "sourceRepoPath", "=", "$", "config", "[", "'source.directory'", "]", ";", "$", "sourceRepoUrl", "=", "$", "config", "[", "'source.git.url'", "]", ";", "$", "sourceRepoBranch", "=", "$", "config", "[", "'source.git.branch'", "]", ";", "$", "this", "->", "checkSourceRepoSettings", "(", "$", "sourceRepoPath", ",", "$", "sourceRepoUrl", ")", ";", "$", "output", "->", "writeln", "(", "[", "\"<b>steak pull configuration:</b>\"", ",", "\" Source repository remote is <path>{$sourceRepoUrl}</path>\"", ",", "\" Source repository branch is <path>{$sourceRepoBranch}</path>\"", ",", "\" Path to local repository is <path>{$sourceRepoPath}</path>\"", ",", "]", ",", "OutputInterface", "::", "VERBOSITY_VERBOSE", ")", ";", "if", "(", "$", "this", "->", "files", "->", "exists", "(", "$", "sourceRepoPath", ")", ")", "{", "$", "workingCopy", "=", "$", "this", "->", "git", "->", "workingCopy", "(", "$", "sourceRepoPath", ")", ";", "if", "(", "!", "$", "workingCopy", "->", "isCloned", "(", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"<path>{$sourceRepoPath}</path> exists but is not a git repository.\"", ")", ";", "}", "if", "(", "$", "workingCopy", "->", "getBranches", "(", ")", "->", "head", "(", ")", "!=", "$", "sourceRepoBranch", ")", "{", "throw", "new", "RuntimeException", "(", "\"<path>{$sourceRepoPath}</path> exists but isn't on the <path>{$sourceRepoBranch}</path> branch.\"", ")", ";", "}", "$", "this", "->", "git", "->", "streamOutput", "(", ")", ";", "$", "workingCopy", "->", "pull", "(", ")", ";", "}", "else", "{", "$", "output", "->", "writeln", "(", "[", "\"The source directory <path>$sourceRepoPath</path> does not exist.\"", ",", "\" Attempting clone from {$sourceRepoUrl}\"", ",", "]", ")", ";", "$", "this", "->", "git", "->", "streamOutput", "(", ")", ";", "$", "this", "->", "git", "->", "cloneRepository", "(", "$", "sourceRepoUrl", ",", "$", "sourceRepoPath", ",", "[", "'single-branch'", "=>", "true", ",", "'branch'", "=>", "$", "sourceRepoBranch", "]", ")", ";", "$", "output", "->", "writeln", "(", "\"<info>Clone complete! Edit your sources in <path>{$sourceRepoPath}</path></info>\"", ")", ";", "}", "$", "output", "->", "writeln", "(", "\"Try <comment>steak serve</comment> to fire up the local development server...\"", ")", ";", "}" ]
Execute the command. @param InputInterface $input @param OutputInterface $output @return void
[ "Execute", "the", "command", "." ]
train
https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/PullCommand.php#L64-L115
xinix-technology/norm
src/Norm/Cursor/BonoCursor.php
BonoCursor.count
public function count($foundOnly = false) { // TODO revisit me if ($foundOnly) { $this->rewind(); return $this->count; } else { $this->rewind(); return count($this->buffer); } }
php
public function count($foundOnly = false) { // TODO revisit me if ($foundOnly) { $this->rewind(); return $this->count; } else { $this->rewind(); return count($this->buffer); } }
[ "public", "function", "count", "(", "$", "foundOnly", "=", "false", ")", "{", "// TODO revisit me", "if", "(", "$", "foundOnly", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "return", "$", "this", "->", "count", ";", "}", "else", "{", "$", "this", "->", "rewind", "(", ")", ";", "return", "count", "(", "$", "this", "->", "buffer", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/BonoCursor.php#L46-L58
xinix-technology/norm
src/Norm/Cursor/BonoCursor.php
BonoCursor.current
public function current() { $current = $this->next[1]; return isset($current) ? $this->collection->attach($current) : null; }
php
public function current() { $current = $this->next[1]; return isset($current) ? $this->collection->attach($current) : null; }
[ "public", "function", "current", "(", ")", "{", "$", "current", "=", "$", "this", "->", "next", "[", "1", "]", ";", "return", "isset", "(", "$", "current", ")", "?", "$", "this", "->", "collection", "->", "attach", "(", "$", "current", ")", ":", "null", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/BonoCursor.php#L71-L75
xinix-technology/norm
src/Norm/Cursor/BonoCursor.php
BonoCursor.next
public function next() { // Try to get the next element in our data buffer. $this->next = each($this->buffer); // Past the end of the data buffer if (false === $this->next && !$this->isQueried) { $this->isQueried = true; $connection = $this->collection->getConnection(); $result = $connection->restGet($this); foreach ($result['entries'] as $k => $row) { $this->buffer[] = $row; } $this->count = count($this->buffer); $this->next = each($this->buffer); } }
php
public function next() { // Try to get the next element in our data buffer. $this->next = each($this->buffer); // Past the end of the data buffer if (false === $this->next && !$this->isQueried) { $this->isQueried = true; $connection = $this->collection->getConnection(); $result = $connection->restGet($this); foreach ($result['entries'] as $k => $row) { $this->buffer[] = $row; } $this->count = count($this->buffer); $this->next = each($this->buffer); } }
[ "public", "function", "next", "(", ")", "{", "// Try to get the next element in our data buffer.", "$", "this", "->", "next", "=", "each", "(", "$", "this", "->", "buffer", ")", ";", "// Past the end of the data buffer", "if", "(", "false", "===", "$", "this", "->", "next", "&&", "!", "$", "this", "->", "isQueried", ")", "{", "$", "this", "->", "isQueried", "=", "true", ";", "$", "connection", "=", "$", "this", "->", "collection", "->", "getConnection", "(", ")", ";", "$", "result", "=", "$", "connection", "->", "restGet", "(", "$", "this", ")", ";", "foreach", "(", "$", "result", "[", "'entries'", "]", "as", "$", "k", "=>", "$", "row", ")", "{", "$", "this", "->", "buffer", "[", "]", "=", "$", "row", ";", "}", "$", "this", "->", "count", "=", "count", "(", "$", "this", "->", "buffer", ")", ";", "$", "this", "->", "next", "=", "each", "(", "$", "this", "->", "buffer", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/BonoCursor.php#L80-L101
rayrutjes/domain-foundation
src/Audit/AuditInterceptor.php
AuditInterceptor.handle
public function handle(Command $command, UnitOfWork $unitOfWork, InterceptorChain $interceptorChain) { $auditListener = new AuditUnitOfWorkListener($command, $this->auditDataProvider, $this->auditLogger); $unitOfWork->registerListener($auditListener); $result = $interceptorChain->proceed(); $auditListener->setResult($result); return $result; }
php
public function handle(Command $command, UnitOfWork $unitOfWork, InterceptorChain $interceptorChain) { $auditListener = new AuditUnitOfWorkListener($command, $this->auditDataProvider, $this->auditLogger); $unitOfWork->registerListener($auditListener); $result = $interceptorChain->proceed(); $auditListener->setResult($result); return $result; }
[ "public", "function", "handle", "(", "Command", "$", "command", ",", "UnitOfWork", "$", "unitOfWork", ",", "InterceptorChain", "$", "interceptorChain", ")", "{", "$", "auditListener", "=", "new", "AuditUnitOfWorkListener", "(", "$", "command", ",", "$", "this", "->", "auditDataProvider", ",", "$", "this", "->", "auditLogger", ")", ";", "$", "unitOfWork", "->", "registerListener", "(", "$", "auditListener", ")", ";", "$", "result", "=", "$", "interceptorChain", "->", "proceed", "(", ")", ";", "$", "auditListener", "->", "setResult", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
@param Command $command @param UnitOfWork $unitOfWork @param InterceptorChain $interceptorChain @return mixed The result of the command handler, if any.
[ "@param", "Command", "$command", "@param", "UnitOfWork", "$unitOfWork", "@param", "InterceptorChain", "$interceptorChain" ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Audit/AuditInterceptor.php#L41-L50
OwlyCode/StreamingBird
src/Monitor.php
Monitor.get
public function get($name) { if (!$this->has($name)) { throw new \RuntimeException(sprintf('Cannot get non existing dimension "%s"', $name)); } return $this->stats[$name]['value']; }
php
public function get($name) { if (!$this->has($name)) { throw new \RuntimeException(sprintf('Cannot get non existing dimension "%s"', $name)); } return $this->stats[$name]['value']; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Cannot get non existing dimension \"%s\"'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "stats", "[", "$", "name", "]", "[", "'value'", "]", ";", "}" ]
@param string $name @return float|int
[ "@param", "string", "$name" ]
train
https://github.com/OwlyCode/StreamingBird/blob/177fc8a9dc8f911865a5abd9ac8d4ef85cef4003/src/Monitor.php#L54-L61
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.normalizeFolderInfo
protected function normalizeFolderInfo(array & $folder, $localizer) { if (strtolower(array_get($folder, 'type')) !== 'dir') { throw new InternalServerErrorException('Fatal error. Invalid folder info provided for normalization.'); } $path = array_get($folder, 'path'); $folder['path'] = FileUtilities::fixFolderPath($path); $folder['name'] = trim(substr($path, strlen($localizer)), '/'); if (empty($folder['name'])) { $folder['name'] = basename($path); } $folder['type'] = 'folder'; }
php
protected function normalizeFolderInfo(array & $folder, $localizer) { if (strtolower(array_get($folder, 'type')) !== 'dir') { throw new InternalServerErrorException('Fatal error. Invalid folder info provided for normalization.'); } $path = array_get($folder, 'path'); $folder['path'] = FileUtilities::fixFolderPath($path); $folder['name'] = trim(substr($path, strlen($localizer)), '/'); if (empty($folder['name'])) { $folder['name'] = basename($path); } $folder['type'] = 'folder'; }
[ "protected", "function", "normalizeFolderInfo", "(", "array", "&", "$", "folder", ",", "$", "localizer", ")", "{", "if", "(", "strtolower", "(", "array_get", "(", "$", "folder", ",", "'type'", ")", ")", "!==", "'dir'", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Fatal error. Invalid folder info provided for normalization.'", ")", ";", "}", "$", "path", "=", "array_get", "(", "$", "folder", ",", "'path'", ")", ";", "$", "folder", "[", "'path'", "]", "=", "FileUtilities", "::", "fixFolderPath", "(", "$", "path", ")", ";", "$", "folder", "[", "'name'", "]", "=", "trim", "(", "substr", "(", "$", "path", ",", "strlen", "(", "$", "localizer", ")", ")", ",", "'/'", ")", ";", "if", "(", "empty", "(", "$", "folder", "[", "'name'", "]", ")", ")", "{", "$", "folder", "[", "'name'", "]", "=", "basename", "(", "$", "path", ")", ";", "}", "$", "folder", "[", "'type'", "]", "=", "'folder'", ";", "}" ]
@param array $folder @param string $localizer @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
[ "@param", "array", "$folder", "@param", "string", "$localizer" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L152-L165
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.normalizeFileInfo
protected function normalizeFileInfo(array &$file, $localizer) { if (strtolower(array_get($file, 'type')) !== 'file') { throw new InternalServerErrorException('Fatal error. Invalid file info provided for normalization.'); } unset($file['visibility']); $path = array_get($file, 'path'); $timestamp = $this->adapter->getTimestamp($path); $file['name'] = trim(substr($path, strlen($localizer)), '/'); if (empty($file['name'])) { $file['name'] = basename($path); } $file['last_modified'] = gmdate('D, d M Y H:i:s \G\M\T', array_get($timestamp, 'timestamp', 0)); $file['content_type'] = array_get($this->adapter->getMimetype($path), 'mimetype'); $file['content_length'] = array_get($file, 'size'); unset($file['size']); }
php
protected function normalizeFileInfo(array &$file, $localizer) { if (strtolower(array_get($file, 'type')) !== 'file') { throw new InternalServerErrorException('Fatal error. Invalid file info provided for normalization.'); } unset($file['visibility']); $path = array_get($file, 'path'); $timestamp = $this->adapter->getTimestamp($path); $file['name'] = trim(substr($path, strlen($localizer)), '/'); if (empty($file['name'])) { $file['name'] = basename($path); } $file['last_modified'] = gmdate('D, d M Y H:i:s \G\M\T', array_get($timestamp, 'timestamp', 0)); $file['content_type'] = array_get($this->adapter->getMimetype($path), 'mimetype'); $file['content_length'] = array_get($file, 'size'); unset($file['size']); }
[ "protected", "function", "normalizeFileInfo", "(", "array", "&", "$", "file", ",", "$", "localizer", ")", "{", "if", "(", "strtolower", "(", "array_get", "(", "$", "file", ",", "'type'", ")", ")", "!==", "'file'", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Fatal error. Invalid file info provided for normalization.'", ")", ";", "}", "unset", "(", "$", "file", "[", "'visibility'", "]", ")", ";", "$", "path", "=", "array_get", "(", "$", "file", ",", "'path'", ")", ";", "$", "timestamp", "=", "$", "this", "->", "adapter", "->", "getTimestamp", "(", "$", "path", ")", ";", "$", "file", "[", "'name'", "]", "=", "trim", "(", "substr", "(", "$", "path", ",", "strlen", "(", "$", "localizer", ")", ")", ",", "'/'", ")", ";", "if", "(", "empty", "(", "$", "file", "[", "'name'", "]", ")", ")", "{", "$", "file", "[", "'name'", "]", "=", "basename", "(", "$", "path", ")", ";", "}", "$", "file", "[", "'last_modified'", "]", "=", "gmdate", "(", "'D, d M Y H:i:s \\G\\M\\T'", ",", "array_get", "(", "$", "timestamp", ",", "'timestamp'", ",", "0", ")", ")", ";", "$", "file", "[", "'content_type'", "]", "=", "array_get", "(", "$", "this", "->", "adapter", "->", "getMimetype", "(", "$", "path", ")", ",", "'mimetype'", ")", ";", "$", "file", "[", "'content_length'", "]", "=", "array_get", "(", "$", "file", ",", "'size'", ")", ";", "unset", "(", "$", "file", "[", "'size'", "]", ")", ";", "}" ]
@param array $file @param string $localizer @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
[ "@param", "array", "$file", "@param", "string", "$localizer" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L173-L190
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.getFolderProperties
public function getFolderProperties($container, $path) { $path = rtrim($path, '/'); $meta = $this->adapter->getMetadata($path); if ($meta === false) { throw new NotFoundException("Specified folder '" . $path . "' not found."); } if (array_get($meta, 'type') === 'dir') { $this->normalizeFolderInfo($meta, $path); unset($meta['type'], $meta['size'], $meta['visibility']); return $meta; } else { throw new InternalServerErrorException('Fatal error. Invalid folder path provided.'); } }
php
public function getFolderProperties($container, $path) { $path = rtrim($path, '/'); $meta = $this->adapter->getMetadata($path); if ($meta === false) { throw new NotFoundException("Specified folder '" . $path . "' not found."); } if (array_get($meta, 'type') === 'dir') { $this->normalizeFolderInfo($meta, $path); unset($meta['type'], $meta['size'], $meta['visibility']); return $meta; } else { throw new InternalServerErrorException('Fatal error. Invalid folder path provided.'); } }
[ "public", "function", "getFolderProperties", "(", "$", "container", ",", "$", "path", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "meta", "=", "$", "this", "->", "adapter", "->", "getMetadata", "(", "$", "path", ")", ";", "if", "(", "$", "meta", "===", "false", ")", "{", "throw", "new", "NotFoundException", "(", "\"Specified folder '\"", ".", "$", "path", ".", "\"' not found.\"", ")", ";", "}", "if", "(", "array_get", "(", "$", "meta", ",", "'type'", ")", "===", "'dir'", ")", "{", "$", "this", "->", "normalizeFolderInfo", "(", "$", "meta", ",", "$", "path", ")", ";", "unset", "(", "$", "meta", "[", "'type'", "]", ",", "$", "meta", "[", "'size'", "]", ",", "$", "meta", "[", "'visibility'", "]", ")", ";", "return", "$", "meta", ";", "}", "else", "{", "throw", "new", "InternalServerErrorException", "(", "'Fatal error. Invalid folder path provided.'", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L195-L210
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.createFolder
public function createFolder($container, $path, $properties = []) { if (empty($path)) { throw new BadRequestException("Invalid empty path."); } if ($this->folderExists($container, $path)) { throw new BadRequestException("Folder '" . $path . "' already exists."); } $path = rtrim($path, '/'); $result = $this->adapter->createDir($path, new Config()); if ($result === false) { throw new InternalServerErrorException("Failed to create folder '" . $path . "'."); } $this->normalizeFolderInfo($result, $path); return $result; }
php
public function createFolder($container, $path, $properties = []) { if (empty($path)) { throw new BadRequestException("Invalid empty path."); } if ($this->folderExists($container, $path)) { throw new BadRequestException("Folder '" . $path . "' already exists."); } $path = rtrim($path, '/'); $result = $this->adapter->createDir($path, new Config()); if ($result === false) { throw new InternalServerErrorException("Failed to create folder '" . $path . "'."); } $this->normalizeFolderInfo($result, $path); return $result; }
[ "public", "function", "createFolder", "(", "$", "container", ",", "$", "path", ",", "$", "properties", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "throw", "new", "BadRequestException", "(", "\"Invalid empty path.\"", ")", ";", "}", "if", "(", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "path", ")", ")", "{", "throw", "new", "BadRequestException", "(", "\"Folder '\"", ".", "$", "path", ".", "\"' already exists.\"", ")", ";", "}", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "result", "=", "$", "this", "->", "adapter", "->", "createDir", "(", "$", "path", ",", "new", "Config", "(", ")", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "throw", "new", "InternalServerErrorException", "(", "\"Failed to create folder '\"", ".", "$", "path", ".", "\"'.\"", ")", ";", "}", "$", "this", "->", "normalizeFolderInfo", "(", "$", "result", ",", "$", "path", ")", ";", "return", "$", "result", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L215-L233
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.copyFolder
public function copyFolder($container, $dest_path, $src_container, $src_path, $check_exist = false) { $dest_path = rtrim($dest_path, '/'); $src_path = rtrim($src_path, '/'); // does this folder already exist? if (!$this->folderExists($src_container, $src_path)) { throw new NotFoundException("Folder '$src_path' does not exist."); } if ($this->folderExists($container, $dest_path)) { if (($check_exist)) { throw new BadRequestException("Folder '$dest_path' already exists."); } } // does this folder's parent folder exist? $parent = FileUtilities::getParentFolder($dest_path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } static::copyTree($src_path, $dest_path); }
php
public function copyFolder($container, $dest_path, $src_container, $src_path, $check_exist = false) { $dest_path = rtrim($dest_path, '/'); $src_path = rtrim($src_path, '/'); // does this folder already exist? if (!$this->folderExists($src_container, $src_path)) { throw new NotFoundException("Folder '$src_path' does not exist."); } if ($this->folderExists($container, $dest_path)) { if (($check_exist)) { throw new BadRequestException("Folder '$dest_path' already exists."); } } // does this folder's parent folder exist? $parent = FileUtilities::getParentFolder($dest_path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } static::copyTree($src_path, $dest_path); }
[ "public", "function", "copyFolder", "(", "$", "container", ",", "$", "dest_path", ",", "$", "src_container", ",", "$", "src_path", ",", "$", "check_exist", "=", "false", ")", "{", "$", "dest_path", "=", "rtrim", "(", "$", "dest_path", ",", "'/'", ")", ";", "$", "src_path", "=", "rtrim", "(", "$", "src_path", ",", "'/'", ")", ";", "// does this folder already exist?", "if", "(", "!", "$", "this", "->", "folderExists", "(", "$", "src_container", ",", "$", "src_path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Folder '$src_path' does not exist.\"", ")", ";", "}", "if", "(", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "dest_path", ")", ")", "{", "if", "(", "(", "$", "check_exist", ")", ")", "{", "throw", "new", "BadRequestException", "(", "\"Folder '$dest_path' already exists.\"", ")", ";", "}", "}", "// does this folder's parent folder exist?", "$", "parent", "=", "FileUtilities", "::", "getParentFolder", "(", "$", "dest_path", ")", ";", "if", "(", "!", "empty", "(", "$", "parent", ")", "&&", "(", "!", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "parent", ")", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Folder '$parent' does not exist.\"", ")", ";", "}", "static", "::", "copyTree", "(", "$", "src_path", ",", "$", "dest_path", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L246-L266
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.deleteFolder
public function deleteFolder($container, $path, $force = false, $content_only = false) { if (!$this->folderExists($container, $path)) { throw new NotFoundException("Folder '" . $path . "' does not exist."); } $path = rtrim($path, '/'); if ($force) { $this->deleteTree($path, !$content_only); } else { try { if (!$this->adapter->deleteDir($path)) { throw new InternalServerErrorException("Failed to delete folder '" . $path . "'"); } } catch (\Exception $e) { throw new InternalServerErrorException("Directory not empty, can not delete without force option."); } } }
php
public function deleteFolder($container, $path, $force = false, $content_only = false) { if (!$this->folderExists($container, $path)) { throw new NotFoundException("Folder '" . $path . "' does not exist."); } $path = rtrim($path, '/'); if ($force) { $this->deleteTree($path, !$content_only); } else { try { if (!$this->adapter->deleteDir($path)) { throw new InternalServerErrorException("Failed to delete folder '" . $path . "'"); } } catch (\Exception $e) { throw new InternalServerErrorException("Directory not empty, can not delete without force option."); } } }
[ "public", "function", "deleteFolder", "(", "$", "container", ",", "$", "path", ",", "$", "force", "=", "false", ",", "$", "content_only", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Folder '\"", ".", "$", "path", ".", "\"' does not exist.\"", ")", ";", "}", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "$", "force", ")", "{", "$", "this", "->", "deleteTree", "(", "$", "path", ",", "!", "$", "content_only", ")", ";", "}", "else", "{", "try", "{", "if", "(", "!", "$", "this", "->", "adapter", "->", "deleteDir", "(", "$", "path", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "\"Failed to delete folder '\"", ".", "$", "path", ".", "\"'\"", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "InternalServerErrorException", "(", "\"Directory not empty, can not delete without force option.\"", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L292-L310
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.getFileProperties
public function getFileProperties($container, $path, $include_content = false, $content_as_base = true) { $path = rtrim($path, '/'); $meta = $this->adapter->getMetadata($path); if ($meta === false) { throw new NotFoundException("Specified file '" . $path . "' does not exist."); } else { $this->normalizeFileInfo($meta, $path); } if ($include_content) { $streamObj = $this->adapter->readStream($path); if ($streamObj !== false) { $stream = array_get($streamObj, 'stream'); if (empty($stream)) { throw new InternalServerErrorException('Failed to retrieve file properties.'); } $contents = fread($stream, array_get($meta, 'content_length')); if ($content_as_base) { $contents = base64_encode($contents); } $meta['content'] = $contents; } } unset($meta['type']); return $meta; }
php
public function getFileProperties($container, $path, $include_content = false, $content_as_base = true) { $path = rtrim($path, '/'); $meta = $this->adapter->getMetadata($path); if ($meta === false) { throw new NotFoundException("Specified file '" . $path . "' does not exist."); } else { $this->normalizeFileInfo($meta, $path); } if ($include_content) { $streamObj = $this->adapter->readStream($path); if ($streamObj !== false) { $stream = array_get($streamObj, 'stream'); if (empty($stream)) { throw new InternalServerErrorException('Failed to retrieve file properties.'); } $contents = fread($stream, array_get($meta, 'content_length')); if ($content_as_base) { $contents = base64_encode($contents); } $meta['content'] = $contents; } } unset($meta['type']); return $meta; }
[ "public", "function", "getFileProperties", "(", "$", "container", ",", "$", "path", ",", "$", "include_content", "=", "false", ",", "$", "content_as_base", "=", "true", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "meta", "=", "$", "this", "->", "adapter", "->", "getMetadata", "(", "$", "path", ")", ";", "if", "(", "$", "meta", "===", "false", ")", "{", "throw", "new", "NotFoundException", "(", "\"Specified file '\"", ".", "$", "path", ".", "\"' does not exist.\"", ")", ";", "}", "else", "{", "$", "this", "->", "normalizeFileInfo", "(", "$", "meta", ",", "$", "path", ")", ";", "}", "if", "(", "$", "include_content", ")", "{", "$", "streamObj", "=", "$", "this", "->", "adapter", "->", "readStream", "(", "$", "path", ")", ";", "if", "(", "$", "streamObj", "!==", "false", ")", "{", "$", "stream", "=", "array_get", "(", "$", "streamObj", ",", "'stream'", ")", ";", "if", "(", "empty", "(", "$", "stream", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Failed to retrieve file properties.'", ")", ";", "}", "$", "contents", "=", "fread", "(", "$", "stream", ",", "array_get", "(", "$", "meta", ",", "'content_length'", ")", ")", ";", "if", "(", "$", "content_as_base", ")", "{", "$", "contents", "=", "base64_encode", "(", "$", "contents", ")", ";", "}", "$", "meta", "[", "'content'", "]", "=", "$", "contents", ";", "}", "}", "unset", "(", "$", "meta", "[", "'type'", "]", ")", ";", "return", "$", "meta", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L361-L389
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.streamFile
public function streamFile($container, $path, $download = false) { try { $result = $this->adapter->readStream($path); $chunk = \Config::get('df.file_chunk_size'); if (!empty($path) && isset($result['stream'])) { $file = basename($path); $meta = $this->adapter->getMetadata($path); $mimeType = array_get($this->adapter->getMimetype($path), 'mimetype'); $timestamp = array_get($this->adapter->getTimestamp($path), 'timestamp'); $stream = array_get($result, 'stream'); $ext = FileUtilities::getFileExtension($file); $disposition = ($download) ? 'attachment; filename="' . $file . '";' : 'inline'; header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', $timestamp)); header('Content-Type: ' . $mimeType); header('Content-Length:' . array_get($meta, 'size')); if ($download || 'html' !== $ext) { header('Content-Disposition: ' . $disposition); } header('Cache-Control: private'); // use this to open files directly header('Expires: 0'); header('Pragma: public'); if (empty($chunk)) { print(fread($stream, array_get($meta, 'size'))); } else { while (!feof($stream) and (connection_status() == 0)) { print(fread($stream, $chunk)); flush(); } } } else { Log::debug('Failed to stream file: ' . $path); $statusHeader = 'HTTP/1.1 404'; header($statusHeader); header('Content-Type: text/html'); echo 'The specified file ' . $path . ' does not exist.'; } } catch (\Exception $e) { Log::debug('Failed to stream file: ' . $path); $statusHeader = 'HTTP/1.1 404'; header($statusHeader); header('Content-Type: text/html'); echo 'Could not open the specified file ' . $path; echo $e->getMessage(); } }
php
public function streamFile($container, $path, $download = false) { try { $result = $this->adapter->readStream($path); $chunk = \Config::get('df.file_chunk_size'); if (!empty($path) && isset($result['stream'])) { $file = basename($path); $meta = $this->adapter->getMetadata($path); $mimeType = array_get($this->adapter->getMimetype($path), 'mimetype'); $timestamp = array_get($this->adapter->getTimestamp($path), 'timestamp'); $stream = array_get($result, 'stream'); $ext = FileUtilities::getFileExtension($file); $disposition = ($download) ? 'attachment; filename="' . $file . '";' : 'inline'; header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', $timestamp)); header('Content-Type: ' . $mimeType); header('Content-Length:' . array_get($meta, 'size')); if ($download || 'html' !== $ext) { header('Content-Disposition: ' . $disposition); } header('Cache-Control: private'); // use this to open files directly header('Expires: 0'); header('Pragma: public'); if (empty($chunk)) { print(fread($stream, array_get($meta, 'size'))); } else { while (!feof($stream) and (connection_status() == 0)) { print(fread($stream, $chunk)); flush(); } } } else { Log::debug('Failed to stream file: ' . $path); $statusHeader = 'HTTP/1.1 404'; header($statusHeader); header('Content-Type: text/html'); echo 'The specified file ' . $path . ' does not exist.'; } } catch (\Exception $e) { Log::debug('Failed to stream file: ' . $path); $statusHeader = 'HTTP/1.1 404'; header($statusHeader); header('Content-Type: text/html'); echo 'Could not open the specified file ' . $path; echo $e->getMessage(); } }
[ "public", "function", "streamFile", "(", "$", "container", ",", "$", "path", ",", "$", "download", "=", "false", ")", "{", "try", "{", "$", "result", "=", "$", "this", "->", "adapter", "->", "readStream", "(", "$", "path", ")", ";", "$", "chunk", "=", "\\", "Config", "::", "get", "(", "'df.file_chunk_size'", ")", ";", "if", "(", "!", "empty", "(", "$", "path", ")", "&&", "isset", "(", "$", "result", "[", "'stream'", "]", ")", ")", "{", "$", "file", "=", "basename", "(", "$", "path", ")", ";", "$", "meta", "=", "$", "this", "->", "adapter", "->", "getMetadata", "(", "$", "path", ")", ";", "$", "mimeType", "=", "array_get", "(", "$", "this", "->", "adapter", "->", "getMimetype", "(", "$", "path", ")", ",", "'mimetype'", ")", ";", "$", "timestamp", "=", "array_get", "(", "$", "this", "->", "adapter", "->", "getTimestamp", "(", "$", "path", ")", ",", "'timestamp'", ")", ";", "$", "stream", "=", "array_get", "(", "$", "result", ",", "'stream'", ")", ";", "$", "ext", "=", "FileUtilities", "::", "getFileExtension", "(", "$", "file", ")", ";", "$", "disposition", "=", "(", "$", "download", ")", "?", "'attachment; filename=\"'", ".", "$", "file", ".", "'\";'", ":", "'inline'", ";", "header", "(", "'Last-Modified: '", ".", "gmdate", "(", "'D, d M Y H:i:s \\G\\M\\T'", ",", "$", "timestamp", ")", ")", ";", "header", "(", "'Content-Type: '", ".", "$", "mimeType", ")", ";", "header", "(", "'Content-Length:'", ".", "array_get", "(", "$", "meta", ",", "'size'", ")", ")", ";", "if", "(", "$", "download", "||", "'html'", "!==", "$", "ext", ")", "{", "header", "(", "'Content-Disposition: '", ".", "$", "disposition", ")", ";", "}", "header", "(", "'Cache-Control: private'", ")", ";", "// use this to open files directly", "header", "(", "'Expires: 0'", ")", ";", "header", "(", "'Pragma: public'", ")", ";", "if", "(", "empty", "(", "$", "chunk", ")", ")", "{", "print", "(", "fread", "(", "$", "stream", ",", "array_get", "(", "$", "meta", ",", "'size'", ")", ")", ")", ";", "}", "else", "{", "while", "(", "!", "feof", "(", "$", "stream", ")", "and", "(", "connection_status", "(", ")", "==", "0", ")", ")", "{", "print", "(", "fread", "(", "$", "stream", ",", "$", "chunk", ")", ")", ";", "flush", "(", ")", ";", "}", "}", "}", "else", "{", "Log", "::", "debug", "(", "'Failed to stream file: '", ".", "$", "path", ")", ";", "$", "statusHeader", "=", "'HTTP/1.1 404'", ";", "header", "(", "$", "statusHeader", ")", ";", "header", "(", "'Content-Type: text/html'", ")", ";", "echo", "'The specified file '", ".", "$", "path", ".", "' does not exist.'", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "Log", "::", "debug", "(", "'Failed to stream file: '", ".", "$", "path", ")", ";", "$", "statusHeader", "=", "'HTTP/1.1 404'", ";", "header", "(", "$", "statusHeader", ")", ";", "header", "(", "'Content-Type: text/html'", ")", ";", "echo", "'Could not open the specified file '", ".", "$", "path", ";", "echo", "$", "e", "->", "getMessage", "(", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L394-L441
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.writeFile
public function writeFile($container, $path, $content, $content_is_base = false, $check_exist = false) { // does this file already exist? if ($this->fileExists($container, $path)) { if (($check_exist)) { throw new InternalServerErrorException("File '$path' already exists."); } } // does this folder's parent exist? $parent = FileUtilities::getParentFolder($path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } if ($content_is_base) { $content = base64_decode($content); } $result = $this->adapter->write($path, $content, new Config()); if (false === $result) { throw new InternalServerErrorException('Failed to create file.'); } }
php
public function writeFile($container, $path, $content, $content_is_base = false, $check_exist = false) { // does this file already exist? if ($this->fileExists($container, $path)) { if (($check_exist)) { throw new InternalServerErrorException("File '$path' already exists."); } } // does this folder's parent exist? $parent = FileUtilities::getParentFolder($path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } if ($content_is_base) { $content = base64_decode($content); } $result = $this->adapter->write($path, $content, new Config()); if (false === $result) { throw new InternalServerErrorException('Failed to create file.'); } }
[ "public", "function", "writeFile", "(", "$", "container", ",", "$", "path", ",", "$", "content", ",", "$", "content_is_base", "=", "false", ",", "$", "check_exist", "=", "false", ")", "{", "// does this file already exist?", "if", "(", "$", "this", "->", "fileExists", "(", "$", "container", ",", "$", "path", ")", ")", "{", "if", "(", "(", "$", "check_exist", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "\"File '$path' already exists.\"", ")", ";", "}", "}", "// does this folder's parent exist?", "$", "parent", "=", "FileUtilities", "::", "getParentFolder", "(", "$", "path", ")", ";", "if", "(", "!", "empty", "(", "$", "parent", ")", "&&", "(", "!", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "parent", ")", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Folder '$parent' does not exist.\"", ")", ";", "}", "if", "(", "$", "content_is_base", ")", "{", "$", "content", "=", "base64_decode", "(", "$", "content", ")", ";", "}", "$", "result", "=", "$", "this", "->", "adapter", "->", "write", "(", "$", "path", ",", "$", "content", ",", "new", "Config", "(", ")", ")", ";", "if", "(", "false", "===", "$", "result", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Failed to create file.'", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L454-L476
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.moveFile
public function moveFile($container, $path, $local_path, $check_exist = false) { // does local file exist? if (!file_exists($local_path)) { throw new NotFoundException("File '$local_path' does not exist."); } // does this file already exist? if ($this->fileExists($container, $path)) { if (($check_exist)) { throw new BadRequestException("File '$path' already exists."); } } // does this file's parent folder exist? $parent = FileUtilities::getParentFolder($path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } $stream = fopen($local_path, 'rb'); $this->adapter->writeStream($path, $stream, new Config()); fclose($stream); }
php
public function moveFile($container, $path, $local_path, $check_exist = false) { // does local file exist? if (!file_exists($local_path)) { throw new NotFoundException("File '$local_path' does not exist."); } // does this file already exist? if ($this->fileExists($container, $path)) { if (($check_exist)) { throw new BadRequestException("File '$path' already exists."); } } // does this file's parent folder exist? $parent = FileUtilities::getParentFolder($path); if (!empty($parent) && (!$this->folderExists($container, $parent))) { throw new NotFoundException("Folder '$parent' does not exist."); } $stream = fopen($local_path, 'rb'); $this->adapter->writeStream($path, $stream, new Config()); fclose($stream); }
[ "public", "function", "moveFile", "(", "$", "container", ",", "$", "path", ",", "$", "local_path", ",", "$", "check_exist", "=", "false", ")", "{", "// does local file exist?", "if", "(", "!", "file_exists", "(", "$", "local_path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"File '$local_path' does not exist.\"", ")", ";", "}", "// does this file already exist?", "if", "(", "$", "this", "->", "fileExists", "(", "$", "container", ",", "$", "path", ")", ")", "{", "if", "(", "(", "$", "check_exist", ")", ")", "{", "throw", "new", "BadRequestException", "(", "\"File '$path' already exists.\"", ")", ";", "}", "}", "// does this file's parent folder exist?", "$", "parent", "=", "FileUtilities", "::", "getParentFolder", "(", "$", "path", ")", ";", "if", "(", "!", "empty", "(", "$", "parent", ")", "&&", "(", "!", "$", "this", "->", "folderExists", "(", "$", "container", ",", "$", "parent", ")", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"Folder '$parent' does not exist.\"", ")", ";", "}", "$", "stream", "=", "fopen", "(", "$", "local_path", ",", "'rb'", ")", ";", "$", "this", "->", "adapter", "->", "writeStream", "(", "$", "path", ",", "$", "stream", ",", "new", "Config", "(", ")", ")", ";", "fclose", "(", "$", "stream", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L481-L502
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.copyFile
public function copyFile($container, $dest_path, $src_container, $src_path, $check_exist = false) { // does this file already exist? if (!$this->fileExists($src_container, $src_path)) { throw new NotFoundException("File '$src_path' does not exist."); } if ($this->fileExists($container, $dest_path)) { if (($check_exist)) { throw new BadRequestException("File '$dest_path' already exists."); } } if (!$this->adapter->copy($src_path, $dest_path)) { throw new InternalServerErrorException('Failed to copy file from ' . $src_path . ' to ' . $dest_path); } }
php
public function copyFile($container, $dest_path, $src_container, $src_path, $check_exist = false) { // does this file already exist? if (!$this->fileExists($src_container, $src_path)) { throw new NotFoundException("File '$src_path' does not exist."); } if ($this->fileExists($container, $dest_path)) { if (($check_exist)) { throw new BadRequestException("File '$dest_path' already exists."); } } if (!$this->adapter->copy($src_path, $dest_path)) { throw new InternalServerErrorException('Failed to copy file from ' . $src_path . ' to ' . $dest_path); } }
[ "public", "function", "copyFile", "(", "$", "container", ",", "$", "dest_path", ",", "$", "src_container", ",", "$", "src_path", ",", "$", "check_exist", "=", "false", ")", "{", "// does this file already exist?", "if", "(", "!", "$", "this", "->", "fileExists", "(", "$", "src_container", ",", "$", "src_path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"File '$src_path' does not exist.\"", ")", ";", "}", "if", "(", "$", "this", "->", "fileExists", "(", "$", "container", ",", "$", "dest_path", ")", ")", "{", "if", "(", "(", "$", "check_exist", ")", ")", "{", "throw", "new", "BadRequestException", "(", "\"File '$dest_path' already exists.\"", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "adapter", "->", "copy", "(", "$", "src_path", ",", "$", "dest_path", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Failed to copy file from '", ".", "$", "src_path", ".", "' to '", ".", "$", "dest_path", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L507-L521
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.deleteFile
public function deleteFile($container, $path, $noCheck = false) { if (!$noCheck && !$this->fileExists($container, $path)) { throw new NotFoundException("File '$path' was not found."); } if (!$this->adapter->delete($path)) { throw new InternalServerErrorException('Failed to delete file.'); } }
php
public function deleteFile($container, $path, $noCheck = false) { if (!$noCheck && !$this->fileExists($container, $path)) { throw new NotFoundException("File '$path' was not found."); } if (!$this->adapter->delete($path)) { throw new InternalServerErrorException('Failed to delete file.'); } }
[ "public", "function", "deleteFile", "(", "$", "container", ",", "$", "path", ",", "$", "noCheck", "=", "false", ")", "{", "if", "(", "!", "$", "noCheck", "&&", "!", "$", "this", "->", "fileExists", "(", "$", "container", ",", "$", "path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "\"File '$path' was not found.\"", ")", ";", "}", "if", "(", "!", "$", "this", "->", "adapter", "->", "delete", "(", "$", "path", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "'Failed to delete file.'", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L526-L534
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.getFolderAsZip
public function getFolderAsZip($container, $path, $zip = null, $zipFileName = null, $overwrite = false) { $path = rtrim($path, '/'); if (empty($zipFileName)) { $temp = basename($path); if (empty($temp)) { $temp = $container; } $tempDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $zipFileName = $tempDir . $temp . '.zip'; } $needClose = false; if (!isset($zip)) { $needClose = true; $zip = new \ZipArchive(); if (true !== $zip->open($zipFileName, ($overwrite ? \ZipArchive::OVERWRITE : \ZipArchive::CREATE))) { throw new InternalServerErrorException("Can not create zip file for directory '$path'."); } } $this->addTreeToZip($zip, $path); if ($needClose) { $zip->close(); } return $zipFileName; }
php
public function getFolderAsZip($container, $path, $zip = null, $zipFileName = null, $overwrite = false) { $path = rtrim($path, '/'); if (empty($zipFileName)) { $temp = basename($path); if (empty($temp)) { $temp = $container; } $tempDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $zipFileName = $tempDir . $temp . '.zip'; } $needClose = false; if (!isset($zip)) { $needClose = true; $zip = new \ZipArchive(); if (true !== $zip->open($zipFileName, ($overwrite ? \ZipArchive::OVERWRITE : \ZipArchive::CREATE))) { throw new InternalServerErrorException("Can not create zip file for directory '$path'."); } } $this->addTreeToZip($zip, $path); if ($needClose) { $zip->close(); } return $zipFileName; }
[ "public", "function", "getFolderAsZip", "(", "$", "container", ",", "$", "path", ",", "$", "zip", "=", "null", ",", "$", "zipFileName", "=", "null", ",", "$", "overwrite", "=", "false", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "empty", "(", "$", "zipFileName", ")", ")", "{", "$", "temp", "=", "basename", "(", "$", "path", ")", ";", "if", "(", "empty", "(", "$", "temp", ")", ")", "{", "$", "temp", "=", "$", "container", ";", "}", "$", "tempDir", "=", "rtrim", "(", "sys_get_temp_dir", "(", ")", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "zipFileName", "=", "$", "tempDir", ".", "$", "temp", ".", "'.zip'", ";", "}", "$", "needClose", "=", "false", ";", "if", "(", "!", "isset", "(", "$", "zip", ")", ")", "{", "$", "needClose", "=", "true", ";", "$", "zip", "=", "new", "\\", "ZipArchive", "(", ")", ";", "if", "(", "true", "!==", "$", "zip", "->", "open", "(", "$", "zipFileName", ",", "(", "$", "overwrite", "?", "\\", "ZipArchive", "::", "OVERWRITE", ":", "\\", "ZipArchive", "::", "CREATE", ")", ")", ")", "{", "throw", "new", "InternalServerErrorException", "(", "\"Can not create zip file for directory '$path'.\"", ")", ";", "}", "}", "$", "this", "->", "addTreeToZip", "(", "$", "zip", ",", "$", "path", ")", ";", "if", "(", "$", "needClose", ")", "{", "$", "zip", "->", "close", "(", ")", ";", "}", "return", "$", "zipFileName", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L588-L613
dreamfactorysoftware/df-file
src/Components/BaseFlysystem.php
BaseFlysystem.addTreeToZip
public function addTreeToZip($zip, $path) { $path = rtrim($path, '/'); if ($this->folderExists('', $path)) { $files = $this->adapter->listContents($path); if (empty($files)) { $newPath = str_replace(DIRECTORY_SEPARATOR, '/', $path); if (!$zip->addEmptyDir($newPath)) { throw new \Exception("Can not include folder '$newPath' in zip file."); } return; } foreach ($files as $file) { if ($file['type'] === 'dir') { static::addTreeToZip($zip, $file['path']); } elseif ($file['type'] === 'file') { $newPath = str_replace(DIRECTORY_SEPARATOR, '/', $file['path']); $fileObj = $this->adapter->read($newPath); if (!empty($fileObj) && isset($fileObj['contents'])) { if (!$zip->addFromString($file['path'], $fileObj['contents'])) { throw new \Exception("Can not include file '$newPath' in zip file."); } } else { throw new InternalServerErrorException("Could not read file '" . $file . "'"); } } } } }
php
public function addTreeToZip($zip, $path) { $path = rtrim($path, '/'); if ($this->folderExists('', $path)) { $files = $this->adapter->listContents($path); if (empty($files)) { $newPath = str_replace(DIRECTORY_SEPARATOR, '/', $path); if (!$zip->addEmptyDir($newPath)) { throw new \Exception("Can not include folder '$newPath' in zip file."); } return; } foreach ($files as $file) { if ($file['type'] === 'dir') { static::addTreeToZip($zip, $file['path']); } elseif ($file['type'] === 'file') { $newPath = str_replace(DIRECTORY_SEPARATOR, '/', $file['path']); $fileObj = $this->adapter->read($newPath); if (!empty($fileObj) && isset($fileObj['contents'])) { if (!$zip->addFromString($file['path'], $fileObj['contents'])) { throw new \Exception("Can not include file '$newPath' in zip file."); } } else { throw new InternalServerErrorException("Could not read file '" . $file . "'"); } } } } }
[ "public", "function", "addTreeToZip", "(", "$", "zip", ",", "$", "path", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "$", "this", "->", "folderExists", "(", "''", ",", "$", "path", ")", ")", "{", "$", "files", "=", "$", "this", "->", "adapter", "->", "listContents", "(", "$", "path", ")", ";", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "$", "newPath", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "$", "path", ")", ";", "if", "(", "!", "$", "zip", "->", "addEmptyDir", "(", "$", "newPath", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Can not include folder '$newPath' in zip file.\"", ")", ";", "}", "return", ";", "}", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "[", "'type'", "]", "===", "'dir'", ")", "{", "static", "::", "addTreeToZip", "(", "$", "zip", ",", "$", "file", "[", "'path'", "]", ")", ";", "}", "elseif", "(", "$", "file", "[", "'type'", "]", "===", "'file'", ")", "{", "$", "newPath", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "$", "file", "[", "'path'", "]", ")", ";", "$", "fileObj", "=", "$", "this", "->", "adapter", "->", "read", "(", "$", "newPath", ")", ";", "if", "(", "!", "empty", "(", "$", "fileObj", ")", "&&", "isset", "(", "$", "fileObj", "[", "'contents'", "]", ")", ")", "{", "if", "(", "!", "$", "zip", "->", "addFromString", "(", "$", "file", "[", "'path'", "]", ",", "$", "fileObj", "[", "'contents'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Can not include file '$newPath' in zip file.\"", ")", ";", "}", "}", "else", "{", "throw", "new", "InternalServerErrorException", "(", "\"Could not read file '\"", ".", "$", "file", ".", "\"'\"", ")", ";", "}", "}", "}", "}", "}" ]
@param \ZipArchive $zip @param string $path @throws \DreamFactory\Core\Exceptions\InternalServerErrorException @throws \Exception
[ "@param", "\\", "ZipArchive", "$zip", "@param", "string", "$path" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Components/BaseFlysystem.php#L622-L651
periaptio/empress-generator
src/Syntax/RemoveForeignKeysFromTable.php
RemoveForeignKeysFromTable.getItem
protected function getItem($foreignKey) { $name = empty($foreignKey['name']) ? $this->createIndexName($foreignKey['field']) : $foreignKey['name']; return sprintf("\$table->dropForeign('%s');", $name); }
php
protected function getItem($foreignKey) { $name = empty($foreignKey['name']) ? $this->createIndexName($foreignKey['field']) : $foreignKey['name']; return sprintf("\$table->dropForeign('%s');", $name); }
[ "protected", "function", "getItem", "(", "$", "foreignKey", ")", "{", "$", "name", "=", "empty", "(", "$", "foreignKey", "[", "'name'", "]", ")", "?", "$", "this", "->", "createIndexName", "(", "$", "foreignKey", "[", "'field'", "]", ")", ":", "$", "foreignKey", "[", "'name'", "]", ";", "return", "sprintf", "(", "\"\\$table->dropForeign('%s');\"", ",", "$", "name", ")", ";", "}" ]
Return string for dropping a foreign key @param array $foreignKey @return string
[ "Return", "string", "for", "dropping", "a", "foreign", "key" ]
train
https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Syntax/RemoveForeignKeysFromTable.php#L16-L20
localhook/localhook
src/Command/SelfUpdateCommand.php
SelfUpdateCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $updater = new Updater(); $strategy = $updater->getStrategy(); if ($strategy instanceof ShaStrategy) { $strategy->setPharUrl('http://localhook.github.io/localhook/localhook.phar'); $strategy->setVersionUrl('http://localhook.github.io/localhook/localhook.phar.version'); } $result = $updater->update(); if (!$result) { $io = new SymfonyStyle($input, $output); $io->success('No update needed.'); return; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $io->success(sprintf('Updated from %s to %s', $old, $new)); return; }
php
protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $updater = new Updater(); $strategy = $updater->getStrategy(); if ($strategy instanceof ShaStrategy) { $strategy->setPharUrl('http://localhook.github.io/localhook/localhook.phar'); $strategy->setVersionUrl('http://localhook.github.io/localhook/localhook.phar.version'); } $result = $updater->update(); if (!$result) { $io = new SymfonyStyle($input, $output); $io->success('No update needed.'); return; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $io->success(sprintf('Updated from %s to %s', $old, $new)); return; }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "io", "=", "new", "SymfonyStyle", "(", "$", "input", ",", "$", "output", ")", ";", "$", "updater", "=", "new", "Updater", "(", ")", ";", "$", "strategy", "=", "$", "updater", "->", "getStrategy", "(", ")", ";", "if", "(", "$", "strategy", "instanceof", "ShaStrategy", ")", "{", "$", "strategy", "->", "setPharUrl", "(", "'http://localhook.github.io/localhook/localhook.phar'", ")", ";", "$", "strategy", "->", "setVersionUrl", "(", "'http://localhook.github.io/localhook/localhook.phar.version'", ")", ";", "}", "$", "result", "=", "$", "updater", "->", "update", "(", ")", ";", "if", "(", "!", "$", "result", ")", "{", "$", "io", "=", "new", "SymfonyStyle", "(", "$", "input", ",", "$", "output", ")", ";", "$", "io", "->", "success", "(", "'No update needed.'", ")", ";", "return", ";", "}", "$", "new", "=", "$", "updater", "->", "getNewVersion", "(", ")", ";", "$", "old", "=", "$", "updater", "->", "getOldVersion", "(", ")", ";", "$", "io", "->", "success", "(", "sprintf", "(", "'Updated from %s to %s'", ",", "$", "old", ",", "$", "new", ")", ")", ";", "return", ";", "}" ]
@param InputInterface $input @param OutputInterface $output @return void @throws Exception
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/localhook/localhook/blob/f8010a7f06ddd514b224ad70dc62e425125d4feb/src/Command/SelfUpdateCommand.php#L32-L56
phpmob/changmin
src/PhpMob/WidgetBundle/Asset/WidgetAssets.php
WidgetAssets.getContent
private function getContent(array $paths, $type) { $cacheKey = $this->getHashKey($paths); if ($this->cacheItemPool->hasItem($cacheKey)) { return $this->cacheItemPool->getItem($cacheKey)->get(); } $minifier = 'js' === $type ? new JS() : new CSS(); $content = ''; foreach ($paths as $path) { foreach ($this->getFiles($path) as $file) { $file = $this->fileLocator->locate($file); if ($this->isDebug) { $content .= file_get_contents($file); } else { $minifier->add($file); } } } $content = $this->isDebug ? $content : $minifier->minify(); $this->cacheItemPool->save($this->cacheItemPool->getItem($cacheKey)->set($content)); return $content; }
php
private function getContent(array $paths, $type) { $cacheKey = $this->getHashKey($paths); if ($this->cacheItemPool->hasItem($cacheKey)) { return $this->cacheItemPool->getItem($cacheKey)->get(); } $minifier = 'js' === $type ? new JS() : new CSS(); $content = ''; foreach ($paths as $path) { foreach ($this->getFiles($path) as $file) { $file = $this->fileLocator->locate($file); if ($this->isDebug) { $content .= file_get_contents($file); } else { $minifier->add($file); } } } $content = $this->isDebug ? $content : $minifier->minify(); $this->cacheItemPool->save($this->cacheItemPool->getItem($cacheKey)->set($content)); return $content; }
[ "private", "function", "getContent", "(", "array", "$", "paths", ",", "$", "type", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "getHashKey", "(", "$", "paths", ")", ";", "if", "(", "$", "this", "->", "cacheItemPool", "->", "hasItem", "(", "$", "cacheKey", ")", ")", "{", "return", "$", "this", "->", "cacheItemPool", "->", "getItem", "(", "$", "cacheKey", ")", "->", "get", "(", ")", ";", "}", "$", "minifier", "=", "'js'", "===", "$", "type", "?", "new", "JS", "(", ")", ":", "new", "CSS", "(", ")", ";", "$", "content", "=", "''", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "foreach", "(", "$", "this", "->", "getFiles", "(", "$", "path", ")", "as", "$", "file", ")", "{", "$", "file", "=", "$", "this", "->", "fileLocator", "->", "locate", "(", "$", "file", ")", ";", "if", "(", "$", "this", "->", "isDebug", ")", "{", "$", "content", ".=", "file_get_contents", "(", "$", "file", ")", ";", "}", "else", "{", "$", "minifier", "->", "add", "(", "$", "file", ")", ";", "}", "}", "}", "$", "content", "=", "$", "this", "->", "isDebug", "?", "$", "content", ":", "$", "minifier", "->", "minify", "(", ")", ";", "$", "this", "->", "cacheItemPool", "->", "save", "(", "$", "this", "->", "cacheItemPool", "->", "getItem", "(", "$", "cacheKey", ")", "->", "set", "(", "$", "content", ")", ")", ";", "return", "$", "content", ";", "}" ]
@param array $paths @param string $type @return string
[ "@param", "array", "$paths", "@param", "string", "$type" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/WidgetBundle/Asset/WidgetAssets.php#L102-L130
phpmob/changmin
src/PhpMob/WidgetBundle/Asset/WidgetAssets.php
WidgetAssets.getFiles
private function getFiles($path) { $files = []; if (false !== $pos = strpos($path, '*')) { list($before, $after) = explode('*', $path, 2); $input = $this->fileLocator->locate($before).'*'.$after; if (false !== $paths = glob($input)) { foreach ($paths as $path) { $files[] = $path; } } } else { $files = [$this->fileLocator->locate($path)]; } return $files; }
php
private function getFiles($path) { $files = []; if (false !== $pos = strpos($path, '*')) { list($before, $after) = explode('*', $path, 2); $input = $this->fileLocator->locate($before).'*'.$after; if (false !== $paths = glob($input)) { foreach ($paths as $path) { $files[] = $path; } } } else { $files = [$this->fileLocator->locate($path)]; } return $files; }
[ "private", "function", "getFiles", "(", "$", "path", ")", "{", "$", "files", "=", "[", "]", ";", "if", "(", "false", "!==", "$", "pos", "=", "strpos", "(", "$", "path", ",", "'*'", ")", ")", "{", "list", "(", "$", "before", ",", "$", "after", ")", "=", "explode", "(", "'*'", ",", "$", "path", ",", "2", ")", ";", "$", "input", "=", "$", "this", "->", "fileLocator", "->", "locate", "(", "$", "before", ")", ".", "'*'", ".", "$", "after", ";", "if", "(", "false", "!==", "$", "paths", "=", "glob", "(", "$", "input", ")", ")", "{", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "$", "files", "[", "]", "=", "$", "path", ";", "}", "}", "}", "else", "{", "$", "files", "=", "[", "$", "this", "->", "fileLocator", "->", "locate", "(", "$", "path", ")", "]", ";", "}", "return", "$", "files", ";", "}" ]
@param string $path @return array
[ "@param", "string", "$path" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/WidgetBundle/Asset/WidgetAssets.php#L137-L155
ChadSikorra/php-simple-enum
src/Enums/FlagEnumTrait.php
FlagEnumTrait.add
public function add(...$flags) { foreach ($flags as $flag) { if ($this->has($flag)) { continue; } foreach ($this->getValuesFromFlagOrEnum($flag) as $value) { $this->value = $this->value | (int) $value; } } return $this; }
php
public function add(...$flags) { foreach ($flags as $flag) { if ($this->has($flag)) { continue; } foreach ($this->getValuesFromFlagOrEnum($flag) as $value) { $this->value = $this->value | (int) $value; } } return $this; }
[ "public", "function", "add", "(", "...", "$", "flags", ")", "{", "foreach", "(", "$", "flags", "as", "$", "flag", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "flag", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "this", "->", "getValuesFromFlagOrEnum", "(", "$", "flag", ")", "as", "$", "value", ")", "{", "$", "this", "->", "value", "=", "$", "this", "->", "value", "|", "(", "int", ")", "$", "value", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add a flag to the value. @param int[]|string[]|FlagEnumTrait[] ...$flags @return $this
[ "Add", "a", "flag", "to", "the", "value", "." ]
train
https://github.com/ChadSikorra/php-simple-enum/blob/781f87ae9f4cc75fb2edab6517c6471c0181e93b/src/Enums/FlagEnumTrait.php#L42-L54
ChadSikorra/php-simple-enum
src/Enums/FlagEnumTrait.php
FlagEnumTrait.has
public function has($flag) { $values = $this->getValuesFromFlagOrEnum($flag); if (empty($values)) { return false; } foreach ($values as $value) { if (!(bool) ($this->value & $value)) { return false; } } return true; }
php
public function has($flag) { $values = $this->getValuesFromFlagOrEnum($flag); if (empty($values)) { return false; } foreach ($values as $value) { if (!(bool) ($this->value & $value)) { return false; } } return true; }
[ "public", "function", "has", "(", "$", "flag", ")", "{", "$", "values", "=", "$", "this", "->", "getValuesFromFlagOrEnum", "(", "$", "flag", ")", ";", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "!", "(", "bool", ")", "(", "$", "this", "->", "value", "&", "$", "value", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Given an enum name, value, or another FlagEnumTrait instance, check if this instance has the same value(s). @param string|int|FlagEnumTrait $flag @return bool
[ "Given", "an", "enum", "name", "value", "or", "another", "FlagEnumTrait", "instance", "check", "if", "this", "instance", "has", "the", "same", "value", "(", "s", ")", "." ]
train
https://github.com/ChadSikorra/php-simple-enum/blob/781f87ae9f4cc75fb2edab6517c6471c0181e93b/src/Enums/FlagEnumTrait.php#L82-L97
ChadSikorra/php-simple-enum
src/Enums/FlagEnumTrait.php
FlagEnumTrait.getNames
public function getNames() { $enums = []; foreach (static::toArray() as $name => $value) { if ($this->has($value)) { $enums[] = $name; } } return $enums; }
php
public function getNames() { $enums = []; foreach (static::toArray() as $name => $value) { if ($this->has($value)) { $enums[] = $name; } } return $enums; }
[ "public", "function", "getNames", "(", ")", "{", "$", "enums", "=", "[", "]", ";", "foreach", "(", "static", "::", "toArray", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "value", ")", ")", "{", "$", "enums", "[", "]", "=", "$", "name", ";", "}", "}", "return", "$", "enums", ";", "}" ]
Get an array of all the enum names this flag instance represents. @return array
[ "Get", "an", "array", "of", "all", "the", "enum", "names", "this", "flag", "instance", "represents", "." ]
train
https://github.com/ChadSikorra/php-simple-enum/blob/781f87ae9f4cc75fb2edab6517c6471c0181e93b/src/Enums/FlagEnumTrait.php#L104-L115
ChadSikorra/php-simple-enum
src/Enums/FlagEnumTrait.php
FlagEnumTrait.getValuesFromFlagOrEnum
protected function getValuesFromFlagOrEnum($flag) { $values = []; if ($flag instanceof static) { foreach ($flag->getNames() as $enum) { $values[] = static::getNameValue($enum); } } elseif (static::isValidName((string) $flag)) { $values[] = static::getNameValue((string) $flag); } elseif (is_numeric($flag)) { $values[] = $flag; } return $values; }
php
protected function getValuesFromFlagOrEnum($flag) { $values = []; if ($flag instanceof static) { foreach ($flag->getNames() as $enum) { $values[] = static::getNameValue($enum); } } elseif (static::isValidName((string) $flag)) { $values[] = static::getNameValue((string) $flag); } elseif (is_numeric($flag)) { $values[] = $flag; } return $values; }
[ "protected", "function", "getValuesFromFlagOrEnum", "(", "$", "flag", ")", "{", "$", "values", "=", "[", "]", ";", "if", "(", "$", "flag", "instanceof", "static", ")", "{", "foreach", "(", "$", "flag", "->", "getNames", "(", ")", "as", "$", "enum", ")", "{", "$", "values", "[", "]", "=", "static", "::", "getNameValue", "(", "$", "enum", ")", ";", "}", "}", "elseif", "(", "static", "::", "isValidName", "(", "(", "string", ")", "$", "flag", ")", ")", "{", "$", "values", "[", "]", "=", "static", "::", "getNameValue", "(", "(", "string", ")", "$", "flag", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "flag", ")", ")", "{", "$", "values", "[", "]", "=", "$", "flag", ";", "}", "return", "$", "values", ";", "}" ]
Given an enum name, enum value, or flag enum instance, get the array of values it represents. @param int|string|FlagEnumTrait $flag @return array
[ "Given", "an", "enum", "name", "enum", "value", "or", "flag", "enum", "instance", "get", "the", "array", "of", "values", "it", "represents", "." ]
train
https://github.com/ChadSikorra/php-simple-enum/blob/781f87ae9f4cc75fb2edab6517c6471c0181e93b/src/Enums/FlagEnumTrait.php#L133-L148
dms-org/package.blog
src/Cms/BlogAuthorModule.php
BlogAuthorModule.defineCrudModule
protected function defineCrudModule(CrudModuleDefinition $module) { $module->name('authors'); $module->metadata([ 'icon' => 'user', ]); $module->labelObjects()->fromProperty(BlogAuthor::NAME); $module->crudForm(function (CrudFormDefinition $form) { $form->section('Details', [ $form->field( Field::create('name', 'Name')->string()->required() )->bindToProperty(BlogAuthor::NAME), ]); SlugField::build($form, 'slug', 'URL Friendly Name', $this->dataSource, $this->blogConfiguration->getSlugGenerator(), 'name', BlogAuthor::SLUG); $form->continueSection([ $form->field( Field::create('role', 'Role')->string()->defaultTo('') )->bindToProperty(BlogAuthor::ROLE), // $form->field( Field::create('bio', 'Bio')->html()->required() )->bindToProperty(BlogAuthor::BIO), ]); if ($form->isCreateForm()) { $form->onSubmit(function (BlogAuthor $blogAuthor) { $blogAuthor->getMetadata(); $blogAuthor->articles = BlogArticle::collection(); }); } }); $module->removeAction()->deleteFromDataSource(); $module->summaryTable(function (SummaryTableDefinition $table) { $table->mapProperty(BlogAuthor::NAME)->to(Field::create('name', 'Name')->string()); $table->mapProperty(BlogAuthor::ROLE)->to(Field::create('role', 'Role')->string()); $table->view('all', 'All') ->asDefault() ->loadAll(); }); }
php
protected function defineCrudModule(CrudModuleDefinition $module) { $module->name('authors'); $module->metadata([ 'icon' => 'user', ]); $module->labelObjects()->fromProperty(BlogAuthor::NAME); $module->crudForm(function (CrudFormDefinition $form) { $form->section('Details', [ $form->field( Field::create('name', 'Name')->string()->required() )->bindToProperty(BlogAuthor::NAME), ]); SlugField::build($form, 'slug', 'URL Friendly Name', $this->dataSource, $this->blogConfiguration->getSlugGenerator(), 'name', BlogAuthor::SLUG); $form->continueSection([ $form->field( Field::create('role', 'Role')->string()->defaultTo('') )->bindToProperty(BlogAuthor::ROLE), // $form->field( Field::create('bio', 'Bio')->html()->required() )->bindToProperty(BlogAuthor::BIO), ]); if ($form->isCreateForm()) { $form->onSubmit(function (BlogAuthor $blogAuthor) { $blogAuthor->getMetadata(); $blogAuthor->articles = BlogArticle::collection(); }); } }); $module->removeAction()->deleteFromDataSource(); $module->summaryTable(function (SummaryTableDefinition $table) { $table->mapProperty(BlogAuthor::NAME)->to(Field::create('name', 'Name')->string()); $table->mapProperty(BlogAuthor::ROLE)->to(Field::create('role', 'Role')->string()); $table->view('all', 'All') ->asDefault() ->loadAll(); }); }
[ "protected", "function", "defineCrudModule", "(", "CrudModuleDefinition", "$", "module", ")", "{", "$", "module", "->", "name", "(", "'authors'", ")", ";", "$", "module", "->", "metadata", "(", "[", "'icon'", "=>", "'user'", ",", "]", ")", ";", "$", "module", "->", "labelObjects", "(", ")", "->", "fromProperty", "(", "BlogAuthor", "::", "NAME", ")", ";", "$", "module", "->", "crudForm", "(", "function", "(", "CrudFormDefinition", "$", "form", ")", "{", "$", "form", "->", "section", "(", "'Details'", ",", "[", "$", "form", "->", "field", "(", "Field", "::", "create", "(", "'name'", ",", "'Name'", ")", "->", "string", "(", ")", "->", "required", "(", ")", ")", "->", "bindToProperty", "(", "BlogAuthor", "::", "NAME", ")", ",", "]", ")", ";", "SlugField", "::", "build", "(", "$", "form", ",", "'slug'", ",", "'URL Friendly Name'", ",", "$", "this", "->", "dataSource", ",", "$", "this", "->", "blogConfiguration", "->", "getSlugGenerator", "(", ")", ",", "'name'", ",", "BlogAuthor", "::", "SLUG", ")", ";", "$", "form", "->", "continueSection", "(", "[", "$", "form", "->", "field", "(", "Field", "::", "create", "(", "'role'", ",", "'Role'", ")", "->", "string", "(", ")", "->", "defaultTo", "(", "''", ")", ")", "->", "bindToProperty", "(", "BlogAuthor", "::", "ROLE", ")", ",", "//", "$", "form", "->", "field", "(", "Field", "::", "create", "(", "'bio'", ",", "'Bio'", ")", "->", "html", "(", ")", "->", "required", "(", ")", ")", "->", "bindToProperty", "(", "BlogAuthor", "::", "BIO", ")", ",", "]", ")", ";", "if", "(", "$", "form", "->", "isCreateForm", "(", ")", ")", "{", "$", "form", "->", "onSubmit", "(", "function", "(", "BlogAuthor", "$", "blogAuthor", ")", "{", "$", "blogAuthor", "->", "getMetadata", "(", ")", ";", "$", "blogAuthor", "->", "articles", "=", "BlogArticle", "::", "collection", "(", ")", ";", "}", ")", ";", "}", "}", ")", ";", "$", "module", "->", "removeAction", "(", ")", "->", "deleteFromDataSource", "(", ")", ";", "$", "module", "->", "summaryTable", "(", "function", "(", "SummaryTableDefinition", "$", "table", ")", "{", "$", "table", "->", "mapProperty", "(", "BlogAuthor", "::", "NAME", ")", "->", "to", "(", "Field", "::", "create", "(", "'name'", ",", "'Name'", ")", "->", "string", "(", ")", ")", ";", "$", "table", "->", "mapProperty", "(", "BlogAuthor", "::", "ROLE", ")", "->", "to", "(", "Field", "::", "create", "(", "'role'", ",", "'Role'", ")", "->", "string", "(", ")", ")", ";", "$", "table", "->", "view", "(", "'all'", ",", "'All'", ")", "->", "asDefault", "(", ")", "->", "loadAll", "(", ")", ";", "}", ")", ";", "}" ]
Defines the structure of this module. @param CrudModuleDefinition $module
[ "Defines", "the", "structure", "of", "this", "module", "." ]
train
https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Cms/BlogAuthorModule.php#L42-L89
datasift/php_webdriver
src/php/DataSift/WebDriver/WebDriverConfiguration.php
WebDriverConfiguration.getVersion
public function getVersion() { $composer = $this->loadJsonFileFromRoot("composer.json"); if (!isset($composer->version)){ throw new \Exception("composer.json does not contain a version"); } return $composer->version; }
php
public function getVersion() { $composer = $this->loadJsonFileFromRoot("composer.json"); if (!isset($composer->version)){ throw new \Exception("composer.json does not contain a version"); } return $composer->version; }
[ "public", "function", "getVersion", "(", ")", "{", "$", "composer", "=", "$", "this", "->", "loadJsonFileFromRoot", "(", "\"composer.json\"", ")", ";", "if", "(", "!", "isset", "(", "$", "composer", "->", "version", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"composer.json does not contain a version\"", ")", ";", "}", "return", "$", "composer", "->", "version", ";", "}" ]
Returns the project's version @return string The version of the project
[ "Returns", "the", "project", "s", "version" ]
train
https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/WebDriver/WebDriverConfiguration.php#L44-L53
iocaste/microservice-foundation
src/Feature/Auth/MicroserviceUserProvider.php
MicroserviceUserProvider.retrieveById
public function retrieveById($identifier) { $userService = app()->make(UserService::class); $user = $userService->byId($identifier)->get(); if (! $user) { return null; } return $user; }
php
public function retrieveById($identifier) { $userService = app()->make(UserService::class); $user = $userService->byId($identifier)->get(); if (! $user) { return null; } return $user; }
[ "public", "function", "retrieveById", "(", "$", "identifier", ")", "{", "$", "userService", "=", "app", "(", ")", "->", "make", "(", "UserService", "::", "class", ")", ";", "$", "user", "=", "$", "userService", "->", "byId", "(", "$", "identifier", ")", "->", "get", "(", ")", ";", "if", "(", "!", "$", "user", ")", "{", "return", "null", ";", "}", "return", "$", "user", ";", "}" ]
Retrieve a user by their unique identifier. @param mixed $identifier @return \Illuminate\Contracts\Auth\Authenticatable|null
[ "Retrieve", "a", "user", "by", "their", "unique", "identifier", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Auth/MicroserviceUserProvider.php#L20-L30
iocaste/microservice-foundation
src/Feature/Auth/MicroserviceUserProvider.php
MicroserviceUserProvider.retrieveByCredentials
public function retrieveByCredentials(array $credentials) { $userService = app()->make(UserService::class); $user = $userService->byCredentials($credentials)->get(); if (! $user) { return null; } return $user; }
php
public function retrieveByCredentials(array $credentials) { $userService = app()->make(UserService::class); $user = $userService->byCredentials($credentials)->get(); if (! $user) { return null; } return $user; }
[ "public", "function", "retrieveByCredentials", "(", "array", "$", "credentials", ")", "{", "$", "userService", "=", "app", "(", ")", "->", "make", "(", "UserService", "::", "class", ")", ";", "$", "user", "=", "$", "userService", "->", "byCredentials", "(", "$", "credentials", ")", "->", "get", "(", ")", ";", "if", "(", "!", "$", "user", ")", "{", "return", "null", ";", "}", "return", "$", "user", ";", "}" ]
Retrieve a user by the given credentials. @param array $credentials @return \Illuminate\Contracts\Auth\Authenticatable|null
[ "Retrieve", "a", "user", "by", "the", "given", "credentials", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Auth/MicroserviceUserProvider.php#L62-L72
iocaste/microservice-foundation
src/Feature/Auth/MicroserviceUserProvider.php
MicroserviceUserProvider.validateCredentials
public function validateCredentials(Authenticatable $user, array $credentials) { if (! app('hash')->check($credentials['password'], $user->password)) { return false; } return true; }
php
public function validateCredentials(Authenticatable $user, array $credentials) { if (! app('hash')->check($credentials['password'], $user->password)) { return false; } return true; }
[ "public", "function", "validateCredentials", "(", "Authenticatable", "$", "user", ",", "array", "$", "credentials", ")", "{", "if", "(", "!", "app", "(", "'hash'", ")", "->", "check", "(", "$", "credentials", "[", "'password'", "]", ",", "$", "user", "->", "password", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validate a user against the given credentials. @param \Illuminate\Contracts\Auth\Authenticatable $user @param array $credentials @return bool
[ "Validate", "a", "user", "against", "the", "given", "credentials", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Auth/MicroserviceUserProvider.php#L81-L88
phpmob/changmin
src/PhpMob/ChangMinBundle/Form/Type/TaxonType.php
TaxonType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', ResourceTranslationsType::class, [ 'entry_type' => TaxonTranslationType::class, 'label' => 'sylius.form.taxon.name', ]) ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $data = $event->getData(); if (empty($data['translations'])) { return; } foreach ($data['translations'] as &$_data) { if (empty($_data['slug']) && !empty($_data['name'])) { $_data['slug'] = uniqid(); } } $event->setData($data); }) ->addEventSubscriber(new AddCodeFormSubscriber()) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { if (null === $event->getData()) { return; } $event->getForm()->add('parent', TaxonChoiceType::class, [ 'label' => 'sylius.form.taxon.parent', 'required' => false, ]); }) ; }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', ResourceTranslationsType::class, [ 'entry_type' => TaxonTranslationType::class, 'label' => 'sylius.form.taxon.name', ]) ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $data = $event->getData(); if (empty($data['translations'])) { return; } foreach ($data['translations'] as &$_data) { if (empty($_data['slug']) && !empty($_data['name'])) { $_data['slug'] = uniqid(); } } $event->setData($data); }) ->addEventSubscriber(new AddCodeFormSubscriber()) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { if (null === $event->getData()) { return; } $event->getForm()->add('parent', TaxonChoiceType::class, [ 'label' => 'sylius.form.taxon.parent', 'required' => false, ]); }) ; }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "add", "(", "'translations'", ",", "ResourceTranslationsType", "::", "class", ",", "[", "'entry_type'", "=>", "TaxonTranslationType", "::", "class", ",", "'label'", "=>", "'sylius.form.taxon.name'", ",", "]", ")", "->", "addEventListener", "(", "FormEvents", "::", "PRE_SUBMIT", ",", "function", "(", "FormEvent", "$", "event", ")", "{", "$", "data", "=", "$", "event", "->", "getData", "(", ")", ";", "if", "(", "empty", "(", "$", "data", "[", "'translations'", "]", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "data", "[", "'translations'", "]", "as", "&", "$", "_data", ")", "{", "if", "(", "empty", "(", "$", "_data", "[", "'slug'", "]", ")", "&&", "!", "empty", "(", "$", "_data", "[", "'name'", "]", ")", ")", "{", "$", "_data", "[", "'slug'", "]", "=", "uniqid", "(", ")", ";", "}", "}", "$", "event", "->", "setData", "(", "$", "data", ")", ";", "}", ")", "->", "addEventSubscriber", "(", "new", "AddCodeFormSubscriber", "(", ")", ")", "->", "addEventListener", "(", "FormEvents", "::", "PRE_SET_DATA", ",", "function", "(", "FormEvent", "$", "event", ")", "{", "if", "(", "null", "===", "$", "event", "->", "getData", "(", ")", ")", "{", "return", ";", "}", "$", "event", "->", "getForm", "(", ")", "->", "add", "(", "'parent'", ",", "TaxonChoiceType", "::", "class", ",", "[", "'label'", "=>", "'sylius.form.taxon.parent'", ",", "'required'", "=>", "false", ",", "]", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Form/Type/TaxonType.php#L30-L64
datasift/php_webdriver
src/php/DataSift/BrowserMobProxy/BrowserMobProxyBase.php
BrowserMobProxyBase.curl
protected function curl( $http_verb, $path, $payload = null, $curl_opts = array() ) { // determine the URL we are posting to if (substr($this->url, -1, 1) !== '/' && substr($path, 0, 1) !== '/') { $url = $this->url . '/' . $path; } else { $url = $this->url . $path; } // create the curl request $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=UTF-8', 'Accept: application/json' ) ); // handle the different kind of verbs switch($http_verb) { case 'POST': // we are POSTing to the URL curl_setopt($curl, CURLOPT_POST, true); // what are we posting? if ($payload) { if (is_array($payload)) { // posting an array of values curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payload)); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); } else if (is_object($payload)){ // sending over a JSON payload curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($payload)); } else { // we assume that the caller has done this // for themselves curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); } } break; case 'PUT': // we are PUT to the URL curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); // what are we posting? if ($payload) { if (is_array($payload)) { // posting an array of values $fields = http_build_query($payload); curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($fields) )); } else if (is_object($payload)){ // sending over a JSON payload $data = json_encode($payload); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data))); } else { // we assume that the caller has done this // for themselves curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($payload))); } } break; case 'DELETE': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } foreach ($curl_opts as $option => $value) { curl_setopt($curl, $option, $value); } // make the curl request $raw_results = trim(curl_exec($curl)); // find out from curl what happened $info = curl_getinfo($curl); // was there an error? if ($error = curl_error($curl)) { // yes, there was // we throw an exception to explain that the call failed $msg = sprintf( 'Curl error thrown for http %s to %s', $http_verb, $url ); if ($payload && is_array($payload)) { $msg .= sprintf(' with params: %s', json_encode($payload)); } throw new E5xx_BrowserMobProxyCurlException($msg . "\n\n" . $error); } // we're done with curl for this request curl_close($curl); // convert the response from webdriver into something we can work with $results = json_decode($raw_results); // are we working with enhanced replies? if (isset($results->success) && $results->success) { if (isset($results->data)) { return $results->data; } else { return null; } } else if (isset($results->error) && $results->error) { // there was an error? $e = new E5xx_BrowserMobProxyCurlException(json_encode($results->data)); $e->data = $results->data; throw $e; } else { // no, we do not appear to be return $results; } // all done return $results; }
php
protected function curl( $http_verb, $path, $payload = null, $curl_opts = array() ) { // determine the URL we are posting to if (substr($this->url, -1, 1) !== '/' && substr($path, 0, 1) !== '/') { $url = $this->url . '/' . $path; } else { $url = $this->url . $path; } // create the curl request $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=UTF-8', 'Accept: application/json' ) ); // handle the different kind of verbs switch($http_verb) { case 'POST': // we are POSTing to the URL curl_setopt($curl, CURLOPT_POST, true); // what are we posting? if ($payload) { if (is_array($payload)) { // posting an array of values curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payload)); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); } else if (is_object($payload)){ // sending over a JSON payload curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($payload)); } else { // we assume that the caller has done this // for themselves curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); } } break; case 'PUT': // we are PUT to the URL curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); // what are we posting? if ($payload) { if (is_array($payload)) { // posting an array of values $fields = http_build_query($payload); curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($fields) )); } else if (is_object($payload)){ // sending over a JSON payload $data = json_encode($payload); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data))); } else { // we assume that the caller has done this // for themselves curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($payload))); } } break; case 'DELETE': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } foreach ($curl_opts as $option => $value) { curl_setopt($curl, $option, $value); } // make the curl request $raw_results = trim(curl_exec($curl)); // find out from curl what happened $info = curl_getinfo($curl); // was there an error? if ($error = curl_error($curl)) { // yes, there was // we throw an exception to explain that the call failed $msg = sprintf( 'Curl error thrown for http %s to %s', $http_verb, $url ); if ($payload && is_array($payload)) { $msg .= sprintf(' with params: %s', json_encode($payload)); } throw new E5xx_BrowserMobProxyCurlException($msg . "\n\n" . $error); } // we're done with curl for this request curl_close($curl); // convert the response from webdriver into something we can work with $results = json_decode($raw_results); // are we working with enhanced replies? if (isset($results->success) && $results->success) { if (isset($results->data)) { return $results->data; } else { return null; } } else if (isset($results->error) && $results->error) { // there was an error? $e = new E5xx_BrowserMobProxyCurlException(json_encode($results->data)); $e->data = $results->data; throw $e; } else { // no, we do not appear to be return $results; } // all done return $results; }
[ "protected", "function", "curl", "(", "$", "http_verb", ",", "$", "path", ",", "$", "payload", "=", "null", ",", "$", "curl_opts", "=", "array", "(", ")", ")", "{", "// determine the URL we are posting to", "if", "(", "substr", "(", "$", "this", "->", "url", ",", "-", "1", ",", "1", ")", "!==", "'/'", "&&", "substr", "(", "$", "path", ",", "0", ",", "1", ")", "!==", "'/'", ")", "{", "$", "url", "=", "$", "this", "->", "url", ".", "'/'", ".", "$", "path", ";", "}", "else", "{", "$", "url", "=", "$", "this", "->", "url", ".", "$", "path", ";", "}", "// create the curl request", "$", "curl", "=", "curl_init", "(", "$", "url", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "'Content-Type: application/json;charset=UTF-8'", ",", "'Accept: application/json'", ")", ")", ";", "// handle the different kind of verbs", "switch", "(", "$", "http_verb", ")", "{", "case", "'POST'", ":", "// we are POSTing to the URL", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POST", ",", "true", ")", ";", "// what are we posting?", "if", "(", "$", "payload", ")", "{", "if", "(", "is_array", "(", "$", "payload", ")", ")", "{", "// posting an array of values", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "http_build_query", "(", "$", "payload", ")", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "'Content-Type: application/x-www-form-urlencoded'", ")", ")", ";", "}", "else", "if", "(", "is_object", "(", "$", "payload", ")", ")", "{", "// sending over a JSON payload", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "json_encode", "(", "$", "payload", ")", ")", ";", "}", "else", "{", "// we assume that the caller has done this", "// for themselves", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "payload", ")", ";", "}", "}", "break", ";", "case", "'PUT'", ":", "// we are PUT to the URL", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_CUSTOMREQUEST", ",", "'PUT'", ")", ";", "// what are we posting?", "if", "(", "$", "payload", ")", "{", "if", "(", "is_array", "(", "$", "payload", ")", ")", "{", "// posting an array of values", "$", "fields", "=", "http_build_query", "(", "$", "payload", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "fields", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "'Content-Type: application/x-www-form-urlencoded'", ",", "'Content-Length: '", ".", "strlen", "(", "$", "fields", ")", ")", ")", ";", "}", "else", "if", "(", "is_object", "(", "$", "payload", ")", ")", "{", "// sending over a JSON payload", "$", "data", "=", "json_encode", "(", "$", "payload", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "data", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "'Content-Length: '", ".", "strlen", "(", "$", "data", ")", ")", ")", ";", "}", "else", "{", "// we assume that the caller has done this", "// for themselves", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "payload", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "'Content-Length: '", ".", "strlen", "(", "$", "payload", ")", ")", ")", ";", "}", "}", "break", ";", "case", "'DELETE'", ":", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_CUSTOMREQUEST", ",", "'DELETE'", ")", ";", "break", ";", "}", "foreach", "(", "$", "curl_opts", "as", "$", "option", "=>", "$", "value", ")", "{", "curl_setopt", "(", "$", "curl", ",", "$", "option", ",", "$", "value", ")", ";", "}", "// make the curl request", "$", "raw_results", "=", "trim", "(", "curl_exec", "(", "$", "curl", ")", ")", ";", "// find out from curl what happened", "$", "info", "=", "curl_getinfo", "(", "$", "curl", ")", ";", "// was there an error?", "if", "(", "$", "error", "=", "curl_error", "(", "$", "curl", ")", ")", "{", "// yes, there was", "// we throw an exception to explain that the call failed", "$", "msg", "=", "sprintf", "(", "'Curl error thrown for http %s to %s'", ",", "$", "http_verb", ",", "$", "url", ")", ";", "if", "(", "$", "payload", "&&", "is_array", "(", "$", "payload", ")", ")", "{", "$", "msg", ".=", "sprintf", "(", "' with params: %s'", ",", "json_encode", "(", "$", "payload", ")", ")", ";", "}", "throw", "new", "E5xx_BrowserMobProxyCurlException", "(", "$", "msg", ".", "\"\\n\\n\"", ".", "$", "error", ")", ";", "}", "// we're done with curl for this request", "curl_close", "(", "$", "curl", ")", ";", "// convert the response from webdriver into something we can work with", "$", "results", "=", "json_decode", "(", "$", "raw_results", ")", ";", "// are we working with enhanced replies?", "if", "(", "isset", "(", "$", "results", "->", "success", ")", "&&", "$", "results", "->", "success", ")", "{", "if", "(", "isset", "(", "$", "results", "->", "data", ")", ")", "{", "return", "$", "results", "->", "data", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "results", "->", "error", ")", "&&", "$", "results", "->", "error", ")", "{", "// there was an error?", "$", "e", "=", "new", "E5xx_BrowserMobProxyCurlException", "(", "json_encode", "(", "$", "results", "->", "data", ")", ")", ";", "$", "e", "->", "data", "=", "$", "results", "->", "data", ";", "throw", "$", "e", ";", "}", "else", "{", "// no, we do not appear to be", "return", "$", "results", ";", "}", "// all done", "return", "$", "results", ";", "}" ]
Curl request to browsermob-proxy server. @var string $http_verb 'GET', 'POST', 'DELETE', or 'PUT' @var string $path the URL to connect to (appended to $this->getUrl()) @var mixed $payload the parameters to send; an array is sent as POSTFIELDS, anything else is sent as raw body @var array $curl_opts any additional options to set in curl
[ "Curl", "request", "to", "browsermob", "-", "proxy", "server", "." ]
train
https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/BrowserMobProxy/BrowserMobProxyBase.php#L96-L238
nyeholt/silverstripe-external-content
thirdparty/Zend/Validate/Db/Abstract.php
Zend_Validate_Db_Abstract._query
protected function _query($value) { /** * Check for an adapter being defined. if not, fetch the default adapter. */ if($this->_adapter === null) { $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); } /** * Build select object */ $select = new Zend_Db_Select($this->_adapter); $select->from($this->_table) ->columns($this->_field) ->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value); if ($this->_exclude !== null) { if (is_array($this->_exclude)) { $select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).' != ?', $this->_exclude['value']); } else { $select->where($this->_exclude); } } $select->limit(1); /** * Run query */ $result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC); return $result; }
php
protected function _query($value) { /** * Check for an adapter being defined. if not, fetch the default adapter. */ if($this->_adapter === null) { $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); } /** * Build select object */ $select = new Zend_Db_Select($this->_adapter); $select->from($this->_table) ->columns($this->_field) ->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value); if ($this->_exclude !== null) { if (is_array($this->_exclude)) { $select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).' != ?', $this->_exclude['value']); } else { $select->where($this->_exclude); } } $select->limit(1); /** * Run query */ $result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC); return $result; }
[ "protected", "function", "_query", "(", "$", "value", ")", "{", "/**\n * Check for an adapter being defined. if not, fetch the default adapter.\n */", "if", "(", "$", "this", "->", "_adapter", "===", "null", ")", "{", "$", "this", "->", "_adapter", "=", "Zend_Db_Table_Abstract", "::", "getDefaultAdapter", "(", ")", ";", "}", "/**\n * Build select object\n */", "$", "select", "=", "new", "Zend_Db_Select", "(", "$", "this", "->", "_adapter", ")", ";", "$", "select", "->", "from", "(", "$", "this", "->", "_table", ")", "->", "columns", "(", "$", "this", "->", "_field", ")", "->", "where", "(", "$", "this", "->", "_adapter", "->", "quoteIdentifier", "(", "$", "this", "->", "_field", ")", ".", "' = ?'", ",", "$", "value", ")", ";", "if", "(", "$", "this", "->", "_exclude", "!==", "null", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_exclude", ")", ")", "{", "$", "select", "->", "where", "(", "$", "this", "->", "_adapter", "->", "quoteIdentifier", "(", "$", "this", "->", "_exclude", "[", "'field'", "]", ")", ".", "' != ?'", ",", "$", "this", "->", "_exclude", "[", "'value'", "]", ")", ";", "}", "else", "{", "$", "select", "->", "where", "(", "$", "this", "->", "_exclude", ")", ";", "}", "}", "$", "select", "->", "limit", "(", "1", ")", ";", "/**\n * Run query\n */", "$", "result", "=", "$", "this", "->", "_adapter", "->", "fetchRow", "(", "$", "select", ",", "array", "(", ")", ",", "Zend_Db", "::", "FETCH_ASSOC", ")", ";", "return", "$", "result", ";", "}" ]
Run query and returns matches, or null if no matches are found. @param String $value @return Array when matches are found.
[ "Run", "query", "and", "returns", "matches", "or", "null", "if", "no", "matches", "are", "found", "." ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Validate/Db/Abstract.php#L101-L132
askupasoftware/amarkal
Extensions/WordPress/Widget/UI/Textarea/controller.php
Textarea.set_error_message
public function set_error_message( $message ) { $this->template->error = true; $this->template->error_message = $message; }
php
public function set_error_message( $message ) { $this->template->error = true; $this->template->error_message = $message; }
[ "public", "function", "set_error_message", "(", "$", "message", ")", "{", "$", "this", "->", "template", "->", "error", "=", "true", ";", "$", "this", "->", "template", "->", "error_message", "=", "$", "message", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/Widget/UI/Textarea/controller.php#L97-L100
qcubed/orm
src/Query/Node/NoParentBase.php
NoParentBase.setAlias
public function setAlias($strAlias) { if ($this->strFullAlias) { throw new \Exception ("You cannot set an alias on a node after you have used it in a query. See the examples doc. You must set the alias while creating the node."); } try { // Changing the alias of the node. Must change pointers to the node too. $strNewAlias = Type::cast($strAlias, Type::STRING); $this->strAlias = $strNewAlias; } catch (Caller $objExc) { $objExc->incrementOffset(); throw $objExc; } }
php
public function setAlias($strAlias) { if ($this->strFullAlias) { throw new \Exception ("You cannot set an alias on a node after you have used it in a query. See the examples doc. You must set the alias while creating the node."); } try { // Changing the alias of the node. Must change pointers to the node too. $strNewAlias = Type::cast($strAlias, Type::STRING); $this->strAlias = $strNewAlias; } catch (Caller $objExc) { $objExc->incrementOffset(); throw $objExc; } }
[ "public", "function", "setAlias", "(", "$", "strAlias", ")", "{", "if", "(", "$", "this", "->", "strFullAlias", ")", "{", "throw", "new", "\\", "Exception", "(", "\"You cannot set an alias on a node after you have used it in a query. See the examples doc. You must set the alias while creating the node.\"", ")", ";", "}", "try", "{", "// Changing the alias of the node. Must change pointers to the node too.", "$", "strNewAlias", "=", "Type", "::", "cast", "(", "$", "strAlias", ",", "Type", "::", "STRING", ")", ";", "$", "this", "->", "strAlias", "=", "$", "strNewAlias", ";", "}", "catch", "(", "Caller", "$", "objExc", ")", "{", "$", "objExc", "->", "incrementOffset", "(", ")", ";", "throw", "$", "objExc", ";", "}", "}" ]
Change the alias of the node, primarily for joining the same table more than once. @param $strAlias @throws Caller @throws \Exception
[ "Change", "the", "alias", "of", "the", "node", "primarily", "for", "joining", "the", "same", "table", "more", "than", "once", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/NoParentBase.php#L38-L51
qcubed/orm
src/Query/Node/NoParentBase.php
NoParentBase.fullAlias
public function fullAlias() { if ($this->strFullAlias) { return $this->strFullAlias; } else { assert(!empty($this->strAlias)); // Alias should always be set by default return $this->strAlias; } }
php
public function fullAlias() { if ($this->strFullAlias) { return $this->strFullAlias; } else { assert(!empty($this->strAlias)); // Alias should always be set by default return $this->strAlias; } }
[ "public", "function", "fullAlias", "(", ")", "{", "if", "(", "$", "this", "->", "strFullAlias", ")", "{", "return", "$", "this", "->", "strFullAlias", ";", "}", "else", "{", "assert", "(", "!", "empty", "(", "$", "this", "->", "strAlias", ")", ")", ";", "// Alias should always be set by default", "return", "$", "this", "->", "strAlias", ";", "}", "}" ]
Aid to generating full aliases. Recursively gets and sets the parent alias, eventually creating, caching and returning an alias for itself. @return string
[ "Aid", "to", "generating", "full", "aliases", ".", "Recursively", "gets", "and", "sets", "the", "parent", "alias", "eventually", "creating", "caching", "and", "returning", "an", "alias", "for", "itself", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/NoParentBase.php#L58-L66
datasift/php_webdriver
src/php/DataSift/BrowserMobProxy/BrowserMobProxySession.php
BrowserMobProxySession.getWebDriverProxyConfig
public function getWebDriverProxyConfig() { $this->requireOpenConnection(); $address = new HttpAddress($this->getUrl()); return array ( 'proxyType' => 'manual', 'httpProxy' => $address->hostname . ':' . $this->getPort(), 'sslProxy' => $address->hostname . ':' . $this->getPort() ); }
php
public function getWebDriverProxyConfig() { $this->requireOpenConnection(); $address = new HttpAddress($this->getUrl()); return array ( 'proxyType' => 'manual', 'httpProxy' => $address->hostname . ':' . $this->getPort(), 'sslProxy' => $address->hostname . ':' . $this->getPort() ); }
[ "public", "function", "getWebDriverProxyConfig", "(", ")", "{", "$", "this", "->", "requireOpenConnection", "(", ")", ";", "$", "address", "=", "new", "HttpAddress", "(", "$", "this", "->", "getUrl", "(", ")", ")", ";", "return", "array", "(", "'proxyType'", "=>", "'manual'", ",", "'httpProxy'", "=>", "$", "address", "->", "hostname", ".", "':'", ".", "$", "this", "->", "getPort", "(", ")", ",", "'sslProxy'", "=>", "$", "address", "->", "hostname", ".", "':'", ".", "$", "this", "->", "getPort", "(", ")", ")", ";", "}" ]
Returns the config information that needs to be given to webdriver to make it use browsermob-proxy @return array
[ "Returns", "the", "config", "information", "that", "needs", "to", "be", "given", "to", "webdriver", "to", "make", "it", "use", "browsermob", "-", "proxy" ]
train
https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/BrowserMobProxy/BrowserMobProxySession.php#L86-L97
datasift/php_webdriver
src/php/DataSift/BrowserMobProxy/BrowserMobProxySession.php
BrowserMobProxySession.startHAR
public function startHAR($logName = 'default') { $this->requireOpenConnection(); $response = $this->curl( 'PUT', '/proxy/' . $this->port . '/har', array('initialPageRef' => $logName) ); }
php
public function startHAR($logName = 'default') { $this->requireOpenConnection(); $response = $this->curl( 'PUT', '/proxy/' . $this->port . '/har', array('initialPageRef' => $logName) ); }
[ "public", "function", "startHAR", "(", "$", "logName", "=", "'default'", ")", "{", "$", "this", "->", "requireOpenConnection", "(", ")", ";", "$", "response", "=", "$", "this", "->", "curl", "(", "'PUT'", ",", "'/proxy/'", ".", "$", "this", "->", "port", ".", "'/har'", ",", "array", "(", "'initialPageRef'", "=>", "$", "logName", ")", ")", ";", "}" ]
Start logging into a HTTP Archive (HAR) @param string $logName the name of the archive to use @return void
[ "Start", "logging", "into", "a", "HTTP", "Archive", "(", "HAR", ")" ]
train
https://github.com/datasift/php_webdriver/blob/efca991198616b53c8f40b59ad05306e2b10e7f0/src/php/DataSift/BrowserMobProxy/BrowserMobProxySession.php#L105-L114