repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.fromUser | public function fromUser($user, array $customClaims = [])
{
$payload = $this->makePayload($user->{$this->identifier}, $customClaims);
return $this->manager->encode($payload)->get();
} | php | public function fromUser($user, array $customClaims = [])
{
$payload = $this->makePayload($user->{$this->identifier}, $customClaims);
return $this->manager->encode($payload)->get();
} | [
"public",
"function",
"fromUser",
"(",
"$",
"user",
",",
"array",
"$",
"customClaims",
"=",
"[",
"]",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"makePayload",
"(",
"$",
"user",
"->",
"{",
"$",
"this",
"->",
"identifier",
"}",
",",
"$",
"customClaims",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
"encode",
"(",
"$",
"payload",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Generate a token using the user identifier as the subject claim.
@param mixed $user
@param array $customClaims
@return string | [
"Generate",
"a",
"token",
"using",
"the",
"user",
"identifier",
"as",
"the",
"subject",
"claim",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L82-L87 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.authenticate | public function authenticate($token = false)
{
$id = $this->getPayload($token)->get('sub');
if (! $this->auth->byId($id)) {
return false;
}
return $this->auth->user();
} | php | public function authenticate($token = false)
{
$id = $this->getPayload($token)->get('sub');
if (! $this->auth->byId($id)) {
return false;
}
return $this->auth->user();
} | [
"public",
"function",
"authenticate",
"(",
"$",
"token",
"=",
"false",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getPayload",
"(",
"$",
"token",
")",
"->",
"get",
"(",
"'sub'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"auth",
"->",
"byId",
"(",
"$",
"id",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"auth",
"->",
"user",
"(",
")",
";",
"}"
] | Authenticate a user via a token.
@param mixed $token
@return mixed | [
"Authenticate",
"a",
"user",
"via",
"a",
"token",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L113-L121 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.refresh | public function refresh($token = false)
{
$this->requireToken($token);
return $this->manager->refresh($this->token)->get();
} | php | public function refresh($token = false)
{
$this->requireToken($token);
return $this->manager->refresh($this->token)->get();
} | [
"public",
"function",
"refresh",
"(",
"$",
"token",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"requireToken",
"(",
"$",
"token",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
"refresh",
"(",
"$",
"this",
"->",
"token",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Refresh an expired token.
@param mixed $token
@return string | [
"Refresh",
"an",
"expired",
"token",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L130-L135 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.invalidate | public function invalidate($token = false)
{
$this->requireToken($token);
return $this->manager->invalidate($this->token);
} | php | public function invalidate($token = false)
{
$this->requireToken($token);
return $this->manager->invalidate($this->token);
} | [
"public",
"function",
"invalidate",
"(",
"$",
"token",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"requireToken",
"(",
"$",
"token",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
"invalidate",
"(",
"$",
"this",
"->",
"token",
")",
";",
"}"
] | Invalidate a token (add it to the blacklist).
@param mixed $token
@return bool | [
"Invalidate",
"a",
"token",
"(",
"add",
"it",
"to",
"the",
"blacklist",
")",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L144-L149 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.getPayload | public function getPayload($token = false)
{
$this->requireToken($token);
return $this->manager->decode($this->token);
} | php | public function getPayload($token = false)
{
$this->requireToken($token);
return $this->manager->decode($this->token);
} | [
"public",
"function",
"getPayload",
"(",
"$",
"token",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"requireToken",
"(",
"$",
"token",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
"decode",
"(",
"$",
"this",
"->",
"token",
")",
";",
"}"
] | Get the raw Payload instance.
@param mixed $token
@return \Lia\Addons\JWTAuth\Payload | [
"Get",
"the",
"raw",
"Payload",
"instance",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L176-L181 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.parseToken | public function parseToken($method = 'bearer', $header = 'authorization', $query = 'token')
{
if (! $token = $this->parseAuthHeader($header, $method)) {
if (! $token = $this->request->{$query}) {
if (! $token = $this->request->header('Token')) {
throw new JWTException('The token could not be parsed from the request', 400);
}
}
}
return $this->setToken($token);
} | php | public function parseToken($method = 'bearer', $header = 'authorization', $query = 'token')
{
if (! $token = $this->parseAuthHeader($header, $method)) {
if (! $token = $this->request->{$query}) {
if (! $token = $this->request->header('Token')) {
throw new JWTException('The token could not be parsed from the request', 400);
}
}
}
return $this->setToken($token);
} | [
"public",
"function",
"parseToken",
"(",
"$",
"method",
"=",
"'bearer'",
",",
"$",
"header",
"=",
"'authorization'",
",",
"$",
"query",
"=",
"'token'",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"=",
"$",
"this",
"->",
"parseAuthHeader",
"(",
"$",
"header",
",",
"$",
"method",
")",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"=",
"$",
"this",
"->",
"request",
"->",
"{",
"$",
"query",
"}",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"=",
"$",
"this",
"->",
"request",
"->",
"header",
"(",
"'Token'",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'The token could not be parsed from the request'",
",",
"400",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"setToken",
"(",
"$",
"token",
")",
";",
"}"
] | Parse the token from the request.
@param string $query
@return JWTAuth | [
"Parse",
"the",
"token",
"from",
"the",
"request",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L190-L201 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.parseAuthHeader | protected function parseAuthHeader($header = 'authorization', $method = 'bearer')
{
$header = $this->request->headers->get($header);
if (! starts_with(strtolower($header), $method)) {
return false;
}
return trim(str_ireplace($method, '', $header));
} | php | protected function parseAuthHeader($header = 'authorization', $method = 'bearer')
{
$header = $this->request->headers->get($header);
if (! starts_with(strtolower($header), $method)) {
return false;
}
return trim(str_ireplace($method, '', $header));
} | [
"protected",
"function",
"parseAuthHeader",
"(",
"$",
"header",
"=",
"'authorization'",
",",
"$",
"method",
"=",
"'bearer'",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"request",
"->",
"headers",
"->",
"get",
"(",
"$",
"header",
")",
";",
"if",
"(",
"!",
"starts_with",
"(",
"strtolower",
"(",
"$",
"header",
")",
",",
"$",
"method",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"trim",
"(",
"str_ireplace",
"(",
"$",
"method",
",",
"''",
",",
"$",
"header",
")",
")",
";",
"}"
] | Parse token from the authorization header.
@param string $header
@param string $method
@return false|string | [
"Parse",
"token",
"from",
"the",
"authorization",
"header",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L211-L220 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.makePayload | protected function makePayload($subject, array $customClaims = [])
{
return $this->manager->getPayloadFactory()->make(
array_merge($customClaims, ['sub' => $subject])
);
} | php | protected function makePayload($subject, array $customClaims = [])
{
return $this->manager->getPayloadFactory()->make(
array_merge($customClaims, ['sub' => $subject])
);
} | [
"protected",
"function",
"makePayload",
"(",
"$",
"subject",
",",
"array",
"$",
"customClaims",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"manager",
"->",
"getPayloadFactory",
"(",
")",
"->",
"make",
"(",
"array_merge",
"(",
"$",
"customClaims",
",",
"[",
"'sub'",
"=>",
"$",
"subject",
"]",
")",
")",
";",
"}"
] | Create a Payload instance.
@param mixed $subject
@param array $customClaims
@return \Lia\Addons\JWTAuth\Payload | [
"Create",
"a",
"Payload",
"instance",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L230-L235 |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/JWTAuth.php | JWTAuth.requireToken | protected function requireToken($token)
{
if ($token) {
return $this->setToken($token);
} elseif ($this->token) {
return $this;
} else {
throw new JWTException('A token is required', 400);
}
} | php | protected function requireToken($token)
{
if ($token) {
return $this->setToken($token);
} elseif ($this->token) {
return $this;
} else {
throw new JWTException('A token is required', 400);
}
} | [
"protected",
"function",
"requireToken",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
")",
"{",
"return",
"$",
"this",
"->",
"setToken",
"(",
"$",
"token",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"token",
")",
"{",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"throw",
"new",
"JWTException",
"(",
"'A token is required'",
",",
"400",
")",
";",
"}",
"}"
] | Ensure that a token is available.
@param mixed $token
@return JWTAuth
@throws \Lia\Addons\JWTAuth\Exceptions\JWTException | [
"Ensure",
"that",
"a",
"token",
"is",
"available",
"."
] | train | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/JWTAuth.php#L284-L293 |
zapheus/zapheus | src/Application.php | Application.add | public function add(ProviderInterface $provider)
{
$container = $this->container;
$this->container = $provider->register($container);
$this->providers[] = (string) get_class($provider);
return $this;
} | php | public function add(ProviderInterface $provider)
{
$container = $this->container;
$this->container = $provider->register($container);
$this->providers[] = (string) get_class($provider);
return $this;
} | [
"public",
"function",
"add",
"(",
"ProviderInterface",
"$",
"provider",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"container",
";",
"$",
"this",
"->",
"container",
"=",
"$",
"provider",
"->",
"register",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"providers",
"[",
"]",
"=",
"(",
"string",
")",
"get_class",
"(",
"$",
"provider",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a new provider to be registered.
@param \Zapheus\Provider\ProviderInterface $provider
@return self | [
"Adds",
"a",
"new",
"provider",
"to",
"be",
"registered",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Application.php#L74-L83 |
zapheus/zapheus | src/Application.php | Application.config | public function config($data)
{
$items = is_array($data) ? $data : array();
$config = new Provider\Configuration($items);
if (is_string($data))
{
$config->load($data);
}
$interface = ProviderInterface::CONFIG;
return $this->set($interface, $config);
} | php | public function config($data)
{
$items = is_array($data) ? $data : array();
$config = new Provider\Configuration($items);
if (is_string($data))
{
$config->load($data);
}
$interface = ProviderInterface::CONFIG;
return $this->set($interface, $config);
} | [
"public",
"function",
"config",
"(",
"$",
"data",
")",
"{",
"$",
"items",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"$",
"data",
":",
"array",
"(",
")",
";",
"$",
"config",
"=",
"new",
"Provider",
"\\",
"Configuration",
"(",
"$",
"items",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"config",
"->",
"load",
"(",
"$",
"data",
")",
";",
"}",
"$",
"interface",
"=",
"ProviderInterface",
"::",
"CONFIG",
";",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"interface",
",",
"$",
"config",
")",
";",
"}"
] | Creates a new configuration based on given data.
@param array|string $data
@return self | [
"Creates",
"a",
"new",
"configuration",
"based",
"on",
"given",
"data",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Application.php#L91-L105 |
zapheus/zapheus | src/Application.php | Application.emit | public function emit(ResponseInterface $response)
{
$code = $response->code() . ' ' . $response->reason();
$headers = $response->headers();
$version = $response->version();
foreach ($headers as $name => $values)
{
header($name . ': ' . implode(',', $values));
}
header(sprintf('HTTP/%s %s', $version, $code));
return $response;
} | php | public function emit(ResponseInterface $response)
{
$code = $response->code() . ' ' . $response->reason();
$headers = $response->headers();
$version = $response->version();
foreach ($headers as $name => $values)
{
header($name . ': ' . implode(',', $values));
}
header(sprintf('HTTP/%s %s', $version, $code));
return $response;
} | [
"public",
"function",
"emit",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"code",
"=",
"$",
"response",
"->",
"code",
"(",
")",
".",
"' '",
".",
"$",
"response",
"->",
"reason",
"(",
")",
";",
"$",
"headers",
"=",
"$",
"response",
"->",
"headers",
"(",
")",
";",
"$",
"version",
"=",
"$",
"response",
"->",
"version",
"(",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"header",
"(",
"$",
"name",
".",
"': '",
".",
"implode",
"(",
"','",
",",
"$",
"values",
")",
")",
";",
"}",
"header",
"(",
"sprintf",
"(",
"'HTTP/%s %s'",
",",
"$",
"version",
",",
"$",
"code",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Emits the headers from the response instance.
@param \Zapheus\Http\Message\ResponseInterface $response
@return \Zapheus\Http\Message\ResponseInterface | [
"Emits",
"the",
"headers",
"from",
"the",
"response",
"instance",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Application.php#L113-L129 |
zapheus/zapheus | src/Application.php | Application.handle | public function handle(RequestInterface $request)
{
$handler = new RoutingHandler($this->container);
if (! $this->has(Application::MIDDLEWARE))
{
return $handler->handle($request);
}
$dispatcher = $this->get(Application::MIDDLEWARE);
return $dispatcher->process($request, $handler);
} | php | public function handle(RequestInterface $request)
{
$handler = new RoutingHandler($this->container);
if (! $this->has(Application::MIDDLEWARE))
{
return $handler->handle($request);
}
$dispatcher = $this->get(Application::MIDDLEWARE);
return $dispatcher->process($request, $handler);
} | [
"public",
"function",
"handle",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"handler",
"=",
"new",
"RoutingHandler",
"(",
"$",
"this",
"->",
"container",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"Application",
"::",
"MIDDLEWARE",
")",
")",
"{",
"return",
"$",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}",
"$",
"dispatcher",
"=",
"$",
"this",
"->",
"get",
"(",
"Application",
"::",
"MIDDLEWARE",
")",
";",
"return",
"$",
"dispatcher",
"->",
"process",
"(",
"$",
"request",
",",
"$",
"handler",
")",
";",
"}"
] | Dispatches the request and returns into a response.
@param \Zapheus\Http\Message\RequestInterface $request
@return \Zapheus\Http\Message\ResponseInterface | [
"Dispatches",
"the",
"request",
"and",
"returns",
"into",
"a",
"response",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Application.php#L150-L162 |
zapheus/zapheus | src/Application.php | Application.run | public function run()
{
$request = $this->container->get(self::REQUEST);
$response = $this->handle($request);
return $this->emit($response)->stream();
} | php | public function run()
{
$request = $this->container->get(self::REQUEST);
$response = $this->handle($request);
return $this->emit($response)->stream();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"self",
"::",
"REQUEST",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"return",
"$",
"this",
"->",
"emit",
"(",
"$",
"response",
")",
"->",
"stream",
"(",
")",
";",
"}"
] | Runs the application and returns the stream instance.
@return \Zapheus\Http\Message\StreamInterface | [
"Runs",
"the",
"application",
"and",
"returns",
"the",
"stream",
"instance",
"."
] | train | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Application.php#L190-L197 |
hamlet-framework/db | src/Processing/Selector.php | Selector.withKey | public function withKey(string $keyField): Collector
{
$generator =
/**
* @return Generator
* @psalm-return Generator<array-key, array<K, V>, mixed, void>
*/
function () use ($keyField): Generator {
foreach ($this->records as &$record) {
$key = $record[$keyField];
if ($key === null) {
continue;
}
assert(is_int($key) || is_string($key));
yield $key => $record;
}
};
return new Collector($generator(), $this->streamingMode);
} | php | public function withKey(string $keyField): Collector
{
$generator =
/**
* @return Generator
* @psalm-return Generator<array-key, array<K, V>, mixed, void>
*/
function () use ($keyField): Generator {
foreach ($this->records as &$record) {
$key = $record[$keyField];
if ($key === null) {
continue;
}
assert(is_int($key) || is_string($key));
yield $key => $record;
}
};
return new Collector($generator(), $this->streamingMode);
} | [
"public",
"function",
"withKey",
"(",
"string",
"$",
"keyField",
")",
":",
"Collector",
"{",
"$",
"generator",
"=",
"/**\n * @return Generator\n * @psalm-return Generator<array-key, array<K, V>, mixed, void>\n */",
"function",
"(",
")",
"use",
"(",
"$",
"keyField",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"records",
"as",
"&",
"$",
"record",
")",
"{",
"$",
"key",
"=",
"$",
"record",
"[",
"$",
"keyField",
"]",
";",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"assert",
"(",
"is_int",
"(",
"$",
"key",
")",
"||",
"is_string",
"(",
"$",
"key",
")",
")",
";",
"yield",
"$",
"key",
"=>",
"$",
"record",
";",
"}",
"}",
";",
"return",
"new",
"Collector",
"(",
"$",
"generator",
"(",
")",
",",
"$",
"this",
"->",
"streamingMode",
")",
";",
"}"
] | @param string $keyField
@return Collector
@psalm-return Collector<array-key,array<K,V>>
@todo it would be nice to have an intersection type Collector<V & array-key, array<K, V>> | [
"@param",
"string",
"$keyField",
"@return",
"Collector",
"@psalm",
"-",
"return",
"Collector<array",
"-",
"key",
"array<K",
"V",
">>"
] | train | https://github.com/hamlet-framework/db/blob/a2c674998db5e5784a59bf8a12548a91c339e135/src/Processing/Selector.php#L126-L145 |
hiqdev/minii-caching | src/ChainedDependency.php | ChainedDependency.getHasChanged | public function getHasChanged($cache)
{
foreach ($this->dependencies as $dependency) {
if ($this->dependOnAll && $dependency->getHasChanged($cache)) {
return true;
} elseif (!$this->dependOnAll && !$dependency->getHasChanged($cache)) {
return false;
}
}
return !$this->dependOnAll;
} | php | public function getHasChanged($cache)
{
foreach ($this->dependencies as $dependency) {
if ($this->dependOnAll && $dependency->getHasChanged($cache)) {
return true;
} elseif (!$this->dependOnAll && !$dependency->getHasChanged($cache)) {
return false;
}
}
return !$this->dependOnAll;
} | [
"public",
"function",
"getHasChanged",
"(",
"$",
"cache",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dependOnAll",
"&&",
"$",
"dependency",
"->",
"getHasChanged",
"(",
"$",
"cache",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"dependOnAll",
"&&",
"!",
"$",
"dependency",
"->",
"getHasChanged",
"(",
"$",
"cache",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"!",
"$",
"this",
"->",
"dependOnAll",
";",
"}"
] | Performs the actual dependency checking.
This method returns true if any of the dependency objects
reports a dependency change.
@param Cache $cache the cache component that is currently evaluating this dependency
@return boolean whether the dependency is changed or not. | [
"Performs",
"the",
"actual",
"dependency",
"checking",
".",
"This",
"method",
"returns",
"true",
"if",
"any",
"of",
"the",
"dependency",
"objects",
"reports",
"a",
"dependency",
"change",
"."
] | train | https://github.com/hiqdev/minii-caching/blob/04c3f810a4af43b53855ee9c5e3ef6455080b538/src/ChainedDependency.php#L65-L76 |
tomas-pecserke/TwigDoctrineLoaderBundle | DependencyInjection/PecserkeTwigDoctrineLoaderExtension.php | PecserkeTwigDoctrineLoaderExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter(sprintf('%s.backend.%s', $this->getAlias(), $config['backend']), true);
$container->setParameter(sprintf('%s.model_manager_name', $this->getAlias()), $config['manager_name']);
switch ($config['backend']) {
case 'mongodb':
$objectManagerServiceId = sprintf('doctrine_mongodb.odm.%s_document_manager', $config['manager_name']);
break;
case 'orm':
default:
$managers = $container->getParameter('doctrine.entity_managers');
$objectManagerServiceId = $managers[$config['manager_name']];
break;
}
$container->setAlias('pecserke_twig_doctrine_loader.object_manager', $objectManagerServiceId);
$container->setParameter('pecserke_twig_doctrine_loader.model.template.class', $config['template_class']);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$cachePrefix = $config['cache_prefix'] ?: sprintf(
'%s/%s/',
$container->getParameter('kernel.root_dir'),
$this->getAlias()
);
$definition = $container->getDefinition('pecserke_twig_doctrine_loader.twig.loader.doctrine');
$definition->replaceArgument(1, $cachePrefix);
} | php | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter(sprintf('%s.backend.%s', $this->getAlias(), $config['backend']), true);
$container->setParameter(sprintf('%s.model_manager_name', $this->getAlias()), $config['manager_name']);
switch ($config['backend']) {
case 'mongodb':
$objectManagerServiceId = sprintf('doctrine_mongodb.odm.%s_document_manager', $config['manager_name']);
break;
case 'orm':
default:
$managers = $container->getParameter('doctrine.entity_managers');
$objectManagerServiceId = $managers[$config['manager_name']];
break;
}
$container->setAlias('pecserke_twig_doctrine_loader.object_manager', $objectManagerServiceId);
$container->setParameter('pecserke_twig_doctrine_loader.model.template.class', $config['template_class']);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$cachePrefix = $config['cache_prefix'] ?: sprintf(
'%s/%s/',
$container->getParameter('kernel.root_dir'),
$this->getAlias()
);
$definition = $container->getDefinition('pecserke_twig_doctrine_loader.twig.loader.doctrine');
$definition->replaceArgument(1, $cachePrefix);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"sprintf",
"(",
"'%s.backend.%s'",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
",",
"$",
"config",
"[",
"'backend'",
"]",
")",
",",
"true",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"sprintf",
"(",
"'%s.model_manager_name'",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
")",
",",
"$",
"config",
"[",
"'manager_name'",
"]",
")",
";",
"switch",
"(",
"$",
"config",
"[",
"'backend'",
"]",
")",
"{",
"case",
"'mongodb'",
":",
"$",
"objectManagerServiceId",
"=",
"sprintf",
"(",
"'doctrine_mongodb.odm.%s_document_manager'",
",",
"$",
"config",
"[",
"'manager_name'",
"]",
")",
";",
"break",
";",
"case",
"'orm'",
":",
"default",
":",
"$",
"managers",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'doctrine.entity_managers'",
")",
";",
"$",
"objectManagerServiceId",
"=",
"$",
"managers",
"[",
"$",
"config",
"[",
"'manager_name'",
"]",
"]",
";",
"break",
";",
"}",
"$",
"container",
"->",
"setAlias",
"(",
"'pecserke_twig_doctrine_loader.object_manager'",
",",
"$",
"objectManagerServiceId",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'pecserke_twig_doctrine_loader.model.template.class'",
",",
"$",
"config",
"[",
"'template_class'",
"]",
")",
";",
"$",
"loader",
"=",
"new",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.yml'",
")",
";",
"$",
"cachePrefix",
"=",
"$",
"config",
"[",
"'cache_prefix'",
"]",
"?",
":",
"sprintf",
"(",
"'%s/%s/'",
",",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.root_dir'",
")",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
")",
";",
"$",
"definition",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'pecserke_twig_doctrine_loader.twig.loader.doctrine'",
")",
";",
"$",
"definition",
"->",
"replaceArgument",
"(",
"1",
",",
"$",
"cachePrefix",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/tomas-pecserke/TwigDoctrineLoaderBundle/blob/85b07d2d4e67c98bc35c3cedeffb61c1cf416bfe/DependencyInjection/PecserkeTwigDoctrineLoaderExtension.php#L27-L57 |
ARCANESOFT/SEO | src/ViewComposers/ViewComposer.php | ViewComposer.cacheResults | protected function cacheResults($name, Closure $callback)
{
return Cache::remember('cache::' . $name, $this->minutes, $callback);
} | php | protected function cacheResults($name, Closure $callback)
{
return Cache::remember('cache::' . $name, $this->minutes, $callback);
} | [
"protected",
"function",
"cacheResults",
"(",
"$",
"name",
",",
"Closure",
"$",
"callback",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"'cache::'",
".",
"$",
"name",
",",
"$",
"this",
"->",
"minutes",
",",
"$",
"callback",
")",
";",
"}"
] | Cache the results.
@param string $name
@param \Closure $callback
@return mixed | [
"Cache",
"the",
"results",
"."
] | train | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/ViewComposers/ViewComposer.php#L39-L42 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.getTask | public function getTask( $object, $operation, $exceptionOnFailure = true )
{
/* debugging
printf(
"\n-- new task %s%s %s\n",
get_class( $object ),
$object instanceof \Bond\Entity\Container ? get_unqualified_class( $object->classGet() ) : null,
count( $object )
);
*/
if( !in_array( $operation, array( Task::PERSIST, Task::DELETE ), true ) ) {
throw new BadOperationException( "Unknown task operation `{$operation}`; you probably want `RecordManager::PERSIST` or `RecordManager::DELETE`" );
}
// tasks only work on objects
if( !is_object($object) ) {
throw new BadTaskException("Tasks can only operate on objects");
}
// detect object
foreach( $this->taskHandlers as $type ){
if( call_user_func( [$type, 'isCompatible'], $object ) ) {
$taskType = $type;
break;
}
}
// Can't handle this? What now?
if( !isset( $taskType ) ) {
// exceptionOnFailure
if( $exceptionOnFailure ) {
$class = get_class( $object );
throw new BadTaskException( "Unable to find a Task compatible which works for object `{$class}` and operation `{$operation}`" );
}
// No exception
return null;
}
// Normality variants?
if(
strpos( $taskType, 'Normality' ) !== false or
strpos( $taskType, 'PgLargeObject' ) !== false
) {
$taskType .= ( $operation === Task::DELETE ) ? '\\Delete' : '\\Persist';
}
// Instantiate
$reflClass = new \ReflectionClass($taskType);
$task = $reflClass->newInstance($this);
// Set object property. No need to go via the setter because we have already determined this is compatible
$reflProperty = $reflClass->getProperty('object');
$reflProperty->setAccessible(true);
$reflProperty->setValue( $task, $object );
return $task;
} | php | public function getTask( $object, $operation, $exceptionOnFailure = true )
{
/* debugging
printf(
"\n-- new task %s%s %s\n",
get_class( $object ),
$object instanceof \Bond\Entity\Container ? get_unqualified_class( $object->classGet() ) : null,
count( $object )
);
*/
if( !in_array( $operation, array( Task::PERSIST, Task::DELETE ), true ) ) {
throw new BadOperationException( "Unknown task operation `{$operation}`; you probably want `RecordManager::PERSIST` or `RecordManager::DELETE`" );
}
// tasks only work on objects
if( !is_object($object) ) {
throw new BadTaskException("Tasks can only operate on objects");
}
// detect object
foreach( $this->taskHandlers as $type ){
if( call_user_func( [$type, 'isCompatible'], $object ) ) {
$taskType = $type;
break;
}
}
// Can't handle this? What now?
if( !isset( $taskType ) ) {
// exceptionOnFailure
if( $exceptionOnFailure ) {
$class = get_class( $object );
throw new BadTaskException( "Unable to find a Task compatible which works for object `{$class}` and operation `{$operation}`" );
}
// No exception
return null;
}
// Normality variants?
if(
strpos( $taskType, 'Normality' ) !== false or
strpos( $taskType, 'PgLargeObject' ) !== false
) {
$taskType .= ( $operation === Task::DELETE ) ? '\\Delete' : '\\Persist';
}
// Instantiate
$reflClass = new \ReflectionClass($taskType);
$task = $reflClass->newInstance($this);
// Set object property. No need to go via the setter because we have already determined this is compatible
$reflProperty = $reflClass->getProperty('object');
$reflProperty->setAccessible(true);
$reflProperty->setValue( $task, $object );
return $task;
} | [
"public",
"function",
"getTask",
"(",
"$",
"object",
",",
"$",
"operation",
",",
"$",
"exceptionOnFailure",
"=",
"true",
")",
"{",
"/* debugging\n printf(\n \"\\n-- new task %s%s %s\\n\",\n get_class( $object ),\n $object instanceof \\Bond\\Entity\\Container ? get_unqualified_class( $object->classGet() ) : null,\n count( $object )\n );\n */",
"if",
"(",
"!",
"in_array",
"(",
"$",
"operation",
",",
"array",
"(",
"Task",
"::",
"PERSIST",
",",
"Task",
"::",
"DELETE",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"BadOperationException",
"(",
"\"Unknown task operation `{$operation}`; you probably want `RecordManager::PERSIST` or `RecordManager::DELETE`\"",
")",
";",
"}",
"// tasks only work on objects",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"BadTaskException",
"(",
"\"Tasks can only operate on objects\"",
")",
";",
"}",
"// detect object",
"foreach",
"(",
"$",
"this",
"->",
"taskHandlers",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"call_user_func",
"(",
"[",
"$",
"type",
",",
"'isCompatible'",
"]",
",",
"$",
"object",
")",
")",
"{",
"$",
"taskType",
"=",
"$",
"type",
";",
"break",
";",
"}",
"}",
"// Can't handle this? What now?",
"if",
"(",
"!",
"isset",
"(",
"$",
"taskType",
")",
")",
"{",
"// exceptionOnFailure",
"if",
"(",
"$",
"exceptionOnFailure",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"throw",
"new",
"BadTaskException",
"(",
"\"Unable to find a Task compatible which works for object `{$class}` and operation `{$operation}`\"",
")",
";",
"}",
"// No exception",
"return",
"null",
";",
"}",
"// Normality variants?",
"if",
"(",
"strpos",
"(",
"$",
"taskType",
",",
"'Normality'",
")",
"!==",
"false",
"or",
"strpos",
"(",
"$",
"taskType",
",",
"'PgLargeObject'",
")",
"!==",
"false",
")",
"{",
"$",
"taskType",
".=",
"(",
"$",
"operation",
"===",
"Task",
"::",
"DELETE",
")",
"?",
"'\\\\Delete'",
":",
"'\\\\Persist'",
";",
"}",
"// Instantiate",
"$",
"reflClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"taskType",
")",
";",
"$",
"task",
"=",
"$",
"reflClass",
"->",
"newInstance",
"(",
"$",
"this",
")",
";",
"// Set object property. No need to go via the setter because we have already determined this is compatible",
"$",
"reflProperty",
"=",
"$",
"reflClass",
"->",
"getProperty",
"(",
"'object'",
")",
";",
"$",
"reflProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"reflProperty",
"->",
"setValue",
"(",
"$",
"task",
",",
"$",
"object",
")",
";",
"return",
"$",
"task",
";",
"}"
] | Decide if how we want to save this
$object | [
"Decide",
"if",
"how",
"we",
"want",
"to",
"save",
"this",
"$object"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L123-L186 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.debug | public function debug( $state = null )
{
$default = self::DEBUG_SIMULATE + self::DEBUG_SHOW_QUERY;
if( is_bool( $state ) ) {
$state = $state ? $default : 0;;
} elseif ( $state === null ) {
$state = $default;
}
$this->debug = $state;
return $this->debug;
} | php | public function debug( $state = null )
{
$default = self::DEBUG_SIMULATE + self::DEBUG_SHOW_QUERY;
if( is_bool( $state ) ) {
$state = $state ? $default : 0;;
} elseif ( $state === null ) {
$state = $default;
}
$this->debug = $state;
return $this->debug;
} | [
"public",
"function",
"debug",
"(",
"$",
"state",
"=",
"null",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"DEBUG_SIMULATE",
"+",
"self",
"::",
"DEBUG_SHOW_QUERY",
";",
"if",
"(",
"is_bool",
"(",
"$",
"state",
")",
")",
"{",
"$",
"state",
"=",
"$",
"state",
"?",
"$",
"default",
":",
"0",
";",
";",
"}",
"elseif",
"(",
"$",
"state",
"===",
"null",
")",
"{",
"$",
"state",
"=",
"$",
"default",
";",
"}",
"$",
"this",
"->",
"debug",
"=",
"$",
"state",
";",
"return",
"$",
"this",
"->",
"debug",
";",
"}"
] | Set the debug state
@param booly $state The requested state
@return bool The state just set. | [
"Set",
"the",
"debug",
"state"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L193-L203 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.newTransaction | public function newTransaction( $name = null, $updateLastTransaction = true )
{
// no name
if( !isset( $name ) ) {
$this->queue[] = array();
$name = $this->getTransaction( self::TRANSACTION_LAST_CREATED );
// name already taken
} elseif( array_key_exists( $name, $this->queue ) ) {
throw new \InvalidArgumentException("Transaction with name `{$name}` already exists can't create new named transaction.");
// new transaction
} elseif( !\is_scalar($name) ) {
throw new \InvalidArgumentException("Transaction name needs to be a scalar." );
} else {
$this->queue[$name] = array();
}
if( $updateLastTransaction ) {
$this->lastTransaction = $name;
}
return $name;
} | php | public function newTransaction( $name = null, $updateLastTransaction = true )
{
// no name
if( !isset( $name ) ) {
$this->queue[] = array();
$name = $this->getTransaction( self::TRANSACTION_LAST_CREATED );
// name already taken
} elseif( array_key_exists( $name, $this->queue ) ) {
throw new \InvalidArgumentException("Transaction with name `{$name}` already exists can't create new named transaction.");
// new transaction
} elseif( !\is_scalar($name) ) {
throw new \InvalidArgumentException("Transaction name needs to be a scalar." );
} else {
$this->queue[$name] = array();
}
if( $updateLastTransaction ) {
$this->lastTransaction = $name;
}
return $name;
} | [
"public",
"function",
"newTransaction",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"updateLastTransaction",
"=",
"true",
")",
"{",
"// no name",
"if",
"(",
"!",
"isset",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"queue",
"[",
"]",
"=",
"array",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getTransaction",
"(",
"self",
"::",
"TRANSACTION_LAST_CREATED",
")",
";",
"// name already taken",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"queue",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Transaction with name `{$name}` already exists can't create new named transaction.\"",
")",
";",
"// new transaction",
"}",
"elseif",
"(",
"!",
"\\",
"is_scalar",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Transaction name needs to be a scalar.\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"queue",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"updateLastTransaction",
")",
"{",
"$",
"this",
"->",
"lastTransaction",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Create a new transaction
@param scalar Optional. Transaction name
@param booly Set update $this->lastTransaction pointer to refer to this new transaction
@return scalar New transaction name | [
"Create",
"a",
"new",
"transaction"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L213-L244 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.persist | public function persist( $object, $transaction = self::TRANSACTION_LAST_USED )
{
if( !is_object( $object ) ) {
throw new \InvalidArgumentException("I can only persist objects.");
}
if( !( $object instanceof Task) ) {
$object = $this->getTask( $object, Task::PERSIST );
}
$transaction = $this->getTransaction($transaction, true);
$this->queue[$transaction][] = $object;
return $this;
} | php | public function persist( $object, $transaction = self::TRANSACTION_LAST_USED )
{
if( !is_object( $object ) ) {
throw new \InvalidArgumentException("I can only persist objects.");
}
if( !( $object instanceof Task) ) {
$object = $this->getTask( $object, Task::PERSIST );
}
$transaction = $this->getTransaction($transaction, true);
$this->queue[$transaction][] = $object;
return $this;
} | [
"public",
"function",
"persist",
"(",
"$",
"object",
",",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTION_LAST_USED",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"I can only persist objects.\"",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"object",
"instanceof",
"Task",
")",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getTask",
"(",
"$",
"object",
",",
"Task",
"::",
"PERSIST",
")",
";",
"}",
"$",
"transaction",
"=",
"$",
"this",
"->",
"getTransaction",
"(",
"$",
"transaction",
",",
"true",
")",
";",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
"[",
"]",
"=",
"$",
"object",
";",
"return",
"$",
"this",
";",
"}"
] | Add a item to the queue for persitance on flush
@param object $object ... to persist
@param scalar $namedTransaction Transaction to persist this entity within
@return true | [
"Add",
"a",
"item",
"to",
"the",
"queue",
"for",
"persitance",
"on",
"flush"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L254-L268 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.delete | public function delete( $object, $transaction = self::TRANSACTION_LAST_USED )
{
// this'll throw a exception if anything isn't right
$task = Task::init( $object, Task::DELETE );
$transaction = $this->getTransaction($transaction,true);
$this->queue[$transaction][] = $task;
return $this;
} | php | public function delete( $object, $transaction = self::TRANSACTION_LAST_USED )
{
// this'll throw a exception if anything isn't right
$task = Task::init( $object, Task::DELETE );
$transaction = $this->getTransaction($transaction,true);
$this->queue[$transaction][] = $task;
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"object",
",",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTION_LAST_USED",
")",
"{",
"// this'll throw a exception if anything isn't right",
"$",
"task",
"=",
"Task",
"::",
"init",
"(",
"$",
"object",
",",
"Task",
"::",
"DELETE",
")",
";",
"$",
"transaction",
"=",
"$",
"this",
"->",
"getTransaction",
"(",
"$",
"transaction",
",",
"true",
")",
";",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
"[",
"]",
"=",
"$",
"task",
";",
"return",
"$",
"this",
";",
"}"
] | Add a item to the queue for persitance on flush
@param object $object ... to delete
@param scalar $namedTransaction Transaction to persist this entity within
@return true | [
"Add",
"a",
"item",
"to",
"the",
"queue",
"for",
"persitance",
"on",
"flush"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L278-L285 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.flush | public function flush( $transaction = null, $onFailure = self::FLUSH_ABORT, $throwExceptions = true )
{
if( is_null( $transaction ) ) {
$transaction = self::TRANSACTIONS_ALL;
}
if( is_null( $onFailure) ) {
$onFailure = self::FLUSH_ABORT;
}
$response = new Response();
$exceptions = [];
$haveAnyTransactionsFailed = false;
// simulate
$simulate = ( $this->debug & self::DEBUG_SIMULATE );
// profiler
$profiler = new Profiler( "Record manager" );
$profiler->log();
// debugging query show
$debugQuery = null;
if( $this->debug & self::DEBUG_SHOW_QUERY ) {
$debugQuery = function ( $e, $event, $data ) {
echo $data . "\n";
};
$this->db->debug->on( Debug::INFO, $debugQuery );
}
// trap all throw exceptions so that we can properly unattach the $db->debug->on( Pg::QueryPassed $listener )
try {
// iterate selected transactions
foreach( $this->getQueue( $transaction, true, true ) as $transaction => $queue ) {
unset( $this->queue[$transaction] );
$taskResponse = null;
$hasTransactionFailed = false;
$beginTransaction = new Query( "BEGIN TRANSACTION READ WRITE; /* %transaction:% */" );
$beginTransaction->transaction = $transaction;
$this->db->query( $beginTransaction );
$this->eventEmitter->emit( EventEmitter::TRANSACTION_START, $this, $transaction, $queue );
// loop over our tasks
foreach( $queue as $task ) {
// are we continuing to process?
if( $hasTransactionFailed or ( $haveAnyTransactionsFailed && $onFailure === self::FLUSH_ABORT ) ) {
$taskResponse = Response::ABORTED;
} else {
try {
$taskResponse = $task->execute( $this->db, $simulate ) ? Response::SUCCESS : Response::FAILED;
} catch( \Exception $e ) {
// It'd be nice if we could just test for Query exceptions here but unfortunately PHPUnit dicks pretty hard with exception types.
// @Mr Beale. I realise this violates the "only handle exceptions that you understand" rule but I can't find a way round this. Pete
$taskResponse = $e;
$exceptions[] = $e;
}
}
// transaction success
if( $taskResponse !== Response::SUCCESS ) {
$hasTransactionFailed = true;
$haveAnyTransactionsFailed = true;
}
$response->add( $transaction, $task, $taskResponse );
}
// end or rollback transaction
$endTransaction = new Query( "%commitOrRollback:% TRANSACTION; /* %transaction:% */" );
$endTransaction->commitOrRollback = new Raw($hasTransactionFailed ? 'ROLLBACK' : 'COMMIT');
$endTransaction->transaction = $transaction;
$this->db->query( $endTransaction );
// response rollback
if( $hasTransactionFailed ) {
$response->rollback( $transaction );
}
$profiler->log( $transaction );
}
// if we've gathered any exceptions throw them here
if( $throwExceptions and $exceptions ) {
throw $exceptions[0];
}
$response->profilerAssign( $profiler );
} catch ( \Exception $e ) {
$this->db->debug->removeListener( Pg::QUERY_PARSED, $debugQuery );
throw $e;
}
return $response;
} | php | public function flush( $transaction = null, $onFailure = self::FLUSH_ABORT, $throwExceptions = true )
{
if( is_null( $transaction ) ) {
$transaction = self::TRANSACTIONS_ALL;
}
if( is_null( $onFailure) ) {
$onFailure = self::FLUSH_ABORT;
}
$response = new Response();
$exceptions = [];
$haveAnyTransactionsFailed = false;
// simulate
$simulate = ( $this->debug & self::DEBUG_SIMULATE );
// profiler
$profiler = new Profiler( "Record manager" );
$profiler->log();
// debugging query show
$debugQuery = null;
if( $this->debug & self::DEBUG_SHOW_QUERY ) {
$debugQuery = function ( $e, $event, $data ) {
echo $data . "\n";
};
$this->db->debug->on( Debug::INFO, $debugQuery );
}
// trap all throw exceptions so that we can properly unattach the $db->debug->on( Pg::QueryPassed $listener )
try {
// iterate selected transactions
foreach( $this->getQueue( $transaction, true, true ) as $transaction => $queue ) {
unset( $this->queue[$transaction] );
$taskResponse = null;
$hasTransactionFailed = false;
$beginTransaction = new Query( "BEGIN TRANSACTION READ WRITE; /* %transaction:% */" );
$beginTransaction->transaction = $transaction;
$this->db->query( $beginTransaction );
$this->eventEmitter->emit( EventEmitter::TRANSACTION_START, $this, $transaction, $queue );
// loop over our tasks
foreach( $queue as $task ) {
// are we continuing to process?
if( $hasTransactionFailed or ( $haveAnyTransactionsFailed && $onFailure === self::FLUSH_ABORT ) ) {
$taskResponse = Response::ABORTED;
} else {
try {
$taskResponse = $task->execute( $this->db, $simulate ) ? Response::SUCCESS : Response::FAILED;
} catch( \Exception $e ) {
// It'd be nice if we could just test for Query exceptions here but unfortunately PHPUnit dicks pretty hard with exception types.
// @Mr Beale. I realise this violates the "only handle exceptions that you understand" rule but I can't find a way round this. Pete
$taskResponse = $e;
$exceptions[] = $e;
}
}
// transaction success
if( $taskResponse !== Response::SUCCESS ) {
$hasTransactionFailed = true;
$haveAnyTransactionsFailed = true;
}
$response->add( $transaction, $task, $taskResponse );
}
// end or rollback transaction
$endTransaction = new Query( "%commitOrRollback:% TRANSACTION; /* %transaction:% */" );
$endTransaction->commitOrRollback = new Raw($hasTransactionFailed ? 'ROLLBACK' : 'COMMIT');
$endTransaction->transaction = $transaction;
$this->db->query( $endTransaction );
// response rollback
if( $hasTransactionFailed ) {
$response->rollback( $transaction );
}
$profiler->log( $transaction );
}
// if we've gathered any exceptions throw them here
if( $throwExceptions and $exceptions ) {
throw $exceptions[0];
}
$response->profilerAssign( $profiler );
} catch ( \Exception $e ) {
$this->db->debug->removeListener( Pg::QUERY_PARSED, $debugQuery );
throw $e;
}
return $response;
} | [
"public",
"function",
"flush",
"(",
"$",
"transaction",
"=",
"null",
",",
"$",
"onFailure",
"=",
"self",
"::",
"FLUSH_ABORT",
",",
"$",
"throwExceptions",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"transaction",
")",
")",
"{",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTIONS_ALL",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"onFailure",
")",
")",
"{",
"$",
"onFailure",
"=",
"self",
"::",
"FLUSH_ABORT",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"exceptions",
"=",
"[",
"]",
";",
"$",
"haveAnyTransactionsFailed",
"=",
"false",
";",
"// simulate",
"$",
"simulate",
"=",
"(",
"$",
"this",
"->",
"debug",
"&",
"self",
"::",
"DEBUG_SIMULATE",
")",
";",
"// profiler",
"$",
"profiler",
"=",
"new",
"Profiler",
"(",
"\"Record manager\"",
")",
";",
"$",
"profiler",
"->",
"log",
"(",
")",
";",
"// debugging query show",
"$",
"debugQuery",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
"&",
"self",
"::",
"DEBUG_SHOW_QUERY",
")",
"{",
"$",
"debugQuery",
"=",
"function",
"(",
"$",
"e",
",",
"$",
"event",
",",
"$",
"data",
")",
"{",
"echo",
"$",
"data",
".",
"\"\\n\"",
";",
"}",
";",
"$",
"this",
"->",
"db",
"->",
"debug",
"->",
"on",
"(",
"Debug",
"::",
"INFO",
",",
"$",
"debugQuery",
")",
";",
"}",
"// trap all throw exceptions so that we can properly unattach the $db->debug->on( Pg::QueryPassed $listener )",
"try",
"{",
"// iterate selected transactions",
"foreach",
"(",
"$",
"this",
"->",
"getQueue",
"(",
"$",
"transaction",
",",
"true",
",",
"true",
")",
"as",
"$",
"transaction",
"=>",
"$",
"queue",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
")",
";",
"$",
"taskResponse",
"=",
"null",
";",
"$",
"hasTransactionFailed",
"=",
"false",
";",
"$",
"beginTransaction",
"=",
"new",
"Query",
"(",
"\"BEGIN TRANSACTION READ WRITE; /* %transaction:% */\"",
")",
";",
"$",
"beginTransaction",
"->",
"transaction",
"=",
"$",
"transaction",
";",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"beginTransaction",
")",
";",
"$",
"this",
"->",
"eventEmitter",
"->",
"emit",
"(",
"EventEmitter",
"::",
"TRANSACTION_START",
",",
"$",
"this",
",",
"$",
"transaction",
",",
"$",
"queue",
")",
";",
"// loop over our tasks",
"foreach",
"(",
"$",
"queue",
"as",
"$",
"task",
")",
"{",
"// are we continuing to process?",
"if",
"(",
"$",
"hasTransactionFailed",
"or",
"(",
"$",
"haveAnyTransactionsFailed",
"&&",
"$",
"onFailure",
"===",
"self",
"::",
"FLUSH_ABORT",
")",
")",
"{",
"$",
"taskResponse",
"=",
"Response",
"::",
"ABORTED",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"taskResponse",
"=",
"$",
"task",
"->",
"execute",
"(",
"$",
"this",
"->",
"db",
",",
"$",
"simulate",
")",
"?",
"Response",
"::",
"SUCCESS",
":",
"Response",
"::",
"FAILED",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// It'd be nice if we could just test for Query exceptions here but unfortunately PHPUnit dicks pretty hard with exception types.",
"// @Mr Beale. I realise this violates the \"only handle exceptions that you understand\" rule but I can't find a way round this. Pete",
"$",
"taskResponse",
"=",
"$",
"e",
";",
"$",
"exceptions",
"[",
"]",
"=",
"$",
"e",
";",
"}",
"}",
"// transaction success",
"if",
"(",
"$",
"taskResponse",
"!==",
"Response",
"::",
"SUCCESS",
")",
"{",
"$",
"hasTransactionFailed",
"=",
"true",
";",
"$",
"haveAnyTransactionsFailed",
"=",
"true",
";",
"}",
"$",
"response",
"->",
"add",
"(",
"$",
"transaction",
",",
"$",
"task",
",",
"$",
"taskResponse",
")",
";",
"}",
"// end or rollback transaction",
"$",
"endTransaction",
"=",
"new",
"Query",
"(",
"\"%commitOrRollback:% TRANSACTION; /* %transaction:% */\"",
")",
";",
"$",
"endTransaction",
"->",
"commitOrRollback",
"=",
"new",
"Raw",
"(",
"$",
"hasTransactionFailed",
"?",
"'ROLLBACK'",
":",
"'COMMIT'",
")",
";",
"$",
"endTransaction",
"->",
"transaction",
"=",
"$",
"transaction",
";",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"endTransaction",
")",
";",
"// response rollback",
"if",
"(",
"$",
"hasTransactionFailed",
")",
"{",
"$",
"response",
"->",
"rollback",
"(",
"$",
"transaction",
")",
";",
"}",
"$",
"profiler",
"->",
"log",
"(",
"$",
"transaction",
")",
";",
"}",
"// if we've gathered any exceptions throw them here",
"if",
"(",
"$",
"throwExceptions",
"and",
"$",
"exceptions",
")",
"{",
"throw",
"$",
"exceptions",
"[",
"0",
"]",
";",
"}",
"$",
"response",
"->",
"profilerAssign",
"(",
"$",
"profiler",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"debug",
"->",
"removeListener",
"(",
"Pg",
"::",
"QUERY_PARSED",
",",
"$",
"debugQuery",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Add a item to the queue for persitance on flush
@param $trancation
@param $onFailure
@return bool | [
"Add",
"a",
"item",
"to",
"the",
"queue",
"for",
"persitance",
"on",
"flush"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L295-L399 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.getTransaction | public function getTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
{
if( $transaction === self::TRANSACTIONS_ALL ) {
return array_keys( $this->queue );
}
if( $transaction === self::TRANSACTION_LAST_CREATED ) {
if( !$this->queue) {
$this->newTransaction();
}
$queue = array_keys( $this->queue );
return array_pop( $queue );
}
if( $transaction === self::TRANSACTION_LAST_USED ) {
if( !$this->queue) {
$this->newTransaction();
}
return $this->lastTransaction;
}
if( $transaction === self::TRANSACTION_NEW ) {
return $this->newTransaction();
}
if( !array_key_exists( $transaction, $this->queue ) ) {
if( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$transaction}` doesn't exist. Sorry."
);
}
return null;
}
return $transaction;
} | php | public function getTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
{
if( $transaction === self::TRANSACTIONS_ALL ) {
return array_keys( $this->queue );
}
if( $transaction === self::TRANSACTION_LAST_CREATED ) {
if( !$this->queue) {
$this->newTransaction();
}
$queue = array_keys( $this->queue );
return array_pop( $queue );
}
if( $transaction === self::TRANSACTION_LAST_USED ) {
if( !$this->queue) {
$this->newTransaction();
}
return $this->lastTransaction;
}
if( $transaction === self::TRANSACTION_NEW ) {
return $this->newTransaction();
}
if( !array_key_exists( $transaction, $this->queue ) ) {
if( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$transaction}` doesn't exist. Sorry."
);
}
return null;
}
return $transaction;
} | [
"public",
"function",
"getTransaction",
"(",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTION_LAST_USED",
",",
"$",
"throwExceptionIfNotFound",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTIONS_ALL",
")",
"{",
"return",
"array_keys",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"}",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTION_LAST_CREATED",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
")",
"{",
"$",
"this",
"->",
"newTransaction",
"(",
")",
";",
"}",
"$",
"queue",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"return",
"array_pop",
"(",
"$",
"queue",
")",
";",
"}",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTION_LAST_USED",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
")",
"{",
"$",
"this",
"->",
"newTransaction",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lastTransaction",
";",
"}",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTION_NEW",
")",
"{",
"return",
"$",
"this",
"->",
"newTransaction",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"transaction",
",",
"$",
"this",
"->",
"queue",
")",
")",
"{",
"if",
"(",
"$",
"throwExceptionIfNotFound",
")",
"{",
"throw",
"new",
"TransactionDoesNotExistException",
"(",
"\"Transaction with this name `{$transaction}` doesn't exist. Sorry.\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"return",
"$",
"transaction",
";",
"}"
] | Get a transaction name
@param scalar The name of a transaction;
@param bool Throw exception if we can't find.
@return scalar|false in the event of not found | [
"Get",
"a",
"transaction",
"name"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L409-L446 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.removeTransaction | public function removeTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
{
// remove all transactions
if( $transaction === self::TRANSACTIONS_ALL ) {
$numTransactions = count( $this->queue );
$this->queue = array();
$this->lastTransaction = null;
return $numTransactions;
}
// last created transaction
if( $transaction === self::TRANSACTION_LAST_CREATED ) {
$keys = array_keys( $this->queue );
if( $transaction = array_pop( $keys ) ) {
if( $this->lastTransaction === $transaction ) {
$this->lastTransaction = null;
}
unset( $this->queue[$transaction] );
return 1;
}
return 0;
}
// last used
if( $transaction === self::TRANSACTION_LAST_USED ) {
if( $this->lastTransaction ) {
unset( $this->queue[$this->lastTransaction] );
$this->lastTransaction = null;
return 0;
}
return 0;
}
// array of transactions
if( is_array( $transaction ) ) {
$output = 0;
foreach( $transaction as $name ) {
if( array_key_exists( $name, $this->queue ) ) {
if( $this->lastTransaction === $name ) {
$this->lastTransaction = null;
}
unset( $this->queue[$name] );
$output++;
} elseif ( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$name}` doesn't exist. Sorry."
);
}
}
return $output;
}
if( is_scalar($transaction) ) {
if( array_key_exists( $transaction, $this->queue ) ) {
if( $this->lastTransaction === $transaction ) {
$this->lastTransaction = null;
}
unset( $this->queue[$name] );
return 1;
} elseif ( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$transaction}` doesn't exist. Sorry."
);
}
return 0;
}
throw new \InvalidArgumentException(
sprintf(
"Not sure how to remove transaction `%s`",
print_r( $transaction, true )
)
);
} | php | public function removeTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
{
// remove all transactions
if( $transaction === self::TRANSACTIONS_ALL ) {
$numTransactions = count( $this->queue );
$this->queue = array();
$this->lastTransaction = null;
return $numTransactions;
}
// last created transaction
if( $transaction === self::TRANSACTION_LAST_CREATED ) {
$keys = array_keys( $this->queue );
if( $transaction = array_pop( $keys ) ) {
if( $this->lastTransaction === $transaction ) {
$this->lastTransaction = null;
}
unset( $this->queue[$transaction] );
return 1;
}
return 0;
}
// last used
if( $transaction === self::TRANSACTION_LAST_USED ) {
if( $this->lastTransaction ) {
unset( $this->queue[$this->lastTransaction] );
$this->lastTransaction = null;
return 0;
}
return 0;
}
// array of transactions
if( is_array( $transaction ) ) {
$output = 0;
foreach( $transaction as $name ) {
if( array_key_exists( $name, $this->queue ) ) {
if( $this->lastTransaction === $name ) {
$this->lastTransaction = null;
}
unset( $this->queue[$name] );
$output++;
} elseif ( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$name}` doesn't exist. Sorry."
);
}
}
return $output;
}
if( is_scalar($transaction) ) {
if( array_key_exists( $transaction, $this->queue ) ) {
if( $this->lastTransaction === $transaction ) {
$this->lastTransaction = null;
}
unset( $this->queue[$name] );
return 1;
} elseif ( $throwExceptionIfNotFound ) {
throw new TransactionDoesNotExistException(
"Transaction with this name `{$transaction}` doesn't exist. Sorry."
);
}
return 0;
}
throw new \InvalidArgumentException(
sprintf(
"Not sure how to remove transaction `%s`",
print_r( $transaction, true )
)
);
} | [
"public",
"function",
"removeTransaction",
"(",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTION_LAST_USED",
",",
"$",
"throwExceptionIfNotFound",
"=",
"true",
")",
"{",
"// remove all transactions",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTIONS_ALL",
")",
"{",
"$",
"numTransactions",
"=",
"count",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"$",
"this",
"->",
"queue",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"lastTransaction",
"=",
"null",
";",
"return",
"$",
"numTransactions",
";",
"}",
"// last created transaction",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTION_LAST_CREATED",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"if",
"(",
"$",
"transaction",
"=",
"array_pop",
"(",
"$",
"keys",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastTransaction",
"===",
"$",
"transaction",
")",
"{",
"$",
"this",
"->",
"lastTransaction",
"=",
"null",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
")",
";",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}",
"// last used",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTION_LAST_USED",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastTransaction",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"this",
"->",
"lastTransaction",
"]",
")",
";",
"$",
"this",
"->",
"lastTransaction",
"=",
"null",
";",
"return",
"0",
";",
"}",
"return",
"0",
";",
"}",
"// array of transactions",
"if",
"(",
"is_array",
"(",
"$",
"transaction",
")",
")",
"{",
"$",
"output",
"=",
"0",
";",
"foreach",
"(",
"$",
"transaction",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"queue",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastTransaction",
"===",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"lastTransaction",
"=",
"null",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"name",
"]",
")",
";",
"$",
"output",
"++",
";",
"}",
"elseif",
"(",
"$",
"throwExceptionIfNotFound",
")",
"{",
"throw",
"new",
"TransactionDoesNotExistException",
"(",
"\"Transaction with this name `{$name}` doesn't exist. Sorry.\"",
")",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"transaction",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"transaction",
",",
"$",
"this",
"->",
"queue",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastTransaction",
"===",
"$",
"transaction",
")",
"{",
"$",
"this",
"->",
"lastTransaction",
"=",
"null",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"name",
"]",
")",
";",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"throwExceptionIfNotFound",
")",
"{",
"throw",
"new",
"TransactionDoesNotExistException",
"(",
"\"Transaction with this name `{$transaction}` doesn't exist. Sorry.\"",
")",
";",
"}",
"return",
"0",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Not sure how to remove transaction `%s`\"",
",",
"print_r",
"(",
"$",
"transaction",
",",
"true",
")",
")",
")",
";",
"}"
] | Remove a transaction
@param scalar|array The name of the transaction
@param bool Throw a exception if the transaction we want to remove can't be found
@return int The number of transactions removed | [
"Remove",
"a",
"transaction"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L456-L531 |
squareproton/Bond | src/Bond/RecordManager.php | RecordManager.getQueue | public function getQueue( $transaction = self::TRANSACTIONS_ALL, $throwExceptionIfNotFound = true, $outputAsArray = false )
{
if( $transaction === self::TRANSACTIONS_ALL ) {
return $this->queue;
// passed a array of transactions
} elseif( is_array( $transaction ) ) {
if( $throwExceptionIfNotFound and $missing = array_diff( $transaction, array_keys( $this->queue ) ) ) {
$missing = implode( ', ', $missing );
throw new TransactionDoesNotExistException(
"The following requested named transactions do not exist `{$missing}`"
);
}
// this is a array_intersect *with ordering*
$output = [];
foreach( $transaction as $name ) {
$output[$name] = $this->queue[$name];
}
return $output;
}
$transaction = $this->getTransaction( $transaction, $throwExceptionIfNotFound );
if( $transaction !== null ) {
return $outputAsArray
? array( $transaction => $this->queue[$transaction] )
: $this->queue[$transaction];
}
return $outputAsArray ? array() : null;
} | php | public function getQueue( $transaction = self::TRANSACTIONS_ALL, $throwExceptionIfNotFound = true, $outputAsArray = false )
{
if( $transaction === self::TRANSACTIONS_ALL ) {
return $this->queue;
// passed a array of transactions
} elseif( is_array( $transaction ) ) {
if( $throwExceptionIfNotFound and $missing = array_diff( $transaction, array_keys( $this->queue ) ) ) {
$missing = implode( ', ', $missing );
throw new TransactionDoesNotExistException(
"The following requested named transactions do not exist `{$missing}`"
);
}
// this is a array_intersect *with ordering*
$output = [];
foreach( $transaction as $name ) {
$output[$name] = $this->queue[$name];
}
return $output;
}
$transaction = $this->getTransaction( $transaction, $throwExceptionIfNotFound );
if( $transaction !== null ) {
return $outputAsArray
? array( $transaction => $this->queue[$transaction] )
: $this->queue[$transaction];
}
return $outputAsArray ? array() : null;
} | [
"public",
"function",
"getQueue",
"(",
"$",
"transaction",
"=",
"self",
"::",
"TRANSACTIONS_ALL",
",",
"$",
"throwExceptionIfNotFound",
"=",
"true",
",",
"$",
"outputAsArray",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"transaction",
"===",
"self",
"::",
"TRANSACTIONS_ALL",
")",
"{",
"return",
"$",
"this",
"->",
"queue",
";",
"// passed a array of transactions",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"transaction",
")",
")",
"{",
"if",
"(",
"$",
"throwExceptionIfNotFound",
"and",
"$",
"missing",
"=",
"array_diff",
"(",
"$",
"transaction",
",",
"array_keys",
"(",
"$",
"this",
"->",
"queue",
")",
")",
")",
"{",
"$",
"missing",
"=",
"implode",
"(",
"', '",
",",
"$",
"missing",
")",
";",
"throw",
"new",
"TransactionDoesNotExistException",
"(",
"\"The following requested named transactions do not exist `{$missing}`\"",
")",
";",
"}",
"// this is a array_intersect *with ordering*",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"transaction",
"as",
"$",
"name",
")",
"{",
"$",
"output",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"queue",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"output",
";",
"}",
"$",
"transaction",
"=",
"$",
"this",
"->",
"getTransaction",
"(",
"$",
"transaction",
",",
"$",
"throwExceptionIfNotFound",
")",
";",
"if",
"(",
"$",
"transaction",
"!==",
"null",
")",
"{",
"return",
"$",
"outputAsArray",
"?",
"array",
"(",
"$",
"transaction",
"=>",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
")",
":",
"$",
"this",
"->",
"queue",
"[",
"$",
"transaction",
"]",
";",
"}",
"return",
"$",
"outputAsArray",
"?",
"array",
"(",
")",
":",
"null",
";",
"}"
] | Get queue.
@param array|scalar The name of a transaction or a array or transactions
@param bool Throw exception if we can't find
@return array The queue | [
"Get",
"queue",
".",
"@param",
"array|scalar",
"The",
"name",
"of",
"a",
"transaction",
"or",
"a",
"array",
"or",
"transactions",
"@param",
"bool",
"Throw",
"exception",
"if",
"we",
"can",
"t",
"find"
] | train | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/RecordManager.php#L540-L573 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.send | public function send($closure = null) {
if(gettype($closure) == 'object') {
call_user_func($closure, $this);
}
//Renders the optional viewmodels and assign the mail variables to them
foreach($this -> viewmodels as $type => $view) {
if(null !== $view) {
$viewmodel = new ViewModel($view, false);
$viewmodel -> assign($this -> variables);
$this -> message[$type] = $viewmodel -> render();
}
}
$to = $this -> formatTo();
$headers = $this -> formatHeaders();
$message = $this -> formatMessage();
@mail($to, $this -> subject, $message, $headers);
if(null === error_get_last()) {
$this -> send = true;
}
return $this;
} | php | public function send($closure = null) {
if(gettype($closure) == 'object') {
call_user_func($closure, $this);
}
//Renders the optional viewmodels and assign the mail variables to them
foreach($this -> viewmodels as $type => $view) {
if(null !== $view) {
$viewmodel = new ViewModel($view, false);
$viewmodel -> assign($this -> variables);
$this -> message[$type] = $viewmodel -> render();
}
}
$to = $this -> formatTo();
$headers = $this -> formatHeaders();
$message = $this -> formatMessage();
@mail($to, $this -> subject, $message, $headers);
if(null === error_get_last()) {
$this -> send = true;
}
return $this;
} | [
"public",
"function",
"send",
"(",
"$",
"closure",
"=",
"null",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"closure",
")",
"==",
"'object'",
")",
"{",
"call_user_func",
"(",
"$",
"closure",
",",
"$",
"this",
")",
";",
"}",
"//Renders the optional viewmodels and assign the mail variables to them\r",
"foreach",
"(",
"$",
"this",
"->",
"viewmodels",
"as",
"$",
"type",
"=>",
"$",
"view",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"view",
")",
"{",
"$",
"viewmodel",
"=",
"new",
"ViewModel",
"(",
"$",
"view",
",",
"false",
")",
";",
"$",
"viewmodel",
"->",
"assign",
"(",
"$",
"this",
"->",
"variables",
")",
";",
"$",
"this",
"->",
"message",
"[",
"$",
"type",
"]",
"=",
"$",
"viewmodel",
"->",
"render",
"(",
")",
";",
"}",
"}",
"$",
"to",
"=",
"$",
"this",
"->",
"formatTo",
"(",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"formatHeaders",
"(",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"formatMessage",
"(",
")",
";",
"@",
"mail",
"(",
"$",
"to",
",",
"$",
"this",
"->",
"subject",
",",
"$",
"message",
",",
"$",
"headers",
")",
";",
"if",
"(",
"null",
"===",
"error_get_last",
"(",
")",
")",
"{",
"$",
"this",
"->",
"send",
"=",
"true",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Try to send the mail with optional callback.
@param object $closure
@return sFire\Mail\Mail | [
"Try",
"to",
"send",
"the",
"mail",
"with",
"optional",
"callback",
"."
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L69-L98 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.addHeader | public function addHeader($key, $value) {
if(false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(false === is_string($value)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($value)), E_USER_ERROR);
}
if(false === isset($this -> headers['custom'])) {
$this -> headers['custom'] = [];
}
$this -> headers['custom'][$key] = $value;
} | php | public function addHeader($key, $value) {
if(false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(false === is_string($value)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($value)), E_USER_ERROR);
}
if(false === isset($this -> headers['custom'])) {
$this -> headers['custom'] = [];
}
$this -> headers['custom'][$key] = $value;
} | [
"public",
"function",
"addHeader",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"key",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"value",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Adds a custom header to the mail
@param string $key
@param string $value
@return sFire\Mail\Mail | [
"Adds",
"a",
"custom",
"header",
"to",
"the",
"mail"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L125-L140 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.message | public function message($html = null, $text = null) {
if(null !== $html && false === is_string($html)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($html)), E_USER_ERROR);
}
if(null !== $text && false === is_string($text)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($text)), E_USER_ERROR);
}
$this -> message['html'] = $html;
$this -> message['text'] = $text;
return $this;
} | php | public function message($html = null, $text = null) {
if(null !== $html && false === is_string($html)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($html)), E_USER_ERROR);
}
if(null !== $text && false === is_string($text)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($text)), E_USER_ERROR);
}
$this -> message['html'] = $html;
$this -> message['text'] = $text;
return $this;
} | [
"public",
"function",
"message",
"(",
"$",
"html",
"=",
"null",
",",
"$",
"text",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"html",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"html",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"html",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"text",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"text",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"message",
"[",
"'html'",
"]",
"=",
"$",
"html",
";",
"$",
"this",
"->",
"message",
"[",
"'text'",
"]",
"=",
"$",
"text",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a message in HTML and/or plain text by giving a string text
@param string $html
@param string $text
@return sFire\Mail\Mail | [
"Adds",
"a",
"message",
"in",
"HTML",
"and",
"/",
"or",
"plain",
"text",
"by",
"giving",
"a",
"string",
"text"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L149-L163 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.removeHeader | public function removeHeader($key) {
if(false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(true === isset($this -> headers['custom'][$key])) {
unset($this -> headers['custom'][$key]);
}
} | php | public function removeHeader($key) {
if(false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(true === isset($this -> headers['custom'][$key])) {
unset($this -> headers['custom'][$key]);
}
} | [
"public",
"function",
"removeHeader",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"key",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Removes a custom header by key
@param string $key
@return sFire\Mail\Mail | [
"Removes",
"a",
"custom",
"header",
"by",
"key"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L180-L189 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.attachment | public function attachment($file, $name = null, $mime = null) {
if(true === is_string($file)) {
$file = new File($file);
}
if(false === $file instanceof File) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or sFire\System\File, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
}
if(false === $file -> isReadable()) {
return trigger_error(sprintf('Argument 1 passed to %s() must existing and readable file', __METHOD__), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(null !== $mime && false === is_string($mime)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mime)), E_USER_ERROR);
}
if(false === isset($this -> headers['files'])) {
$this -> headers['files'] = [];
}
$name = null !== $name ? $name : $file -> entity() -> getBasename();
$mime = null !== $mime ? $mime : $file -> getMime();
$this -> headers['files'][] = (object) ['file' => $file, 'name' => $name, 'mime' => $mime];
return $this;
} | php | public function attachment($file, $name = null, $mime = null) {
if(true === is_string($file)) {
$file = new File($file);
}
if(false === $file instanceof File) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or sFire\System\File, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
}
if(false === $file -> isReadable()) {
return trigger_error(sprintf('Argument 1 passed to %s() must existing and readable file', __METHOD__), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(null !== $mime && false === is_string($mime)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mime)), E_USER_ERROR);
}
if(false === isset($this -> headers['files'])) {
$this -> headers['files'] = [];
}
$name = null !== $name ? $name : $file -> entity() -> getBasename();
$mime = null !== $mime ? $mime : $file -> getMime();
$this -> headers['files'][] = (object) ['file' => $file, 'name' => $name, 'mime' => $mime];
return $this;
} | [
"public",
"function",
"attachment",
"(",
"$",
"file",
",",
"$",
"name",
"=",
"null",
",",
"$",
"mime",
"=",
"null",
")",
"{",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"file",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"file",
"instanceof",
"File",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or sFire\\System\\File, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"file",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"file",
"->",
"isReadable",
"(",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must existing and readable file'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"name",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"mime",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"mime",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"mime",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"name",
"=",
"null",
"!==",
"$",
"name",
"?",
"$",
"name",
":",
"$",
"file",
"->",
"entity",
"(",
")",
"->",
"getBasename",
"(",
")",
";",
"$",
"mime",
"=",
"null",
"!==",
"$",
"mime",
"?",
"$",
"mime",
":",
"$",
"file",
"->",
"getMime",
"(",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'file'",
"=>",
"$",
"file",
",",
"'name'",
"=>",
"$",
"name",
",",
"'mime'",
"=>",
"$",
"mime",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Adds an attachment to the email
@param sFire\System\File|string $file
@param string $name
@param string $mime
@return sFire\Mail\Mail | [
"Adds",
"an",
"attachment",
"to",
"the",
"email"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L199-L231 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.subject | public function subject($subject) {
if(false === is_string($subject)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($subject)), E_USER_ERROR);
}
$this -> subject = $subject;
return $this;
} | php | public function subject($subject) {
if(false === is_string($subject)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($subject)), E_USER_ERROR);
}
$this -> subject = $subject;
return $this;
} | [
"public",
"function",
"subject",
"(",
"$",
"subject",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"subject",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"subject",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"subject",
"=",
"$",
"subject",
";",
"return",
"$",
"this",
";",
"}"
] | Adds subject
@param string $subject
@return sFire\Mail\Mail | [
"Adds",
"subject"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L239-L248 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.render | public function render($htmlview = null, $textview = null) {
if(null !== $htmlview && false === is_string($htmlview)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($htmlview)), E_USER_ERROR);
}
if(null !== $textview && false === is_string($textview)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($textview)), E_USER_ERROR);
}
$this -> viewmodels = ['html' => $htmlview, 'text' => $textview];
return $this;
} | php | public function render($htmlview = null, $textview = null) {
if(null !== $htmlview && false === is_string($htmlview)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($htmlview)), E_USER_ERROR);
}
if(null !== $textview && false === is_string($textview)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($textview)), E_USER_ERROR);
}
$this -> viewmodels = ['html' => $htmlview, 'text' => $textview];
return $this;
} | [
"public",
"function",
"render",
"(",
"$",
"htmlview",
"=",
"null",
",",
"$",
"textview",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"htmlview",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"htmlview",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"htmlview",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"textview",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"textview",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"textview",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"viewmodels",
"=",
"[",
"'html'",
"=>",
"$",
"htmlview",
",",
"'text'",
"=>",
"$",
"textview",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Parses the message by given an optional HTML view and an optional plain text view
@param string $htmlview
@param string $textview
@return sFire\Mail\Mail | [
"Parses",
"the",
"message",
"by",
"given",
"an",
"optional",
"HTML",
"view",
"and",
"an",
"optional",
"plain",
"text",
"view"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L257-L270 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.priority | public function priority($level = 1) {
if(false === ('-' . intval($level) == '-' . $level)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($level)), E_USER_ERROR);
}
if($level < 1 || $level > 5) {
return trigger_error(sprintf('Argument 1 passed to %s() should be between 1 and 5, "%s" given', __METHOD__, $level), E_USER_ERROR);
}
$priorities = [
1 => ['1 (Highest)', 'High', 'High'],
2 => ['2 (High)', 'High', 'High'],
3 => ['3 (Normal)', 'Normal', 'Normal'],
4 => ['4 (Low)', 'Low', 'Low'],
5 => ['5 (Lowest)', 'Low', 'Low'],
];
$this -> headers['priority'] = $priorities[$level];
return $this;
} | php | public function priority($level = 1) {
if(false === ('-' . intval($level) == '-' . $level)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($level)), E_USER_ERROR);
}
if($level < 1 || $level > 5) {
return trigger_error(sprintf('Argument 1 passed to %s() should be between 1 and 5, "%s" given', __METHOD__, $level), E_USER_ERROR);
}
$priorities = [
1 => ['1 (Highest)', 'High', 'High'],
2 => ['2 (High)', 'High', 'High'],
3 => ['3 (Normal)', 'Normal', 'Normal'],
4 => ['4 (Low)', 'Low', 'Low'],
5 => ['5 (Lowest)', 'Low', 'Low'],
];
$this -> headers['priority'] = $priorities[$level];
return $this;
} | [
"public",
"function",
"priority",
"(",
"$",
"level",
"=",
"1",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"level",
")",
"==",
"'-'",
".",
"$",
"level",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"level",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"level",
"<",
"1",
"||",
"$",
"level",
">",
"5",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() should be between 1 and 5, \"%s\" given'",
",",
"__METHOD__",
",",
"$",
"level",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"priorities",
"=",
"[",
"1",
"=>",
"[",
"'1 (Highest)'",
",",
"'High'",
",",
"'High'",
"]",
",",
"2",
"=>",
"[",
"'2 (High)'",
",",
"'High'",
",",
"'High'",
"]",
",",
"3",
"=>",
"[",
"'3 (Normal)'",
",",
"'Normal'",
",",
"'Normal'",
"]",
",",
"4",
"=>",
"[",
"'4 (Low)'",
",",
"'Low'",
",",
"'Low'",
"]",
",",
"5",
"=>",
"[",
"'5 (Lowest)'",
",",
"'Low'",
",",
"'Low'",
"]",
",",
"]",
";",
"$",
"this",
"->",
"headers",
"[",
"'priority'",
"]",
"=",
"$",
"priorities",
"[",
"$",
"level",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the priority Level between 1 and 5
@param int $level
@return sFire\Mail\Mail | [
"Sets",
"the",
"priority",
"Level",
"between",
"1",
"and",
"5"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L296-L318 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.to | public function to($email, $name = null) {
if(false === $this -> validateEmail($email)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be a valid email', __METHOD__), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false === isset($this -> headers['to'])) {
$this -> headers['to'] = [];
}
$this -> headers['to'][] = (object) ['email' => $email, 'name' => $name];
return $this;
} | php | public function to($email, $name = null) {
if(false === $this -> validateEmail($email)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be a valid email', __METHOD__), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false === isset($this -> headers['to'])) {
$this -> headers['to'] = [];
}
$this -> headers['to'][] = (object) ['email' => $email, 'name' => $name];
return $this;
} | [
"public",
"function",
"to",
"(",
"$",
"email",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"validateEmail",
"(",
"$",
"email",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be a valid email'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"name",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'to'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'to'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"headers",
"[",
"'to'",
"]",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'email'",
"=>",
"$",
"email",
",",
"'name'",
"=>",
"$",
"name",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Adds to email
@param string $email
@param string $name
@return sFire\Mail\Mail | [
"Adds",
"to",
"email"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L327-L344 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.validateEmail | private function validateEmail($email) {
if(true === is_string($email)) {
return false !== filter_var(trim($email), \FILTER_VALIDATE_EMAIL);
}
return false;
} | php | private function validateEmail($email) {
if(true === is_string($email)) {
return false !== filter_var(trim($email), \FILTER_VALIDATE_EMAIL);
}
return false;
} | [
"private",
"function",
"validateEmail",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"email",
")",
")",
"{",
"return",
"false",
"!==",
"filter_var",
"(",
"trim",
"(",
"$",
"email",
")",
",",
"\\",
"FILTER_VALIDATE_EMAIL",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns if a email is valid or not
@param string email
@return boolean | [
"Returns",
"if",
"a",
"email",
"is",
"valid",
"or",
"not"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L473-L480 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.emailsToString | private function emailsToString($emails) {
$format = [];
foreach($emails as $email) {
if(true === isset($email -> name) && trim($email -> name) !== '') {
$format[] = sprintf('"%s" <%s>', $email -> name, filter_var($email -> email, FILTER_SANITIZE_EMAIL));
}
else {
$format[] = filter_var($email -> email, FILTER_SANITIZE_EMAIL);
}
}
$emails = implode($format, ',');
return ('' !== trim($emails)) ? $emails : null;
} | php | private function emailsToString($emails) {
$format = [];
foreach($emails as $email) {
if(true === isset($email -> name) && trim($email -> name) !== '') {
$format[] = sprintf('"%s" <%s>', $email -> name, filter_var($email -> email, FILTER_SANITIZE_EMAIL));
}
else {
$format[] = filter_var($email -> email, FILTER_SANITIZE_EMAIL);
}
}
$emails = implode($format, ',');
return ('' !== trim($emails)) ? $emails : null;
} | [
"private",
"function",
"emailsToString",
"(",
"$",
"emails",
")",
"{",
"$",
"format",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"emails",
"as",
"$",
"email",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"email",
"->",
"name",
")",
"&&",
"trim",
"(",
"$",
"email",
"->",
"name",
")",
"!==",
"''",
")",
"{",
"$",
"format",
"[",
"]",
"=",
"sprintf",
"(",
"'\"%s\" <%s>'",
",",
"$",
"email",
"->",
"name",
",",
"filter_var",
"(",
"$",
"email",
"->",
"email",
",",
"FILTER_SANITIZE_EMAIL",
")",
")",
";",
"}",
"else",
"{",
"$",
"format",
"[",
"]",
"=",
"filter_var",
"(",
"$",
"email",
"->",
"email",
",",
"FILTER_SANITIZE_EMAIL",
")",
";",
"}",
"}",
"$",
"emails",
"=",
"implode",
"(",
"$",
"format",
",",
"','",
")",
";",
"return",
"(",
"''",
"!==",
"trim",
"(",
"$",
"emails",
")",
")",
"?",
"$",
"emails",
":",
"null",
";",
"}"
] | Formats an array with emails to string
@param array $emails
@return null|string | [
"Formats",
"an",
"array",
"with",
"emails",
"to",
"string"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L488-L505 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.formatTo | private function formatTo() {
$to = null;
if(true === isset($this -> headers['to'])) {
$to = $this -> emailsToString($this -> headers['to']);
}
return $to;
} | php | private function formatTo() {
$to = null;
if(true === isset($this -> headers['to'])) {
$to = $this -> emailsToString($this -> headers['to']);
}
return $to;
} | [
"private",
"function",
"formatTo",
"(",
")",
"{",
"$",
"to",
"=",
"null",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'to'",
"]",
")",
")",
"{",
"$",
"to",
"=",
"$",
"this",
"->",
"emailsToString",
"(",
"$",
"this",
"->",
"headers",
"[",
"'to'",
"]",
")",
";",
"}",
"return",
"$",
"to",
";",
"}"
] | Formats the "to" email and returns it
@return string | [
"Formats",
"the",
"to",
"email",
"and",
"returns",
"it"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L512-L521 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.formatHeaders | private function formatHeaders() {
$headers = [];
$files = true === isset($this -> headers['files']) ? $this -> headers['files'] : [];
//Prepair emailaddresses
foreach(['BCC', 'CC', 'Reply-To', 'From'] as $type) {
if(true === isset($this -> headers[strtolower($type)])) {
$headers[] = sprintf("%s: %s\r\n", $type, $this -> emailsToString($this -> headers[strtolower($type)]));
}
}
//Notify
if($notify = $this -> formatNotify()) {
$headers[] = sprintf("Disposition-Notification-To: %s\r\n", $notify);
$headers[] = sprintf("X-Confirm-Reading-To: %s\r\n", $notify);
}
//Priority
if(true === isset($this -> headers['priority'])) {
$headers[] = sprintf("X-Priority: %s\r\n", $this -> headers['priority'][0]);
$headers[] = sprintf("X-MSMail-Priority: %s\r\n", $this -> headers['priority'][1]);
$headers[] = sprintf("Importance: %s\r\n", $this -> headers['priority'][2]);
}
//Custom headers
if(true === isset($this -> headers['custom'])) {
foreach($this -> headers['custom'] as $key => $value) {
$headers[] = sprintf("%s: %s\r\n", $key, $value);
}
}
//Files
if(count($files) > 0) {
$headers[] = sprintf("Content-Type: multipart/mixed; boundary=\"Boundary-mixed-%s\"\r\n", $this -> getBoundary());
}
else {
$headers[] = sprintf("Content-Type: multipart/alternative; boundary=\"Boundary-alt-%s\"\r\n\r\n", $this -> getBoundary());
}
return implode('', $headers);
} | php | private function formatHeaders() {
$headers = [];
$files = true === isset($this -> headers['files']) ? $this -> headers['files'] : [];
//Prepair emailaddresses
foreach(['BCC', 'CC', 'Reply-To', 'From'] as $type) {
if(true === isset($this -> headers[strtolower($type)])) {
$headers[] = sprintf("%s: %s\r\n", $type, $this -> emailsToString($this -> headers[strtolower($type)]));
}
}
//Notify
if($notify = $this -> formatNotify()) {
$headers[] = sprintf("Disposition-Notification-To: %s\r\n", $notify);
$headers[] = sprintf("X-Confirm-Reading-To: %s\r\n", $notify);
}
//Priority
if(true === isset($this -> headers['priority'])) {
$headers[] = sprintf("X-Priority: %s\r\n", $this -> headers['priority'][0]);
$headers[] = sprintf("X-MSMail-Priority: %s\r\n", $this -> headers['priority'][1]);
$headers[] = sprintf("Importance: %s\r\n", $this -> headers['priority'][2]);
}
//Custom headers
if(true === isset($this -> headers['custom'])) {
foreach($this -> headers['custom'] as $key => $value) {
$headers[] = sprintf("%s: %s\r\n", $key, $value);
}
}
//Files
if(count($files) > 0) {
$headers[] = sprintf("Content-Type: multipart/mixed; boundary=\"Boundary-mixed-%s\"\r\n", $this -> getBoundary());
}
else {
$headers[] = sprintf("Content-Type: multipart/alternative; boundary=\"Boundary-alt-%s\"\r\n\r\n", $this -> getBoundary());
}
return implode('', $headers);
} | [
"private",
"function",
"formatHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"files",
"=",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
":",
"[",
"]",
";",
"//Prepair emailaddresses\r",
"foreach",
"(",
"[",
"'BCC'",
",",
"'CC'",
",",
"'Reply-To'",
",",
"'From'",
"]",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"$",
"type",
")",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s: %s\\r\\n\"",
",",
"$",
"type",
",",
"$",
"this",
"->",
"emailsToString",
"(",
"$",
"this",
"->",
"headers",
"[",
"strtolower",
"(",
"$",
"type",
")",
"]",
")",
")",
";",
"}",
"}",
"//Notify\r",
"if",
"(",
"$",
"notify",
"=",
"$",
"this",
"->",
"formatNotify",
"(",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"Disposition-Notification-To: %s\\r\\n\"",
",",
"$",
"notify",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"X-Confirm-Reading-To: %s\\r\\n\"",
",",
"$",
"notify",
")",
";",
"}",
"//Priority\r",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'priority'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"X-Priority: %s\\r\\n\"",
",",
"$",
"this",
"->",
"headers",
"[",
"'priority'",
"]",
"[",
"0",
"]",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"X-MSMail-Priority: %s\\r\\n\"",
",",
"$",
"this",
"->",
"headers",
"[",
"'priority'",
"]",
"[",
"1",
"]",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"Importance: %s\\r\\n\"",
",",
"$",
"this",
"->",
"headers",
"[",
"'priority'",
"]",
"[",
"2",
"]",
")",
";",
"}",
"//Custom headers\r",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"[",
"'custom'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s: %s\\r\\n\"",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"//Files\r",
"if",
"(",
"count",
"(",
"$",
"files",
")",
">",
"0",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"Content-Type: multipart/mixed; boundary=\\\"Boundary-mixed-%s\\\"\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"\"Content-Type: multipart/alternative; boundary=\\\"Boundary-alt-%s\\\"\\r\\n\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"headers",
")",
";",
"}"
] | Formats the headers and returns it as a string
@return string | [
"Formats",
"the",
"headers",
"and",
"returns",
"it",
"as",
"a",
"string"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L528-L573 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.formatMessage | private function formatMessage() {
$message = [];
$files = true === isset($this -> headers['files']) ? $this -> headers['files'] : [];
if(count($files) > 0) {
$message[] = sprintf("--Boundary-mixed-%s\r\n", $this -> getBoundary());
$message[] = sprintf("Content-Type: multipart/alternative; boundary=\"Boundary-alt-%s\"\r\n\r\n", $this -> getBoundary());
}
if(true === isset($this -> message['text'])) {
$message[] = sprintf("--Boundary-alt-%s\r\n", $this -> getBoundary());
$message[] = "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message[] = "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message[] = sprintf("%s\r\n\r\n", $this -> message['text']);
}
if(true === isset($this -> message['html'])) {
$message[] = sprintf("--Boundary-alt-%s\r\n", $this -> getBoundary());
$message[] = "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message[] = "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message[] = sprintf("%s\r\n\r\n", $this -> message['html']);
}
$message[] = sprintf("--Boundary-alt-%s--\r\n\r\n", $this -> getBoundary());
if(count($files) > 0) {
foreach($files as $attachment) {
$stream = fopen($attachment -> file -> entity() -> getBasepath(), 'rb');
$data = fread($stream, $attachment -> file -> getFilesize());
$data = chunk_split(base64_encode($data));
$message[] = sprintf("--Boundary-mixed-%s\r\n", $this -> getBoundary());
$message[] = sprintf("Content-Type: %s; name=\"%s\"\r\n", $attachment -> mime, $attachment -> name);
$message[] = "Content-Transfer-Encoding: base64\r\n";
$message[] = "Content-Disposition: attachment \r\n\r\n";
$message[] = sprintf("%s\r\n", $data);
}
$message[] = sprintf("--Boundary-mixed-%s--\r\n", $this -> getBoundary());
}
return implode('', $message);
} | php | private function formatMessage() {
$message = [];
$files = true === isset($this -> headers['files']) ? $this -> headers['files'] : [];
if(count($files) > 0) {
$message[] = sprintf("--Boundary-mixed-%s\r\n", $this -> getBoundary());
$message[] = sprintf("Content-Type: multipart/alternative; boundary=\"Boundary-alt-%s\"\r\n\r\n", $this -> getBoundary());
}
if(true === isset($this -> message['text'])) {
$message[] = sprintf("--Boundary-alt-%s\r\n", $this -> getBoundary());
$message[] = "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message[] = "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message[] = sprintf("%s\r\n\r\n", $this -> message['text']);
}
if(true === isset($this -> message['html'])) {
$message[] = sprintf("--Boundary-alt-%s\r\n", $this -> getBoundary());
$message[] = "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message[] = "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message[] = sprintf("%s\r\n\r\n", $this -> message['html']);
}
$message[] = sprintf("--Boundary-alt-%s--\r\n\r\n", $this -> getBoundary());
if(count($files) > 0) {
foreach($files as $attachment) {
$stream = fopen($attachment -> file -> entity() -> getBasepath(), 'rb');
$data = fread($stream, $attachment -> file -> getFilesize());
$data = chunk_split(base64_encode($data));
$message[] = sprintf("--Boundary-mixed-%s\r\n", $this -> getBoundary());
$message[] = sprintf("Content-Type: %s; name=\"%s\"\r\n", $attachment -> mime, $attachment -> name);
$message[] = "Content-Transfer-Encoding: base64\r\n";
$message[] = "Content-Disposition: attachment \r\n\r\n";
$message[] = sprintf("%s\r\n", $data);
}
$message[] = sprintf("--Boundary-mixed-%s--\r\n", $this -> getBoundary());
}
return implode('', $message);
} | [
"private",
"function",
"formatMessage",
"(",
")",
"{",
"$",
"message",
"=",
"[",
"]",
";",
"$",
"files",
"=",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"'files'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"files",
")",
">",
"0",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-mixed-%s\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"Content-Type: multipart/alternative; boundary=\\\"Boundary-alt-%s\\\"\\r\\n\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"message",
"[",
"'text'",
"]",
")",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-alt-%s\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Type: text/plain; charset=\\\"iso-8859-1\\\"\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Transfer-Encoding: 7bit\\r\\n\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s\\r\\n\\r\\n\"",
",",
"$",
"this",
"->",
"message",
"[",
"'text'",
"]",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"message",
"[",
"'html'",
"]",
")",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-alt-%s\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Type: text/html; charset=\\\"iso-8859-1\\\"\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Transfer-Encoding: 7bit\\r\\n\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s\\r\\n\\r\\n\"",
",",
"$",
"this",
"->",
"message",
"[",
"'html'",
"]",
")",
";",
"}",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-alt-%s--\\r\\n\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"files",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"attachment",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"attachment",
"->",
"file",
"->",
"entity",
"(",
")",
"->",
"getBasepath",
"(",
")",
",",
"'rb'",
")",
";",
"$",
"data",
"=",
"fread",
"(",
"$",
"stream",
",",
"$",
"attachment",
"->",
"file",
"->",
"getFilesize",
"(",
")",
")",
";",
"$",
"data",
"=",
"chunk_split",
"(",
"base64_encode",
"(",
"$",
"data",
")",
")",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-mixed-%s\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"Content-Type: %s; name=\\\"%s\\\"\\r\\n\"",
",",
"$",
"attachment",
"->",
"mime",
",",
"$",
"attachment",
"->",
"name",
")",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Transfer-Encoding: base64\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"\"Content-Disposition: attachment \\r\\n\\r\\n\"",
";",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s\\r\\n\"",
",",
"$",
"data",
")",
";",
"}",
"$",
"message",
"[",
"]",
"=",
"sprintf",
"(",
"\"--Boundary-mixed-%s--\\r\\n\"",
",",
"$",
"this",
"->",
"getBoundary",
"(",
")",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"message",
")",
";",
"}"
] | Formats the messages and returns it as a string
@return string | [
"Formats",
"the",
"messages",
"and",
"returns",
"it",
"as",
"a",
"string"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L580-L628 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.formatNotify | private function formatNotify() {
$notify = null;
if(true === isset($this -> headers['notify'])) {
$notify = $this -> emailsToString($this -> headers['notify']);
if(null === $notify) {
if(true === isset($this -> headers['from'])) {
$notify = $this -> emailsToString($this -> headers['from']);
}
else {
$notify = ini_get('sendmail_from');
}
}
}
return $notify;
} | php | private function formatNotify() {
$notify = null;
if(true === isset($this -> headers['notify'])) {
$notify = $this -> emailsToString($this -> headers['notify']);
if(null === $notify) {
if(true === isset($this -> headers['from'])) {
$notify = $this -> emailsToString($this -> headers['from']);
}
else {
$notify = ini_get('sendmail_from');
}
}
}
return $notify;
} | [
"private",
"function",
"formatNotify",
"(",
")",
"{",
"$",
"notify",
"=",
"null",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'notify'",
"]",
")",
")",
"{",
"$",
"notify",
"=",
"$",
"this",
"->",
"emailsToString",
"(",
"$",
"this",
"->",
"headers",
"[",
"'notify'",
"]",
")",
";",
"if",
"(",
"null",
"===",
"$",
"notify",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'from'",
"]",
")",
")",
"{",
"$",
"notify",
"=",
"$",
"this",
"->",
"emailsToString",
"(",
"$",
"this",
"->",
"headers",
"[",
"'from'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"notify",
"=",
"ini_get",
"(",
"'sendmail_from'",
")",
";",
"}",
"}",
"}",
"return",
"$",
"notify",
";",
"}"
] | Formats the notify email and returns it
@return null|string | [
"Formats",
"the",
"notify",
"email",
"and",
"returns",
"it"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L635-L655 |
Kris-Kuiper/sFire-Framework | src/Mail/Mail.php | Mail.getBoundary | private function getBoundary() {
if(null === $this -> boundary) {
$this -> boundary = md5(date('r', time()));
}
return $this -> boundary;
} | php | private function getBoundary() {
if(null === $this -> boundary) {
$this -> boundary = md5(date('r', time()));
}
return $this -> boundary;
} | [
"private",
"function",
"getBoundary",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"boundary",
")",
"{",
"$",
"this",
"->",
"boundary",
"=",
"md5",
"(",
"date",
"(",
"'r'",
",",
"time",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"boundary",
";",
"}"
] | Generates if needed and returns the boundary
@return string | [
"Generates",
"if",
"needed",
"and",
"returns",
"the",
"boundary"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Mail/Mail.php#L662-L669 |
jstewmc/path | src/Path.php | Path.appendSegment | public function appendSegment($segment)
{
if (is_string($segment)) {
$this->segments[] = $segment;
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $this;
} | php | public function appendSegment($segment)
{
if (is_string($segment)) {
$this->segments[] = $segment;
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $this;
} | [
"public",
"function",
"appendSegment",
"(",
"$",
"segment",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"[",
"]",
"=",
"$",
"segment",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, segment, to be a string\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Appends $segment to the end of the path
@param string $segment the segment to append
@return self
@throws InvalidArgumentException if $segment is not a string
@since 0.1.0 | [
"Appends",
"$segment",
"to",
"the",
"end",
"of",
"the",
"path"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L118-L129 |
jstewmc/path | src/Path.php | Path.format | public function format()
{
$string = '';
if ( ! empty($this->segments)) {
$string = implode($this->separator, $this->segments);
}
return $string;
} | php | public function format()
{
$string = '';
if ( ! empty($this->segments)) {
$string = implode($this->separator, $this->segments);
}
return $string;
} | [
"public",
"function",
"format",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"$",
"string",
"=",
"implode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"this",
"->",
"segments",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Returns the path as a string
@return string
@since 0.1.0 | [
"Returns",
"the",
"path",
"as",
"a",
"string"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L137-L146 |
jstewmc/path | src/Path.php | Path.getIndex | public function getIndex($segment)
{
$index = false;
if (is_string($segment)) {
$index = array_search($segment, $this->segments);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $index;
} | php | public function getIndex($segment)
{
$index = false;
if (is_string($segment)) {
$index = array_search($segment, $this->segments);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $index;
} | [
"public",
"function",
"getIndex",
"(",
"$",
"segment",
")",
"{",
"$",
"index",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"segment",
",",
"$",
"this",
"->",
"segments",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, segment, to be a string\"",
")",
";",
"}",
"return",
"$",
"index",
";",
"}"
] | Returns the 0-based index of $segment
WARNING! This method may return false ($segment does not exist in the
path) or 0 ($segment exists in the first position). Be sure to use the
strict comparison operator === when testing this method's return values.
For example:
$path = new Path('foo/bar/baz');
$path->getIndex('foo'); // returns 0
$path->getIndex('bar'); // returns 1
$path->getIndex('qux'); // returns false
@param string $segment the segment to find (case-sensitive)
@return int|bool the integer index or false if the segment does not exist
@throws InvalidArgumentException if $segment is not a string
@since 0.1.0 | [
"Returns",
"the",
"0",
"-",
"based",
"index",
"of",
"$segment"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L167-L180 |
jstewmc/path | src/Path.php | Path.getSegment | public function getSegment($offset)
{
$segment = false;
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
$segment = $this->segments[$index];
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to result in "
. " a valid index; $index is not a valid index"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
$segment = reset($this->segments);
break;
case 'last':
$segment = end($this->segments);
break;
case 'rand':
case 'random':
$segment = $this->segments[array_rand($this->segments)];
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be one "
. "of the following: 'first', 'last', or 'rand[om]'; '$offset' is not "
. "supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, index, to be a string or integer"
);
}
return $segment;
} | php | public function getSegment($offset)
{
$segment = false;
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
$segment = $this->segments[$index];
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to result in "
. " a valid index; $index is not a valid index"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
$segment = reset($this->segments);
break;
case 'last':
$segment = end($this->segments);
break;
case 'rand':
case 'random':
$segment = $this->segments[array_rand($this->segments)];
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be one "
. "of the following: 'first', 'last', or 'rand[om]'; '$offset' is not "
. "supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, index, to be a string or integer"
);
}
return $segment;
} | [
"public",
"function",
"getSegment",
"(",
"$",
"offset",
")",
"{",
"$",
"segment",
"=",
"false",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"$",
"segment",
"=",
"$",
"this",
"->",
"segments",
"[",
"$",
"index",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when an integer, to result in \"",
".",
"\" a valid index; $index is not a valid index\"",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"offset",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"offset",
")",
")",
"{",
"case",
"'first'",
":",
"$",
"segment",
"=",
"reset",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"break",
";",
"case",
"'last'",
":",
"$",
"segment",
"=",
"end",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"break",
";",
"case",
"'rand'",
":",
"case",
"'random'",
":",
"$",
"segment",
"=",
"$",
"this",
"->",
"segments",
"[",
"array_rand",
"(",
"$",
"this",
"->",
"segments",
")",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when a string, to be one \"",
".",
"\"of the following: 'first', 'last', or 'rand[om]'; '$offset' is not \"",
".",
"\"supported\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, index, to be a string or integer\"",
")",
";",
"}",
"return",
"$",
"segment",
";",
"}"
] | Returns the segment at $offset
For example:
$path = new Path('foo/bar/baz');
$path->getSegment(0); // returns 'foo' (zero segments from beginning)
$path->getSegment(-3); // returns 'foo' (third segment from end)
$path->getSegment('first'); // returns 'foo'
@param int|string $offset if offset is non-negative, the segment that many
places from the beginning of the path will be returned; if offset is negative,
the segment that many places from the end of the path will be returned; if
offset is a non-integer string, it must be one of the following strings:
'first', for the first segment; 'last', for the last segment; or, 'rand[om]',
for a random segment (case-insensitive)
@return string
@throws InvalidArgumentException if $offset is not a string or integer
@throws InvalidArgumentException if $offset is an unsupported string
@throws OutOfBoundsException if $offset results in an invalid index
@since 0.1.0 | [
"Returns",
"the",
"segment",
"at",
"$offset"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L214-L258 |
jstewmc/path | src/Path.php | Path.getSlice | public function getSlice($offset, $length = null)
{
$slice = false;
if (is_numeric($offset) && is_int(+$offset)) {
if ($length === null || (is_numeric($length) && is_int(+$length))) {
$slice = (new Path())
->setSegments(array_slice($this->segments, $offset, $length))
->setSeparator($this->separator);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, length, to be null or an integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $slice;
} | php | public function getSlice($offset, $length = null)
{
$slice = false;
if (is_numeric($offset) && is_int(+$offset)) {
if ($length === null || (is_numeric($length) && is_int(+$length))) {
$slice = (new Path())
->setSegments(array_slice($this->segments, $offset, $length))
->setSeparator($this->separator);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, length, to be null or an integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $slice;
} | [
"public",
"function",
"getSlice",
"(",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
"{",
"$",
"slice",
"=",
"false",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"null",
"||",
"(",
"is_numeric",
"(",
"$",
"length",
")",
"&&",
"is_int",
"(",
"+",
"$",
"length",
")",
")",
")",
"{",
"$",
"slice",
"=",
"(",
"new",
"Path",
"(",
")",
")",
"->",
"setSegments",
"(",
"array_slice",
"(",
"$",
"this",
"->",
"segments",
",",
"$",
"offset",
",",
"$",
"length",
")",
")",
"->",
"setSeparator",
"(",
"$",
"this",
"->",
"separator",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter two, length, to be null or an integer\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be an integer\"",
")",
";",
"}",
"return",
"$",
"slice",
";",
"}"
] | Returns a slice of the path starting at $offset for $length segments
I'll return a new Path object (leaving this Path unchanged). To slice this
path, use the slice() method instead.
For example:
$a = new Path('foo/bar/baz');
$b = $a->getSlice(1);
echo $a; // prints 'foo/bar/baz'
echo $b; // prints 'bar/baz'
@param int $offset if offset is non-negative, the slice will start at that
offset from the beginning of the path; if offset is negative, the slice
will start that far from the end of the path
@param int $length if length is given and positive, the slice will have up
to that many segments in it; if the path is shorter than length, then only
the available segments will be present; if length is given and negative,
the slice will stop that many segments from the end of the path; finally,
if length is omitted, the slice will have everything from the offset to the
end of the path
@return Jstewmc\Url\Path the slice
@throws InvalidArgumentException if $offset is not an integer
@throws InvalidArgumentException if $length is not an integer or null
@since 0.1.0 | [
"Returns",
"a",
"slice",
"of",
"the",
"path",
"starting",
"at",
"$offset",
"for",
"$length",
"segments"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L288-L309 |
jstewmc/path | src/Path.php | Path.hasIndex | public function hasIndex($offset)
{
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
return true;
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return false;
} | php | public function hasIndex($offset)
{
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
return true;
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return false;
} | [
"public",
"function",
"hasIndex",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be an integer\"",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the path has any segment at $index
For example:
$path = new Path('foo/bar/baz');
$path->hasIndex(0); // returns true
$path->hasIndex(3); // returns false
@param int $offset if offset is non-negative, the search will occur that
many places from the beginning of the path; if offset is negative, the search
will occur that many places from the end of the path
@return bool
@throws InvalidArgumentException if $offset is not an integer
@since 0.1.0 | [
"Returns",
"true",
"if",
"the",
"path",
"has",
"any",
"segment",
"at",
"$index"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L351-L365 |
jstewmc/path | src/Path.php | Path.hasSegment | public function hasSegment($segment, $offset = null)
{
if (is_string($segment)) {
if ($offset === null ) {
foreach ($this->segments as $key => $value) {
if ($value == $segment) {
return true;
}
}
} elseif (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
if ($this->segments[$index] == $segment) {
return true;
}
}
} elseif ($offset === 'first') {
if (reset($this->segments) === $segment) {
return true;
}
} elseif ($offset === 'last') {
if (end($this->segments) === $segment) {
return true;
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, offset, to be an integer, the string "
. "'first' or 'last', or null"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return false;
} | php | public function hasSegment($segment, $offset = null)
{
if (is_string($segment)) {
if ($offset === null ) {
foreach ($this->segments as $key => $value) {
if ($value == $segment) {
return true;
}
}
} elseif (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
if ($this->segments[$index] == $segment) {
return true;
}
}
} elseif ($offset === 'first') {
if (reset($this->segments) === $segment) {
return true;
}
} elseif ($offset === 'last') {
if (end($this->segments) === $segment) {
return true;
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, offset, to be an integer, the string "
. "'first' or 'last', or null"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return false;
} | [
"public",
"function",
"hasSegment",
"(",
"$",
"segment",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"segment",
")",
")",
"{",
"if",
"(",
"$",
"offset",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"segments",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"$",
"segment",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"segments",
"[",
"$",
"index",
"]",
"==",
"$",
"segment",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"offset",
"===",
"'first'",
")",
"{",
"if",
"(",
"reset",
"(",
"$",
"this",
"->",
"segments",
")",
"===",
"$",
"segment",
")",
"{",
"return",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"offset",
"===",
"'last'",
")",
"{",
"if",
"(",
"end",
"(",
"$",
"this",
"->",
"segments",
")",
"===",
"$",
"segment",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter two, offset, to be an integer, the string \"",
".",
"\"'first' or 'last', or null\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, segment, to be a string\"",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the path has $segment (optionally, at $offset)
For example:
$path = new Path('foo/bar/baz');
$path->hasSegment('foo'); // returns true
$path->hasSegment('foo', 0); // returns true
$path->hasSegment('foo', 'first'); // returns true
$path->hasSegment('qux'); // returns false
$path->hasSegment('foo', 1); // returns false
@param string $segment the segment to search for
@param null|int|string $offset if offset is non-negative, the search will
occur that many places from the beginning of the path; if offset is negative,
the search will occur that far from the end of the path; if string, must be
'first' or 'last' (optional; if omitted, defaults to null and the segment's
position doesn't matter)
@return bool
@throws InvalidArgumentException if $segment is not a string
@throws InvalidArgumentException if $offset is not an integer, not the strings
'first' or 'last', and not null
@since 0.1.0 | [
"Returns",
"true",
"if",
"the",
"path",
"has",
"$segment",
"(",
"optionally",
"at",
"$offset",
")"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L391-L428 |
jstewmc/path | src/Path.php | Path.insertSegment | public function insertSegment($offset, $segment)
{
if (is_numeric($offset) && is_int(+$offset)) {
if (is_string($segment)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
array_splice($this->segments, $offset, 0, $segment);
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, to correspond to a valid "
. "index; $index is not a valid index"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, segment, to be a string"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $this;
} | php | public function insertSegment($offset, $segment)
{
if (is_numeric($offset) && is_int(+$offset)) {
if (is_string($segment)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
array_splice($this->segments, $offset, 0, $segment);
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, to correspond to a valid "
. "index; $index is not a valid index"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, segment, to be a string"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $this;
} | [
"public",
"function",
"insertSegment",
"(",
"$",
"offset",
",",
"$",
"segment",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"segments",
",",
"$",
"offset",
",",
"0",
",",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to correspond to a valid \"",
".",
"\"index; $index is not a valid index\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter two, segment, to be a string\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be an integer\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Inserts $segment at $offset
For example:
$path = new Path('foo/bar/baz');
$path->insertSegment('qux', 1);
echo $path; // prints "foo/qux/bar/baz"
@param int $offset if offset is non-negative, the insert starts at that
position from the beginning of the path; if offset is negative, the insert
starts that far from the end of the array
@param string $segment the segment to insert
@return self
@throws InvalidArgumentException if $offset is not an integer
@throws InvalidArgumentException if $segment is not a string
@throws OutOfBoundsException if $offset corresponds to invalid index
@since 0.1.0 | [
"Inserts",
"$segment",
"at",
"$offset"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L450-L475 |
jstewmc/path | src/Path.php | Path.parse | public function parse($path)
{
if (is_string($path)) {
if (substr($path, 0, 1) === $this->separator) {
$path = substr($path, 1);
}
$this->segments = explode($this->separator, $path);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, path, to be a string"
);
}
return;
} | php | public function parse($path)
{
if (is_string($path)) {
if (substr($path, 0, 1) === $this->separator) {
$path = substr($path, 1);
}
$this->segments = explode($this->separator, $path);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, path, to be a string"
);
}
return;
} | [
"public",
"function",
"parse",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"===",
"$",
"this",
"->",
"separator",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"1",
")",
";",
"}",
"$",
"this",
"->",
"segments",
"=",
"explode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, path, to be a string\"",
")",
";",
"}",
"return",
";",
"}"
] | Parses the string path into this Path object
Keep in mind, if $path does not use the default separator, you should set the
path's separator first, before calling parse().
@param string $path the path to parse (with or without leading separator)
@return self
@throws InvalidArgumentException if $path is not a string
@since 0.1.0 | [
"Parses",
"the",
"string",
"path",
"into",
"this",
"Path",
"object"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L488-L502 |
jstewmc/path | src/Path.php | Path.prependSegment | public function prependSegment($segment)
{
if (is_string($segment)) {
array_unshift($this->segments, $segment);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $this;
} | php | public function prependSegment($segment)
{
if (is_string($segment)) {
array_unshift($this->segments, $segment);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, segment, to be a string"
);
}
return $this;
} | [
"public",
"function",
"prependSegment",
"(",
"$",
"segment",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"segment",
")",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"segments",
",",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, segment, to be a string\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Prepends $segment to the path
For example:
$path = new Path('foo/bar/baz');
$path->prependSegment('qux');
echo $path; // prints "qux/foo/bar/baz"
@param string $segment the segment to prepend to the beginning of the path
@return self
@throws InvalidArgumentException if $segment is not a string
@since 0.1.0 | [
"Prepends",
"$segment",
"to",
"the",
"path"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L519-L530 |
jstewmc/path | src/Path.php | Path.setSegment | public function setSegment($offset, $value)
{
if (is_string($value)) {
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
$this->segments[$index] = $value;
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to correspond "
. "to a valid index; $index is not a valid index"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
$this->segments[0] = $value;
break;
case 'last':
$this->segments[count($this->segments) - 1] = $value;
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be "
. "'first' or 'last'; '$offset' is not supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be a string or integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, value, to be a string"
);
}
return $this;
} | php | public function setSegment($offset, $value)
{
if (is_string($value)) {
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
$this->segments[$index] = $value;
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to correspond "
. "to a valid index; $index is not a valid index"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
$this->segments[0] = $value;
break;
case 'last':
$this->segments[count($this->segments) - 1] = $value;
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be "
. "'first' or 'last'; '$offset' is not supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be a string or integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, value, to be a string"
);
}
return $this;
} | [
"public",
"function",
"setSegment",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when an integer, to correspond \"",
".",
"\"to a valid index; $index is not a valid index\"",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"offset",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"offset",
")",
")",
"{",
"case",
"'first'",
":",
"$",
"this",
"->",
"segments",
"[",
"0",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'last'",
":",
"$",
"this",
"->",
"segments",
"[",
"count",
"(",
"$",
"this",
"->",
"segments",
")",
"-",
"1",
"]",
"=",
"$",
"value",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when a string, to be \"",
".",
"\"'first' or 'last'; '$offset' is not supported\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be a string or integer\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter two, value, to be a string\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets segment at $offset to $value
For example:
$path = new Path('foo/bar/baz');
$path->setSegment(0, 'qux'); // path is "qux/bar/baz"
$path->setSegment('last', 'quux'); // path is "qux/bar/quux"
$path->setSegment(-2, 'corge'); // path is "qux/corge/quux"
echo $path; // prints "qux/corge/quux"
@param int|string $offset if offset is non-negative, the segment that many
places from the beginning of the path will be updated; if offset is negative,
the segment that many places from the end of the path will be updated; if
offset is a string, it must be "first", the first segment, or "last", the
last segment (case-insensitive)
@param string $value the segment's new value
@return self
@throws InvalidArgumentException if $value is not a string
@throws InvalidArgumentException if $offset is not an integer or string
@throws InvalidArgumentException if $offset is an unsupported string
@throws OutOfBoundsException if $offset results in an invalid index
@since 0.1.0 | [
"Sets",
"segment",
"at",
"$offset",
"to",
"$value"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L578-L620 |
jstewmc/path | src/Path.php | Path.slice | public function slice($offset, $length = null)
{
if (is_numeric($offset) && is_int(+$offset)) {
if ($length === null || (is_numeric($length) && is_int(+$length))) {
$this->segments = array_slice($this->segments, $offset, $length);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, length, to be null or an integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $this;
} | php | public function slice($offset, $length = null)
{
if (is_numeric($offset) && is_int(+$offset)) {
if ($length === null || (is_numeric($length) && is_int(+$length))) {
$this->segments = array_slice($this->segments, $offset, $length);
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter two, length, to be null or an integer"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $this;
} | [
"public",
"function",
"slice",
"(",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"null",
"||",
"(",
"is_numeric",
"(",
"$",
"length",
")",
"&&",
"is_int",
"(",
"+",
"$",
"length",
")",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"segments",
",",
"$",
"offset",
",",
"$",
"length",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter two, length, to be null or an integer\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be an integer\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Slices the path
Keep in mind, I will change this path. To keep this path the same and return a
new, sliced Path, use the getSlice() method instead.
For example:
$path = new Path('foo/bar/baz');
$path->slice(1);
echo $path; // prints "bar/baz"
@param int $offset if offset is non-negative, the slice will start at that
offset from the beginning of the path; if offset is negative, the slice
will start that far from the end of the path
@param int $length if length is given and positive, the slice will have up
to that many segments in it; if the path is shorter than length, then only
the available segments will be present; if length is given and negative,
the slice will stop that many segments from the end of the path; finally,
if length is omitted, the slice will have everything from the offset to the
end of the path (optional; if omitted, defaults to null)
@return self
@throws InvalidArgumentException if $offset is not an integer
@throws InvalidArgumentException if $length is not null or an integer
@since 0.1.0 | [
"Slices",
"the",
"path"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L649-L666 |
jstewmc/path | src/Path.php | Path.unsetSegment | public function unsetSegment($offset)
{
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
unset($this->segments[$index]);
$this->segments = array_values($this->segments);
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to correspond"
. " with a valid index; $index is not valid"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
array_shift($this->segments);
break;
case 'last':
array_pop($this->segments);
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be 'first' "
. " or 'last'; '$offset' is not supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be a string or integer"
);
}
return $this;
} | php | public function unsetSegment($offset)
{
if (is_numeric($offset) && is_int(+$offset)) {
$index = $this->getIndexFromOffset($offset);
if ($index >= 0 && array_key_exists($index, $this->segments)) {
unset($this->segments[$index]);
$this->segments = array_values($this->segments);
} else {
throw new \OutOfBoundsException(
__METHOD__."() expects parameter one, offset, when an integer, to correspond"
. " with a valid index; $index is not valid"
);
}
} elseif (is_string($offset)) {
switch (strtolower($offset)) {
case 'first':
array_shift($this->segments);
break;
case 'last':
array_pop($this->segments);
break;
default:
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, when a string, to be 'first' "
. " or 'last'; '$offset' is not supported"
);
}
} else {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be a string or integer"
);
}
return $this;
} | [
"public",
"function",
"unsetSegment",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"index",
">=",
"0",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"segments",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"segments",
"[",
"$",
"index",
"]",
")",
";",
"$",
"this",
"->",
"segments",
"=",
"array_values",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when an integer, to correspond\"",
".",
"\" with a valid index; $index is not valid\"",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"offset",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"offset",
")",
")",
"{",
"case",
"'first'",
":",
"array_shift",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"break",
";",
"case",
"'last'",
":",
"array_pop",
"(",
"$",
"this",
"->",
"segments",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, when a string, to be 'first' \"",
".",
"\" or 'last'; '$offset' is not supported\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be a string or integer\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Unsets the segment at $offset
Keep in mind, keys will be reset after this method call.
For example:
$path = new Path('foo/bar/baz');
$path->unsetSegment(0); // path is "bar/baz"
$path->unsetSegment('first'); // path is "baz"
$path->unsetSegment('last'); // path is ""
@param int|string $offset if offset is non-negative, the segment that many
place from the beginning of the path will be removed; if offset is negative,
the segment that many places from the end of the path will be removed; if
the offset is a non-integer string, it must be 'first', the first segment or
'last', the last segment (case-insensitive)
@return self
@throws InvalidArgumentException if $offset is not an integer or string
@throws InvalidArgumentException if $offset is an unsupported string
@throws OutOfBoundsException if $offset results in an invalid index
@since 0.1.0 | [
"Unsets",
"the",
"segment",
"at",
"$offset"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L691-L728 |
jstewmc/path | src/Path.php | Path.getIndexFromOffset | protected function getIndexFromOffset($offset)
{
if ( ! is_numeric($offset) && is_int(+$offset)) {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $offset < 0 ? count($this->segments) + $offset : $offset;
} | php | protected function getIndexFromOffset($offset)
{
if ( ! is_numeric($offset) && is_int(+$offset)) {
throw new \InvalidArgumentException(
__METHOD__."() expects parameter one, offset, to be an integer"
);
}
return $offset < 0 ? count($this->segments) + $offset : $offset;
} | [
"protected",
"function",
"getIndexFromOffset",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"is_int",
"(",
"+",
"$",
"offset",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter one, offset, to be an integer\"",
")",
";",
"}",
"return",
"$",
"offset",
"<",
"0",
"?",
"count",
"(",
"$",
"this",
"->",
"segments",
")",
"+",
"$",
"offset",
":",
"$",
"offset",
";",
"}"
] | Returns an index in $segments based on $offset
@param int $offset the array's offset
@return int the array's index
@throws InvalidArgumentException if $offset is not a string
@since 0.1.0 | [
"Returns",
"an",
"index",
"in",
"$segments",
"based",
"on",
"$offset"
] | train | https://github.com/jstewmc/path/blob/d9813721cc10407710113865bd8baae7419b2f84/src/Path.php#L741-L750 |
alkemann/h.l | src/debug/util/Debug.php | Debug.dump | public function dump($var, $options = array()) {
$options += self::$defaults + array('split' => false, 'trace' => false);
$this->options = $options;
$this->current_depth = 0;
$this->object_references = array();
if (!$options['trace']) $options['trace'] = debug_backtrace();
extract($options);
$location = $this->location($trace);
$dump = array();
if ($options['split'] && is_array($var)) {
$this->current_depth = 0;
foreach ($var as $one) {
$dump = array_merge($dump, array($this->dump_it($one), ' - '));
}
$dump = array_slice($dump, 0, -1);
} else
$dump[] = $this->dump_it($var);
switch ($mode) {
case 'FirePHP':
$locString = \alkemann\hl\debug\util\adapters\FirePHP::locationString($location);
require_once LITHIUM_LIBRARY_PATH . '/FirePHPCore/FirePHP.class.php';
$firephp = \FirePHP::getInstance(true);
if (!$firephp) throw new \Exception('FirePHP not installed');
$firephp->group($locString, array('Collapsed' => false, 'Color' => '#AA0000'));
$f = function($o) use ($firephp,&$f) {
if (is_array($o)) {
foreach ($o as $r)
$f($r);
} else {
$firephp->log($o);
}
};
$f($dump);
$firephp->groupEnd();
return;
break;
case 'Json':
$locString = \alkemann\hl\debug\util\adapters\Json::locationString($location);
$this->output[] = array('location' => $locString, 'dump' => $dump);
break;
case 'Log' :
$locString = \alkemann\hl\debug\util\adapters\Log::locationString($location);
\lithium\analysis\Logger::debug($locString . "\n" . implode("\n", $dump));
return;
break;
case 'Html' :
default :
$locString = \alkemann\hl\debug\util\adapters\Html::locationString($location);
$this->output[] = '<div class="debug-dump"><div class="debug-location">' . $locString . '</div>'.
'<div class="debug-content"> ' . implode("<br>\n", $dump) . '</div></div>';
break;
}
if ($options['echo']) {
$this->__out();
}
} | php | public function dump($var, $options = array()) {
$options += self::$defaults + array('split' => false, 'trace' => false);
$this->options = $options;
$this->current_depth = 0;
$this->object_references = array();
if (!$options['trace']) $options['trace'] = debug_backtrace();
extract($options);
$location = $this->location($trace);
$dump = array();
if ($options['split'] && is_array($var)) {
$this->current_depth = 0;
foreach ($var as $one) {
$dump = array_merge($dump, array($this->dump_it($one), ' - '));
}
$dump = array_slice($dump, 0, -1);
} else
$dump[] = $this->dump_it($var);
switch ($mode) {
case 'FirePHP':
$locString = \alkemann\hl\debug\util\adapters\FirePHP::locationString($location);
require_once LITHIUM_LIBRARY_PATH . '/FirePHPCore/FirePHP.class.php';
$firephp = \FirePHP::getInstance(true);
if (!$firephp) throw new \Exception('FirePHP not installed');
$firephp->group($locString, array('Collapsed' => false, 'Color' => '#AA0000'));
$f = function($o) use ($firephp,&$f) {
if (is_array($o)) {
foreach ($o as $r)
$f($r);
} else {
$firephp->log($o);
}
};
$f($dump);
$firephp->groupEnd();
return;
break;
case 'Json':
$locString = \alkemann\hl\debug\util\adapters\Json::locationString($location);
$this->output[] = array('location' => $locString, 'dump' => $dump);
break;
case 'Log' :
$locString = \alkemann\hl\debug\util\adapters\Log::locationString($location);
\lithium\analysis\Logger::debug($locString . "\n" . implode("\n", $dump));
return;
break;
case 'Html' :
default :
$locString = \alkemann\hl\debug\util\adapters\Html::locationString($location);
$this->output[] = '<div class="debug-dump"><div class="debug-location">' . $locString . '</div>'.
'<div class="debug-content"> ' . implode("<br>\n", $dump) . '</div></div>';
break;
}
if ($options['echo']) {
$this->__out();
}
} | [
"public",
"function",
"dump",
"(",
"$",
"var",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"+=",
"self",
"::",
"$",
"defaults",
"+",
"array",
"(",
"'split'",
"=>",
"false",
",",
"'trace'",
"=>",
"false",
")",
";",
"$",
"this",
"->",
"options",
"=",
"$",
"options",
";",
"$",
"this",
"->",
"current_depth",
"=",
"0",
";",
"$",
"this",
"->",
"object_references",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"options",
"[",
"'trace'",
"]",
")",
"$",
"options",
"[",
"'trace'",
"]",
"=",
"debug_backtrace",
"(",
")",
";",
"extract",
"(",
"$",
"options",
")",
";",
"$",
"location",
"=",
"$",
"this",
"->",
"location",
"(",
"$",
"trace",
")",
";",
"$",
"dump",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'split'",
"]",
"&&",
"is_array",
"(",
"$",
"var",
")",
")",
"{",
"$",
"this",
"->",
"current_depth",
"=",
"0",
";",
"foreach",
"(",
"$",
"var",
"as",
"$",
"one",
")",
"{",
"$",
"dump",
"=",
"array_merge",
"(",
"$",
"dump",
",",
"array",
"(",
"$",
"this",
"->",
"dump_it",
"(",
"$",
"one",
")",
",",
"' - '",
")",
")",
";",
"}",
"$",
"dump",
"=",
"array_slice",
"(",
"$",
"dump",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"else",
"$",
"dump",
"[",
"]",
"=",
"$",
"this",
"->",
"dump_it",
"(",
"$",
"var",
")",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"'FirePHP'",
":",
"$",
"locString",
"=",
"\\",
"alkemann",
"\\",
"hl",
"\\",
"debug",
"\\",
"util",
"\\",
"adapters",
"\\",
"FirePHP",
"::",
"locationString",
"(",
"$",
"location",
")",
";",
"require_once",
"LITHIUM_LIBRARY_PATH",
".",
"'/FirePHPCore/FirePHP.class.php'",
";",
"$",
"firephp",
"=",
"\\",
"FirePHP",
"::",
"getInstance",
"(",
"true",
")",
";",
"if",
"(",
"!",
"$",
"firephp",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'FirePHP not installed'",
")",
";",
"$",
"firephp",
"->",
"group",
"(",
"$",
"locString",
",",
"array",
"(",
"'Collapsed'",
"=>",
"false",
",",
"'Color'",
"=>",
"'#AA0000'",
")",
")",
";",
"$",
"f",
"=",
"function",
"(",
"$",
"o",
")",
"use",
"(",
"$",
"firephp",
",",
"&",
"$",
"f",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"o",
")",
")",
"{",
"foreach",
"(",
"$",
"o",
"as",
"$",
"r",
")",
"$",
"f",
"(",
"$",
"r",
")",
";",
"}",
"else",
"{",
"$",
"firephp",
"->",
"log",
"(",
"$",
"o",
")",
";",
"}",
"}",
";",
"$",
"f",
"(",
"$",
"dump",
")",
";",
"$",
"firephp",
"->",
"groupEnd",
"(",
")",
";",
"return",
";",
"break",
";",
"case",
"'Json'",
":",
"$",
"locString",
"=",
"\\",
"alkemann",
"\\",
"hl",
"\\",
"debug",
"\\",
"util",
"\\",
"adapters",
"\\",
"Json",
"::",
"locationString",
"(",
"$",
"location",
")",
";",
"$",
"this",
"->",
"output",
"[",
"]",
"=",
"array",
"(",
"'location'",
"=>",
"$",
"locString",
",",
"'dump'",
"=>",
"$",
"dump",
")",
";",
"break",
";",
"case",
"'Log'",
":",
"$",
"locString",
"=",
"\\",
"alkemann",
"\\",
"hl",
"\\",
"debug",
"\\",
"util",
"\\",
"adapters",
"\\",
"Log",
"::",
"locationString",
"(",
"$",
"location",
")",
";",
"\\",
"lithium",
"\\",
"analysis",
"\\",
"Logger",
"::",
"debug",
"(",
"$",
"locString",
".",
"\"\\n\"",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"dump",
")",
")",
";",
"return",
";",
"break",
";",
"case",
"'Html'",
":",
"default",
":",
"$",
"locString",
"=",
"\\",
"alkemann",
"\\",
"hl",
"\\",
"debug",
"\\",
"util",
"\\",
"adapters",
"\\",
"Html",
"::",
"locationString",
"(",
"$",
"location",
")",
";",
"$",
"this",
"->",
"output",
"[",
"]",
"=",
"'<div class=\"debug-dump\"><div class=\"debug-location\">'",
".",
"$",
"locString",
".",
"'</div>'",
".",
"'<div class=\"debug-content\"> '",
".",
"implode",
"(",
"\"<br>\\n\"",
",",
"$",
"dump",
")",
".",
"'</div></div>'",
";",
"break",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'echo'",
"]",
")",
"{",
"$",
"this",
"->",
"__out",
"(",
")",
";",
"}",
"}"
] | Dump
@param mixed $var
@param array $options | [
"Dump"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L48-L107 |
alkemann/h.l | src/debug/util/Debug.php | Debug.array_out | public function array_out($key = null) {
if (count($this->output) < 2 || ($key && !isset($this->output[$key]))) {
return array();
}
if ($key) {
return $this->output[$key];
}
array_shift($this->output);
return $this->output;
} | php | public function array_out($key = null) {
if (count($this->output) < 2 || ($key && !isset($this->output[$key]))) {
return array();
}
if ($key) {
return $this->output[$key];
}
array_shift($this->output);
return $this->output;
} | [
"public",
"function",
"array_out",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"output",
")",
"<",
"2",
"||",
"(",
"$",
"key",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"output",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"output",
"[",
"$",
"key",
"]",
";",
"}",
"array_shift",
"(",
"$",
"this",
"->",
"output",
")",
";",
"return",
"$",
"this",
"->",
"output",
";",
"}"
] | Return output dump as array
@param string $key
@return array | [
"Return",
"output",
"dump",
"as",
"array"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L115-L124 |
alkemann/h.l | src/debug/util/Debug.php | Debug.out | public function out($key = null) {
if ($this->options['mode'] == 'Html') {
\alkemann\hl\debug\util\adapters\Html::top($this->output, $key);
return;
}
$this->__out($key);
} | php | public function out($key = null) {
if ($this->options['mode'] == 'Html') {
\alkemann\hl\debug\util\adapters\Html::top($this->output, $key);
return;
}
$this->__out($key);
} | [
"public",
"function",
"out",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'mode'",
"]",
"==",
"'Html'",
")",
"{",
"\\",
"alkemann",
"\\",
"hl",
"\\",
"debug",
"\\",
"util",
"\\",
"adapters",
"\\",
"Html",
"::",
"top",
"(",
"$",
"this",
"->",
"output",
",",
"$",
"key",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"__out",
"(",
"$",
"key",
")",
";",
"}"
] | Echo out stored debugging
@param int $key | [
"Echo",
"out",
"stored",
"debugging"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L131-L137 |
alkemann/h.l | src/debug/util/Debug.php | Debug.defines | public function defines() {
$defines = get_defined_constants();
$ret = array(); $offset = -1;
while ($def = array_slice($defines, $offset--, 1)) {
$key = key($def);
$value = current($def);
if ($key == 'FIRST_APP_CONSTANT') break;
$ret[$key ] = $value;
}
return $ret;
} | php | public function defines() {
$defines = get_defined_constants();
$ret = array(); $offset = -1;
while ($def = array_slice($defines, $offset--, 1)) {
$key = key($def);
$value = current($def);
if ($key == 'FIRST_APP_CONSTANT') break;
$ret[$key ] = $value;
}
return $ret;
} | [
"public",
"function",
"defines",
"(",
")",
"{",
"$",
"defines",
"=",
"get_defined_constants",
"(",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"offset",
"=",
"-",
"1",
";",
"while",
"(",
"$",
"def",
"=",
"array_slice",
"(",
"$",
"defines",
",",
"$",
"offset",
"--",
",",
"1",
")",
")",
"{",
"$",
"key",
"=",
"key",
"(",
"$",
"def",
")",
";",
"$",
"value",
"=",
"current",
"(",
"$",
"def",
")",
";",
"if",
"(",
"$",
"key",
"==",
"'FIRST_APP_CONSTANT'",
")",
"break",
";",
"$",
"ret",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Grab global defines, will start at 'FIRST_APP_CONSTANT', if defined
@return type | [
"Grab",
"global",
"defines",
"will",
"start",
"at",
"FIRST_APP_CONSTANT",
"if",
"defined"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L158-L168 |
alkemann/h.l | src/debug/util/Debug.php | Debug.dump_it | public function dump_it($var) {
$adapter = '\alkemann\hl\debug\util\adapters\\'. $this->options['mode'];
if (is_array($var))
return $adapter::dump_array($var, $this);
elseif (is_object($var))
return $adapter::dump_object($var, $this);
else
return $adapter::dump_other($var);
} | php | public function dump_it($var) {
$adapter = '\alkemann\hl\debug\util\adapters\\'. $this->options['mode'];
if (is_array($var))
return $adapter::dump_array($var, $this);
elseif (is_object($var))
return $adapter::dump_object($var, $this);
else
return $adapter::dump_other($var);
} | [
"public",
"function",
"dump_it",
"(",
"$",
"var",
")",
"{",
"$",
"adapter",
"=",
"'\\alkemann\\hl\\debug\\util\\adapters\\\\'",
".",
"$",
"this",
"->",
"options",
"[",
"'mode'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"var",
")",
")",
"return",
"$",
"adapter",
"::",
"dump_array",
"(",
"$",
"var",
",",
"$",
"this",
")",
";",
"elseif",
"(",
"is_object",
"(",
"$",
"var",
")",
")",
"return",
"$",
"adapter",
"::",
"dump_object",
"(",
"$",
"var",
",",
"$",
"this",
")",
";",
"else",
"return",
"$",
"adapter",
"::",
"dump_other",
"(",
"$",
"var",
")",
";",
"}"
] | Send a variable to the adapter and return it's formated output
@param mixed $var
@return string | [
"Send",
"a",
"variable",
"to",
"the",
"adapter",
"and",
"return",
"it",
"s",
"formated",
"output"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L176-L184 |
alkemann/h.l | src/debug/util/Debug.php | Debug.location | public function location($trace) {
$root = substr($_SERVER['DOCUMENT_ROOT'], 0 , strlen(static::$defaults['docroot']) * -1);
$file = implode('/', array_diff(explode('/', $trace[0]['file']), explode('/', $root)));
$ret = array(
'file' => $file,
'line' => $trace[0]['line']
);
if (isset($trace[1]['function'])) $ret['function'] = $trace[1]['function'];
if (isset($trace[1]['class'])) $ret['class'] = $trace[1]['class'];
return $ret;
} | php | public function location($trace) {
$root = substr($_SERVER['DOCUMENT_ROOT'], 0 , strlen(static::$defaults['docroot']) * -1);
$file = implode('/', array_diff(explode('/', $trace[0]['file']), explode('/', $root)));
$ret = array(
'file' => $file,
'line' => $trace[0]['line']
);
if (isset($trace[1]['function'])) $ret['function'] = $trace[1]['function'];
if (isset($trace[1]['class'])) $ret['class'] = $trace[1]['class'];
return $ret;
} | [
"public",
"function",
"location",
"(",
"$",
"trace",
")",
"{",
"$",
"root",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
",",
"0",
",",
"strlen",
"(",
"static",
"::",
"$",
"defaults",
"[",
"'docroot'",
"]",
")",
"*",
"-",
"1",
")",
";",
"$",
"file",
"=",
"implode",
"(",
"'/'",
",",
"array_diff",
"(",
"explode",
"(",
"'/'",
",",
"$",
"trace",
"[",
"0",
"]",
"[",
"'file'",
"]",
")",
",",
"explode",
"(",
"'/'",
",",
"$",
"root",
")",
")",
")",
";",
"$",
"ret",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'line'",
"=>",
"$",
"trace",
"[",
"0",
"]",
"[",
"'line'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"trace",
"[",
"1",
"]",
"[",
"'function'",
"]",
")",
")",
"$",
"ret",
"[",
"'function'",
"]",
"=",
"$",
"trace",
"[",
"1",
"]",
"[",
"'function'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"trace",
"[",
"1",
"]",
"[",
"'class'",
"]",
")",
")",
"$",
"ret",
"[",
"'class'",
"]",
"=",
"$",
"trace",
"[",
"1",
"]",
"[",
"'class'",
"]",
";",
"return",
"$",
"ret",
";",
"}"
] | Create an array that describes the location of the debug call
@param string $trace
@return array | [
"Create",
"an",
"array",
"that",
"describes",
"the",
"location",
"of",
"the",
"debug",
"call"
] | train | https://github.com/alkemann/h.l/blob/0ba9a9738e317b32c4d6f800c618524fccfdbc9a/src/debug/util/Debug.php#L192-L202 |
SteeinRu/steein-sdk-php | src/Steein/SDK/Core/FileUpload/SteeinFile.php | SteeinFile.open | public function open()
{
if (!$this->isRemoteFile($this->path) && !is_readable($this->path)) {
throw new SteeinSDKException('Не удалось создать объект SteeinFile. Невозможно прочитать ресурс: ' . $this->path . '.');
}
$this->stream = fopen($this->path, 'r');
if (!$this->stream) {
throw new SteeinSDKException('Не удалось создать объект SteeinFile. Не удалось открыть ресурс: ' . $this->path . '.');
}
} | php | public function open()
{
if (!$this->isRemoteFile($this->path) && !is_readable($this->path)) {
throw new SteeinSDKException('Не удалось создать объект SteeinFile. Невозможно прочитать ресурс: ' . $this->path . '.');
}
$this->stream = fopen($this->path, 'r');
if (!$this->stream) {
throw new SteeinSDKException('Не удалось создать объект SteeinFile. Не удалось открыть ресурс: ' . $this->path . '.');
}
} | [
"public",
"function",
"open",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isRemoteFile",
"(",
"$",
"this",
"->",
"path",
")",
"&&",
"!",
"is_readable",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"throw",
"new",
"SteeinSDKException",
"(",
"'Не удалось создать объект SteeinFile. Невозможно прочитать ресурс: ' . $this->path . '.');",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"}",
"$",
"this",
"->",
"stream",
"=",
"fopen",
"(",
"$",
"this",
"->",
"path",
",",
"'r'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"stream",
")",
"{",
"throw",
"new",
"SteeinSDKException",
"(",
"'Не удалось создать объект SteeinFile. Не удалось открыть ресурс: ' . $this->path . '.');",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"}",
"}"
] | Открывает поток для файла.
@throws SteeinSDKException | [
"Открывает",
"поток",
"для",
"файла",
"."
] | train | https://github.com/SteeinRu/steein-sdk-php/blob/27113624a6582d27bb55d7c9724e8306739ef167/src/Steein/SDK/Core/FileUpload/SteeinFile.php#L101-L112 |
KDF5000/EasyThink | src/ThinkPHP/Library/Think/Log/Driver/File.php | File.write | public function write($log,$destination='') {
$now = date($this->config['log_time_format']);
if(empty($destination)){
$destination = $this->config['log_path'].date('y_m_d').'.log';
}
// 自动创建日志目录
$log_dir = dirname($destination);
if (!is_dir($log_dir)) {
mkdir($log_dir, 0755, true);
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) ){
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
}
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
} | php | public function write($log,$destination='') {
$now = date($this->config['log_time_format']);
if(empty($destination)){
$destination = $this->config['log_path'].date('y_m_d').'.log';
}
// 自动创建日志目录
$log_dir = dirname($destination);
if (!is_dir($log_dir)) {
mkdir($log_dir, 0755, true);
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) ){
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
}
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
} | [
"public",
"function",
"write",
"(",
"$",
"log",
",",
"$",
"destination",
"=",
"''",
")",
"{",
"$",
"now",
"=",
"date",
"(",
"$",
"this",
"->",
"config",
"[",
"'log_time_format'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"destination",
")",
")",
"{",
"$",
"destination",
"=",
"$",
"this",
"->",
"config",
"[",
"'log_path'",
"]",
".",
"date",
"(",
"'y_m_d'",
")",
".",
"'.log'",
";",
"}",
"// 自动创建日志目录",
"$",
"log_dir",
"=",
"dirname",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"log_dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"log_dir",
",",
"0755",
",",
"true",
")",
";",
"}",
"//检测日志文件大小,超过配置大小则备份日志文件重新生成",
"if",
"(",
"is_file",
"(",
"$",
"destination",
")",
"&&",
"floor",
"(",
"$",
"this",
"->",
"config",
"[",
"'log_file_size'",
"]",
")",
"<=",
"filesize",
"(",
"$",
"destination",
")",
")",
"{",
"rename",
"(",
"$",
"destination",
",",
"dirname",
"(",
"$",
"destination",
")",
".",
"'/'",
".",
"time",
"(",
")",
".",
"'-'",
".",
"basename",
"(",
"$",
"destination",
")",
")",
";",
"}",
"error_log",
"(",
"\"[{$now}] \"",
".",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
".",
"' '",
".",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
".",
"\"\\r\\n{$log}\\r\\n\"",
",",
"3",
",",
"$",
"destination",
")",
";",
"}"
] | 日志写入接口
@access public
@param string $log 日志信息
@param string $destination 写入目标
@return void | [
"日志写入接口"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Log/Driver/File.php#L34-L49 |
RhubarbPHP/Scaffold.AuthenticationWithRoles | src/User.php | User.hasRole | public function hasRole($name)
{
if ($this->RoleID) {
$role = new Role($this->RoleID);
if ($role->RoleName == $name) {
return true;
}
}
foreach ($this->Roles as $role) {
if ($role->RoleName == $name) {
return true;
}
}
return false;
} | php | public function hasRole($name)
{
if ($this->RoleID) {
$role = new Role($this->RoleID);
if ($role->RoleName == $name) {
return true;
}
}
foreach ($this->Roles as $role) {
if ($role->RoleName == $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasRole",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"RoleID",
")",
"{",
"$",
"role",
"=",
"new",
"Role",
"(",
"$",
"this",
"->",
"RoleID",
")",
";",
"if",
"(",
"$",
"role",
"->",
"RoleName",
"==",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"Roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"->",
"RoleName",
"==",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if user has a specific role
@param $name string
@return bool | [
"Checks",
"if",
"user",
"has",
"a",
"specific",
"role"
] | train | https://github.com/RhubarbPHP/Scaffold.AuthenticationWithRoles/blob/7402e741b67f1936dfbb3d3ae6e1f6193c226f9b/src/User.php#L96-L111 |
EdwinDayot/shorty-framework | src/Framework/Middlewares/RequestHandler.php | RequestHandler.handle | public function handle(RequestInterface $request): ResponseInterface
{
if (!array_key_exists($this->index, $this->middlewares)) {
return $this->response;
}
$current = $this->index;
++$this->index;
$response = $this->container->call([$this->middlewares[$current], 'process'], [$request, $this]);
return $response;
} | php | public function handle(RequestInterface $request): ResponseInterface
{
if (!array_key_exists($this->index, $this->middlewares)) {
return $this->response;
}
$current = $this->index;
++$this->index;
$response = $this->container->call([$this->middlewares[$current], 'process'], [$request, $this]);
return $response;
} | [
"public",
"function",
"handle",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"index",
",",
"$",
"this",
"->",
"middlewares",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
";",
"}",
"$",
"current",
"=",
"$",
"this",
"->",
"index",
";",
"++",
"$",
"this",
"->",
"index",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"container",
"->",
"call",
"(",
"[",
"$",
"this",
"->",
"middlewares",
"[",
"$",
"current",
"]",
",",
"'process'",
"]",
",",
"[",
"$",
"request",
",",
"$",
"this",
"]",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Handle the request and return a response.
@param RequestInterface $request
@return ResponseInterface | [
"Handle",
"the",
"request",
"and",
"return",
"a",
"response",
"."
] | train | https://github.com/EdwinDayot/shorty-framework/blob/e03c991ea86aedbd87674d1ee2f9041b55b5e578/src/Framework/Middlewares/RequestHandler.php#L69-L82 |
Steptro/laravel-commands | src/commands/CreateUserCommand.php | CreateUserCommand.handle | public function handle()
{
// Retrieve attributes
$attributes = config('commands.user_attributes');
// Retrieve sensitive fields
$sensitive_attributes = config('commands.user_attributes_sensitive');
// Ask questions and prepare data
foreach ($attributes as $attribute => $question) {
if (is_null($attribute) || $attribute === 0) {
$attribute = $question;
}
// Check if sensitive field
if (in_array($attribute, $sensitive_attributes)) {
$attributes[$attribute] = Hash::make($this->secret($question));
continue;
}
$attributes[$attribute] = $this->ask($question);
}
// Create new user
try {
$user = App::make(config('commands.user'));
$user::create($attributes);
$this->info('User created');
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
} | php | public function handle()
{
// Retrieve attributes
$attributes = config('commands.user_attributes');
// Retrieve sensitive fields
$sensitive_attributes = config('commands.user_attributes_sensitive');
// Ask questions and prepare data
foreach ($attributes as $attribute => $question) {
if (is_null($attribute) || $attribute === 0) {
$attribute = $question;
}
// Check if sensitive field
if (in_array($attribute, $sensitive_attributes)) {
$attributes[$attribute] = Hash::make($this->secret($question));
continue;
}
$attributes[$attribute] = $this->ask($question);
}
// Create new user
try {
$user = App::make(config('commands.user'));
$user::create($attributes);
$this->info('User created');
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"// Retrieve attributes",
"$",
"attributes",
"=",
"config",
"(",
"'commands.user_attributes'",
")",
";",
"// Retrieve sensitive fields",
"$",
"sensitive_attributes",
"=",
"config",
"(",
"'commands.user_attributes_sensitive'",
")",
";",
"// Ask questions and prepare data",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"question",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"attribute",
")",
"||",
"$",
"attribute",
"===",
"0",
")",
"{",
"$",
"attribute",
"=",
"$",
"question",
";",
"}",
"// Check if sensitive field",
"if",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"sensitive_attributes",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"attribute",
"]",
"=",
"Hash",
"::",
"make",
"(",
"$",
"this",
"->",
"secret",
"(",
"$",
"question",
")",
")",
";",
"continue",
";",
"}",
"$",
"attributes",
"[",
"$",
"attribute",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"$",
"question",
")",
";",
"}",
"// Create new user",
"try",
"{",
"$",
"user",
"=",
"App",
"::",
"make",
"(",
"config",
"(",
"'commands.user'",
")",
")",
";",
"$",
"user",
"::",
"create",
"(",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'User created'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/Steptro/laravel-commands/blob/4fd69f26b76250f3634dd3aa77ce931b762227a2/src/commands/CreateUserCommand.php#L30-L61 |
netbull/CoreBundle | Form/Type/DynamicType.php | DynamicType.finishView | public function finishView(FormView $view, FormInterface $form, array $options)
{
parent::finishView($view, $form, $options);
$varNames = ['multiple', 'primary_key', 'hidden'];
foreach ($varNames as $varName) {
$view->vars[$varName] = $options[$varName];
}
if ($options['multiple']) {
$view->vars['full_name'] .= '[]';
}
} | php | public function finishView(FormView $view, FormInterface $form, array $options)
{
parent::finishView($view, $form, $options);
$varNames = ['multiple', 'primary_key', 'hidden'];
foreach ($varNames as $varName) {
$view->vars[$varName] = $options[$varName];
}
if ($options['multiple']) {
$view->vars['full_name'] .= '[]';
}
} | [
"public",
"function",
"finishView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"parent",
"::",
"finishView",
"(",
"$",
"view",
",",
"$",
"form",
",",
"$",
"options",
")",
";",
"$",
"varNames",
"=",
"[",
"'multiple'",
",",
"'primary_key'",
",",
"'hidden'",
"]",
";",
"foreach",
"(",
"$",
"varNames",
"as",
"$",
"varName",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"$",
"varName",
"]",
"=",
"$",
"options",
"[",
"$",
"varName",
"]",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'multiple'",
"]",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'full_name'",
"]",
".=",
"'[]'",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Form/Type/DynamicType.php#L67-L80 |
maxvu/skeletal | src/HTTP/Response.php | Response.code | public function code ( $code = NULL ) {
if ( $code === NULL )
return $this->code;
if ( ResponseCode::find( $code ) === NULL )
throw new \InvalidArgumentException( "Response: no code $code" );
$this->code = intval( $code );
return $this;
} | php | public function code ( $code = NULL ) {
if ( $code === NULL )
return $this->code;
if ( ResponseCode::find( $code ) === NULL )
throw new \InvalidArgumentException( "Response: no code $code" );
$this->code = intval( $code );
return $this;
} | [
"public",
"function",
"code",
"(",
"$",
"code",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"code",
"===",
"NULL",
")",
"return",
"$",
"this",
"->",
"code",
";",
"if",
"(",
"ResponseCode",
"::",
"find",
"(",
"$",
"code",
")",
"===",
"NULL",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Response: no code $code\"",
")",
";",
"$",
"this",
"->",
"code",
"=",
"intval",
"(",
"$",
"code",
")",
";",
"return",
"$",
"this",
";",
"}"
] | /*
Basic properties | [
"/",
"*",
"Basic",
"properties"
] | train | https://github.com/maxvu/skeletal/blob/fd403dc685dfb7e23b4a318a2d3e196be75cd270/src/HTTP/Response.php#L25-L32 |
maxvu/skeletal | src/HTTP/Response.php | Response.header | public function header ( $name, $value = NULL ) {
if ( $value === NULL )
if ( isset( $this->headers[$name] ) )
return $this->headers[$name];
else
return NULL;
$this->headers[$name] = $value;
return $this;
} | php | public function header ( $name, $value = NULL ) {
if ( $value === NULL )
if ( isset( $this->headers[$name] ) )
return $this->headers[$name];
else
return NULL;
$this->headers[$name] = $value;
return $this;
} | [
"public",
"function",
"header",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"NULL",
")",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
")",
"return",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
";",
"else",
"return",
"NULL",
";",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | /*
Headers | [
"/",
"*",
"Headers"
] | train | https://github.com/maxvu/skeletal/blob/fd403dc685dfb7e23b4a318a2d3e196be75cd270/src/HTTP/Response.php#L50-L58 |
maxvu/skeletal | src/HTTP/Response.php | Response.redirect | public function redirect ( $to ) {
if ( $to === NULL )
return $this->header( 'Location' ) ? $this->header( 'Location' ) : NULL;
return $this->header( 'Location', $to )->code(301);
} | php | public function redirect ( $to ) {
if ( $to === NULL )
return $this->header( 'Location' ) ? $this->header( 'Location' ) : NULL;
return $this->header( 'Location', $to )->code(301);
} | [
"public",
"function",
"redirect",
"(",
"$",
"to",
")",
"{",
"if",
"(",
"$",
"to",
"===",
"NULL",
")",
"return",
"$",
"this",
"->",
"header",
"(",
"'Location'",
")",
"?",
"$",
"this",
"->",
"header",
"(",
"'Location'",
")",
":",
"NULL",
";",
"return",
"$",
"this",
"->",
"header",
"(",
"'Location'",
",",
"$",
"to",
")",
"->",
"code",
"(",
"301",
")",
";",
"}"
] | /*
Codes | [
"/",
"*",
"Codes"
] | train | https://github.com/maxvu/skeletal/blob/fd403dc685dfb7e23b4a318a2d3e196be75cd270/src/HTTP/Response.php#L93-L97 |
maxvu/skeletal | src/HTTP/Response.php | Response.send | public static function send ( $response ) {
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ?
$_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
$code = $response->code();
$status = ResponseCode::find( $code );
$body = $response->body();
header( "$protocol $code $status", true, intval( $code ) );
foreach ( $response->headers() as $a => $v )
header( "$a: $v" );
if ( is_string( $body ) && strlen( $body ) > 0 )
echo $body;
} | php | public static function send ( $response ) {
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ?
$_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
$code = $response->code();
$status = ResponseCode::find( $code );
$body = $response->body();
header( "$protocol $code $status", true, intval( $code ) );
foreach ( $response->headers() as $a => $v )
header( "$a: $v" );
if ( is_string( $body ) && strlen( $body ) > 0 )
echo $body;
} | [
"public",
"static",
"function",
"send",
"(",
"$",
"response",
")",
"{",
"$",
"protocol",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
":",
"'HTTP/1.1'",
";",
"$",
"code",
"=",
"$",
"response",
"->",
"code",
"(",
")",
";",
"$",
"status",
"=",
"ResponseCode",
"::",
"find",
"(",
"$",
"code",
")",
";",
"$",
"body",
"=",
"$",
"response",
"->",
"body",
"(",
")",
";",
"header",
"(",
"\"$protocol $code $status\"",
",",
"true",
",",
"intval",
"(",
"$",
"code",
")",
")",
";",
"foreach",
"(",
"$",
"response",
"->",
"headers",
"(",
")",
"as",
"$",
"a",
"=>",
"$",
"v",
")",
"header",
"(",
"\"$a: $v\"",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"body",
")",
"&&",
"strlen",
"(",
"$",
"body",
")",
">",
"0",
")",
"echo",
"$",
"body",
";",
"}"
] | /*
Dispatch headers and send message body. | [
"/",
"*",
"Dispatch",
"headers",
"and",
"send",
"message",
"body",
"."
] | train | https://github.com/maxvu/skeletal/blob/fd403dc685dfb7e23b4a318a2d3e196be75cd270/src/HTTP/Response.php#L178-L189 |
lhj1982/ademes-core | src/Ademes/Core/CoreServiceProvider.php | CoreServiceProvider.register | public function register()
{
$this->app['authClient'] = $this->app->share(function($app)
{
return new AuthClient;
});
$this->app['userClient'] = $this->app->share(function($app)
{
return new UserClient;
});
$this->app['client'] = $this->app->share(function($app)
{
return new Client;
});
$this->app['solariumClient'] = $this->app->share(function($app)
{
return new SolariumClientImpl();
});
// Shortcut so developers don't need to add an Alias in app/config/app.php
$this->app->booting(function()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('AuthClient', 'Ademes\Core\Facades\AuthClient');
$loader->alias('UserClient', 'Ademes\Core\Facades\UserClient');
$loader->alias('HttpClient', 'Ademes\Core\Facades\HttpClient');
$loader->alias('SolariumClient', 'Ademes\Core\Facades\SolariumClient');
});
} | php | public function register()
{
$this->app['authClient'] = $this->app->share(function($app)
{
return new AuthClient;
});
$this->app['userClient'] = $this->app->share(function($app)
{
return new UserClient;
});
$this->app['client'] = $this->app->share(function($app)
{
return new Client;
});
$this->app['solariumClient'] = $this->app->share(function($app)
{
return new SolariumClientImpl();
});
// Shortcut so developers don't need to add an Alias in app/config/app.php
$this->app->booting(function()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('AuthClient', 'Ademes\Core\Facades\AuthClient');
$loader->alias('UserClient', 'Ademes\Core\Facades\UserClient');
$loader->alias('HttpClient', 'Ademes\Core\Facades\HttpClient');
$loader->alias('SolariumClient', 'Ademes\Core\Facades\SolariumClient');
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'authClient'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"AuthClient",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'userClient'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"UserClient",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'client'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Client",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'solariumClient'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"SolariumClientImpl",
"(",
")",
";",
"}",
")",
";",
"// Shortcut so developers don't need to add an Alias in app/config/app.php",
"$",
"this",
"->",
"app",
"->",
"booting",
"(",
"function",
"(",
")",
"{",
"$",
"loader",
"=",
"\\",
"Illuminate",
"\\",
"Foundation",
"\\",
"AliasLoader",
"::",
"getInstance",
"(",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'AuthClient'",
",",
"'Ademes\\Core\\Facades\\AuthClient'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'UserClient'",
",",
"'Ademes\\Core\\Facades\\UserClient'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'HttpClient'",
",",
"'Ademes\\Core\\Facades\\HttpClient'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'SolariumClient'",
",",
"'Ademes\\Core\\Facades\\SolariumClient'",
")",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/lhj1982/ademes-core/blob/7a40a5c413fa26aaf23e2313fa3b1e0100ff4cb9/src/Ademes/Core/CoreServiceProvider.php#L33-L64 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.addAttributeMapping | public function addAttributeMapping(PropertyMetadata $mapping)
{
if ($this->discriminatorAttribute !== null && $this->discriminatorAttribute === $mapping->attributeName) {
throw MappingException::discriminatorAttributeConflict($this->name, $this->discriminatorAttribute);
}
if ($this->isEmbeddedDocument && $mapping->isCollectionType() && $mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET) {
throw MappingException::atomicCollectionStrategyNotAllowed($this->name, $mapping->name);
}
$this->propertyMetadata[$mapping->name] = $mapping;
if ($mapping->association !== null) {
$this->associationMetadata[$mapping->name] = $mapping;
}
if ($mapping->generator !== null) {
$this->generatedProperties[$mapping->name] = $mapping;
}
} | php | public function addAttributeMapping(PropertyMetadata $mapping)
{
if ($this->discriminatorAttribute !== null && $this->discriminatorAttribute === $mapping->attributeName) {
throw MappingException::discriminatorAttributeConflict($this->name, $this->discriminatorAttribute);
}
if ($this->isEmbeddedDocument && $mapping->isCollectionType() && $mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET) {
throw MappingException::atomicCollectionStrategyNotAllowed($this->name, $mapping->name);
}
$this->propertyMetadata[$mapping->name] = $mapping;
if ($mapping->association !== null) {
$this->associationMetadata[$mapping->name] = $mapping;
}
if ($mapping->generator !== null) {
$this->generatedProperties[$mapping->name] = $mapping;
}
} | [
"public",
"function",
"addAttributeMapping",
"(",
"PropertyMetadata",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"discriminatorAttribute",
"!==",
"null",
"&&",
"$",
"this",
"->",
"discriminatorAttribute",
"===",
"$",
"mapping",
"->",
"attributeName",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorAttributeConflict",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"discriminatorAttribute",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isEmbeddedDocument",
"&&",
"$",
"mapping",
"->",
"isCollectionType",
"(",
")",
"&&",
"$",
"mapping",
"->",
"strategy",
"===",
"PropertyMetadata",
"::",
"STORAGE_STRATEGY_ATOMIC_SET",
")",
"{",
"throw",
"MappingException",
"::",
"atomicCollectionStrategyNotAllowed",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"->",
"name",
")",
";",
"}",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"mapping",
"->",
"name",
"]",
"=",
"$",
"mapping",
";",
"if",
"(",
"$",
"mapping",
"->",
"association",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"associationMetadata",
"[",
"$",
"mapping",
"->",
"name",
"]",
"=",
"$",
"mapping",
";",
"}",
"if",
"(",
"$",
"mapping",
"->",
"generator",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"generatedProperties",
"[",
"$",
"mapping",
"->",
"name",
"]",
"=",
"$",
"mapping",
";",
"}",
"}"
] | @param PropertyMetadata $mapping
@throws MappingException | [
"@param",
"PropertyMetadata",
"$mapping"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L407-L426 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.addSecondaryIndex | public function addSecondaryIndex(Index $index)
{
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentsNotIndexable($this->getName());
}
if (isset($this->secondaryIndexes[$index->getName()])) {
throw MappingException::indexExists($this->getName(), $index->getName());
}
$this->secondaryIndexes[$index->getName()] = $index;
} | php | public function addSecondaryIndex(Index $index)
{
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentsNotIndexable($this->getName());
}
if (isset($this->secondaryIndexes[$index->getName()])) {
throw MappingException::indexExists($this->getName(), $index->getName());
}
$this->secondaryIndexes[$index->getName()] = $index;
} | [
"public",
"function",
"addSecondaryIndex",
"(",
"Index",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmbeddedDocument",
")",
"{",
"throw",
"MappingException",
"::",
"embeddedDocumentsNotIndexable",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"secondaryIndexes",
"[",
"$",
"index",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"indexExists",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"index",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"secondaryIndexes",
"[",
"$",
"index",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"index",
";",
"}"
] | @param Index $index
@throws MappingException | [
"@param",
"Index",
"$index"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L450-L461 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.createIdentifier | public function createIdentifier($document, $unmarshal = false)
{
$index = $this->getIndex();
$hashKey = $index->getHashKey();
$hashValue = $hashKey->getPropertyMetadata()->getValue($document);
if ($unmarshal) {
$hashValue = $hashKey->getType()->convertToPHPValue($hashValue);
}
if (!$index->isComposite()) {
return $this->createIdentifierFromValues($hashValue);
}
$rangeKey = $index->getRangeKey();
$rangeValue = $rangeKey->getPropertyMetadata()->getValue($document);
if ($unmarshal) {
$rangeValue = $rangeKey->getType()->convertToPHPValue($rangeValue);
}
return $this->createIdentifierFromValues($hashValue, $rangeValue);
} | php | public function createIdentifier($document, $unmarshal = false)
{
$index = $this->getIndex();
$hashKey = $index->getHashKey();
$hashValue = $hashKey->getPropertyMetadata()->getValue($document);
if ($unmarshal) {
$hashValue = $hashKey->getType()->convertToPHPValue($hashValue);
}
if (!$index->isComposite()) {
return $this->createIdentifierFromValues($hashValue);
}
$rangeKey = $index->getRangeKey();
$rangeValue = $rangeKey->getPropertyMetadata()->getValue($document);
if ($unmarshal) {
$rangeValue = $rangeKey->getType()->convertToPHPValue($rangeValue);
}
return $this->createIdentifierFromValues($hashValue, $rangeValue);
} | [
"public",
"function",
"createIdentifier",
"(",
"$",
"document",
",",
"$",
"unmarshal",
"=",
"false",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"getIndex",
"(",
")",
";",
"$",
"hashKey",
"=",
"$",
"index",
"->",
"getHashKey",
"(",
")",
";",
"$",
"hashValue",
"=",
"$",
"hashKey",
"->",
"getPropertyMetadata",
"(",
")",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"unmarshal",
")",
"{",
"$",
"hashValue",
"=",
"$",
"hashKey",
"->",
"getType",
"(",
")",
"->",
"convertToPHPValue",
"(",
"$",
"hashValue",
")",
";",
"}",
"if",
"(",
"!",
"$",
"index",
"->",
"isComposite",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createIdentifierFromValues",
"(",
"$",
"hashValue",
")",
";",
"}",
"$",
"rangeKey",
"=",
"$",
"index",
"->",
"getRangeKey",
"(",
")",
";",
"$",
"rangeValue",
"=",
"$",
"rangeKey",
"->",
"getPropertyMetadata",
"(",
")",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"unmarshal",
")",
"{",
"$",
"rangeValue",
"=",
"$",
"rangeKey",
"->",
"getType",
"(",
")",
"->",
"convertToPHPValue",
"(",
"$",
"rangeValue",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createIdentifierFromValues",
"(",
"$",
"hashValue",
",",
"$",
"rangeValue",
")",
";",
"}"
] | Create an Identifier from the key value(s) in the provided object or array.
@param object|array $document
@param bool $unmarshal
@return Identifier|CompositeIdentifier $identifier | [
"Create",
"an",
"Identifier",
"from",
"the",
"key",
"value",
"(",
"s",
")",
"in",
"the",
"provided",
"object",
"or",
"array",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L471-L493 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.createIdentifierFromValues | public function createIdentifierFromValues($hashValue, $rangeValue = null)
{
if ($this->index->isComposite()) {
return new CompositeIdentifier($this, $hashValue, $rangeValue);
}
return new Identifier($this, $hashValue);
} | php | public function createIdentifierFromValues($hashValue, $rangeValue = null)
{
if ($this->index->isComposite()) {
return new CompositeIdentifier($this, $hashValue, $rangeValue);
}
return new Identifier($this, $hashValue);
} | [
"public",
"function",
"createIdentifierFromValues",
"(",
"$",
"hashValue",
",",
"$",
"rangeValue",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"index",
"->",
"isComposite",
"(",
")",
")",
"{",
"return",
"new",
"CompositeIdentifier",
"(",
"$",
"this",
",",
"$",
"hashValue",
",",
"$",
"rangeValue",
")",
";",
"}",
"return",
"new",
"Identifier",
"(",
"$",
"this",
",",
"$",
"hashValue",
")",
";",
"}"
] | Create an Identifier from the provided key value(s).
@param mixed $hashValue
@param mixed $rangeValue
@return Identifier|CompositeIdentifier $identifier | [
"Create",
"an",
"Identifier",
"from",
"the",
"provided",
"key",
"value",
"(",
"s",
")",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L503-L510 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getAssociationTargetClass | public function getAssociationTargetClass($assocName)
{
if (!isset($this->associationMetadata[$assocName])) {
throw new \InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
}
return $this->associationMetadata[$assocName]->targetDocument;
} | php | public function getAssociationTargetClass($assocName)
{
if (!isset($this->associationMetadata[$assocName])) {
throw new \InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
}
return $this->associationMetadata[$assocName]->targetDocument;
} | [
"public",
"function",
"getAssociationTargetClass",
"(",
"$",
"assocName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"associationMetadata",
"[",
"$",
"assocName",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Association name expected, '\"",
".",
"$",
"assocName",
".",
"\"' is not an association.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"associationMetadata",
"[",
"$",
"assocName",
"]",
"->",
"targetDocument",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L531-L538 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getAttributeValue | public function getAttributeValue($document, $attribute)
{
if ($document instanceof Proxy && !in_array($attribute, $this->getIdentifierAttributeNames()) && !$document->__isInitialized()) {
$document->__load();
}
return $this->getPropertyMetadata($attribute)->getValue($document);
} | php | public function getAttributeValue($document, $attribute)
{
if ($document instanceof Proxy && !in_array($attribute, $this->getIdentifierAttributeNames()) && !$document->__isInitialized()) {
$document->__load();
}
return $this->getPropertyMetadata($attribute)->getValue($document);
} | [
"public",
"function",
"getAttributeValue",
"(",
"$",
"document",
",",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"Proxy",
"&&",
"!",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"this",
"->",
"getIdentifierAttributeNames",
"(",
")",
")",
"&&",
"!",
"$",
"document",
"->",
"__isInitialized",
"(",
")",
")",
"{",
"$",
"document",
"->",
"__load",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getPropertyMetadata",
"(",
"$",
"attribute",
")",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"}"
] | Gets the specified attribute's value off the given document.
@param object $document
@param string $attribute
@return mixed | [
"Gets",
"the",
"specified",
"attribute",
"s",
"value",
"off",
"the",
"given",
"document",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L560-L567 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getDefinitionTable | public function getDefinitionTable()
{
$definition = array_merge(
$this->getIndex()->getDefinition(),
$this->getDefinitionSecondaryIndexes()
);
$definition['TableName'] = $this->getTableName();
$definition['AttributeDefinitions'] = $this->getDefinitionIndexAttributes();
return $definition;
} | php | public function getDefinitionTable()
{
$definition = array_merge(
$this->getIndex()->getDefinition(),
$this->getDefinitionSecondaryIndexes()
);
$definition['TableName'] = $this->getTableName();
$definition['AttributeDefinitions'] = $this->getDefinitionIndexAttributes();
return $definition;
} | [
"public",
"function",
"getDefinitionTable",
"(",
")",
"{",
"$",
"definition",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"getDefinition",
"(",
")",
",",
"$",
"this",
"->",
"getDefinitionSecondaryIndexes",
"(",
")",
")",
";",
"$",
"definition",
"[",
"'TableName'",
"]",
"=",
"$",
"this",
"->",
"getTableName",
"(",
")",
";",
"$",
"definition",
"[",
"'AttributeDefinitions'",
"]",
"=",
"$",
"this",
"->",
"getDefinitionIndexAttributes",
"(",
")",
";",
"return",
"$",
"definition",
";",
"}"
] | Return the table definition for this class, formatted for AWS SDK.
@return array | [
"Return",
"the",
"table",
"definition",
"for",
"this",
"class",
"formatted",
"for",
"AWS",
"SDK",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L605-L616 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getEmbeddedDiscriminatorValue | public function getEmbeddedDiscriminatorValue(PropertyMetadata $mapping, $embeddedDocument)
{
if (!$mapping->embedded || get_class($embeddedDocument) !== $this->name) {
throw new \InvalidArgumentException;
}
if ($mapping->targetDocument !== null) {
return null;
}
$discriminatorMetadata = $this->getPropertyMetadata($mapping->discriminatorAttribute);
$discriminatorValue = $discriminatorMetadata->getValue($embeddedDocument);
if ($discriminatorValue === null) {
if ($discriminatorMetadata->discriminatorDefaultValue === null) {
return null;
}
$discriminatorValue = $discriminatorMetadata->discriminatorDefaultValue;
}
if (isset($discriminatorMetadata->discriminatorMap[$discriminatorValue])) {
return $discriminatorMetadata->discriminatorMap[$discriminatorValue];
}
return $discriminatorValue;
} | php | public function getEmbeddedDiscriminatorValue(PropertyMetadata $mapping, $embeddedDocument)
{
if (!$mapping->embedded || get_class($embeddedDocument) !== $this->name) {
throw new \InvalidArgumentException;
}
if ($mapping->targetDocument !== null) {
return null;
}
$discriminatorMetadata = $this->getPropertyMetadata($mapping->discriminatorAttribute);
$discriminatorValue = $discriminatorMetadata->getValue($embeddedDocument);
if ($discriminatorValue === null) {
if ($discriminatorMetadata->discriminatorDefaultValue === null) {
return null;
}
$discriminatorValue = $discriminatorMetadata->discriminatorDefaultValue;
}
if (isset($discriminatorMetadata->discriminatorMap[$discriminatorValue])) {
return $discriminatorMetadata->discriminatorMap[$discriminatorValue];
}
return $discriminatorValue;
} | [
"public",
"function",
"getEmbeddedDiscriminatorValue",
"(",
"PropertyMetadata",
"$",
"mapping",
",",
"$",
"embeddedDocument",
")",
"{",
"if",
"(",
"!",
"$",
"mapping",
"->",
"embedded",
"||",
"get_class",
"(",
"$",
"embeddedDocument",
")",
"!==",
"$",
"this",
"->",
"name",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
";",
"}",
"if",
"(",
"$",
"mapping",
"->",
"targetDocument",
"!==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"discriminatorMetadata",
"=",
"$",
"this",
"->",
"getPropertyMetadata",
"(",
"$",
"mapping",
"->",
"discriminatorAttribute",
")",
";",
"$",
"discriminatorValue",
"=",
"$",
"discriminatorMetadata",
"->",
"getValue",
"(",
"$",
"embeddedDocument",
")",
";",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"discriminatorMetadata",
"->",
"discriminatorDefaultValue",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"discriminatorValue",
"=",
"$",
"discriminatorMetadata",
"->",
"discriminatorDefaultValue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"discriminatorMetadata",
"->",
"discriminatorMap",
"[",
"$",
"discriminatorValue",
"]",
")",
")",
"{",
"return",
"$",
"discriminatorMetadata",
"->",
"discriminatorMap",
"[",
"$",
"discriminatorValue",
"]",
";",
"}",
"return",
"$",
"discriminatorValue",
";",
"}"
] | @param PropertyMetadata $mapping
@param object $embeddedDocument
@return string|null | [
"@param",
"PropertyMetadata",
"$mapping",
"@param",
"object",
"$embeddedDocument"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L639-L665 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getPropertyMetadata | public function getPropertyMetadata($propertyName)
{
if (!isset($this->propertyMetadata[$propertyName])) {
throw MappingException::mappingNotFound($this->name, $propertyName);
}
return $this->propertyMetadata[$propertyName];
} | php | public function getPropertyMetadata($propertyName)
{
if (!isset($this->propertyMetadata[$propertyName])) {
throw MappingException::mappingNotFound($this->name, $propertyName);
}
return $this->propertyMetadata[$propertyName];
} | [
"public",
"function",
"getPropertyMetadata",
"(",
"$",
"propertyName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"mappingNotFound",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"propertyName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"propertyName",
"]",
";",
"}"
] | Gets the mapping metadata of a property.
@param string $propertyName The property name.
@return PropertyMetadata The property mapping.
@throws MappingException | [
"Gets",
"the",
"mapping",
"metadata",
"of",
"a",
"property",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L788-L795 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getReflectionClass | public function getReflectionClass()
{
if (!$this->reflection) {
$this->reflection = new \ReflectionClass($this->name);
}
return $this->reflection;
} | php | public function getReflectionClass()
{
if (!$this->reflection) {
$this->reflection = new \ReflectionClass($this->name);
}
return $this->reflection;
} | [
"public",
"function",
"getReflectionClass",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"reflection",
")",
"{",
"$",
"this",
"->",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"reflection",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L800-L807 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.getTypeOfAttribute | public function getTypeOfAttribute($attributeName)
{
return isset($this->propertyMetadata[$attributeName]) ?
$this->propertyMetadata[$attributeName]->type : null;
} | php | public function getTypeOfAttribute($attributeName)
{
return isset($this->propertyMetadata[$attributeName]) ?
$this->propertyMetadata[$attributeName]->type : null;
} | [
"public",
"function",
"getTypeOfAttribute",
"(",
"$",
"attributeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
")",
"?",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"type",
":",
"null",
";",
"}"
] | Returns a type name of this attribute.
This type names can be implementation specific but should at least include the php types:
integer, string, boolean, float/double, datetime.
@param string $attributeName
@return string | [
"Returns",
"a",
"type",
"name",
"of",
"this",
"attribute",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L847-L851 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.invokeLifecycleCallbacks | public function invokeLifecycleCallbacks($event, $document, array $arguments = null)
{
if (!$document instanceof $this->name) {
throw new \InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document)));
}
if (empty($this->lifecycleCallbacks[$event])) {
return;
}
foreach ($this->lifecycleCallbacks[$event] as $callback) {
if ($arguments !== null) {
call_user_func_array([$document, $callback], $arguments);
} else {
$document->$callback();
}
}
} | php | public function invokeLifecycleCallbacks($event, $document, array $arguments = null)
{
if (!$document instanceof $this->name) {
throw new \InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document)));
}
if (empty($this->lifecycleCallbacks[$event])) {
return;
}
foreach ($this->lifecycleCallbacks[$event] as $callback) {
if ($arguments !== null) {
call_user_func_array([$document, $callback], $arguments);
} else {
$document->$callback();
}
}
} | [
"public",
"function",
"invokeLifecycleCallbacks",
"(",
"$",
"event",
",",
"$",
"document",
",",
"array",
"$",
"arguments",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"document",
"instanceof",
"$",
"this",
"->",
"name",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Expected document class \"%s\"; found: \"%s\"'",
",",
"$",
"this",
"->",
"name",
",",
"get_class",
"(",
"$",
"document",
")",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"lifecycleCallbacks",
"[",
"$",
"event",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"lifecycleCallbacks",
"[",
"$",
"event",
"]",
"as",
"$",
"callback",
")",
"{",
"if",
"(",
"$",
"arguments",
"!==",
"null",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"document",
",",
"$",
"callback",
"]",
",",
"$",
"arguments",
")",
";",
"}",
"else",
"{",
"$",
"document",
"->",
"$",
"callback",
"(",
")",
";",
"}",
"}",
"}"
] | Dispatches the lifecycle event of the given document by invoking all
registered callbacks.
@param string $event Lifecycle event
@param object $document Document on which the event occurred
@param array $arguments Arguments to pass to all callbacks
@throws \InvalidArgumentException if document class is not this class or
a Proxy of this class | [
"Dispatches",
"the",
"lifecycle",
"event",
"of",
"the",
"given",
"document",
"by",
"invoking",
"all",
"registered",
"callbacks",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L957-L974 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.isCollectionValuedEmbed | public function isCollectionValuedEmbed($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_EMBED_MANY;
} | php | public function isCollectionValuedEmbed($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_EMBED_MANY;
} | [
"public",
"function",
"isCollectionValuedEmbed",
"(",
"$",
"attributeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
")",
"&&",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
"===",
"PropertyMetadata",
"::",
"ASSOCIATION_TYPE_EMBED_MANY",
";",
"}"
] | Checks whether the class has a mapped embedded document for the
specified attribute and if yes, checks whether it is a collection-valued
association (to-many).
@param string $attributeName
@return bool TRUE if the association exists and is collection-valued,
FALSE otherwise. | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"embedded",
"document",
"for",
"the",
"specified",
"attribute",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"collection",
"-",
"valued",
"association",
"(",
"to",
"-",
"many",
")",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1037-L1041 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.isCollectionValuedReference | public function isCollectionValuedReference($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_MANY;
} | php | public function isCollectionValuedReference($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_MANY;
} | [
"public",
"function",
"isCollectionValuedReference",
"(",
"$",
"attributeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
")",
"&&",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
"===",
"PropertyMetadata",
"::",
"ASSOCIATION_TYPE_REFERENCE_MANY",
";",
"}"
] | Checks whether the class has a mapped association for the specified attribute
and if yes, checks whether it is a collection-valued association (to-many).
@param string $attributeName
@return bool TRUE if the association exists and is collection-valued,
FALSE otherwise. | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"association",
"for",
"the",
"specified",
"attribute",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"collection",
"-",
"valued",
"association",
"(",
"to",
"-",
"many",
")",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1052-L1056 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.isSingleValuedEmbed | public function isSingleValuedEmbed($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_EMBED_ONE;
} | php | public function isSingleValuedEmbed($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_EMBED_ONE;
} | [
"public",
"function",
"isSingleValuedEmbed",
"(",
"$",
"attributeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
")",
"&&",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
"===",
"PropertyMetadata",
"::",
"ASSOCIATION_TYPE_EMBED_ONE",
";",
"}"
] | Checks whether the class has a mapped embedded document for the
specified attribute and if yes, checks whether it is a single-valued
association (to-one).
@param string $attributeName
@return bool TRUE if the association exists and is single-valued,
FALSE otherwise. | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"embedded",
"document",
"for",
"the",
"specified",
"attribute",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"single",
"-",
"valued",
"association",
"(",
"to",
"-",
"one",
")",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1133-L1137 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.isSingleValuedReference | public function isSingleValuedReference($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_ONE;
} | php | public function isSingleValuedReference($attributeName)
{
return isset($this->propertyMetadata[$attributeName]->association) &&
$this->propertyMetadata[$attributeName]->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_ONE;
} | [
"public",
"function",
"isSingleValuedReference",
"(",
"$",
"attributeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
")",
"&&",
"$",
"this",
"->",
"propertyMetadata",
"[",
"$",
"attributeName",
"]",
"->",
"association",
"===",
"PropertyMetadata",
"::",
"ASSOCIATION_TYPE_REFERENCE_ONE",
";",
"}"
] | Checks whether the class has a mapped association for the specified attribute
and if yes, checks whether it is a single-valued association (to-one).
@param string $attributeName
@return bool TRUE if the association exists and is single-valued,
FALSE otherwise. | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"association",
"for",
"the",
"specified",
"attribute",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"single",
"-",
"valued",
"association",
"(",
"to",
"-",
"one",
")",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1148-L1152 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.registerAlsoLoadMethod | public function registerAlsoLoadMethod($method, $attributes)
{
$this->alsoLoadMethods[$method] = is_array($attributes) ? $attributes : [$attributes];
} | php | public function registerAlsoLoadMethod($method, $attributes)
{
$this->alsoLoadMethods[$method] = is_array($attributes) ? $attributes : [$attributes];
} | [
"public",
"function",
"registerAlsoLoadMethod",
"(",
"$",
"method",
",",
"$",
"attributes",
")",
"{",
"$",
"this",
"->",
"alsoLoadMethods",
"[",
"$",
"method",
"]",
"=",
"is_array",
"(",
"$",
"attributes",
")",
"?",
"$",
"attributes",
":",
"[",
"$",
"attributes",
"]",
";",
"}"
] | Registers a method for loading document data before attribute hydration.
Note: A method may be registered multiple times for different attributes.
it will be invoked only once for the first attribute found.
@param string $method Method name
@param array|string $attributes Database attribute name(s) | [
"Registers",
"a",
"method",
"for",
"loading",
"document",
"data",
"before",
"attribute",
"hydration",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1181-L1184 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setDiscriminatorAttribute | public function setDiscriminatorAttribute($discriminatorAttribute)
{
if ($discriminatorAttribute === null) {
$this->discriminatorAttribute = null;
return;
}
foreach ($this->propertyMetadata as $attributeMapping) {
if ($discriminatorAttribute === $attributeMapping->attributeName) {
throw MappingException::discriminatorAttributeConflict($this->name, $discriminatorAttribute);
}
}
$this->discriminatorAttribute = $discriminatorAttribute;
} | php | public function setDiscriminatorAttribute($discriminatorAttribute)
{
if ($discriminatorAttribute === null) {
$this->discriminatorAttribute = null;
return;
}
foreach ($this->propertyMetadata as $attributeMapping) {
if ($discriminatorAttribute === $attributeMapping->attributeName) {
throw MappingException::discriminatorAttributeConflict($this->name, $discriminatorAttribute);
}
}
$this->discriminatorAttribute = $discriminatorAttribute;
} | [
"public",
"function",
"setDiscriminatorAttribute",
"(",
"$",
"discriminatorAttribute",
")",
"{",
"if",
"(",
"$",
"discriminatorAttribute",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"discriminatorAttribute",
"=",
"null",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"propertyMetadata",
"as",
"$",
"attributeMapping",
")",
"{",
"if",
"(",
"$",
"discriminatorAttribute",
"===",
"$",
"attributeMapping",
"->",
"attributeName",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorAttributeConflict",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"discriminatorAttribute",
")",
";",
"}",
"}",
"$",
"this",
"->",
"discriminatorAttribute",
"=",
"$",
"discriminatorAttribute",
";",
"}"
] | Sets the discriminator attribute.
The attribute name is the the unmapped database attribute. Discriminator
values are only used to discern the hydration class and are not mapped to
class properties.
@param string $discriminatorAttribute
@throws MappingException If the discriminator attribute conflicts with the
name of a mapped attribute. | [
"Sets",
"the",
"discriminator",
"attribute",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1239-L1254 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setDiscriminatorDefaultValue | public function setDiscriminatorDefaultValue($discriminatorDefaultValue)
{
if ($discriminatorDefaultValue !== null && !array_key_exists($discriminatorDefaultValue, $this->discriminatorMap)) {
throw MappingException::invalidDiscriminatorValue($discriminatorDefaultValue, $this->name);
}
$this->discriminatorDefaultValue = $discriminatorDefaultValue;
} | php | public function setDiscriminatorDefaultValue($discriminatorDefaultValue)
{
if ($discriminatorDefaultValue !== null && !array_key_exists($discriminatorDefaultValue, $this->discriminatorMap)) {
throw MappingException::invalidDiscriminatorValue($discriminatorDefaultValue, $this->name);
}
$this->discriminatorDefaultValue = $discriminatorDefaultValue;
} | [
"public",
"function",
"setDiscriminatorDefaultValue",
"(",
"$",
"discriminatorDefaultValue",
")",
"{",
"if",
"(",
"$",
"discriminatorDefaultValue",
"!==",
"null",
"&&",
"!",
"array_key_exists",
"(",
"$",
"discriminatorDefaultValue",
",",
"$",
"this",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidDiscriminatorValue",
"(",
"$",
"discriminatorDefaultValue",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"$",
"this",
"->",
"discriminatorDefaultValue",
"=",
"$",
"discriminatorDefaultValue",
";",
"}"
] | Sets the default discriminator value to be used for this class
Used for JOINED and SINGLE_TABLE inheritance mapping strategies if the
document has no discriminator value
@param string $discriminatorDefaultValue
@throws MappingException | [
"Sets",
"the",
"default",
"discriminator",
"value",
"to",
"be",
"used",
"for",
"this",
"class",
"Used",
"for",
"JOINED",
"and",
"SINGLE_TABLE",
"inheritance",
"mapping",
"strategies",
"if",
"the",
"document",
"has",
"no",
"discriminator",
"value"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1265-L1272 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setDiscriminatorMap | public function setDiscriminatorMap(array $map)
{
foreach ($map as $value => $className) {
$this->discriminatorMap[$value] = $className;
if ($this->name == $className) {
$this->discriminatorValue = $value;
} else {
if (!class_exists($className)) {
throw MappingException::invalidClassInDiscriminatorMap($className, $this->name);
}
if (is_subclass_of($className, $this->name)) {
$this->subClassNames[] = $className;
}
}
}
} | php | public function setDiscriminatorMap(array $map)
{
foreach ($map as $value => $className) {
$this->discriminatorMap[$value] = $className;
if ($this->name == $className) {
$this->discriminatorValue = $value;
} else {
if (!class_exists($className)) {
throw MappingException::invalidClassInDiscriminatorMap($className, $this->name);
}
if (is_subclass_of($className, $this->name)) {
$this->subClassNames[] = $className;
}
}
}
} | [
"public",
"function",
"setDiscriminatorMap",
"(",
"array",
"$",
"map",
")",
"{",
"foreach",
"(",
"$",
"map",
"as",
"$",
"value",
"=>",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"discriminatorMap",
"[",
"$",
"value",
"]",
"=",
"$",
"className",
";",
"if",
"(",
"$",
"this",
"->",
"name",
"==",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"discriminatorValue",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidClassInDiscriminatorMap",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"if",
"(",
"is_subclass_of",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"$",
"this",
"->",
"subClassNames",
"[",
"]",
"=",
"$",
"className",
";",
"}",
"}",
"}",
"}"
] | Sets the discriminator values used by this class.
Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
@param array $map
@throws MappingException | [
"Sets",
"the",
"discriminator",
"values",
"used",
"by",
"this",
"class",
".",
"Used",
"for",
"JOINED",
"and",
"SINGLE_TABLE",
"inheritance",
"mapping",
"strategies",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1282-L1297 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setDiscriminatorValue | public function setDiscriminatorValue($value)
{
$this->discriminatorMap[$value] = $this->name;
$this->discriminatorValue = $value;
} | php | public function setDiscriminatorValue($value)
{
$this->discriminatorMap[$value] = $this->name;
$this->discriminatorValue = $value;
} | [
"public",
"function",
"setDiscriminatorValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"discriminatorMap",
"[",
"$",
"value",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"this",
"->",
"discriminatorValue",
"=",
"$",
"value",
";",
"}"
] | Sets the discriminator value for this class.
Used for JOINED/SINGLE_TABLE inheritance and multiple document types in
a single collection.
@param string $value | [
"Sets",
"the",
"discriminator",
"value",
"for",
"this",
"class",
".",
"Used",
"for",
"JOINED",
"/",
"SINGLE_TABLE",
"inheritance",
"and",
"multiple",
"document",
"types",
"in",
"a",
"single",
"collection",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1306-L1310 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setIndex | public function setIndex(Index $index)
{
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentsNotIndexable($this->getName());
}
if ($this->index !== null) {
throw MappingException::indexExists($this->getName(), 'primary');
}
$this->index = $index;
} | php | public function setIndex(Index $index)
{
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentsNotIndexable($this->getName());
}
if ($this->index !== null) {
throw MappingException::indexExists($this->getName(), 'primary');
}
$this->index = $index;
} | [
"public",
"function",
"setIndex",
"(",
"Index",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmbeddedDocument",
")",
"{",
"throw",
"MappingException",
"::",
"embeddedDocumentsNotIndexable",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"index",
"!==",
"null",
")",
"{",
"throw",
"MappingException",
"::",
"indexExists",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'primary'",
")",
";",
"}",
"$",
"this",
"->",
"index",
"=",
"$",
"index",
";",
"}"
] | @param Index $index
@throws MappingException | [
"@param",
"Index",
"$index"
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1317-L1328 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setLockMetadata | public function setLockMetadata(PropertyMetadata $mapping)
{
if ($mapping->type !== 'int') {
throw LockException::invalidLockAttributeType($mapping->type);
}
$this->isLockable = true;
$this->lockMetadata = $mapping;
} | php | public function setLockMetadata(PropertyMetadata $mapping)
{
if ($mapping->type !== 'int') {
throw LockException::invalidLockAttributeType($mapping->type);
}
$this->isLockable = true;
$this->lockMetadata = $mapping;
} | [
"public",
"function",
"setLockMetadata",
"(",
"PropertyMetadata",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"mapping",
"->",
"type",
"!==",
"'int'",
")",
"{",
"throw",
"LockException",
"::",
"invalidLockAttributeType",
"(",
"$",
"mapping",
"->",
"type",
")",
";",
"}",
"$",
"this",
"->",
"isLockable",
"=",
"true",
";",
"$",
"this",
"->",
"lockMetadata",
"=",
"$",
"mapping",
";",
"}"
] | Sets the version attribute mapping used for versioning. Sets the default
value to use depending on the column type.
@param PropertyMetadata $mapping The version attribute mapping array
@throws LockException | [
"Sets",
"the",
"version",
"attribute",
"mapping",
"used",
"for",
"versioning",
".",
"Sets",
"the",
"default",
"value",
"to",
"use",
"depending",
"on",
"the",
"column",
"type",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1360-L1368 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setParentClassNames | public function setParentClassNames(array $classNames)
{
$this->parentClassNames = $classNames;
if (count($classNames) > 0) {
$this->rootDocumentName = array_pop($classNames);
}
} | php | public function setParentClassNames(array $classNames)
{
$this->parentClassNames = $classNames;
if (count($classNames) > 0) {
$this->rootDocumentName = array_pop($classNames);
}
} | [
"public",
"function",
"setParentClassNames",
"(",
"array",
"$",
"classNames",
")",
"{",
"$",
"this",
"->",
"parentClassNames",
"=",
"$",
"classNames",
";",
"if",
"(",
"count",
"(",
"$",
"classNames",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"rootDocumentName",
"=",
"array_pop",
"(",
"$",
"classNames",
")",
";",
"}",
"}"
] | Sets the parent class names.
Assumes that the class names in the passed array are in the order:
directParent -> directParentParent -> directParentParentParent ... ->
root.
@param string[] $classNames | [
"Sets",
"the",
"parent",
"class",
"names",
".",
"Assumes",
"that",
"the",
"class",
"names",
"in",
"the",
"passed",
"array",
"are",
"in",
"the",
"order",
":",
"directParent",
"-",
">",
"directParentParent",
"-",
">",
"directParentParentParent",
"...",
"-",
">",
"root",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1388-L1395 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setTable | public function setTable($table)
{
if (is_array($table)) {
if (!isset($table['name'])) {
throw new \InvalidArgumentException('A name key is required when passing an array to setTable()');
}
$this->table = $table['name'];
} else {
$this->table = $table;
}
} | php | public function setTable($table)
{
if (is_array($table)) {
if (!isset($table['name'])) {
throw new \InvalidArgumentException('A name key is required when passing an array to setTable()');
}
$this->table = $table['name'];
} else {
$this->table = $table;
}
} | [
"public",
"function",
"setTable",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"table",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'A name key is required when passing an array to setTable()'",
")",
";",
"}",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"}",
"}"
] | Sets the table this document is mapped to.
@param array|string $table The table name.
@throws \InvalidArgumentException | [
"Sets",
"the",
"table",
"this",
"document",
"is",
"mapped",
"to",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1430-L1440 |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php | ClassMetadata.setVersionMapping | public function setVersionMapping(PropertyMetadata $mapping)
{
if ($mapping->type !== Type::INT && $mapping->type !== Type::DATE) {
throw LockException::invalidVersionAttributeType($mapping->type);
}
$this->isVersioned = true;
$this->versionAttribute = $mapping->name;
} | php | public function setVersionMapping(PropertyMetadata $mapping)
{
if ($mapping->type !== Type::INT && $mapping->type !== Type::DATE) {
throw LockException::invalidVersionAttributeType($mapping->type);
}
$this->isVersioned = true;
$this->versionAttribute = $mapping->name;
} | [
"public",
"function",
"setVersionMapping",
"(",
"PropertyMetadata",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"mapping",
"->",
"type",
"!==",
"Type",
"::",
"INT",
"&&",
"$",
"mapping",
"->",
"type",
"!==",
"Type",
"::",
"DATE",
")",
"{",
"throw",
"LockException",
"::",
"invalidVersionAttributeType",
"(",
"$",
"mapping",
"->",
"type",
")",
";",
"}",
"$",
"this",
"->",
"isVersioned",
"=",
"true",
";",
"$",
"this",
"->",
"versionAttribute",
"=",
"$",
"mapping",
"->",
"name",
";",
"}"
] | Sets the version attribute mapping used for versioning. Sets the default
value to use depending on the column type.
@param PropertyMetadata $mapping The version attribute mapping array
@throws LockException | [
"Sets",
"the",
"version",
"attribute",
"mapping",
"used",
"for",
"versioning",
".",
"Sets",
"the",
"default",
"value",
"to",
"use",
"depending",
"on",
"the",
"column",
"type",
"."
] | train | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/ClassMetadata.php#L1461-L1469 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.