id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
27,400
|
melisplatform/melis-core
|
src/Controller/MelisAuthController.php
|
MelisAuthController.getProfilePictureAction
|
public function getProfilePictureAction()
{
$melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');
$moduleSvc = $this->getServiceLocator()->get('ModulesService');
$user = $melisCoreAuth->getIdentity();
$imageDefault = $moduleSvc->getModulePath('MelisCore') . '/public/images/profile/default_picture.jpg';
if (!empty($user) && !empty($user->usr_image)) {
$image = $user->usr_image;
} else {
$image = file_get_contents($imageDefault);
}
$response = $this->getResponse();
$response->setContent($image);
$response->getHeaders()
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Type', 'image/jpg');
return $response;
}
|
php
|
public function getProfilePictureAction()
{
$melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');
$moduleSvc = $this->getServiceLocator()->get('ModulesService');
$user = $melisCoreAuth->getIdentity();
$imageDefault = $moduleSvc->getModulePath('MelisCore') . '/public/images/profile/default_picture.jpg';
if (!empty($user) && !empty($user->usr_image)) {
$image = $user->usr_image;
} else {
$image = file_get_contents($imageDefault);
}
$response = $this->getResponse();
$response->setContent($image);
$response->getHeaders()
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Type', 'image/jpg');
return $response;
}
|
[
"public",
"function",
"getProfilePictureAction",
"(",
")",
"{",
"$",
"melisCoreAuth",
"=",
"$",
"this",
"->",
"serviceLocator",
"->",
"get",
"(",
"'MelisCoreAuth'",
")",
";",
"$",
"moduleSvc",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ModulesService'",
")",
";",
"$",
"user",
"=",
"$",
"melisCoreAuth",
"->",
"getIdentity",
"(",
")",
";",
"$",
"imageDefault",
"=",
"$",
"moduleSvc",
"->",
"getModulePath",
"(",
"'MelisCore'",
")",
".",
"'/public/images/profile/default_picture.jpg'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
"&&",
"!",
"empty",
"(",
"$",
"user",
"->",
"usr_image",
")",
")",
"{",
"$",
"image",
"=",
"$",
"user",
"->",
"usr_image",
";",
"}",
"else",
"{",
"$",
"image",
"=",
"file_get_contents",
"(",
"$",
"imageDefault",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"image",
")",
";",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"->",
"addHeaderLine",
"(",
"'Content-Transfer-Encoding'",
",",
"'binary'",
")",
"->",
"addHeaderLine",
"(",
"'Content-Type'",
",",
"'image/jpg'",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Get the profile picture
@return \Zend\Stdlib\ResponseInterface
|
[
"Get",
"the",
"profile",
"picture"
] |
f8b0648930e21d1f2b2e5b9300781c335bd34ea4
|
https://github.com/melisplatform/melis-core/blob/f8b0648930e21d1f2b2e5b9300781c335bd34ea4/src/Controller/MelisAuthController.php#L488-L509
|
27,401
|
locomotivemtl/charcoal-app
|
src/Charcoal/App/Middleware/IpMiddleware.php
|
IpMiddleware.isIpBlacklisted
|
private function isIpBlacklisted($ip)
{
if (empty($this->blacklist)) {
return false;
}
return $this->isIpInRange($ip, $this->blacklist);
}
|
php
|
private function isIpBlacklisted($ip)
{
if (empty($this->blacklist)) {
return false;
}
return $this->isIpInRange($ip, $this->blacklist);
}
|
[
"private",
"function",
"isIpBlacklisted",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"blacklist",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"isIpInRange",
"(",
"$",
"ip",
",",
"$",
"this",
"->",
"blacklist",
")",
";",
"}"
] |
Check wether a certain IP is explicitely blacklisted.
If the blacklist is null or empty, then nothing is ever blacklisted (return false).
Note: this method only performs an exact string match on IP address, no IP masking / range features.
@param string $ip The IP address to check against the blacklist.
@return boolean
|
[
"Check",
"wether",
"a",
"certain",
"IP",
"is",
"explicitely",
"blacklisted",
"."
] |
d25bdab08d40dda83c71b770c59e3b469e0ebfbc
|
https://github.com/locomotivemtl/charcoal-app/blob/d25bdab08d40dda83c71b770c59e3b469e0ebfbc/src/Charcoal/App/Middleware/IpMiddleware.php#L137-L143
|
27,402
|
locomotivemtl/charcoal-app
|
src/Charcoal/App/Middleware/IpMiddleware.php
|
IpMiddleware.isIpWhitelisted
|
private function isIpWhitelisted($ip)
{
if (empty($this->whitelist)) {
return true;
}
return $this->isIpInRange($ip, $this->whitelist);
}
|
php
|
private function isIpWhitelisted($ip)
{
if (empty($this->whitelist)) {
return true;
}
return $this->isIpInRange($ip, $this->whitelist);
}
|
[
"private",
"function",
"isIpWhitelisted",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"whitelist",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"isIpInRange",
"(",
"$",
"ip",
",",
"$",
"this",
"->",
"whitelist",
")",
";",
"}"
] |
Check wether a certain IP is explicitely whitelisted.
If the whitelist is null or empty, then all IPs are whitelisted (return true).
Note; This method only performs an exact string match on IP address, no IP masking / range features.
@param string $ip The IP address to check against the whitelist.
@return boolean
|
[
"Check",
"wether",
"a",
"certain",
"IP",
"is",
"explicitely",
"whitelisted",
"."
] |
d25bdab08d40dda83c71b770c59e3b469e0ebfbc
|
https://github.com/locomotivemtl/charcoal-app/blob/d25bdab08d40dda83c71b770c59e3b469e0ebfbc/src/Charcoal/App/Middleware/IpMiddleware.php#L155-L161
|
27,403
|
locomotivemtl/charcoal-app
|
src/Charcoal/App/Module/AbstractModule.php
|
AbstractModule.config
|
public function config($key = null)
{
if ($this->config === null) {
throw new InvalidArgumentException(
'Configuration not set.'
);
}
if ($key !== null) {
return $this->config->get($key);
} else {
return $this->config;
}
}
|
php
|
public function config($key = null)
{
if ($this->config === null) {
throw new InvalidArgumentException(
'Configuration not set.'
);
}
if ($key !== null) {
return $this->config->get($key);
} else {
return $this->config;
}
}
|
[
"public",
"function",
"config",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Configuration not set.'",
")",
";",
"}",
"if",
"(",
"$",
"key",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"config",
";",
"}",
"}"
] |
Retrieve the module's configuration container, or one of its entry.
If a key is provided, return the configuration key value instead of the full object.
@param string $key Optional. If provided, the config key value will be returned, instead of the full object.
@throws InvalidArgumentException If a config has not been defined.
@return \Charcoal\Config\ConfigInterface|mixed
|
[
"Retrieve",
"the",
"module",
"s",
"configuration",
"container",
"or",
"one",
"of",
"its",
"entry",
"."
] |
d25bdab08d40dda83c71b770c59e3b469e0ebfbc
|
https://github.com/locomotivemtl/charcoal-app/blob/d25bdab08d40dda83c71b770c59e3b469e0ebfbc/src/Charcoal/App/Module/AbstractModule.php#L77-L90
|
27,404
|
locomotivemtl/charcoal-app
|
src/Charcoal/App/Module/AbstractModule.php
|
AbstractModule.setupRoutes
|
public function setupRoutes()
{
if (!isset($this->routeManager)) {
$config = $this->config();
$routes = (isset($config['routes']) ? $config['routes'] : [] );
$this->routeManager = new RouteManager([
'config' => $routes,
'app' => $this->app(),
'logger' => $this->logger
]);
$this->routeManager->setupRoutes();
}
return $this;
}
|
php
|
public function setupRoutes()
{
if (!isset($this->routeManager)) {
$config = $this->config();
$routes = (isset($config['routes']) ? $config['routes'] : [] );
$this->routeManager = new RouteManager([
'config' => $routes,
'app' => $this->app(),
'logger' => $this->logger
]);
$this->routeManager->setupRoutes();
}
return $this;
}
|
[
"public",
"function",
"setupRoutes",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"routeManager",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
")",
";",
"$",
"routes",
"=",
"(",
"isset",
"(",
"$",
"config",
"[",
"'routes'",
"]",
")",
"?",
"$",
"config",
"[",
"'routes'",
"]",
":",
"[",
"]",
")",
";",
"$",
"this",
"->",
"routeManager",
"=",
"new",
"RouteManager",
"(",
"[",
"'config'",
"=>",
"$",
"routes",
",",
"'app'",
"=>",
"$",
"this",
"->",
"app",
"(",
")",
",",
"'logger'",
"=>",
"$",
"this",
"->",
"logger",
"]",
")",
";",
"$",
"this",
"->",
"routeManager",
"->",
"setupRoutes",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set up the module's routes, via a RouteManager
@return self
|
[
"Set",
"up",
"the",
"module",
"s",
"routes",
"via",
"a",
"RouteManager"
] |
d25bdab08d40dda83c71b770c59e3b469e0ebfbc
|
https://github.com/locomotivemtl/charcoal-app/blob/d25bdab08d40dda83c71b770c59e3b469e0ebfbc/src/Charcoal/App/Module/AbstractModule.php#L109-L125
|
27,405
|
locomotivemtl/charcoal-app
|
src/Charcoal/App/Route/TemplateRouteConfig.php
|
TemplateRouteConfig.setTemplateData
|
public function setTemplateData(array $templateData)
{
if (!isset($this->templateData)) {
$this->templateData = [];
}
$this->templateData = array_merge($this->templateData, $templateData);
return $this;
}
|
php
|
public function setTemplateData(array $templateData)
{
if (!isset($this->templateData)) {
$this->templateData = [];
}
$this->templateData = array_merge($this->templateData, $templateData);
return $this;
}
|
[
"public",
"function",
"setTemplateData",
"(",
"array",
"$",
"templateData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templateData",
")",
")",
"{",
"$",
"this",
"->",
"templateData",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"templateData",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"templateData",
",",
"$",
"templateData",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the template data for the view.
@param array $templateData The route template data.
@return TemplateRouteConfig Chainable
|
[
"Set",
"the",
"template",
"data",
"for",
"the",
"view",
"."
] |
d25bdab08d40dda83c71b770c59e3b469e0ebfbc
|
https://github.com/locomotivemtl/charcoal-app/blob/d25bdab08d40dda83c71b770c59e3b469e0ebfbc/src/Charcoal/App/Route/TemplateRouteConfig.php#L161-L170
|
27,406
|
Magicalex/WriteiniFile
|
src/WriteiniFile.php
|
WriteiniFile.rm
|
public function rm(array $rm_value)
{
$this->data_ini_file = self::arrayDiffRecursive($this->data_ini_file, $rm_value);
return $this;
}
|
php
|
public function rm(array $rm_value)
{
$this->data_ini_file = self::arrayDiffRecursive($this->data_ini_file, $rm_value);
return $this;
}
|
[
"public",
"function",
"rm",
"(",
"array",
"$",
"rm_value",
")",
"{",
"$",
"this",
"->",
"data_ini_file",
"=",
"self",
"::",
"arrayDiffRecursive",
"(",
"$",
"this",
"->",
"data_ini_file",
",",
"$",
"rm_value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
method for remove some values in the ini file.
@param array $rm_value
@return $this
|
[
"method",
"for",
"remove",
"some",
"values",
"in",
"the",
"ini",
"file",
"."
] |
19fe9bd3041219fecdd63e1f0ae14f86cb6800cb
|
https://github.com/Magicalex/WriteiniFile/blob/19fe9bd3041219fecdd63e1f0ae14f86cb6800cb/src/WriteiniFile.php#L102-L107
|
27,407
|
Magicalex/WriteiniFile
|
src/WriteiniFile.php
|
WriteiniFile.write
|
public function write()
{
$file_content = null;
foreach ($this->data_ini_file as $key_1 => $groupe) {
$file_content .= PHP_EOL.'['.$key_1.']'.PHP_EOL;
foreach ($groupe as $key_2 => $value_2) {
if (is_array($value_2)) {
foreach ($value_2 as $key_3 => $value_3) {
$file_content .= $key_2.'['.$key_3.']='.self::encode($value_3).PHP_EOL;
}
} else {
$file_content .= $key_2.'='.self::encode($value_2).PHP_EOL;
}
}
}
$file_content = preg_replace('#^'.PHP_EOL.'#', '', $file_content);
$result = @file_put_contents($this->path_to_ini_file, $file_content);
if (false === $result) {
throw new \Exception(sprintf('Unable to write in the file ini: %s', $this->path_to_ini_file));
}
return ($result !== false) ? true : false;
}
|
php
|
public function write()
{
$file_content = null;
foreach ($this->data_ini_file as $key_1 => $groupe) {
$file_content .= PHP_EOL.'['.$key_1.']'.PHP_EOL;
foreach ($groupe as $key_2 => $value_2) {
if (is_array($value_2)) {
foreach ($value_2 as $key_3 => $value_3) {
$file_content .= $key_2.'['.$key_3.']='.self::encode($value_3).PHP_EOL;
}
} else {
$file_content .= $key_2.'='.self::encode($value_2).PHP_EOL;
}
}
}
$file_content = preg_replace('#^'.PHP_EOL.'#', '', $file_content);
$result = @file_put_contents($this->path_to_ini_file, $file_content);
if (false === $result) {
throw new \Exception(sprintf('Unable to write in the file ini: %s', $this->path_to_ini_file));
}
return ($result !== false) ? true : false;
}
|
[
"public",
"function",
"write",
"(",
")",
"{",
"$",
"file_content",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"data_ini_file",
"as",
"$",
"key_1",
"=>",
"$",
"groupe",
")",
"{",
"$",
"file_content",
".=",
"PHP_EOL",
".",
"'['",
".",
"$",
"key_1",
".",
"']'",
".",
"PHP_EOL",
";",
"foreach",
"(",
"$",
"groupe",
"as",
"$",
"key_2",
"=>",
"$",
"value_2",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value_2",
")",
")",
"{",
"foreach",
"(",
"$",
"value_2",
"as",
"$",
"key_3",
"=>",
"$",
"value_3",
")",
"{",
"$",
"file_content",
".=",
"$",
"key_2",
".",
"'['",
".",
"$",
"key_3",
".",
"']='",
".",
"self",
"::",
"encode",
"(",
"$",
"value_3",
")",
".",
"PHP_EOL",
";",
"}",
"}",
"else",
"{",
"$",
"file_content",
".=",
"$",
"key_2",
".",
"'='",
".",
"self",
"::",
"encode",
"(",
"$",
"value_2",
")",
".",
"PHP_EOL",
";",
"}",
"}",
"}",
"$",
"file_content",
"=",
"preg_replace",
"(",
"'#^'",
".",
"PHP_EOL",
".",
"'#'",
",",
"''",
",",
"$",
"file_content",
")",
";",
"$",
"result",
"=",
"@",
"file_put_contents",
"(",
"$",
"this",
"->",
"path_to_ini_file",
",",
"$",
"file_content",
")",
";",
"if",
"(",
"false",
"===",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to write in the file ini: %s'",
",",
"$",
"this",
"->",
"path_to_ini_file",
")",
")",
";",
"}",
"return",
"(",
"$",
"result",
"!==",
"false",
")",
"?",
"true",
":",
"false",
";",
"}"
] |
method for write data in the ini file.
@return bool
|
[
"method",
"for",
"write",
"data",
"in",
"the",
"ini",
"file",
"."
] |
19fe9bd3041219fecdd63e1f0ae14f86cb6800cb
|
https://github.com/Magicalex/WriteiniFile/blob/19fe9bd3041219fecdd63e1f0ae14f86cb6800cb/src/WriteiniFile.php#L114-L138
|
27,408
|
UseMuffin/Tokenize
|
src/Model/Entity/Token.php
|
Token.random
|
public static function random($length = null)
{
if ($length === null) {
$length = Configure::read('Muffin/Tokenize.length', self::DEFAULT_LENGTH);
}
return bin2hex(Security::randomBytes($length / 2));
}
|
php
|
public static function random($length = null)
{
if ($length === null) {
$length = Configure::read('Muffin/Tokenize.length', self::DEFAULT_LENGTH);
}
return bin2hex(Security::randomBytes($length / 2));
}
|
[
"public",
"static",
"function",
"random",
"(",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"$",
"length",
"=",
"Configure",
"::",
"read",
"(",
"'Muffin/Tokenize.length'",
",",
"self",
"::",
"DEFAULT_LENGTH",
")",
";",
"}",
"return",
"bin2hex",
"(",
"Security",
"::",
"randomBytes",
"(",
"$",
"length",
"/",
"2",
")",
")",
";",
"}"
] |
Creates a secure random token.
@param int|null $length Token length
@return string
@see http://stackoverflow.com/a/29137661/2020428
|
[
"Creates",
"a",
"secure",
"random",
"token",
"."
] |
a7ecf4114782abe12b0ab36e8a32504428fe91ec
|
https://github.com/UseMuffin/Tokenize/blob/a7ecf4114782abe12b0ab36e8a32504428fe91ec/src/Model/Entity/Token.php#L49-L56
|
27,409
|
flash-global/api-client
|
src/AbstractApiClient.php
|
AbstractApiClient.getAppropriateTransport
|
protected function getAppropriateTransport($flags)
{
if ($flags & ApiRequestOption::NO_RESPONSE) {
$transport = $this->getAsyncTransport();
if (is_null($transport)) {
$transport = $this->getTransport();
} else {
$fallback = $this->getTransport();
if ($fallback) {
$this->setFallbackTransport($fallback);
}
}
} else {
$transport = $this->getTransport();
}
return $transport;
}
|
php
|
protected function getAppropriateTransport($flags)
{
if ($flags & ApiRequestOption::NO_RESPONSE) {
$transport = $this->getAsyncTransport();
if (is_null($transport)) {
$transport = $this->getTransport();
} else {
$fallback = $this->getTransport();
if ($fallback) {
$this->setFallbackTransport($fallback);
}
}
} else {
$transport = $this->getTransport();
}
return $transport;
}
|
[
"protected",
"function",
"getAppropriateTransport",
"(",
"$",
"flags",
")",
"{",
"if",
"(",
"$",
"flags",
"&",
"ApiRequestOption",
"::",
"NO_RESPONSE",
")",
"{",
"$",
"transport",
"=",
"$",
"this",
"->",
"getAsyncTransport",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"transport",
")",
")",
"{",
"$",
"transport",
"=",
"$",
"this",
"->",
"getTransport",
"(",
")",
";",
"}",
"else",
"{",
"$",
"fallback",
"=",
"$",
"this",
"->",
"getTransport",
"(",
")",
";",
"if",
"(",
"$",
"fallback",
")",
"{",
"$",
"this",
"->",
"setFallbackTransport",
"(",
"$",
"fallback",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"transport",
"=",
"$",
"this",
"->",
"getTransport",
"(",
")",
";",
"}",
"return",
"$",
"transport",
";",
"}"
] |
Returns the most appropriate transport according to request flags
@param $flags
@return AsyncTransportInterface|TransportInterface
|
[
"Returns",
"the",
"most",
"appropriate",
"transport",
"according",
"to",
"request",
"flags"
] |
5e54dea5c37ef7b5736d46f9997ea6c245c4949f
|
https://github.com/flash-global/api-client/blob/5e54dea5c37ef7b5736d46f9997ea6c245c4949f/src/AbstractApiClient.php#L380-L397
|
27,410
|
flash-global/api-client
|
src/ApiClientException.php
|
ApiClientException.getRequestException
|
public function getRequestException()
{
if (!is_null($this->requestException)) {
return $this->requestException;
}
$search = function (\Exception $exception = null) use (&$search) {
$previous = $exception->getPrevious();
if (is_null($previous)) {
return null;
}
if ($previous instanceof RequestException) {
return $this->requestException = $previous;
}
return $search($previous);
};
return $search($this);
}
|
php
|
public function getRequestException()
{
if (!is_null($this->requestException)) {
return $this->requestException;
}
$search = function (\Exception $exception = null) use (&$search) {
$previous = $exception->getPrevious();
if (is_null($previous)) {
return null;
}
if ($previous instanceof RequestException) {
return $this->requestException = $previous;
}
return $search($previous);
};
return $search($this);
}
|
[
"public",
"function",
"getRequestException",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"requestException",
")",
")",
"{",
"return",
"$",
"this",
"->",
"requestException",
";",
"}",
"$",
"search",
"=",
"function",
"(",
"\\",
"Exception",
"$",
"exception",
"=",
"null",
")",
"use",
"(",
"&",
"$",
"search",
")",
"{",
"$",
"previous",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"previous",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"previous",
"instanceof",
"RequestException",
")",
"{",
"return",
"$",
"this",
"->",
"requestException",
"=",
"$",
"previous",
";",
"}",
"return",
"$",
"search",
"(",
"$",
"previous",
")",
";",
"}",
";",
"return",
"$",
"search",
"(",
"$",
"this",
")",
";",
"}"
] |
Return the response body of the exception
@return null|RequestException
|
[
"Return",
"the",
"response",
"body",
"of",
"the",
"exception"
] |
5e54dea5c37ef7b5736d46f9997ea6c245c4949f
|
https://github.com/flash-global/api-client/blob/5e54dea5c37ef7b5736d46f9997ea6c245c4949f/src/ApiClientException.php#L23-L44
|
27,411
|
n2n/n2n
|
src/app/n2n/core/err/ThrowableInfoFactory.php
|
ThrowableInfoFactory.findCallPos
|
public static function findCallPos(\Throwable $t, string &$filePath = null, int &$lineNo = null) {
if (!($t instanceof \TypeError || $t instanceof WarningError || $t instanceof RecoverableError)) {
return;
}
$message = $t->getMessage();
if (false !== strpos($message, '{closure}')) {
return;
}
$fmatches = array();
$lmatches = array();
if (preg_match('/(?<=called in )[^ \(]+/', $message, $fmatches)
&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
$filePath = $fmatches[0];
$lineNo = $lmatches[0];
}
$fmatches = array();
$lmatches = array();
if (preg_match('/(?<=passed in )[^ \(]+/', $message, $fmatches)
&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
$filePath = $fmatches[0];
$lineNo = $lmatches[0];
}
}
|
php
|
public static function findCallPos(\Throwable $t, string &$filePath = null, int &$lineNo = null) {
if (!($t instanceof \TypeError || $t instanceof WarningError || $t instanceof RecoverableError)) {
return;
}
$message = $t->getMessage();
if (false !== strpos($message, '{closure}')) {
return;
}
$fmatches = array();
$lmatches = array();
if (preg_match('/(?<=called in )[^ \(]+/', $message, $fmatches)
&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
$filePath = $fmatches[0];
$lineNo = $lmatches[0];
}
$fmatches = array();
$lmatches = array();
if (preg_match('/(?<=passed in )[^ \(]+/', $message, $fmatches)
&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
$filePath = $fmatches[0];
$lineNo = $lmatches[0];
}
}
|
[
"public",
"static",
"function",
"findCallPos",
"(",
"\\",
"Throwable",
"$",
"t",
",",
"string",
"&",
"$",
"filePath",
"=",
"null",
",",
"int",
"&",
"$",
"lineNo",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"t",
"instanceof",
"\\",
"TypeError",
"||",
"$",
"t",
"instanceof",
"WarningError",
"||",
"$",
"t",
"instanceof",
"RecoverableError",
")",
")",
"{",
"return",
";",
"}",
"$",
"message",
"=",
"$",
"t",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"message",
",",
"'{closure}'",
")",
")",
"{",
"return",
";",
"}",
"$",
"fmatches",
"=",
"array",
"(",
")",
";",
"$",
"lmatches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(?<=called in )[^ \\(]+/'",
",",
"$",
"message",
",",
"$",
"fmatches",
")",
"&&",
"preg_match",
"(",
"'/((?<=on line )|(?<=\\())[0-9]+/'",
",",
"$",
"message",
",",
"$",
"lmatches",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fmatches",
"[",
"0",
"]",
";",
"$",
"lineNo",
"=",
"$",
"lmatches",
"[",
"0",
"]",
";",
"}",
"$",
"fmatches",
"=",
"array",
"(",
")",
";",
"$",
"lmatches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(?<=passed in )[^ \\(]+/'",
",",
"$",
"message",
",",
"$",
"fmatches",
")",
"&&",
"preg_match",
"(",
"'/((?<=on line )|(?<=\\())[0-9]+/'",
",",
"$",
"message",
",",
"$",
"lmatches",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fmatches",
"[",
"0",
"]",
";",
"$",
"lineNo",
"=",
"$",
"lmatches",
"[",
"0",
"]",
";",
"}",
"}"
] |
Makes error infos more user friendly
@param string $errmsg;
@param string $filePath
@param string $lineNo
|
[
"Makes",
"error",
"infos",
"more",
"user",
"friendly"
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ThrowableInfoFactory.php#L73-L98
|
27,412
|
thebuggenie/b2db
|
src/Core.php
|
Core.initialize
|
public static function initialize($configuration = array(), $cache_object = null)
{
try {
if (array_key_exists('dsn', $configuration) && $configuration['dsn'])
self::setDSN($configuration['dsn']);
if (array_key_exists('driver', $configuration) && $configuration['driver'])
self::setDriver($configuration['driver']);
if (array_key_exists('hostname', $configuration) && $configuration['hostname'])
self::setHostname($configuration['hostname']);
if (array_key_exists('port', $configuration) && $configuration['port'])
self::setPort($configuration['port']);
if (array_key_exists('username', $configuration) && $configuration['username'])
self::setUsername($configuration['username']);
if (array_key_exists('password', $configuration) && $configuration['password'])
self::setPassword($configuration['password']);
if (array_key_exists('database', $configuration) && $configuration['database'])
self::setDatabaseName($configuration['database']);
if (array_key_exists('tableprefix', $configuration) && $configuration['tableprefix'])
self::setTablePrefix($configuration['tableprefix']);
if (array_key_exists('debug', $configuration))
self::setDebugMode((bool) $configuration['debug']);
if (array_key_exists('caching', $configuration))
self::setCacheEntities((bool) $configuration['caching']);
if ($cache_object !== null) {
if (is_callable($cache_object)) {
self::$cache_object = call_user_func($cache_object);
} else {
self::$cache_object = $cache_object;
}
}
if (!self::$cache_object) {
self::$cache_object = new Cache(Cache::TYPE_DUMMY);
self::$cache_object->disable();
}
} catch (\Exception $e) {
throw $e;
}
}
|
php
|
public static function initialize($configuration = array(), $cache_object = null)
{
try {
if (array_key_exists('dsn', $configuration) && $configuration['dsn'])
self::setDSN($configuration['dsn']);
if (array_key_exists('driver', $configuration) && $configuration['driver'])
self::setDriver($configuration['driver']);
if (array_key_exists('hostname', $configuration) && $configuration['hostname'])
self::setHostname($configuration['hostname']);
if (array_key_exists('port', $configuration) && $configuration['port'])
self::setPort($configuration['port']);
if (array_key_exists('username', $configuration) && $configuration['username'])
self::setUsername($configuration['username']);
if (array_key_exists('password', $configuration) && $configuration['password'])
self::setPassword($configuration['password']);
if (array_key_exists('database', $configuration) && $configuration['database'])
self::setDatabaseName($configuration['database']);
if (array_key_exists('tableprefix', $configuration) && $configuration['tableprefix'])
self::setTablePrefix($configuration['tableprefix']);
if (array_key_exists('debug', $configuration))
self::setDebugMode((bool) $configuration['debug']);
if (array_key_exists('caching', $configuration))
self::setCacheEntities((bool) $configuration['caching']);
if ($cache_object !== null) {
if (is_callable($cache_object)) {
self::$cache_object = call_user_func($cache_object);
} else {
self::$cache_object = $cache_object;
}
}
if (!self::$cache_object) {
self::$cache_object = new Cache(Cache::TYPE_DUMMY);
self::$cache_object->disable();
}
} catch (\Exception $e) {
throw $e;
}
}
|
[
"public",
"static",
"function",
"initialize",
"(",
"$",
"configuration",
"=",
"array",
"(",
")",
",",
"$",
"cache_object",
"=",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"array_key_exists",
"(",
"'dsn'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'dsn'",
"]",
")",
"self",
"::",
"setDSN",
"(",
"$",
"configuration",
"[",
"'dsn'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'driver'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'driver'",
"]",
")",
"self",
"::",
"setDriver",
"(",
"$",
"configuration",
"[",
"'driver'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'hostname'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'hostname'",
"]",
")",
"self",
"::",
"setHostname",
"(",
"$",
"configuration",
"[",
"'hostname'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'port'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'port'",
"]",
")",
"self",
"::",
"setPort",
"(",
"$",
"configuration",
"[",
"'port'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'username'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'username'",
"]",
")",
"self",
"::",
"setUsername",
"(",
"$",
"configuration",
"[",
"'username'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'password'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'password'",
"]",
")",
"self",
"::",
"setPassword",
"(",
"$",
"configuration",
"[",
"'password'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'database'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'database'",
"]",
")",
"self",
"::",
"setDatabaseName",
"(",
"$",
"configuration",
"[",
"'database'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'tableprefix'",
",",
"$",
"configuration",
")",
"&&",
"$",
"configuration",
"[",
"'tableprefix'",
"]",
")",
"self",
"::",
"setTablePrefix",
"(",
"$",
"configuration",
"[",
"'tableprefix'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'debug'",
",",
"$",
"configuration",
")",
")",
"self",
"::",
"setDebugMode",
"(",
"(",
"bool",
")",
"$",
"configuration",
"[",
"'debug'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'caching'",
",",
"$",
"configuration",
")",
")",
"self",
"::",
"setCacheEntities",
"(",
"(",
"bool",
")",
"$",
"configuration",
"[",
"'caching'",
"]",
")",
";",
"if",
"(",
"$",
"cache_object",
"!==",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"cache_object",
")",
")",
"{",
"self",
"::",
"$",
"cache_object",
"=",
"call_user_func",
"(",
"$",
"cache_object",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"cache_object",
"=",
"$",
"cache_object",
";",
"}",
"}",
"if",
"(",
"!",
"self",
"::",
"$",
"cache_object",
")",
"{",
"self",
"::",
"$",
"cache_object",
"=",
"new",
"Cache",
"(",
"Cache",
"::",
"TYPE_DUMMY",
")",
";",
"self",
"::",
"$",
"cache_object",
"->",
"disable",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Initialize B2DB and load related B2DB classes
@param array $configuration [optional] Configuration to load
@param \b2db\interfaces\Cache $cache_object
|
[
"Initialize",
"B2DB",
"and",
"load",
"related",
"B2DB",
"classes"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L147-L186
|
27,413
|
thebuggenie/b2db
|
src/Core.php
|
Core.saveConnectionParameters
|
public static function saveConnectionParameters($bootstrap_location)
{
$string = "b2db:\n";
$string .= " driver: " . self::getDriver() . "\n";
$string .= " username: " . self::getUsername() . "\n";
$string .= " password: \"" . self::getPassword() . "\"\n";
$string .= ' dsn: "' . self::getDSN() . "\"\n";
$string .= " tableprefix: '" . self::getTablePrefix() . "'\n";
$string .= "\n";
try {
if (file_put_contents($bootstrap_location, $string) === false) {
throw new Exception('Could not save the database connection details');
}
} catch (\Exception $e) {
throw $e;
}
}
|
php
|
public static function saveConnectionParameters($bootstrap_location)
{
$string = "b2db:\n";
$string .= " driver: " . self::getDriver() . "\n";
$string .= " username: " . self::getUsername() . "\n";
$string .= " password: \"" . self::getPassword() . "\"\n";
$string .= ' dsn: "' . self::getDSN() . "\"\n";
$string .= " tableprefix: '" . self::getTablePrefix() . "'\n";
$string .= "\n";
try {
if (file_put_contents($bootstrap_location, $string) === false) {
throw new Exception('Could not save the database connection details');
}
} catch (\Exception $e) {
throw $e;
}
}
|
[
"public",
"static",
"function",
"saveConnectionParameters",
"(",
"$",
"bootstrap_location",
")",
"{",
"$",
"string",
"=",
"\"b2db:\\n\"",
";",
"$",
"string",
".=",
"\" driver: \"",
".",
"self",
"::",
"getDriver",
"(",
")",
".",
"\"\\n\"",
";",
"$",
"string",
".=",
"\" username: \"",
".",
"self",
"::",
"getUsername",
"(",
")",
".",
"\"\\n\"",
";",
"$",
"string",
".=",
"\" password: \\\"\"",
".",
"self",
"::",
"getPassword",
"(",
")",
".",
"\"\\\"\\n\"",
";",
"$",
"string",
".=",
"' dsn: \"'",
".",
"self",
"::",
"getDSN",
"(",
")",
".",
"\"\\\"\\n\"",
";",
"$",
"string",
".=",
"\" tableprefix: '\"",
".",
"self",
"::",
"getTablePrefix",
"(",
")",
".",
"\"'\\n\"",
";",
"$",
"string",
".=",
"\"\\n\"",
";",
"try",
"{",
"if",
"(",
"file_put_contents",
"(",
"$",
"bootstrap_location",
",",
"$",
"string",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Could not save the database connection details'",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Store connection parameters
@param string $bootstrap_location Where to save the connection parameters
|
[
"Store",
"connection",
"parameters"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L203-L219
|
27,414
|
thebuggenie/b2db
|
src/Core.php
|
Core.getTable
|
public static function getTable($table_name)
{
if (!isset(self::$tables[$table_name])) {
self::loadNewTable(new $table_name());
}
if (!isset(self::$tables[$table_name])) {
throw new Exception('Table ' . $table_name . ' is not loaded');
}
return self::$tables[$table_name];
}
|
php
|
public static function getTable($table_name)
{
if (!isset(self::$tables[$table_name])) {
self::loadNewTable(new $table_name());
}
if (!isset(self::$tables[$table_name])) {
throw new Exception('Table ' . $table_name . ' is not loaded');
}
return self::$tables[$table_name];
}
|
[
"public",
"static",
"function",
"getTable",
"(",
"$",
"table_name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"tables",
"[",
"$",
"table_name",
"]",
")",
")",
"{",
"self",
"::",
"loadNewTable",
"(",
"new",
"$",
"table_name",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"tables",
"[",
"$",
"table_name",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Table '",
".",
"$",
"table_name",
".",
"' is not loaded'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"tables",
"[",
"$",
"table_name",
"]",
";",
"}"
] |
Returns the Table object
@param string $table_name The table class name to load
@return Table
|
[
"Returns",
"the",
"Table",
"object"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L228-L237
|
27,415
|
thebuggenie/b2db
|
src/Core.php
|
Core.simpleQuery
|
public static function simpleQuery($sql)
{
self::$sql_hits++;
try {
$res = self::getDBLink()->query($sql);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
return $res;
}
|
php
|
public static function simpleQuery($sql)
{
self::$sql_hits++;
try {
$res = self::getDBLink()->query($sql);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
return $res;
}
|
[
"public",
"static",
"function",
"simpleQuery",
"(",
"$",
"sql",
")",
"{",
"self",
"::",
"$",
"sql_hits",
"++",
";",
"try",
"{",
"$",
"res",
"=",
"self",
"::",
"getDBLink",
"(",
")",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
returns a PDO resultset
@param string $sql
@return \PDOStatement
|
[
"returns",
"a",
"PDO",
"resultset"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L373-L382
|
27,416
|
thebuggenie/b2db
|
src/Core.php
|
Core.setDSN
|
public static function setDSN($dsn)
{
$dsn_details = parse_url($dsn);
if (!is_array($dsn_details) || !array_key_exists('scheme', $dsn_details)) {
throw new Exception('This does not look like a valid DSN - cannot read the database type');
}
try {
self::setDriver($dsn_details['scheme']);
$details = explode(';', $dsn_details['path']);
foreach ($details as $detail) {
$detail_info = explode('=', $detail);
if (count($detail_info) != 2) {
throw new Exception('This does not look like a valid DSN - cannot read the connection details');
}
switch ($detail_info[0]) {
case 'host':
self::setHostname($detail_info[1]);
break;
case 'port':
self::setPort($detail_info[1]);
break;
case 'dbname':
self::setDatabaseName($detail_info[1]);
break;
}
}
} catch (\Exception $e) {
throw $e;
}
self::$dsn = $dsn;
}
|
php
|
public static function setDSN($dsn)
{
$dsn_details = parse_url($dsn);
if (!is_array($dsn_details) || !array_key_exists('scheme', $dsn_details)) {
throw new Exception('This does not look like a valid DSN - cannot read the database type');
}
try {
self::setDriver($dsn_details['scheme']);
$details = explode(';', $dsn_details['path']);
foreach ($details as $detail) {
$detail_info = explode('=', $detail);
if (count($detail_info) != 2) {
throw new Exception('This does not look like a valid DSN - cannot read the connection details');
}
switch ($detail_info[0]) {
case 'host':
self::setHostname($detail_info[1]);
break;
case 'port':
self::setPort($detail_info[1]);
break;
case 'dbname':
self::setDatabaseName($detail_info[1]);
break;
}
}
} catch (\Exception $e) {
throw $e;
}
self::$dsn = $dsn;
}
|
[
"public",
"static",
"function",
"setDSN",
"(",
"$",
"dsn",
")",
"{",
"$",
"dsn_details",
"=",
"parse_url",
"(",
"$",
"dsn",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dsn_details",
")",
"||",
"!",
"array_key_exists",
"(",
"'scheme'",
",",
"$",
"dsn_details",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'This does not look like a valid DSN - cannot read the database type'",
")",
";",
"}",
"try",
"{",
"self",
"::",
"setDriver",
"(",
"$",
"dsn_details",
"[",
"'scheme'",
"]",
")",
";",
"$",
"details",
"=",
"explode",
"(",
"';'",
",",
"$",
"dsn_details",
"[",
"'path'",
"]",
")",
";",
"foreach",
"(",
"$",
"details",
"as",
"$",
"detail",
")",
"{",
"$",
"detail_info",
"=",
"explode",
"(",
"'='",
",",
"$",
"detail",
")",
";",
"if",
"(",
"count",
"(",
"$",
"detail_info",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'This does not look like a valid DSN - cannot read the connection details'",
")",
";",
"}",
"switch",
"(",
"$",
"detail_info",
"[",
"0",
"]",
")",
"{",
"case",
"'host'",
":",
"self",
"::",
"setHostname",
"(",
"$",
"detail_info",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"'port'",
":",
"self",
"::",
"setPort",
"(",
"$",
"detail_info",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"'dbname'",
":",
"self",
"::",
"setDatabaseName",
"(",
"$",
"detail_info",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"self",
"::",
"$",
"dsn",
"=",
"$",
"dsn",
";",
"}"
] |
Set the DSN
@param string $dsn
|
[
"Set",
"the",
"DSN"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L389-L419
|
27,417
|
thebuggenie/b2db
|
src/Core.php
|
Core.generateDSN
|
protected static function generateDSN()
{
$dsn = self::getDriver() . ":host=" . self::getHostname();
if (self::getPort()) {
$dsn .= ';port=' . self::getPort();
}
$dsn .= ';dbname=' . self::getDatabaseName();
self::$dsn = $dsn;
}
|
php
|
protected static function generateDSN()
{
$dsn = self::getDriver() . ":host=" . self::getHostname();
if (self::getPort()) {
$dsn .= ';port=' . self::getPort();
}
$dsn .= ';dbname=' . self::getDatabaseName();
self::$dsn = $dsn;
}
|
[
"protected",
"static",
"function",
"generateDSN",
"(",
")",
"{",
"$",
"dsn",
"=",
"self",
"::",
"getDriver",
"(",
")",
".",
"\":host=\"",
".",
"self",
"::",
"getHostname",
"(",
")",
";",
"if",
"(",
"self",
"::",
"getPort",
"(",
")",
")",
"{",
"$",
"dsn",
".=",
"';port='",
".",
"self",
"::",
"getPort",
"(",
")",
";",
"}",
"$",
"dsn",
".=",
"';dbname='",
".",
"self",
"::",
"getDatabaseName",
"(",
")",
";",
"self",
"::",
"$",
"dsn",
"=",
"$",
"dsn",
";",
"}"
] |
Generate the DSN when needed
|
[
"Generate",
"the",
"DSN",
"when",
"needed"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L424-L432
|
27,418
|
thebuggenie/b2db
|
src/Core.php
|
Core.setDriver
|
public static function setDriver($driver)
{
if (self::isDriverSupported($driver) == false) {
throw new Exception('The selected database is not supported: "' . $driver . '".');
}
self::$driver = $driver;
}
|
php
|
public static function setDriver($driver)
{
if (self::isDriverSupported($driver) == false) {
throw new Exception('The selected database is not supported: "' . $driver . '".');
}
self::$driver = $driver;
}
|
[
"public",
"static",
"function",
"setDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"self",
"::",
"isDriverSupported",
"(",
"$",
"driver",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The selected database is not supported: \"'",
".",
"$",
"driver",
".",
"'\".'",
")",
";",
"}",
"self",
"::",
"$",
"driver",
"=",
"$",
"driver",
";",
"}"
] |
Set the database type
@param string $driver
|
[
"Set",
"the",
"database",
"type"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L573-L579
|
27,419
|
thebuggenie/b2db
|
src/Core.php
|
Core.doConnect
|
public static function doConnect()
{
if (!\class_exists('\\PDO')) {
throw new Exception('B2DB needs the PDO PHP libraries installed. See http://php.net/PDO for more information.');
}
try {
$uname = self::getUsername();
$pwd = self::getPassword();
$dsn = self::getDSN();
if (self::$db_connection instanceof PDO) {
self::$db_connection = null;
}
self::$db_connection = new PDO($dsn, $uname, $pwd);
if (!self::$db_connection instanceof PDO) {
throw new Exception('Could not connect to the database, but not caught by PDO');
}
switch (self::getDriver())
{
case self::DRIVER_MYSQL:
self::getDBLink()->query('SET NAMES UTF8');
break;
case self::DRIVER_POSTGRES:
self::getDBlink()->query('set client_encoding to UTF8');
break;
}
} catch (PDOException $e) {
throw new Exception("Could not connect to the database [" . $e->getMessage() . "], dsn: ".self::getDSN());
} catch (Exception $e) {
throw $e;
}
}
|
php
|
public static function doConnect()
{
if (!\class_exists('\\PDO')) {
throw new Exception('B2DB needs the PDO PHP libraries installed. See http://php.net/PDO for more information.');
}
try {
$uname = self::getUsername();
$pwd = self::getPassword();
$dsn = self::getDSN();
if (self::$db_connection instanceof PDO) {
self::$db_connection = null;
}
self::$db_connection = new PDO($dsn, $uname, $pwd);
if (!self::$db_connection instanceof PDO) {
throw new Exception('Could not connect to the database, but not caught by PDO');
}
switch (self::getDriver())
{
case self::DRIVER_MYSQL:
self::getDBLink()->query('SET NAMES UTF8');
break;
case self::DRIVER_POSTGRES:
self::getDBlink()->query('set client_encoding to UTF8');
break;
}
} catch (PDOException $e) {
throw new Exception("Could not connect to the database [" . $e->getMessage() . "], dsn: ".self::getDSN());
} catch (Exception $e) {
throw $e;
}
}
|
[
"public",
"static",
"function",
"doConnect",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"class_exists",
"(",
"'\\\\PDO'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'B2DB needs the PDO PHP libraries installed. See http://php.net/PDO for more information.'",
")",
";",
"}",
"try",
"{",
"$",
"uname",
"=",
"self",
"::",
"getUsername",
"(",
")",
";",
"$",
"pwd",
"=",
"self",
"::",
"getPassword",
"(",
")",
";",
"$",
"dsn",
"=",
"self",
"::",
"getDSN",
"(",
")",
";",
"if",
"(",
"self",
"::",
"$",
"db_connection",
"instanceof",
"PDO",
")",
"{",
"self",
"::",
"$",
"db_connection",
"=",
"null",
";",
"}",
"self",
"::",
"$",
"db_connection",
"=",
"new",
"PDO",
"(",
"$",
"dsn",
",",
"$",
"uname",
",",
"$",
"pwd",
")",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"db_connection",
"instanceof",
"PDO",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Could not connect to the database, but not caught by PDO'",
")",
";",
"}",
"switch",
"(",
"self",
"::",
"getDriver",
"(",
")",
")",
"{",
"case",
"self",
"::",
"DRIVER_MYSQL",
":",
"self",
"::",
"getDBLink",
"(",
")",
"->",
"query",
"(",
"'SET NAMES UTF8'",
")",
";",
"break",
";",
"case",
"self",
"::",
"DRIVER_POSTGRES",
":",
"self",
"::",
"getDBlink",
"(",
")",
"->",
"query",
"(",
"'set client_encoding to UTF8'",
")",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Could not connect to the database [\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\"], dsn: \"",
".",
"self",
"::",
"getDSN",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Try connecting to the database
|
[
"Try",
"connecting",
"to",
"the",
"database"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L599-L629
|
27,420
|
thebuggenie/b2db
|
src/Core.php
|
Core.getDrivers
|
public static function getDrivers()
{
$types = array();
if (class_exists('\PDO')) {
$types[self::DRIVER_MYSQL] = 'MySQL / MariaDB';
$types[self::DRIVER_POSTGRES] = 'PostgreSQL';
$types[self::DRIVER_MS_SQL_SERVER] = 'Microsoft SQL Server';
} else {
throw new Exception('You need to have PHP PDO installed to be able to use B2DB');
}
return $types;
}
|
php
|
public static function getDrivers()
{
$types = array();
if (class_exists('\PDO')) {
$types[self::DRIVER_MYSQL] = 'MySQL / MariaDB';
$types[self::DRIVER_POSTGRES] = 'PostgreSQL';
$types[self::DRIVER_MS_SQL_SERVER] = 'Microsoft SQL Server';
} else {
throw new Exception('You need to have PHP PDO installed to be able to use B2DB');
}
return $types;
}
|
[
"public",
"static",
"function",
"getDrivers",
"(",
")",
"{",
"$",
"types",
"=",
"array",
"(",
")",
";",
"if",
"(",
"class_exists",
"(",
"'\\PDO'",
")",
")",
"{",
"$",
"types",
"[",
"self",
"::",
"DRIVER_MYSQL",
"]",
"=",
"'MySQL / MariaDB'",
";",
"$",
"types",
"[",
"self",
"::",
"DRIVER_POSTGRES",
"]",
"=",
"'PostgreSQL'",
";",
"$",
"types",
"[",
"self",
"::",
"DRIVER_MS_SQL_SERVER",
"]",
"=",
"'Microsoft SQL Server'",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'You need to have PHP PDO installed to be able to use B2DB'",
")",
";",
"}",
"return",
"$",
"types",
";",
"}"
] |
Get available DB drivers
@return array
|
[
"Get",
"available",
"DB",
"drivers"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Core.php#L746-L759
|
27,421
|
thebuggenie/b2db
|
src/Statement.php
|
Statement.execute
|
public function execute()
{
$values = ($this->getQuery() instanceof QueryInterface) ? $this->getQuery()->getValues() : array();
if (Core::isDebugMode()) {
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('executing PDO query (' . Core::getSQLCount() . ') - ' . (($this->getQuery() instanceof Criteria) ? $this->getQuery()->getAction() : 'unknown'), 'B2DB');
}
$previous_time = Core::getDebugTime();
}
$res = $this->statement->execute($values);
if (!$res) {
$error = $this->statement->errorInfo();
if (Core::isDebugMode()) {
Core::sqlHit($this, $previous_time);
}
throw new Exception($error[2], $this->printSQL());
}
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('done', 'B2DB');
}
if ($this->getQuery() instanceof Query && $this->getQuery()->isInsert()) {
if (Core::getDriver() == Core::DRIVER_MYSQL) {
$this->insert_id = Core::getDBLink()->lastInsertId();
} elseif (Core::getDriver() == Core::DRIVER_POSTGRES) {
$this->insert_id = Core::getDBLink()->lastInsertId(Core::getTablePrefix() . $this->getQuery()->getTable()->getB2DBName() . '_id_seq');
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('sequence: ' . Core::getTablePrefix() . $this->getQuery()->getTable()->getB2DBName() . '_id_seq', 'b2db');
\caspar\core\Logging::log('id is: ' . $this->insert_id, 'b2db');
}
}
}
$return_value = new Resultset($this);
if (Core::isDebugMode()) {
Core::sqlHit($this, $previous_time);
}
if (!$this->getQuery() || $this->getQuery()->isSelect()) {
$this->statement->closeCursor();
}
return $return_value;
}
|
php
|
public function execute()
{
$values = ($this->getQuery() instanceof QueryInterface) ? $this->getQuery()->getValues() : array();
if (Core::isDebugMode()) {
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('executing PDO query (' . Core::getSQLCount() . ') - ' . (($this->getQuery() instanceof Criteria) ? $this->getQuery()->getAction() : 'unknown'), 'B2DB');
}
$previous_time = Core::getDebugTime();
}
$res = $this->statement->execute($values);
if (!$res) {
$error = $this->statement->errorInfo();
if (Core::isDebugMode()) {
Core::sqlHit($this, $previous_time);
}
throw new Exception($error[2], $this->printSQL());
}
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('done', 'B2DB');
}
if ($this->getQuery() instanceof Query && $this->getQuery()->isInsert()) {
if (Core::getDriver() == Core::DRIVER_MYSQL) {
$this->insert_id = Core::getDBLink()->lastInsertId();
} elseif (Core::getDriver() == Core::DRIVER_POSTGRES) {
$this->insert_id = Core::getDBLink()->lastInsertId(Core::getTablePrefix() . $this->getQuery()->getTable()->getB2DBName() . '_id_seq');
if (Core::isDebugLoggingEnabled() && class_exists('\\caspar\\core\\Logging')) {
\caspar\core\Logging::log('sequence: ' . Core::getTablePrefix() . $this->getQuery()->getTable()->getB2DBName() . '_id_seq', 'b2db');
\caspar\core\Logging::log('id is: ' . $this->insert_id, 'b2db');
}
}
}
$return_value = new Resultset($this);
if (Core::isDebugMode()) {
Core::sqlHit($this, $previous_time);
}
if (!$this->getQuery() || $this->getQuery()->isSelect()) {
$this->statement->closeCursor();
}
return $return_value;
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"values",
"=",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
"instanceof",
"QueryInterface",
")",
"?",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getValues",
"(",
")",
":",
"array",
"(",
")",
";",
"if",
"(",
"Core",
"::",
"isDebugMode",
"(",
")",
")",
"{",
"if",
"(",
"Core",
"::",
"isDebugLoggingEnabled",
"(",
")",
"&&",
"class_exists",
"(",
"'\\\\caspar\\\\core\\\\Logging'",
")",
")",
"{",
"\\",
"caspar",
"\\",
"core",
"\\",
"Logging",
"::",
"log",
"(",
"'executing PDO query ('",
".",
"Core",
"::",
"getSQLCount",
"(",
")",
".",
"') - '",
".",
"(",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
"instanceof",
"Criteria",
")",
"?",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getAction",
"(",
")",
":",
"'unknown'",
")",
",",
"'B2DB'",
")",
";",
"}",
"$",
"previous_time",
"=",
"Core",
"::",
"getDebugTime",
"(",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
"$",
"values",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"statement",
"->",
"errorInfo",
"(",
")",
";",
"if",
"(",
"Core",
"::",
"isDebugMode",
"(",
")",
")",
"{",
"Core",
"::",
"sqlHit",
"(",
"$",
"this",
",",
"$",
"previous_time",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"$",
"error",
"[",
"2",
"]",
",",
"$",
"this",
"->",
"printSQL",
"(",
")",
")",
";",
"}",
"if",
"(",
"Core",
"::",
"isDebugLoggingEnabled",
"(",
")",
"&&",
"class_exists",
"(",
"'\\\\caspar\\\\core\\\\Logging'",
")",
")",
"{",
"\\",
"caspar",
"\\",
"core",
"\\",
"Logging",
"::",
"log",
"(",
"'done'",
",",
"'B2DB'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
"instanceof",
"Query",
"&&",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"isInsert",
"(",
")",
")",
"{",
"if",
"(",
"Core",
"::",
"getDriver",
"(",
")",
"==",
"Core",
"::",
"DRIVER_MYSQL",
")",
"{",
"$",
"this",
"->",
"insert_id",
"=",
"Core",
"::",
"getDBLink",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"}",
"elseif",
"(",
"Core",
"::",
"getDriver",
"(",
")",
"==",
"Core",
"::",
"DRIVER_POSTGRES",
")",
"{",
"$",
"this",
"->",
"insert_id",
"=",
"Core",
"::",
"getDBLink",
"(",
")",
"->",
"lastInsertId",
"(",
"Core",
"::",
"getTablePrefix",
"(",
")",
".",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getTable",
"(",
")",
"->",
"getB2DBName",
"(",
")",
".",
"'_id_seq'",
")",
";",
"if",
"(",
"Core",
"::",
"isDebugLoggingEnabled",
"(",
")",
"&&",
"class_exists",
"(",
"'\\\\caspar\\\\core\\\\Logging'",
")",
")",
"{",
"\\",
"caspar",
"\\",
"core",
"\\",
"Logging",
"::",
"log",
"(",
"'sequence: '",
".",
"Core",
"::",
"getTablePrefix",
"(",
")",
".",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getTable",
"(",
")",
"->",
"getB2DBName",
"(",
")",
".",
"'_id_seq'",
",",
"'b2db'",
")",
";",
"\\",
"caspar",
"\\",
"core",
"\\",
"Logging",
"::",
"log",
"(",
"'id is: '",
".",
"$",
"this",
"->",
"insert_id",
",",
"'b2db'",
")",
";",
"}",
"}",
"}",
"$",
"return_value",
"=",
"new",
"Resultset",
"(",
"$",
"this",
")",
";",
"if",
"(",
"Core",
"::",
"isDebugMode",
"(",
")",
")",
"{",
"Core",
"::",
"sqlHit",
"(",
"$",
"this",
",",
"$",
"previous_time",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getQuery",
"(",
")",
"||",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"isSelect",
"(",
")",
")",
"{",
"$",
"this",
"->",
"statement",
"->",
"closeCursor",
"(",
")",
";",
"}",
"return",
"$",
"return_value",
";",
"}"
] |
Performs a query, then returns a resultset
@return Resultset
|
[
"Performs",
"a",
"query",
"then",
"returns",
"a",
"resultset"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Statement.php#L79-L126
|
27,422
|
thebuggenie/b2db
|
src/Statement.php
|
Statement.fetch
|
public function fetch()
{
try {
if ($this->values = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
return $this->values;
} else {
return false;
}
} catch (\PDOException $e) {
throw new Exception('An error occured while trying to fetch the result: "' . $e->getMessage() . '"');
}
}
|
php
|
public function fetch()
{
try {
if ($this->values = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
return $this->values;
} else {
return false;
}
} catch (\PDOException $e) {
throw new Exception('An error occured while trying to fetch the result: "' . $e->getMessage() . '"');
}
}
|
[
"public",
"function",
"fetch",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
"=",
"$",
"this",
"->",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'An error occured while trying to fetch the result: \"'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'\"'",
")",
";",
"}",
"}"
] |
Fetch the resultset
|
[
"Fetch",
"the",
"resultset"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Statement.php#L162-L173
|
27,423
|
thebuggenie/b2db
|
src/Statement.php
|
Statement.prepare
|
protected function prepare()
{
if (!Core::getDBlink() instanceof \PDO) {
throw new Exception('Connection not up, can\'t prepare the statement');
}
$this->statement = Core::getDBlink()->prepare($this->query->getSql());
}
|
php
|
protected function prepare()
{
if (!Core::getDBlink() instanceof \PDO) {
throw new Exception('Connection not up, can\'t prepare the statement');
}
$this->statement = Core::getDBlink()->prepare($this->query->getSql());
}
|
[
"protected",
"function",
"prepare",
"(",
")",
"{",
"if",
"(",
"!",
"Core",
"::",
"getDBlink",
"(",
")",
"instanceof",
"\\",
"PDO",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Connection not up, can\\'t prepare the statement'",
")",
";",
"}",
"$",
"this",
"->",
"statement",
"=",
"Core",
"::",
"getDBlink",
"(",
")",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
"->",
"getSql",
"(",
")",
")",
";",
"}"
] |
Prepare the statement
|
[
"Prepare",
"the",
"statement"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Statement.php#L178-L185
|
27,424
|
n2n/n2n
|
src/app/n2n/core/module/ModuleManager.php
|
ModuleManager.getModuleOfTypeName
|
public function getModuleOfTypeName(string $typeName, bool $required = true) {
$typeName = trim($typeName, '\\');
$module = null;
$nsLength = 0;
foreach ($this->modules as $curNamespace => $curModule) {
if (!StringUtils::startsWith($curNamespace . '\\', $typeName)) continue;
$curNsLength = strlen($curNamespace);
if ($curNsLength > $nsLength) {
$module = $curModule;
$nsLength = $curNsLength;
}
}
if (!$required || $module !== null) return $module;
throw new UnknownModuleException('Type is not part of any installed modules: ' . $typeName);
}
|
php
|
public function getModuleOfTypeName(string $typeName, bool $required = true) {
$typeName = trim($typeName, '\\');
$module = null;
$nsLength = 0;
foreach ($this->modules as $curNamespace => $curModule) {
if (!StringUtils::startsWith($curNamespace . '\\', $typeName)) continue;
$curNsLength = strlen($curNamespace);
if ($curNsLength > $nsLength) {
$module = $curModule;
$nsLength = $curNsLength;
}
}
if (!$required || $module !== null) return $module;
throw new UnknownModuleException('Type is not part of any installed modules: ' . $typeName);
}
|
[
"public",
"function",
"getModuleOfTypeName",
"(",
"string",
"$",
"typeName",
",",
"bool",
"$",
"required",
"=",
"true",
")",
"{",
"$",
"typeName",
"=",
"trim",
"(",
"$",
"typeName",
",",
"'\\\\'",
")",
";",
"$",
"module",
"=",
"null",
";",
"$",
"nsLength",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"curNamespace",
"=>",
"$",
"curModule",
")",
"{",
"if",
"(",
"!",
"StringUtils",
"::",
"startsWith",
"(",
"$",
"curNamespace",
".",
"'\\\\'",
",",
"$",
"typeName",
")",
")",
"continue",
";",
"$",
"curNsLength",
"=",
"strlen",
"(",
"$",
"curNamespace",
")",
";",
"if",
"(",
"$",
"curNsLength",
">",
"$",
"nsLength",
")",
"{",
"$",
"module",
"=",
"$",
"curModule",
";",
"$",
"nsLength",
"=",
"$",
"curNsLength",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"required",
"||",
"$",
"module",
"!==",
"null",
")",
"return",
"$",
"module",
";",
"throw",
"new",
"UnknownModuleException",
"(",
"'Type is not part of any installed modules: '",
".",
"$",
"typeName",
")",
";",
"}"
] |
Returns the module which the passed type is part of.
@param string $typeName
@param bool $required
@throws UnknownModuleException if $required is true and type is not part of any module.
@return Module or null if $required is false and type is not part of any module.
|
[
"Returns",
"the",
"module",
"which",
"the",
"passed",
"type",
"is",
"part",
"of",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/module/ModuleManager.php#L64-L82
|
27,425
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.setLogMailRecipient
|
public function setLogMailRecipient(string $mailRecipient, string $mailAddresser) {
$this->logMailRecipient = $mailRecipient;
$this->logMailAddresser = $mailAddresser;
}
|
php
|
public function setLogMailRecipient(string $mailRecipient, string $mailAddresser) {
$this->logMailRecipient = $mailRecipient;
$this->logMailAddresser = $mailAddresser;
}
|
[
"public",
"function",
"setLogMailRecipient",
"(",
"string",
"$",
"mailRecipient",
",",
"string",
"$",
"mailAddresser",
")",
"{",
"$",
"this",
"->",
"logMailRecipient",
"=",
"$",
"mailRecipient",
";",
"$",
"this",
"->",
"logMailAddresser",
"=",
"$",
"mailAddresser",
";",
"}"
] |
If mailRecipient and mailAddresser are set, the exception handler
sends an mail when an exception was handled by this exception handler.
@param string $mailRecipient
@param string $mailAddresser
|
[
"If",
"mailRecipient",
"and",
"mailAddresser",
"are",
"set",
"the",
"exception",
"handler",
"sends",
"an",
"mail",
"when",
"an",
"exception",
"was",
"handled",
"by",
"this",
"exception",
"handler",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L146-L149
|
27,426
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.checkForFatalErrors
|
public function checkForFatalErrors() {
// in case of memory size exhausted error
gc_collect_cycles();
// $this->checkForPendingLogExceptions();
$error = error_get_last();
if (!isset($error) || $this->checkForError($error['type'], $error['file'], $error['line'], $error['message'])) {
return;
}
// if ($error['type'] == E_WARNING && substr($error['message'], 0, 23) == 'DateTime::__construct()') {
// return;
// }
// if (!$this->strictAttitude || ($error['type'] & self::STRICT_ATTITUTE_PHP_SEVERITIES)) {
// return;
// }
try {
$this->handleTriggeredError($error['type'], $error['message'], $error['file'], $error['line'], null, true);
} catch (\Throwable $e) {
$this->dispatchException($e);
}
$this->checkForPendingLogExceptions();
}
|
php
|
public function checkForFatalErrors() {
// in case of memory size exhausted error
gc_collect_cycles();
// $this->checkForPendingLogExceptions();
$error = error_get_last();
if (!isset($error) || $this->checkForError($error['type'], $error['file'], $error['line'], $error['message'])) {
return;
}
// if ($error['type'] == E_WARNING && substr($error['message'], 0, 23) == 'DateTime::__construct()') {
// return;
// }
// if (!$this->strictAttitude || ($error['type'] & self::STRICT_ATTITUTE_PHP_SEVERITIES)) {
// return;
// }
try {
$this->handleTriggeredError($error['type'], $error['message'], $error['file'], $error['line'], null, true);
} catch (\Throwable $e) {
$this->dispatchException($e);
}
$this->checkForPendingLogExceptions();
}
|
[
"public",
"function",
"checkForFatalErrors",
"(",
")",
"{",
"// in case of memory size exhausted error\r",
"gc_collect_cycles",
"(",
")",
";",
"// \t\t$this->checkForPendingLogExceptions();\r",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"error",
")",
"||",
"$",
"this",
"->",
"checkForError",
"(",
"$",
"error",
"[",
"'type'",
"]",
",",
"$",
"error",
"[",
"'file'",
"]",
",",
"$",
"error",
"[",
"'line'",
"]",
",",
"$",
"error",
"[",
"'message'",
"]",
")",
")",
"{",
"return",
";",
"}",
"// \t\tif ($error['type'] == E_WARNING && substr($error['message'], 0, 23) == 'DateTime::__construct()') {\r",
"// \t\t\treturn;\r",
"// \t\t}\r",
"// \t\tif (!$this->strictAttitude || ($error['type'] & self::STRICT_ATTITUTE_PHP_SEVERITIES)) {\r",
"// \t\t\treturn;\r",
"// \t\t}\r",
"try",
"{",
"$",
"this",
"->",
"handleTriggeredError",
"(",
"$",
"error",
"[",
"'type'",
"]",
",",
"$",
"error",
"[",
"'message'",
"]",
",",
"$",
"error",
"[",
"'file'",
"]",
",",
"$",
"error",
"[",
"'line'",
"]",
",",
"null",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"dispatchException",
"(",
"$",
"e",
")",
";",
"}",
"$",
"this",
"->",
"checkForPendingLogExceptions",
"(",
")",
";",
"}"
] |
Is called from N2N after shutdown was performed to detect and handle fatal errors which
weren't handled yet.
|
[
"Is",
"called",
"from",
"N2N",
"after",
"shutdown",
"was",
"performed",
"to",
"detect",
"and",
"handle",
"fatal",
"errors",
"which",
"weren",
"t",
"handled",
"yet",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L302-L328
|
27,427
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.checkForPendingLogExceptions
|
private function checkForPendingLogExceptions() {
foreach ($this->pendingLogException as $logException) {
$this->log($logException);
$this->dispatchException($logException);
}
$this->pendingLogException = array();
}
|
php
|
private function checkForPendingLogExceptions() {
foreach ($this->pendingLogException as $logException) {
$this->log($logException);
$this->dispatchException($logException);
}
$this->pendingLogException = array();
}
|
[
"private",
"function",
"checkForPendingLogExceptions",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"pendingLogException",
"as",
"$",
"logException",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"$",
"logException",
")",
";",
"$",
"this",
"->",
"dispatchException",
"(",
"$",
"logException",
")",
";",
"}",
"$",
"this",
"->",
"pendingLogException",
"=",
"array",
"(",
")",
";",
"}"
] |
Possible exceptions which were thrown while logging will be handled.
|
[
"Possible",
"exceptions",
"which",
"were",
"thrown",
"while",
"logging",
"will",
"be",
"handled",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L332-L338
|
27,428
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.createPhpError
|
private function createPhpError($errno, $errstr, $errfile, $errline) {
switch($errno) {
case E_ERROR:
// if (!is_null($exception = $this->checkForTypeLoaderException($errno, $errstr, $errfile, $errline))) {
// return $exception;
// }
case E_USER_ERROR:
case E_COMPILE_ERROR:
case E_CORE_ERROR:
return new FatalError($errstr, $errno, $errfile, $errline);
case E_WARNING:
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_CORE_WARNING:
return new WarningError($errstr, $errno, $errfile, $errline);
case E_NOTICE:
case E_USER_NOTICE:
return new NoticeError($errstr, $errno, $errfile, $errline);
case E_RECOVERABLE_ERROR:
return new RecoverableError($errstr, $errno, $errfile, $errline);
case E_STRICT:
return new StrictError($errstr, $errno, $errfile, $errline);
case E_PARSE:
return new ParseError($errstr, $errno, $errfile, $errline);
case E_DEPRECATED:
case E_USER_DEPRECATED:
return new DeprecatedError($errstr, $errno, $errfile, $errline);
default:
return new FatalError($errstr, $errno, $errfile, $errline);
}
}
|
php
|
private function createPhpError($errno, $errstr, $errfile, $errline) {
switch($errno) {
case E_ERROR:
// if (!is_null($exception = $this->checkForTypeLoaderException($errno, $errstr, $errfile, $errline))) {
// return $exception;
// }
case E_USER_ERROR:
case E_COMPILE_ERROR:
case E_CORE_ERROR:
return new FatalError($errstr, $errno, $errfile, $errline);
case E_WARNING:
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_CORE_WARNING:
return new WarningError($errstr, $errno, $errfile, $errline);
case E_NOTICE:
case E_USER_NOTICE:
return new NoticeError($errstr, $errno, $errfile, $errline);
case E_RECOVERABLE_ERROR:
return new RecoverableError($errstr, $errno, $errfile, $errline);
case E_STRICT:
return new StrictError($errstr, $errno, $errfile, $errline);
case E_PARSE:
return new ParseError($errstr, $errno, $errfile, $errline);
case E_DEPRECATED:
case E_USER_DEPRECATED:
return new DeprecatedError($errstr, $errno, $errfile, $errline);
default:
return new FatalError($errstr, $errno, $errfile, $errline);
}
}
|
[
"private",
"function",
"createPhpError",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"{",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"E_ERROR",
":",
"// \t\t\t\tif (!is_null($exception = $this->checkForTypeLoaderException($errno, $errstr, $errfile, $errline))) {\r",
"// \t\t\t\t\treturn $exception;\r",
"// \t\t\t\t}\r",
"case",
"E_USER_ERROR",
":",
"case",
"E_COMPILE_ERROR",
":",
"case",
"E_CORE_ERROR",
":",
"return",
"new",
"FatalError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_WARNING",
":",
"case",
"E_USER_WARNING",
":",
"case",
"E_COMPILE_WARNING",
":",
"case",
"E_CORE_WARNING",
":",
"return",
"new",
"WarningError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_NOTICE",
":",
"case",
"E_USER_NOTICE",
":",
"return",
"new",
"NoticeError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_RECOVERABLE_ERROR",
":",
"return",
"new",
"RecoverableError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_STRICT",
":",
"return",
"new",
"StrictError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_PARSE",
":",
"return",
"new",
"ParseError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"case",
"E_DEPRECATED",
":",
"case",
"E_USER_DEPRECATED",
":",
"return",
"new",
"DeprecatedError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"default",
":",
"return",
"new",
"FatalError",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"}",
"}"
] |
Creates an exception based on a triggered error
@param string $errno
@param string $errstr
@param string $errfile
@param string $errline
@return \Error created exception
|
[
"Creates",
"an",
"exception",
"based",
"on",
"a",
"triggered",
"error"
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L349-L379
|
27,429
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.buildErrorHash
|
private function buildErrorHash($errno, $errfile, $errline, $errstr) {
return sha1($errno . '-' . $errfile . '-' . $errline . '-' . $errstr);
}
|
php
|
private function buildErrorHash($errno, $errfile, $errline, $errstr) {
return sha1($errno . '-' . $errfile . '-' . $errline . '-' . $errstr);
}
|
[
"private",
"function",
"buildErrorHash",
"(",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
",",
"$",
"errstr",
")",
"{",
"return",
"sha1",
"(",
"$",
"errno",
".",
"'-'",
".",
"$",
"errfile",
".",
"'-'",
".",
"$",
"errline",
".",
"'-'",
".",
"$",
"errstr",
")",
";",
"}"
] |
An Error Hash is a unique hash of an triggered error.
@param int $errno
@param string $errfile
@param int $errline
@param string $errstr
@return string
|
[
"An",
"Error",
"Hash",
"is",
"a",
"unique",
"hash",
"of",
"an",
"triggered",
"error",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L467-L469
|
27,430
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.createSimpleLogMessage
|
private function createSimpleLogMessage(\Throwable $e) {
$message = get_class($e) . ': ' . $e->getMessage();
if ($e instanceof \ErrorException || $e instanceof \Error) {
$message .= ' in ' . $e->getFile() . ' on line ' . $e->getLine();
}
return $message;
}
|
php
|
private function createSimpleLogMessage(\Throwable $e) {
$message = get_class($e) . ': ' . $e->getMessage();
if ($e instanceof \ErrorException || $e instanceof \Error) {
$message .= ' in ' . $e->getFile() . ' on line ' . $e->getLine();
}
return $message;
}
|
[
"private",
"function",
"createSimpleLogMessage",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"ErrorException",
"||",
"$",
"e",
"instanceof",
"\\",
"Error",
")",
"{",
"$",
"message",
".=",
"' in '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' on line '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] |
Creates short description of an exception used for logging
@param \Exception $e
@return string short description
|
[
"Creates",
"short",
"description",
"of",
"an",
"exception",
"used",
"for",
"logging"
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L563-L569
|
27,431
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.dispatchException
|
private function dispatchException(\Throwable $t) {
array_unshift($this->dispatchingThrowables, $t);
$numDispatchingThrowables = sizeof($this->dispatchingThrowables);
if (!N2N::isInitialized() || 2 < $numDispatchingThrowables || (2 == $numDispatchingThrowables
&& !($this->dispatchingThrowables[1] instanceof StatusException)) || !$this->stable) {
if (!isset($_SERVER['HTTP_HOST'])) {
$this->renderExceptionConsoleInfo($t);
return;
}
$this->renderFatalExceptionsHtmlInfo($this->dispatchingThrowables);
return;
}
if (!N2N::isHttpContextAvailable()) {
$this->renderExceptionConsoleInfo($t);
return;
}
try {
$this->renderBeautifulExceptionView($t);
} catch (\Throwable $t) {
$this->handleThrowable($t);
}
}
|
php
|
private function dispatchException(\Throwable $t) {
array_unshift($this->dispatchingThrowables, $t);
$numDispatchingThrowables = sizeof($this->dispatchingThrowables);
if (!N2N::isInitialized() || 2 < $numDispatchingThrowables || (2 == $numDispatchingThrowables
&& !($this->dispatchingThrowables[1] instanceof StatusException)) || !$this->stable) {
if (!isset($_SERVER['HTTP_HOST'])) {
$this->renderExceptionConsoleInfo($t);
return;
}
$this->renderFatalExceptionsHtmlInfo($this->dispatchingThrowables);
return;
}
if (!N2N::isHttpContextAvailable()) {
$this->renderExceptionConsoleInfo($t);
return;
}
try {
$this->renderBeautifulExceptionView($t);
} catch (\Throwable $t) {
$this->handleThrowable($t);
}
}
|
[
"private",
"function",
"dispatchException",
"(",
"\\",
"Throwable",
"$",
"t",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"dispatchingThrowables",
",",
"$",
"t",
")",
";",
"$",
"numDispatchingThrowables",
"=",
"sizeof",
"(",
"$",
"this",
"->",
"dispatchingThrowables",
")",
";",
"if",
"(",
"!",
"N2N",
"::",
"isInitialized",
"(",
")",
"||",
"2",
"<",
"$",
"numDispatchingThrowables",
"||",
"(",
"2",
"==",
"$",
"numDispatchingThrowables",
"&&",
"!",
"(",
"$",
"this",
"->",
"dispatchingThrowables",
"[",
"1",
"]",
"instanceof",
"StatusException",
")",
")",
"||",
"!",
"$",
"this",
"->",
"stable",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"renderExceptionConsoleInfo",
"(",
"$",
"t",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"renderFatalExceptionsHtmlInfo",
"(",
"$",
"this",
"->",
"dispatchingThrowables",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"N2N",
"::",
"isHttpContextAvailable",
"(",
")",
")",
"{",
"$",
"this",
"->",
"renderExceptionConsoleInfo",
"(",
"$",
"t",
")",
";",
"return",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"renderBeautifulExceptionView",
"(",
"$",
"t",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"t",
")",
"{",
"$",
"this",
"->",
"handleThrowable",
"(",
"$",
"t",
")",
";",
"}",
"}"
] |
Decides what exception infos should be rendered.
@param \Throwable $t
|
[
"Decides",
"what",
"exception",
"infos",
"should",
"be",
"rendered",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L665-L690
|
27,432
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.renderFatalExceptionsHtmlInfo
|
private function renderFatalExceptionsHtmlInfo(array $exceptions) {
if ($this->httpFatalExceptionSent) return;
if (!$this->isObActive()) {
$this->httpFatalExceptionSent = true;
}
$output = $this->fetchObDirty();
if (!headers_sent()) {
header('Content-Type: text/html; charset=utf-8');
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\r\n"
. '<html xmlns="http://www.w3.org/1999/xhtml" lang="de">' . "\r\n"
. '<head>' . "\r\n"
. '<title>Fatal Error occurred</title>' . "\r\n"
. '</head>' . "\r\n"
. '<body>' . "\r\n"
. '<h1>Fatal Error occurred</h1>' . "\r\n";
if (N2N::isLiveStageOn()) {
echo '<p>Webmaster was informed. Please try later again.</p>' . "\r\n";
} else {
$i = 0;
foreach ($exceptions as $e) {
if ($i++ == 0) {
echo '<h2>' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h2>' . "\r\n"
. $this->buildDevelopmentExceptionHtmlContent($e);
continue;
}
echo '<h2>caused by: ' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h2>' . "\r\n"
. $this->buildDevelopmentExceptionHtmlContent($e);
}
echo '<h2>Output</h2>' . "\r\n" .
'<pre>' . htmlspecialchars($output, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</pre>' . "\r\n";
}
echo '</body>' . "\r\n" .
'</html>';
}
|
php
|
private function renderFatalExceptionsHtmlInfo(array $exceptions) {
if ($this->httpFatalExceptionSent) return;
if (!$this->isObActive()) {
$this->httpFatalExceptionSent = true;
}
$output = $this->fetchObDirty();
if (!headers_sent()) {
header('Content-Type: text/html; charset=utf-8');
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\r\n"
. '<html xmlns="http://www.w3.org/1999/xhtml" lang="de">' . "\r\n"
. '<head>' . "\r\n"
. '<title>Fatal Error occurred</title>' . "\r\n"
. '</head>' . "\r\n"
. '<body>' . "\r\n"
. '<h1>Fatal Error occurred</h1>' . "\r\n";
if (N2N::isLiveStageOn()) {
echo '<p>Webmaster was informed. Please try later again.</p>' . "\r\n";
} else {
$i = 0;
foreach ($exceptions as $e) {
if ($i++ == 0) {
echo '<h2>' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h2>' . "\r\n"
. $this->buildDevelopmentExceptionHtmlContent($e);
continue;
}
echo '<h2>caused by: ' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h2>' . "\r\n"
. $this->buildDevelopmentExceptionHtmlContent($e);
}
echo '<h2>Output</h2>' . "\r\n" .
'<pre>' . htmlspecialchars($output, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</pre>' . "\r\n";
}
echo '</body>' . "\r\n" .
'</html>';
}
|
[
"private",
"function",
"renderFatalExceptionsHtmlInfo",
"(",
"array",
"$",
"exceptions",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"httpFatalExceptionSent",
")",
"return",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isObActive",
"(",
")",
")",
"{",
"$",
"this",
"->",
"httpFatalExceptionSent",
"=",
"true",
";",
"}",
"$",
"output",
"=",
"$",
"this",
"->",
"fetchObDirty",
"(",
")",
";",
"if",
"(",
"!",
"headers_sent",
"(",
")",
")",
"{",
"header",
"(",
"'Content-Type: text/html; charset=utf-8'",
")",
";",
"header",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
".",
"' 500 Internal Server Error'",
")",
";",
"}",
"echo",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
".",
"\"\\r\\n\"",
".",
"'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">'",
".",
"\"\\r\\n\"",
".",
"'<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"de\">'",
".",
"\"\\r\\n\"",
".",
"'<head>'",
".",
"\"\\r\\n\"",
".",
"'<title>Fatal Error occurred</title>'",
".",
"\"\\r\\n\"",
".",
"'</head>'",
".",
"\"\\r\\n\"",
".",
"'<body>'",
".",
"\"\\r\\n\"",
".",
"'<h1>Fatal Error occurred</h1>'",
".",
"\"\\r\\n\"",
";",
"if",
"(",
"N2N",
"::",
"isLiveStageOn",
"(",
")",
")",
"{",
"echo",
"'<p>Webmaster was informed. Please try later again.</p>'",
".",
"\"\\r\\n\"",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"exceptions",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"i",
"++",
"==",
"0",
")",
"{",
"echo",
"'<h2>'",
".",
"htmlspecialchars",
"(",
"get_class",
"(",
"$",
"e",
")",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</h2>'",
".",
"\"\\r\\n\"",
".",
"$",
"this",
"->",
"buildDevelopmentExceptionHtmlContent",
"(",
"$",
"e",
")",
";",
"continue",
";",
"}",
"echo",
"'<h2>caused by: '",
".",
"htmlspecialchars",
"(",
"get_class",
"(",
"$",
"e",
")",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</h2>'",
".",
"\"\\r\\n\"",
".",
"$",
"this",
"->",
"buildDevelopmentExceptionHtmlContent",
"(",
"$",
"e",
")",
";",
"}",
"echo",
"'<h2>Output</h2>'",
".",
"\"\\r\\n\"",
".",
"'<pre>'",
".",
"htmlspecialchars",
"(",
"$",
"output",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</pre>'",
".",
"\"\\r\\n\"",
";",
"}",
"echo",
"'</body>'",
".",
"\"\\r\\n\"",
".",
"'</html>'",
";",
"}"
] |
prints fatal exception infos in html
@param array $exceptions
|
[
"prints",
"fatal",
"exception",
"infos",
"in",
"html"
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L696-L738
|
27,433
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.renderBeautifulExceptionView
|
private function renderBeautifulExceptionView(\Throwable $e) {
$request = N2N::getCurrentRequest();
$response = N2N::getCurrentResponse();
$status = null;
$viewName = null;
if ($e instanceof StatusException) {
$status = $e->getStatus();
} else {
$status = Response::STATUS_500_INTERNAL_SERVER_ERROR;
}
$throwableModel = null;
// if ($e instanceof StatusException && isset($viewName)) {
// $throwableModel = new ThrowableModel($e, null);
// } else {
$throwableModel = new ThrowableModel($e);
$this->pendingOutputs[] = $response->fetchBufferedOutput(false);
$that = $this;
$throwableModel->setOutputCallback(function () use ($that) {
$output = implode('', $this->pendingOutputs);
$this->pendingOutputs = array();
return $output;
});
// }
$viewName = N2N::getAppConfig()->error()->getErrorViewName($status);
if ($viewName === null) {
if (!N2N::isDevelopmentModeOn()) {
$viewName = self::DEFAULT_STATUS_LIVE_VIEW;
} else {
if ($status == Response::STATUS_500_INTERNAL_SERVER_ERROR) {
$viewName = self::DEFAULT_500_DEV_VIEW;
} else {
$viewName = self::DEFAULT_STATUS_DEV_VIEW;
}
}
}
$view = N2N::getN2nContext()->lookup(ViewFactory::class)->create($viewName, array('throwableModel' => $throwableModel));
$view->setControllerContext(new ControllerContext($request->getCmdPath(), $request->getCmdContextPath()));
$response->reset();
$response->setStatus($status);
if ($e instanceof StatusException) {
$e->prepareResponse($response);
}
$response->send($view);
}
|
php
|
private function renderBeautifulExceptionView(\Throwable $e) {
$request = N2N::getCurrentRequest();
$response = N2N::getCurrentResponse();
$status = null;
$viewName = null;
if ($e instanceof StatusException) {
$status = $e->getStatus();
} else {
$status = Response::STATUS_500_INTERNAL_SERVER_ERROR;
}
$throwableModel = null;
// if ($e instanceof StatusException && isset($viewName)) {
// $throwableModel = new ThrowableModel($e, null);
// } else {
$throwableModel = new ThrowableModel($e);
$this->pendingOutputs[] = $response->fetchBufferedOutput(false);
$that = $this;
$throwableModel->setOutputCallback(function () use ($that) {
$output = implode('', $this->pendingOutputs);
$this->pendingOutputs = array();
return $output;
});
// }
$viewName = N2N::getAppConfig()->error()->getErrorViewName($status);
if ($viewName === null) {
if (!N2N::isDevelopmentModeOn()) {
$viewName = self::DEFAULT_STATUS_LIVE_VIEW;
} else {
if ($status == Response::STATUS_500_INTERNAL_SERVER_ERROR) {
$viewName = self::DEFAULT_500_DEV_VIEW;
} else {
$viewName = self::DEFAULT_STATUS_DEV_VIEW;
}
}
}
$view = N2N::getN2nContext()->lookup(ViewFactory::class)->create($viewName, array('throwableModel' => $throwableModel));
$view->setControllerContext(new ControllerContext($request->getCmdPath(), $request->getCmdContextPath()));
$response->reset();
$response->setStatus($status);
if ($e instanceof StatusException) {
$e->prepareResponse($response);
}
$response->send($view);
}
|
[
"private",
"function",
"renderBeautifulExceptionView",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"request",
"=",
"N2N",
"::",
"getCurrentRequest",
"(",
")",
";",
"$",
"response",
"=",
"N2N",
"::",
"getCurrentResponse",
"(",
")",
";",
"$",
"status",
"=",
"null",
";",
"$",
"viewName",
"=",
"null",
";",
"if",
"(",
"$",
"e",
"instanceof",
"StatusException",
")",
"{",
"$",
"status",
"=",
"$",
"e",
"->",
"getStatus",
"(",
")",
";",
"}",
"else",
"{",
"$",
"status",
"=",
"Response",
"::",
"STATUS_500_INTERNAL_SERVER_ERROR",
";",
"}",
"$",
"throwableModel",
"=",
"null",
";",
"// \t\tif ($e instanceof StatusException && isset($viewName)) {\r",
"// \t\t\t$throwableModel = new ThrowableModel($e, null);\r",
"// \t\t} else {\r",
"$",
"throwableModel",
"=",
"new",
"ThrowableModel",
"(",
"$",
"e",
")",
";",
"$",
"this",
"->",
"pendingOutputs",
"[",
"]",
"=",
"$",
"response",
"->",
"fetchBufferedOutput",
"(",
"false",
")",
";",
"$",
"that",
"=",
"$",
"this",
";",
"$",
"throwableModel",
"->",
"setOutputCallback",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"that",
")",
"{",
"$",
"output",
"=",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"pendingOutputs",
")",
";",
"$",
"this",
"->",
"pendingOutputs",
"=",
"array",
"(",
")",
";",
"return",
"$",
"output",
";",
"}",
")",
";",
"// \t\t}\r",
"$",
"viewName",
"=",
"N2N",
"::",
"getAppConfig",
"(",
")",
"->",
"error",
"(",
")",
"->",
"getErrorViewName",
"(",
"$",
"status",
")",
";",
"if",
"(",
"$",
"viewName",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"N2N",
"::",
"isDevelopmentModeOn",
"(",
")",
")",
"{",
"$",
"viewName",
"=",
"self",
"::",
"DEFAULT_STATUS_LIVE_VIEW",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"status",
"==",
"Response",
"::",
"STATUS_500_INTERNAL_SERVER_ERROR",
")",
"{",
"$",
"viewName",
"=",
"self",
"::",
"DEFAULT_500_DEV_VIEW",
";",
"}",
"else",
"{",
"$",
"viewName",
"=",
"self",
"::",
"DEFAULT_STATUS_DEV_VIEW",
";",
"}",
"}",
"}",
"$",
"view",
"=",
"N2N",
"::",
"getN2nContext",
"(",
")",
"->",
"lookup",
"(",
"ViewFactory",
"::",
"class",
")",
"->",
"create",
"(",
"$",
"viewName",
",",
"array",
"(",
"'throwableModel'",
"=>",
"$",
"throwableModel",
")",
")",
";",
"$",
"view",
"->",
"setControllerContext",
"(",
"new",
"ControllerContext",
"(",
"$",
"request",
"->",
"getCmdPath",
"(",
")",
",",
"$",
"request",
"->",
"getCmdContextPath",
"(",
")",
")",
")",
";",
"$",
"response",
"->",
"reset",
"(",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"status",
")",
";",
"if",
"(",
"$",
"e",
"instanceof",
"StatusException",
")",
"{",
"$",
"e",
"->",
"prepareResponse",
"(",
"$",
"response",
")",
";",
"}",
"$",
"response",
"->",
"send",
"(",
"$",
"view",
")",
";",
"}"
] |
Sends a nice detailed view to the Response
@param \Exception $e
|
[
"Sends",
"a",
"nice",
"detailed",
"view",
"to",
"the",
"Response"
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L756-L804
|
27,434
|
n2n/n2n
|
src/app/n2n/core/err/ExceptionHandler.php
|
ExceptionHandler.buildDevelopmentExceptionHtmlContent
|
private function buildDevelopmentExceptionHtmlContent(\Throwable $e) {
$html = '';
$first = true;
do {
if ($first) $first = false;
else {
$html .= '<h3>caused by: ' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h3>' . "\r\n";
}
$html .= '<p>' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</p>' . "\r\n";
if ($e instanceof \ErrorException || $e instanceof \Error) {
$filePath = $e->getFile();
$lineNo = $e->getLine();
ThrowableInfoFactory::findCallPos($e, $filePath, $lineNo);
if ($filePath !== null) {
$html .= '<p>File: <strong>' . htmlspecialchars($filePath, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</strong></p>' . "\r\n";
}
if ($lineNo !== null) {
$html .= '<p>Line: <strong>' . htmlspecialchars($lineNo, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</strong></p>' . "\r\n";
}
}
$html .= '<pre>' . htmlspecialchars(ThrowableInfoFactory::buildStackTraceString($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</pre>' . "\r\n";
} while (null != ($e = $e->getPrevious()));
return $html;
}
|
php
|
private function buildDevelopmentExceptionHtmlContent(\Throwable $e) {
$html = '';
$first = true;
do {
if ($first) $first = false;
else {
$html .= '<h3>caused by: ' . htmlspecialchars(get_class($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</h3>' . "\r\n";
}
$html .= '<p>' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</p>' . "\r\n";
if ($e instanceof \ErrorException || $e instanceof \Error) {
$filePath = $e->getFile();
$lineNo = $e->getLine();
ThrowableInfoFactory::findCallPos($e, $filePath, $lineNo);
if ($filePath !== null) {
$html .= '<p>File: <strong>' . htmlspecialchars($filePath, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</strong></p>' . "\r\n";
}
if ($lineNo !== null) {
$html .= '<p>Line: <strong>' . htmlspecialchars($lineNo, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</strong></p>' . "\r\n";
}
}
$html .= '<pre>' . htmlspecialchars(ThrowableInfoFactory::buildStackTraceString($e), ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE) . '</pre>' . "\r\n";
} while (null != ($e = $e->getPrevious()));
return $html;
}
|
[
"private",
"function",
"buildDevelopmentExceptionHtmlContent",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"first",
"=",
"true",
";",
"do",
"{",
"if",
"(",
"$",
"first",
")",
"$",
"first",
"=",
"false",
";",
"else",
"{",
"$",
"html",
".=",
"'<h3>caused by: '",
".",
"htmlspecialchars",
"(",
"get_class",
"(",
"$",
"e",
")",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</h3>'",
".",
"\"\\r\\n\"",
";",
"}",
"$",
"html",
".=",
"'<p>'",
".",
"htmlspecialchars",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</p>'",
".",
"\"\\r\\n\"",
";",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"ErrorException",
"||",
"$",
"e",
"instanceof",
"\\",
"Error",
")",
"{",
"$",
"filePath",
"=",
"$",
"e",
"->",
"getFile",
"(",
")",
";",
"$",
"lineNo",
"=",
"$",
"e",
"->",
"getLine",
"(",
")",
";",
"ThrowableInfoFactory",
"::",
"findCallPos",
"(",
"$",
"e",
",",
"$",
"filePath",
",",
"$",
"lineNo",
")",
";",
"if",
"(",
"$",
"filePath",
"!==",
"null",
")",
"{",
"$",
"html",
".=",
"'<p>File: <strong>'",
".",
"htmlspecialchars",
"(",
"$",
"filePath",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</strong></p>'",
".",
"\"\\r\\n\"",
";",
"}",
"if",
"(",
"$",
"lineNo",
"!==",
"null",
")",
"{",
"$",
"html",
".=",
"'<p>Line: <strong>'",
".",
"htmlspecialchars",
"(",
"$",
"lineNo",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</strong></p>'",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"$",
"html",
".=",
"'<pre>'",
".",
"htmlspecialchars",
"(",
"ThrowableInfoFactory",
"::",
"buildStackTraceString",
"(",
"$",
"e",
")",
",",
"ENT_QUOTES",
"|",
"ENT_HTML5",
"|",
"ENT_SUBSTITUTE",
")",
".",
"'</pre>'",
".",
"\"\\r\\n\"",
";",
"}",
"while",
"(",
"null",
"!=",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Create html description of an exception for fatal error view if development
is enabled.
@param \Exception $e
@return string html description
|
[
"Create",
"html",
"description",
"of",
"an",
"exception",
"for",
"fatal",
"error",
"view",
"if",
"development",
"is",
"enabled",
"."
] |
b3d45f9cccea5ee59592420dc2cacefd0d1c83ae
|
https://github.com/n2n/n2n/blob/b3d45f9cccea5ee59592420dc2cacefd0d1c83ae/src/app/n2n/core/err/ExceptionHandler.php#L812-L841
|
27,435
|
thebuggenie/b2db
|
src/Table.php
|
Table.addForeignKeyColumn
|
protected function addForeignKeyColumn($column, Table $table, $key = null)
{
$add_table = clone $table;
$key = ($key !== null) ? $key : $add_table->getIdColumn();
$foreign_column = $add_table->getColumn($key);
switch ($foreign_column['type']) {
case 'integer':
$this->addInteger($column, $foreign_column['length'], $foreign_column['default_value'], false, false, $foreign_column['unsigned']);
break;
case 'float':
$this->addFloat($column, $foreign_column['precision'], $foreign_column['default_value'], false, false, $foreign_column['unsigned']);
break;
case 'varchar':
$this->addVarchar($column, $foreign_column['length'], $foreign_column['default_value'], false);
break;
case 'text':
case 'boolean':
case 'blob':
throw new Exception('Cannot use a text, blob or boolean column as a foreign key');
}
$this->foreign_columns[$column] = array('class' => '\\'.get_class($table), 'key' => $key, 'name' => $column);
}
|
php
|
protected function addForeignKeyColumn($column, Table $table, $key = null)
{
$add_table = clone $table;
$key = ($key !== null) ? $key : $add_table->getIdColumn();
$foreign_column = $add_table->getColumn($key);
switch ($foreign_column['type']) {
case 'integer':
$this->addInteger($column, $foreign_column['length'], $foreign_column['default_value'], false, false, $foreign_column['unsigned']);
break;
case 'float':
$this->addFloat($column, $foreign_column['precision'], $foreign_column['default_value'], false, false, $foreign_column['unsigned']);
break;
case 'varchar':
$this->addVarchar($column, $foreign_column['length'], $foreign_column['default_value'], false);
break;
case 'text':
case 'boolean':
case 'blob':
throw new Exception('Cannot use a text, blob or boolean column as a foreign key');
}
$this->foreign_columns[$column] = array('class' => '\\'.get_class($table), 'key' => $key, 'name' => $column);
}
|
[
"protected",
"function",
"addForeignKeyColumn",
"(",
"$",
"column",
",",
"Table",
"$",
"table",
",",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"add_table",
"=",
"clone",
"$",
"table",
";",
"$",
"key",
"=",
"(",
"$",
"key",
"!==",
"null",
")",
"?",
"$",
"key",
":",
"$",
"add_table",
"->",
"getIdColumn",
"(",
")",
";",
"$",
"foreign_column",
"=",
"$",
"add_table",
"->",
"getColumn",
"(",
"$",
"key",
")",
";",
"switch",
"(",
"$",
"foreign_column",
"[",
"'type'",
"]",
")",
"{",
"case",
"'integer'",
":",
"$",
"this",
"->",
"addInteger",
"(",
"$",
"column",
",",
"$",
"foreign_column",
"[",
"'length'",
"]",
",",
"$",
"foreign_column",
"[",
"'default_value'",
"]",
",",
"false",
",",
"false",
",",
"$",
"foreign_column",
"[",
"'unsigned'",
"]",
")",
";",
"break",
";",
"case",
"'float'",
":",
"$",
"this",
"->",
"addFloat",
"(",
"$",
"column",
",",
"$",
"foreign_column",
"[",
"'precision'",
"]",
",",
"$",
"foreign_column",
"[",
"'default_value'",
"]",
",",
"false",
",",
"false",
",",
"$",
"foreign_column",
"[",
"'unsigned'",
"]",
")",
";",
"break",
";",
"case",
"'varchar'",
":",
"$",
"this",
"->",
"addVarchar",
"(",
"$",
"column",
",",
"$",
"foreign_column",
"[",
"'length'",
"]",
",",
"$",
"foreign_column",
"[",
"'default_value'",
"]",
",",
"false",
")",
";",
"break",
";",
"case",
"'text'",
":",
"case",
"'boolean'",
":",
"case",
"'blob'",
":",
"throw",
"new",
"Exception",
"(",
"'Cannot use a text, blob or boolean column as a foreign key'",
")",
";",
"}",
"$",
"this",
"->",
"foreign_columns",
"[",
"$",
"column",
"]",
"=",
"array",
"(",
"'class'",
"=>",
"'\\\\'",
".",
"get_class",
"(",
"$",
"table",
")",
",",
"'key'",
"=>",
"$",
"key",
",",
"'name'",
"=>",
"$",
"column",
")",
";",
"}"
] |
Adds a foreign table
@param string $column
@param Table $table
@param string $key
|
[
"Adds",
"a",
"foreign",
"table"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L164-L185
|
27,436
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawSelectAll
|
public function rawSelectAll()
{
$query = new Query($this);
$query->generateSelectSQL(true);
return Statement::getPreparedStatement($query)->execute();
}
|
php
|
public function rawSelectAll()
{
$query = new Query($this);
$query->generateSelectSQL(true);
return Statement::getPreparedStatement($query)->execute();
}
|
[
"public",
"function",
"rawSelectAll",
"(",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"generateSelectSQL",
"(",
"true",
")",
";",
"return",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"}"
] |
Selects all records in this table
@return Resultset
|
[
"Selects",
"all",
"records",
"in",
"this",
"table"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L337-L343
|
27,437
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawSelectById
|
public function rawSelectById($id, Query $query = null, $join = 'all')
{
if (!$id) {
return null;
}
if (!$query instanceof Query) {
$query = new Query($this);
}
$query->where($this->id_column, $id);
$query->setLimit(1);
return $this->rawSelectOne($query, $join);
}
|
php
|
public function rawSelectById($id, Query $query = null, $join = 'all')
{
if (!$id) {
return null;
}
if (!$query instanceof Query) {
$query = new Query($this);
}
$query->where($this->id_column, $id);
$query->setLimit(1);
return $this->rawSelectOne($query, $join);
}
|
[
"public",
"function",
"rawSelectById",
"(",
"$",
"id",
",",
"Query",
"$",
"query",
"=",
"null",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"query",
"instanceof",
"Query",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
")",
";",
"}",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"id_column",
",",
"$",
"id",
")",
";",
"$",
"query",
"->",
"setLimit",
"(",
"1",
")",
";",
"return",
"$",
"this",
"->",
"rawSelectOne",
"(",
"$",
"query",
",",
"$",
"join",
")",
";",
"}"
] |
Returns one row from the current table based on a given id
@param integer $id
@param Query|null $query
@param mixed $join
@return \b2db\Row|null
|
[
"Returns",
"one",
"row",
"from",
"the",
"current",
"table",
"based",
"on",
"a",
"given",
"id"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L360-L372
|
27,438
|
thebuggenie/b2db
|
src/Table.php
|
Table.selectById
|
public function selectById($id, Query $query = null, $join = 'all')
{
if (!$this->hasCachedB2DBObject($id)) {
$row = $this->rawSelectById($id, $query, $join);
$object = $this->populateFromRow($row);
} else {
$object = $this->getB2DBCachedObject($id);
}
return $object;
}
|
php
|
public function selectById($id, Query $query = null, $join = 'all')
{
if (!$this->hasCachedB2DBObject($id)) {
$row = $this->rawSelectById($id, $query, $join);
$object = $this->populateFromRow($row);
} else {
$object = $this->getB2DBCachedObject($id);
}
return $object;
}
|
[
"public",
"function",
"selectById",
"(",
"$",
"id",
",",
"Query",
"$",
"query",
"=",
"null",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCachedB2DBObject",
"(",
"$",
"id",
")",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"rawSelectById",
"(",
"$",
"id",
",",
"$",
"query",
",",
"$",
"join",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"populateFromRow",
"(",
"$",
"row",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getB2DBCachedObject",
"(",
"$",
"id",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] |
Select an object by its unique id
@param integer $id
@param Query $query (optional) Criteria with filters
@param mixed $join
@return Saveable
@throws Exception
|
[
"Select",
"an",
"object",
"by",
"its",
"unique",
"id"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L384-L393
|
27,439
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawSelect
|
public function rawSelect(Query $query, $join = 'all')
{
if (!$query instanceof Query) {
$query = new Query($this);
}
$query->setupJoinTables($join);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
return ($resultset->count()) ? $resultset : null;
}
|
php
|
public function rawSelect(Query $query, $join = 'all')
{
if (!$query instanceof Query) {
$query = new Query($this);
}
$query->setupJoinTables($join);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
return ($resultset->count()) ? $resultset : null;
}
|
[
"public",
"function",
"rawSelect",
"(",
"Query",
"$",
"query",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"if",
"(",
"!",
"$",
"query",
"instanceof",
"Query",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
")",
";",
"}",
"$",
"query",
"->",
"setupJoinTables",
"(",
"$",
"join",
")",
";",
"$",
"query",
"->",
"generateSelectSQL",
"(",
")",
";",
"$",
"resultset",
"=",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"return",
"(",
"$",
"resultset",
"->",
"count",
"(",
")",
")",
"?",
"$",
"resultset",
":",
"null",
";",
"}"
] |
Selects rows based on given criteria
@param Query $query
@param string $join
@return Resultset
|
[
"Selects",
"rows",
"based",
"on",
"given",
"criteria"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L419-L430
|
27,440
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawSelectOne
|
public function rawSelectOne(Query $query, $join = 'all')
{
$query->setTable($this);
$query->setupJoinTables($join);
$query->setLimit(1);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
$resultset->next();
return $resultset->getCurrentRow();
}
|
php
|
public function rawSelectOne(Query $query, $join = 'all')
{
$query->setTable($this);
$query->setupJoinTables($join);
$query->setLimit(1);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
$resultset->next();
return $resultset->getCurrentRow();
}
|
[
"public",
"function",
"rawSelectOne",
"(",
"Query",
"$",
"query",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"$",
"query",
"->",
"setTable",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"setupJoinTables",
"(",
"$",
"join",
")",
";",
"$",
"query",
"->",
"setLimit",
"(",
"1",
")",
";",
"$",
"query",
"->",
"generateSelectSQL",
"(",
")",
";",
"$",
"resultset",
"=",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"$",
"resultset",
"->",
"next",
"(",
")",
";",
"return",
"$",
"resultset",
"->",
"getCurrentRow",
"(",
")",
";",
"}"
] |
Selects one row from the table based on the given criteria
@param Query $query
@param mixed $join
@return Row
@throws Exception
|
[
"Selects",
"one",
"row",
"from",
"the",
"table",
"based",
"on",
"the",
"given",
"criteria"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L447-L458
|
27,441
|
thebuggenie/b2db
|
src/Table.php
|
Table.selectOne
|
public function selectOne(Query $query, $join = 'all')
{
$row = $this->rawSelectOne($query, $join);
return $this->populateFromRow($row);
}
|
php
|
public function selectOne(Query $query, $join = 'all')
{
$row = $this->rawSelectOne($query, $join);
return $this->populateFromRow($row);
}
|
[
"public",
"function",
"selectOne",
"(",
"Query",
"$",
"query",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"rawSelectOne",
"(",
"$",
"query",
",",
"$",
"join",
")",
";",
"return",
"$",
"this",
"->",
"populateFromRow",
"(",
"$",
"row",
")",
";",
"}"
] |
Selects one object based on the given criteria
@param Query $query
@param mixed $join
@return Saveable
|
[
"Selects",
"one",
"object",
"based",
"on",
"the",
"given",
"criteria"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L468-L472
|
27,442
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawDelete
|
public function rawDelete(Query $query)
{
$query->setTable($this);
$query->generateDeleteSQL();
$value = Statement::getPreparedStatement($query)->execute();
$this->clearB2DBCachedObjects();
return $value;
}
|
php
|
public function rawDelete(Query $query)
{
$query->setTable($this);
$query->generateDeleteSQL();
$value = Statement::getPreparedStatement($query)->execute();
$this->clearB2DBCachedObjects();
return $value;
}
|
[
"public",
"function",
"rawDelete",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"setTable",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"generateDeleteSQL",
"(",
")",
";",
"$",
"value",
"=",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"clearB2DBCachedObjects",
"(",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
Perform an SQL delete
@param Query $query
@return Resultset
|
[
"Perform",
"an",
"SQL",
"delete"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L543-L552
|
27,443
|
thebuggenie/b2db
|
src/Table.php
|
Table.rawDeleteById
|
public function rawDeleteById($id)
{
if (!$id) {
return null;
}
$query = new Query($this);
$query->where($this->id_column, $id);
$query->generateDeleteSQL();
$this->deleteB2DBObjectFromCache($id);
return Statement::getPreparedStatement($query)->execute();
}
|
php
|
public function rawDeleteById($id)
{
if (!$id) {
return null;
}
$query = new Query($this);
$query->where($this->id_column, $id);
$query->generateDeleteSQL();
$this->deleteB2DBObjectFromCache($id);
return Statement::getPreparedStatement($query)->execute();
}
|
[
"public",
"function",
"rawDeleteById",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"null",
";",
"}",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"id_column",
",",
"$",
"id",
")",
";",
"$",
"query",
"->",
"generateDeleteSQL",
"(",
")",
";",
"$",
"this",
"->",
"deleteB2DBObjectFromCache",
"(",
"$",
"id",
")",
";",
"return",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"}"
] |
Perform an SQL delete by an id
@param integer $id
@return Resultset|null
|
[
"Perform",
"an",
"SQL",
"delete",
"by",
"an",
"id"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L561-L574
|
27,444
|
thebuggenie/b2db
|
src/Table.php
|
Table.create
|
public function create()
{
$sql = $this->generateCreateSql();
$query = new RawQuery($sql);
try {
$this->drop();
return Statement::getPreparedStatement($query)->execute();
} catch (\Exception $e) {
throw new Exception('Error creating table ' . $this->getB2DBName() . ': ' . $e->getMessage(), $sql);
}
}
|
php
|
public function create()
{
$sql = $this->generateCreateSql();
$query = new RawQuery($sql);
try {
$this->drop();
return Statement::getPreparedStatement($query)->execute();
} catch (\Exception $e) {
throw new Exception('Error creating table ' . $this->getB2DBName() . ': ' . $e->getMessage(), $sql);
}
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateCreateSql",
"(",
")",
";",
"$",
"query",
"=",
"new",
"RawQuery",
"(",
"$",
"sql",
")",
";",
"try",
"{",
"$",
"this",
"->",
"drop",
"(",
")",
";",
"return",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Error creating table '",
".",
"$",
"this",
"->",
"getB2DBName",
"(",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"sql",
")",
";",
"}",
"}"
] |
creates the table by executing the sql create statement
@return Resultset
|
[
"creates",
"the",
"table",
"by",
"executing",
"the",
"sql",
"create",
"statement"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L581-L591
|
27,445
|
thebuggenie/b2db
|
src/Table.php
|
Table.upgrade
|
public function upgrade(Table $old_table)
{
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
/** @var RawQuery[] $queries */
$queries = [];
foreach ($added_columns as $details) {
$queries[] = $this->getAddColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof QueryInterface) {
Statement::getPreparedStatement($query)->execute();
}
}
$this->migrateData($old_table);
$queries = [];
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) continue;
$queries[] = $this->getAlterColumnQuery($new_columns[$column]);
$queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
}
foreach ($dropped_columns as $details) {
$queries[] = $this->getDropColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof RawQuery) {
Statement::getPreparedStatement($query)->execute();
}
}
}
|
php
|
public function upgrade(Table $old_table)
{
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
/** @var RawQuery[] $queries */
$queries = [];
foreach ($added_columns as $details) {
$queries[] = $this->getAddColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof QueryInterface) {
Statement::getPreparedStatement($query)->execute();
}
}
$this->migrateData($old_table);
$queries = [];
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) continue;
$queries[] = $this->getAlterColumnQuery($new_columns[$column]);
$queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
}
foreach ($dropped_columns as $details) {
$queries[] = $this->getDropColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof RawQuery) {
Statement::getPreparedStatement($query)->execute();
}
}
}
|
[
"public",
"function",
"upgrade",
"(",
"Table",
"$",
"old_table",
")",
"{",
"$",
"old_columns",
"=",
"$",
"old_table",
"->",
"getColumns",
"(",
")",
";",
"$",
"new_columns",
"=",
"$",
"this",
"->",
"getColumns",
"(",
")",
";",
"$",
"added_columns",
"=",
"\\",
"array_diff_key",
"(",
"$",
"new_columns",
",",
"$",
"old_columns",
")",
";",
"$",
"altered_columns",
"=",
"Tools",
"::",
"array_diff_recursive",
"(",
"$",
"old_columns",
",",
"$",
"new_columns",
")",
";",
"$",
"dropped_columns",
"=",
"\\",
"array_keys",
"(",
"array_diff_key",
"(",
"$",
"old_columns",
",",
"$",
"new_columns",
")",
")",
";",
"/** @var RawQuery[] $queries */",
"$",
"queries",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"added_columns",
"as",
"$",
"details",
")",
"{",
"$",
"queries",
"[",
"]",
"=",
"$",
"this",
"->",
"getAddColumnQuery",
"(",
"$",
"details",
")",
";",
"}",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"query",
"instanceof",
"QueryInterface",
")",
"{",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"migrateData",
"(",
"$",
"old_table",
")",
";",
"$",
"queries",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"altered_columns",
"as",
"$",
"column",
"=>",
"$",
"details",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"column",
",",
"$",
"dropped_columns",
")",
")",
"continue",
";",
"$",
"queries",
"[",
"]",
"=",
"$",
"this",
"->",
"getAlterColumnQuery",
"(",
"$",
"new_columns",
"[",
"$",
"column",
"]",
")",
";",
"$",
"queries",
"[",
"]",
"=",
"$",
"this",
"->",
"getAlterColumnDefaultQuery",
"(",
"$",
"new_columns",
"[",
"$",
"column",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"dropped_columns",
"as",
"$",
"details",
")",
"{",
"$",
"queries",
"[",
"]",
"=",
"$",
"this",
"->",
"getDropColumnQuery",
"(",
"$",
"details",
")",
";",
"}",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"query",
"instanceof",
"RawQuery",
")",
"{",
"Statement",
"::",
"getPreparedStatement",
"(",
"$",
"query",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}"
] |
Perform upgrade for a table, by comparing one table to an old version
of the same table
@param Table $old_table
|
[
"Perform",
"upgrade",
"for",
"a",
"table",
"by",
"comparing",
"one",
"table",
"to",
"an",
"old",
"version",
"of",
"the",
"same",
"table"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L912-L950
|
27,446
|
thebuggenie/b2db
|
src/Cache.php
|
Cache.set
|
public function set($key, $value)
{
if (!$this->enabled) {
return false;
}
switch ($this->type) {
case self::TYPE_APC:
apc_store($key, $value);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
file_put_contents($filename, serialize($value));
break;
}
return true;
}
|
php
|
public function set($key, $value)
{
if (!$this->enabled) {
return false;
}
switch ($this->type) {
case self::TYPE_APC:
apc_store($key, $value);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
file_put_contents($filename, serialize($value));
break;
}
return true;
}
|
[
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"{",
"return",
"false",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_APC",
":",
"apc_store",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_FILE",
":",
"$",
"filename",
"=",
"$",
"this",
"->",
"path",
".",
"$",
"key",
".",
"'.cache'",
";",
"file_put_contents",
"(",
"$",
"filename",
",",
"serialize",
"(",
"$",
"value",
")",
")",
";",
"break",
";",
"}",
"return",
"true",
";",
"}"
] |
Store an item in the cache
@param string $key The cache key to store the item under
@param mixed $value The value to store
@return bool
|
[
"Store",
"an",
"item",
"in",
"the",
"cache"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L131-L149
|
27,447
|
thebuggenie/b2db
|
src/Cache.php
|
Cache.delete
|
public function delete($key)
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_APC:
apc_delete($key);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
unlink($filename);
}
}
|
php
|
public function delete($key)
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_APC:
apc_delete($key);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
unlink($filename);
}
}
|
[
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"return",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_APC",
":",
"apc_delete",
"(",
"$",
"key",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_FILE",
":",
"$",
"filename",
"=",
"$",
"this",
"->",
"path",
".",
"$",
"key",
".",
"'.cache'",
";",
"unlink",
"(",
"$",
"filename",
")",
";",
"}",
"}"
] |
Delete an entry from the cache
@param string $key The cache key to delete
|
[
"Delete",
"an",
"entry",
"from",
"the",
"cache"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L156-L168
|
27,448
|
thebuggenie/b2db
|
src/Cache.php
|
Cache.flush
|
public function flush()
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_FILE:
$iterator = new \DirectoryIterator($this->path);
foreach ($iterator as $file_info)
{
if (!$file_info->isDir())
{
unlink($file_info->getPathname());
}
}
}
}
|
php
|
public function flush()
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_FILE:
$iterator = new \DirectoryIterator($this->path);
foreach ($iterator as $file_info)
{
if (!$file_info->isDir())
{
unlink($file_info->getPathname());
}
}
}
}
|
[
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"return",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_FILE",
":",
"$",
"iterator",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"path",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file_info",
")",
"{",
"if",
"(",
"!",
"$",
"file_info",
"->",
"isDir",
"(",
")",
")",
"{",
"unlink",
"(",
"$",
"file_info",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Flush all entries in the cache
|
[
"Flush",
"all",
"entries",
"in",
"the",
"cache"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L199-L214
|
27,449
|
thebuggenie/b2db
|
src/Resultset.php
|
Resultset.getCurrentRow
|
public function getCurrentRow()
{
if (isset($this->rows[($this->int_ptr - 1)])) {
return $this->rows[($this->int_ptr - 1)];
}
return null;
}
|
php
|
public function getCurrentRow()
{
if (isset($this->rows[($this->int_ptr - 1)])) {
return $this->rows[($this->int_ptr - 1)];
}
return null;
}
|
[
"public",
"function",
"getCurrentRow",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rows",
"[",
"(",
"$",
"this",
"->",
"int_ptr",
"-",
"1",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rows",
"[",
"(",
"$",
"this",
"->",
"int_ptr",
"-",
"1",
")",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the current row
@return Row
|
[
"Returns",
"the",
"current",
"row"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Resultset.php#L94-L100
|
27,450
|
thebuggenie/b2db
|
src/Resultset.php
|
Resultset.getNextRow
|
public function getNextRow()
{
if ($this->_next()) {
$row = $this->getCurrentRow();
if ($row instanceof Row) {
return $row;
}
throw new \Exception('This should never happen. Please file a bug report');
} else {
return false;
}
}
|
php
|
public function getNextRow()
{
if ($this->_next()) {
$row = $this->getCurrentRow();
if ($row instanceof Row) {
return $row;
}
throw new \Exception('This should never happen. Please file a bug report');
} else {
return false;
}
}
|
[
"public",
"function",
"getNextRow",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_next",
"(",
")",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"getCurrentRow",
"(",
")",
";",
"if",
"(",
"$",
"row",
"instanceof",
"Row",
")",
"{",
"return",
"$",
"row",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'This should never happen. Please file a bug report'",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Advances through the resultset and returns the current row
Returns false when there are no more rows
@return Row|false
|
[
"Advances",
"through",
"the",
"resultset",
"and",
"returns",
"the",
"current",
"row",
"Returns",
"false",
"when",
"there",
"are",
"no",
"more",
"rows"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Resultset.php#L108-L119
|
27,451
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.addValue
|
protected function addValue($value, $force_null = false)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null || $force_null) {
$this->values[] = $this->query->getDatabaseValue($value);
}
}
}
|
php
|
protected function addValue($value, $force_null = false)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null || $force_null) {
$this->values[] = $this->query->getDatabaseValue($value);
}
}
}
|
[
"protected",
"function",
"addValue",
"(",
"$",
"value",
",",
"$",
"force_null",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"single_value",
")",
"{",
"$",
"this",
"->",
"addValue",
"(",
"$",
"single_value",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"||",
"$",
"force_null",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"query",
"->",
"getDatabaseValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Add a specified value
@param mixed $value
@param bool $force_null
|
[
"Add",
"a",
"specified",
"value"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L48-L59
|
27,452
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateWhereSQL
|
protected function generateWhereSQL($strip = false)
{
$sql = $this->generateWherePartSql($strip);
$sql .= $this->generateGroupPartSql();
$sql .= $this->generateOrderByPartSql();
if ($this->query->isSelect()) {
if ($this->query->hasLimit()) {
$sql .= ' LIMIT ' . $this->query->getLimit();
}
if ($this->query->hasOffset()) {
$sql .= ' OFFSET ' . $this->query->getOffset();
}
}
return $sql;
}
|
php
|
protected function generateWhereSQL($strip = false)
{
$sql = $this->generateWherePartSql($strip);
$sql .= $this->generateGroupPartSql();
$sql .= $this->generateOrderByPartSql();
if ($this->query->isSelect()) {
if ($this->query->hasLimit()) {
$sql .= ' LIMIT ' . $this->query->getLimit();
}
if ($this->query->hasOffset()) {
$sql .= ' OFFSET ' . $this->query->getOffset();
}
}
return $sql;
}
|
[
"protected",
"function",
"generateWhereSQL",
"(",
"$",
"strip",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateWherePartSql",
"(",
"$",
"strip",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateGroupPartSql",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateOrderByPartSql",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isSelect",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"hasLimit",
"(",
")",
")",
"{",
"$",
"sql",
".=",
"' LIMIT '",
".",
"$",
"this",
"->",
"query",
"->",
"getLimit",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"hasOffset",
"(",
")",
")",
"{",
"$",
"sql",
".=",
"' OFFSET '",
".",
"$",
"this",
"->",
"query",
"->",
"getOffset",
"(",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Generate the "where" part of the query
@param bool $strip
@return string
|
[
"Generate",
"the",
"where",
"part",
"of",
"the",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L159-L174
|
27,453
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateJoinSQL
|
protected function generateJoinSQL()
{
$sql = ' FROM ' . $this->getTable()->getSelectFromSql();
foreach ($this->query->getJoins() as $join) {
$sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
$sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());
if ($join->hasAdditionalCriteria()) {
$sql_parts = [];
foreach ($join->getAdditionalCriteria() as $criteria) {
$criteria->setQuery($this->query);
$sql_parts[] = $criteria->getSql();
foreach ($criteria->getValues() as $value) {
$this->query->addValue($value);
}
}
$sql .= ' AND ' . join(' AND ', $sql_parts);
}
$sql .= ')';
}
return $sql;
}
|
php
|
protected function generateJoinSQL()
{
$sql = ' FROM ' . $this->getTable()->getSelectFromSql();
foreach ($this->query->getJoins() as $join) {
$sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
$sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());
if ($join->hasAdditionalCriteria()) {
$sql_parts = [];
foreach ($join->getAdditionalCriteria() as $criteria) {
$criteria->setQuery($this->query);
$sql_parts[] = $criteria->getSql();
foreach ($criteria->getValues() as $value) {
$this->query->addValue($value);
}
}
$sql .= ' AND ' . join(' AND ', $sql_parts);
}
$sql .= ')';
}
return $sql;
}
|
[
"protected",
"function",
"generateJoinSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"' FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getSelectFromSql",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getJoins",
"(",
")",
"as",
"$",
"join",
")",
"{",
"$",
"sql",
".=",
"' '",
".",
"$",
"join",
"->",
"getJoinType",
"(",
")",
".",
"' '",
".",
"$",
"join",
"->",
"getTable",
"(",
")",
"->",
"getSelectFromSql",
"(",
")",
";",
"$",
"sql",
".=",
"' ON ('",
".",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"join",
"->",
"getLeftColumn",
"(",
")",
")",
".",
"Criterion",
"::",
"EQUALS",
".",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"join",
"->",
"getRightColumn",
"(",
")",
")",
";",
"if",
"(",
"$",
"join",
"->",
"hasAdditionalCriteria",
"(",
")",
")",
"{",
"$",
"sql_parts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"join",
"->",
"getAdditionalCriteria",
"(",
")",
"as",
"$",
"criteria",
")",
"{",
"$",
"criteria",
"->",
"setQuery",
"(",
"$",
"this",
"->",
"query",
")",
";",
"$",
"sql_parts",
"[",
"]",
"=",
"$",
"criteria",
"->",
"getSql",
"(",
")",
";",
"foreach",
"(",
"$",
"criteria",
"->",
"getValues",
"(",
")",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"sql",
".=",
"' AND '",
".",
"join",
"(",
"' AND '",
",",
"$",
"sql_parts",
")",
";",
"}",
"$",
"sql",
".=",
"')'",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Generate the "join" part of the sql
@return string
|
[
"Generate",
"the",
"join",
"part",
"of",
"the",
"sql"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L181-L206
|
27,454
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.addAllSelectColumns
|
protected function addAllSelectColumns()
{
foreach ($this->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
foreach ($this->query->getJoins() as $join) {
foreach ($join->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
}
}
|
php
|
protected function addAllSelectColumns()
{
foreach ($this->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
foreach ($this->query->getJoins() as $join) {
foreach ($join->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
}
}
|
[
"protected",
"function",
"addAllSelectColumns",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getAliasColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addSelectionColumnRaw",
"(",
"$",
"column",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getJoins",
"(",
")",
"as",
"$",
"join",
")",
"{",
"foreach",
"(",
"$",
"join",
"->",
"getTable",
"(",
")",
"->",
"getAliasColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addSelectionColumnRaw",
"(",
"$",
"column",
")",
";",
"}",
"}",
"}"
] |
Adds all select columns from all available tables in the query
|
[
"Adds",
"all",
"select",
"columns",
"from",
"all",
"available",
"tables",
"in",
"the",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L211-L222
|
27,455
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateSelectAllSQL
|
protected function generateSelectAllSQL()
{
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $selection) {
$sql_parts[] = $selection->getSql();
}
return implode(', ', $sql_parts);
}
|
php
|
protected function generateSelectAllSQL()
{
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $selection) {
$sql_parts[] = $selection->getSql();
}
return implode(', ', $sql_parts);
}
|
[
"protected",
"function",
"generateSelectAllSQL",
"(",
")",
"{",
"$",
"sql_parts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getSelectionColumns",
"(",
")",
"as",
"$",
"selection",
")",
"{",
"$",
"sql_parts",
"[",
"]",
"=",
"$",
"selection",
"->",
"getSql",
"(",
")",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"sql_parts",
")",
";",
"}"
] |
Generates "select all" SQL
@return string
|
[
"Generates",
"select",
"all",
"SQL"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L229-L236
|
27,456
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateSelectSQL
|
protected function generateSelectSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';
if ($this->query->isCustomSelection()) {
if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
foreach ($this->query->getSortOrders() as $sort_order) {
$this->query->addSelectionColumn($sort_order->getColumn());
}
}
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $column => $selection) {
$alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
$sub_sql = $selection->getVariableString();
if ($selection->isSpecial()) {
$sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
if ($selection->hasAdditional())
$sub_sql .= ' ' . $selection->getAdditional() . ' ';
if (mb_strpos($selection->getSpecial(), '(') !== false)
$sub_sql .= ')';
} else {
$sub_sql .= Query::quoteIdentifier($selection->getColumn());
}
$sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
$sql_parts[] = $sub_sql;
}
$sql .= implode(', ', $sql_parts);
} else {
$this->addAllSelectColumns();
$sql .= $this->generateSelectAllSQL();
}
return $sql;
}
|
php
|
protected function generateSelectSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';
if ($this->query->isCustomSelection()) {
if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
foreach ($this->query->getSortOrders() as $sort_order) {
$this->query->addSelectionColumn($sort_order->getColumn());
}
}
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $column => $selection) {
$alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
$sub_sql = $selection->getVariableString();
if ($selection->isSpecial()) {
$sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
if ($selection->hasAdditional())
$sub_sql .= ' ' . $selection->getAdditional() . ' ';
if (mb_strpos($selection->getSpecial(), '(') !== false)
$sub_sql .= ')';
} else {
$sub_sql .= Query::quoteIdentifier($selection->getColumn());
}
$sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
$sql_parts[] = $sub_sql;
}
$sql .= implode(', ', $sql_parts);
} else {
$this->addAllSelectColumns();
$sql .= $this->generateSelectAllSQL();
}
return $sql;
}
|
[
"protected",
"function",
"generateSelectSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"(",
"$",
"this",
"->",
"query",
"->",
"isDistinct",
"(",
")",
")",
"?",
"'SELECT DISTINCT '",
":",
"'SELECT '",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isCustomSelection",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isDistinct",
"(",
")",
"&&",
"Core",
"::",
"getDriver",
"(",
")",
"==",
"Core",
"::",
"DRIVER_POSTGRES",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getSortOrders",
"(",
")",
"as",
"$",
"sort_order",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addSelectionColumn",
"(",
"$",
"sort_order",
"->",
"getColumn",
"(",
")",
")",
";",
"}",
"}",
"$",
"sql_parts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getSelectionColumns",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"selection",
")",
"{",
"$",
"alias",
"=",
"(",
"$",
"selection",
"->",
"getAlias",
"(",
")",
")",
"??",
"$",
"this",
"->",
"query",
"->",
"getSelectionAlias",
"(",
"$",
"column",
")",
";",
"$",
"sub_sql",
"=",
"$",
"selection",
"->",
"getVariableString",
"(",
")",
";",
"if",
"(",
"$",
"selection",
"->",
"isSpecial",
"(",
")",
")",
"{",
"$",
"sub_sql",
".=",
"mb_strtoupper",
"(",
"$",
"selection",
"->",
"getSpecial",
"(",
")",
")",
".",
"'('",
".",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"selection",
"->",
"getColumn",
"(",
")",
")",
".",
"')'",
";",
"if",
"(",
"$",
"selection",
"->",
"hasAdditional",
"(",
")",
")",
"$",
"sub_sql",
".=",
"' '",
".",
"$",
"selection",
"->",
"getAdditional",
"(",
")",
".",
"' '",
";",
"if",
"(",
"mb_strpos",
"(",
"$",
"selection",
"->",
"getSpecial",
"(",
")",
",",
"'('",
")",
"!==",
"false",
")",
"$",
"sub_sql",
".=",
"')'",
";",
"}",
"else",
"{",
"$",
"sub_sql",
".=",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"selection",
"->",
"getColumn",
"(",
")",
")",
";",
"}",
"$",
"sub_sql",
".=",
"' AS '",
".",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"alias",
")",
";",
"$",
"sql_parts",
"[",
"]",
"=",
"$",
"sub_sql",
";",
"}",
"$",
"sql",
".=",
"implode",
"(",
"', '",
",",
"$",
"sql_parts",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addAllSelectColumns",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateSelectAllSQL",
"(",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Generate the "select" part of the query
@return string
|
[
"Generate",
"the",
"select",
"part",
"of",
"the",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L243-L277
|
27,457
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.getSelectSQL
|
public function getSelectSQL($all = false)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateSelectSQL();
$sql .= $this->generateJoinSQL();
if (!$all) {
$sql .= $this->generateWhereSQL();
}
return $sql;
}
|
php
|
public function getSelectSQL($all = false)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateSelectSQL();
$sql .= $this->generateJoinSQL();
if (!$all) {
$sql .= $this->generateWhereSQL();
}
return $sql;
}
|
[
"public",
"function",
"getSelectSQL",
"(",
"$",
"all",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"}",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateSelectSQL",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateJoinSQL",
"(",
")",
";",
"if",
"(",
"!",
"$",
"all",
")",
"{",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateWhereSQL",
"(",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Generate a "select" query
@param boolean $all [optional]
@return string
|
[
"Generate",
"a",
"select",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L285-L297
|
27,458
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateCountSQL
|
protected function generateCountSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT COUNT(DISTINCT ' : 'SELECT COUNT(';
$sql .= Query::quoteIdentifier($this->query->getSelectionColumn($this->getTable()->getIdColumn()));
$sql .= ') as num_col';
return $sql;
}
|
php
|
protected function generateCountSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT COUNT(DISTINCT ' : 'SELECT COUNT(';
$sql .= Query::quoteIdentifier($this->query->getSelectionColumn($this->getTable()->getIdColumn()));
$sql .= ') as num_col';
return $sql;
}
|
[
"protected",
"function",
"generateCountSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"(",
"$",
"this",
"->",
"query",
"->",
"isDistinct",
"(",
")",
")",
"?",
"'SELECT COUNT(DISTINCT '",
":",
"'SELECT COUNT('",
";",
"$",
"sql",
".=",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"this",
"->",
"query",
"->",
"getSelectionColumn",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getIdColumn",
"(",
")",
")",
")",
";",
"$",
"sql",
".=",
"') as num_col'",
";",
"return",
"$",
"sql",
";",
"}"
] |
Generate the "count" part of the query
@return string
|
[
"Generate",
"the",
"count",
"part",
"of",
"the",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L304-L311
|
27,459
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.getCountSQL
|
public function getCountSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateCountSQL();
$sql .= $this->generateJoinSQL();
$sql .= $this->generateWhereSQL();
return $sql;
}
|
php
|
public function getCountSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateCountSQL();
$sql .= $this->generateJoinSQL();
$sql .= $this->generateWhereSQL();
return $sql;
}
|
[
"public",
"function",
"getCountSQL",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"}",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateCountSQL",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateJoinSQL",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateWhereSQL",
"(",
")",
";",
"return",
"$",
"sql",
";",
"}"
] |
Generate a "count" query
@return string
|
[
"Generate",
"a",
"count",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L318-L328
|
27,460
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.generateUpdateSQL
|
protected function generateUpdateSQL(Update $update)
{
$updates = [];
foreach ($update->getValues() as $column => $value) {
$column = mb_substr($column, mb_strpos($column, '.') + 1);
$prefix = Query::quoteIdentifier($column);
$updates[] = $prefix . Criterion::EQUALS . '?';
$this->addValue($value, true);
}
$sql = 'UPDATE ' . $this->getTable()->getSqlTableName() . ' SET ' . implode(', ', $updates);
return $sql;
}
|
php
|
protected function generateUpdateSQL(Update $update)
{
$updates = [];
foreach ($update->getValues() as $column => $value) {
$column = mb_substr($column, mb_strpos($column, '.') + 1);
$prefix = Query::quoteIdentifier($column);
$updates[] = $prefix . Criterion::EQUALS . '?';
$this->addValue($value, true);
}
$sql = 'UPDATE ' . $this->getTable()->getSqlTableName() . ' SET ' . implode(', ', $updates);
return $sql;
}
|
[
"protected",
"function",
"generateUpdateSQL",
"(",
"Update",
"$",
"update",
")",
"{",
"$",
"updates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"update",
"->",
"getValues",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"column",
"=",
"mb_substr",
"(",
"$",
"column",
",",
"mb_strpos",
"(",
"$",
"column",
",",
"'.'",
")",
"+",
"1",
")",
";",
"$",
"prefix",
"=",
"Query",
"::",
"quoteIdentifier",
"(",
"$",
"column",
")",
";",
"$",
"updates",
"[",
"]",
"=",
"$",
"prefix",
".",
"Criterion",
"::",
"EQUALS",
".",
"'?'",
";",
"$",
"this",
"->",
"addValue",
"(",
"$",
"value",
",",
"true",
")",
";",
"}",
"$",
"sql",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getSqlTableName",
"(",
")",
".",
"' SET '",
".",
"implode",
"(",
"', '",
",",
"$",
"updates",
")",
";",
"return",
"$",
"sql",
";",
"}"
] |
Generate the "update" part of the query
@param Update $update
@return string
|
[
"Generate",
"the",
"update",
"part",
"of",
"the",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L336-L348
|
27,461
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.getUpdateSQL
|
public function getUpdateSQL(Update $update)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateUpdateSQL($update);
$sql .= $this->generateWhereSQL(true);
return $sql;
}
|
php
|
public function getUpdateSQL(Update $update)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateUpdateSQL($update);
$sql .= $this->generateWhereSQL(true);
return $sql;
}
|
[
"public",
"function",
"getUpdateSQL",
"(",
"Update",
"$",
"update",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"}",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateUpdateSQL",
"(",
"$",
"update",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateWhereSQL",
"(",
"true",
")",
";",
"return",
"$",
"sql",
";",
"}"
] |
Generate an "update" query
@param Update $update
@return string
@throws Exception
|
[
"Generate",
"an",
"update",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L357-L366
|
27,462
|
thebuggenie/b2db
|
src/SqlGenerator.php
|
SqlGenerator.getDeleteSQL
|
public function getDeleteSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = 'DELETE FROM ' . $this->getTable()->getSqlTableName();
$sql .= $this->generateWhereSQL(true);
return $sql;
}
|
php
|
public function getDeleteSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = 'DELETE FROM ' . $this->getTable()->getSqlTableName();
$sql .= $this->generateWhereSQL(true);
return $sql;
}
|
[
"public",
"function",
"getDeleteSQL",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"}",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getSqlTableName",
"(",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateWhereSQL",
"(",
"true",
")",
";",
"return",
"$",
"sql",
";",
"}"
] |
Generate a "delete" query
@return string
|
[
"Generate",
"a",
"delete",
"query"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L410-L419
|
27,463
|
thebuggenie/b2db
|
src/Query.php
|
Query.setTable
|
public function setTable(Table $table, $setup_join_tables = false): self
{
$this->table = $table;
if ($setup_join_tables) {
$this->setupJoinTables();
}
return $this;
}
|
php
|
public function setTable(Table $table, $setup_join_tables = false): self
{
$this->table = $table;
if ($setup_join_tables) {
$this->setupJoinTables();
}
return $this;
}
|
[
"public",
"function",
"setTable",
"(",
"Table",
"$",
"table",
",",
"$",
"setup_join_tables",
"=",
"false",
")",
":",
"self",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"if",
"(",
"$",
"setup_join_tables",
")",
"{",
"$",
"this",
"->",
"setupJoinTables",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the "from" table
@param Table $table The table
@param bool $setup_join_tables [optional] Whether to automatically join other tables
@return Query
|
[
"Set",
"the",
"from",
"table"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L116-L125
|
27,464
|
thebuggenie/b2db
|
src/Query.php
|
Query.addValue
|
public function addValue($value)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null) {
$this->values[] = $this->getDatabaseValue($value);
}
}
}
|
php
|
public function addValue($value)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null) {
$this->values[] = $this->getDatabaseValue($value);
}
}
}
|
[
"public",
"function",
"addValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"single_value",
")",
"{",
"$",
"this",
"->",
"addValue",
"(",
"$",
"single_value",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"getDatabaseValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Add a value to the value container
@param mixed $value
|
[
"Add",
"a",
"value",
"to",
"the",
"value",
"container"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L204-L215
|
27,465
|
thebuggenie/b2db
|
src/Query.php
|
Query.addSelectionColumn
|
public function addSelectionColumn($column, $alias = '', $special = '', $variable = '', $additional = ''): self
{
if (!$this->table instanceof Table) {
throw new \Exception('You must set the from-table before adding selection columns');
}
$column = $this->getSelectionColumn($column);
$alias = ($alias === '') ? str_replace('.', '_', $column) : $alias;
$this->is_custom_selection = true;
$this->addSelectionColumnRaw($column, $alias, $special, $variable, $additional);
return $this;
}
|
php
|
public function addSelectionColumn($column, $alias = '', $special = '', $variable = '', $additional = ''): self
{
if (!$this->table instanceof Table) {
throw new \Exception('You must set the from-table before adding selection columns');
}
$column = $this->getSelectionColumn($column);
$alias = ($alias === '') ? str_replace('.', '_', $column) : $alias;
$this->is_custom_selection = true;
$this->addSelectionColumnRaw($column, $alias, $special, $variable, $additional);
return $this;
}
|
[
"public",
"function",
"addSelectionColumn",
"(",
"$",
"column",
",",
"$",
"alias",
"=",
"''",
",",
"$",
"special",
"=",
"''",
",",
"$",
"variable",
"=",
"''",
",",
"$",
"additional",
"=",
"''",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"table",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'You must set the from-table before adding selection columns'",
")",
";",
"}",
"$",
"column",
"=",
"$",
"this",
"->",
"getSelectionColumn",
"(",
"$",
"column",
")",
";",
"$",
"alias",
"=",
"(",
"$",
"alias",
"===",
"''",
")",
"?",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"column",
")",
":",
"$",
"alias",
";",
"$",
"this",
"->",
"is_custom_selection",
"=",
"true",
";",
"$",
"this",
"->",
"addSelectionColumnRaw",
"(",
"$",
"column",
",",
"$",
"alias",
",",
"$",
"special",
",",
"$",
"variable",
",",
"$",
"additional",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a column to select
@param string $column The column
@param string $alias [optional] An alias for the column
@param string $special [optional] Whether to use a special method on the column
@param string $variable [optional] An optional variable to assign it to
@param string $additional [optional] Additional parameter
@return Query
|
[
"Add",
"a",
"column",
"to",
"select"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L228-L241
|
27,466
|
thebuggenie/b2db
|
src/Query.php
|
Query.update
|
public function update($column, $value): self
{
if (is_object($value)) {
throw new Exception("Invalid value, can't be an object.");
}
$this->updates[] = compact('column', 'value');
return $this;
}
|
php
|
public function update($column, $value): self
{
if (is_object($value)) {
throw new Exception("Invalid value, can't be an object.");
}
$this->updates[] = compact('column', 'value');
return $this;
}
|
[
"public",
"function",
"update",
"(",
"$",
"column",
",",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid value, can't be an object.\"",
")",
";",
"}",
"$",
"this",
"->",
"updates",
"[",
"]",
"=",
"compact",
"(",
"'column'",
",",
"'value'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a field to update
@param string $column The column name
@param mixed $value The value to update
@return Query
|
[
"Add",
"a",
"field",
"to",
"update"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L261-L269
|
27,467
|
thebuggenie/b2db
|
src/Query.php
|
Query.join
|
public function join(Table $table, $joined_table_column, $column, $criteria = [], $join_type = Join::LEFT, $on_table = null)
{
if (!$this->table instanceof Table) {
throw new Exception('Cannot use ' . $this->table . ' as a table. You need to call setTable() before trying to join a new table');
}
if (!$table instanceof Table) {
throw new Exception('Cannot join table ' . $table . ' since it is not a table');
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBAlias() === $table->getB2DBAlias()) {
$table = clone $table;
break;
}
}
$left_column = $table->getB2DBAlias() . '.' . Table::getColumnName($joined_table_column);
$join_on_table = $on_table ?? $this->table;
$right_column = $join_on_table->getB2DBAlias() . '.' . Table::getColumnName($column);
$this->joins[$table->getB2DBAlias()] = new Join($table, $left_column, $right_column, $this->getRealColumnName($column), $criteria, $join_type);
return $table;
}
|
php
|
public function join(Table $table, $joined_table_column, $column, $criteria = [], $join_type = Join::LEFT, $on_table = null)
{
if (!$this->table instanceof Table) {
throw new Exception('Cannot use ' . $this->table . ' as a table. You need to call setTable() before trying to join a new table');
}
if (!$table instanceof Table) {
throw new Exception('Cannot join table ' . $table . ' since it is not a table');
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBAlias() === $table->getB2DBAlias()) {
$table = clone $table;
break;
}
}
$left_column = $table->getB2DBAlias() . '.' . Table::getColumnName($joined_table_column);
$join_on_table = $on_table ?? $this->table;
$right_column = $join_on_table->getB2DBAlias() . '.' . Table::getColumnName($column);
$this->joins[$table->getB2DBAlias()] = new Join($table, $left_column, $right_column, $this->getRealColumnName($column), $criteria, $join_type);
return $table;
}
|
[
"public",
"function",
"join",
"(",
"Table",
"$",
"table",
",",
"$",
"joined_table_column",
",",
"$",
"column",
",",
"$",
"criteria",
"=",
"[",
"]",
",",
"$",
"join_type",
"=",
"Join",
"::",
"LEFT",
",",
"$",
"on_table",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"table",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot use '",
".",
"$",
"this",
"->",
"table",
".",
"' as a table. You need to call setTable() before trying to join a new table'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"table",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot join table '",
".",
"$",
"table",
".",
"' since it is not a table'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"joins",
"as",
"$",
"join",
")",
"{",
"if",
"(",
"$",
"join",
"->",
"getTable",
"(",
")",
"->",
"getB2DBAlias",
"(",
")",
"===",
"$",
"table",
"->",
"getB2DBAlias",
"(",
")",
")",
"{",
"$",
"table",
"=",
"clone",
"$",
"table",
";",
"break",
";",
"}",
"}",
"$",
"left_column",
"=",
"$",
"table",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"Table",
"::",
"getColumnName",
"(",
"$",
"joined_table_column",
")",
";",
"$",
"join_on_table",
"=",
"$",
"on_table",
"??",
"$",
"this",
"->",
"table",
";",
"$",
"right_column",
"=",
"$",
"join_on_table",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"Table",
"::",
"getColumnName",
"(",
"$",
"column",
")",
";",
"$",
"this",
"->",
"joins",
"[",
"$",
"table",
"->",
"getB2DBAlias",
"(",
")",
"]",
"=",
"new",
"Join",
"(",
"$",
"table",
",",
"$",
"left_column",
",",
"$",
"right_column",
",",
"$",
"this",
"->",
"getRealColumnName",
"(",
"$",
"column",
")",
",",
"$",
"criteria",
",",
"$",
"join_type",
")",
";",
"return",
"$",
"table",
";",
"}"
] |
Join one table on another
@param Table $table The table to join
@param string $joined_table_column The left matching column
@param string $column The right matching column
@param Criteria[] $criteria An array of criteria (ex: array(array(DB_FLD_ISSUE_ID, 1), array(DB_FLD_ISSUE_STATE, 1));
@param string $join_type Type of join
@param Table $on_table If different than the main table, specify the left side of the join here
@return Table
|
[
"Join",
"one",
"table",
"on",
"another"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L359-L383
|
27,468
|
thebuggenie/b2db
|
src/Query.php
|
Query.getSelectionColumn
|
public function getSelectionColumn($column)
{
if (isset($this->selections[$column])) {
return $this->selections[$column]->getColumn();
}
foreach ($this->selections as $selection) {
if ($selection->getAlias() == $column) {
return $column;
}
}
list($table_name, $column_name) = (strpos($column, '.') !== false) ? explode('.', $column) : [$this->table->getB2DBName(), $column];
if ($this->table->getB2DBAlias() == $table_name || $this->table->getB2DBName() == $table_name) {
return $this->table->getB2DBAlias() . '.' . $column_name;
} elseif (isset($this->joins[$table_name])) {
return $this->joins[$table_name]->getTable()->getB2DBAlias() . '.' . $column_name;
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBName() == $table_name) {
return $join->getTable()->getB2DBAlias() . '.' . $column_name;
}
}
throw new Exception("Couldn't find table name '{$table_name}' for column '{$column_name}', column was '{$column}'. If this is a column from a foreign table, make sure the foreign table is joined.");
}
|
php
|
public function getSelectionColumn($column)
{
if (isset($this->selections[$column])) {
return $this->selections[$column]->getColumn();
}
foreach ($this->selections as $selection) {
if ($selection->getAlias() == $column) {
return $column;
}
}
list($table_name, $column_name) = (strpos($column, '.') !== false) ? explode('.', $column) : [$this->table->getB2DBName(), $column];
if ($this->table->getB2DBAlias() == $table_name || $this->table->getB2DBName() == $table_name) {
return $this->table->getB2DBAlias() . '.' . $column_name;
} elseif (isset($this->joins[$table_name])) {
return $this->joins[$table_name]->getTable()->getB2DBAlias() . '.' . $column_name;
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBName() == $table_name) {
return $join->getTable()->getB2DBAlias() . '.' . $column_name;
}
}
throw new Exception("Couldn't find table name '{$table_name}' for column '{$column_name}', column was '{$column}'. If this is a column from a foreign table, make sure the foreign table is joined.");
}
|
[
"public",
"function",
"getSelectionColumn",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"selections",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"selections",
"[",
"$",
"column",
"]",
"->",
"getColumn",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"selections",
"as",
"$",
"selection",
")",
"{",
"if",
"(",
"$",
"selection",
"->",
"getAlias",
"(",
")",
"==",
"$",
"column",
")",
"{",
"return",
"$",
"column",
";",
"}",
"}",
"list",
"(",
"$",
"table_name",
",",
"$",
"column_name",
")",
"=",
"(",
"strpos",
"(",
"$",
"column",
",",
"'.'",
")",
"!==",
"false",
")",
"?",
"explode",
"(",
"'.'",
",",
"$",
"column",
")",
":",
"[",
"$",
"this",
"->",
"table",
"->",
"getB2DBName",
"(",
")",
",",
"$",
"column",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"table",
"->",
"getB2DBAlias",
"(",
")",
"==",
"$",
"table_name",
"||",
"$",
"this",
"->",
"table",
"->",
"getB2DBName",
"(",
")",
"==",
"$",
"table_name",
")",
"{",
"return",
"$",
"this",
"->",
"table",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"$",
"column_name",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"joins",
"[",
"$",
"table_name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"joins",
"[",
"$",
"table_name",
"]",
"->",
"getTable",
"(",
")",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"$",
"column_name",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"joins",
"as",
"$",
"join",
")",
"{",
"if",
"(",
"$",
"join",
"->",
"getTable",
"(",
")",
"->",
"getB2DBName",
"(",
")",
"==",
"$",
"table_name",
")",
"{",
"return",
"$",
"join",
"->",
"getTable",
"(",
")",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"$",
"column_name",
";",
"}",
"}",
"throw",
"new",
"Exception",
"(",
"\"Couldn't find table name '{$table_name}' for column '{$column_name}', column was '{$column}'. If this is a column from a foreign table, make sure the foreign table is joined.\"",
")",
";",
"}"
] |
Return a select column
@param string $column
@return string
|
[
"Return",
"a",
"select",
"column"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L470-L497
|
27,469
|
thebuggenie/b2db
|
src/Query.php
|
Query.getSelectionAlias
|
public function getSelectionAlias($column)
{
if (!is_numeric($column) && !is_string($column)) {
if (is_array($column) && array_key_exists('column', $column)) {
$column = $column['column'];
} else {
throw new Exception('Invalid column!');
}
}
if (!isset($this->aliases[$column])) {
$this->aliases[$column] = str_replace('.', '_', $column);
}
return $this->aliases[$column];
}
|
php
|
public function getSelectionAlias($column)
{
if (!is_numeric($column) && !is_string($column)) {
if (is_array($column) && array_key_exists('column', $column)) {
$column = $column['column'];
} else {
throw new Exception('Invalid column!');
}
}
if (!isset($this->aliases[$column])) {
$this->aliases[$column] = str_replace('.', '_', $column);
}
return $this->aliases[$column];
}
|
[
"public",
"function",
"getSelectionAlias",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"column",
")",
"&&",
"!",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
"&&",
"array_key_exists",
"(",
"'column'",
",",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"column",
"[",
"'column'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid column!'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"column",
"]",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"column",
")",
";",
"}",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"column",
"]",
";",
"}"
] |
Get the selection alias for a specified column
@param string $column
@return string
|
[
"Get",
"the",
"selection",
"alias",
"for",
"a",
"specified",
"column"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L506-L520
|
27,470
|
thebuggenie/b2db
|
src/Query.php
|
Query.addOrderBy
|
public function addOrderBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addOrderBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_orders[] = new QueryColumnSort($column, $sort);
}
return $this;
}
|
php
|
public function addOrderBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addOrderBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_orders[] = new QueryColumnSort($column, $sort);
}
return $this;
}
|
[
"public",
"function",
"addOrderBy",
"(",
"$",
"column",
",",
"$",
"sort",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"single_column",
")",
"{",
"$",
"this",
"->",
"addOrderBy",
"(",
"$",
"single_column",
"[",
"0",
"]",
",",
"$",
"single_column",
"[",
"1",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"sort_orders",
"[",
"]",
"=",
"new",
"QueryColumnSort",
"(",
"$",
"column",
",",
"$",
"sort",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add an order by clause
@param string|array $column The column to order by
@param string $sort [optional] The sort order
@return Query
|
[
"Add",
"an",
"order",
"by",
"clause"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L530-L541
|
27,471
|
thebuggenie/b2db
|
src/Query.php
|
Query.addGroupBy
|
public function addGroupBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addGroupBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_groups[] = new QueryColumnSort($column, $sort);
}
return $this;
}
|
php
|
public function addGroupBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addGroupBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_groups[] = new QueryColumnSort($column, $sort);
}
return $this;
}
|
[
"public",
"function",
"addGroupBy",
"(",
"$",
"column",
",",
"$",
"sort",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"single_column",
")",
"{",
"$",
"this",
"->",
"addGroupBy",
"(",
"$",
"single_column",
"[",
"0",
"]",
",",
"$",
"single_column",
"[",
"1",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"sort_groups",
"[",
"]",
"=",
"new",
"QueryColumnSort",
"(",
"$",
"column",
",",
"$",
"sort",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a group by clause
@param string|array $column The column to group by
@param string $sort [optional] The sort order
@return Query
|
[
"Add",
"a",
"group",
"by",
"clause"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L588-L599
|
27,472
|
thebuggenie/b2db
|
src/Query.php
|
Query.setupJoinTables
|
public function setupJoinTables($join = 'all')
{
if (is_array($join)) {
foreach ($join as $join_column) {
$foreign_table = $this->table->getForeignTableByLocalColumn($join_column);
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
} elseif (!is_array($join) && $join == 'all') {
foreach ($this->table->getForeignTables() as $foreign_table) {
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
}
}
|
php
|
public function setupJoinTables($join = 'all')
{
if (is_array($join)) {
foreach ($join as $join_column) {
$foreign_table = $this->table->getForeignTableByLocalColumn($join_column);
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
} elseif (!is_array($join) && $join == 'all') {
foreach ($this->table->getForeignTables() as $foreign_table) {
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
}
}
|
[
"public",
"function",
"setupJoinTables",
"(",
"$",
"join",
"=",
"'all'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"join",
")",
")",
"{",
"foreach",
"(",
"$",
"join",
"as",
"$",
"join_column",
")",
"{",
"$",
"foreign_table",
"=",
"$",
"this",
"->",
"table",
"->",
"getForeignTableByLocalColumn",
"(",
"$",
"join_column",
")",
";",
"$",
"this",
"->",
"join",
"(",
"$",
"foreign_table",
"->",
"getTable",
"(",
")",
",",
"$",
"foreign_table",
"->",
"getKeyColumnName",
"(",
")",
",",
"$",
"this",
"->",
"table",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"$",
"foreign_table",
"->",
"getColumnName",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"join",
")",
"&&",
"$",
"join",
"==",
"'all'",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"table",
"->",
"getForeignTables",
"(",
")",
"as",
"$",
"foreign_table",
")",
"{",
"$",
"this",
"->",
"join",
"(",
"$",
"foreign_table",
"->",
"getTable",
"(",
")",
",",
"$",
"foreign_table",
"->",
"getKeyColumnName",
"(",
")",
",",
"$",
"this",
"->",
"table",
"->",
"getB2DBAlias",
"(",
")",
".",
"'.'",
".",
"$",
"foreign_table",
"->",
"getColumnName",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Add all available foreign tables
@param array|string|bool $join [optional]
|
[
"Add",
"all",
"available",
"foreign",
"tables"
] |
8501d737cd824ff961659e059cd920dc0ebd17cf
|
https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L742-L754
|
27,473
|
contributte/utils
|
src/FileSystem.php
|
FileSystem.copy
|
public static function copy(string $source, string $dest, bool $overwrite = true): void
{
NetteFileSystem::copy($source, $dest, $overwrite);
}
|
php
|
public static function copy(string $source, string $dest, bool $overwrite = true): void
{
NetteFileSystem::copy($source, $dest, $overwrite);
}
|
[
"public",
"static",
"function",
"copy",
"(",
"string",
"$",
"source",
",",
"string",
"$",
"dest",
",",
"bool",
"$",
"overwrite",
"=",
"true",
")",
":",
"void",
"{",
"NetteFileSystem",
"::",
"copy",
"(",
"$",
"source",
",",
"$",
"dest",
",",
"$",
"overwrite",
")",
";",
"}"
] |
Copies a file or directory.
@throws IOException
|
[
"Copies",
"a",
"file",
"or",
"directory",
"."
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/FileSystem.php#L74-L77
|
27,474
|
contributte/utils
|
src/Http.php
|
Http.metadata
|
public static function metadata(string $content): array
{
if (preg_match_all(self::$metadataPattern, $content, $matches) !== false) {
$combine = array_combine($matches[1], $matches[2]);
if ($combine === false) {
throw new LogicException('Matches count is not equal.');
}
return $combine;
}
return [];
}
|
php
|
public static function metadata(string $content): array
{
if (preg_match_all(self::$metadataPattern, $content, $matches) !== false) {
$combine = array_combine($matches[1], $matches[2]);
if ($combine === false) {
throw new LogicException('Matches count is not equal.');
}
return $combine;
}
return [];
}
|
[
"public",
"static",
"function",
"metadata",
"(",
"string",
"$",
"content",
")",
":",
"array",
"{",
"if",
"(",
"preg_match_all",
"(",
"self",
"::",
"$",
"metadataPattern",
",",
"$",
"content",
",",
"$",
"matches",
")",
"!==",
"false",
")",
"{",
"$",
"combine",
"=",
"array_combine",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"if",
"(",
"$",
"combine",
"===",
"false",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Matches count is not equal.'",
")",
";",
"}",
"return",
"$",
"combine",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Gets http metadata from string
@return string[] [name => content]
|
[
"Gets",
"http",
"metadata",
"from",
"string"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Http.php#L37-L50
|
27,475
|
GiacoCorsiglia/php-stubs-generator
|
src/NodeVisitor.php
|
NodeVisitor.getStubStmts
|
public function getStubStmts(): array
{
foreach ($this->classLikes as $classLike) {
$this->resolveClassLike($classLike);
}
if ($this->allAreGlobal($this->namespaces) && $this->allAreGlobal($this->classLikeNamespaces)) {
return array_merge(
$this->reduceStmts($this->classLikeNamespaces),
$this->reduceStmts($this->namespaces),
$this->globalNamespace->stmts,
$this->globalExpressions
);
}
return array_merge(
$this->classLikeNamespaces,
$this->namespaces,
$this->globalNamespace->stmts ? [$this->globalNamespace] : [],
$this->globalExpressions ? [new Namespace_(null, $this->globalExpressions)] : []
);
}
|
php
|
public function getStubStmts(): array
{
foreach ($this->classLikes as $classLike) {
$this->resolveClassLike($classLike);
}
if ($this->allAreGlobal($this->namespaces) && $this->allAreGlobal($this->classLikeNamespaces)) {
return array_merge(
$this->reduceStmts($this->classLikeNamespaces),
$this->reduceStmts($this->namespaces),
$this->globalNamespace->stmts,
$this->globalExpressions
);
}
return array_merge(
$this->classLikeNamespaces,
$this->namespaces,
$this->globalNamespace->stmts ? [$this->globalNamespace] : [],
$this->globalExpressions ? [new Namespace_(null, $this->globalExpressions)] : []
);
}
|
[
"public",
"function",
"getStubStmts",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"classLikes",
"as",
"$",
"classLike",
")",
"{",
"$",
"this",
"->",
"resolveClassLike",
"(",
"$",
"classLike",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"allAreGlobal",
"(",
"$",
"this",
"->",
"namespaces",
")",
"&&",
"$",
"this",
"->",
"allAreGlobal",
"(",
"$",
"this",
"->",
"classLikeNamespaces",
")",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"reduceStmts",
"(",
"$",
"this",
"->",
"classLikeNamespaces",
")",
",",
"$",
"this",
"->",
"reduceStmts",
"(",
"$",
"this",
"->",
"namespaces",
")",
",",
"$",
"this",
"->",
"globalNamespace",
"->",
"stmts",
",",
"$",
"this",
"->",
"globalExpressions",
")",
";",
"}",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"classLikeNamespaces",
",",
"$",
"this",
"->",
"namespaces",
",",
"$",
"this",
"->",
"globalNamespace",
"->",
"stmts",
"?",
"[",
"$",
"this",
"->",
"globalNamespace",
"]",
":",
"[",
"]",
",",
"$",
"this",
"->",
"globalExpressions",
"?",
"[",
"new",
"Namespace_",
"(",
"null",
",",
"$",
"this",
"->",
"globalExpressions",
")",
"]",
":",
"[",
"]",
")",
";",
"}"
] |
Returns the stored set of stub nodes which are built up during traversal.
@return Node[]
|
[
"Returns",
"the",
"stored",
"set",
"of",
"stub",
"nodes",
"which",
"are",
"built",
"up",
"during",
"traversal",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L263-L284
|
27,476
|
GiacoCorsiglia/php-stubs-generator
|
src/NodeVisitor.php
|
NodeVisitor.count
|
private function count(string $type, string $name = null): bool
{
assert(isset($this->counts[$type]), 'Expected valid `$type`');
if (!$name) {
return false;
}
return ($this->counts[$type][$name] = ($this->counts[$type][$name] ?? 0) + 1) === 1;
}
|
php
|
private function count(string $type, string $name = null): bool
{
assert(isset($this->counts[$type]), 'Expected valid `$type`');
if (!$name) {
return false;
}
return ($this->counts[$type][$name] = ($this->counts[$type][$name] ?? 0) + 1) === 1;
}
|
[
"private",
"function",
"count",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"name",
"=",
"null",
")",
":",
"bool",
"{",
"assert",
"(",
"isset",
"(",
"$",
"this",
"->",
"counts",
"[",
"$",
"type",
"]",
")",
",",
"'Expected valid `$type`'",
")",
";",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"counts",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
"=",
"(",
"$",
"this",
"->",
"counts",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
"??",
"0",
")",
"+",
"1",
")",
"===",
"1",
";",
"}"
] |
Keeps a count of declarations by type and name of node.
@param string $type One of `array_keys($this->counts)`.
@param string|null $name Name of the node. Theoretically could be null.
@return bool If true, this is the first declaration of this type with
this name, so it can be safely included.
|
[
"Keeps",
"a",
"count",
"of",
"declarations",
"by",
"type",
"and",
"name",
"of",
"node",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L364-L373
|
27,477
|
GiacoCorsiglia/php-stubs-generator
|
src/NodeVisitor.php
|
NodeVisitor.resolveClassLike
|
private function resolveClassLike(ClassLikeWithDependencies $clwd): void
{
if (isset($this->resolvedClassLikes[$clwd->fullyQualifiedName])) {
// Already resolved.
return;
}
$this->resolvedClassLikes[$clwd->fullyQualifiedName] = true;
foreach ($clwd->dependencies as $dependencyName) {
if (isset($this->classLikes[$dependencyName])) {
$this->resolveClassLike($this->classLikes[$dependencyName]);
}
}
if (!$this->currentClassLikeNamespace) {
$namespaceMatches = false;
} elseif ($this->currentClassLikeNamespace->name) {
$namespaceMatches = $this->currentClassLikeNamespace->name->toString() === $clwd->namespace;
} else {
$namespaceMatches = !$clwd->namespace;
}
// Reduntant check to make Psalm happy.
if ($this->currentClassLikeNamespace && $namespaceMatches) {
$this->currentClassLikeNamespace->stmts[] = $clwd->node;
} else {
$name = $clwd->namespace ? new Name($clwd->namespace) : null;
$this->currentClassLikeNamespace = new Namespace_($name, [$clwd->node]);
$this->classLikeNamespaces[] = $this->currentClassLikeNamespace;
}
}
|
php
|
private function resolveClassLike(ClassLikeWithDependencies $clwd): void
{
if (isset($this->resolvedClassLikes[$clwd->fullyQualifiedName])) {
// Already resolved.
return;
}
$this->resolvedClassLikes[$clwd->fullyQualifiedName] = true;
foreach ($clwd->dependencies as $dependencyName) {
if (isset($this->classLikes[$dependencyName])) {
$this->resolveClassLike($this->classLikes[$dependencyName]);
}
}
if (!$this->currentClassLikeNamespace) {
$namespaceMatches = false;
} elseif ($this->currentClassLikeNamespace->name) {
$namespaceMatches = $this->currentClassLikeNamespace->name->toString() === $clwd->namespace;
} else {
$namespaceMatches = !$clwd->namespace;
}
// Reduntant check to make Psalm happy.
if ($this->currentClassLikeNamespace && $namespaceMatches) {
$this->currentClassLikeNamespace->stmts[] = $clwd->node;
} else {
$name = $clwd->namespace ? new Name($clwd->namespace) : null;
$this->currentClassLikeNamespace = new Namespace_($name, [$clwd->node]);
$this->classLikeNamespaces[] = $this->currentClassLikeNamespace;
}
}
|
[
"private",
"function",
"resolveClassLike",
"(",
"ClassLikeWithDependencies",
"$",
"clwd",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"resolvedClassLikes",
"[",
"$",
"clwd",
"->",
"fullyQualifiedName",
"]",
")",
")",
"{",
"// Already resolved.",
"return",
";",
"}",
"$",
"this",
"->",
"resolvedClassLikes",
"[",
"$",
"clwd",
"->",
"fullyQualifiedName",
"]",
"=",
"true",
";",
"foreach",
"(",
"$",
"clwd",
"->",
"dependencies",
"as",
"$",
"dependencyName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"classLikes",
"[",
"$",
"dependencyName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"resolveClassLike",
"(",
"$",
"this",
"->",
"classLikes",
"[",
"$",
"dependencyName",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"currentClassLikeNamespace",
")",
"{",
"$",
"namespaceMatches",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"currentClassLikeNamespace",
"->",
"name",
")",
"{",
"$",
"namespaceMatches",
"=",
"$",
"this",
"->",
"currentClassLikeNamespace",
"->",
"name",
"->",
"toString",
"(",
")",
"===",
"$",
"clwd",
"->",
"namespace",
";",
"}",
"else",
"{",
"$",
"namespaceMatches",
"=",
"!",
"$",
"clwd",
"->",
"namespace",
";",
"}",
"// Reduntant check to make Psalm happy.",
"if",
"(",
"$",
"this",
"->",
"currentClassLikeNamespace",
"&&",
"$",
"namespaceMatches",
")",
"{",
"$",
"this",
"->",
"currentClassLikeNamespace",
"->",
"stmts",
"[",
"]",
"=",
"$",
"clwd",
"->",
"node",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"clwd",
"->",
"namespace",
"?",
"new",
"Name",
"(",
"$",
"clwd",
"->",
"namespace",
")",
":",
"null",
";",
"$",
"this",
"->",
"currentClassLikeNamespace",
"=",
"new",
"Namespace_",
"(",
"$",
"name",
",",
"[",
"$",
"clwd",
"->",
"node",
"]",
")",
";",
"$",
"this",
"->",
"classLikeNamespaces",
"[",
"]",
"=",
"$",
"this",
"->",
"currentClassLikeNamespace",
";",
"}",
"}"
] |
Populates the `classLikeNamespaces` property with namespaces with classes
declared in a valid order.
@param ClassLikeWithDependencies $clwd
@return void
|
[
"Populates",
"the",
"classLikeNamespaces",
"property",
"with",
"namespaces",
"with",
"classes",
"declared",
"in",
"a",
"valid",
"order",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L382-L412
|
27,478
|
GiacoCorsiglia/php-stubs-generator
|
src/NodeVisitor.php
|
NodeVisitor.allAreGlobal
|
private function allAreGlobal(array $namespaces): bool
{
foreach ($namespaces as $namespace) {
if ($namespace->name && $namespace->name->toString() !== '') {
return false;
}
}
return true;
}
|
php
|
private function allAreGlobal(array $namespaces): bool
{
foreach ($namespaces as $namespace) {
if ($namespace->name && $namespace->name->toString() !== '') {
return false;
}
}
return true;
}
|
[
"private",
"function",
"allAreGlobal",
"(",
"array",
"$",
"namespaces",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"if",
"(",
"$",
"namespace",
"->",
"name",
"&&",
"$",
"namespace",
"->",
"name",
"->",
"toString",
"(",
")",
"!==",
"''",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Determines if each namespace in the list is a global namespace.
@param Namespace_[] $namespaces
@return bool
|
[
"Determines",
"if",
"each",
"namespace",
"in",
"the",
"list",
"is",
"a",
"global",
"namespace",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L420-L428
|
27,479
|
GiacoCorsiglia/php-stubs-generator
|
src/NodeVisitor.php
|
NodeVisitor.reduceStmts
|
private function reduceStmts(array $namespaces): array
{
$stmts = [];
foreach ($namespaces as $namespace) {
foreach ($namespace->stmts as $stmt) {
$stmts[] = $stmt;
}
}
return $stmts;
}
|
php
|
private function reduceStmts(array $namespaces): array
{
$stmts = [];
foreach ($namespaces as $namespace) {
foreach ($namespace->stmts as $stmt) {
$stmts[] = $stmt;
}
}
return $stmts;
}
|
[
"private",
"function",
"reduceStmts",
"(",
"array",
"$",
"namespaces",
")",
":",
"array",
"{",
"$",
"stmts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"foreach",
"(",
"$",
"namespace",
"->",
"stmts",
"as",
"$",
"stmt",
")",
"{",
"$",
"stmts",
"[",
"]",
"=",
"$",
"stmt",
";",
"}",
"}",
"return",
"$",
"stmts",
";",
"}"
] |
Merges the statements of each namespace into one array.
@param Namespace_[] $namespaces
@return Stmt[]
|
[
"Merges",
"the",
"statements",
"of",
"each",
"namespace",
"into",
"one",
"array",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L436-L445
|
27,480
|
hiqdev/yii2-data-mapper
|
src/components/EntityManager.php
|
EntityManager.getRepository
|
public function getRepository($entityClass)
{
if (is_object($entityClass)) {
$entityClass = get_class($entityClass);
}
if (!isset($this->repositories[$entityClass])) {
throw new \Exception("no repository defined for: $entityClass");
}
if (!is_object($this->repositories[$entityClass])) {
$this->repositories[$entityClass] = $this->di->get($this->repositories[$entityClass]);
}
return $this->repositories[$entityClass];
}
|
php
|
public function getRepository($entityClass)
{
if (is_object($entityClass)) {
$entityClass = get_class($entityClass);
}
if (!isset($this->repositories[$entityClass])) {
throw new \Exception("no repository defined for: $entityClass");
}
if (!is_object($this->repositories[$entityClass])) {
$this->repositories[$entityClass] = $this->di->get($this->repositories[$entityClass]);
}
return $this->repositories[$entityClass];
}
|
[
"public",
"function",
"getRepository",
"(",
"$",
"entityClass",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"entityClass",
")",
")",
"{",
"$",
"entityClass",
"=",
"get_class",
"(",
"$",
"entityClass",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"repositories",
"[",
"$",
"entityClass",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"no repository defined for: $entityClass\"",
")",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"repositories",
"[",
"$",
"entityClass",
"]",
")",
")",
"{",
"$",
"this",
"->",
"repositories",
"[",
"$",
"entityClass",
"]",
"=",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"$",
"this",
"->",
"repositories",
"[",
"$",
"entityClass",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"repositories",
"[",
"$",
"entityClass",
"]",
";",
"}"
] |
Get entity repository by entity or class.
@param object|string $entityClass entity or class
@return BaseRepository
|
[
"Get",
"entity",
"repository",
"by",
"entity",
"or",
"class",
"."
] |
2e39de404b010b2beb527b913ddf3149422ed738
|
https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/components/EntityManager.php#L75-L90
|
27,481
|
contributte/utils
|
src/DateTime.php
|
DateTime.setCurrentTime
|
public function setCurrentTime(): self
{
return $this->modifyClone()->setTime((int) date('H'), (int) date('i'), (int) date('s'));
}
|
php
|
public function setCurrentTime(): self
{
return $this->modifyClone()->setTime((int) date('H'), (int) date('i'), (int) date('s'));
}
|
[
"public",
"function",
"setCurrentTime",
"(",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"modifyClone",
"(",
")",
"->",
"setTime",
"(",
"(",
"int",
")",
"date",
"(",
"'H'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'i'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'s'",
")",
")",
";",
"}"
] |
Set time to current time
|
[
"Set",
"time",
"to",
"current",
"time"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/DateTime.php#L37-L40
|
27,482
|
contributte/utils
|
src/DateTime.php
|
DateTime.setToday
|
public function setToday(): self
{
return $this->modifyClone()->setDate((int) date('Y'), (int) date('m'), (int) date('d'));
}
|
php
|
public function setToday(): self
{
return $this->modifyClone()->setDate((int) date('Y'), (int) date('m'), (int) date('d'));
}
|
[
"public",
"function",
"setToday",
"(",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"modifyClone",
"(",
")",
"->",
"setDate",
"(",
"(",
"int",
")",
"date",
"(",
"'Y'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'m'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'d'",
")",
")",
";",
"}"
] |
Set date to today
|
[
"Set",
"date",
"to",
"today"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/DateTime.php#L69-L72
|
27,483
|
TargetLiu/PHPRedis
|
src/Database.php
|
Database.createClient
|
protected function createClient(array $servers)
{
$clients = [];
foreach ($servers as $key => $server) {
$clients[$key] = new \Redis();
$clients[$key]->pconnect($server['host'], $server['port'], 0, $key . $server['database']);
if (!empty($server['password'])) {
$clients[$key]->auth($server['password']);
}
if (!empty($server['database'])) {
$clients[$key]->select($server['database']);
}
}
return $clients;
}
|
php
|
protected function createClient(array $servers)
{
$clients = [];
foreach ($servers as $key => $server) {
$clients[$key] = new \Redis();
$clients[$key]->pconnect($server['host'], $server['port'], 0, $key . $server['database']);
if (!empty($server['password'])) {
$clients[$key]->auth($server['password']);
}
if (!empty($server['database'])) {
$clients[$key]->select($server['database']);
}
}
return $clients;
}
|
[
"protected",
"function",
"createClient",
"(",
"array",
"$",
"servers",
")",
"{",
"$",
"clients",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"key",
"=>",
"$",
"server",
")",
"{",
"$",
"clients",
"[",
"$",
"key",
"]",
"=",
"new",
"\\",
"Redis",
"(",
")",
";",
"$",
"clients",
"[",
"$",
"key",
"]",
"->",
"pconnect",
"(",
"$",
"server",
"[",
"'host'",
"]",
",",
"$",
"server",
"[",
"'port'",
"]",
",",
"0",
",",
"$",
"key",
".",
"$",
"server",
"[",
"'database'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"server",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"clients",
"[",
"$",
"key",
"]",
"->",
"auth",
"(",
"$",
"server",
"[",
"'password'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"server",
"[",
"'database'",
"]",
")",
")",
"{",
"$",
"clients",
"[",
"$",
"key",
"]",
"->",
"select",
"(",
"$",
"server",
"[",
"'database'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"clients",
";",
"}"
] |
Create an array of connection clients.
@param array $servers
@param array $options
@return array
|
[
"Create",
"an",
"array",
"of",
"connection",
"clients",
"."
] |
5930a9233e603754ff284c35a96575ed1e384af1
|
https://github.com/TargetLiu/PHPRedis/blob/5930a9233e603754ff284c35a96575ed1e384af1/src/Database.php#L62-L79
|
27,484
|
hiqdev/yii2-data-mapper
|
src/repositories/BaseRepository.php
|
BaseRepository.findByIds
|
public function findByIds(array $ids): array
{
$spec = $this->createSpecification()->where(['id' => $ids]);
return $this->findAll($spec);
}
|
php
|
public function findByIds(array $ids): array
{
$spec = $this->createSpecification()->where(['id' => $ids]);
return $this->findAll($spec);
}
|
[
"public",
"function",
"findByIds",
"(",
"array",
"$",
"ids",
")",
":",
"array",
"{",
"$",
"spec",
"=",
"$",
"this",
"->",
"createSpecification",
"(",
")",
"->",
"where",
"(",
"[",
"'id'",
"=>",
"$",
"ids",
"]",
")",
";",
"return",
"$",
"this",
"->",
"findAll",
"(",
"$",
"spec",
")",
";",
"}"
] |
Selects entities from DB by given IDs.
@param string[] $ids
@return array
|
[
"Selects",
"entities",
"from",
"DB",
"by",
"given",
"IDs",
"."
] |
2e39de404b010b2beb527b913ddf3149422ed738
|
https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/repositories/BaseRepository.php#L68-L73
|
27,485
|
TargetLiu/PHPRedis
|
src/Queue/PHPRedisQueue.php
|
PHPRedisQueue.migrateAllExpiredJobs
|
protected function migrateAllExpiredJobs($queue)
{
$this->migrateExpiredJobs($queue . ':delayed', $queue);
$this->migrateExpiredJobs($queue . ':reserved', $queue);
}
|
php
|
protected function migrateAllExpiredJobs($queue)
{
$this->migrateExpiredJobs($queue . ':delayed', $queue);
$this->migrateExpiredJobs($queue . ':reserved', $queue);
}
|
[
"protected",
"function",
"migrateAllExpiredJobs",
"(",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"migrateExpiredJobs",
"(",
"$",
"queue",
".",
"':delayed'",
",",
"$",
"queue",
")",
";",
"$",
"this",
"->",
"migrateExpiredJobs",
"(",
"$",
"queue",
".",
"':reserved'",
",",
"$",
"queue",
")",
";",
"}"
] |
Migrate all of the waiting jobs in the queue.
@param string $queue
@return void
|
[
"Migrate",
"all",
"of",
"the",
"waiting",
"jobs",
"in",
"the",
"queue",
"."
] |
5930a9233e603754ff284c35a96575ed1e384af1
|
https://github.com/TargetLiu/PHPRedis/blob/5930a9233e603754ff284c35a96575ed1e384af1/src/Queue/PHPRedisQueue.php#L161-L166
|
27,486
|
contributte/utils
|
src/Strings.php
|
Strings.spaceless
|
public static function spaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s#', '');
return $s;
}
|
php
|
public static function spaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s#', '');
return $s;
}
|
[
"public",
"static",
"function",
"spaceless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\s#'",
",",
"''",
")",
";",
"return",
"$",
"s",
";",
"}"
] |
Remove spaces from the beginning and end of a string
and between chars
@return mixed
|
[
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"between",
"chars"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L40-L46
|
27,487
|
contributte/utils
|
src/Strings.php
|
Strings.doublespaceless
|
public static function doublespaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s{2,}#', ' ');
return $s;
}
|
php
|
public static function doublespaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s{2,}#', ' ');
return $s;
}
|
[
"public",
"static",
"function",
"doublespaceless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\s{2,}#'",
",",
"' '",
")",
";",
"return",
"$",
"s",
";",
"}"
] |
Remove spaces from the beginning and end of a string
and convert double and more spaces between chars to one space
@return mixed
|
[
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"convert",
"double",
"and",
"more",
"spaces",
"between",
"chars",
"to",
"one",
"space"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L54-L60
|
27,488
|
contributte/utils
|
src/Strings.php
|
Strings.dashless
|
public static function dashless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\-#', '');
return $s;
}
|
php
|
public static function dashless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\-#', '');
return $s;
}
|
[
"public",
"static",
"function",
"dashless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\-#'",
",",
"''",
")",
";",
"return",
"$",
"s",
";",
"}"
] |
Remove spaces from the beginning and end of a string and remove dashes
@return mixed
|
[
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"remove",
"dashes"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L67-L73
|
27,489
|
contributte/utils
|
src/Strings.php
|
Strings.slashless
|
public static function slashless(string $s): string
{
$s = trim($s);
$s = self::replace($s, '#\/{2,}#', '/');
return $s;
}
|
php
|
public static function slashless(string $s): string
{
$s = trim($s);
$s = self::replace($s, '#\/{2,}#', '/');
return $s;
}
|
[
"public",
"static",
"function",
"slashless",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\/{2,}#'",
",",
"'/'",
")",
";",
"return",
"$",
"s",
";",
"}"
] |
Remove spaces from the beginning and end of a string
and convert double and more slashes between chars to one slash
|
[
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"convert",
"double",
"and",
"more",
"slashes",
"between",
"chars",
"to",
"one",
"slash"
] |
3afb4010ee60fd01307850c13000b1918dc90859
|
https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L79-L85
|
27,490
|
hiqdev/yii2-data-mapper
|
src/hydrator/ConfigurableAggregateHydrator.php
|
ConfigurableAggregateHydrator.extractAll
|
public function extractAll(array $array, int $depth = 1)
{
$depth--;
$res = [];
foreach ($array as $key => $object) {
$res[$key] = $depth>0 ? $this->extractAll($object, $depth) : $this->extract($object);
}
return $res;
}
|
php
|
public function extractAll(array $array, int $depth = 1)
{
$depth--;
$res = [];
foreach ($array as $key => $object) {
$res[$key] = $depth>0 ? $this->extractAll($object, $depth) : $this->extract($object);
}
return $res;
}
|
[
"public",
"function",
"extractAll",
"(",
"array",
"$",
"array",
",",
"int",
"$",
"depth",
"=",
"1",
")",
"{",
"$",
"depth",
"--",
";",
"$",
"res",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{",
"$",
"res",
"[",
"$",
"key",
"]",
"=",
"$",
"depth",
">",
"0",
"?",
"$",
"this",
"->",
"extractAll",
"(",
"$",
"object",
",",
"$",
"depth",
")",
":",
"$",
"this",
"->",
"extract",
"(",
"$",
"object",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
Extract multiple objects.
@param array $array
@return array
|
[
"Extract",
"multiple",
"objects",
"."
] |
2e39de404b010b2beb527b913ddf3149422ed738
|
https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/hydrator/ConfigurableAggregateHydrator.php#L105-L114
|
27,491
|
GiacoCorsiglia/php-stubs-generator
|
src/Result.php
|
Result.getDuplicates
|
public function getDuplicates(): array
{
$dupes = [];
foreach ($this->visitor->getCounts() as $type => $names) {
foreach ($names as $name => $count) {
if ($count > 1) {
$dupes[] = [
'type' => $type,
'name' => $type === 'globals' ? '$' . $name : ltrim($name, '\\'),
'count' => $count,
];
}
}
}
usort($dupes, function (array $a, array $b): int {
return $a['type'] <=> $b['type'] ?: $a['name'] <=> $b['name'];
});
return $dupes;
}
|
php
|
public function getDuplicates(): array
{
$dupes = [];
foreach ($this->visitor->getCounts() as $type => $names) {
foreach ($names as $name => $count) {
if ($count > 1) {
$dupes[] = [
'type' => $type,
'name' => $type === 'globals' ? '$' . $name : ltrim($name, '\\'),
'count' => $count,
];
}
}
}
usort($dupes, function (array $a, array $b): int {
return $a['type'] <=> $b['type'] ?: $a['name'] <=> $b['name'];
});
return $dupes;
}
|
[
"public",
"function",
"getDuplicates",
"(",
")",
":",
"array",
"{",
"$",
"dupes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"visitor",
"->",
"getCounts",
"(",
")",
"as",
"$",
"type",
"=>",
"$",
"names",
")",
"{",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
"=>",
"$",
"count",
")",
"{",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"$",
"dupes",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'name'",
"=>",
"$",
"type",
"===",
"'globals'",
"?",
"'$'",
".",
"$",
"name",
":",
"ltrim",
"(",
"$",
"name",
",",
"'\\\\'",
")",
",",
"'count'",
"=>",
"$",
"count",
",",
"]",
";",
"}",
"}",
"}",
"usort",
"(",
"$",
"dupes",
",",
"function",
"(",
"array",
"$",
"a",
",",
"array",
"$",
"b",
")",
":",
"int",
"{",
"return",
"$",
"a",
"[",
"'type'",
"]",
"<=>",
"$",
"b",
"[",
"'type'",
"]",
"?",
":",
"$",
"a",
"[",
"'name'",
"]",
"<=>",
"$",
"b",
"[",
"'name'",
"]",
";",
"}",
")",
";",
"return",
"$",
"dupes",
";",
"}"
] |
Returns a list which includes any symbols for which more than one
declaration was found during stub generation.
@return (string|int)[][]
@psalm-return array<array{ type: string, name: string, count: int }>
|
[
"Returns",
"a",
"list",
"which",
"includes",
"any",
"symbols",
"for",
"which",
"more",
"than",
"one",
"declaration",
"was",
"found",
"during",
"stub",
"generation",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/Result.php#L75-L95
|
27,492
|
GiacoCorsiglia/php-stubs-generator
|
src/Result.php
|
Result.prettyPrint
|
public function prettyPrint(PrettyPrinterAbstract $printer = null): string
{
if (!$printer) {
$printer = new Standard();
}
return $printer->prettyPrintFile($this->getStubStmts());
}
|
php
|
public function prettyPrint(PrettyPrinterAbstract $printer = null): string
{
if (!$printer) {
$printer = new Standard();
}
return $printer->prettyPrintFile($this->getStubStmts());
}
|
[
"public",
"function",
"prettyPrint",
"(",
"PrettyPrinterAbstract",
"$",
"printer",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"printer",
")",
"{",
"$",
"printer",
"=",
"new",
"Standard",
"(",
")",
";",
"}",
"return",
"$",
"printer",
"->",
"prettyPrintFile",
"(",
"$",
"this",
"->",
"getStubStmts",
"(",
")",
")",
";",
"}"
] |
Shortcut to pretty print all the stubs as one file.
If no `$printer` is provided, a `\PhpParser\PrettyPrinter\Standard` will
be used.
@param PrettyPrinterAbstract|null $printer Pretty printer instance.
@return string The pretty printed version.
|
[
"Shortcut",
"to",
"pretty",
"print",
"all",
"the",
"stubs",
"as",
"one",
"file",
"."
] |
c5796427ebc8052c6c662e5101e8250ed5f295fe
|
https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/Result.php#L107-L113
|
27,493
|
vanry/laravel-scout-tntsearch
|
src/TokenizerManager.php
|
TokenizerManager.createAnalysisDriver
|
public function createAnalysisDriver()
{
$analysis = new Phpanalysis;
foreach ($this->getConfig('analysis') as $key => $value) {
$key = camel_case($key);
if (property_exists($analysis, $key)) {
$analysis->$key = $value;
}
}
return new PhpAnalysisTokenizer($analysis);
}
|
php
|
public function createAnalysisDriver()
{
$analysis = new Phpanalysis;
foreach ($this->getConfig('analysis') as $key => $value) {
$key = camel_case($key);
if (property_exists($analysis, $key)) {
$analysis->$key = $value;
}
}
return new PhpAnalysisTokenizer($analysis);
}
|
[
"public",
"function",
"createAnalysisDriver",
"(",
")",
"{",
"$",
"analysis",
"=",
"new",
"Phpanalysis",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'analysis'",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"camel_case",
"(",
"$",
"key",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"analysis",
",",
"$",
"key",
")",
")",
"{",
"$",
"analysis",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"new",
"PhpAnalysisTokenizer",
"(",
"$",
"analysis",
")",
";",
"}"
] |
Create a PhpAnalysis tokenizer instance.
@return \Vanry\Scout\Tokenizers\PhpAnalysisTokenizer
|
[
"Create",
"a",
"PhpAnalysis",
"tokenizer",
"instance",
"."
] |
ece71f76030f2c055214ec496a21e123388fa63f
|
https://github.com/vanry/laravel-scout-tntsearch/blob/ece71f76030f2c055214ec496a21e123388fa63f/src/TokenizerManager.php#L30-L43
|
27,494
|
Litepie/Message
|
src/Message.php
|
Message.count
|
public function count($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailCount();
}
|
php
|
public function count($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailCount();
}
|
[
"public",
"function",
"count",
"(",
"$",
"folder",
",",
"$",
"label",
"=",
"null",
",",
"$",
"read",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"pushCriteria",
"(",
"new",
"MessageResourceCriteria",
"(",
"$",
"folder",
",",
"$",
"label",
",",
"$",
"read",
")",
")",
"->",
"mailCount",
"(",
")",
";",
"}"
] |
Returns count of message.
@param array $filter
@return int
|
[
"Returns",
"count",
"of",
"message",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Message.php#L31-L36
|
27,495
|
Litepie/Message
|
src/Message.php
|
Message.list
|
public function list($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailList();
}
|
php
|
public function list($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailList();
}
|
[
"public",
"function",
"list",
"(",
"$",
"folder",
",",
"$",
"label",
"=",
"null",
",",
"$",
"read",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"pushCriteria",
"(",
"new",
"MessageResourceCriteria",
"(",
"$",
"folder",
",",
"$",
"label",
",",
"$",
"read",
")",
")",
"->",
"mailList",
"(",
")",
";",
"}"
] |
Returns count of message with given label.
@param array $filter
@return int
|
[
"Returns",
"count",
"of",
"message",
"with",
"given",
"label",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Message.php#L45-L50
|
27,496
|
Litepie/Message
|
src/Http/Requests/MessageRequest.php
|
MessageRequest.canAccess
|
protected function canAccess()
{
if ($this->formRequest->user()->isAdmin() || $this->formRequest->user()->isUser()) {
return true;
}
return $this->formRequest->user()->canDo('message.message.view');
}
|
php
|
protected function canAccess()
{
if ($this->formRequest->user()->isAdmin() || $this->formRequest->user()->isUser()) {
return true;
}
return $this->formRequest->user()->canDo('message.message.view');
}
|
[
"protected",
"function",
"canAccess",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formRequest",
"->",
"user",
"(",
")",
"->",
"isAdmin",
"(",
")",
"||",
"$",
"this",
"->",
"formRequest",
"->",
"user",
"(",
")",
"->",
"isUser",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"formRequest",
"->",
"user",
"(",
")",
"->",
"canDo",
"(",
"'message.message.view'",
")",
";",
"}"
] |
Check whether the user can access the module.
@return bool
|
[
"Check",
"whether",
"the",
"user",
"can",
"access",
"the",
"module",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Requests/MessageRequest.php#L78-L85
|
27,497
|
Litepie/Message
|
src/Policies/MessagePolicy.php
|
MessagePolicy.view
|
public function view(UserPolicy $user, Message $message)
{
if ($user->canDo('message.message.view') && $user->hasRole('admin')) {
return true;
}
return $user->id == $message->user_id && get_class($user) == $message->user_type;
}
|
php
|
public function view(UserPolicy $user, Message $message)
{
if ($user->canDo('message.message.view') && $user->hasRole('admin')) {
return true;
}
return $user->id == $message->user_id && get_class($user) == $message->user_type;
}
|
[
"public",
"function",
"view",
"(",
"UserPolicy",
"$",
"user",
",",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'message.message.view'",
")",
"&&",
"$",
"user",
"->",
"hasRole",
"(",
"'admin'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"message",
"->",
"user_id",
"&&",
"get_class",
"(",
"$",
"user",
")",
"==",
"$",
"message",
"->",
"user_type",
";",
"}"
] |
Determine if the given user can view the message.
@param User $user
@param Message $message
@return bool
|
[
"Determine",
"if",
"the",
"given",
"user",
"can",
"view",
"the",
"message",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Policies/MessagePolicy.php#L18-L25
|
27,498
|
Litepie/Message
|
src/Policies/MessagePolicy.php
|
MessagePolicy.update
|
public function update(UserPolicy $user, Message $message)
{
return $user->id == $message->user_id && get_class($user) == $message->user_type;
}
|
php
|
public function update(UserPolicy $user, Message $message)
{
return $user->id == $message->user_id && get_class($user) == $message->user_type;
}
|
[
"public",
"function",
"update",
"(",
"UserPolicy",
"$",
"user",
",",
"Message",
"$",
"message",
")",
"{",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"message",
"->",
"user_id",
"&&",
"get_class",
"(",
"$",
"user",
")",
"==",
"$",
"message",
"->",
"user_type",
";",
"}"
] |
Determine if the given user can update the given message.
@param User $user
@param Message $message
@return bool
|
[
"Determine",
"if",
"the",
"given",
"user",
"can",
"update",
"the",
"given",
"message",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Policies/MessagePolicy.php#L48-L51
|
27,499
|
Litepie/Message
|
src/Http/Controllers/MessageResourceController.php
|
MessageResourceController.index
|
public function index(MessageRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litepie\Message\Repositories\Presenter\MessageListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$messages = $this->repository->paginate();
return $this->response->title(trans('message::message.names'))
->view('message::message.index', true)
->data(compact('messages'))
->output();
}
|
php
|
public function index(MessageRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litepie\Message\Repositories\Presenter\MessageListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$messages = $this->repository->paginate();
return $this->response->title(trans('message::message.names'))
->view('message::message.index', true)
->data(compact('messages'))
->output();
}
|
[
"public",
"function",
"index",
"(",
"MessageRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"typeIs",
"(",
"'json'",
")",
")",
"{",
"$",
"pageLimit",
"=",
"$",
"request",
"->",
"input",
"(",
"'pageLimit'",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"repository",
"->",
"setPresenter",
"(",
"\\",
"Litepie",
"\\",
"Message",
"\\",
"Repositories",
"\\",
"Presenter",
"\\",
"MessageListPresenter",
"::",
"class",
")",
"->",
"getDataTable",
"(",
"$",
"pageLimit",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"data",
"(",
"$",
"data",
")",
"->",
"output",
"(",
")",
";",
"}",
"$",
"messages",
"=",
"$",
"this",
"->",
"repository",
"->",
"paginate",
"(",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"title",
"(",
"trans",
"(",
"'message::message.names'",
")",
")",
"->",
"view",
"(",
"'message::message.index'",
",",
"true",
")",
"->",
"data",
"(",
"compact",
"(",
"'messages'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] |
Display a list of message.
@return Response
|
[
"Display",
"a",
"list",
"of",
"message",
"."
] |
6c123f0feea627d572141fd71935250f3ba3cad0
|
https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L36-L56
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.