repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
appzcoder/laravel-admin | src/Setting.php | Setting.get | public function get($key)
{
$setting = SettingModel::where('key', $key)->first();
return $setting ? $setting->value : false;
} | php | public function get($key)
{
$setting = SettingModel::where('key', $key)->first();
return $setting ? $setting->value : false;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"setting",
"=",
"SettingModel",
"::",
"where",
"(",
"'key'",
",",
"$",
"key",
")",
"->",
"first",
"(",
")",
";",
"return",
"$",
"setting",
"?",
"$",
"setting",
"->",
"value",
":",
"false",
";",
"}"
]
| Get value by a key.
@param string $key
@return mixed | [
"Get",
"value",
"by",
"a",
"key",
"."
]
| 70fcbbd82a267b5bbd462e23945dbcf13cab43b2 | https://github.com/appzcoder/laravel-admin/blob/70fcbbd82a267b5bbd462e23945dbcf13cab43b2/src/Setting.php#L37-L42 | train |
bshaffer/oauth2-server-php | src/OAuth2/Storage/CouchbaseDB.php | CouchbaseDB.deleteObjectByType | protected function deleteObjectByType($name,$id)
{
$this->db->delete($this->config[$name].'-'.$id,"",1);
} | php | protected function deleteObjectByType($name,$id)
{
$this->db->delete($this->config[$name].'-'.$id,"",1);
} | [
"protected",
"function",
"deleteObjectByType",
"(",
"$",
"name",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"delete",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"name",
"]",
".",
"'-'",
".",
"$",
"id",
",",
"\"\"",
",",
"1",
")",
";",
"}"
]
| Helper function to delete couchbase item by type, wait for persist to at least 1 node | [
"Helper",
"function",
"to",
"delete",
"couchbase",
"item",
"by",
"type",
"wait",
"for",
"persist",
"to",
"at",
"least",
"1",
"node"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Storage/CouchbaseDB.php#L65-L68 | train |
bshaffer/oauth2-server-php | src/OAuth2/Server.php | Server.handleAuthorizeRequest | public function handleAuthorizeRequest(RequestInterface $request, ResponseInterface $response, $is_authorized, $user_id = null)
{
$this->response = $response;
$this->getAuthorizeController()->handleAuthorizeRequest($request, $this->response, $is_authorized, $user_id);
return $this->response;
} | php | public function handleAuthorizeRequest(RequestInterface $request, ResponseInterface $response, $is_authorized, $user_id = null)
{
$this->response = $response;
$this->getAuthorizeController()->handleAuthorizeRequest($request, $this->response, $is_authorized, $user_id);
return $this->response;
} | [
"public",
"function",
"handleAuthorizeRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"is_authorized",
",",
"$",
"user_id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"$",
"this",
"->",
"getAuthorizeController",
"(",
")",
"->",
"handleAuthorizeRequest",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"response",
",",
"$",
"is_authorized",
",",
"$",
"user_id",
")",
";",
"return",
"$",
"this",
"->",
"response",
";",
"}"
]
| Redirect the user appropriately after approval.
After the user has approved or denied the resource request the
authorization server should call this function to redirect the user
appropriately.
@param RequestInterface $request - The request should have the follow parameters set in the querystring:
- response_type: The requested response: an access token, an authorization code, or both.
- client_id: The client identifier as described in Section 2.
- redirect_uri: An absolute URI to which the authorization server will redirect the user-agent to when the
end-user authorization step is completed.
- scope: (optional) The scope of the resource request expressed as a list of space-delimited strings.
- state: (optional) An opaque value used by the client to maintain state between the request and callback.
@param ResponseInterface $response - Response object
@param bool $is_authorized - TRUE or FALSE depending on whether the user authorized the access.
@param mixed $user_id - Identifier of user who authorized the client
@return ResponseInterface
@see http://tools.ietf.org/html/rfc6749#section-4
@ingroup oauth2_section_4 | [
"Redirect",
"the",
"user",
"appropriately",
"after",
"approval",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Server.php#L380-L386 | train |
bshaffer/oauth2-server-php | src/OAuth2/Server.php | Server.addStorage | public function addStorage($storage, $key = null)
{
// if explicitly set to a valid key, do not "magically" set below
if (isset($this->storageMap[$key])) {
if (!is_null($storage) && !$storage instanceof $this->storageMap[$key]) {
throw new \InvalidArgumentException(sprintf('storage of type "%s" must implement interface "%s"', $key, $this->storageMap[$key]));
}
$this->storages[$key] = $storage;
// special logic to handle "client" and "client_credentials" strangeness
if ($key === 'client' && !isset($this->storages['client_credentials'])) {
if ($storage instanceof ClientCredentialsInterface) {
$this->storages['client_credentials'] = $storage;
}
} elseif ($key === 'client_credentials' && !isset($this->storages['client'])) {
if ($storage instanceof ClientInterface) {
$this->storages['client'] = $storage;
}
}
} elseif (!is_null($key) && !is_numeric($key)) {
throw new \InvalidArgumentException(sprintf('unknown storage key "%s", must be one of [%s]', $key, implode(', ', array_keys($this->storageMap))));
} else {
$set = false;
foreach ($this->storageMap as $type => $interface) {
if ($storage instanceof $interface) {
$this->storages[$type] = $storage;
$set = true;
}
}
if (!$set) {
throw new \InvalidArgumentException(sprintf('storage of class "%s" must implement one of [%s]', get_class($storage), implode(', ', $this->storageMap)));
}
}
} | php | public function addStorage($storage, $key = null)
{
// if explicitly set to a valid key, do not "magically" set below
if (isset($this->storageMap[$key])) {
if (!is_null($storage) && !$storage instanceof $this->storageMap[$key]) {
throw new \InvalidArgumentException(sprintf('storage of type "%s" must implement interface "%s"', $key, $this->storageMap[$key]));
}
$this->storages[$key] = $storage;
// special logic to handle "client" and "client_credentials" strangeness
if ($key === 'client' && !isset($this->storages['client_credentials'])) {
if ($storage instanceof ClientCredentialsInterface) {
$this->storages['client_credentials'] = $storage;
}
} elseif ($key === 'client_credentials' && !isset($this->storages['client'])) {
if ($storage instanceof ClientInterface) {
$this->storages['client'] = $storage;
}
}
} elseif (!is_null($key) && !is_numeric($key)) {
throw new \InvalidArgumentException(sprintf('unknown storage key "%s", must be one of [%s]', $key, implode(', ', array_keys($this->storageMap))));
} else {
$set = false;
foreach ($this->storageMap as $type => $interface) {
if ($storage instanceof $interface) {
$this->storages[$type] = $storage;
$set = true;
}
}
if (!$set) {
throw new \InvalidArgumentException(sprintf('storage of class "%s" must implement one of [%s]', get_class($storage), implode(', ', $this->storageMap)));
}
}
} | [
"public",
"function",
"addStorage",
"(",
"$",
"storage",
",",
"$",
"key",
"=",
"null",
")",
"{",
"// if explicitly set to a valid key, do not \"magically\" set below",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storageMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"storage",
")",
"&&",
"!",
"$",
"storage",
"instanceof",
"$",
"this",
"->",
"storageMap",
"[",
"$",
"key",
"]",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'storage of type \"%s\" must implement interface \"%s\"'",
",",
"$",
"key",
",",
"$",
"this",
"->",
"storageMap",
"[",
"$",
"key",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"storages",
"[",
"$",
"key",
"]",
"=",
"$",
"storage",
";",
"// special logic to handle \"client\" and \"client_credentials\" strangeness",
"if",
"(",
"$",
"key",
"===",
"'client'",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'client_credentials'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"storage",
"instanceof",
"ClientCredentialsInterface",
")",
"{",
"$",
"this",
"->",
"storages",
"[",
"'client_credentials'",
"]",
"=",
"$",
"storage",
";",
"}",
"}",
"elseif",
"(",
"$",
"key",
"===",
"'client_credentials'",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'client'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"storage",
"instanceof",
"ClientInterface",
")",
"{",
"$",
"this",
"->",
"storages",
"[",
"'client'",
"]",
"=",
"$",
"storage",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'unknown storage key \"%s\", must be one of [%s]'",
",",
"$",
"key",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"storageMap",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"set",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"storageMap",
"as",
"$",
"type",
"=>",
"$",
"interface",
")",
"{",
"if",
"(",
"$",
"storage",
"instanceof",
"$",
"interface",
")",
"{",
"$",
"this",
"->",
"storages",
"[",
"$",
"type",
"]",
"=",
"$",
"storage",
";",
"$",
"set",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"set",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'storage of class \"%s\" must implement one of [%s]'",
",",
"get_class",
"(",
"$",
"storage",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"storageMap",
")",
")",
")",
";",
"}",
"}",
"}"
]
| Set a storage object for the server
@param object $storage - An object implementing one of the Storage interfaces
@param mixed $key - If null, the storage is set to the key of each storage interface it implements
@throws InvalidArgumentException
@see storageMap | [
"Set",
"a",
"storage",
"object",
"for",
"the",
"server"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Server.php#L472-L506 | train |
bshaffer/oauth2-server-php | src/OAuth2/Server.php | Server.createDefaultJwtAccessTokenStorage | protected function createDefaultJwtAccessTokenStorage()
{
if (!isset($this->storages['public_key'])) {
throw new \LogicException('You must supply a storage object implementing OAuth2\Storage\PublicKeyInterface to use crypto tokens');
}
$tokenStorage = null;
if (!empty($this->config['store_encrypted_token_string']) && isset($this->storages['access_token'])) {
$tokenStorage = $this->storages['access_token'];
}
// wrap the access token storage as required.
return new JwtAccessTokenStorage($this->storages['public_key'], $tokenStorage);
} | php | protected function createDefaultJwtAccessTokenStorage()
{
if (!isset($this->storages['public_key'])) {
throw new \LogicException('You must supply a storage object implementing OAuth2\Storage\PublicKeyInterface to use crypto tokens');
}
$tokenStorage = null;
if (!empty($this->config['store_encrypted_token_string']) && isset($this->storages['access_token'])) {
$tokenStorage = $this->storages['access_token'];
}
// wrap the access token storage as required.
return new JwtAccessTokenStorage($this->storages['public_key'], $tokenStorage);
} | [
"protected",
"function",
"createDefaultJwtAccessTokenStorage",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'public_key'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'You must supply a storage object implementing OAuth2\\Storage\\PublicKeyInterface to use crypto tokens'",
")",
";",
"}",
"$",
"tokenStorage",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'store_encrypted_token_string'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'access_token'",
"]",
")",
")",
"{",
"$",
"tokenStorage",
"=",
"$",
"this",
"->",
"storages",
"[",
"'access_token'",
"]",
";",
"}",
"// wrap the access token storage as required.",
"return",
"new",
"JwtAccessTokenStorage",
"(",
"$",
"this",
"->",
"storages",
"[",
"'public_key'",
"]",
",",
"$",
"tokenStorage",
")",
";",
"}"
]
| For Resource Controller
@return JwtAccessTokenStorage
@throws LogicException | [
"For",
"Resource",
"Controller"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Server.php#L809-L820 | train |
bshaffer/oauth2-server-php | src/OAuth2/Server.php | Server.createDefaultJwtAccessTokenResponseType | protected function createDefaultJwtAccessTokenResponseType()
{
if (!isset($this->storages['public_key'])) {
throw new \LogicException('You must supply a storage object implementing OAuth2\Storage\PublicKeyInterface to use crypto tokens');
}
$tokenStorage = null;
if (isset($this->storages['access_token'])) {
$tokenStorage = $this->storages['access_token'];
}
$refreshStorage = null;
if (isset($this->storages['refresh_token'])) {
$refreshStorage = $this->storages['refresh_token'];
}
$config = array_intersect_key($this->config, array_flip(explode(' ', 'store_encrypted_token_string issuer access_lifetime refresh_token_lifetime jwt_extra_payload_callable')));
return new JwtAccessToken($this->storages['public_key'], $tokenStorage, $refreshStorage, $config);
} | php | protected function createDefaultJwtAccessTokenResponseType()
{
if (!isset($this->storages['public_key'])) {
throw new \LogicException('You must supply a storage object implementing OAuth2\Storage\PublicKeyInterface to use crypto tokens');
}
$tokenStorage = null;
if (isset($this->storages['access_token'])) {
$tokenStorage = $this->storages['access_token'];
}
$refreshStorage = null;
if (isset($this->storages['refresh_token'])) {
$refreshStorage = $this->storages['refresh_token'];
}
$config = array_intersect_key($this->config, array_flip(explode(' ', 'store_encrypted_token_string issuer access_lifetime refresh_token_lifetime jwt_extra_payload_callable')));
return new JwtAccessToken($this->storages['public_key'], $tokenStorage, $refreshStorage, $config);
} | [
"protected",
"function",
"createDefaultJwtAccessTokenResponseType",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'public_key'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'You must supply a storage object implementing OAuth2\\Storage\\PublicKeyInterface to use crypto tokens'",
")",
";",
"}",
"$",
"tokenStorage",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'access_token'",
"]",
")",
")",
"{",
"$",
"tokenStorage",
"=",
"$",
"this",
"->",
"storages",
"[",
"'access_token'",
"]",
";",
"}",
"$",
"refreshStorage",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storages",
"[",
"'refresh_token'",
"]",
")",
")",
"{",
"$",
"refreshStorage",
"=",
"$",
"this",
"->",
"storages",
"[",
"'refresh_token'",
"]",
";",
"}",
"$",
"config",
"=",
"array_intersect_key",
"(",
"$",
"this",
"->",
"config",
",",
"array_flip",
"(",
"explode",
"(",
"' '",
",",
"'store_encrypted_token_string issuer access_lifetime refresh_token_lifetime jwt_extra_payload_callable'",
")",
")",
")",
";",
"return",
"new",
"JwtAccessToken",
"(",
"$",
"this",
"->",
"storages",
"[",
"'public_key'",
"]",
",",
"$",
"tokenStorage",
",",
"$",
"refreshStorage",
",",
"$",
"config",
")",
";",
"}"
]
| For Authorize and Token Controllers
@return JwtAccessToken
@throws LogicException | [
"For",
"Authorize",
"and",
"Token",
"Controllers"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Server.php#L828-L847 | train |
bshaffer/oauth2-server-php | src/OAuth2/Storage/DynamoDB.php | DynamoDB.dynamo2array | private function dynamo2array($dynamodbResult)
{
$result = array();
foreach ($dynamodbResult["Item"] as $key => $val) {
$result[$key] = $val["S"];
$result[] = $val["S"];
}
return $result;
} | php | private function dynamo2array($dynamodbResult)
{
$result = array();
foreach ($dynamodbResult["Item"] as $key => $val) {
$result[$key] = $val["S"];
$result[] = $val["S"];
}
return $result;
} | [
"private",
"function",
"dynamo2array",
"(",
"$",
"dynamodbResult",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dynamodbResult",
"[",
"\"Item\"",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
"[",
"\"S\"",
"]",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"val",
"[",
"\"S\"",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Transform dynamodb resultset to an array.
@param $dynamodbResult
@return $array | [
"Transform",
"dynamodb",
"resultset",
"to",
"an",
"array",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Storage/DynamoDB.php#L525-L534 | train |
bshaffer/oauth2-server-php | src/OAuth2/ClientAssertionType/HttpBasic.php | HttpBasic.getClientCredentials | public function getClientCredentials(RequestInterface $request, ResponseInterface $response = null)
{
if (!is_null($request->headers('PHP_AUTH_USER')) && !is_null($request->headers('PHP_AUTH_PW'))) {
return array('client_id' => $request->headers('PHP_AUTH_USER'), 'client_secret' => $request->headers('PHP_AUTH_PW'));
}
if ($this->config['allow_credentials_in_request_body']) {
// Using POST for HttpBasic authorization is not recommended, but is supported by specification
if (!is_null($request->request('client_id'))) {
/**
* client_secret can be null if the client's password is an empty string
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
*/
return array('client_id' => $request->request('client_id'), 'client_secret' => $request->request('client_secret'));
}
}
if ($response) {
$message = $this->config['allow_credentials_in_request_body'] ? ' or body' : '';
$response->setError(400, 'invalid_client', 'Client credentials were not found in the headers'.$message);
}
return null;
} | php | public function getClientCredentials(RequestInterface $request, ResponseInterface $response = null)
{
if (!is_null($request->headers('PHP_AUTH_USER')) && !is_null($request->headers('PHP_AUTH_PW'))) {
return array('client_id' => $request->headers('PHP_AUTH_USER'), 'client_secret' => $request->headers('PHP_AUTH_PW'));
}
if ($this->config['allow_credentials_in_request_body']) {
// Using POST for HttpBasic authorization is not recommended, but is supported by specification
if (!is_null($request->request('client_id'))) {
/**
* client_secret can be null if the client's password is an empty string
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
*/
return array('client_id' => $request->request('client_id'), 'client_secret' => $request->request('client_secret'));
}
}
if ($response) {
$message = $this->config['allow_credentials_in_request_body'] ? ' or body' : '';
$response->setError(400, 'invalid_client', 'Client credentials were not found in the headers'.$message);
}
return null;
} | [
"public",
"function",
"getClientCredentials",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"request",
"->",
"headers",
"(",
"'PHP_AUTH_USER'",
")",
")",
"&&",
"!",
"is_null",
"(",
"$",
"request",
"->",
"headers",
"(",
"'PHP_AUTH_PW'",
")",
")",
")",
"{",
"return",
"array",
"(",
"'client_id'",
"=>",
"$",
"request",
"->",
"headers",
"(",
"'PHP_AUTH_USER'",
")",
",",
"'client_secret'",
"=>",
"$",
"request",
"->",
"headers",
"(",
"'PHP_AUTH_PW'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'allow_credentials_in_request_body'",
"]",
")",
"{",
"// Using POST for HttpBasic authorization is not recommended, but is supported by specification",
"if",
"(",
"!",
"is_null",
"(",
"$",
"request",
"->",
"request",
"(",
"'client_id'",
")",
")",
")",
"{",
"/**\n * client_secret can be null if the client's password is an empty string\n * @see http://tools.ietf.org/html/rfc6749#section-2.3.1\n */",
"return",
"array",
"(",
"'client_id'",
"=>",
"$",
"request",
"->",
"request",
"(",
"'client_id'",
")",
",",
"'client_secret'",
"=>",
"$",
"request",
"->",
"request",
"(",
"'client_secret'",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"response",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"config",
"[",
"'allow_credentials_in_request_body'",
"]",
"?",
"' or body'",
":",
"''",
";",
"$",
"response",
"->",
"setError",
"(",
"400",
",",
"'invalid_client'",
",",
"'Client credentials were not found in the headers'",
".",
"$",
"message",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Internal function used to get the client credentials from HTTP basic
auth or POST data.
According to the spec (draft 20), the client_id can be provided in
the Basic Authorization header (recommended) or via GET/POST.
@param RequestInterface $request
@param ResponseInterface $response
@return array|null A list containing the client identifier and password, for example:
@code
return array(
"client_id" => CLIENT_ID, // REQUIRED the client id
"client_secret" => CLIENT_SECRET, // OPTIONAL the client secret (may be omitted for public clients)
);
@endcode
@see http://tools.ietf.org/html/rfc6749#section-2.3.1
@ingroup oauth2_section_2 | [
"Internal",
"function",
"used",
"to",
"get",
"the",
"client",
"credentials",
"from",
"HTTP",
"basic",
"auth",
"or",
"POST",
"data",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/ClientAssertionType/HttpBasic.php#L115-L138 | train |
bshaffer/oauth2-server-php | src/OAuth2/ResponseType/AccessToken.php | AccessToken.getAuthorizeResponse | public function getAuthorizeResponse($params, $user_id = null)
{
// build the URL to redirect to
$result = array('query' => array());
$params += array('scope' => null, 'state' => null);
/*
* a refresh token MUST NOT be included in the fragment
*
* @see http://tools.ietf.org/html/rfc6749#section-4.2.2
*/
$includeRefreshToken = false;
$result["fragment"] = $this->createAccessToken($params['client_id'], $user_id, $params['scope'], $includeRefreshToken);
if (isset($params['state'])) {
$result["fragment"]["state"] = $params['state'];
}
return array($params['redirect_uri'], $result);
} | php | public function getAuthorizeResponse($params, $user_id = null)
{
// build the URL to redirect to
$result = array('query' => array());
$params += array('scope' => null, 'state' => null);
/*
* a refresh token MUST NOT be included in the fragment
*
* @see http://tools.ietf.org/html/rfc6749#section-4.2.2
*/
$includeRefreshToken = false;
$result["fragment"] = $this->createAccessToken($params['client_id'], $user_id, $params['scope'], $includeRefreshToken);
if (isset($params['state'])) {
$result["fragment"]["state"] = $params['state'];
}
return array($params['redirect_uri'], $result);
} | [
"public",
"function",
"getAuthorizeResponse",
"(",
"$",
"params",
",",
"$",
"user_id",
"=",
"null",
")",
"{",
"// build the URL to redirect to",
"$",
"result",
"=",
"array",
"(",
"'query'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"params",
"+=",
"array",
"(",
"'scope'",
"=>",
"null",
",",
"'state'",
"=>",
"null",
")",
";",
"/*\n * a refresh token MUST NOT be included in the fragment\n *\n * @see http://tools.ietf.org/html/rfc6749#section-4.2.2\n */",
"$",
"includeRefreshToken",
"=",
"false",
";",
"$",
"result",
"[",
"\"fragment\"",
"]",
"=",
"$",
"this",
"->",
"createAccessToken",
"(",
"$",
"params",
"[",
"'client_id'",
"]",
",",
"$",
"user_id",
",",
"$",
"params",
"[",
"'scope'",
"]",
",",
"$",
"includeRefreshToken",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'state'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"\"fragment\"",
"]",
"[",
"\"state\"",
"]",
"=",
"$",
"params",
"[",
"'state'",
"]",
";",
"}",
"return",
"array",
"(",
"$",
"params",
"[",
"'redirect_uri'",
"]",
",",
"$",
"result",
")",
";",
"}"
]
| Get authorize response
@param array $params
@param mixed $user_id
@return array | [
"Get",
"authorize",
"response"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/ResponseType/AccessToken.php#L60-L80 | train |
bshaffer/oauth2-server-php | src/OAuth2/Storage/JwtAccessToken.php | JwtAccessToken.convertJwtToOAuth2 | protected function convertJwtToOAuth2($tokenData)
{
$keyMapping = array(
'aud' => 'client_id',
'exp' => 'expires',
'sub' => 'user_id'
);
foreach ($keyMapping as $jwtKey => $oauth2Key) {
if (isset($tokenData[$jwtKey])) {
$tokenData[$oauth2Key] = $tokenData[$jwtKey];
unset($tokenData[$jwtKey]);
}
}
return $tokenData;
} | php | protected function convertJwtToOAuth2($tokenData)
{
$keyMapping = array(
'aud' => 'client_id',
'exp' => 'expires',
'sub' => 'user_id'
);
foreach ($keyMapping as $jwtKey => $oauth2Key) {
if (isset($tokenData[$jwtKey])) {
$tokenData[$oauth2Key] = $tokenData[$jwtKey];
unset($tokenData[$jwtKey]);
}
}
return $tokenData;
} | [
"protected",
"function",
"convertJwtToOAuth2",
"(",
"$",
"tokenData",
")",
"{",
"$",
"keyMapping",
"=",
"array",
"(",
"'aud'",
"=>",
"'client_id'",
",",
"'exp'",
"=>",
"'expires'",
",",
"'sub'",
"=>",
"'user_id'",
")",
";",
"foreach",
"(",
"$",
"keyMapping",
"as",
"$",
"jwtKey",
"=>",
"$",
"oauth2Key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tokenData",
"[",
"$",
"jwtKey",
"]",
")",
")",
"{",
"$",
"tokenData",
"[",
"$",
"oauth2Key",
"]",
"=",
"$",
"tokenData",
"[",
"$",
"jwtKey",
"]",
";",
"unset",
"(",
"$",
"tokenData",
"[",
"$",
"jwtKey",
"]",
")",
";",
"}",
"}",
"return",
"$",
"tokenData",
";",
"}"
]
| converts a JWT access token into an OAuth2-friendly format | [
"converts",
"a",
"JWT",
"access",
"token",
"into",
"an",
"OAuth2",
"-",
"friendly",
"format"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Storage/JwtAccessToken.php#L70-L86 | train |
bshaffer/oauth2-server-php | src/OAuth2/OpenID/Controller/AuthorizeController.php | AuthorizeController.getValidResponseTypes | protected function getValidResponseTypes()
{
return array(
self::RESPONSE_TYPE_ACCESS_TOKEN,
self::RESPONSE_TYPE_AUTHORIZATION_CODE,
self::RESPONSE_TYPE_ID_TOKEN,
self::RESPONSE_TYPE_ID_TOKEN_TOKEN,
self::RESPONSE_TYPE_CODE_ID_TOKEN,
);
} | php | protected function getValidResponseTypes()
{
return array(
self::RESPONSE_TYPE_ACCESS_TOKEN,
self::RESPONSE_TYPE_AUTHORIZATION_CODE,
self::RESPONSE_TYPE_ID_TOKEN,
self::RESPONSE_TYPE_ID_TOKEN_TOKEN,
self::RESPONSE_TYPE_CODE_ID_TOKEN,
);
} | [
"protected",
"function",
"getValidResponseTypes",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"RESPONSE_TYPE_ACCESS_TOKEN",
",",
"self",
"::",
"RESPONSE_TYPE_AUTHORIZATION_CODE",
",",
"self",
"::",
"RESPONSE_TYPE_ID_TOKEN",
",",
"self",
"::",
"RESPONSE_TYPE_ID_TOKEN_TOKEN",
",",
"self",
"::",
"RESPONSE_TYPE_CODE_ID_TOKEN",
",",
")",
";",
"}"
]
| Array of valid response types
@return array | [
"Array",
"of",
"valid",
"response",
"types"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/OpenID/Controller/AuthorizeController.php#L101-L110 | train |
bshaffer/oauth2-server-php | src/OAuth2/ResponseType/JwtAccessToken.php | JwtAccessToken.createPayload | protected function createPayload($client_id, $user_id, $scope = null)
{
// token to encrypt
$expires = time() + $this->config['access_lifetime'];
$id = $this->generateAccessToken();
$payload = array(
'id' => $id, // for BC (see #591)
'jti' => $id,
'iss' => $this->config['issuer'],
'aud' => $client_id,
'sub' => $user_id,
'exp' => $expires,
'iat' => time(),
'token_type' => $this->config['token_type'],
'scope' => $scope
);
if (isset($this->config['jwt_extra_payload_callable'])) {
if (!is_callable($this->config['jwt_extra_payload_callable'])) {
throw new \InvalidArgumentException('jwt_extra_payload_callable is not callable');
}
$extra = call_user_func($this->config['jwt_extra_payload_callable'], $client_id, $user_id, $scope);
if (!is_array($extra)) {
throw new \InvalidArgumentException('jwt_extra_payload_callable must return array');
}
$payload = array_merge($extra, $payload);
}
return $payload;
} | php | protected function createPayload($client_id, $user_id, $scope = null)
{
// token to encrypt
$expires = time() + $this->config['access_lifetime'];
$id = $this->generateAccessToken();
$payload = array(
'id' => $id, // for BC (see #591)
'jti' => $id,
'iss' => $this->config['issuer'],
'aud' => $client_id,
'sub' => $user_id,
'exp' => $expires,
'iat' => time(),
'token_type' => $this->config['token_type'],
'scope' => $scope
);
if (isset($this->config['jwt_extra_payload_callable'])) {
if (!is_callable($this->config['jwt_extra_payload_callable'])) {
throw new \InvalidArgumentException('jwt_extra_payload_callable is not callable');
}
$extra = call_user_func($this->config['jwt_extra_payload_callable'], $client_id, $user_id, $scope);
if (!is_array($extra)) {
throw new \InvalidArgumentException('jwt_extra_payload_callable must return array');
}
$payload = array_merge($extra, $payload);
}
return $payload;
} | [
"protected",
"function",
"createPayload",
"(",
"$",
"client_id",
",",
"$",
"user_id",
",",
"$",
"scope",
"=",
"null",
")",
"{",
"// token to encrypt",
"$",
"expires",
"=",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"[",
"'access_lifetime'",
"]",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"generateAccessToken",
"(",
")",
";",
"$",
"payload",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"// for BC (see #591)",
"'jti'",
"=>",
"$",
"id",
",",
"'iss'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'issuer'",
"]",
",",
"'aud'",
"=>",
"$",
"client_id",
",",
"'sub'",
"=>",
"$",
"user_id",
",",
"'exp'",
"=>",
"$",
"expires",
",",
"'iat'",
"=>",
"time",
"(",
")",
",",
"'token_type'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'token_type'",
"]",
",",
"'scope'",
"=>",
"$",
"scope",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'jwt_extra_payload_callable'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"this",
"->",
"config",
"[",
"'jwt_extra_payload_callable'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'jwt_extra_payload_callable is not callable'",
")",
";",
"}",
"$",
"extra",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"config",
"[",
"'jwt_extra_payload_callable'",
"]",
",",
"$",
"client_id",
",",
"$",
"user_id",
",",
"$",
"scope",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extra",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'jwt_extra_payload_callable must return array'",
")",
";",
"}",
"$",
"payload",
"=",
"array_merge",
"(",
"$",
"extra",
",",
"$",
"payload",
")",
";",
"}",
"return",
"$",
"payload",
";",
"}"
]
| This function can be used to create custom JWT payloads
@param mixed $client_id - Client identifier related to the access token.
@param mixed $user_id - User ID associated with the access token
@param string $scope - (optional) Scopes to be stored in space-separated string.
@return array - The access token | [
"This",
"function",
"can",
"be",
"used",
"to",
"create",
"custom",
"JWT",
"payloads"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/ResponseType/JwtAccessToken.php#L125-L158 | train |
bshaffer/oauth2-server-php | src/OAuth2/OpenID/Controller/UserInfoController.php | UserInfoController.handleUserInfoRequest | public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response)
{
if (!$this->verifyResourceRequest($request, $response, 'openid')) {
return;
}
$token = $this->getToken();
$claims = $this->userClaimsStorage->getUserClaims($token['user_id'], $token['scope']);
// The sub Claim MUST always be returned in the UserInfo Response.
// http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
$claims += array(
'sub' => $token['user_id'],
);
$response->addParameters($claims);
} | php | public function handleUserInfoRequest(RequestInterface $request, ResponseInterface $response)
{
if (!$this->verifyResourceRequest($request, $response, 'openid')) {
return;
}
$token = $this->getToken();
$claims = $this->userClaimsStorage->getUserClaims($token['user_id'], $token['scope']);
// The sub Claim MUST always be returned in the UserInfo Response.
// http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
$claims += array(
'sub' => $token['user_id'],
);
$response->addParameters($claims);
} | [
"public",
"function",
"handleUserInfoRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"verifyResourceRequest",
"(",
"$",
"request",
",",
"$",
"response",
",",
"'openid'",
")",
")",
"{",
"return",
";",
"}",
"$",
"token",
"=",
"$",
"this",
"->",
"getToken",
"(",
")",
";",
"$",
"claims",
"=",
"$",
"this",
"->",
"userClaimsStorage",
"->",
"getUserClaims",
"(",
"$",
"token",
"[",
"'user_id'",
"]",
",",
"$",
"token",
"[",
"'scope'",
"]",
")",
";",
"// The sub Claim MUST always be returned in the UserInfo Response.",
"// http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse",
"$",
"claims",
"+=",
"array",
"(",
"'sub'",
"=>",
"$",
"token",
"[",
"'user_id'",
"]",
",",
")",
";",
"$",
"response",
"->",
"addParameters",
"(",
"$",
"claims",
")",
";",
"}"
]
| Handle the user info request
@param RequestInterface $request
@param ResponseInterface $response
@return void | [
"Handle",
"the",
"user",
"info",
"request"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/OpenID/Controller/UserInfoController.php#L47-L61 | train |
bshaffer/oauth2-server-php | src/OAuth2/Controller/AuthorizeController.php | AuthorizeController.handleAuthorizeRequest | public function handleAuthorizeRequest(RequestInterface $request, ResponseInterface $response, $is_authorized, $user_id = null)
{
if (!is_bool($is_authorized)) {
throw new InvalidArgumentException('Argument "is_authorized" must be a boolean. This method must know if the user has granted access to the client.');
}
// We repeat this, because we need to re-validate. The request could be POSTed
// by a 3rd-party (because we are not internally enforcing NONCEs, etc)
if (!$this->validateAuthorizeRequest($request, $response)) {
return;
}
// If no redirect_uri is passed in the request, use client's registered one
if (empty($this->redirect_uri)) {
$clientData = $this->clientStorage->getClientDetails($this->client_id);
$registered_redirect_uri = $clientData['redirect_uri'];
}
// the user declined access to the client's application
if ($is_authorized === false) {
$redirect_uri = $this->redirect_uri ?: $registered_redirect_uri;
$this->setNotAuthorizedResponse($request, $response, $redirect_uri, $user_id);
return;
}
// build the parameters to set in the redirect URI
if (!$params = $this->buildAuthorizeParameters($request, $response, $user_id)) {
return;
}
$authResult = $this->responseTypes[$this->response_type]->getAuthorizeResponse($params, $user_id);
list($redirect_uri, $uri_params) = $authResult;
if (empty($redirect_uri) && !empty($registered_redirect_uri)) {
$redirect_uri = $registered_redirect_uri;
}
$uri = $this->buildUri($redirect_uri, $uri_params);
// return redirect response
$response->setRedirect($this->config['redirect_status_code'], $uri);
} | php | public function handleAuthorizeRequest(RequestInterface $request, ResponseInterface $response, $is_authorized, $user_id = null)
{
if (!is_bool($is_authorized)) {
throw new InvalidArgumentException('Argument "is_authorized" must be a boolean. This method must know if the user has granted access to the client.');
}
// We repeat this, because we need to re-validate. The request could be POSTed
// by a 3rd-party (because we are not internally enforcing NONCEs, etc)
if (!$this->validateAuthorizeRequest($request, $response)) {
return;
}
// If no redirect_uri is passed in the request, use client's registered one
if (empty($this->redirect_uri)) {
$clientData = $this->clientStorage->getClientDetails($this->client_id);
$registered_redirect_uri = $clientData['redirect_uri'];
}
// the user declined access to the client's application
if ($is_authorized === false) {
$redirect_uri = $this->redirect_uri ?: $registered_redirect_uri;
$this->setNotAuthorizedResponse($request, $response, $redirect_uri, $user_id);
return;
}
// build the parameters to set in the redirect URI
if (!$params = $this->buildAuthorizeParameters($request, $response, $user_id)) {
return;
}
$authResult = $this->responseTypes[$this->response_type]->getAuthorizeResponse($params, $user_id);
list($redirect_uri, $uri_params) = $authResult;
if (empty($redirect_uri) && !empty($registered_redirect_uri)) {
$redirect_uri = $registered_redirect_uri;
}
$uri = $this->buildUri($redirect_uri, $uri_params);
// return redirect response
$response->setRedirect($this->config['redirect_status_code'], $uri);
} | [
"public",
"function",
"handleAuthorizeRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"is_authorized",
",",
"$",
"user_id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"is_authorized",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Argument \"is_authorized\" must be a boolean. This method must know if the user has granted access to the client.'",
")",
";",
"}",
"// We repeat this, because we need to re-validate. The request could be POSTed",
"// by a 3rd-party (because we are not internally enforcing NONCEs, etc)",
"if",
"(",
"!",
"$",
"this",
"->",
"validateAuthorizeRequest",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"{",
"return",
";",
"}",
"// If no redirect_uri is passed in the request, use client's registered one",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"redirect_uri",
")",
")",
"{",
"$",
"clientData",
"=",
"$",
"this",
"->",
"clientStorage",
"->",
"getClientDetails",
"(",
"$",
"this",
"->",
"client_id",
")",
";",
"$",
"registered_redirect_uri",
"=",
"$",
"clientData",
"[",
"'redirect_uri'",
"]",
";",
"}",
"// the user declined access to the client's application",
"if",
"(",
"$",
"is_authorized",
"===",
"false",
")",
"{",
"$",
"redirect_uri",
"=",
"$",
"this",
"->",
"redirect_uri",
"?",
":",
"$",
"registered_redirect_uri",
";",
"$",
"this",
"->",
"setNotAuthorizedResponse",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"redirect_uri",
",",
"$",
"user_id",
")",
";",
"return",
";",
"}",
"// build the parameters to set in the redirect URI",
"if",
"(",
"!",
"$",
"params",
"=",
"$",
"this",
"->",
"buildAuthorizeParameters",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"user_id",
")",
")",
"{",
"return",
";",
"}",
"$",
"authResult",
"=",
"$",
"this",
"->",
"responseTypes",
"[",
"$",
"this",
"->",
"response_type",
"]",
"->",
"getAuthorizeResponse",
"(",
"$",
"params",
",",
"$",
"user_id",
")",
";",
"list",
"(",
"$",
"redirect_uri",
",",
"$",
"uri_params",
")",
"=",
"$",
"authResult",
";",
"if",
"(",
"empty",
"(",
"$",
"redirect_uri",
")",
"&&",
"!",
"empty",
"(",
"$",
"registered_redirect_uri",
")",
")",
"{",
"$",
"redirect_uri",
"=",
"$",
"registered_redirect_uri",
";",
"}",
"$",
"uri",
"=",
"$",
"this",
"->",
"buildUri",
"(",
"$",
"redirect_uri",
",",
"$",
"uri_params",
")",
";",
"// return redirect response",
"$",
"response",
"->",
"setRedirect",
"(",
"$",
"this",
"->",
"config",
"[",
"'redirect_status_code'",
"]",
",",
"$",
"uri",
")",
";",
"}"
]
| Handle the authorization request
@param RequestInterface $request
@param ResponseInterface $response
@param boolean $is_authorized
@param mixed $user_id
@return mixed|void
@throws InvalidArgumentException | [
"Handle",
"the",
"authorization",
"request"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Controller/AuthorizeController.php#L108-L151 | train |
bshaffer/oauth2-server-php | src/OAuth2/Controller/ResourceController.php | ResourceController.verifyResourceRequest | public function verifyResourceRequest(RequestInterface $request, ResponseInterface $response, $scope = null)
{
$token = $this->getAccessTokenData($request, $response);
// Check if we have token data
if (is_null($token)) {
return false;
}
/**
* Check scope, if provided
* If token doesn't have a scope, it's null/empty, or it's insufficient, then throw 403
* @see http://tools.ietf.org/html/rfc6750#section-3.1
*/
if ($scope && (!isset($token["scope"]) || !$token["scope"] || !$this->scopeUtil->checkScope($scope, $token["scope"]))) {
$response->setError(403, 'insufficient_scope', 'The request requires higher privileges than provided by the access token');
$response->addHttpHeaders(array(
'WWW-Authenticate' => sprintf('%s realm="%s", scope="%s", error="%s", error_description="%s"',
$this->tokenType->getTokenType(),
$this->config['www_realm'],
$scope,
$response->getParameter('error'),
$response->getParameter('error_description')
)
));
return false;
}
// allow retrieval of the token
$this->token = $token;
return (bool) $token;
} | php | public function verifyResourceRequest(RequestInterface $request, ResponseInterface $response, $scope = null)
{
$token = $this->getAccessTokenData($request, $response);
// Check if we have token data
if (is_null($token)) {
return false;
}
/**
* Check scope, if provided
* If token doesn't have a scope, it's null/empty, or it's insufficient, then throw 403
* @see http://tools.ietf.org/html/rfc6750#section-3.1
*/
if ($scope && (!isset($token["scope"]) || !$token["scope"] || !$this->scopeUtil->checkScope($scope, $token["scope"]))) {
$response->setError(403, 'insufficient_scope', 'The request requires higher privileges than provided by the access token');
$response->addHttpHeaders(array(
'WWW-Authenticate' => sprintf('%s realm="%s", scope="%s", error="%s", error_description="%s"',
$this->tokenType->getTokenType(),
$this->config['www_realm'],
$scope,
$response->getParameter('error'),
$response->getParameter('error_description')
)
));
return false;
}
// allow retrieval of the token
$this->token = $token;
return (bool) $token;
} | [
"public",
"function",
"verifyResourceRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"scope",
"=",
"null",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getAccessTokenData",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"// Check if we have token data",
"if",
"(",
"is_null",
"(",
"$",
"token",
")",
")",
"{",
"return",
"false",
";",
"}",
"/**\n * Check scope, if provided\n * If token doesn't have a scope, it's null/empty, or it's insufficient, then throw 403\n * @see http://tools.ietf.org/html/rfc6750#section-3.1\n */",
"if",
"(",
"$",
"scope",
"&&",
"(",
"!",
"isset",
"(",
"$",
"token",
"[",
"\"scope\"",
"]",
")",
"||",
"!",
"$",
"token",
"[",
"\"scope\"",
"]",
"||",
"!",
"$",
"this",
"->",
"scopeUtil",
"->",
"checkScope",
"(",
"$",
"scope",
",",
"$",
"token",
"[",
"\"scope\"",
"]",
")",
")",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"403",
",",
"'insufficient_scope'",
",",
"'The request requires higher privileges than provided by the access token'",
")",
";",
"$",
"response",
"->",
"addHttpHeaders",
"(",
"array",
"(",
"'WWW-Authenticate'",
"=>",
"sprintf",
"(",
"'%s realm=\"%s\", scope=\"%s\", error=\"%s\", error_description=\"%s\"'",
",",
"$",
"this",
"->",
"tokenType",
"->",
"getTokenType",
"(",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'www_realm'",
"]",
",",
"$",
"scope",
",",
"$",
"response",
"->",
"getParameter",
"(",
"'error'",
")",
",",
"$",
"response",
"->",
"getParameter",
"(",
"'error_description'",
")",
")",
")",
")",
";",
"return",
"false",
";",
"}",
"// allow retrieval of the token",
"$",
"this",
"->",
"token",
"=",
"$",
"token",
";",
"return",
"(",
"bool",
")",
"$",
"token",
";",
"}"
]
| Verify the resource request
@param RequestInterface $request
@param ResponseInterface $response
@param null $scope
@return bool | [
"Verify",
"the",
"resource",
"request"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Controller/ResourceController.php#L73-L106 | train |
bshaffer/oauth2-server-php | src/OAuth2/Controller/ResourceController.php | ResourceController.getAccessTokenData | public function getAccessTokenData(RequestInterface $request, ResponseInterface $response)
{
// Get the token parameter
if ($token_param = $this->tokenType->getAccessTokenParameter($request, $response)) {
// Get the stored token data (from the implementing subclass)
// Check we have a well formed token
// Check token expiration (expires is a mandatory paramter)
if (!$token = $this->tokenStorage->getAccessToken($token_param)) {
$response->setError(401, 'invalid_token', 'The access token provided is invalid');
} elseif (!isset($token["expires"]) || !isset($token["client_id"])) {
$response->setError(401, 'malformed_token', 'Malformed token (missing "expires")');
} elseif (time() > $token["expires"]) {
$response->setError(401, 'invalid_token', 'The access token provided has expired');
} else {
return $token;
}
}
$authHeader = sprintf('%s realm="%s"', $this->tokenType->getTokenType(), $this->config['www_realm']);
if ($error = $response->getParameter('error')) {
$authHeader = sprintf('%s, error="%s"', $authHeader, $error);
if ($error_description = $response->getParameter('error_description')) {
$authHeader = sprintf('%s, error_description="%s"', $authHeader, $error_description);
}
}
$response->addHttpHeaders(array('WWW-Authenticate' => $authHeader));
return null;
} | php | public function getAccessTokenData(RequestInterface $request, ResponseInterface $response)
{
// Get the token parameter
if ($token_param = $this->tokenType->getAccessTokenParameter($request, $response)) {
// Get the stored token data (from the implementing subclass)
// Check we have a well formed token
// Check token expiration (expires is a mandatory paramter)
if (!$token = $this->tokenStorage->getAccessToken($token_param)) {
$response->setError(401, 'invalid_token', 'The access token provided is invalid');
} elseif (!isset($token["expires"]) || !isset($token["client_id"])) {
$response->setError(401, 'malformed_token', 'Malformed token (missing "expires")');
} elseif (time() > $token["expires"]) {
$response->setError(401, 'invalid_token', 'The access token provided has expired');
} else {
return $token;
}
}
$authHeader = sprintf('%s realm="%s"', $this->tokenType->getTokenType(), $this->config['www_realm']);
if ($error = $response->getParameter('error')) {
$authHeader = sprintf('%s, error="%s"', $authHeader, $error);
if ($error_description = $response->getParameter('error_description')) {
$authHeader = sprintf('%s, error_description="%s"', $authHeader, $error_description);
}
}
$response->addHttpHeaders(array('WWW-Authenticate' => $authHeader));
return null;
} | [
"public",
"function",
"getAccessTokenData",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"// Get the token parameter",
"if",
"(",
"$",
"token_param",
"=",
"$",
"this",
"->",
"tokenType",
"->",
"getAccessTokenParameter",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"{",
"// Get the stored token data (from the implementing subclass)",
"// Check we have a well formed token",
"// Check token expiration (expires is a mandatory paramter)",
"if",
"(",
"!",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getAccessToken",
"(",
"$",
"token_param",
")",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"401",
",",
"'invalid_token'",
",",
"'The access token provided is invalid'",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"token",
"[",
"\"expires\"",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"token",
"[",
"\"client_id\"",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"401",
",",
"'malformed_token'",
",",
"'Malformed token (missing \"expires\")'",
")",
";",
"}",
"elseif",
"(",
"time",
"(",
")",
">",
"$",
"token",
"[",
"\"expires\"",
"]",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"401",
",",
"'invalid_token'",
",",
"'The access token provided has expired'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"token",
";",
"}",
"}",
"$",
"authHeader",
"=",
"sprintf",
"(",
"'%s realm=\"%s\"'",
",",
"$",
"this",
"->",
"tokenType",
"->",
"getTokenType",
"(",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'www_realm'",
"]",
")",
";",
"if",
"(",
"$",
"error",
"=",
"$",
"response",
"->",
"getParameter",
"(",
"'error'",
")",
")",
"{",
"$",
"authHeader",
"=",
"sprintf",
"(",
"'%s, error=\"%s\"'",
",",
"$",
"authHeader",
",",
"$",
"error",
")",
";",
"if",
"(",
"$",
"error_description",
"=",
"$",
"response",
"->",
"getParameter",
"(",
"'error_description'",
")",
")",
"{",
"$",
"authHeader",
"=",
"sprintf",
"(",
"'%s, error_description=\"%s\"'",
",",
"$",
"authHeader",
",",
"$",
"error_description",
")",
";",
"}",
"}",
"$",
"response",
"->",
"addHttpHeaders",
"(",
"array",
"(",
"'WWW-Authenticate'",
"=>",
"$",
"authHeader",
")",
")",
";",
"return",
"null",
";",
"}"
]
| Get access token data.
@param RequestInterface $request
@param ResponseInterface $response
@return array|null | [
"Get",
"access",
"token",
"data",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Controller/ResourceController.php#L115-L145 | train |
bshaffer/oauth2-server-php | src/OAuth2/Controller/TokenController.php | TokenController.addGrantType | public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
{
if (is_null($identifier) || is_numeric($identifier)) {
$identifier = $grantType->getQueryStringIdentifier();
}
$this->grantTypes[$identifier] = $grantType;
} | php | public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
{
if (is_null($identifier) || is_numeric($identifier)) {
$identifier = $grantType->getQueryStringIdentifier();
}
$this->grantTypes[$identifier] = $grantType;
} | [
"public",
"function",
"addGrantType",
"(",
"GrantTypeInterface",
"$",
"grantType",
",",
"$",
"identifier",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"identifier",
")",
"||",
"is_numeric",
"(",
"$",
"identifier",
")",
")",
"{",
"$",
"identifier",
"=",
"$",
"grantType",
"->",
"getQueryStringIdentifier",
"(",
")",
";",
"}",
"$",
"this",
"->",
"grantTypes",
"[",
"$",
"identifier",
"]",
"=",
"$",
"grantType",
";",
"}"
]
| Add grant type
@param GrantTypeInterface $grantType - the grant type to add for the specified identifier
@param string|null $identifier - a string passed in as "grant_type" in the response that will call this grantType | [
"Add",
"grant",
"type"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Controller/TokenController.php#L260-L267 | train |
bshaffer/oauth2-server-php | src/OAuth2/Controller/TokenController.php | TokenController.revokeToken | public function revokeToken(RequestInterface $request, ResponseInterface $response)
{
if (strtolower($request->server('REQUEST_METHOD')) === 'options') {
$response->addHttpHeaders(array('Allow' => 'POST, OPTIONS'));
return null;
}
if (strtolower($request->server('REQUEST_METHOD')) !== 'post') {
$response->setError(405, 'invalid_request', 'The request method must be POST when revoking an access token', '#section-3.2');
$response->addHttpHeaders(array('Allow' => 'POST, OPTIONS'));
return null;
}
$token_type_hint = $request->request('token_type_hint');
if (!in_array($token_type_hint, array(null, 'access_token', 'refresh_token'), true)) {
$response->setError(400, 'invalid_request', 'Token type hint must be either \'access_token\' or \'refresh_token\'');
return null;
}
$token = $request->request('token');
if ($token === null) {
$response->setError(400, 'invalid_request', 'Missing token parameter to revoke');
return null;
}
// @todo remove this check for v2.0
if (!method_exists($this->accessToken, 'revokeToken')) {
$class = get_class($this->accessToken);
throw new RuntimeException("AccessToken {$class} does not implement required revokeToken method");
}
$this->accessToken->revokeToken($token, $token_type_hint);
return true;
} | php | public function revokeToken(RequestInterface $request, ResponseInterface $response)
{
if (strtolower($request->server('REQUEST_METHOD')) === 'options') {
$response->addHttpHeaders(array('Allow' => 'POST, OPTIONS'));
return null;
}
if (strtolower($request->server('REQUEST_METHOD')) !== 'post') {
$response->setError(405, 'invalid_request', 'The request method must be POST when revoking an access token', '#section-3.2');
$response->addHttpHeaders(array('Allow' => 'POST, OPTIONS'));
return null;
}
$token_type_hint = $request->request('token_type_hint');
if (!in_array($token_type_hint, array(null, 'access_token', 'refresh_token'), true)) {
$response->setError(400, 'invalid_request', 'Token type hint must be either \'access_token\' or \'refresh_token\'');
return null;
}
$token = $request->request('token');
if ($token === null) {
$response->setError(400, 'invalid_request', 'Missing token parameter to revoke');
return null;
}
// @todo remove this check for v2.0
if (!method_exists($this->accessToken, 'revokeToken')) {
$class = get_class($this->accessToken);
throw new RuntimeException("AccessToken {$class} does not implement required revokeToken method");
}
$this->accessToken->revokeToken($token, $token_type_hint);
return true;
} | [
"public",
"function",
"revokeToken",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"request",
"->",
"server",
"(",
"'REQUEST_METHOD'",
")",
")",
"===",
"'options'",
")",
"{",
"$",
"response",
"->",
"addHttpHeaders",
"(",
"array",
"(",
"'Allow'",
"=>",
"'POST, OPTIONS'",
")",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"request",
"->",
"server",
"(",
"'REQUEST_METHOD'",
")",
")",
"!==",
"'post'",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"405",
",",
"'invalid_request'",
",",
"'The request method must be POST when revoking an access token'",
",",
"'#section-3.2'",
")",
";",
"$",
"response",
"->",
"addHttpHeaders",
"(",
"array",
"(",
"'Allow'",
"=>",
"'POST, OPTIONS'",
")",
")",
";",
"return",
"null",
";",
"}",
"$",
"token_type_hint",
"=",
"$",
"request",
"->",
"request",
"(",
"'token_type_hint'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"token_type_hint",
",",
"array",
"(",
"null",
",",
"'access_token'",
",",
"'refresh_token'",
")",
",",
"true",
")",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"400",
",",
"'invalid_request'",
",",
"'Token type hint must be either \\'access_token\\' or \\'refresh_token\\''",
")",
";",
"return",
"null",
";",
"}",
"$",
"token",
"=",
"$",
"request",
"->",
"request",
"(",
"'token'",
")",
";",
"if",
"(",
"$",
"token",
"===",
"null",
")",
"{",
"$",
"response",
"->",
"setError",
"(",
"400",
",",
"'invalid_request'",
",",
"'Missing token parameter to revoke'",
")",
";",
"return",
"null",
";",
"}",
"// @todo remove this check for v2.0",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
"->",
"accessToken",
",",
"'revokeToken'",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
"->",
"accessToken",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"\"AccessToken {$class} does not implement required revokeToken method\"",
")",
";",
"}",
"$",
"this",
"->",
"accessToken",
"->",
"revokeToken",
"(",
"$",
"token",
",",
"$",
"token_type_hint",
")",
";",
"return",
"true",
";",
"}"
]
| Revoke a refresh or access token. Returns true on success and when tokens are invalid
Note: invalid tokens do not cause an error response since the client
cannot handle such an error in a reasonable way. Moreover, the
purpose of the revocation request, invalidating the particular token,
is already achieved.
@param RequestInterface $request
@param ResponseInterface $response
@throws RuntimeException
@return bool|null | [
"Revoke",
"a",
"refresh",
"or",
"access",
"token",
".",
"Returns",
"true",
"on",
"success",
"and",
"when",
"tokens",
"are",
"invalid"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Controller/TokenController.php#L294-L332 | train |
bshaffer/oauth2-server-php | src/OAuth2/Response.php | Response.getHttpHeadersAsString | private function getHttpHeadersAsString($headers)
{
if (count($headers) == 0) {
return '';
}
$max = max(array_map('strlen', array_keys($headers))) + 1;
$content = '';
ksort($headers);
foreach ($headers as $name => $values) {
foreach ($values as $value) {
$content .= sprintf("%-{$max}s %s\r\n", $this->beautifyHeaderName($name).':', $value);
}
}
return $content;
} | php | private function getHttpHeadersAsString($headers)
{
if (count($headers) == 0) {
return '';
}
$max = max(array_map('strlen', array_keys($headers))) + 1;
$content = '';
ksort($headers);
foreach ($headers as $name => $values) {
foreach ($values as $value) {
$content .= sprintf("%-{$max}s %s\r\n", $this->beautifyHeaderName($name).':', $value);
}
}
return $content;
} | [
"private",
"function",
"getHttpHeadersAsString",
"(",
"$",
"headers",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"headers",
")",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"max",
"=",
"max",
"(",
"array_map",
"(",
"'strlen'",
",",
"array_keys",
"(",
"$",
"headers",
")",
")",
")",
"+",
"1",
";",
"$",
"content",
"=",
"''",
";",
"ksort",
"(",
"$",
"headers",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"content",
".=",
"sprintf",
"(",
"\"%-{$max}s %s\\r\\n\"",
",",
"$",
"this",
"->",
"beautifyHeaderName",
"(",
"$",
"name",
")",
".",
"':'",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"content",
";",
"}"
]
| Function from Symfony2 HttpFoundation - output pretty header
@param array $headers
@return string | [
"Function",
"from",
"Symfony2",
"HttpFoundation",
"-",
"output",
"pretty",
"header"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Response.php#L448-L464 | train |
bshaffer/oauth2-server-php | src/OAuth2/Scope.php | Scope.checkScope | public function checkScope($required_scope, $available_scope)
{
$required_scope = explode(' ', trim($required_scope));
$available_scope = explode(' ', trim($available_scope));
return (count(array_diff($required_scope, $available_scope)) == 0);
} | php | public function checkScope($required_scope, $available_scope)
{
$required_scope = explode(' ', trim($required_scope));
$available_scope = explode(' ', trim($available_scope));
return (count(array_diff($required_scope, $available_scope)) == 0);
} | [
"public",
"function",
"checkScope",
"(",
"$",
"required_scope",
",",
"$",
"available_scope",
")",
"{",
"$",
"required_scope",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"required_scope",
")",
")",
";",
"$",
"available_scope",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"available_scope",
")",
")",
";",
"return",
"(",
"count",
"(",
"array_diff",
"(",
"$",
"required_scope",
",",
"$",
"available_scope",
")",
")",
"==",
"0",
")",
";",
"}"
]
| Check if everything in required scope is contained in available scope.
@param string $required_scope - A space-separated string of scopes.
@param string $available_scope - A space-separated string of scopes.
@return bool - TRUE if everything in required scope is contained in available scope and FALSE
if it isn't.
@see http://tools.ietf.org/html/rfc6749#section-7
@ingroup oauth2_section_7 | [
"Check",
"if",
"everything",
"in",
"required",
"scope",
"is",
"contained",
"in",
"available",
"scope",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Scope.php#L48-L54 | train |
bshaffer/oauth2-server-php | src/OAuth2/Scope.php | Scope.scopeExists | public function scopeExists($scope)
{
// Check reserved scopes first.
$scope = explode(' ', trim($scope));
$reservedScope = $this->getReservedScopes();
$nonReservedScopes = array_diff($scope, $reservedScope);
if (count($nonReservedScopes) == 0) {
return true;
} else {
// Check the storage for non-reserved scopes.
$nonReservedScopes = implode(' ', $nonReservedScopes);
return $this->storage->scopeExists($nonReservedScopes);
}
} | php | public function scopeExists($scope)
{
// Check reserved scopes first.
$scope = explode(' ', trim($scope));
$reservedScope = $this->getReservedScopes();
$nonReservedScopes = array_diff($scope, $reservedScope);
if (count($nonReservedScopes) == 0) {
return true;
} else {
// Check the storage for non-reserved scopes.
$nonReservedScopes = implode(' ', $nonReservedScopes);
return $this->storage->scopeExists($nonReservedScopes);
}
} | [
"public",
"function",
"scopeExists",
"(",
"$",
"scope",
")",
"{",
"// Check reserved scopes first.",
"$",
"scope",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"scope",
")",
")",
";",
"$",
"reservedScope",
"=",
"$",
"this",
"->",
"getReservedScopes",
"(",
")",
";",
"$",
"nonReservedScopes",
"=",
"array_diff",
"(",
"$",
"scope",
",",
"$",
"reservedScope",
")",
";",
"if",
"(",
"count",
"(",
"$",
"nonReservedScopes",
")",
"==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"// Check the storage for non-reserved scopes.",
"$",
"nonReservedScopes",
"=",
"implode",
"(",
"' '",
",",
"$",
"nonReservedScopes",
")",
";",
"return",
"$",
"this",
"->",
"storage",
"->",
"scopeExists",
"(",
"$",
"nonReservedScopes",
")",
";",
"}",
"}"
]
| Check if the provided scope exists in storage.
@param string $scope - A space-separated string of scopes.
@return bool - TRUE if it exists, FALSE otherwise. | [
"Check",
"if",
"the",
"provided",
"scope",
"exists",
"in",
"storage",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/Scope.php#L62-L76 | train |
bshaffer/oauth2-server-php | src/OAuth2/ResponseType/AuthorizationCode.php | AuthorizationCode.createAuthorizationCode | public function createAuthorizationCode($client_id, $user_id, $redirect_uri, $scope = null)
{
$code = $this->generateAuthorizationCode();
$this->storage->setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, time() + $this->config['auth_code_lifetime'], $scope);
return $code;
} | php | public function createAuthorizationCode($client_id, $user_id, $redirect_uri, $scope = null)
{
$code = $this->generateAuthorizationCode();
$this->storage->setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, time() + $this->config['auth_code_lifetime'], $scope);
return $code;
} | [
"public",
"function",
"createAuthorizationCode",
"(",
"$",
"client_id",
",",
"$",
"user_id",
",",
"$",
"redirect_uri",
",",
"$",
"scope",
"=",
"null",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"generateAuthorizationCode",
"(",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"setAuthorizationCode",
"(",
"$",
"code",
",",
"$",
"client_id",
",",
"$",
"user_id",
",",
"$",
"redirect_uri",
",",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"[",
"'auth_code_lifetime'",
"]",
",",
"$",
"scope",
")",
";",
"return",
"$",
"code",
";",
"}"
]
| Handle the creation of the authorization code.
@param $client_id
Client identifier related to the authorization code
@param $user_id
User ID associated with the authorization code
@param $redirect_uri
An absolute URI to which the authorization server will redirect the
user-agent to when the end-user authorization step is completed.
@param $scope
(optional) Scopes to be stored in space-separated string.
@see http://tools.ietf.org/html/rfc6749#section-4
@ingroup oauth2_section_4 | [
"Handle",
"the",
"creation",
"of",
"the",
"authorization",
"code",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/ResponseType/AuthorizationCode.php#L56-L62 | train |
bshaffer/oauth2-server-php | src/OAuth2/ResponseType/AuthorizationCode.php | AuthorizationCode.generateAuthorizationCode | protected function generateAuthorizationCode()
{
$tokenLen = 40;
if (function_exists('random_bytes')) {
$randomData = random_bytes(100);
} elseif (function_exists('openssl_random_pseudo_bytes')) {
$randomData = openssl_random_pseudo_bytes(100);
} elseif (function_exists('mcrypt_create_iv')) {
$randomData = mcrypt_create_iv(100, MCRYPT_DEV_URANDOM);
} elseif (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
$randomData = file_get_contents('/dev/urandom', false, null, 0, 100) . uniqid(mt_rand(), true);
} else {
$randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);
}
return substr(hash('sha512', $randomData), 0, $tokenLen);
} | php | protected function generateAuthorizationCode()
{
$tokenLen = 40;
if (function_exists('random_bytes')) {
$randomData = random_bytes(100);
} elseif (function_exists('openssl_random_pseudo_bytes')) {
$randomData = openssl_random_pseudo_bytes(100);
} elseif (function_exists('mcrypt_create_iv')) {
$randomData = mcrypt_create_iv(100, MCRYPT_DEV_URANDOM);
} elseif (@file_exists('/dev/urandom')) { // Get 100 bytes of random data
$randomData = file_get_contents('/dev/urandom', false, null, 0, 100) . uniqid(mt_rand(), true);
} else {
$randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);
}
return substr(hash('sha512', $randomData), 0, $tokenLen);
} | [
"protected",
"function",
"generateAuthorizationCode",
"(",
")",
"{",
"$",
"tokenLen",
"=",
"40",
";",
"if",
"(",
"function_exists",
"(",
"'random_bytes'",
")",
")",
"{",
"$",
"randomData",
"=",
"random_bytes",
"(",
"100",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'openssl_random_pseudo_bytes'",
")",
")",
"{",
"$",
"randomData",
"=",
"openssl_random_pseudo_bytes",
"(",
"100",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'mcrypt_create_iv'",
")",
")",
"{",
"$",
"randomData",
"=",
"mcrypt_create_iv",
"(",
"100",
",",
"MCRYPT_DEV_URANDOM",
")",
";",
"}",
"elseif",
"(",
"@",
"file_exists",
"(",
"'/dev/urandom'",
")",
")",
"{",
"// Get 100 bytes of random data",
"$",
"randomData",
"=",
"file_get_contents",
"(",
"'/dev/urandom'",
",",
"false",
",",
"null",
",",
"0",
",",
"100",
")",
".",
"uniqid",
"(",
"mt_rand",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"randomData",
"=",
"mt_rand",
"(",
")",
".",
"mt_rand",
"(",
")",
".",
"mt_rand",
"(",
")",
".",
"mt_rand",
"(",
")",
".",
"microtime",
"(",
"true",
")",
".",
"uniqid",
"(",
"mt_rand",
"(",
")",
",",
"true",
")",
";",
"}",
"return",
"substr",
"(",
"hash",
"(",
"'sha512'",
",",
"$",
"randomData",
")",
",",
"0",
",",
"$",
"tokenLen",
")",
";",
"}"
]
| Generates an unique auth code.
Implementing classes may want to override this function to implement
other auth code generation schemes.
@return
An unique auth code.
@ingroup oauth2_section_4 | [
"Generates",
"an",
"unique",
"auth",
"code",
"."
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/ResponseType/AuthorizationCode.php#L84-L100 | train |
bshaffer/oauth2-server-php | src/OAuth2/OpenID/ResponseType/IdToken.php | IdToken.createIdToken | public function createIdToken($client_id, $userInfo, $nonce = null, $userClaims = null, $access_token = null)
{
// pull auth_time from user info if supplied
list($user_id, $auth_time) = $this->getUserIdAndAuthTime($userInfo);
$token = array(
'iss' => $this->config['issuer'],
'sub' => $user_id,
'aud' => $client_id,
'iat' => time(),
'exp' => time() + $this->config['id_lifetime'],
'auth_time' => $auth_time,
);
if ($nonce) {
$token['nonce'] = $nonce;
}
if ($userClaims) {
$token += $userClaims;
}
if ($access_token) {
$token['at_hash'] = $this->createAtHash($access_token, $client_id);
}
return $this->encodeToken($token, $client_id);
} | php | public function createIdToken($client_id, $userInfo, $nonce = null, $userClaims = null, $access_token = null)
{
// pull auth_time from user info if supplied
list($user_id, $auth_time) = $this->getUserIdAndAuthTime($userInfo);
$token = array(
'iss' => $this->config['issuer'],
'sub' => $user_id,
'aud' => $client_id,
'iat' => time(),
'exp' => time() + $this->config['id_lifetime'],
'auth_time' => $auth_time,
);
if ($nonce) {
$token['nonce'] = $nonce;
}
if ($userClaims) {
$token += $userClaims;
}
if ($access_token) {
$token['at_hash'] = $this->createAtHash($access_token, $client_id);
}
return $this->encodeToken($token, $client_id);
} | [
"public",
"function",
"createIdToken",
"(",
"$",
"client_id",
",",
"$",
"userInfo",
",",
"$",
"nonce",
"=",
"null",
",",
"$",
"userClaims",
"=",
"null",
",",
"$",
"access_token",
"=",
"null",
")",
"{",
"// pull auth_time from user info if supplied",
"list",
"(",
"$",
"user_id",
",",
"$",
"auth_time",
")",
"=",
"$",
"this",
"->",
"getUserIdAndAuthTime",
"(",
"$",
"userInfo",
")",
";",
"$",
"token",
"=",
"array",
"(",
"'iss'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'issuer'",
"]",
",",
"'sub'",
"=>",
"$",
"user_id",
",",
"'aud'",
"=>",
"$",
"client_id",
",",
"'iat'",
"=>",
"time",
"(",
")",
",",
"'exp'",
"=>",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"[",
"'id_lifetime'",
"]",
",",
"'auth_time'",
"=>",
"$",
"auth_time",
",",
")",
";",
"if",
"(",
"$",
"nonce",
")",
"{",
"$",
"token",
"[",
"'nonce'",
"]",
"=",
"$",
"nonce",
";",
"}",
"if",
"(",
"$",
"userClaims",
")",
"{",
"$",
"token",
"+=",
"$",
"userClaims",
";",
"}",
"if",
"(",
"$",
"access_token",
")",
"{",
"$",
"token",
"[",
"'at_hash'",
"]",
"=",
"$",
"this",
"->",
"createAtHash",
"(",
"$",
"access_token",
",",
"$",
"client_id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"encodeToken",
"(",
"$",
"token",
",",
"$",
"client_id",
")",
";",
"}"
]
| Create id token
@param string $client_id
@param mixed $userInfo
@param mixed $nonce
@param mixed $userClaims
@param mixed $access_token
@return mixed|string | [
"Create",
"id",
"token"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/OpenID/ResponseType/IdToken.php#L92-L119 | train |
bshaffer/oauth2-server-php | src/OAuth2/TokenType/Bearer.php | Bearer.requestHasToken | public function requestHasToken(RequestInterface $request)
{
$headers = $request->headers('AUTHORIZATION');
// check the header, then the querystring, then the request body
return !empty($headers) || (bool) ($request->request($this->config['token_param_name'])) || (bool) ($request->query($this->config['token_param_name']));
} | php | public function requestHasToken(RequestInterface $request)
{
$headers = $request->headers('AUTHORIZATION');
// check the header, then the querystring, then the request body
return !empty($headers) || (bool) ($request->request($this->config['token_param_name'])) || (bool) ($request->query($this->config['token_param_name']));
} | [
"public",
"function",
"requestHasToken",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"headers",
"=",
"$",
"request",
"->",
"headers",
"(",
"'AUTHORIZATION'",
")",
";",
"// check the header, then the querystring, then the request body",
"return",
"!",
"empty",
"(",
"$",
"headers",
")",
"||",
"(",
"bool",
")",
"(",
"$",
"request",
"->",
"request",
"(",
"$",
"this",
"->",
"config",
"[",
"'token_param_name'",
"]",
")",
")",
"||",
"(",
"bool",
")",
"(",
"$",
"request",
"->",
"query",
"(",
"$",
"this",
"->",
"config",
"[",
"'token_param_name'",
"]",
")",
")",
";",
"}"
]
| Check if the request has supplied token
@see https://github.com/bshaffer/oauth2-server-php/issues/349#issuecomment-37993588 | [
"Check",
"if",
"the",
"request",
"has",
"supplied",
"token"
]
| 5a0c8000d4763b276919e2106f54eddda6bc50fa | https://github.com/bshaffer/oauth2-server-php/blob/5a0c8000d4763b276919e2106f54eddda6bc50fa/src/OAuth2/TokenType/Bearer.php#L33-L39 | train |
saleem-hadad/larecipe | src/Models/Documentation.php | Documentation.getIndex | public function getIndex($version)
{
return $this->cache->remember(function() use($version) {
$path = base_path(config('larecipe.docs.path').'/'.$version.'/index.md');
if ($this->files->exists($path)) {
$parsedContent = $this->parse($this->files->get($path));
return $this->replaceLinks($version, $parsedContent);
}
return null;
}, 'larecipe.docs.'.$version.'.index');
} | php | public function getIndex($version)
{
return $this->cache->remember(function() use($version) {
$path = base_path(config('larecipe.docs.path').'/'.$version.'/index.md');
if ($this->files->exists($path)) {
$parsedContent = $this->parse($this->files->get($path));
return $this->replaceLinks($version, $parsedContent);
}
return null;
}, 'larecipe.docs.'.$version.'.index');
} | [
"public",
"function",
"getIndex",
"(",
"$",
"version",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"->",
"remember",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"version",
")",
"{",
"$",
"path",
"=",
"base_path",
"(",
"config",
"(",
"'larecipe.docs.path'",
")",
".",
"'/'",
".",
"$",
"version",
".",
"'/index.md'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"parsedContent",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"$",
"path",
")",
")",
";",
"return",
"$",
"this",
"->",
"replaceLinks",
"(",
"$",
"version",
",",
"$",
"parsedContent",
")",
";",
"}",
"return",
"null",
";",
"}",
",",
"'larecipe.docs.'",
".",
"$",
"version",
".",
"'.index'",
")",
";",
"}"
]
| Get the documentation index page.
@param string $version
@return string | [
"Get",
"the",
"documentation",
"index",
"page",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Models/Documentation.php#L47-L60 | train |
saleem-hadad/larecipe | src/Models/Documentation.php | Documentation.get | public function get($version, $page, $data = [])
{
return $this->cache->remember(function() use($version, $page, $data) {
$path = base_path(config('larecipe.docs.path').'/'.$version.'/'.$page.'.md');
if ($this->files->exists($path)) {
$parsedContent = $this->parse($this->files->get($path));
$parsedContent = $this->replaceLinks($version, $parsedContent);
return $this->renderBlade($parsedContent, $data);
}
return null;
}, 'larecipe.docs.'.$version.'.'.$page);
} | php | public function get($version, $page, $data = [])
{
return $this->cache->remember(function() use($version, $page, $data) {
$path = base_path(config('larecipe.docs.path').'/'.$version.'/'.$page.'.md');
if ($this->files->exists($path)) {
$parsedContent = $this->parse($this->files->get($path));
$parsedContent = $this->replaceLinks($version, $parsedContent);
return $this->renderBlade($parsedContent, $data);
}
return null;
}, 'larecipe.docs.'.$version.'.'.$page);
} | [
"public",
"function",
"get",
"(",
"$",
"version",
",",
"$",
"page",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"->",
"remember",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"version",
",",
"$",
"page",
",",
"$",
"data",
")",
"{",
"$",
"path",
"=",
"base_path",
"(",
"config",
"(",
"'larecipe.docs.path'",
")",
".",
"'/'",
".",
"$",
"version",
".",
"'/'",
".",
"$",
"page",
".",
"'.md'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"parsedContent",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"$",
"path",
")",
")",
";",
"$",
"parsedContent",
"=",
"$",
"this",
"->",
"replaceLinks",
"(",
"$",
"version",
",",
"$",
"parsedContent",
")",
";",
"return",
"$",
"this",
"->",
"renderBlade",
"(",
"$",
"parsedContent",
",",
"$",
"data",
")",
";",
"}",
"return",
"null",
";",
"}",
",",
"'larecipe.docs.'",
".",
"$",
"version",
".",
"'.'",
".",
"$",
"page",
")",
";",
"}"
]
| Get the given documentation page.
@param $version
@param $page
@param array $data
@return mixed | [
"Get",
"the",
"given",
"documentation",
"page",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Models/Documentation.php#L70-L85 | train |
saleem-hadad/larecipe | src/Models/Documentation.php | Documentation.replaceLinks | public static function replaceLinks($version, $content)
{
$content = str_replace('{{version}}', $version, $content);
$content = str_replace('{{route}}', trim(config('larecipe.docs.route'), '/'), $content);
return $content;
} | php | public static function replaceLinks($version, $content)
{
$content = str_replace('{{version}}', $version, $content);
$content = str_replace('{{route}}', trim(config('larecipe.docs.route'), '/'), $content);
return $content;
} | [
"public",
"static",
"function",
"replaceLinks",
"(",
"$",
"version",
",",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"str_replace",
"(",
"'{{version}}'",
",",
"$",
"version",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"'{{route}}'",
",",
"trim",
"(",
"config",
"(",
"'larecipe.docs.route'",
")",
",",
"'/'",
")",
",",
"$",
"content",
")",
";",
"return",
"$",
"content",
";",
"}"
]
| Replace the version and route placeholders.
@param string $version
@param string $content
@return string | [
"Replace",
"the",
"version",
"and",
"route",
"placeholders",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Models/Documentation.php#L94-L101 | train |
saleem-hadad/larecipe | src/Models/Documentation.php | Documentation.sectionExists | public function sectionExists($version, $page)
{
return $this->files->exists(
base_path(config('larecipe.docs.path').'/'.$version.'/'.$page.'.md')
);
} | php | public function sectionExists($version, $page)
{
return $this->files->exists(
base_path(config('larecipe.docs.path').'/'.$version.'/'.$page.'.md')
);
} | [
"public",
"function",
"sectionExists",
"(",
"$",
"version",
",",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"base_path",
"(",
"config",
"(",
"'larecipe.docs.path'",
")",
".",
"'/'",
".",
"$",
"version",
".",
"'/'",
".",
"$",
"page",
".",
"'.md'",
")",
")",
";",
"}"
]
| Check if the given section exists.
@param string $version
@param string $page
@return bool | [
"Check",
"if",
"the",
"given",
"section",
"exists",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Models/Documentation.php#L110-L115 | train |
saleem-hadad/larecipe | src/Commands/AssetCommand.php | AssetCommand.runCommand | protected function runCommand($command, $path)
{
$process = (new Process($command, $path))->setTimeout(null);
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
$process->setTty(true);
}
$process->run(function ($type, $line) {
$this->output->write($line);
});
} | php | protected function runCommand($command, $path)
{
$process = (new Process($command, $path))->setTimeout(null);
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
$process->setTty(true);
}
$process->run(function ($type, $line) {
$this->output->write($line);
});
} | [
"protected",
"function",
"runCommand",
"(",
"$",
"command",
",",
"$",
"path",
")",
"{",
"$",
"process",
"=",
"(",
"new",
"Process",
"(",
"$",
"command",
",",
"$",
"path",
")",
")",
"->",
"setTimeout",
"(",
"null",
")",
";",
"if",
"(",
"'\\\\'",
"!==",
"DIRECTORY_SEPARATOR",
"&&",
"file_exists",
"(",
"'/dev/tty'",
")",
"&&",
"is_readable",
"(",
"'/dev/tty'",
")",
")",
"{",
"$",
"process",
"->",
"setTty",
"(",
"true",
")",
";",
"}",
"$",
"process",
"->",
"run",
"(",
"function",
"(",
"$",
"type",
",",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"write",
"(",
"$",
"line",
")",
";",
"}",
")",
";",
"}"
]
| Run the given command as a process.
@param string $command
@param string $path
@return void | [
"Run",
"the",
"given",
"command",
"as",
"a",
"process",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/AssetCommand.php#L180-L191 | train |
saleem-hadad/larecipe | src/Commands/AssetCommand.php | AssetCommand.hasValidNameArgument | public function hasValidNameArgument()
{
$name = $this->argument('name');
if (! Str::contains($name, '/')) {
$this->error("The name argument expects a vendor and name in 'Composer' format. Here's an example: `vendor/name`.");
return false;
}
return true;
} | php | public function hasValidNameArgument()
{
$name = $this->argument('name');
if (! Str::contains($name, '/')) {
$this->error("The name argument expects a vendor and name in 'Composer' format. Here's an example: `vendor/name`.");
return false;
}
return true;
} | [
"public",
"function",
"hasValidNameArgument",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
";",
"if",
"(",
"!",
"Str",
"::",
"contains",
"(",
"$",
"name",
",",
"'/'",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The name argument expects a vendor and name in 'Composer' format. Here's an example: `vendor/name`.\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Determine if the name argument is valid.
@return bool | [
"Determine",
"if",
"the",
"name",
"argument",
"is",
"valid",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/AssetCommand.php#L281-L292 | train |
saleem-hadad/larecipe | src/Commands/AssetCommand.php | AssetCommand.renameStubs | protected function renameStubs()
{
foreach ($this->stubsToRename() as $stub) {
(new Filesystem)->move($stub, str_replace('.stub', '.php', $stub));
}
} | php | protected function renameStubs()
{
foreach ($this->stubsToRename() as $stub) {
(new Filesystem)->move($stub, str_replace('.stub', '.php', $stub));
}
} | [
"protected",
"function",
"renameStubs",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"stubsToRename",
"(",
")",
"as",
"$",
"stub",
")",
"{",
"(",
"new",
"Filesystem",
")",
"->",
"move",
"(",
"$",
"stub",
",",
"str_replace",
"(",
"'.stub'",
",",
"'.php'",
",",
"$",
"stub",
")",
")",
";",
"}",
"}"
]
| Rename the stubs with PHP file extensions.
@return void | [
"Rename",
"the",
"stubs",
"with",
"PHP",
"file",
"extensions",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/AssetCommand.php#L299-L304 | train |
saleem-hadad/larecipe | src/LaRecipeServiceProvider.php | LaRecipeServiceProvider.registerConsoleCommands | protected function registerConsoleCommands()
{
$this->commands(AssetCommand::class);
$this->commands(ThemeCommand::class);
$this->commands(InstallCommand::class);
$this->commands(GenerateDocumentationCommand::class);
} | php | protected function registerConsoleCommands()
{
$this->commands(AssetCommand::class);
$this->commands(ThemeCommand::class);
$this->commands(InstallCommand::class);
$this->commands(GenerateDocumentationCommand::class);
} | [
"protected",
"function",
"registerConsoleCommands",
"(",
")",
"{",
"$",
"this",
"->",
"commands",
"(",
"AssetCommand",
"::",
"class",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"ThemeCommand",
"::",
"class",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"InstallCommand",
"::",
"class",
")",
";",
"$",
"this",
"->",
"commands",
"(",
"GenerateDocumentationCommand",
"::",
"class",
")",
";",
"}"
]
| Register the commands accessible from the Console. | [
"Register",
"the",
"commands",
"accessible",
"from",
"the",
"Console",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/LaRecipeServiceProvider.php#L102-L108 | train |
saleem-hadad/larecipe | src/DocumentationRepository.php | DocumentationRepository.prepareNotFound | protected function prepareNotFound()
{
$this->title = 'Page not found';
$this->content = view('larecipe::partials.404');
$this->currentSection = '';
$this->canonical = '';
$this->statusCode = 404;
return $this;
} | php | protected function prepareNotFound()
{
$this->title = 'Page not found';
$this->content = view('larecipe::partials.404');
$this->currentSection = '';
$this->canonical = '';
$this->statusCode = 404;
return $this;
} | [
"protected",
"function",
"prepareNotFound",
"(",
")",
"{",
"$",
"this",
"->",
"title",
"=",
"'Page not found'",
";",
"$",
"this",
"->",
"content",
"=",
"view",
"(",
"'larecipe::partials.404'",
")",
";",
"$",
"this",
"->",
"currentSection",
"=",
"''",
";",
"$",
"this",
"->",
"canonical",
"=",
"''",
";",
"$",
"this",
"->",
"statusCode",
"=",
"404",
";",
"return",
"$",
"this",
";",
"}"
]
| If the docs content is empty then show 404 page.
@return $this | [
"If",
"the",
"docs",
"content",
"is",
"empty",
"then",
"show",
"404",
"page",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/DocumentationRepository.php#L66-L75 | train |
saleem-hadad/larecipe | src/DocumentationRepository.php | DocumentationRepository.prepareTitle | protected function prepareTitle()
{
$this->title = (new Crawler($this->content))->filterXPath('//h1');
$this->title = count($this->title) ? $this->title->text() : null;
return $this;
} | php | protected function prepareTitle()
{
$this->title = (new Crawler($this->content))->filterXPath('//h1');
$this->title = count($this->title) ? $this->title->text() : null;
return $this;
} | [
"protected",
"function",
"prepareTitle",
"(",
")",
"{",
"$",
"this",
"->",
"title",
"=",
"(",
"new",
"Crawler",
"(",
"$",
"this",
"->",
"content",
")",
")",
"->",
"filterXPath",
"(",
"'//h1'",
")",
";",
"$",
"this",
"->",
"title",
"=",
"count",
"(",
"$",
"this",
"->",
"title",
")",
"?",
"$",
"this",
"->",
"title",
"->",
"text",
"(",
")",
":",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Prepare the page title from the first h1 found.
@return $this | [
"Prepare",
"the",
"page",
"title",
"from",
"the",
"first",
"h1",
"found",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/DocumentationRepository.php#L82-L88 | train |
saleem-hadad/larecipe | src/DocumentationRepository.php | DocumentationRepository.prepareSection | protected function prepareSection($version, $page)
{
if ($this->documentation->sectionExists($version, $page)) {
$this->currentSection = '/'.$page;
}
return $this;
} | php | protected function prepareSection($version, $page)
{
if ($this->documentation->sectionExists($version, $page)) {
$this->currentSection = '/'.$page;
}
return $this;
} | [
"protected",
"function",
"prepareSection",
"(",
"$",
"version",
",",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"documentation",
"->",
"sectionExists",
"(",
"$",
"version",
",",
"$",
"page",
")",
")",
"{",
"$",
"this",
"->",
"currentSection",
"=",
"'/'",
".",
"$",
"page",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Prepare the current section page.
@param $version
@param $page
@return $this | [
"Prepare",
"the",
"current",
"section",
"page",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/DocumentationRepository.php#L97-L104 | train |
saleem-hadad/larecipe | src/DocumentationRepository.php | DocumentationRepository.prepareCanonical | protected function prepareCanonical()
{
if ($this->documentation->sectionExists($this->defaultVersion, $this->sectionPage)) {
$this->canonical = $this->docsRoute.'/'.$this->defaultVersion.'/'.$this->sectionPage;
}
return $this;
} | php | protected function prepareCanonical()
{
if ($this->documentation->sectionExists($this->defaultVersion, $this->sectionPage)) {
$this->canonical = $this->docsRoute.'/'.$this->defaultVersion.'/'.$this->sectionPage;
}
return $this;
} | [
"protected",
"function",
"prepareCanonical",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"documentation",
"->",
"sectionExists",
"(",
"$",
"this",
"->",
"defaultVersion",
",",
"$",
"this",
"->",
"sectionPage",
")",
")",
"{",
"$",
"this",
"->",
"canonical",
"=",
"$",
"this",
"->",
"docsRoute",
".",
"'/'",
".",
"$",
"this",
"->",
"defaultVersion",
".",
"'/'",
".",
"$",
"this",
"->",
"sectionPage",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Prepare the canonical link.
@return $this | [
"Prepare",
"the",
"canonical",
"link",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/DocumentationRepository.php#L111-L118 | train |
saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | GenerateDocumentationCommand.createVersionDirectory | protected function createVersionDirectory($versionDirectory)
{
if (! $this->filesystem->isDirectory($versionDirectory)) {
$this->filesystem->makeDirectory($versionDirectory, 0755, true);
return true;
}
return false;
} | php | protected function createVersionDirectory($versionDirectory)
{
if (! $this->filesystem->isDirectory($versionDirectory)) {
$this->filesystem->makeDirectory($versionDirectory, 0755, true);
return true;
}
return false;
} | [
"protected",
"function",
"createVersionDirectory",
"(",
"$",
"versionDirectory",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"isDirectory",
"(",
"$",
"versionDirectory",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"makeDirectory",
"(",
"$",
"versionDirectory",
",",
"0755",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Create a new directory for the given version if not exists.
@return bool | [
"Create",
"a",
"new",
"directory",
"for",
"the",
"given",
"version",
"if",
"not",
"exists",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/GenerateDocumentationCommand.php#L90-L99 | train |
saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | GenerateDocumentationCommand.createVersionIndex | protected function createVersionIndex($versionDirectory)
{
$indexPath = $versionDirectory.'/index.md';
if (! $this->filesystem->exists($indexPath)) {
$content = $this->generateIndexContent($this->getStub('index'));
$this->filesystem->put($indexPath, $content);
return true;
}
return false;
} | php | protected function createVersionIndex($versionDirectory)
{
$indexPath = $versionDirectory.'/index.md';
if (! $this->filesystem->exists($indexPath)) {
$content = $this->generateIndexContent($this->getStub('index'));
$this->filesystem->put($indexPath, $content);
return true;
}
return false;
} | [
"protected",
"function",
"createVersionIndex",
"(",
"$",
"versionDirectory",
")",
"{",
"$",
"indexPath",
"=",
"$",
"versionDirectory",
".",
"'/index.md'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"$",
"indexPath",
")",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"generateIndexContent",
"(",
"$",
"this",
"->",
"getStub",
"(",
"'index'",
")",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"indexPath",
",",
"$",
"content",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Create index.md for the given version if it's not exists.
@param $versionDirectory
@return bool
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException | [
"Create",
"index",
".",
"md",
"for",
"the",
"given",
"version",
"if",
"it",
"s",
"not",
"exists",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/GenerateDocumentationCommand.php#L108-L120 | train |
saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | GenerateDocumentationCommand.generateIndexContent | protected function generateIndexContent($stub)
{
$content = str_replace(
'{{LANDING}}',
ucwords(config('larecipe.docs.landing')),
$stub
);
$content = str_replace(
'{{ROOT}}',
config('larecipe.docs.route'),
$content
);
$content = str_replace(
'{{LANDINGSMALL}}',
trim(config('larecipe.docs.landing'), '/'),
$content
);
return $content;
} | php | protected function generateIndexContent($stub)
{
$content = str_replace(
'{{LANDING}}',
ucwords(config('larecipe.docs.landing')),
$stub
);
$content = str_replace(
'{{ROOT}}',
config('larecipe.docs.route'),
$content
);
$content = str_replace(
'{{LANDINGSMALL}}',
trim(config('larecipe.docs.landing'), '/'),
$content
);
return $content;
} | [
"protected",
"function",
"generateIndexContent",
"(",
"$",
"stub",
")",
"{",
"$",
"content",
"=",
"str_replace",
"(",
"'{{LANDING}}'",
",",
"ucwords",
"(",
"config",
"(",
"'larecipe.docs.landing'",
")",
")",
",",
"$",
"stub",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"'{{ROOT}}'",
",",
"config",
"(",
"'larecipe.docs.route'",
")",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"'{{LANDINGSMALL}}'",
",",
"trim",
"(",
"config",
"(",
"'larecipe.docs.landing'",
")",
",",
"'/'",
")",
",",
"$",
"content",
")",
";",
"return",
"$",
"content",
";",
"}"
]
| replace stub placeholders.
@return string | [
"replace",
"stub",
"placeholders",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/GenerateDocumentationCommand.php#L148-L169 | train |
saleem-hadad/larecipe | src/Cache.php | Cache.checkTtlNeedsChanged | public function checkTtlNeedsChanged($ttl)
{
$app_version = explode('.', app()->version());
if (((int) $app_version[0] == 5 && (int) $app_version[1] >= 8) || $app_version[0] > 5) {
return config('larecipe.cache.period') * 60;
}
return $ttl;
} | php | public function checkTtlNeedsChanged($ttl)
{
$app_version = explode('.', app()->version());
if (((int) $app_version[0] == 5 && (int) $app_version[1] >= 8) || $app_version[0] > 5) {
return config('larecipe.cache.period') * 60;
}
return $ttl;
} | [
"public",
"function",
"checkTtlNeedsChanged",
"(",
"$",
"ttl",
")",
"{",
"$",
"app_version",
"=",
"explode",
"(",
"'.'",
",",
"app",
"(",
")",
"->",
"version",
"(",
")",
")",
";",
"if",
"(",
"(",
"(",
"int",
")",
"$",
"app_version",
"[",
"0",
"]",
"==",
"5",
"&&",
"(",
"int",
")",
"$",
"app_version",
"[",
"1",
"]",
">=",
"8",
")",
"||",
"$",
"app_version",
"[",
"0",
"]",
">",
"5",
")",
"{",
"return",
"config",
"(",
"'larecipe.cache.period'",
")",
"*",
"60",
";",
"}",
"return",
"$",
"ttl",
";",
"}"
]
| Checks if minutes need to be changed to seconds
@param $ttl
@return float|int | [
"Checks",
"if",
"minutes",
"need",
"to",
"be",
"changed",
"to",
"seconds"
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Cache.php#L51-L60 | train |
saleem-hadad/larecipe | src/Traits/HasBladeParser.php | HasBladeParser.renderBlade | public function renderBlade($content, $data = [])
{
$content = $this->compileBlade($content);
$obLevel = ob_get_level();
ob_start();
extract($data, EXTR_SKIP);
try {
eval('?'.'>'.$content);
} catch (\Exception $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw $e;
} catch (\Throwable $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw new \Exception($e);
}
$contents = ob_get_clean();
return $contents;
} | php | public function renderBlade($content, $data = [])
{
$content = $this->compileBlade($content);
$obLevel = ob_get_level();
ob_start();
extract($data, EXTR_SKIP);
try {
eval('?'.'>'.$content);
} catch (\Exception $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw $e;
} catch (\Throwable $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw new \Exception($e);
}
$contents = ob_get_clean();
return $contents;
} | [
"public",
"function",
"renderBlade",
"(",
"$",
"content",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"compileBlade",
"(",
"$",
"content",
")",
";",
"$",
"obLevel",
"=",
"ob_get_level",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"extract",
"(",
"$",
"data",
",",
"EXTR_SKIP",
")",
";",
"try",
"{",
"eval",
"(",
"'?'",
".",
"'>'",
".",
"$",
"content",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"$",
"obLevel",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"$",
"obLevel",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"$",
"contents",
"=",
"ob_get_clean",
"(",
")",
";",
"return",
"$",
"contents",
";",
"}"
]
| Render markdown contain blade syntax.
@param $content
@param array $data
@return false|string
@throws \Exception | [
"Render",
"markdown",
"contain",
"blade",
"syntax",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Traits/HasBladeParser.php#L17-L41 | train |
saleem-hadad/larecipe | src/Commands/ThemeCommand.php | ThemeCommand.addThemeRepositoryToRootComposer | protected function addThemeRepositoryToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['repositories'][] = [
'type' => 'path',
'url' => './'.$this->relativeThemePath(),
];
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | php | protected function addThemeRepositoryToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['repositories'][] = [
'type' => 'path',
'url' => './'.$this->relativeThemePath(),
];
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | [
"protected",
"function",
"addThemeRepositoryToRootComposer",
"(",
")",
"{",
"$",
"composer",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"base_path",
"(",
"'composer.json'",
")",
")",
",",
"true",
")",
";",
"$",
"composer",
"[",
"'repositories'",
"]",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'path'",
",",
"'url'",
"=>",
"'./'",
".",
"$",
"this",
"->",
"relativeThemePath",
"(",
")",
",",
"]",
";",
"file_put_contents",
"(",
"base_path",
"(",
"'composer.json'",
")",
",",
"json_encode",
"(",
"$",
"composer",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
]
| Add a path repository for the theme to the application's composer.json file.
@return void | [
"Add",
"a",
"path",
"repository",
"for",
"the",
"theme",
"to",
"the",
"application",
"s",
"composer",
".",
"json",
"file",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/ThemeCommand.php#L80-L93 | train |
saleem-hadad/larecipe | src/Commands/ThemeCommand.php | ThemeCommand.addThemePackageToRootComposer | protected function addThemePackageToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['require'][$this->argument('name')] = '*';
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | php | protected function addThemePackageToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['require'][$this->argument('name')] = '*';
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | [
"protected",
"function",
"addThemePackageToRootComposer",
"(",
")",
"{",
"$",
"composer",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"base_path",
"(",
"'composer.json'",
")",
")",
",",
"true",
")",
";",
"$",
"composer",
"[",
"'require'",
"]",
"[",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
"]",
"=",
"'*'",
";",
"file_put_contents",
"(",
"base_path",
"(",
"'composer.json'",
")",
",",
"json_encode",
"(",
"$",
"composer",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
]
| Add a package entry for the theme to the application's composer.json file.
@return void | [
"Add",
"a",
"package",
"entry",
"for",
"the",
"theme",
"to",
"the",
"application",
"s",
"composer",
".",
"json",
"file",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Commands/ThemeCommand.php#L100-L110 | train |
saleem-hadad/larecipe | src/Http/Controllers/DocumentationController.php | DocumentationController.show | public function show($version, $page = null)
{
$documentation = $this->documentationRepository->get($version, $page);
if (Gate::has('viewLarecipe')) {
$this->authorize('viewLarecipe', $documentation);
}
if ($this->documentationRepository->isNotPublishedVersion($version)) {
return redirect()->route(
'larecipe.show',
[
'version' => config('larecipe.versions.default'),
'page' => config('larecipe.docs.landing')
]
);
}
return response()->view('larecipe::docs', [
'title' => $documentation->title,
'index' => $documentation->index,
'content' => $documentation->content,
'currentVersion' => $version,
'versions' => $documentation->publishedVersions,
'currentSection' => $documentation->currentSection,
'canonical' => $documentation->canonical,
], $documentation->statusCode);
} | php | public function show($version, $page = null)
{
$documentation = $this->documentationRepository->get($version, $page);
if (Gate::has('viewLarecipe')) {
$this->authorize('viewLarecipe', $documentation);
}
if ($this->documentationRepository->isNotPublishedVersion($version)) {
return redirect()->route(
'larecipe.show',
[
'version' => config('larecipe.versions.default'),
'page' => config('larecipe.docs.landing')
]
);
}
return response()->view('larecipe::docs', [
'title' => $documentation->title,
'index' => $documentation->index,
'content' => $documentation->content,
'currentVersion' => $version,
'versions' => $documentation->publishedVersions,
'currentSection' => $documentation->currentSection,
'canonical' => $documentation->canonical,
], $documentation->statusCode);
} | [
"public",
"function",
"show",
"(",
"$",
"version",
",",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"documentation",
"=",
"$",
"this",
"->",
"documentationRepository",
"->",
"get",
"(",
"$",
"version",
",",
"$",
"page",
")",
";",
"if",
"(",
"Gate",
"::",
"has",
"(",
"'viewLarecipe'",
")",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'viewLarecipe'",
",",
"$",
"documentation",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"documentationRepository",
"->",
"isNotPublishedVersion",
"(",
"$",
"version",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'larecipe.show'",
",",
"[",
"'version'",
"=>",
"config",
"(",
"'larecipe.versions.default'",
")",
",",
"'page'",
"=>",
"config",
"(",
"'larecipe.docs.landing'",
")",
"]",
")",
";",
"}",
"return",
"response",
"(",
")",
"->",
"view",
"(",
"'larecipe::docs'",
",",
"[",
"'title'",
"=>",
"$",
"documentation",
"->",
"title",
",",
"'index'",
"=>",
"$",
"documentation",
"->",
"index",
",",
"'content'",
"=>",
"$",
"documentation",
"->",
"content",
",",
"'currentVersion'",
"=>",
"$",
"version",
",",
"'versions'",
"=>",
"$",
"documentation",
"->",
"publishedVersions",
",",
"'currentSection'",
"=>",
"$",
"documentation",
"->",
"currentSection",
",",
"'canonical'",
"=>",
"$",
"documentation",
"->",
"canonical",
",",
"]",
",",
"$",
"documentation",
"->",
"statusCode",
")",
";",
"}"
]
| Show a documentation page.
@param $version
@param null $page
@return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector
@throws \Illuminate\Auth\Access\AuthorizationException | [
"Show",
"a",
"documentation",
"page",
"."
]
| d59a639c633cd51fbcc7f607db1513a04f93d213 | https://github.com/saleem-hadad/larecipe/blob/d59a639c633cd51fbcc7f607db1513a04f93d213/src/Http/Controllers/DocumentationController.php#L52-L79 | train |
spatie/laravel-analytics | src/AnalyticsClient.php | AnalyticsClient.performQuery | public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [])
{
$cacheName = $this->determineCacheName(func_get_args());
if ($this->cacheLifeTimeInMinutes == 0) {
$this->cache->forget($cacheName);
}
return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use ($viewId, $startDate, $endDate, $metrics, $others) {
$result = $this->service->data_ga->get(
"ga:{$viewId}",
$startDate->format('Y-m-d'),
$endDate->format('Y-m-d'),
$metrics,
$others
);
while ($nextLink = $result->getNextLink()) {
if (isset($others['max-results']) && count($result->rows) >= $others['max-results']) {
break;
}
$options = [];
parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);
$response = $this->service->data_ga->call('get', [$options], 'Google_Service_Analytics_GaData');
if ($response->rows) {
$result->rows = array_merge($result->rows, $response->rows);
}
$result->nextLink = $response->nextLink;
}
return $result;
});
} | php | public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [])
{
$cacheName = $this->determineCacheName(func_get_args());
if ($this->cacheLifeTimeInMinutes == 0) {
$this->cache->forget($cacheName);
}
return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use ($viewId, $startDate, $endDate, $metrics, $others) {
$result = $this->service->data_ga->get(
"ga:{$viewId}",
$startDate->format('Y-m-d'),
$endDate->format('Y-m-d'),
$metrics,
$others
);
while ($nextLink = $result->getNextLink()) {
if (isset($others['max-results']) && count($result->rows) >= $others['max-results']) {
break;
}
$options = [];
parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);
$response = $this->service->data_ga->call('get', [$options], 'Google_Service_Analytics_GaData');
if ($response->rows) {
$result->rows = array_merge($result->rows, $response->rows);
}
$result->nextLink = $response->nextLink;
}
return $result;
});
} | [
"public",
"function",
"performQuery",
"(",
"string",
"$",
"viewId",
",",
"DateTime",
"$",
"startDate",
",",
"DateTime",
"$",
"endDate",
",",
"string",
"$",
"metrics",
",",
"array",
"$",
"others",
"=",
"[",
"]",
")",
"{",
"$",
"cacheName",
"=",
"$",
"this",
"->",
"determineCacheName",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cacheLifeTimeInMinutes",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"forget",
"(",
"$",
"cacheName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"->",
"remember",
"(",
"$",
"cacheName",
",",
"$",
"this",
"->",
"cacheLifeTimeInMinutes",
",",
"function",
"(",
")",
"use",
"(",
"$",
"viewId",
",",
"$",
"startDate",
",",
"$",
"endDate",
",",
"$",
"metrics",
",",
"$",
"others",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"service",
"->",
"data_ga",
"->",
"get",
"(",
"\"ga:{$viewId}\"",
",",
"$",
"startDate",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"$",
"endDate",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"$",
"metrics",
",",
"$",
"others",
")",
";",
"while",
"(",
"$",
"nextLink",
"=",
"$",
"result",
"->",
"getNextLink",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"others",
"[",
"'max-results'",
"]",
")",
"&&",
"count",
"(",
"$",
"result",
"->",
"rows",
")",
">=",
"$",
"others",
"[",
"'max-results'",
"]",
")",
"{",
"break",
";",
"}",
"$",
"options",
"=",
"[",
"]",
";",
"parse_str",
"(",
"substr",
"(",
"$",
"nextLink",
",",
"strpos",
"(",
"$",
"nextLink",
",",
"'?'",
")",
"+",
"1",
")",
",",
"$",
"options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"data_ga",
"->",
"call",
"(",
"'get'",
",",
"[",
"$",
"options",
"]",
",",
"'Google_Service_Analytics_GaData'",
")",
";",
"if",
"(",
"$",
"response",
"->",
"rows",
")",
"{",
"$",
"result",
"->",
"rows",
"=",
"array_merge",
"(",
"$",
"result",
"->",
"rows",
",",
"$",
"response",
"->",
"rows",
")",
";",
"}",
"$",
"result",
"->",
"nextLink",
"=",
"$",
"response",
"->",
"nextLink",
";",
"}",
"return",
"$",
"result",
";",
"}",
")",
";",
"}"
]
| Query the Google Analytics Service with given parameters.
@param string $viewId
@param \DateTime $startDate
@param \DateTime $endDate
@param string $metrics
@param array $others
@return array|null | [
"Query",
"the",
"Google",
"Analytics",
"Service",
"with",
"given",
"parameters",
"."
]
| 368ec15bd8b15f5c435e5d89d4898cf03e33b635 | https://github.com/spatie/laravel-analytics/blob/368ec15bd8b15f5c435e5d89d4898cf03e33b635/src/AnalyticsClient.php#L52-L89 | train |
spatie/laravel-analytics | src/Analytics.php | Analytics.performQuery | public function performQuery(Period $period, string $metrics, array $others = [])
{
return $this->client->performQuery(
$this->viewId,
$period->startDate,
$period->endDate,
$metrics,
$others
);
} | php | public function performQuery(Period $period, string $metrics, array $others = [])
{
return $this->client->performQuery(
$this->viewId,
$period->startDate,
$period->endDate,
$metrics,
$others
);
} | [
"public",
"function",
"performQuery",
"(",
"Period",
"$",
"period",
",",
"string",
"$",
"metrics",
",",
"array",
"$",
"others",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"performQuery",
"(",
"$",
"this",
"->",
"viewId",
",",
"$",
"period",
"->",
"startDate",
",",
"$",
"period",
"->",
"endDate",
",",
"$",
"metrics",
",",
"$",
"others",
")",
";",
"}"
]
| Call the query method on the authenticated client.
@param Period $period
@param string $metrics
@param array $others
@return array|null | [
"Call",
"the",
"query",
"method",
"on",
"the",
"authenticated",
"client",
"."
]
| 368ec15bd8b15f5c435e5d89d4898cf03e33b635 | https://github.com/spatie/laravel-analytics/blob/368ec15bd8b15f5c435e5d89d4898cf03e33b635/src/Analytics.php#L181-L190 | train |
smalot/pdfparser | src/Smalot/PdfParser/Header.php | Header.getElements | public function getElements()
{
foreach ($this->elements as $name => $element) {
$this->resolveXRef($name);
}
return $this->elements;
} | php | public function getElements()
{
foreach ($this->elements as $name => $element) {
$this->resolveXRef($name);
}
return $this->elements;
} | [
"public",
"function",
"getElements",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"name",
"=>",
"$",
"element",
")",
"{",
"$",
"this",
"->",
"resolveXRef",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"elements",
";",
"}"
]
| Returns all elements.
@return mixed | [
"Returns",
"all",
"elements",
"."
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Header.php#L70-L77 | train |
smalot/pdfparser | src/Smalot/PdfParser/Header.php | Header.getElementTypes | public function getElementTypes()
{
$types = array();
foreach ($this->elements as $key => $element) {
$types[$key] = get_class($element);
}
return $types;
} | php | public function getElementTypes()
{
$types = array();
foreach ($this->elements as $key => $element) {
$types[$key] = get_class($element);
}
return $types;
} | [
"public",
"function",
"getElementTypes",
"(",
")",
"{",
"$",
"types",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"{",
"$",
"types",
"[",
"$",
"key",
"]",
"=",
"get_class",
"(",
"$",
"element",
")",
";",
"}",
"return",
"$",
"types",
";",
"}"
]
| Used only for debug.
@return array | [
"Used",
"only",
"for",
"debug",
"."
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Header.php#L84-L93 | train |
smalot/pdfparser | src/Smalot/PdfParser/Header.php | Header.resolveXRef | protected function resolveXRef($name)
{
if (($obj = $this->elements[$name]) instanceof ElementXRef && !is_null($this->document)) {
/** @var ElementXRef $obj */
$object = $this->document->getObjectById($obj->getId());
if (is_null($object)) {
return new ElementMissing(null, null);
}
// Update elements list for future calls.
$this->elements[$name] = $object;
}
return $this->elements[$name];
} | php | protected function resolveXRef($name)
{
if (($obj = $this->elements[$name]) instanceof ElementXRef && !is_null($this->document)) {
/** @var ElementXRef $obj */
$object = $this->document->getObjectById($obj->getId());
if (is_null($object)) {
return new ElementMissing(null, null);
}
// Update elements list for future calls.
$this->elements[$name] = $object;
}
return $this->elements[$name];
} | [
"protected",
"function",
"resolveXRef",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"(",
"$",
"obj",
"=",
"$",
"this",
"->",
"elements",
"[",
"$",
"name",
"]",
")",
"instanceof",
"ElementXRef",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"document",
")",
")",
"{",
"/** @var ElementXRef $obj */",
"$",
"object",
"=",
"$",
"this",
"->",
"document",
"->",
"getObjectById",
"(",
"$",
"obj",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"object",
")",
")",
"{",
"return",
"new",
"ElementMissing",
"(",
"null",
",",
"null",
")",
";",
"}",
"// Update elements list for future calls.",
"$",
"this",
"->",
"elements",
"[",
"$",
"name",
"]",
"=",
"$",
"object",
";",
"}",
"return",
"$",
"this",
"->",
"elements",
"[",
"$",
"name",
"]",
";",
"}"
]
| Resolve XRef to object.
@param string $name
@return Element|PDFObject
@throws \Exception | [
"Resolve",
"XRef",
"to",
"object",
"."
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Header.php#L160-L175 | train |
smalot/pdfparser | src/Smalot/PdfParser/Page.php | Page.getXObjects | public function getXObjects()
{
if (!is_null($this->xobjects)) {
return $this->xobjects;
}
$resources = $this->get('Resources');
if (method_exists($resources, 'has') && $resources->has('XObject')) {
if ($resources->get('XObject') instanceof Header) {
$xobjects = $resources->get('XObject')->getElements();
} else {
$xobjects = $resources->get('XObject')->getHeader()->getElements();
}
$table = array();
foreach ($xobjects as $id => $xobject) {
$table[$id] = $xobject;
// Store too on cleaned id value (only numeric)
$id = preg_replace('/[^0-9\.\-_]/', '', $id);
if ($id != '') {
$table[$id] = $xobject;
}
}
return ($this->xobjects = $table);
} else {
return array();
}
} | php | public function getXObjects()
{
if (!is_null($this->xobjects)) {
return $this->xobjects;
}
$resources = $this->get('Resources');
if (method_exists($resources, 'has') && $resources->has('XObject')) {
if ($resources->get('XObject') instanceof Header) {
$xobjects = $resources->get('XObject')->getElements();
} else {
$xobjects = $resources->get('XObject')->getHeader()->getElements();
}
$table = array();
foreach ($xobjects as $id => $xobject) {
$table[$id] = $xobject;
// Store too on cleaned id value (only numeric)
$id = preg_replace('/[^0-9\.\-_]/', '', $id);
if ($id != '') {
$table[$id] = $xobject;
}
}
return ($this->xobjects = $table);
} else {
return array();
}
} | [
"public",
"function",
"getXObjects",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"xobjects",
")",
")",
"{",
"return",
"$",
"this",
"->",
"xobjects",
";",
"}",
"$",
"resources",
"=",
"$",
"this",
"->",
"get",
"(",
"'Resources'",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"resources",
",",
"'has'",
")",
"&&",
"$",
"resources",
"->",
"has",
"(",
"'XObject'",
")",
")",
"{",
"if",
"(",
"$",
"resources",
"->",
"get",
"(",
"'XObject'",
")",
"instanceof",
"Header",
")",
"{",
"$",
"xobjects",
"=",
"$",
"resources",
"->",
"get",
"(",
"'XObject'",
")",
"->",
"getElements",
"(",
")",
";",
"}",
"else",
"{",
"$",
"xobjects",
"=",
"$",
"resources",
"->",
"get",
"(",
"'XObject'",
")",
"->",
"getHeader",
"(",
")",
"->",
"getElements",
"(",
")",
";",
"}",
"$",
"table",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xobjects",
"as",
"$",
"id",
"=>",
"$",
"xobject",
")",
"{",
"$",
"table",
"[",
"$",
"id",
"]",
"=",
"$",
"xobject",
";",
"// Store too on cleaned id value (only numeric)",
"$",
"id",
"=",
"preg_replace",
"(",
"'/[^0-9\\.\\-_]/'",
",",
"''",
",",
"$",
"id",
")",
";",
"if",
"(",
"$",
"id",
"!=",
"''",
")",
"{",
"$",
"table",
"[",
"$",
"id",
"]",
"=",
"$",
"xobject",
";",
"}",
"}",
"return",
"(",
"$",
"this",
"->",
"xobjects",
"=",
"$",
"table",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
]
| Support for XObject
@return PDFObject[] | [
"Support",
"for",
"XObject"
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Page.php#L121-L153 | train |
smalot/pdfparser | src/Smalot/PdfParser/Document.php | Document.buildDictionary | protected function buildDictionary()
{
// Build dictionary.
$this->dictionary = array();
foreach ($this->objects as $id => $object) {
$type = $object->getHeader()->get('Type')->getContent();
if (!empty($type)) {
$this->dictionary[$type][$id] = $id;
}
}
} | php | protected function buildDictionary()
{
// Build dictionary.
$this->dictionary = array();
foreach ($this->objects as $id => $object) {
$type = $object->getHeader()->get('Type')->getContent();
if (!empty($type)) {
$this->dictionary[$type][$id] = $id;
}
}
} | [
"protected",
"function",
"buildDictionary",
"(",
")",
"{",
"// Build dictionary.",
"$",
"this",
"->",
"dictionary",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"objects",
"as",
"$",
"id",
"=>",
"$",
"object",
")",
"{",
"$",
"type",
"=",
"$",
"object",
"->",
"getHeader",
"(",
")",
"->",
"get",
"(",
"'Type'",
")",
"->",
"getContent",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"dictionary",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"id",
";",
"}",
"}",
"}"
]
| Build dictionary based on type header field. | [
"Build",
"dictionary",
"based",
"on",
"type",
"header",
"field",
"."
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Document.php#L97-L109 | train |
smalot/pdfparser | src/Smalot/PdfParser/Document.php | Document.buildDetails | protected function buildDetails()
{
// Build details array.
$details = array();
// Extract document info
if ($this->trailer->has('Info')) {
/** @var PDFObject $info */
$info = $this->trailer->get('Info');
// This could be an ElementMissing object, so we need to check for
// the getHeader method first.
if ($info !== null && method_exists($info, 'getHeader')) {
$details = $info->getHeader()->getDetails();
}
}
// Retrieve the page count
try {
$pages = $this->getPages();
$details['Pages'] = count($pages);
} catch (\Exception $e) {
$details['Pages'] = 0;
}
$this->details = $details;
} | php | protected function buildDetails()
{
// Build details array.
$details = array();
// Extract document info
if ($this->trailer->has('Info')) {
/** @var PDFObject $info */
$info = $this->trailer->get('Info');
// This could be an ElementMissing object, so we need to check for
// the getHeader method first.
if ($info !== null && method_exists($info, 'getHeader')) {
$details = $info->getHeader()->getDetails();
}
}
// Retrieve the page count
try {
$pages = $this->getPages();
$details['Pages'] = count($pages);
} catch (\Exception $e) {
$details['Pages'] = 0;
}
$this->details = $details;
} | [
"protected",
"function",
"buildDetails",
"(",
")",
"{",
"// Build details array.",
"$",
"details",
"=",
"array",
"(",
")",
";",
"// Extract document info",
"if",
"(",
"$",
"this",
"->",
"trailer",
"->",
"has",
"(",
"'Info'",
")",
")",
"{",
"/** @var PDFObject $info */",
"$",
"info",
"=",
"$",
"this",
"->",
"trailer",
"->",
"get",
"(",
"'Info'",
")",
";",
"// This could be an ElementMissing object, so we need to check for",
"// the getHeader method first.",
"if",
"(",
"$",
"info",
"!==",
"null",
"&&",
"method_exists",
"(",
"$",
"info",
",",
"'getHeader'",
")",
")",
"{",
"$",
"details",
"=",
"$",
"info",
"->",
"getHeader",
"(",
")",
"->",
"getDetails",
"(",
")",
";",
"}",
"}",
"// Retrieve the page count",
"try",
"{",
"$",
"pages",
"=",
"$",
"this",
"->",
"getPages",
"(",
")",
";",
"$",
"details",
"[",
"'Pages'",
"]",
"=",
"count",
"(",
"$",
"pages",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"details",
"[",
"'Pages'",
"]",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"details",
"=",
"$",
"details",
";",
"}"
]
| Build details array. | [
"Build",
"details",
"array",
"."
]
| 0c85b15e6950a2c6be44db680cb136792a715d94 | https://github.com/smalot/pdfparser/blob/0c85b15e6950a2c6be44db680cb136792a715d94/src/Smalot/PdfParser/Document.php#L114-L139 | train |
kiddyuchina/Beanbun | src/Lib/BloomFilter.php | BloomFilter.positions | protected function positions($value)
{
mt_srand(crc32($value));
$positions = new SplFixedArray($this->k);
for ($i = 0; $i < $this->k; $i++) {
$positions[$i] = mt_rand(1, $this->m);
}
return $positions;
} | php | protected function positions($value)
{
mt_srand(crc32($value));
$positions = new SplFixedArray($this->k);
for ($i = 0; $i < $this->k; $i++) {
$positions[$i] = mt_rand(1, $this->m);
}
return $positions;
} | [
"protected",
"function",
"positions",
"(",
"$",
"value",
")",
"{",
"mt_srand",
"(",
"crc32",
"(",
"$",
"value",
")",
")",
";",
"$",
"positions",
"=",
"new",
"SplFixedArray",
"(",
"$",
"this",
"->",
"k",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"k",
";",
"$",
"i",
"++",
")",
"{",
"$",
"positions",
"[",
"$",
"i",
"]",
"=",
"mt_rand",
"(",
"1",
",",
"$",
"this",
"->",
"m",
")",
";",
"}",
"return",
"$",
"positions",
";",
"}"
]
| Calculates the positions a value hashes to in the bitfield.
@param string $value The value to insert into the bitfield.
@return SplFixedArray Array containing the numeric positions in the bitfield. | [
"Calculates",
"the",
"positions",
"a",
"value",
"hashes",
"to",
"in",
"the",
"bitfield",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/BloomFilter.php#L120-L128 | train |
kiddyuchina/Beanbun | src/Lib/BloomFilter.php | BloomFilter.add | public function add($value)
{
foreach ($this->positions($value) as $position) {
$this->setBitAtPosition($position);
}
} | php | public function add($value)
{
foreach ($this->positions($value) as $position) {
$this->setBitAtPosition($position);
}
} | [
"public",
"function",
"add",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"positions",
"(",
"$",
"value",
")",
"as",
"$",
"position",
")",
"{",
"$",
"this",
"->",
"setBitAtPosition",
"(",
"$",
"position",
")",
";",
"}",
"}"
]
| Add a value into the set.
@param string $value | [
"Add",
"a",
"value",
"into",
"the",
"set",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/BloomFilter.php#L135-L140 | train |
kiddyuchina/Beanbun | src/Lib/BloomFilter.php | BloomFilter.maybeInSet | public function maybeInSet($value)
{
foreach ($this->positions($value) as $position) {
if (!$this->getBitAtPosition($position)) {
return false;
}
}
return true;
} | php | public function maybeInSet($value)
{
foreach ($this->positions($value) as $position) {
if (!$this->getBitAtPosition($position)) {
return false;
}
}
return true;
} | [
"public",
"function",
"maybeInSet",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"positions",
"(",
"$",
"value",
")",
"as",
"$",
"position",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getBitAtPosition",
"(",
"$",
"position",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Checks if the value may have been added to the set before.
False positives are possible, false negatives are not.
@param string $value
@return boolean | [
"Checks",
"if",
"the",
"value",
"may",
"have",
"been",
"added",
"to",
"the",
"set",
"before",
".",
"False",
"positives",
"are",
"possible",
"false",
"negatives",
"are",
"not",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/BloomFilter.php#L149-L157 | train |
kiddyuchina/Beanbun | src/Lib/BloomFilter.php | BloomFilter.showBitField | public function showBitField()
{
return join(array_map(function ($chr) {return str_pad(base_convert(bin2hex($chr), 16, 2), 8, '0', STR_PAD_LEFT);}, str_split($this->bitField)));
} | php | public function showBitField()
{
return join(array_map(function ($chr) {return str_pad(base_convert(bin2hex($chr), 16, 2), 8, '0', STR_PAD_LEFT);}, str_split($this->bitField)));
} | [
"public",
"function",
"showBitField",
"(",
")",
"{",
"return",
"join",
"(",
"array_map",
"(",
"function",
"(",
"$",
"chr",
")",
"{",
"return",
"str_pad",
"(",
"base_convert",
"(",
"bin2hex",
"(",
"$",
"chr",
")",
",",
"16",
",",
"2",
")",
",",
"8",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
",",
"str_split",
"(",
"$",
"this",
"->",
"bitField",
")",
")",
")",
";",
"}"
]
| Returns an ASCII representation of the current bit field.
@return string | [
"Returns",
"an",
"ASCII",
"representation",
"of",
"the",
"current",
"bit",
"field",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/BloomFilter.php#L164-L167 | train |
kiddyuchina/Beanbun | src/Lib/Client.php | Client.getConnection | protected function getConnection($key)
{
$offset = crc32($key) % count($this->_globalServers);
if ($offset < 0) {
$offset = -$offset;
}
if (!isset($this->_globalConnections[$offset]) || feof($this->_globalConnections[$offset])) {
$connection = stream_socket_client("tcp://{$this->_globalServers[$offset]}", $code, $msg, $this->timeout);
if (!$connection) {
throw new \Exception($msg);
}
stream_set_timeout($connection, $this->timeout);
if (class_exists('\Workerman\Lib\Timer') && php_sapi_name() === 'cli') {
$timer_id = \Workerman\Lib\Timer::add($this->pingInterval, function ($connection) use (&$timer_id) {
$buffer = pack('N', 8) . "ping";
if (strlen($buffer) !== @fwrite($connection, $buffer)) {
@fclose($connection);
\Workerman\Lib\Timer::del($timer_id);
}
}, array($connection));
}
$this->_globalConnections[$offset] = $connection;
}
return $this->_globalConnections[$offset];
} | php | protected function getConnection($key)
{
$offset = crc32($key) % count($this->_globalServers);
if ($offset < 0) {
$offset = -$offset;
}
if (!isset($this->_globalConnections[$offset]) || feof($this->_globalConnections[$offset])) {
$connection = stream_socket_client("tcp://{$this->_globalServers[$offset]}", $code, $msg, $this->timeout);
if (!$connection) {
throw new \Exception($msg);
}
stream_set_timeout($connection, $this->timeout);
if (class_exists('\Workerman\Lib\Timer') && php_sapi_name() === 'cli') {
$timer_id = \Workerman\Lib\Timer::add($this->pingInterval, function ($connection) use (&$timer_id) {
$buffer = pack('N', 8) . "ping";
if (strlen($buffer) !== @fwrite($connection, $buffer)) {
@fclose($connection);
\Workerman\Lib\Timer::del($timer_id);
}
}, array($connection));
}
$this->_globalConnections[$offset] = $connection;
}
return $this->_globalConnections[$offset];
} | [
"protected",
"function",
"getConnection",
"(",
"$",
"key",
")",
"{",
"$",
"offset",
"=",
"crc32",
"(",
"$",
"key",
")",
"%",
"count",
"(",
"$",
"this",
"->",
"_globalServers",
")",
";",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"$",
"offset",
"=",
"-",
"$",
"offset",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_globalConnections",
"[",
"$",
"offset",
"]",
")",
"||",
"feof",
"(",
"$",
"this",
"->",
"_globalConnections",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"$",
"connection",
"=",
"stream_socket_client",
"(",
"\"tcp://{$this->_globalServers[$offset]}\"",
",",
"$",
"code",
",",
"$",
"msg",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"if",
"(",
"!",
"$",
"connection",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"msg",
")",
";",
"}",
"stream_set_timeout",
"(",
"$",
"connection",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"if",
"(",
"class_exists",
"(",
"'\\Workerman\\Lib\\Timer'",
")",
"&&",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
")",
"{",
"$",
"timer_id",
"=",
"\\",
"Workerman",
"\\",
"Lib",
"\\",
"Timer",
"::",
"add",
"(",
"$",
"this",
"->",
"pingInterval",
",",
"function",
"(",
"$",
"connection",
")",
"use",
"(",
"&",
"$",
"timer_id",
")",
"{",
"$",
"buffer",
"=",
"pack",
"(",
"'N'",
",",
"8",
")",
".",
"\"ping\"",
";",
"if",
"(",
"strlen",
"(",
"$",
"buffer",
")",
"!==",
"@",
"fwrite",
"(",
"$",
"connection",
",",
"$",
"buffer",
")",
")",
"{",
"@",
"fclose",
"(",
"$",
"connection",
")",
";",
"\\",
"Workerman",
"\\",
"Lib",
"\\",
"Timer",
"::",
"del",
"(",
"$",
"timer_id",
")",
";",
"}",
"}",
",",
"array",
"(",
"$",
"connection",
")",
")",
";",
"}",
"$",
"this",
"->",
"_globalConnections",
"[",
"$",
"offset",
"]",
"=",
"$",
"connection",
";",
"}",
"return",
"$",
"this",
"->",
"_globalConnections",
"[",
"$",
"offset",
"]",
";",
"}"
]
| Connect to global server.
@throws \Exception | [
"Connect",
"to",
"global",
"server",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/Client.php#L56-L81 | train |
kiddyuchina/Beanbun | src/Lib/Client.php | Client.writeToRemote | protected function writeToRemote($data, $connection)
{
$buffer = serialize($data);
$buffer = pack('N', 4 + strlen($buffer)) . $buffer;
$len = fwrite($connection, $buffer);
if ($len !== strlen($buffer)) {
throw new \Exception('writeToRemote fail');
}
} | php | protected function writeToRemote($data, $connection)
{
$buffer = serialize($data);
$buffer = pack('N', 4 + strlen($buffer)) . $buffer;
$len = fwrite($connection, $buffer);
if ($len !== strlen($buffer)) {
throw new \Exception('writeToRemote fail');
}
} | [
"protected",
"function",
"writeToRemote",
"(",
"$",
"data",
",",
"$",
"connection",
")",
"{",
"$",
"buffer",
"=",
"serialize",
"(",
"$",
"data",
")",
";",
"$",
"buffer",
"=",
"pack",
"(",
"'N'",
",",
"4",
"+",
"strlen",
"(",
"$",
"buffer",
")",
")",
".",
"$",
"buffer",
";",
"$",
"len",
"=",
"fwrite",
"(",
"$",
"connection",
",",
"$",
"buffer",
")",
";",
"if",
"(",
"$",
"len",
"!==",
"strlen",
"(",
"$",
"buffer",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'writeToRemote fail'",
")",
";",
"}",
"}"
]
| Write data to global server.
@param string $buffer | [
"Write",
"data",
"to",
"global",
"server",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/Client.php#L406-L414 | train |
kiddyuchina/Beanbun | src/Lib/Client.php | Client.readFromRemote | protected function readFromRemote($connection)
{
$all_buffer = '';
$total_len = 4;
$head_read = false;
while (1) {
$buffer = fread($connection, 8192);
if ($buffer === '' || $buffer === false) {
throw new \Exception('readFromRemote fail');
}
$all_buffer .= $buffer;
$recv_len = strlen($all_buffer);
if ($recv_len >= $total_len) {
if ($head_read) {
break;
}
$unpack_data = unpack('Ntotal_length', $all_buffer);
$total_len = $unpack_data['total_length'];
if ($recv_len >= $total_len) {
break;
}
$head_read = true;
}
}
return unserialize(substr($all_buffer, 4));
} | php | protected function readFromRemote($connection)
{
$all_buffer = '';
$total_len = 4;
$head_read = false;
while (1) {
$buffer = fread($connection, 8192);
if ($buffer === '' || $buffer === false) {
throw new \Exception('readFromRemote fail');
}
$all_buffer .= $buffer;
$recv_len = strlen($all_buffer);
if ($recv_len >= $total_len) {
if ($head_read) {
break;
}
$unpack_data = unpack('Ntotal_length', $all_buffer);
$total_len = $unpack_data['total_length'];
if ($recv_len >= $total_len) {
break;
}
$head_read = true;
}
}
return unserialize(substr($all_buffer, 4));
} | [
"protected",
"function",
"readFromRemote",
"(",
"$",
"connection",
")",
"{",
"$",
"all_buffer",
"=",
"''",
";",
"$",
"total_len",
"=",
"4",
";",
"$",
"head_read",
"=",
"false",
";",
"while",
"(",
"1",
")",
"{",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"connection",
",",
"8192",
")",
";",
"if",
"(",
"$",
"buffer",
"===",
"''",
"||",
"$",
"buffer",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'readFromRemote fail'",
")",
";",
"}",
"$",
"all_buffer",
".=",
"$",
"buffer",
";",
"$",
"recv_len",
"=",
"strlen",
"(",
"$",
"all_buffer",
")",
";",
"if",
"(",
"$",
"recv_len",
">=",
"$",
"total_len",
")",
"{",
"if",
"(",
"$",
"head_read",
")",
"{",
"break",
";",
"}",
"$",
"unpack_data",
"=",
"unpack",
"(",
"'Ntotal_length'",
",",
"$",
"all_buffer",
")",
";",
"$",
"total_len",
"=",
"$",
"unpack_data",
"[",
"'total_length'",
"]",
";",
"if",
"(",
"$",
"recv_len",
">=",
"$",
"total_len",
")",
"{",
"break",
";",
"}",
"$",
"head_read",
"=",
"true",
";",
"}",
"}",
"return",
"unserialize",
"(",
"substr",
"(",
"$",
"all_buffer",
",",
"4",
")",
")",
";",
"}"
]
| Read data from global server.
@throws Exception | [
"Read",
"data",
"from",
"global",
"server",
"."
]
| 696a9681b7bc0425af7a783176dad43ab613fdc8 | https://github.com/kiddyuchina/Beanbun/blob/696a9681b7bc0425af7a783176dad43ab613fdc8/src/Lib/Client.php#L420-L445 | train |
acquia/blt | src/Robo/Commands/Composer/ComposerCommand.php | ComposerCommand.requirePackage | public function requirePackage($package_name, $package_version, $options = ['dev' => FALSE]) {
/** @var \Robo\Task\Composer\RequireDependency $task */
$task = $this->taskComposerRequire()
->printOutput(TRUE)
->printMetadata(TRUE)
->dir($this->getConfigValue('repo.root'))
->interactive($this->input()->isInteractive())
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);
if ($options['dev']) {
$task->dev(TRUE);
}
if ($package_version) {
$task->dependency($package_name, $package_version);
}
else {
$task->dependency($package_name);
}
$result = $task->run();
if (!$result->wasSuccessful()) {
$this->logger->error("An error occurred while requiring {$package_name}.");
$this->say("This is likely due to an incompatibility with your existing packages or memory exhaustion. See full error output above.");
$confirm = $this->confirm("Should BLT attempt to update all of your Composer packages in order to find a compatible version?");
if ($confirm) {
$command = "composer require '{$package_name}:{$package_version}' --no-update ";
if ($options['dev']) {
$command .= "--dev ";
}
$command .= "&& composer update";
$task = $this->taskExec($command)
->printOutput(TRUE)
->printMetadata(TRUE)
->dir($this->getConfigValue('repo.root'))
->interactive($this->input()->isInteractive())
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);
;
$result = $task->run();
if (!$result->wasSuccessful()) {
throw new BltException("Unable to install {$package_name} package.");
}
}
else {
// @todo Revert previous file changes.
throw new BltException("Unable to install {$package_name} package.");
}
}
return $result;
} | php | public function requirePackage($package_name, $package_version, $options = ['dev' => FALSE]) {
/** @var \Robo\Task\Composer\RequireDependency $task */
$task = $this->taskComposerRequire()
->printOutput(TRUE)
->printMetadata(TRUE)
->dir($this->getConfigValue('repo.root'))
->interactive($this->input()->isInteractive())
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);
if ($options['dev']) {
$task->dev(TRUE);
}
if ($package_version) {
$task->dependency($package_name, $package_version);
}
else {
$task->dependency($package_name);
}
$result = $task->run();
if (!$result->wasSuccessful()) {
$this->logger->error("An error occurred while requiring {$package_name}.");
$this->say("This is likely due to an incompatibility with your existing packages or memory exhaustion. See full error output above.");
$confirm = $this->confirm("Should BLT attempt to update all of your Composer packages in order to find a compatible version?");
if ($confirm) {
$command = "composer require '{$package_name}:{$package_version}' --no-update ";
if ($options['dev']) {
$command .= "--dev ";
}
$command .= "&& composer update";
$task = $this->taskExec($command)
->printOutput(TRUE)
->printMetadata(TRUE)
->dir($this->getConfigValue('repo.root'))
->interactive($this->input()->isInteractive())
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);
;
$result = $task->run();
if (!$result->wasSuccessful()) {
throw new BltException("Unable to install {$package_name} package.");
}
}
else {
// @todo Revert previous file changes.
throw new BltException("Unable to install {$package_name} package.");
}
}
return $result;
} | [
"public",
"function",
"requirePackage",
"(",
"$",
"package_name",
",",
"$",
"package_version",
",",
"$",
"options",
"=",
"[",
"'dev'",
"=>",
"FALSE",
"]",
")",
"{",
"/** @var \\Robo\\Task\\Composer\\RequireDependency $task */",
"$",
"task",
"=",
"$",
"this",
"->",
"taskComposerRequire",
"(",
")",
"->",
"printOutput",
"(",
"TRUE",
")",
"->",
"printMetadata",
"(",
"TRUE",
")",
"->",
"dir",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'repo.root'",
")",
")",
"->",
"interactive",
"(",
"$",
"this",
"->",
"input",
"(",
")",
"->",
"isInteractive",
"(",
")",
")",
"->",
"setVerbosityThreshold",
"(",
"VerbosityThresholdInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'dev'",
"]",
")",
"{",
"$",
"task",
"->",
"dev",
"(",
"TRUE",
")",
";",
"}",
"if",
"(",
"$",
"package_version",
")",
"{",
"$",
"task",
"->",
"dependency",
"(",
"$",
"package_name",
",",
"$",
"package_version",
")",
";",
"}",
"else",
"{",
"$",
"task",
"->",
"dependency",
"(",
"$",
"package_name",
")",
";",
"}",
"$",
"result",
"=",
"$",
"task",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"\"An error occurred while requiring {$package_name}.\"",
")",
";",
"$",
"this",
"->",
"say",
"(",
"\"This is likely due to an incompatibility with your existing packages or memory exhaustion. See full error output above.\"",
")",
";",
"$",
"confirm",
"=",
"$",
"this",
"->",
"confirm",
"(",
"\"Should BLT attempt to update all of your Composer packages in order to find a compatible version?\"",
")",
";",
"if",
"(",
"$",
"confirm",
")",
"{",
"$",
"command",
"=",
"\"composer require '{$package_name}:{$package_version}' --no-update \"",
";",
"if",
"(",
"$",
"options",
"[",
"'dev'",
"]",
")",
"{",
"$",
"command",
".=",
"\"--dev \"",
";",
"}",
"$",
"command",
".=",
"\"&& composer update\"",
";",
"$",
"task",
"=",
"$",
"this",
"->",
"taskExec",
"(",
"$",
"command",
")",
"->",
"printOutput",
"(",
"TRUE",
")",
"->",
"printMetadata",
"(",
"TRUE",
")",
"->",
"dir",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'repo.root'",
")",
")",
"->",
"interactive",
"(",
"$",
"this",
"->",
"input",
"(",
")",
"->",
"isInteractive",
"(",
")",
")",
"->",
"setVerbosityThreshold",
"(",
"VerbosityThresholdInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
";",
"$",
"result",
"=",
"$",
"task",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"Unable to install {$package_name} package.\"",
")",
";",
"}",
"}",
"else",
"{",
"// @todo Revert previous file changes.",
"throw",
"new",
"BltException",
"(",
"\"Unable to install {$package_name} package.\"",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Requires a composer package.
@command internal:composer:require
@hidden
@option dev Whether package should be added to require-dev. | [
"Requires",
"a",
"composer",
"package",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Composer/ComposerCommand.php#L22-L71 | train |
acquia/blt | src/Robo/Hooks/InteractHook.php | InteractHook.interactGenerateSettingsFiles | public function interactGenerateSettingsFiles(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\SetupWizard $setup_wizard */
$setup_wizard = $this->getContainer()->get(SetupWizard::class);
$setup_wizard->wizardGenerateSettingsFiles();
} | php | public function interactGenerateSettingsFiles(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\SetupWizard $setup_wizard */
$setup_wizard = $this->getContainer()->get(SetupWizard::class);
$setup_wizard->wizardGenerateSettingsFiles();
} | [
"public",
"function",
"interactGenerateSettingsFiles",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"AnnotationData",
"$",
"annotationData",
")",
"{",
"/** @var \\Acquia\\Blt\\Robo\\Wizards\\SetupWizard $setup_wizard */",
"$",
"setup_wizard",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"SetupWizard",
"::",
"class",
")",
";",
"$",
"setup_wizard",
"->",
"wizardGenerateSettingsFiles",
"(",
")",
";",
"}"
]
| Runs wizard for generating settings files.
@hook interact @interactGenerateSettingsFiles | [
"Runs",
"wizard",
"for",
"generating",
"settings",
"files",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Hooks/InteractHook.php#L40-L48 | train |
acquia/blt | src/Robo/Hooks/InteractHook.php | InteractHook.interactInstallDrupal | public function interactInstallDrupal(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\SetupWizard $setup_wizard */
$setup_wizard = $this->getContainer()->get(SetupWizard::class);
$setup_wizard->wizardInstallDrupal();
} | php | public function interactInstallDrupal(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\SetupWizard $setup_wizard */
$setup_wizard = $this->getContainer()->get(SetupWizard::class);
$setup_wizard->wizardInstallDrupal();
} | [
"public",
"function",
"interactInstallDrupal",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"AnnotationData",
"$",
"annotationData",
")",
"{",
"/** @var \\Acquia\\Blt\\Robo\\Wizards\\SetupWizard $setup_wizard */",
"$",
"setup_wizard",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"SetupWizard",
"::",
"class",
")",
";",
"$",
"setup_wizard",
"->",
"wizardInstallDrupal",
"(",
")",
";",
"}"
]
| Runs wizard for installing Drupal.
@hook interact @interactInstallDrupal | [
"Runs",
"wizard",
"for",
"installing",
"Drupal",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Hooks/InteractHook.php#L55-L63 | train |
acquia/blt | src/Robo/Hooks/InteractHook.php | InteractHook.interactConfigureBehat | public function interactConfigureBehat(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\TestsWizard $tests_wizard */
$tests_wizard = $this->getContainer()->get(TestsWizard::class);
$tests_wizard->wizardConfigureBehat();
} | php | public function interactConfigureBehat(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
/** @var \Acquia\Blt\Robo\Wizards\TestsWizard $tests_wizard */
$tests_wizard = $this->getContainer()->get(TestsWizard::class);
$tests_wizard->wizardConfigureBehat();
} | [
"public",
"function",
"interactConfigureBehat",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"AnnotationData",
"$",
"annotationData",
")",
"{",
"/** @var \\Acquia\\Blt\\Robo\\Wizards\\TestsWizard $tests_wizard */",
"$",
"tests_wizard",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"TestsWizard",
"::",
"class",
")",
";",
"$",
"tests_wizard",
"->",
"wizardConfigureBehat",
"(",
")",
";",
"}"
]
| Runs wizard for configuring Behat.
@hook interact @interactConfigureBehat | [
"Runs",
"wizard",
"for",
"configuring",
"Behat",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Hooks/InteractHook.php#L70-L78 | train |
acquia/blt | src/Robo/Hooks/InteractHook.php | InteractHook.interactExecuteUpdates | public function interactExecuteUpdates(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
if ($this->invokeDepth == 0
&& $input->getFirstArgument() != 'blt:update'
&& $input->getFirstArgument() != 'update'
&& !$this->getInspector()->isSchemaVersionUpToDate()) {
$this->logger->warning("Your BLT schema is out of date.");
if (!$input->isInteractive()) {
$this->logger->warning("Run `blt blt:update` to update it.");
}
$confirm = $this->confirm("Would you like to run outstanding updates?");
if ($confirm) {
$this->invokeCommand('blt:update');
}
}
} | php | public function interactExecuteUpdates(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
if ($this->invokeDepth == 0
&& $input->getFirstArgument() != 'blt:update'
&& $input->getFirstArgument() != 'update'
&& !$this->getInspector()->isSchemaVersionUpToDate()) {
$this->logger->warning("Your BLT schema is out of date.");
if (!$input->isInteractive()) {
$this->logger->warning("Run `blt blt:update` to update it.");
}
$confirm = $this->confirm("Would you like to run outstanding updates?");
if ($confirm) {
$this->invokeCommand('blt:update');
}
}
} | [
"public",
"function",
"interactExecuteUpdates",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"AnnotationData",
"$",
"annotationData",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"invokeDepth",
"==",
"0",
"&&",
"$",
"input",
"->",
"getFirstArgument",
"(",
")",
"!=",
"'blt:update'",
"&&",
"$",
"input",
"->",
"getFirstArgument",
"(",
")",
"!=",
"'update'",
"&&",
"!",
"$",
"this",
"->",
"getInspector",
"(",
")",
"->",
"isSchemaVersionUpToDate",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Your BLT schema is out of date.\"",
")",
";",
"if",
"(",
"!",
"$",
"input",
"->",
"isInteractive",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Run `blt blt:update` to update it.\"",
")",
";",
"}",
"$",
"confirm",
"=",
"$",
"this",
"->",
"confirm",
"(",
"\"Would you like to run outstanding updates?\"",
")",
";",
"if",
"(",
"$",
"confirm",
")",
"{",
"$",
"this",
"->",
"invokeCommand",
"(",
"'blt:update'",
")",
";",
"}",
"}",
"}"
]
| Executes outstanding updates.
@hook interact * | [
"Executes",
"outstanding",
"updates",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Hooks/InteractHook.php#L85-L103 | train |
acquia/blt | src/Robo/Hooks/InteractHook.php | InteractHook.interactConfigIdentical | public function interactConfigIdentical(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
$cm_strategies = [
'config-split',
'core-only',
];
if (in_array($this->getConfigValue('cm.strategy'), $cm_strategies) && $this->getInspector()->isDrupalInstalled()) {
if (!$this->getInspector()->isActiveConfigIdentical()) {
$this->logger->warning("The active configuration is not identical to the configuration in the export directory.");
$this->logger->warning("This means that you have not exported all of your active configuration.");
$this->logger->warning("Run <comment>drush cex</comment> to export the active config to the sync directory.");
if ($this->input()->isInteractive()) {
$this->logger->warning("Continuing will overwrite the active configuration.");
$confirm = $this->confirm("Continue?");
if (!$confirm) {
throw new BltException("The active configuration is not identical to the configuration in the export directory.");
}
}
}
}
} | php | public function interactConfigIdentical(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
$cm_strategies = [
'config-split',
'core-only',
];
if (in_array($this->getConfigValue('cm.strategy'), $cm_strategies) && $this->getInspector()->isDrupalInstalled()) {
if (!$this->getInspector()->isActiveConfigIdentical()) {
$this->logger->warning("The active configuration is not identical to the configuration in the export directory.");
$this->logger->warning("This means that you have not exported all of your active configuration.");
$this->logger->warning("Run <comment>drush cex</comment> to export the active config to the sync directory.");
if ($this->input()->isInteractive()) {
$this->logger->warning("Continuing will overwrite the active configuration.");
$confirm = $this->confirm("Continue?");
if (!$confirm) {
throw new BltException("The active configuration is not identical to the configuration in the export directory.");
}
}
}
}
} | [
"public",
"function",
"interactConfigIdentical",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"AnnotationData",
"$",
"annotationData",
")",
"{",
"$",
"cm_strategies",
"=",
"[",
"'config-split'",
",",
"'core-only'",
",",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'cm.strategy'",
")",
",",
"$",
"cm_strategies",
")",
"&&",
"$",
"this",
"->",
"getInspector",
"(",
")",
"->",
"isDrupalInstalled",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getInspector",
"(",
")",
"->",
"isActiveConfigIdentical",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"The active configuration is not identical to the configuration in the export directory.\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"This means that you have not exported all of your active configuration.\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Run <comment>drush cex</comment> to export the active config to the sync directory.\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"input",
"(",
")",
"->",
"isInteractive",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Continuing will overwrite the active configuration.\"",
")",
";",
"$",
"confirm",
"=",
"$",
"this",
"->",
"confirm",
"(",
"\"Continue?\"",
")",
";",
"if",
"(",
"!",
"$",
"confirm",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"The active configuration is not identical to the configuration in the export directory.\"",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Prompts user to confirm overwrite of active config on blt setup.
@hook interact @interactConfigIdentical | [
"Prompts",
"user",
"to",
"confirm",
"overwrite",
"of",
"active",
"config",
"on",
"blt",
"setup",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Hooks/InteractHook.php#L110-L133 | train |
acquia/blt | src/Robo/Commands/Doctor/NodeCheck.php | NodeCheck.checkNodeVersionFileExists | protected function checkNodeVersionFileExists() {
if (file_exists($this->getConfigValue('repo.root') . '/.nvmrc')) {
$this->logProblem(__FUNCTION__, ".nvmrc file exists", 'info');
}
elseif (file_exists($this->getConfigValue('repo.root') . '/.node-version')) {
$this->logProblem(__FUNCTION__, ".node-version file exists", 'info');
}
else {
$this->logProblem(__FUNCTION__, "Neither .nvmrc nor .node-version file found in repo root.", 'comment');
}
} | php | protected function checkNodeVersionFileExists() {
if (file_exists($this->getConfigValue('repo.root') . '/.nvmrc')) {
$this->logProblem(__FUNCTION__, ".nvmrc file exists", 'info');
}
elseif (file_exists($this->getConfigValue('repo.root') . '/.node-version')) {
$this->logProblem(__FUNCTION__, ".node-version file exists", 'info');
}
else {
$this->logProblem(__FUNCTION__, "Neither .nvmrc nor .node-version file found in repo root.", 'comment');
}
} | [
"protected",
"function",
"checkNodeVersionFileExists",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'repo.root'",
")",
".",
"'/.nvmrc'",
")",
")",
"{",
"$",
"this",
"->",
"logProblem",
"(",
"__FUNCTION__",
",",
"\".nvmrc file exists\"",
",",
"'info'",
")",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'repo.root'",
")",
".",
"'/.node-version'",
")",
")",
"{",
"$",
"this",
"->",
"logProblem",
"(",
"__FUNCTION__",
",",
"\".node-version file exists\"",
",",
"'info'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logProblem",
"(",
"__FUNCTION__",
",",
"\"Neither .nvmrc nor .node-version file found in repo root.\"",
",",
"'comment'",
")",
";",
"}",
"}"
]
| Checks that one of .nvmrc or .node-version exists in repo root. | [
"Checks",
"that",
"one",
"of",
".",
"nvmrc",
"or",
".",
"node",
"-",
"version",
"exists",
"in",
"repo",
"root",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Doctor/NodeCheck.php#L17-L27 | train |
acquia/blt | src/Robo/Commands/Setup/ImportCommand.php | ImportCommand.import | public function import() {
$task = $this->taskDrush()
->drush('sql-drop')
->drush('sql-cli < ' . $this->getConfigValue('setup.dump-file'));
$result = $task->run();
$exit_code = $result->getExitCode();
if ($exit_code) {
throw new BltException("Unable to import setup.dump-file.");
}
} | php | public function import() {
$task = $this->taskDrush()
->drush('sql-drop')
->drush('sql-cli < ' . $this->getConfigValue('setup.dump-file'));
$result = $task->run();
$exit_code = $result->getExitCode();
if ($exit_code) {
throw new BltException("Unable to import setup.dump-file.");
}
} | [
"public",
"function",
"import",
"(",
")",
"{",
"$",
"task",
"=",
"$",
"this",
"->",
"taskDrush",
"(",
")",
"->",
"drush",
"(",
"'sql-drop'",
")",
"->",
"drush",
"(",
"'sql-cli < '",
".",
"$",
"this",
"->",
"getConfigValue",
"(",
"'setup.dump-file'",
")",
")",
";",
"$",
"result",
"=",
"$",
"task",
"->",
"run",
"(",
")",
";",
"$",
"exit_code",
"=",
"$",
"result",
"->",
"getExitCode",
"(",
")",
";",
"if",
"(",
"$",
"exit_code",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"Unable to import setup.dump-file.\"",
")",
";",
"}",
"}"
]
| Imports a .sql file into the Drupal database.
@command drupal:sql:import
@aliases dsi
@validateDrushConfig
@executeInVm | [
"Imports",
"a",
".",
"sql",
"file",
"into",
"the",
"Drupal",
"database",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Setup/ImportCommand.php#L23-L33 | train |
acquia/blt | src/Robo/Commands/Generate/MultisiteCommand.php | MultisiteCommand.generate | public function generate($options = [
'site-dir' => InputOption::VALUE_REQUIRED,
'site-uri' => InputOption::VALUE_REQUIRED,
'remote-alias' => InputOption::VALUE_REQUIRED,
]) {
$this->say("This will generate a new site in the docroot/sites directory.");
$site_name = $this->getNewSiteName($options);
$new_site_dir = $this->getConfigValue('docroot') . '/sites/' . $site_name;
if (file_exists($new_site_dir)) {
throw new BltException("Cannot generate new multisite, $new_site_dir already exists!");
}
$domain = $this->getNewSiteDoman($options, $site_name);
$url = parse_url($domain);
// @todo Validate uri, ensure includes scheme.
$newDBSettings = $this->setLocalDbConfig();
if ($this->getInspector()->isDrupalVmConfigPresent()) {
$this->configureDrupalVm($url, $site_name, $newDBSettings);
}
$default_site_dir = $this->getConfigValue('docroot') . '/sites/default';
$this->createDefaultBltSiteYml($default_site_dir);
$this->createSiteDrushAlias('default');
$this->createNewSiteDir($default_site_dir, $new_site_dir);
$remote_alias = $this->getNewSiteRemoteAlias($site_name, $options);
$this->createNewBltSiteYml($new_site_dir, $site_name, $url, $remote_alias);
$this->createNewSiteConfigDir($site_name);
$this->createSiteDrushAlias($site_name);
$this->resetMultisiteConfig();
$this->invokeCommand('blt:init:settings');
$this->say("New site generated at <comment>$new_site_dir</comment>");
$this->say("Drush aliases generated:");
if (!file_exists($default_site_dir . "/blt.yml")) {
$this->say(" * @default.local");
}
$this->say(" * @$remote_alias");
$this->say("Config directory created for new site at <comment>config/$site_name</comment>");
} | php | public function generate($options = [
'site-dir' => InputOption::VALUE_REQUIRED,
'site-uri' => InputOption::VALUE_REQUIRED,
'remote-alias' => InputOption::VALUE_REQUIRED,
]) {
$this->say("This will generate a new site in the docroot/sites directory.");
$site_name = $this->getNewSiteName($options);
$new_site_dir = $this->getConfigValue('docroot') . '/sites/' . $site_name;
if (file_exists($new_site_dir)) {
throw new BltException("Cannot generate new multisite, $new_site_dir already exists!");
}
$domain = $this->getNewSiteDoman($options, $site_name);
$url = parse_url($domain);
// @todo Validate uri, ensure includes scheme.
$newDBSettings = $this->setLocalDbConfig();
if ($this->getInspector()->isDrupalVmConfigPresent()) {
$this->configureDrupalVm($url, $site_name, $newDBSettings);
}
$default_site_dir = $this->getConfigValue('docroot') . '/sites/default';
$this->createDefaultBltSiteYml($default_site_dir);
$this->createSiteDrushAlias('default');
$this->createNewSiteDir($default_site_dir, $new_site_dir);
$remote_alias = $this->getNewSiteRemoteAlias($site_name, $options);
$this->createNewBltSiteYml($new_site_dir, $site_name, $url, $remote_alias);
$this->createNewSiteConfigDir($site_name);
$this->createSiteDrushAlias($site_name);
$this->resetMultisiteConfig();
$this->invokeCommand('blt:init:settings');
$this->say("New site generated at <comment>$new_site_dir</comment>");
$this->say("Drush aliases generated:");
if (!file_exists($default_site_dir . "/blt.yml")) {
$this->say(" * @default.local");
}
$this->say(" * @$remote_alias");
$this->say("Config directory created for new site at <comment>config/$site_name</comment>");
} | [
"public",
"function",
"generate",
"(",
"$",
"options",
"=",
"[",
"'site-dir'",
"=>",
"InputOption",
"::",
"VALUE_REQUIRED",
",",
"'site-uri'",
"=>",
"InputOption",
"::",
"VALUE_REQUIRED",
",",
"'remote-alias'",
"=>",
"InputOption",
"::",
"VALUE_REQUIRED",
",",
"]",
")",
"{",
"$",
"this",
"->",
"say",
"(",
"\"This will generate a new site in the docroot/sites directory.\"",
")",
";",
"$",
"site_name",
"=",
"$",
"this",
"->",
"getNewSiteName",
"(",
"$",
"options",
")",
";",
"$",
"new_site_dir",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'docroot'",
")",
".",
"'/sites/'",
".",
"$",
"site_name",
";",
"if",
"(",
"file_exists",
"(",
"$",
"new_site_dir",
")",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"Cannot generate new multisite, $new_site_dir already exists!\"",
")",
";",
"}",
"$",
"domain",
"=",
"$",
"this",
"->",
"getNewSiteDoman",
"(",
"$",
"options",
",",
"$",
"site_name",
")",
";",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"domain",
")",
";",
"// @todo Validate uri, ensure includes scheme.",
"$",
"newDBSettings",
"=",
"$",
"this",
"->",
"setLocalDbConfig",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getInspector",
"(",
")",
"->",
"isDrupalVmConfigPresent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"configureDrupalVm",
"(",
"$",
"url",
",",
"$",
"site_name",
",",
"$",
"newDBSettings",
")",
";",
"}",
"$",
"default_site_dir",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'docroot'",
")",
".",
"'/sites/default'",
";",
"$",
"this",
"->",
"createDefaultBltSiteYml",
"(",
"$",
"default_site_dir",
")",
";",
"$",
"this",
"->",
"createSiteDrushAlias",
"(",
"'default'",
")",
";",
"$",
"this",
"->",
"createNewSiteDir",
"(",
"$",
"default_site_dir",
",",
"$",
"new_site_dir",
")",
";",
"$",
"remote_alias",
"=",
"$",
"this",
"->",
"getNewSiteRemoteAlias",
"(",
"$",
"site_name",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"createNewBltSiteYml",
"(",
"$",
"new_site_dir",
",",
"$",
"site_name",
",",
"$",
"url",
",",
"$",
"remote_alias",
")",
";",
"$",
"this",
"->",
"createNewSiteConfigDir",
"(",
"$",
"site_name",
")",
";",
"$",
"this",
"->",
"createSiteDrushAlias",
"(",
"$",
"site_name",
")",
";",
"$",
"this",
"->",
"resetMultisiteConfig",
"(",
")",
";",
"$",
"this",
"->",
"invokeCommand",
"(",
"'blt:init:settings'",
")",
";",
"$",
"this",
"->",
"say",
"(",
"\"New site generated at <comment>$new_site_dir</comment>\"",
")",
";",
"$",
"this",
"->",
"say",
"(",
"\"Drush aliases generated:\"",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"default_site_dir",
".",
"\"/blt.yml\"",
")",
")",
"{",
"$",
"this",
"->",
"say",
"(",
"\" * @default.local\"",
")",
";",
"}",
"$",
"this",
"->",
"say",
"(",
"\" * @$remote_alias\"",
")",
";",
"$",
"this",
"->",
"say",
"(",
"\"Config directory created for new site at <comment>config/$site_name</comment>\"",
")",
";",
"}"
]
| Generates a new multisite.
@command recipes:multisite:init
@aliases rmi multisite | [
"Generates",
"a",
"new",
"multisite",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Generate/MultisiteCommand.php#L26-L68 | train |
acquia/blt | src/Robo/Commands/Generate/MultisiteCommand.php | MultisiteCommand.setLocalDbConfig | protected function setLocalDbConfig() {
$config_local_db = $this->confirm("Would you like to configure the local database credentials?");
$db = [];
if ($config_local_db) {
$default_db = $this->getConfigValue('drupal.db');
$db['database'] = $this->askDefault("Local database name",
$default_db['database']);
$db['username'] = $this->askDefault("Local database user",
$default_db['username']);
$db['password'] = $this->askDefault("Local database password",
$default_db['password']);
$db['host'] = $this->askDefault("Local database host",
$default_db['host']);
$db['port'] = $this->askDefault("Local database port",
$default_db['port']);
$this->getConfig()->set('drupal.db', $db);
}
return $db;
} | php | protected function setLocalDbConfig() {
$config_local_db = $this->confirm("Would you like to configure the local database credentials?");
$db = [];
if ($config_local_db) {
$default_db = $this->getConfigValue('drupal.db');
$db['database'] = $this->askDefault("Local database name",
$default_db['database']);
$db['username'] = $this->askDefault("Local database user",
$default_db['username']);
$db['password'] = $this->askDefault("Local database password",
$default_db['password']);
$db['host'] = $this->askDefault("Local database host",
$default_db['host']);
$db['port'] = $this->askDefault("Local database port",
$default_db['port']);
$this->getConfig()->set('drupal.db', $db);
}
return $db;
} | [
"protected",
"function",
"setLocalDbConfig",
"(",
")",
"{",
"$",
"config_local_db",
"=",
"$",
"this",
"->",
"confirm",
"(",
"\"Would you like to configure the local database credentials?\"",
")",
";",
"$",
"db",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"config_local_db",
")",
"{",
"$",
"default_db",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.db'",
")",
";",
"$",
"db",
"[",
"'database'",
"]",
"=",
"$",
"this",
"->",
"askDefault",
"(",
"\"Local database name\"",
",",
"$",
"default_db",
"[",
"'database'",
"]",
")",
";",
"$",
"db",
"[",
"'username'",
"]",
"=",
"$",
"this",
"->",
"askDefault",
"(",
"\"Local database user\"",
",",
"$",
"default_db",
"[",
"'username'",
"]",
")",
";",
"$",
"db",
"[",
"'password'",
"]",
"=",
"$",
"this",
"->",
"askDefault",
"(",
"\"Local database password\"",
",",
"$",
"default_db",
"[",
"'password'",
"]",
")",
";",
"$",
"db",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"askDefault",
"(",
"\"Local database host\"",
",",
"$",
"default_db",
"[",
"'host'",
"]",
")",
";",
"$",
"db",
"[",
"'port'",
"]",
"=",
"$",
"this",
"->",
"askDefault",
"(",
"\"Local database port\"",
",",
"$",
"default_db",
"[",
"'port'",
"]",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"set",
"(",
"'drupal.db'",
",",
"$",
"db",
")",
";",
"}",
"return",
"$",
"db",
";",
"}"
]
| Prompts for and sets config for new database.
@return array
Empty array if user did not want to configure local db. Populated array
otherwise. | [
"Prompts",
"for",
"and",
"sets",
"config",
"for",
"new",
"database",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Generate/MultisiteCommand.php#L120-L140 | train |
acquia/blt | src/Update/Updater.php | Updater.setRepoRoot | public function setRepoRoot($repoRoot) {
if (!$this->fs->exists($repoRoot)) {
throw new FileNotFoundException();
}
$this->repoRoot = $repoRoot;
} | php | public function setRepoRoot($repoRoot) {
if (!$this->fs->exists($repoRoot)) {
throw new FileNotFoundException();
}
$this->repoRoot = $repoRoot;
} | [
"public",
"function",
"setRepoRoot",
"(",
"$",
"repoRoot",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"repoRoot",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"repoRoot",
"=",
"$",
"repoRoot",
";",
"}"
]
| The filepath of the repository root directory.
This directory is expected to contain the composer.json that defines
acquia/blt as a dependency.
@param string $repoRoot
The filepath of the repository root directory. | [
"The",
"filepath",
"of",
"the",
"repository",
"root",
"directory",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L118-L124 | train |
acquia/blt | src/Update/Updater.php | Updater.executeUpdates | public function executeUpdates($updates) {
/** @var Updates $updates_object */
$updates_object = new $this->updateClassName($this);
$this->output->writeln("Executing updates...");
/**
* @var string $method_name
* @var Update $update
*/
foreach ($updates as $method_name => $update) {
$this->output->writeln("-> $method_name: {$update->description}");
call_user_func([$updates_object, $method_name]);
}
} | php | public function executeUpdates($updates) {
/** @var Updates $updates_object */
$updates_object = new $this->updateClassName($this);
$this->output->writeln("Executing updates...");
/**
* @var string $method_name
* @var Update $update
*/
foreach ($updates as $method_name => $update) {
$this->output->writeln("-> $method_name: {$update->description}");
call_user_func([$updates_object, $method_name]);
}
} | [
"public",
"function",
"executeUpdates",
"(",
"$",
"updates",
")",
"{",
"/** @var Updates $updates_object */",
"$",
"updates_object",
"=",
"new",
"$",
"this",
"->",
"updateClassName",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"Executing updates...\"",
")",
";",
"/**\n * @var string $method_name\n * @var Update $update\n */",
"foreach",
"(",
"$",
"updates",
"as",
"$",
"method_name",
"=>",
"$",
"update",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"-> $method_name: {$update->description}\"",
")",
";",
"call_user_func",
"(",
"[",
"$",
"updates_object",
",",
"$",
"method_name",
"]",
")",
";",
"}",
"}"
]
| Executes an array of updates.
@param $updates \Acquia\Blt\Annotations\Update[] | [
"Executes",
"an",
"array",
"of",
"updates",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L165-L178 | train |
acquia/blt | src/Update/Updater.php | Updater.printUpdates | public function printUpdates($updates) {
/**
* @var string $method_name
* @var Update $update
*/
foreach ($updates as $method_name => $update) {
$this->output->writeln(" - $method_name: {$update->description}");
}
$this->output->writeln('');
} | php | public function printUpdates($updates) {
/**
* @var string $method_name
* @var Update $update
*/
foreach ($updates as $method_name => $update) {
$this->output->writeln(" - $method_name: {$update->description}");
}
$this->output->writeln('');
} | [
"public",
"function",
"printUpdates",
"(",
"$",
"updates",
")",
"{",
"/**\n * @var string $method_name\n * @var Update $update\n */",
"foreach",
"(",
"$",
"updates",
"as",
"$",
"method_name",
"=>",
"$",
"update",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\" - $method_name: {$update->description}\"",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}"
]
| Prints a human-readable list of update methods to the screen.
@param $updates \Acquia\Blt\Annotations\Update[] | [
"Prints",
"a",
"human",
"-",
"readable",
"list",
"of",
"update",
"methods",
"to",
"the",
"screen",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L185-L194 | train |
acquia/blt | src/Update/Updater.php | Updater.getUpdates | public function getUpdates($starting_version, $ending_version = NULL) {
if (!$ending_version) {
$ending_version = $this->getLatestUpdateMethodVersion();
}
$updates = [];
$update_methods = $this->getAllUpdateMethods();
/**
* @var string $method_name
* @var Update $metadata
*/
foreach ($update_methods as $method_name => $metadata) {
$version = $metadata->version;
if (($version > $starting_version) && $version <= $ending_version) {
$updates[$method_name] = $metadata;
}
}
return $updates;
} | php | public function getUpdates($starting_version, $ending_version = NULL) {
if (!$ending_version) {
$ending_version = $this->getLatestUpdateMethodVersion();
}
$updates = [];
$update_methods = $this->getAllUpdateMethods();
/**
* @var string $method_name
* @var Update $metadata
*/
foreach ($update_methods as $method_name => $metadata) {
$version = $metadata->version;
if (($version > $starting_version) && $version <= $ending_version) {
$updates[$method_name] = $metadata;
}
}
return $updates;
} | [
"public",
"function",
"getUpdates",
"(",
"$",
"starting_version",
",",
"$",
"ending_version",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"ending_version",
")",
"{",
"$",
"ending_version",
"=",
"$",
"this",
"->",
"getLatestUpdateMethodVersion",
"(",
")",
";",
"}",
"$",
"updates",
"=",
"[",
"]",
";",
"$",
"update_methods",
"=",
"$",
"this",
"->",
"getAllUpdateMethods",
"(",
")",
";",
"/**\n * @var string $method_name\n * @var Update $metadata\n */",
"foreach",
"(",
"$",
"update_methods",
"as",
"$",
"method_name",
"=>",
"$",
"metadata",
")",
"{",
"$",
"version",
"=",
"$",
"metadata",
"->",
"version",
";",
"if",
"(",
"(",
"$",
"version",
">",
"$",
"starting_version",
")",
"&&",
"$",
"version",
"<=",
"$",
"ending_version",
")",
"{",
"$",
"updates",
"[",
"$",
"method_name",
"]",
"=",
"$",
"metadata",
";",
"}",
"}",
"return",
"$",
"updates",
";",
"}"
]
| Gets all applicable updates for a given version delta.
@param string $starting_version
The starting version, e.g., 8005000.
@param string $ending_version
The ending version, e.g., 8005001.
@return array
An array of applicable update methods, keyed by method name. Each row
contains the metadata from the Update annotation. | [
"Gets",
"all",
"applicable",
"updates",
"for",
"a",
"given",
"version",
"delta",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L209-L230 | train |
acquia/blt | src/Update/Updater.php | Updater.getAllUpdateMethods | public function getAllUpdateMethods() {
$update_methods = [];
$methods = get_class_methods($this->updateClassName);
foreach ($methods as $method_name) {
$reflectionMethod = new \ReflectionMethod($this->updateClassName, $method_name);
$annotations = $this->annotationsReader->getMethodAnnotation($reflectionMethod, 'Acquia\Blt\Annotations\Update');
if ($annotations) {
$update_methods[$method_name] = $annotations;
}
}
return $update_methods;
} | php | public function getAllUpdateMethods() {
$update_methods = [];
$methods = get_class_methods($this->updateClassName);
foreach ($methods as $method_name) {
$reflectionMethod = new \ReflectionMethod($this->updateClassName, $method_name);
$annotations = $this->annotationsReader->getMethodAnnotation($reflectionMethod, 'Acquia\Blt\Annotations\Update');
if ($annotations) {
$update_methods[$method_name] = $annotations;
}
}
return $update_methods;
} | [
"public",
"function",
"getAllUpdateMethods",
"(",
")",
"{",
"$",
"update_methods",
"=",
"[",
"]",
";",
"$",
"methods",
"=",
"get_class_methods",
"(",
"$",
"this",
"->",
"updateClassName",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method_name",
")",
"{",
"$",
"reflectionMethod",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
"->",
"updateClassName",
",",
"$",
"method_name",
")",
";",
"$",
"annotations",
"=",
"$",
"this",
"->",
"annotationsReader",
"->",
"getMethodAnnotation",
"(",
"$",
"reflectionMethod",
",",
"'Acquia\\Blt\\Annotations\\Update'",
")",
";",
"if",
"(",
"$",
"annotations",
")",
"{",
"$",
"update_methods",
"[",
"$",
"method_name",
"]",
"=",
"$",
"annotations",
";",
"}",
"}",
"return",
"$",
"update_methods",
";",
"}"
]
| Gather an array of all available update methods.
This will only return methods using the Update annotation.
@see drupal_get_schema_versions() | [
"Gather",
"an",
"array",
"of",
"all",
"available",
"update",
"methods",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L239-L251 | train |
acquia/blt | src/Update/Updater.php | Updater.removeComposerPatch | public function removeComposerPatch($package, $url) {
$composer_json = $this->getComposerJson();
if (!empty($composer_json['extra']['patches'][$package])) {
foreach ($composer_json['extra']['patches'][$package] as $key => $patch_url) {
if ($patch_url == $url) {
unset($composer_json['extra']['patches'][$package][$key]);
// If that was the only patch for this module, unset the parent too.
if (empty($composer_json['extra']['patches'][$package])) {
unset($composer_json['extra']['patches'][$package]);
}
$this->writeComposerJson($composer_json);
return TRUE;
}
}
}
return FALSE;
} | php | public function removeComposerPatch($package, $url) {
$composer_json = $this->getComposerJson();
if (!empty($composer_json['extra']['patches'][$package])) {
foreach ($composer_json['extra']['patches'][$package] as $key => $patch_url) {
if ($patch_url == $url) {
unset($composer_json['extra']['patches'][$package][$key]);
// If that was the only patch for this module, unset the parent too.
if (empty($composer_json['extra']['patches'][$package])) {
unset($composer_json['extra']['patches'][$package]);
}
$this->writeComposerJson($composer_json);
return TRUE;
}
}
}
return FALSE;
} | [
"public",
"function",
"removeComposerPatch",
"(",
"$",
"package",
",",
"$",
"url",
")",
"{",
"$",
"composer_json",
"=",
"$",
"this",
"->",
"getComposerJson",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"composer_json",
"[",
"'extra'",
"]",
"[",
"'patches'",
"]",
"[",
"$",
"package",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"composer_json",
"[",
"'extra'",
"]",
"[",
"'patches'",
"]",
"[",
"$",
"package",
"]",
"as",
"$",
"key",
"=>",
"$",
"patch_url",
")",
"{",
"if",
"(",
"$",
"patch_url",
"==",
"$",
"url",
")",
"{",
"unset",
"(",
"$",
"composer_json",
"[",
"'extra'",
"]",
"[",
"'patches'",
"]",
"[",
"$",
"package",
"]",
"[",
"$",
"key",
"]",
")",
";",
"// If that was the only patch for this module, unset the parent too.",
"if",
"(",
"empty",
"(",
"$",
"composer_json",
"[",
"'extra'",
"]",
"[",
"'patches'",
"]",
"[",
"$",
"package",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"composer_json",
"[",
"'extra'",
"]",
"[",
"'patches'",
"]",
"[",
"$",
"package",
"]",
")",
";",
"}",
"$",
"this",
"->",
"writeComposerJson",
"(",
"$",
"composer_json",
")",
";",
"return",
"TRUE",
";",
"}",
"}",
"}",
"return",
"FALSE",
";",
"}"
]
| Removes a patch from repo's root composer.json file.
@param string $package
The composer package name, e.g., 'drupal/features'.
@param string $url
The URL of the patch.
@return bool
TRUE if patch was removed, otherwise FALSE. | [
"Removes",
"a",
"patch",
"from",
"repo",
"s",
"root",
"composer",
".",
"json",
"file",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L315-L332 | train |
acquia/blt | src/Update/Updater.php | Updater.writeComposerJson | public function writeComposerJson($contents) {
// Ensure that require and require-dev are objects and not arrays.
if (array_key_exists('require', $contents) && is_array($contents['require'])) {
ksort($contents['require']);
$contents['require'] = (object) $contents['require'];
}
if (array_key_exists('require-dev', $contents)&& is_array($contents['require-dev'])) {
ksort($contents['require-dev']);
$contents['require-dev'] = (object) $contents['require-dev'];
}
file_put_contents($this->composerJsonFilepath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} | php | public function writeComposerJson($contents) {
// Ensure that require and require-dev are objects and not arrays.
if (array_key_exists('require', $contents) && is_array($contents['require'])) {
ksort($contents['require']);
$contents['require'] = (object) $contents['require'];
}
if (array_key_exists('require-dev', $contents)&& is_array($contents['require-dev'])) {
ksort($contents['require-dev']);
$contents['require-dev'] = (object) $contents['require-dev'];
}
file_put_contents($this->composerJsonFilepath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} | [
"public",
"function",
"writeComposerJson",
"(",
"$",
"contents",
")",
"{",
"// Ensure that require and require-dev are objects and not arrays.",
"if",
"(",
"array_key_exists",
"(",
"'require'",
",",
"$",
"contents",
")",
"&&",
"is_array",
"(",
"$",
"contents",
"[",
"'require'",
"]",
")",
")",
"{",
"ksort",
"(",
"$",
"contents",
"[",
"'require'",
"]",
")",
";",
"$",
"contents",
"[",
"'require'",
"]",
"=",
"(",
"object",
")",
"$",
"contents",
"[",
"'require'",
"]",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'require-dev'",
",",
"$",
"contents",
")",
"&&",
"is_array",
"(",
"$",
"contents",
"[",
"'require-dev'",
"]",
")",
")",
"{",
"ksort",
"(",
"$",
"contents",
"[",
"'require-dev'",
"]",
")",
";",
"$",
"contents",
"[",
"'require-dev'",
"]",
"=",
"(",
"object",
")",
"$",
"contents",
"[",
"'require-dev'",
"]",
";",
"}",
"file_put_contents",
"(",
"$",
"this",
"->",
"composerJsonFilepath",
",",
"json_encode",
"(",
"$",
"contents",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
]
| Writes an array to composer.json.
@param array $contents
The new contents of composer.json. | [
"Writes",
"an",
"array",
"to",
"composer",
".",
"json",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L437-L448 | train |
acquia/blt | src/Update/Updater.php | Updater.moveFile | public function moveFile($source, $target, $overwrite = FALSE) {
$source_path = $this->getRepoRoot() . '/' . $source;
$target_path = $this->getRepoRoot() . '/' . $target;
if ($this->getFileSystem()->exists($source)) {
if ($overwrite) {
$this->getFileSystem()->rename($source_path, $target_path, TRUE);
}
// We "fail" silently if target file already exists. The default behavior
// is quiet and non-destructive.
elseif (!$this->getFileSystem()->exists($target_path)) {
$this->getFileSystem()->rename($source_path, $target_path);
}
}
return FALSE;
} | php | public function moveFile($source, $target, $overwrite = FALSE) {
$source_path = $this->getRepoRoot() . '/' . $source;
$target_path = $this->getRepoRoot() . '/' . $target;
if ($this->getFileSystem()->exists($source)) {
if ($overwrite) {
$this->getFileSystem()->rename($source_path, $target_path, TRUE);
}
// We "fail" silently if target file already exists. The default behavior
// is quiet and non-destructive.
elseif (!$this->getFileSystem()->exists($target_path)) {
$this->getFileSystem()->rename($source_path, $target_path);
}
}
return FALSE;
} | [
"public",
"function",
"moveFile",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"overwrite",
"=",
"FALSE",
")",
"{",
"$",
"source_path",
"=",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/'",
".",
"$",
"source",
";",
"$",
"target_path",
"=",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/'",
".",
"$",
"target",
";",
"if",
"(",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"exists",
"(",
"$",
"source",
")",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"rename",
"(",
"$",
"source_path",
",",
"$",
"target_path",
",",
"TRUE",
")",
";",
"}",
"// We \"fail\" silently if target file already exists. The default behavior",
"// is quiet and non-destructive.",
"elseif",
"(",
"!",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"exists",
"(",
"$",
"target_path",
")",
")",
"{",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"rename",
"(",
"$",
"source_path",
",",
"$",
"target_path",
")",
";",
"}",
"}",
"return",
"FALSE",
";",
"}"
]
| Moves a file from one location to another, relative to repo root.
@param string $source
The source filepath, relative to the repository root.
@param string $target
The target filepath, relative to the repository root.
@return bool
FALSE if nothing happened. | [
"Moves",
"a",
"file",
"from",
"one",
"location",
"to",
"another",
"relative",
"to",
"repo",
"root",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L489-L505 | train |
acquia/blt | src/Update/Updater.php | Updater.syncWithTemplate | public function syncWithTemplate($filePath, $overwrite = FALSE) {
$sourcePath = $this->getBltRoot() . '/template/' . $filePath;
$targetPath = $this->getRepoRoot() . '/' . $filePath;
if ($this->getFileSystem()->exists($sourcePath)) {
try {
$this->getFileSystem()->copy($sourcePath, $targetPath, $overwrite);
}
catch (IOException $e) {
throw $e;
}
}
} | php | public function syncWithTemplate($filePath, $overwrite = FALSE) {
$sourcePath = $this->getBltRoot() . '/template/' . $filePath;
$targetPath = $this->getRepoRoot() . '/' . $filePath;
if ($this->getFileSystem()->exists($sourcePath)) {
try {
$this->getFileSystem()->copy($sourcePath, $targetPath, $overwrite);
}
catch (IOException $e) {
throw $e;
}
}
} | [
"public",
"function",
"syncWithTemplate",
"(",
"$",
"filePath",
",",
"$",
"overwrite",
"=",
"FALSE",
")",
"{",
"$",
"sourcePath",
"=",
"$",
"this",
"->",
"getBltRoot",
"(",
")",
".",
"'/template/'",
".",
"$",
"filePath",
";",
"$",
"targetPath",
"=",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/'",
".",
"$",
"filePath",
";",
"if",
"(",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"exists",
"(",
"$",
"sourcePath",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"copy",
"(",
"$",
"sourcePath",
",",
"$",
"targetPath",
",",
"$",
"overwrite",
")",
";",
"}",
"catch",
"(",
"IOException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
]
| Copies a file from the BLT template to the repository.
@param string $filePath
The filepath, relative to the BLT template directory.
@param bool $overwrite
If true, target files newer than origin files are overwritten. | [
"Copies",
"a",
"file",
"from",
"the",
"BLT",
"template",
"to",
"the",
"repository",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L515-L528 | train |
acquia/blt | src/Update/Updater.php | Updater.replaceInFile | public function replaceInFile($source, $original, $replacement) {
$source_path = $this->getRepoRoot() . '/' . $source;
if ($this->getFileSystem()->exists($source)) {
$contents = file_get_contents($source_path);
$new_contents = str_replace($original, $replacement, $contents);
file_put_contents($source_path, $new_contents);
}
} | php | public function replaceInFile($source, $original, $replacement) {
$source_path = $this->getRepoRoot() . '/' . $source;
if ($this->getFileSystem()->exists($source)) {
$contents = file_get_contents($source_path);
$new_contents = str_replace($original, $replacement, $contents);
file_put_contents($source_path, $new_contents);
}
} | [
"public",
"function",
"replaceInFile",
"(",
"$",
"source",
",",
"$",
"original",
",",
"$",
"replacement",
")",
"{",
"$",
"source_path",
"=",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/'",
".",
"$",
"source",
";",
"if",
"(",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"exists",
"(",
"$",
"source",
")",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"source_path",
")",
";",
"$",
"new_contents",
"=",
"str_replace",
"(",
"$",
"original",
",",
"$",
"replacement",
",",
"$",
"contents",
")",
";",
"file_put_contents",
"(",
"$",
"source_path",
",",
"$",
"new_contents",
")",
";",
"}",
"}"
]
| Performs a find and replace in a text file.
@param string $source
The source filepath, relative to the repository root.
@param string $original
The original string to find.
@param string $replacement
The string with which to replace the original. | [
"Performs",
"a",
"find",
"and",
"replace",
"in",
"a",
"text",
"file",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L540-L547 | train |
acquia/blt | src/Update/Updater.php | Updater.regenerateCloudHooks | public function regenerateCloudHooks() {
if (file_exists($this->getRepoRoot() . '/hooks') && !$this->cloudHooksAlreadyUpdated) {
self::executeCommand("./vendor/bin/blt recipes:cloud-hooks:init", NULL, FALSE);
$this->cloudHooksAlreadyUpdated = TRUE;
return TRUE;
}
return FALSE;
} | php | public function regenerateCloudHooks() {
if (file_exists($this->getRepoRoot() . '/hooks') && !$this->cloudHooksAlreadyUpdated) {
self::executeCommand("./vendor/bin/blt recipes:cloud-hooks:init", NULL, FALSE);
$this->cloudHooksAlreadyUpdated = TRUE;
return TRUE;
}
return FALSE;
} | [
"public",
"function",
"regenerateCloudHooks",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/hooks'",
")",
"&&",
"!",
"$",
"this",
"->",
"cloudHooksAlreadyUpdated",
")",
"{",
"self",
"::",
"executeCommand",
"(",
"\"./vendor/bin/blt recipes:cloud-hooks:init\"",
",",
"NULL",
",",
"FALSE",
")",
";",
"$",
"this",
"->",
"cloudHooksAlreadyUpdated",
"=",
"TRUE",
";",
"return",
"TRUE",
";",
"}",
"return",
"FALSE",
";",
"}"
]
| Regenerate Cloud Hooks, but only once. | [
"Regenerate",
"Cloud",
"Hooks",
"but",
"only",
"once",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Update/Updater.php#L564-L571 | train |
acquia/blt | src/Robo/Application.php | Application.runCommand | public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
return $this->doRunCommand($command, $input, $output);
} | php | public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
return $this->doRunCommand($command, $input, $output);
} | [
"public",
"function",
"runCommand",
"(",
"Command",
"$",
"command",
",",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"return",
"$",
"this",
"->",
"doRunCommand",
"(",
"$",
"command",
",",
"$",
"input",
",",
"$",
"output",
")",
";",
"}"
]
| This command is identical to its parent, but public rather than protected. | [
"This",
"command",
"is",
"identical",
"to",
"its",
"parent",
"but",
"public",
"rather",
"than",
"protected",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Application.php#L21-L23 | train |
acquia/blt | src/Robo/Filesets/Filesets.php | Filesets.getPhpFilesetFinder | protected function getPhpFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.inc")
->name("*.install")
->name("*.module")
->name("*.php")
->name("*.profile")
->name("*.test")
->name("*.theme")
// Behat php files are ignored because method names and comments do not
// conform to Drupal coding standards by default.
->notPath('behat')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | php | protected function getPhpFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.inc")
->name("*.install")
->name("*.module")
->name("*.php")
->name("*.profile")
->name("*.test")
->name("*.theme")
// Behat php files are ignored because method names and comments do not
// conform to Drupal coding standards by default.
->notPath('behat')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | [
"protected",
"function",
"getPhpFilesetFinder",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*.inc\"",
")",
"->",
"name",
"(",
"\"*.install\"",
")",
"->",
"name",
"(",
"\"*.module\"",
")",
"->",
"name",
"(",
"\"*.php\"",
")",
"->",
"name",
"(",
"\"*.profile\"",
")",
"->",
"name",
"(",
"\"*.test\"",
")",
"->",
"name",
"(",
"\"*.theme\"",
")",
"// Behat php files are ignored because method names and comments do not",
"// conform to Drupal coding standards by default.",
"->",
"notPath",
"(",
"'behat'",
")",
"->",
"notPath",
"(",
"'node_modules'",
")",
"->",
"notPath",
"(",
"'vendor'",
")",
";",
"return",
"$",
"finder",
";",
"}"
]
| Adds Drupalistic PHP patterns to a Symfony finder object.
@return \Symfony\Component\Finder\Finder
The finder object. | [
"Adds",
"Drupalistic",
"PHP",
"patterns",
"to",
"a",
"Symfony",
"finder",
"object",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Filesets/Filesets.php#L102-L119 | train |
acquia/blt | src/Robo/Filesets/Filesets.php | Filesets.getFrontendFilesetFinder | protected function getFrontendFilesetFinder() {
$finder = new Finder();
$finder
->files()
->path("*/js/*")
->name("*.js")
->notName('*.min.js')
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | php | protected function getFrontendFilesetFinder() {
$finder = new Finder();
$finder
->files()
->path("*/js/*")
->name("*.js")
->notName('*.min.js')
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | [
"protected",
"function",
"getFrontendFilesetFinder",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"path",
"(",
"\"*/js/*\"",
")",
"->",
"name",
"(",
"\"*.js\"",
")",
"->",
"notName",
"(",
"'*.min.js'",
")",
"->",
"notPath",
"(",
"'bower_components'",
")",
"->",
"notPath",
"(",
"'node_modules'",
")",
"->",
"notPath",
"(",
"'vendor'",
")",
";",
"return",
"$",
"finder",
";",
"}"
]
| Adds Drupalistic JS patterns to a Symfony finder object.
@return \Symfony\Component\Finder\Finder
The finder object. | [
"Adds",
"Drupalistic",
"JS",
"patterns",
"to",
"a",
"Symfony",
"finder",
"object",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Filesets/Filesets.php#L127-L139 | train |
acquia/blt | src/Robo/Filesets/Filesets.php | Filesets.getYamlFilesetFinder | protected function getYamlFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.yml")
->name("*.yaml")
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | php | protected function getYamlFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.yml")
->name("*.yaml")
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | [
"protected",
"function",
"getYamlFilesetFinder",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*.yml\"",
")",
"->",
"name",
"(",
"\"*.yaml\"",
")",
"->",
"notPath",
"(",
"'bower_components'",
")",
"->",
"notPath",
"(",
"'node_modules'",
")",
"->",
"notPath",
"(",
"'vendor'",
")",
";",
"return",
"$",
"finder",
";",
"}"
]
| Adds Drupalistic YAML patterns to a Symfony finder object.
@return \Symfony\Component\Finder\Finder
The finder object. | [
"Adds",
"Drupalistic",
"YAML",
"patterns",
"to",
"a",
"Symfony",
"finder",
"object",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Filesets/Filesets.php#L147-L158 | train |
acquia/blt | src/Robo/Filesets/Filesets.php | Filesets.getTwigFilesetFinder | protected function getTwigFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.twig")
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | php | protected function getTwigFilesetFinder() {
$finder = new Finder();
$finder
->files()
->name("*.twig")
->notPath('bower_components')
->notPath('node_modules')
->notPath('vendor');
return $finder;
} | [
"protected",
"function",
"getTwigFilesetFinder",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*.twig\"",
")",
"->",
"notPath",
"(",
"'bower_components'",
")",
"->",
"notPath",
"(",
"'node_modules'",
")",
"->",
"notPath",
"(",
"'vendor'",
")",
";",
"return",
"$",
"finder",
";",
"}"
]
| Adds Drupalistic Twig patterns to a Symfony finder object.
@return \Symfony\Component\Finder\Finder
The finder object. | [
"Adds",
"Drupalistic",
"Twig",
"patterns",
"to",
"a",
"Symfony",
"finder",
"object",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Filesets/Filesets.php#L166-L176 | train |
acquia/blt | src/Robo/Log/BltLogStyle.php | BltLogStyle.formatMessage | protected function formatMessage($label, $message, $context, $taskNameStyle, $messageStyle = '') {
$message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle);
$message = trim($message);
return $message;
} | php | protected function formatMessage($label, $message, $context, $taskNameStyle, $messageStyle = '') {
$message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle);
$message = trim($message);
return $message;
} | [
"protected",
"function",
"formatMessage",
"(",
"$",
"label",
",",
"$",
"message",
",",
"$",
"context",
",",
"$",
"taskNameStyle",
",",
"$",
"messageStyle",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"parent",
"::",
"formatMessage",
"(",
"$",
"label",
",",
"$",
"message",
",",
"$",
"context",
",",
"$",
"taskNameStyle",
",",
"$",
"messageStyle",
")",
";",
"$",
"message",
"=",
"trim",
"(",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}"
]
| Log style customization for Robo.
@param string $label
The log event label.
@param string $message
The log message.
@param array $context
The context, e.g., $context['time'] for task duration.
@param string $taskNameStyle
The style wrapper for the label, e.g., 'comment' for
'<comment></comment>'.
@param string $messageStyle
The style wrapper for the message, e.g., 'comment' for
'<comment></comment>'.
@return string
The formatted message. | [
"Log",
"style",
"customization",
"for",
"Robo",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Log/BltLogStyle.php#L31-L36 | train |
acquia/blt | src/Robo/Commands/Artifact/AcHooksCommand.php | AcHooksCommand.dbScrub | public function dbScrub($site, $target_env, $db_name, $source_env) {
if (!EnvironmentDetector::isAcsfEnv($site, $target_env)) {
$password = RandomString::string(10, FALSE,
function ($string) {
return !preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $string);
},
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'
);
$this->say("Scrubbing database in $target_env");
$result = $this->taskDrush()
->drush("sql-sanitize --sanitize-password=\"$password\" --yes")
->run();
if (!$result->wasSuccessful()) {
throw new BltException("Failed to sanitize database!");
}
$this->taskDrush()
->drush("cr")
->run();
}
} | php | public function dbScrub($site, $target_env, $db_name, $source_env) {
if (!EnvironmentDetector::isAcsfEnv($site, $target_env)) {
$password = RandomString::string(10, FALSE,
function ($string) {
return !preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $string);
},
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'
);
$this->say("Scrubbing database in $target_env");
$result = $this->taskDrush()
->drush("sql-sanitize --sanitize-password=\"$password\" --yes")
->run();
if (!$result->wasSuccessful()) {
throw new BltException("Failed to sanitize database!");
}
$this->taskDrush()
->drush("cr")
->run();
}
} | [
"public",
"function",
"dbScrub",
"(",
"$",
"site",
",",
"$",
"target_env",
",",
"$",
"db_name",
",",
"$",
"source_env",
")",
"{",
"if",
"(",
"!",
"EnvironmentDetector",
"::",
"isAcsfEnv",
"(",
"$",
"site",
",",
"$",
"target_env",
")",
")",
"{",
"$",
"password",
"=",
"RandomString",
"::",
"string",
"(",
"10",
",",
"FALSE",
",",
"function",
"(",
"$",
"string",
")",
"{",
"return",
"!",
"preg_match",
"(",
"'/[^\\x{80}-\\x{F7} a-z0-9@+_.\\'-]/i'",
",",
"$",
"string",
")",
";",
"}",
",",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'",
")",
";",
"$",
"this",
"->",
"say",
"(",
"\"Scrubbing database in $target_env\"",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"taskDrush",
"(",
")",
"->",
"drush",
"(",
"\"sql-sanitize --sanitize-password=\\\"$password\\\" --yes\"",
")",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"Failed to sanitize database!\"",
")",
";",
"}",
"$",
"this",
"->",
"taskDrush",
"(",
")",
"->",
"drush",
"(",
"\"cr\"",
")",
"->",
"run",
"(",
")",
";",
"}",
"}"
]
| Execute sql-sanitize against a database hosted in AC Cloud.
This is intended to be called from db-scrub.sh cloud hook.
@param string $site
The site name, e.g., site1.
@param string $target_env
The cloud env, e.g., dev
@param string $db_name
The name of the database.
@param string $source_env
The source environment.
@command artifact:ac-hooks:db-scrub
@throws \Exception | [
"Execute",
"sql",
"-",
"sanitize",
"against",
"a",
"database",
"hosted",
"in",
"AC",
"Cloud",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Artifact/AcHooksCommand.php#L136-L155 | train |
acquia/blt | src/Robo/Commands/Artifact/AcHooksCommand.php | AcHooksCommand.sendPostCodeUpdateNotifications | protected function sendPostCodeUpdateNotifications($site, $target_env, $source_branch, $deployed_tag, $success) {
$is_tag = $source_branch != $deployed_tag;
if ($success) {
if ($is_tag) {
$message = "An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.";
}
else {
$message = "An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.";
}
}
else {
$message = "Deployment has FAILED for environment *$site.$target_env*.";
}
$this->notifySlack($success, $message);
} | php | protected function sendPostCodeUpdateNotifications($site, $target_env, $source_branch, $deployed_tag, $success) {
$is_tag = $source_branch != $deployed_tag;
if ($success) {
if ($is_tag) {
$message = "An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.";
}
else {
$message = "An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.";
}
}
else {
$message = "Deployment has FAILED for environment *$site.$target_env*.";
}
$this->notifySlack($success, $message);
} | [
"protected",
"function",
"sendPostCodeUpdateNotifications",
"(",
"$",
"site",
",",
"$",
"target_env",
",",
"$",
"source_branch",
",",
"$",
"deployed_tag",
",",
"$",
"success",
")",
"{",
"$",
"is_tag",
"=",
"$",
"source_branch",
"!=",
"$",
"deployed_tag",
";",
"if",
"(",
"$",
"success",
")",
"{",
"if",
"(",
"$",
"is_tag",
")",
"{",
"$",
"message",
"=",
"\"An updated deployment has been made to *$site.$target_env* using tag *$deployed_tag*.\"",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"An updated deployment has been made to *$site.$target_env* using branch *$source_branch* as *$deployed_tag*.\"",
";",
"}",
"}",
"else",
"{",
"$",
"message",
"=",
"\"Deployment has FAILED for environment *$site.$target_env*.\"",
";",
"}",
"$",
"this",
"->",
"notifySlack",
"(",
"$",
"success",
",",
"$",
"message",
")",
";",
"}"
]
| Sends updates to notification endpoints.
@param $site
@param $target_env
@param $source_branch
@param $deployed_tag
@param $success | [
"Sends",
"updates",
"to",
"notification",
"endpoints",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Artifact/AcHooksCommand.php#L186-L202 | train |
acquia/blt | src/Robo/Commands/Artifact/AcHooksCommand.php | AcHooksCommand.getSlackWebhookUrl | protected function getSlackWebhookUrl() {
if ($this->getConfig()->has('slack.webhook-url')) {
return $this->getConfigValue('slack.webhook-url');
}
elseif (getenv('SLACK_WEBHOOK_URL')) {
return getenv('SLACK_WEBHOOK_URL');
}
$this->say("Slack webhook url not found. To enable Slack notifications, set <comment>slack.webhook-url</comment>.");
return FALSE;
} | php | protected function getSlackWebhookUrl() {
if ($this->getConfig()->has('slack.webhook-url')) {
return $this->getConfigValue('slack.webhook-url');
}
elseif (getenv('SLACK_WEBHOOK_URL')) {
return getenv('SLACK_WEBHOOK_URL');
}
$this->say("Slack webhook url not found. To enable Slack notifications, set <comment>slack.webhook-url</comment>.");
return FALSE;
} | [
"protected",
"function",
"getSlackWebhookUrl",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"has",
"(",
"'slack.webhook-url'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getConfigValue",
"(",
"'slack.webhook-url'",
")",
";",
"}",
"elseif",
"(",
"getenv",
"(",
"'SLACK_WEBHOOK_URL'",
")",
")",
"{",
"return",
"getenv",
"(",
"'SLACK_WEBHOOK_URL'",
")",
";",
"}",
"$",
"this",
"->",
"say",
"(",
"\"Slack webhook url not found. To enable Slack notifications, set <comment>slack.webhook-url</comment>.\"",
")",
";",
"return",
"FALSE",
";",
"}"
]
| Gets slack web url.
@return array|false|mixed|null|string | [
"Gets",
"slack",
"web",
"url",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Artifact/AcHooksCommand.php#L225-L235 | train |
acquia/blt | src/Robo/Commands/Artifact/AcHooksCommand.php | AcHooksCommand.sendSlackNotification | protected function sendSlackNotification($url, $payload) {
$this->say("Sending slack notification...");
$data = "payload=" . json_encode($payload);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
} | php | protected function sendSlackNotification($url, $payload) {
$this->say("Sending slack notification...");
$data = "payload=" . json_encode($payload);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
} | [
"protected",
"function",
"sendSlackNotification",
"(",
"$",
"url",
",",
"$",
"payload",
")",
"{",
"$",
"this",
"->",
"say",
"(",
"\"Sending slack notification...\"",
")",
";",
"$",
"data",
"=",
"\"payload=\"",
".",
"json_encode",
"(",
"$",
"payload",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"POST\"",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"data",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"TRUE",
")",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"}"
]
| Sends a message to a slack channel.
@param $url
@param $payload | [
"Sends",
"a",
"message",
"to",
"a",
"slack",
"channel",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Artifact/AcHooksCommand.php#L243-L252 | train |
acquia/blt | src/Robo/Commands/Artifact/AcHooksCommand.php | AcHooksCommand.updateSites | protected function updateSites($site, $target_env) {
if (EnvironmentDetector::isAhOdeEnv($target_env)) {
$this->updateOdeSites();
}
else {
$this->updateAceSites($target_env);
}
} | php | protected function updateSites($site, $target_env) {
if (EnvironmentDetector::isAhOdeEnv($target_env)) {
$this->updateOdeSites();
}
else {
$this->updateAceSites($target_env);
}
} | [
"protected",
"function",
"updateSites",
"(",
"$",
"site",
",",
"$",
"target_env",
")",
"{",
"if",
"(",
"EnvironmentDetector",
"::",
"isAhOdeEnv",
"(",
"$",
"target_env",
")",
")",
"{",
"$",
"this",
"->",
"updateOdeSites",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"updateAceSites",
"(",
"$",
"target_env",
")",
";",
"}",
"}"
]
| Executes updates against all sites.
@param $site
@param $target_env
@throws BltException | [
"Executes",
"updates",
"against",
"all",
"sites",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Artifact/AcHooksCommand.php#L261-L268 | train |
acquia/blt | src/Composer/Plugin.php | Plugin.onPostPackageEvent | public function onPostPackageEvent(PackageEvent $event) {
$package = $this->getBltPackage($event->getOperation());
if ($package) {
// By explicitly setting the blt package, the onPostCmdEvent() will
// process the update automatically.
$this->bltPackage = $package;
}
} | php | public function onPostPackageEvent(PackageEvent $event) {
$package = $this->getBltPackage($event->getOperation());
if ($package) {
// By explicitly setting the blt package, the onPostCmdEvent() will
// process the update automatically.
$this->bltPackage = $package;
}
} | [
"public",
"function",
"onPostPackageEvent",
"(",
"PackageEvent",
"$",
"event",
")",
"{",
"$",
"package",
"=",
"$",
"this",
"->",
"getBltPackage",
"(",
"$",
"event",
"->",
"getOperation",
"(",
")",
")",
";",
"if",
"(",
"$",
"package",
")",
"{",
"// By explicitly setting the blt package, the onPostCmdEvent() will",
"// process the update automatically.",
"$",
"this",
"->",
"bltPackage",
"=",
"$",
"package",
";",
"}",
"}"
]
| Marks blt to be processed after an install or update command.
@param \Composer\Installer\PackageEvent $event | [
"Marks",
"blt",
"to",
"be",
"processed",
"after",
"an",
"install",
"or",
"update",
"command",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Composer/Plugin.php#L100-L107 | train |
acquia/blt | src/Composer/Plugin.php | Plugin.isNewProject | protected function isNewProject() {
$composer_json = json_decode(file_get_contents($this->getRepoRoot() . '/composer.json'), TRUE);
if (isset($composer_json['name']) && in_array($composer_json['name'], ['acquia/blt-project', 'acquia/blted8'])) {
return TRUE;
}
return FALSE;
} | php | protected function isNewProject() {
$composer_json = json_decode(file_get_contents($this->getRepoRoot() . '/composer.json'), TRUE);
if (isset($composer_json['name']) && in_array($composer_json['name'], ['acquia/blt-project', 'acquia/blted8'])) {
return TRUE;
}
return FALSE;
} | [
"protected",
"function",
"isNewProject",
"(",
")",
"{",
"$",
"composer_json",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"getRepoRoot",
"(",
")",
".",
"'/composer.json'",
")",
",",
"TRUE",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"composer_json",
"[",
"'name'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"composer_json",
"[",
"'name'",
"]",
",",
"[",
"'acquia/blt-project'",
",",
"'acquia/blted8'",
"]",
")",
")",
"{",
"return",
"TRUE",
";",
"}",
"return",
"FALSE",
";",
"}"
]
| Determine if this is a project being newly created.
This would execute in the context of `composer create-project acquia/blt-project`.
@return bool
TRUE if this is a newly create project. | [
"Determine",
"if",
"this",
"is",
"a",
"project",
"being",
"newly",
"created",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Composer/Plugin.php#L203-L209 | train |
acquia/blt | src/Composer/Plugin.php | Plugin.getVendorPath | public function getVendorPath() {
$config = $this->composer->getConfig();
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
return $vendorPath;
} | php | public function getVendorPath() {
$config = $this->composer->getConfig();
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
return $vendorPath;
} | [
"public",
"function",
"getVendorPath",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"composer",
"->",
"getConfig",
"(",
")",
";",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"filesystem",
"->",
"ensureDirectoryExists",
"(",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
";",
"$",
"vendorPath",
"=",
"$",
"filesystem",
"->",
"normalizePath",
"(",
"realpath",
"(",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
")",
";",
"return",
"$",
"vendorPath",
";",
"}"
]
| Get the path to the 'vendor' directory.
@return string | [
"Get",
"the",
"path",
"to",
"the",
"vendor",
"directory",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Composer/Plugin.php#L236-L243 | train |
acquia/blt | src/Composer/Plugin.php | Plugin.getOptions | protected function getOptions() {
$defaults = [
'update' => TRUE,
];
$extra = $this->composer->getPackage()->getExtra() + ['blt' => []];
$extra['blt'] = $extra['blt'] + $defaults;
return $extra;
} | php | protected function getOptions() {
$defaults = [
'update' => TRUE,
];
$extra = $this->composer->getPackage()->getExtra() + ['blt' => []];
$extra['blt'] = $extra['blt'] + $defaults;
return $extra;
} | [
"protected",
"function",
"getOptions",
"(",
")",
"{",
"$",
"defaults",
"=",
"[",
"'update'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"extra",
"=",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
"->",
"getExtra",
"(",
")",
"+",
"[",
"'blt'",
"=>",
"[",
"]",
"]",
";",
"$",
"extra",
"[",
"'blt'",
"]",
"=",
"$",
"extra",
"[",
"'blt'",
"]",
"+",
"$",
"defaults",
";",
"return",
"$",
"extra",
";",
"}"
]
| Retrieve "extra" configuration.
@return array | [
"Retrieve",
"extra",
"configuration",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Composer/Plugin.php#L250-L258 | train |
acquia/blt | src/Robo/Commands/Setup/DrupalCommand.php | DrupalCommand.install | public function install() {
// Allows for installs to define custom user 0 name.
if ($this->getConfigValue('drupal.account.name') !== NULL) {
$username = $this->getConfigValue('drupal.account.name');
}
else {
// Generate a random, valid username.
// @see \Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator
$username = RandomString::string(10, FALSE,
function ($string) {
return !preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $string);
},
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'
);
}
/** @var \Acquia\Blt\Robo\Tasks\DrushTask $task */
$task = $this->taskDrush()
->drush("site-install")
->arg($this->getConfigValue('project.profile.name'))
->rawArg("install_configure_form.enable_update_status_module=NULL")
->option('sites-subdir', $this->getConfigValue('site'))
->option('site-name', $this->getConfigValue('project.human_name'))
->option('site-mail', $this->getConfigValue('drupal.account.mail'))
->option('account-name', $username, '=')
->option('account-mail', $this->getConfigValue('drupal.account.mail'))
->option('locale', $this->getConfigValue('drupal.locale'))
->verbose(TRUE)
->printOutput(TRUE);
// Install site from existing config if supported.
$strategy = $this->getConfigValue('cm.strategy');
$cm_core_key = $this->getConfigValue('cm.core.key');
$install_from_config = $this->getConfigValue('cm.core.install_from_config');
if (in_array($strategy, ['core-only', 'config-split']) && $cm_core_key == 'sync' && $install_from_config) {
$core_config_file = $this->getConfigValue('docroot') . '/' . $this->getConfigValue("cm.core.dirs.$cm_core_key.path") . '/core.extension.yml';
if (file_exists($core_config_file)) {
$task->option('existing-config');
}
}
$result = $task->interactive($this->input()->isInteractive())->run();
if (!$result->wasSuccessful()) {
throw new BltException("Failed to install Drupal!");
}
return $result;
} | php | public function install() {
// Allows for installs to define custom user 0 name.
if ($this->getConfigValue('drupal.account.name') !== NULL) {
$username = $this->getConfigValue('drupal.account.name');
}
else {
// Generate a random, valid username.
// @see \Drupal\user\Plugin\Validation\Constraint\UserNameConstraintValidator
$username = RandomString::string(10, FALSE,
function ($string) {
return !preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $string);
},
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'
);
}
/** @var \Acquia\Blt\Robo\Tasks\DrushTask $task */
$task = $this->taskDrush()
->drush("site-install")
->arg($this->getConfigValue('project.profile.name'))
->rawArg("install_configure_form.enable_update_status_module=NULL")
->option('sites-subdir', $this->getConfigValue('site'))
->option('site-name', $this->getConfigValue('project.human_name'))
->option('site-mail', $this->getConfigValue('drupal.account.mail'))
->option('account-name', $username, '=')
->option('account-mail', $this->getConfigValue('drupal.account.mail'))
->option('locale', $this->getConfigValue('drupal.locale'))
->verbose(TRUE)
->printOutput(TRUE);
// Install site from existing config if supported.
$strategy = $this->getConfigValue('cm.strategy');
$cm_core_key = $this->getConfigValue('cm.core.key');
$install_from_config = $this->getConfigValue('cm.core.install_from_config');
if (in_array($strategy, ['core-only', 'config-split']) && $cm_core_key == 'sync' && $install_from_config) {
$core_config_file = $this->getConfigValue('docroot') . '/' . $this->getConfigValue("cm.core.dirs.$cm_core_key.path") . '/core.extension.yml';
if (file_exists($core_config_file)) {
$task->option('existing-config');
}
}
$result = $task->interactive($this->input()->isInteractive())->run();
if (!$result->wasSuccessful()) {
throw new BltException("Failed to install Drupal!");
}
return $result;
} | [
"public",
"function",
"install",
"(",
")",
"{",
"// Allows for installs to define custom user 0 name.",
"if",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.account.name'",
")",
"!==",
"NULL",
")",
"{",
"$",
"username",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.account.name'",
")",
";",
"}",
"else",
"{",
"// Generate a random, valid username.",
"// @see \\Drupal\\user\\Plugin\\Validation\\Constraint\\UserNameConstraintValidator",
"$",
"username",
"=",
"RandomString",
"::",
"string",
"(",
"10",
",",
"FALSE",
",",
"function",
"(",
"$",
"string",
")",
"{",
"return",
"!",
"preg_match",
"(",
"'/[^\\x{80}-\\x{F7} a-z0-9@+_.\\'-]/i'",
",",
"$",
"string",
")",
";",
"}",
",",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'",
")",
";",
"}",
"/** @var \\Acquia\\Blt\\Robo\\Tasks\\DrushTask $task */",
"$",
"task",
"=",
"$",
"this",
"->",
"taskDrush",
"(",
")",
"->",
"drush",
"(",
"\"site-install\"",
")",
"->",
"arg",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'project.profile.name'",
")",
")",
"->",
"rawArg",
"(",
"\"install_configure_form.enable_update_status_module=NULL\"",
")",
"->",
"option",
"(",
"'sites-subdir'",
",",
"$",
"this",
"->",
"getConfigValue",
"(",
"'site'",
")",
")",
"->",
"option",
"(",
"'site-name'",
",",
"$",
"this",
"->",
"getConfigValue",
"(",
"'project.human_name'",
")",
")",
"->",
"option",
"(",
"'site-mail'",
",",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.account.mail'",
")",
")",
"->",
"option",
"(",
"'account-name'",
",",
"$",
"username",
",",
"'='",
")",
"->",
"option",
"(",
"'account-mail'",
",",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.account.mail'",
")",
")",
"->",
"option",
"(",
"'locale'",
",",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drupal.locale'",
")",
")",
"->",
"verbose",
"(",
"TRUE",
")",
"->",
"printOutput",
"(",
"TRUE",
")",
";",
"// Install site from existing config if supported.",
"$",
"strategy",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'cm.strategy'",
")",
";",
"$",
"cm_core_key",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'cm.core.key'",
")",
";",
"$",
"install_from_config",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'cm.core.install_from_config'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"strategy",
",",
"[",
"'core-only'",
",",
"'config-split'",
"]",
")",
"&&",
"$",
"cm_core_key",
"==",
"'sync'",
"&&",
"$",
"install_from_config",
")",
"{",
"$",
"core_config_file",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'docroot'",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getConfigValue",
"(",
"\"cm.core.dirs.$cm_core_key.path\"",
")",
".",
"'/core.extension.yml'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"core_config_file",
")",
")",
"{",
"$",
"task",
"->",
"option",
"(",
"'existing-config'",
")",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"task",
"->",
"interactive",
"(",
"$",
"this",
"->",
"input",
"(",
")",
"->",
"isInteractive",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"BltException",
"(",
"\"Failed to install Drupal!\"",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Installs Drupal and imports configuration.
@command internal:drupal:install
@validateDrushConfig
@hidden
@return \Robo\Result
The `drush site-install` command result.
@throws BltException | [
"Installs",
"Drupal",
"and",
"imports",
"configuration",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Setup/DrupalCommand.php#L26-L73 | train |
acquia/blt | src/Robo/Commands/Doctor/BehatCheck.php | BehatCheck.checkBehat | protected function checkBehat() {
$this->checkLocalConfig();
if ($this->behatLocalYmlExists()) {
$behatDefaultLocalConfig = $this->getInspector()->getLocalBehatConfig()->export();
$this->checkDrupalVm($behatDefaultLocalConfig);
$this->checkBaseUrl($behatDefaultLocalConfig);
}
} | php | protected function checkBehat() {
$this->checkLocalConfig();
if ($this->behatLocalYmlExists()) {
$behatDefaultLocalConfig = $this->getInspector()->getLocalBehatConfig()->export();
$this->checkDrupalVm($behatDefaultLocalConfig);
$this->checkBaseUrl($behatDefaultLocalConfig);
}
} | [
"protected",
"function",
"checkBehat",
"(",
")",
"{",
"$",
"this",
"->",
"checkLocalConfig",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"behatLocalYmlExists",
"(",
")",
")",
"{",
"$",
"behatDefaultLocalConfig",
"=",
"$",
"this",
"->",
"getInspector",
"(",
")",
"->",
"getLocalBehatConfig",
"(",
")",
"->",
"export",
"(",
")",
";",
"$",
"this",
"->",
"checkDrupalVm",
"(",
"$",
"behatDefaultLocalConfig",
")",
";",
"$",
"this",
"->",
"checkBaseUrl",
"(",
"$",
"behatDefaultLocalConfig",
")",
";",
"}",
"}"
]
| Checks Behat configuration in local.yml.
@return bool | [
"Checks",
"Behat",
"configuration",
"in",
"local",
".",
"yml",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Commands/Doctor/BehatCheck.php#L19-L26 | train |
acquia/blt | src/Robo/Common/Executor.php | Executor.drush | public function drush($command) {
// @todo Set to silent if verbosity is less than very verbose.
$bin = $this->getConfigValue('composer.bin');
/** @var \Robo\Common\ProcessExecutor $process_executor */
$drush_alias = $this->getConfigValue('drush.alias');
$command_string = "'$bin/drush' @$drush_alias $command";
// URIs do not work on remote drush aliases in Drush 9. Instead, it is
// expected that the alias define the uri in its configuration.
if ($drush_alias != 'self') {
$command_string .= ' --uri=' . $this->getConfigValue('site');
}
$process_executor = Robo::process(new Process($command_string));
return $process_executor->dir($this->getConfigValue('docroot'))
->interactive(FALSE)
->printOutput(TRUE)
->printMetadata(TRUE)
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE);
} | php | public function drush($command) {
// @todo Set to silent if verbosity is less than very verbose.
$bin = $this->getConfigValue('composer.bin');
/** @var \Robo\Common\ProcessExecutor $process_executor */
$drush_alias = $this->getConfigValue('drush.alias');
$command_string = "'$bin/drush' @$drush_alias $command";
// URIs do not work on remote drush aliases in Drush 9. Instead, it is
// expected that the alias define the uri in its configuration.
if ($drush_alias != 'self') {
$command_string .= ' --uri=' . $this->getConfigValue('site');
}
$process_executor = Robo::process(new Process($command_string));
return $process_executor->dir($this->getConfigValue('docroot'))
->interactive(FALSE)
->printOutput(TRUE)
->printMetadata(TRUE)
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE);
} | [
"public",
"function",
"drush",
"(",
"$",
"command",
")",
"{",
"// @todo Set to silent if verbosity is less than very verbose.",
"$",
"bin",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'composer.bin'",
")",
";",
"/** @var \\Robo\\Common\\ProcessExecutor $process_executor */",
"$",
"drush_alias",
"=",
"$",
"this",
"->",
"getConfigValue",
"(",
"'drush.alias'",
")",
";",
"$",
"command_string",
"=",
"\"'$bin/drush' @$drush_alias $command\"",
";",
"// URIs do not work on remote drush aliases in Drush 9. Instead, it is",
"// expected that the alias define the uri in its configuration.",
"if",
"(",
"$",
"drush_alias",
"!=",
"'self'",
")",
"{",
"$",
"command_string",
".=",
"' --uri='",
".",
"$",
"this",
"->",
"getConfigValue",
"(",
"'site'",
")",
";",
"}",
"$",
"process_executor",
"=",
"Robo",
"::",
"process",
"(",
"new",
"Process",
"(",
"$",
"command_string",
")",
")",
";",
"return",
"$",
"process_executor",
"->",
"dir",
"(",
"$",
"this",
"->",
"getConfigValue",
"(",
"'docroot'",
")",
")",
"->",
"interactive",
"(",
"FALSE",
")",
"->",
"printOutput",
"(",
"TRUE",
")",
"->",
"printMetadata",
"(",
"TRUE",
")",
"->",
"setVerbosityThreshold",
"(",
"VerbosityThresholdInterface",
"::",
"VERBOSITY_VERY_VERBOSE",
")",
";",
"}"
]
| Executes a drush command.
@param string $command
The command to execute, without "drush" prefix.
@return \Robo\Common\ProcessExecutor
The unexecuted process. | [
"Executes",
"a",
"drush",
"command",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Common/Executor.php#L77-L97 | train |
acquia/blt | src/Robo/Common/Executor.php | Executor.wait | public function wait(callable $callable, array $args, $message = '') {
$maxWait = 60 * 1000;
$checkEvery = 1 * 1000;
$start = microtime(TRUE) * 1000;
$end = $start + $maxWait;
if (!$message) {
$method_name = is_array($callable) ? $callable[1] : $callable;
$message = "Waiting for $method_name() to return true.";
}
// For some reason we can't reuse $start here.
while (microtime(TRUE) * 1000 < $end) {
$this->logger->info($message);
try {
if (call_user_func_array($callable, $args)) {
return TRUE;
}
}
catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
usleep($checkEvery * 1000);
}
throw new BltException("Timed out.");
} | php | public function wait(callable $callable, array $args, $message = '') {
$maxWait = 60 * 1000;
$checkEvery = 1 * 1000;
$start = microtime(TRUE) * 1000;
$end = $start + $maxWait;
if (!$message) {
$method_name = is_array($callable) ? $callable[1] : $callable;
$message = "Waiting for $method_name() to return true.";
}
// For some reason we can't reuse $start here.
while (microtime(TRUE) * 1000 < $end) {
$this->logger->info($message);
try {
if (call_user_func_array($callable, $args)) {
return TRUE;
}
}
catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
usleep($checkEvery * 1000);
}
throw new BltException("Timed out.");
} | [
"public",
"function",
"wait",
"(",
"callable",
"$",
"callable",
",",
"array",
"$",
"args",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"maxWait",
"=",
"60",
"*",
"1000",
";",
"$",
"checkEvery",
"=",
"1",
"*",
"1000",
";",
"$",
"start",
"=",
"microtime",
"(",
"TRUE",
")",
"*",
"1000",
";",
"$",
"end",
"=",
"$",
"start",
"+",
"$",
"maxWait",
";",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"method_name",
"=",
"is_array",
"(",
"$",
"callable",
")",
"?",
"$",
"callable",
"[",
"1",
"]",
":",
"$",
"callable",
";",
"$",
"message",
"=",
"\"Waiting for $method_name() to return true.\"",
";",
"}",
"// For some reason we can't reuse $start here.",
"while",
"(",
"microtime",
"(",
"TRUE",
")",
"*",
"1000",
"<",
"$",
"end",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"$",
"message",
")",
";",
"try",
"{",
"if",
"(",
"call_user_func_array",
"(",
"$",
"callable",
",",
"$",
"args",
")",
")",
"{",
"return",
"TRUE",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"usleep",
"(",
"$",
"checkEvery",
"*",
"1000",
")",
";",
"}",
"throw",
"new",
"BltException",
"(",
"\"Timed out.\"",
")",
";",
"}"
]
| Waits until a given callable returns TRUE.
This does have a maximum timeout.
@param callable $callable
The method/function to wait for a TRUE response from.
@param array $args
Arguments to pass to $callable.
@param string $message
The message to display when this function is called.
@return bool
TRUE if callable returns TRUE.
@throws \Exception | [
"Waits",
"until",
"a",
"given",
"callable",
"returns",
"TRUE",
"."
]
| 8a903c1d930f82f4b9ee657d62d123782dd2ed59 | https://github.com/acquia/blt/blob/8a903c1d930f82f4b9ee657d62d123782dd2ed59/src/Robo/Common/Executor.php#L174-L200 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.