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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
PitonCMS/Session | src/SessionHandler.php | SessionHandler.setFlashData | public function setFlashData($newdata, $value = '')
{
if (is_string($newdata)) {
$newdata = [$newdata => $value];
}
if (!empty($newdata)) {
foreach ($newdata as $key => $val) {
$this->newFlashData[$key] = $val;
}
}
} | php | public function setFlashData($newdata, $value = '')
{
if (is_string($newdata)) {
$newdata = [$newdata => $value];
}
if (!empty($newdata)) {
foreach ($newdata as $key => $val) {
$this->newFlashData[$key] = $val;
}
}
} | [
"public",
"function",
"setFlashData",
"(",
"$",
"newdata",
",",
"$",
"value",
"=",
"''",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"newdata",
")",
")",
"{",
"$",
"newdata",
"=",
"[",
"$",
"newdata",
"=>",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"newdata",
")",
")",
"{",
"foreach",
"(",
"$",
"newdata",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"newFlashData",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}"
] | Set Flash Data
Set flash data that will persist only until next request
@param mixed $newdata Flash data array or string (key)
@param string $value Value for single key | [
"Set",
"Flash",
"Data"
] | ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed | https://github.com/PitonCMS/Session/blob/ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed/src/SessionHandler.php#L240-L251 | train |
PitonCMS/Session | src/SessionHandler.php | SessionHandler.getFlashData | public function getFlashData($key = null)
{
if ($key === null) {
return $this->lastFlashData;
}
return isset($this->lastFlashData[$key]) ? $this->lastFlashData[$key] : null;
} | php | public function getFlashData($key = null)
{
if ($key === null) {
return $this->lastFlashData;
}
return isset($this->lastFlashData[$key]) ? $this->lastFlashData[$key] : null;
} | [
"public",
"function",
"getFlashData",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"lastFlashData",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"lastFlashData",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"lastFlashData",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Get Flash Data
Returns flash data
@param string $key Flash data array key
@return mixed Value or array | [
"Get",
"Flash",
"Data"
] | ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed | https://github.com/PitonCMS/Session/blob/ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed/src/SessionHandler.php#L260-L267 | train |
PitonCMS/Session | src/SessionHandler.php | SessionHandler.write | private function write()
{
$sessionData['data'] = $this->data;
$sessionData['flash'] = $this->newFlashData;
// Write session data to database
$stmt = $this->db->prepare("UPDATE {$this->tableName} SET data = ? WHERE session_id = ?");
$stmt->execute([json_encode($sessionData), $this->sessionId]);
} | php | private function write()
{
$sessionData['data'] = $this->data;
$sessionData['flash'] = $this->newFlashData;
// Write session data to database
$stmt = $this->db->prepare("UPDATE {$this->tableName} SET data = ? WHERE session_id = ?");
$stmt->execute([json_encode($sessionData), $this->sessionId]);
} | [
"private",
"function",
"write",
"(",
")",
"{",
"$",
"sessionData",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"data",
";",
"$",
"sessionData",
"[",
"'flash'",
"]",
"=",
"$",
"this",
"->",
"newFlashData",
";",
"// Write session data to database",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"\"UPDATE {$this->tableName} SET data = ? WHERE session_id = ?\"",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"json_encode",
"(",
"$",
"sessionData",
")",
",",
"$",
"this",
"->",
"sessionId",
"]",
")",
";",
"}"
] | Write Session Data
Writes session data to the database.
@return void | [
"Write",
"Session",
"Data"
] | ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed | https://github.com/PitonCMS/Session/blob/ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed/src/SessionHandler.php#L377-L385 | train |
PitonCMS/Session | src/SessionHandler.php | SessionHandler.cleanExpired | private function cleanExpired()
{
// 10% chance to clean the database of expired sessions
if (mt_rand(1, 10) == 1) {
$expiredTime = $this->now - $this->secondsUntilExpiration;
$stmt = $this->db->prepare("DELETE FROM {$this->tableName} WHERE time_updated < {$expiredTime}");
$stmt->execute();
}
} | php | private function cleanExpired()
{
// 10% chance to clean the database of expired sessions
if (mt_rand(1, 10) == 1) {
$expiredTime = $this->now - $this->secondsUntilExpiration;
$stmt = $this->db->prepare("DELETE FROM {$this->tableName} WHERE time_updated < {$expiredTime}");
$stmt->execute();
}
} | [
"private",
"function",
"cleanExpired",
"(",
")",
"{",
"// 10% chance to clean the database of expired sessions",
"if",
"(",
"mt_rand",
"(",
"1",
",",
"10",
")",
"==",
"1",
")",
"{",
"$",
"expiredTime",
"=",
"$",
"this",
"->",
"now",
"-",
"$",
"this",
"->",
"secondsUntilExpiration",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"\"DELETE FROM {$this->tableName} WHERE time_updated < {$expiredTime}\"",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"}",
"}"
] | Clean Old Sessions
Removes expired sessions from the database
@return void | [
"Clean",
"Old",
"Sessions"
] | ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed | https://github.com/PitonCMS/Session/blob/ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed/src/SessionHandler.php#L412-L420 | train |
PitonCMS/Session | src/SessionHandler.php | SessionHandler.generateId | private function generateId()
{
$randomNumber = mt_rand(0, mt_getrandmax());
$ipAddressFragment = md5(substr($this->ipAddress, 0, 5));
$timestamp = md5(microtime(true) . $this->now);
return hash('sha256', $randomNumber . $ipAddressFragment . $this->salt . $timestamp);
} | php | private function generateId()
{
$randomNumber = mt_rand(0, mt_getrandmax());
$ipAddressFragment = md5(substr($this->ipAddress, 0, 5));
$timestamp = md5(microtime(true) . $this->now);
return hash('sha256', $randomNumber . $ipAddressFragment . $this->salt . $timestamp);
} | [
"private",
"function",
"generateId",
"(",
")",
"{",
"$",
"randomNumber",
"=",
"mt_rand",
"(",
"0",
",",
"mt_getrandmax",
"(",
")",
")",
";",
"$",
"ipAddressFragment",
"=",
"md5",
"(",
"substr",
"(",
"$",
"this",
"->",
"ipAddress",
",",
"0",
",",
"5",
")",
")",
";",
"$",
"timestamp",
"=",
"md5",
"(",
"microtime",
"(",
"true",
")",
".",
"$",
"this",
"->",
"now",
")",
";",
"return",
"hash",
"(",
"'sha256'",
",",
"$",
"randomNumber",
".",
"$",
"ipAddressFragment",
".",
"$",
"this",
"->",
"salt",
".",
"$",
"timestamp",
")",
";",
"}"
] | Generate New Session ID
Create a unique session ID
@return string | [
"Generate",
"New",
"Session",
"ID"
] | ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed | https://github.com/PitonCMS/Session/blob/ac7fdb75e9fab92941ee28cff5ae29952a7ca5ed/src/SessionHandler.php#L428-L435 | train |
froq/froq-collection | src/Collection.php | Collection.hasValue | public function hasValue($value, bool $strict = false): bool
{
return in_array($value, $this->data, $strict);
} | php | public function hasValue($value, bool $strict = false): bool
{
return in_array($value, $this->data, $strict);
} | [
"public",
"function",
"hasValue",
"(",
"$",
"value",
",",
"bool",
"$",
"strict",
"=",
"false",
")",
":",
"bool",
"{",
"return",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"data",
",",
"$",
"strict",
")",
";",
"}"
] | Has value.
@param any $value
@param bool $strict
@return bool | [
"Has",
"value",
"."
] | 0d5e89a820d805af69835d3269d3ec45ad02716e | https://github.com/froq/froq-collection/blob/0d5e89a820d805af69835d3269d3ec45ad02716e/src/Collection.php#L250-L253 | train |
froq/froq-collection | src/Collection.php | Collection.pullAll | public function pullAll(array $keys, $valueDefault = null): array
{
return Arrays::pullAll($this->data, $keys, $valueDefault);
} | php | public function pullAll(array $keys, $valueDefault = null): array
{
return Arrays::pullAll($this->data, $keys, $valueDefault);
} | [
"public",
"function",
"pullAll",
"(",
"array",
"$",
"keys",
",",
"$",
"valueDefault",
"=",
"null",
")",
":",
"array",
"{",
"return",
"Arrays",
"::",
"pullAll",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"keys",
",",
"$",
"valueDefault",
")",
";",
"}"
] | Pull all.
@param array $keys
@param any $valueDefault
@return any
@since 3.0 | [
"Pull",
"all",
"."
] | 0d5e89a820d805af69835d3269d3ec45ad02716e | https://github.com/froq/froq-collection/blob/0d5e89a820d805af69835d3269d3ec45ad02716e/src/Collection.php#L274-L277 | train |
frameworkwtf/auth | src/Auth/Middleware/RBAC.php | RBAC.isAllowed | protected function isAllowed(ServerRequestInterface $request, string $role): bool
{
$route = $request->getAttribute('route');
// Get config string like 'routes./home.second.rbac.anonymous' to get rbac config for route with name "second" in route group "home"
$config = 'routes.'.$route->getGroups()[0]->getPattern().'.'.\strtr('/'.$route->getName(), [$route->getGroups()[0]->getPattern() => '', '-' => '']).'.rbac.'.$role;
if (\in_array($request->getMethod(), $this->config($config, []), true)) {
return true;
}
return false;
} | php | protected function isAllowed(ServerRequestInterface $request, string $role): bool
{
$route = $request->getAttribute('route');
// Get config string like 'routes./home.second.rbac.anonymous' to get rbac config for route with name "second" in route group "home"
$config = 'routes.'.$route->getGroups()[0]->getPattern().'.'.\strtr('/'.$route->getName(), [$route->getGroups()[0]->getPattern() => '', '-' => '']).'.rbac.'.$role;
if (\in_array($request->getMethod(), $this->config($config, []), true)) {
return true;
}
return false;
} | [
"protected",
"function",
"isAllowed",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"string",
"$",
"role",
")",
":",
"bool",
"{",
"$",
"route",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'route'",
")",
";",
"// Get config string like 'routes./home.second.rbac.anonymous' to get rbac config for route with name \"second\" in route group \"home\"",
"$",
"config",
"=",
"'routes.'",
".",
"$",
"route",
"->",
"getGroups",
"(",
")",
"[",
"0",
"]",
"->",
"getPattern",
"(",
")",
".",
"'.'",
".",
"\\",
"strtr",
"(",
"'/'",
".",
"$",
"route",
"->",
"getName",
"(",
")",
",",
"[",
"$",
"route",
"->",
"getGroups",
"(",
")",
"[",
"0",
"]",
"->",
"getPattern",
"(",
")",
"=>",
"''",
",",
"'-'",
"=>",
"''",
"]",
")",
".",
"'.rbac.'",
".",
"$",
"role",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"this",
"->",
"config",
"(",
"$",
"config",
",",
"[",
"]",
")",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if request allowed for current user.
@param ServerRequestInterface $request
@param string $role
@return bool | [
"Check",
"if",
"request",
"allowed",
"for",
"current",
"user",
"."
] | 2535d19ee326d1b491e36a341fe06d00bcc0731e | https://github.com/frameworkwtf/auth/blob/2535d19ee326d1b491e36a341fe06d00bcc0731e/src/Auth/Middleware/RBAC.php#L57-L67 | train |
prolic/HumusMvc | src/HumusMvc/Service/FrontControllerFactory.php | FrontControllerFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$frontController = FrontController::getInstance();
// handle injections
$frontController->setDispatcher($serviceLocator->get('Dispatcher'));
$frontController->setRequest($serviceLocator->get('Request'));
$frontController->setResponse($serviceLocator->get('Response'));
$frontController->setRouter($serviceLocator->get('Router'));
// get config
$appConfig = $serviceLocator->get('Config');
if (isset($appConfig['front_controller'])) {
$config = ArrayUtils::merge($this->defaultOptions, $appConfig['front_controller']);
} else {
$config = $this->defaultOptions;
}
// handle configuration
$frontController->setModuleControllerDirectoryName($config['module_controller_directory_name']);
$frontController->setBaseUrl($config['base_url']);
$frontController->setControllerDirectory($config['controller_directory']);
$frontController->throwExceptions($config['throw_exceptions']);
$frontController->returnResponse($config['return_response']);
$frontController->setDefaultModule($config['default_module']);
$frontController->setDefaultAction($config['default_action']);
$frontController->setDefaultControllerName($config['default_controller_name']);
$frontController->setParams($config['params']);
foreach ($config['plugins'] as $plugin) {
if (is_array(($plugin))) {
$pluginClass = $plugin['class'];
$stackIndex = $plugin['stack_index'];
} else {
$pluginClass = $plugin;
$stackIndex = null;
}
// plugins can be loaded with service locator
if ($serviceLocator->has($pluginClass)) {
$plugin = $serviceLocator->get($pluginClass);
} else {
$plugin = new $pluginClass();
}
$frontController->registerPlugin($plugin, $stackIndex);
}
// set action helper plugin manager
$actionHelperManager = $serviceLocator->get('ActionHelperManager');
ActionHelperBroker::setPluginLoader($actionHelperManager);
ActionHelperBroker::addHelper($actionHelperManager->get('viewRenderer'));
// start layout, if needed
if (isset($appConfig['layout'])) {
Layout::startMvc($appConfig['layout']);
}
return $frontController;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$frontController = FrontController::getInstance();
// handle injections
$frontController->setDispatcher($serviceLocator->get('Dispatcher'));
$frontController->setRequest($serviceLocator->get('Request'));
$frontController->setResponse($serviceLocator->get('Response'));
$frontController->setRouter($serviceLocator->get('Router'));
// get config
$appConfig = $serviceLocator->get('Config');
if (isset($appConfig['front_controller'])) {
$config = ArrayUtils::merge($this->defaultOptions, $appConfig['front_controller']);
} else {
$config = $this->defaultOptions;
}
// handle configuration
$frontController->setModuleControllerDirectoryName($config['module_controller_directory_name']);
$frontController->setBaseUrl($config['base_url']);
$frontController->setControllerDirectory($config['controller_directory']);
$frontController->throwExceptions($config['throw_exceptions']);
$frontController->returnResponse($config['return_response']);
$frontController->setDefaultModule($config['default_module']);
$frontController->setDefaultAction($config['default_action']);
$frontController->setDefaultControllerName($config['default_controller_name']);
$frontController->setParams($config['params']);
foreach ($config['plugins'] as $plugin) {
if (is_array(($plugin))) {
$pluginClass = $plugin['class'];
$stackIndex = $plugin['stack_index'];
} else {
$pluginClass = $plugin;
$stackIndex = null;
}
// plugins can be loaded with service locator
if ($serviceLocator->has($pluginClass)) {
$plugin = $serviceLocator->get($pluginClass);
} else {
$plugin = new $pluginClass();
}
$frontController->registerPlugin($plugin, $stackIndex);
}
// set action helper plugin manager
$actionHelperManager = $serviceLocator->get('ActionHelperManager');
ActionHelperBroker::setPluginLoader($actionHelperManager);
ActionHelperBroker::addHelper($actionHelperManager->get('viewRenderer'));
// start layout, if needed
if (isset($appConfig['layout'])) {
Layout::startMvc($appConfig['layout']);
}
return $frontController;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"frontController",
"=",
"FrontController",
"::",
"getInstance",
"(",
")",
";",
"// handle injections",
"$",
"frontController",
"->",
"setDispatcher",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Dispatcher'",
")",
")",
";",
"$",
"frontController",
"->",
"setRequest",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Request'",
")",
")",
";",
"$",
"frontController",
"->",
"setResponse",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Response'",
")",
")",
";",
"$",
"frontController",
"->",
"setRouter",
"(",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Router'",
")",
")",
";",
"// get config",
"$",
"appConfig",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'Config'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"appConfig",
"[",
"'front_controller'",
"]",
")",
")",
"{",
"$",
"config",
"=",
"ArrayUtils",
"::",
"merge",
"(",
"$",
"this",
"->",
"defaultOptions",
",",
"$",
"appConfig",
"[",
"'front_controller'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"defaultOptions",
";",
"}",
"// handle configuration",
"$",
"frontController",
"->",
"setModuleControllerDirectoryName",
"(",
"$",
"config",
"[",
"'module_controller_directory_name'",
"]",
")",
";",
"$",
"frontController",
"->",
"setBaseUrl",
"(",
"$",
"config",
"[",
"'base_url'",
"]",
")",
";",
"$",
"frontController",
"->",
"setControllerDirectory",
"(",
"$",
"config",
"[",
"'controller_directory'",
"]",
")",
";",
"$",
"frontController",
"->",
"throwExceptions",
"(",
"$",
"config",
"[",
"'throw_exceptions'",
"]",
")",
";",
"$",
"frontController",
"->",
"returnResponse",
"(",
"$",
"config",
"[",
"'return_response'",
"]",
")",
";",
"$",
"frontController",
"->",
"setDefaultModule",
"(",
"$",
"config",
"[",
"'default_module'",
"]",
")",
";",
"$",
"frontController",
"->",
"setDefaultAction",
"(",
"$",
"config",
"[",
"'default_action'",
"]",
")",
";",
"$",
"frontController",
"->",
"setDefaultControllerName",
"(",
"$",
"config",
"[",
"'default_controller_name'",
"]",
")",
";",
"$",
"frontController",
"->",
"setParams",
"(",
"$",
"config",
"[",
"'params'",
"]",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'plugins'",
"]",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"is_array",
"(",
"(",
"$",
"plugin",
")",
")",
")",
"{",
"$",
"pluginClass",
"=",
"$",
"plugin",
"[",
"'class'",
"]",
";",
"$",
"stackIndex",
"=",
"$",
"plugin",
"[",
"'stack_index'",
"]",
";",
"}",
"else",
"{",
"$",
"pluginClass",
"=",
"$",
"plugin",
";",
"$",
"stackIndex",
"=",
"null",
";",
"}",
"// plugins can be loaded with service locator",
"if",
"(",
"$",
"serviceLocator",
"->",
"has",
"(",
"$",
"pluginClass",
")",
")",
"{",
"$",
"plugin",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"$",
"pluginClass",
")",
";",
"}",
"else",
"{",
"$",
"plugin",
"=",
"new",
"$",
"pluginClass",
"(",
")",
";",
"}",
"$",
"frontController",
"->",
"registerPlugin",
"(",
"$",
"plugin",
",",
"$",
"stackIndex",
")",
";",
"}",
"// set action helper plugin manager",
"$",
"actionHelperManager",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'ActionHelperManager'",
")",
";",
"ActionHelperBroker",
"::",
"setPluginLoader",
"(",
"$",
"actionHelperManager",
")",
";",
"ActionHelperBroker",
"::",
"addHelper",
"(",
"$",
"actionHelperManager",
"->",
"get",
"(",
"'viewRenderer'",
")",
")",
";",
"// start layout, if needed",
"if",
"(",
"isset",
"(",
"$",
"appConfig",
"[",
"'layout'",
"]",
")",
")",
"{",
"Layout",
"::",
"startMvc",
"(",
"$",
"appConfig",
"[",
"'layout'",
"]",
")",
";",
"}",
"return",
"$",
"frontController",
";",
"}"
] | Create front controller service
@param ServiceLocatorInterface $serviceLocator
@return FrontController | [
"Create",
"front",
"controller",
"service"
] | 09e8c6422d84b57745cc643047e10761be2a21a7 | https://github.com/prolic/HumusMvc/blob/09e8c6422d84b57745cc643047e10761be2a21a7/src/HumusMvc/Service/FrontControllerFactory.php#L61-L117 | train |
WellCommerce/PageBundle | Controller/Front/PageController.php | PageController.findOr404 | protected function findOr404(Request $request, array $criteria = [])
{
// check whether request contains ID attribute
if (!$request->attributes->has('id')) {
throw new \LogicException('Request does not have "id" attribute set.');
}
$criteria['id'] = $request->attributes->get('id');
if (null === $resource = $this->getManager()->getRepository()->findOneBy($criteria)) {
throw new NotFoundHttpException(sprintf('Resource not found'));
}
return $resource;
} | php | protected function findOr404(Request $request, array $criteria = [])
{
// check whether request contains ID attribute
if (!$request->attributes->has('id')) {
throw new \LogicException('Request does not have "id" attribute set.');
}
$criteria['id'] = $request->attributes->get('id');
if (null === $resource = $this->getManager()->getRepository()->findOneBy($criteria)) {
throw new NotFoundHttpException(sprintf('Resource not found'));
}
return $resource;
} | [
"protected",
"function",
"findOr404",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"criteria",
"=",
"[",
"]",
")",
"{",
"// check whether request contains ID attribute",
"if",
"(",
"!",
"$",
"request",
"->",
"attributes",
"->",
"has",
"(",
"'id'",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Request does not have \"id\" attribute set.'",
")",
";",
"}",
"$",
"criteria",
"[",
"'id'",
"]",
"=",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'id'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"resource",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getRepository",
"(",
")",
"->",
"findOneBy",
"(",
"$",
"criteria",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"sprintf",
"(",
"'Resource not found'",
")",
")",
";",
"}",
"return",
"$",
"resource",
";",
"}"
] | Returns resource by ID parameter
@param Request $request
@param array $criteria
@return mixed | [
"Returns",
"resource",
"by",
"ID",
"parameter"
] | c9a1e8c8c52177e3b82f246fd38a4598214aa222 | https://github.com/WellCommerce/PageBundle/blob/c9a1e8c8c52177e3b82f246fd38a4598214aa222/Controller/Front/PageController.php#L59-L73 | train |
theomessin/ts-framework | src/Node/Client.php | Client.iconDownload | public function iconDownload()
{
if ($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) {
return;
}
$download = $this->getParent()->transferInitDownload(
rand(0x0000, 0xFFFF),
0,
$this->iconGetName("client_icon_id")
);
$transfer = Teamspeak::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
} | php | public function iconDownload()
{
if ($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) {
return;
}
$download = $this->getParent()->transferInitDownload(
rand(0x0000, 0xFFFF),
0,
$this->iconGetName("client_icon_id")
);
$transfer = Teamspeak::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
} | [
"public",
"function",
"iconDownload",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"iconIsLocal",
"(",
"\"client_icon_id\"",
")",
"||",
"$",
"this",
"[",
"\"client_icon_id\"",
"]",
"==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"download",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"transferInitDownload",
"(",
"rand",
"(",
"0x0000",
",",
"0xFFFF",
")",
",",
"0",
",",
"$",
"this",
"->",
"iconGetName",
"(",
"\"client_icon_id\"",
")",
")",
";",
"$",
"transfer",
"=",
"Teamspeak",
"::",
"factory",
"(",
"\"filetransfer://\"",
".",
"$",
"download",
"[",
"\"host\"",
"]",
".",
"\":\"",
".",
"$",
"download",
"[",
"\"port\"",
"]",
")",
";",
"return",
"$",
"transfer",
"->",
"download",
"(",
"$",
"download",
"[",
"\"ftkey\"",
"]",
",",
"$",
"download",
"[",
"\"size\"",
"]",
")",
";",
"}"
] | Downloads and returns the clients icon file content.
@return TeamSpeak3_Helper_String | [
"Downloads",
"and",
"returns",
"the",
"clients",
"icon",
"file",
"content",
"."
] | d60e36553241db05cb05ef19e749866cc977437c | https://github.com/theomessin/ts-framework/blob/d60e36553241db05cb05ef19e749866cc977437c/src/Node/Client.php#L350-L364 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.uploadsUrl | public static function uploadsUrl($url = ''){
$url = Config::get('congraph::congraph.uploads_url') . '/' . $url;
$rtrim = !empty($url);
$url = url(self::normalizeUrl($url, $rtrim));
return $url;
} | php | public static function uploadsUrl($url = ''){
$url = Config::get('congraph::congraph.uploads_url') . '/' . $url;
$rtrim = !empty($url);
$url = url(self::normalizeUrl($url, $rtrim));
return $url;
} | [
"public",
"static",
"function",
"uploadsUrl",
"(",
"$",
"url",
"=",
"''",
")",
"{",
"$",
"url",
"=",
"Config",
"::",
"get",
"(",
"'congraph::congraph.uploads_url'",
")",
".",
"'/'",
".",
"$",
"url",
";",
"$",
"rtrim",
"=",
"!",
"empty",
"(",
"$",
"url",
")",
";",
"$",
"url",
"=",
"url",
"(",
"self",
"::",
"normalizeUrl",
"(",
"$",
"url",
",",
"$",
"rtrim",
")",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Get uploads url from config and optionally concatonates
given url to uploads url
@param string $url - optional url
@return string | [
"Get",
"uploads",
"url",
"from",
"config",
"and",
"optionally",
"concatonates",
"given",
"url",
"to",
"uploads",
"url"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L38-L44 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.normalizePath | public static function normalizePath($path, $rtrim = true){
$path = trim($path);
// replace every back slash with forward slash
$path = str_replace('\\', '/', $path);
// replace all double slashes with single
$path = preg_replace( '/\/+/', '==DS==', $path );
// trim slashes on begining
$segments = explode('==DS==', $path);
$path = implode(DIRECTORY_SEPARATOR, $segments);
//$path = ltrim($path, DIRECTORY_SEPARATOR);
if($rtrim){
$path = rtrim($path, DIRECTORY_SEPARATOR);
}
return $path;
} | php | public static function normalizePath($path, $rtrim = true){
$path = trim($path);
// replace every back slash with forward slash
$path = str_replace('\\', '/', $path);
// replace all double slashes with single
$path = preg_replace( '/\/+/', '==DS==', $path );
// trim slashes on begining
$segments = explode('==DS==', $path);
$path = implode(DIRECTORY_SEPARATOR, $segments);
//$path = ltrim($path, DIRECTORY_SEPARATOR);
if($rtrim){
$path = rtrim($path, DIRECTORY_SEPARATOR);
}
return $path;
} | [
"public",
"static",
"function",
"normalizePath",
"(",
"$",
"path",
",",
"$",
"rtrim",
"=",
"true",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
")",
";",
"// replace every back slash with forward slash",
"$",
"path",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"// replace all double slashes with single",
"$",
"path",
"=",
"preg_replace",
"(",
"'/\\/+/'",
",",
"'==DS=='",
",",
"$",
"path",
")",
";",
"// trim slashes on begining",
"$",
"segments",
"=",
"explode",
"(",
"'==DS=='",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"segments",
")",
";",
"//$path = ltrim($path, DIRECTORY_SEPARATOR);",
"if",
"(",
"$",
"rtrim",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Normalizes path slashes when mixed between path and url conversion
It takes string with mixed or doubled slashes and converts them
to single slashes dependent on system beacose of use of DIRECTORY_SEPARATOR const,
and optionally trims right slash.
There are two parameters,
string that will be normalized and optional rtrim flag
@param string $path - string to be normalized
@param boolean $rtrim - flag for right trim option
@return string normalized path. | [
"Normalizes",
"path",
"slashes",
"when",
"mixed",
"between",
"path",
"and",
"url",
"conversion"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L79-L95 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.normalizeUrl | public static function normalizeUrl($url, $rtrim = true){
$url = trim($url);
// replace every back slash with forward slash
$url = str_replace('\\', '/', $url);
// replace all double slashes with single
$url = preg_replace( '/\/+/', '==DS==', $url );
// trim slashes on begining
$segments = explode('==DS==', $url);
$url = implode('/', $segments);
//$url = ltrim($url, '/');
if($rtrim){
$url = rtrim($url, '/');
}
return $url;
} | php | public static function normalizeUrl($url, $rtrim = true){
$url = trim($url);
// replace every back slash with forward slash
$url = str_replace('\\', '/', $url);
// replace all double slashes with single
$url = preg_replace( '/\/+/', '==DS==', $url );
// trim slashes on begining
$segments = explode('==DS==', $url);
$url = implode('/', $segments);
//$url = ltrim($url, '/');
if($rtrim){
$url = rtrim($url, '/');
}
return $url;
} | [
"public",
"static",
"function",
"normalizeUrl",
"(",
"$",
"url",
",",
"$",
"rtrim",
"=",
"true",
")",
"{",
"$",
"url",
"=",
"trim",
"(",
"$",
"url",
")",
";",
"// replace every back slash with forward slash",
"$",
"url",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"url",
")",
";",
"// replace all double slashes with single",
"$",
"url",
"=",
"preg_replace",
"(",
"'/\\/+/'",
",",
"'==DS=='",
",",
"$",
"url",
")",
";",
"// trim slashes on begining",
"$",
"segments",
"=",
"explode",
"(",
"'==DS=='",
",",
"$",
"url",
")",
";",
"$",
"url",
"=",
"implode",
"(",
"'/'",
",",
"$",
"segments",
")",
";",
"//$url = ltrim($url, '/');",
"if",
"(",
"$",
"rtrim",
")",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Normalizes url slashes when mixed between path and url conversion
It takes string with mixed or doubled slashes and converts them
to single forward slashes, and optionally trims right slash
There are two parameters,
string that will be normalized and optional rtrim flag
@param string $url - string to be normalized
@param boolean $rtrim - flag for right trim option
@return string normalized url. | [
"Normalizes",
"url",
"slashes",
"when",
"mixed",
"between",
"path",
"and",
"url",
"conversion"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L110-L124 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.uniqueFilename | public static function uniqueFilename($path) {
// get directory
$dir = self::getDirectory($path);
// get filename
$filename = self::getFileName($path);
// sanitize the file name before we begin processing
$filename = self::sanitizeFileName($filename);
// separate the filename into a name and extension
$info = pathinfo($filename);
$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
$name = basename($filename, $ext);
// edge case: if file is named '.ext', treat as an empty name
if ( $name === $ext ) $name = '';
// Increment the file number until we have a unique file to save in $dir.
$number = '';
// change '.ext' to lower case
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// check for both lower and upper case extension or image sub-sizes may be overwritten
while ( Storage::has($dir . DIRECTORY_SEPARATOR . $filename) || Storage::has($dir . DIRECTORY_SEPARATOR . $filename2) ) {
$new_number = $number + 1;
$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
$number = $new_number;
}
return $filename2;
}
while ( Storage::has( $dir . DIRECTORY_SEPARATOR . $filename ) ) {
if ( '' == "$number$ext" )
$filename = $filename . ++$number . $ext;
else
$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
}
return self::normalizePath($dir . DIRECTORY_SEPARATOR . $filename);
} | php | public static function uniqueFilename($path) {
// get directory
$dir = self::getDirectory($path);
// get filename
$filename = self::getFileName($path);
// sanitize the file name before we begin processing
$filename = self::sanitizeFileName($filename);
// separate the filename into a name and extension
$info = pathinfo($filename);
$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
$name = basename($filename, $ext);
// edge case: if file is named '.ext', treat as an empty name
if ( $name === $ext ) $name = '';
// Increment the file number until we have a unique file to save in $dir.
$number = '';
// change '.ext' to lower case
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// check for both lower and upper case extension or image sub-sizes may be overwritten
while ( Storage::has($dir . DIRECTORY_SEPARATOR . $filename) || Storage::has($dir . DIRECTORY_SEPARATOR . $filename2) ) {
$new_number = $number + 1;
$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
$number = $new_number;
}
return $filename2;
}
while ( Storage::has( $dir . DIRECTORY_SEPARATOR . $filename ) ) {
if ( '' == "$number$ext" )
$filename = $filename . ++$number . $ext;
else
$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
}
return self::normalizePath($dir . DIRECTORY_SEPARATOR . $filename);
} | [
"public",
"static",
"function",
"uniqueFilename",
"(",
"$",
"path",
")",
"{",
"// get directory",
"$",
"dir",
"=",
"self",
"::",
"getDirectory",
"(",
"$",
"path",
")",
";",
"// get filename",
"$",
"filename",
"=",
"self",
"::",
"getFileName",
"(",
"$",
"path",
")",
";",
"// sanitize the file name before we begin processing",
"$",
"filename",
"=",
"self",
"::",
"sanitizeFileName",
"(",
"$",
"filename",
")",
";",
"// separate the filename into a name and extension",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"filename",
")",
";",
"$",
"ext",
"=",
"!",
"empty",
"(",
"$",
"info",
"[",
"'extension'",
"]",
")",
"?",
"'.'",
".",
"$",
"info",
"[",
"'extension'",
"]",
":",
"''",
";",
"$",
"name",
"=",
"basename",
"(",
"$",
"filename",
",",
"$",
"ext",
")",
";",
"// edge case: if file is named '.ext', treat as an empty name",
"if",
"(",
"$",
"name",
"===",
"$",
"ext",
")",
"$",
"name",
"=",
"''",
";",
"// Increment the file number until we have a unique file to save in $dir.",
"$",
"number",
"=",
"''",
";",
"// change '.ext' to lower case",
"if",
"(",
"$",
"ext",
"&&",
"strtolower",
"(",
"$",
"ext",
")",
"!=",
"$",
"ext",
")",
"{",
"$",
"ext2",
"=",
"strtolower",
"(",
"$",
"ext",
")",
";",
"$",
"filename2",
"=",
"preg_replace",
"(",
"'|'",
".",
"preg_quote",
"(",
"$",
"ext",
")",
".",
"'$|'",
",",
"$",
"ext2",
",",
"$",
"filename",
")",
";",
"// check for both lower and upper case extension or image sub-sizes may be overwritten",
"while",
"(",
"Storage",
"::",
"has",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
")",
"||",
"Storage",
"::",
"has",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename2",
")",
")",
"{",
"$",
"new_number",
"=",
"$",
"number",
"+",
"1",
";",
"$",
"filename",
"=",
"str_replace",
"(",
"\"$number$ext\"",
",",
"\"$new_number$ext\"",
",",
"$",
"filename",
")",
";",
"$",
"filename2",
"=",
"str_replace",
"(",
"\"$number$ext2\"",
",",
"\"$new_number$ext2\"",
",",
"$",
"filename2",
")",
";",
"$",
"number",
"=",
"$",
"new_number",
";",
"}",
"return",
"$",
"filename2",
";",
"}",
"while",
"(",
"Storage",
"::",
"has",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"''",
"==",
"\"$number$ext\"",
")",
"$",
"filename",
"=",
"$",
"filename",
".",
"++",
"$",
"number",
".",
"$",
"ext",
";",
"else",
"$",
"filename",
"=",
"str_replace",
"(",
"\"$number$ext\"",
",",
"++",
"$",
"number",
".",
"$",
"ext",
",",
"$",
"filename",
")",
";",
"}",
"return",
"self",
"::",
"normalizePath",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
")",
";",
"}"
] | Get a filename that is sanitized and unique for the given directory.
If the filename is not unique, then a number will be added to the filename
before the extension, and will continue adding numbers until the filename is
unique.
@param string $path
@return string | [
"Get",
"a",
"filename",
"that",
"is",
"sanitized",
"and",
"unique",
"for",
"the",
"given",
"directory",
"."
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L166-L207 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.sanitizeFileName | public static function sanitizeFileName( $filename ) {
$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
$filename = str_replace($special_chars, '', $filename);
$filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = trim($filename, '.-_');
return $filename;
} | php | public static function sanitizeFileName( $filename ) {
$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
$filename = str_replace($special_chars, '', $filename);
$filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = trim($filename, '.-_');
return $filename;
} | [
"public",
"static",
"function",
"sanitizeFileName",
"(",
"$",
"filename",
")",
"{",
"$",
"special_chars",
"=",
"array",
"(",
"\"?\"",
",",
"\"[\"",
",",
"\"]\"",
",",
"\"/\"",
",",
"\"\\\\\"",
",",
"\"=\"",
",",
"\"<\"",
",",
"\">\"",
",",
"\":\"",
",",
"\";\"",
",",
"\",\"",
",",
"\"'\"",
",",
"\"\\\"\"",
",",
"\"&\"",
",",
"\"$\"",
",",
"\"#\"",
",",
"\"*\"",
",",
"\"(\"",
",",
"\")\"",
",",
"\"|\"",
",",
"\"~\"",
",",
"\"`\"",
",",
"\"!\"",
",",
"\"{\"",
",",
"\"}\"",
",",
"chr",
"(",
"0",
")",
")",
";",
"$",
"filename",
"=",
"str_replace",
"(",
"$",
"special_chars",
",",
"''",
",",
"$",
"filename",
")",
";",
"$",
"filename",
"=",
"preg_replace",
"(",
"'/[\\s-]+/'",
",",
"'-'",
",",
"$",
"filename",
")",
";",
"$",
"filename",
"=",
"trim",
"(",
"$",
"filename",
",",
"'.-_'",
")",
";",
"return",
"$",
"filename",
";",
"}"
] | Sanitizes a filename replacing whitespace with dashes
Removes special characters that are illegal in filenames on certain
operating systems and special characters requiring special escaping
to manipulate at the command line. Replaces spaces and consecutive
dashes with a single dash. Trim period, dash and underscore from beginning
and end of filename.
@param string $filename The filename to be sanitized
@return string The sanitized filename | [
"Sanitizes",
"a",
"filename",
"replacing",
"whitespace",
"with",
"dashes"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L222-L230 | train |
congraphcms/core | Helpers/FileHelper.php | FileHelper.getFileName | public static function getFileName( $path, $includeExtension = true )
{
$option = ($includeExtension)?PATHINFO_BASENAME:PATHINFO_FILENAME;
return pathinfo($path, $option);
} | php | public static function getFileName( $path, $includeExtension = true )
{
$option = ($includeExtension)?PATHINFO_BASENAME:PATHINFO_FILENAME;
return pathinfo($path, $option);
} | [
"public",
"static",
"function",
"getFileName",
"(",
"$",
"path",
",",
"$",
"includeExtension",
"=",
"true",
")",
"{",
"$",
"option",
"=",
"(",
"$",
"includeExtension",
")",
"?",
"PATHINFO_BASENAME",
":",
"PATHINFO_FILENAME",
";",
"return",
"pathinfo",
"(",
"$",
"path",
",",
"$",
"option",
")",
";",
"}"
] | Extracts filename from path, with or without extension
You can optionally specify if you want extensino to be included
Defaults to extension included
@param string $path from wich filename will be extracted
@param boolean $includeExtension flag for including extension
@return string extracted filename | [
"Extracts",
"filename",
"from",
"path",
"with",
"or",
"without",
"extension"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/FileHelper.php#L242-L246 | train |
ingro/Rest | src/Ingruz/Rest/Controllers/RestIlluminateController.php | AbstractIlluminateApiController.index | public function index()
{
$options = $this->getQueryHelperOptions();
$items = $this->repo->allPaged($options);
if ( ! $items)
{
return $this->respondNotFound('Unable to fetch the selected resources');
}
$response = [
'data' => [],
'meta' => [
'pagination' => []
]
];
$resource = new Fractal\Resource\Collection($items->getCollection(), new $this->transformerClass);
$resource->setPaginator(new Fractal\Pagination\IlluminatePaginatorAdapter($items));
$response['data'] = $this->fractal->createData($resource)->toArray()['data'];
$paginator = new Fractal\Pagination\IlluminatePaginatorAdapter($items);
$response['meta']['pagination'] = [
'total' => $paginator->getTotal(),
'count' => $paginator->count(),
'per_page' => $paginator->getPerPage(),
'current_page' => $paginator->getCurrentPage(),
'total_pages' => $paginator->getLastPage()
];
return $response;
} | php | public function index()
{
$options = $this->getQueryHelperOptions();
$items = $this->repo->allPaged($options);
if ( ! $items)
{
return $this->respondNotFound('Unable to fetch the selected resources');
}
$response = [
'data' => [],
'meta' => [
'pagination' => []
]
];
$resource = new Fractal\Resource\Collection($items->getCollection(), new $this->transformerClass);
$resource->setPaginator(new Fractal\Pagination\IlluminatePaginatorAdapter($items));
$response['data'] = $this->fractal->createData($resource)->toArray()['data'];
$paginator = new Fractal\Pagination\IlluminatePaginatorAdapter($items);
$response['meta']['pagination'] = [
'total' => $paginator->getTotal(),
'count' => $paginator->count(),
'per_page' => $paginator->getPerPage(),
'current_page' => $paginator->getCurrentPage(),
'total_pages' => $paginator->getLastPage()
];
return $response;
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getQueryHelperOptions",
"(",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"repo",
"->",
"allPaged",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"items",
")",
"{",
"return",
"$",
"this",
"->",
"respondNotFound",
"(",
"'Unable to fetch the selected resources'",
")",
";",
"}",
"$",
"response",
"=",
"[",
"'data'",
"=>",
"[",
"]",
",",
"'meta'",
"=>",
"[",
"'pagination'",
"=>",
"[",
"]",
"]",
"]",
";",
"$",
"resource",
"=",
"new",
"Fractal",
"\\",
"Resource",
"\\",
"Collection",
"(",
"$",
"items",
"->",
"getCollection",
"(",
")",
",",
"new",
"$",
"this",
"->",
"transformerClass",
")",
";",
"$",
"resource",
"->",
"setPaginator",
"(",
"new",
"Fractal",
"\\",
"Pagination",
"\\",
"IlluminatePaginatorAdapter",
"(",
"$",
"items",
")",
")",
";",
"$",
"response",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
"[",
"'data'",
"]",
";",
"$",
"paginator",
"=",
"new",
"Fractal",
"\\",
"Pagination",
"\\",
"IlluminatePaginatorAdapter",
"(",
"$",
"items",
")",
";",
"$",
"response",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"=",
"[",
"'total'",
"=>",
"$",
"paginator",
"->",
"getTotal",
"(",
")",
",",
"'count'",
"=>",
"$",
"paginator",
"->",
"count",
"(",
")",
",",
"'per_page'",
"=>",
"$",
"paginator",
"->",
"getPerPage",
"(",
")",
",",
"'current_page'",
"=>",
"$",
"paginator",
"->",
"getCurrentPage",
"(",
")",
",",
"'total_pages'",
"=>",
"$",
"paginator",
"->",
"getLastPage",
"(",
")",
"]",
";",
"return",
"$",
"response",
";",
"}"
] | Return items in a paged way
@return mixed | [
"Return",
"items",
"in",
"a",
"paged",
"way"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Controllers/RestIlluminateController.php#L79-L112 | train |
ingro/Rest | src/Ingruz/Rest/Controllers/RestIlluminateController.php | AbstractIlluminateApiController.show | public function show($id)
{
$item = $this->repo->getById($id);
if ( ! $item)
{
return $this->respondNotFound();
}
$resource = new Fractal\Resource\Item($item, new $this->transformerClass);
return $this->fractal->createData($resource)->toArray();
} | php | public function show($id)
{
$item = $this->repo->getById($id);
if ( ! $item)
{
return $this->respondNotFound();
}
$resource = new Fractal\Resource\Item($item, new $this->transformerClass);
return $this->fractal->createData($resource)->toArray();
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"repo",
"->",
"getById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"item",
")",
"{",
"return",
"$",
"this",
"->",
"respondNotFound",
"(",
")",
";",
"}",
"$",
"resource",
"=",
"new",
"Fractal",
"\\",
"Resource",
"\\",
"Item",
"(",
"$",
"item",
",",
"new",
"$",
"this",
"->",
"transformerClass",
")",
";",
"return",
"$",
"this",
"->",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Return an item by it's id
@param $id
@return mixed | [
"Return",
"an",
"item",
"by",
"it",
"s",
"id"
] | 922bed071b8ea41feb067d97a3e283f944a86cb8 | https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Controllers/RestIlluminateController.php#L120-L131 | train |
congraphcms/core | Repositories/Collection.php | Collection.setDefaultModel | public function setDefaultModel($model)
{
if(is_string($model))
{
$model = new ReflectionClass($model);
$model = $model->newInstanceWithoutConstructor();
}
if( $model instanceof Model)
{
$this->defaultModel = get_class($model);
return;
}
throw new \InvalidArgumentException('Collection default model must be instance of ' . Model::class);
} | php | public function setDefaultModel($model)
{
if(is_string($model))
{
$model = new ReflectionClass($model);
$model = $model->newInstanceWithoutConstructor();
}
if( $model instanceof Model)
{
$this->defaultModel = get_class($model);
return;
}
throw new \InvalidArgumentException('Collection default model must be instance of ' . Model::class);
} | [
"public",
"function",
"setDefaultModel",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"model",
")",
")",
"{",
"$",
"model",
"=",
"new",
"ReflectionClass",
"(",
"$",
"model",
")",
";",
"$",
"model",
"=",
"$",
"model",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"}",
"if",
"(",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"$",
"this",
"->",
"defaultModel",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"return",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Collection default model must be instance of '",
".",
"Model",
"::",
"class",
")",
";",
"}"
] | Set default model class
@param Congraph\Core\Repositories\Model|string $model
@throws \InvalidArgumentException | [
"Set",
"default",
"model",
"class"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/Collection.php#L98-L113 | train |
congraphcms/core | Repositories/Collection.php | Collection.checkItems | protected function checkItems(array $data)
{
foreach ($data as &$item)
{
if( ! $item instanceof Model )
{
$item = new $this->defaultModel($item);
}
}
return $data;
} | php | protected function checkItems(array $data)
{
foreach ($data as &$item)
{
if( ! $item instanceof Model )
{
$item = new $this->defaultModel($item);
}
}
return $data;
} | [
"protected",
"function",
"checkItems",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"instanceof",
"Model",
")",
"{",
"$",
"item",
"=",
"new",
"$",
"this",
"->",
"defaultModel",
"(",
"$",
"item",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Check if all items are instance of Model
if not, create new Model for each item
@param array $data
@return array | [
"Check",
"if",
"all",
"items",
"are",
"instance",
"of",
"Model",
"if",
"not",
"create",
"new",
"Model",
"for",
"each",
"item"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/Collection.php#L182-L193 | train |
phospr/DoubleEntryBundle | Model/JournalHandler.php | JournalHandler.findJournalForId | public function findJournalForId($id)
{
$dql = '
SELECT j,p
FROM %s j
LEFT JOIN j.postings p
WHERE j.id = :id
AND j.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->journalFqcn))
->setParameter('id', $id)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | php | public function findJournalForId($id)
{
$dql = '
SELECT j,p
FROM %s j
LEFT JOIN j.postings p
WHERE j.id = :id
AND j.organization = :organization
';
return $this->em
->createQuery(sprintf($dql, $this->journalFqcn))
->setParameter('id', $id)
->setParameter('organization', $this->oh->getOrganization())
->getSingleResult()
;
} | [
"public",
"function",
"findJournalForId",
"(",
"$",
"id",
")",
"{",
"$",
"dql",
"=",
"'\n SELECT j,p\n FROM %s j\n LEFT JOIN j.postings p\n WHERE j.id = :id\n AND j.organization = :organization\n '",
";",
"return",
"$",
"this",
"->",
"em",
"->",
"createQuery",
"(",
"sprintf",
"(",
"$",
"dql",
",",
"$",
"this",
"->",
"journalFqcn",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"id",
")",
"->",
"setParameter",
"(",
"'organization'",
",",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}"
] | Find Journal for id
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@param int $id
@return Journal | [
"Find",
"Journal",
"for",
"id"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/JournalHandler.php#L98-L114 | train |
phospr/DoubleEntryBundle | Model/JournalHandler.php | JournalHandler.createJournal | public function createJournal()
{
$journal = new $this->journalFqcn();
$journal->setOrganization($this->oh->getOrganization());
return $journal;
} | php | public function createJournal()
{
$journal = new $this->journalFqcn();
$journal->setOrganization($this->oh->getOrganization());
return $journal;
} | [
"public",
"function",
"createJournal",
"(",
")",
"{",
"$",
"journal",
"=",
"new",
"$",
"this",
"->",
"journalFqcn",
"(",
")",
";",
"$",
"journal",
"->",
"setOrganization",
"(",
"$",
"this",
"->",
"oh",
"->",
"getOrganization",
"(",
")",
")",
";",
"return",
"$",
"journal",
";",
"}"
] | Create new Journal
@author Tom Haskins-Vaughan <[email protected]>
@since 0.8.0
@return Journal | [
"Create",
"new",
"Journal"
] | d9c421f30922b461483731983c59beb26047fb7f | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/JournalHandler.php#L124-L130 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.addRoute | public function addRoute($expression, $route)
{
//Detect command expression
if (strpos($expression, '*') !== false) {
return $this->addRegexpRoute($expression, $route);
} else {
return $this->addSimpleRoute($expression, $route);
}
} | php | public function addRoute($expression, $route)
{
//Detect command expression
if (strpos($expression, '*') !== false) {
return $this->addRegexpRoute($expression, $route);
} else {
return $this->addSimpleRoute($expression, $route);
}
} | [
"public",
"function",
"addRoute",
"(",
"$",
"expression",
",",
"$",
"route",
")",
"{",
"//Detect command expression",
"if",
"(",
"strpos",
"(",
"$",
"expression",
",",
"'*'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"addRegexpRoute",
"(",
"$",
"expression",
",",
"$",
"route",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"addSimpleRoute",
"(",
"$",
"expression",
",",
"$",
"route",
")",
";",
"}",
"}"
] | Add new route.
@param string $expression Either simple expression, or RegExp describing route.
@param string $route Route name.
@return bool True, if route has been set, false otherwise. | [
"Add",
"new",
"route",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L55-L63 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.addRegexpRoute | private function addRegexpRoute($expression, $route)
{
$expression = '|^'.str_replace(array('*', '\\'), array('.*', '\\\\'), $expression).'$|i';
if (array_key_exists($expression, $this->regexpRoutes) && $this->regexpRoutes[$expression] == $route) {
return false;
}
$this->regexpRoutes[$expression] = (string) $route;
return true;
} | php | private function addRegexpRoute($expression, $route)
{
$expression = '|^'.str_replace(array('*', '\\'), array('.*', '\\\\'), $expression).'$|i';
if (array_key_exists($expression, $this->regexpRoutes) && $this->regexpRoutes[$expression] == $route) {
return false;
}
$this->regexpRoutes[$expression] = (string) $route;
return true;
} | [
"private",
"function",
"addRegexpRoute",
"(",
"$",
"expression",
",",
"$",
"route",
")",
"{",
"$",
"expression",
"=",
"'|^'",
".",
"str_replace",
"(",
"array",
"(",
"'*'",
",",
"'\\\\'",
")",
",",
"array",
"(",
"'.*'",
",",
"'\\\\\\\\'",
")",
",",
"$",
"expression",
")",
".",
"'$|i'",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"expression",
",",
"$",
"this",
"->",
"regexpRoutes",
")",
"&&",
"$",
"this",
"->",
"regexpRoutes",
"[",
"$",
"expression",
"]",
"==",
"$",
"route",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"regexpRoutes",
"[",
"$",
"expression",
"]",
"=",
"(",
"string",
")",
"$",
"route",
";",
"return",
"true",
";",
"}"
] | Add new regexp route.
@param string $expression RegExp describing route.
@param string $route Route name.
@return bool True, if route has been set, false otherwise. | [
"Add",
"new",
"regexp",
"route",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L73-L81 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.addSimpleRoute | private function addSimpleRoute($expression, $route)
{
if (array_key_exists($expression, $this->simpleRoutes) && $this->simpleRoutes[$expression] == $route) {
return false;
}
$this->simpleRoutes[$expression] = (string) $route;
return true;
} | php | private function addSimpleRoute($expression, $route)
{
if (array_key_exists($expression, $this->simpleRoutes) && $this->simpleRoutes[$expression] == $route) {
return false;
}
$this->simpleRoutes[$expression] = (string) $route;
return true;
} | [
"private",
"function",
"addSimpleRoute",
"(",
"$",
"expression",
",",
"$",
"route",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"expression",
",",
"$",
"this",
"->",
"simpleRoutes",
")",
"&&",
"$",
"this",
"->",
"simpleRoutes",
"[",
"$",
"expression",
"]",
"==",
"$",
"route",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"simpleRoutes",
"[",
"$",
"expression",
"]",
"=",
"(",
"string",
")",
"$",
"route",
";",
"return",
"true",
";",
"}"
] | Add new simple route.
@param string $expression Simple route expression.
@param string $route Route name.
@return bool True, if route has been set, false otherwise. | [
"Add",
"new",
"simple",
"route",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L91-L98 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.doDetect | private function doDetect($className, $performInterfaceDetection = true)
{
$detection = $this->doDetectByRoutes($className);
if ($detection) {
return $detection;
}
//Nothing is found so far. We will check all of the class interfaces and base classes.
//First - check base classes up to the 'root'
$parentClass = get_parent_class($className);
if ($parentClass) {
$parentDetection = $this->doDetect($parentClass, false);
if ($parentDetection instanceof ClassDetection) {
return $parentDetection;
}
}
//Check the class interfaces
if ($performInterfaceDetection) {
$definition = $this->doDetectByInterfaces($className);
if ($definition) {
return $definition;
}
}
return new DefaultDetection($this->defaultRoute);
} | php | private function doDetect($className, $performInterfaceDetection = true)
{
$detection = $this->doDetectByRoutes($className);
if ($detection) {
return $detection;
}
//Nothing is found so far. We will check all of the class interfaces and base classes.
//First - check base classes up to the 'root'
$parentClass = get_parent_class($className);
if ($parentClass) {
$parentDetection = $this->doDetect($parentClass, false);
if ($parentDetection instanceof ClassDetection) {
return $parentDetection;
}
}
//Check the class interfaces
if ($performInterfaceDetection) {
$definition = $this->doDetectByInterfaces($className);
if ($definition) {
return $definition;
}
}
return new DefaultDetection($this->defaultRoute);
} | [
"private",
"function",
"doDetect",
"(",
"$",
"className",
",",
"$",
"performInterfaceDetection",
"=",
"true",
")",
"{",
"$",
"detection",
"=",
"$",
"this",
"->",
"doDetectByRoutes",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"detection",
")",
"{",
"return",
"$",
"detection",
";",
"}",
"//Nothing is found so far. We will check all of the class interfaces and base classes.",
"//First - check base classes up to the 'root'",
"$",
"parentClass",
"=",
"get_parent_class",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"parentClass",
")",
"{",
"$",
"parentDetection",
"=",
"$",
"this",
"->",
"doDetect",
"(",
"$",
"parentClass",
",",
"false",
")",
";",
"if",
"(",
"$",
"parentDetection",
"instanceof",
"ClassDetection",
")",
"{",
"return",
"$",
"parentDetection",
";",
"}",
"}",
"//Check the class interfaces",
"if",
"(",
"$",
"performInterfaceDetection",
")",
"{",
"$",
"definition",
"=",
"$",
"this",
"->",
"doDetectByInterfaces",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"definition",
")",
"{",
"return",
"$",
"definition",
";",
"}",
"}",
"return",
"new",
"DefaultDetection",
"(",
"$",
"this",
"->",
"defaultRoute",
")",
";",
"}"
] | Detect pool.
@param string $className
@param boolean $performInterfaceDetection
@return DetectionInterface | [
"Detect",
"pool",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L146-L170 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.doDetectByRoutes | private function doDetectByRoutes($className)
{
//If we have entry for a command class, we should always return it, as it is most specific.
if (!empty($this->simpleRoutes[$className])) {
return new ClassDetection($this->simpleRoutes[$className]);
}
//Now, we should check, if we have 'regexp' entry for class
foreach ($this->regexpRoutes as $regexpRoute => $poolName) {
if (preg_match($regexpRoute, $className)) {
return new ClassDetection($poolName);
}
}
} | php | private function doDetectByRoutes($className)
{
//If we have entry for a command class, we should always return it, as it is most specific.
if (!empty($this->simpleRoutes[$className])) {
return new ClassDetection($this->simpleRoutes[$className]);
}
//Now, we should check, if we have 'regexp' entry for class
foreach ($this->regexpRoutes as $regexpRoute => $poolName) {
if (preg_match($regexpRoute, $className)) {
return new ClassDetection($poolName);
}
}
} | [
"private",
"function",
"doDetectByRoutes",
"(",
"$",
"className",
")",
"{",
"//If we have entry for a command class, we should always return it, as it is most specific.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"simpleRoutes",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"new",
"ClassDetection",
"(",
"$",
"this",
"->",
"simpleRoutes",
"[",
"$",
"className",
"]",
")",
";",
"}",
"//Now, we should check, if we have 'regexp' entry for class",
"foreach",
"(",
"$",
"this",
"->",
"regexpRoutes",
"as",
"$",
"regexpRoute",
"=>",
"$",
"poolName",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"regexpRoute",
",",
"$",
"className",
")",
")",
"{",
"return",
"new",
"ClassDetection",
"(",
"$",
"poolName",
")",
";",
"}",
"}",
"}"
] | Perform detection based on class name and routes registered for this class.
@param string $className
@return ClassDetection|null | [
"Perform",
"detection",
"based",
"on",
"class",
"name",
"and",
"routes",
"registered",
"for",
"this",
"class",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L179-L191 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.doDetectByInterfaces | private function doDetectByInterfaces($className)
{
$interfaces = $this->getOrderedInterfaces($className);
foreach ($interfaces as $interface) {
$candidate = $this->doDetectByRoutes($interface);
if ($candidate) {
return $candidate;
}
}
return;
} | php | private function doDetectByInterfaces($className)
{
$interfaces = $this->getOrderedInterfaces($className);
foreach ($interfaces as $interface) {
$candidate = $this->doDetectByRoutes($interface);
if ($candidate) {
return $candidate;
}
}
return;
} | [
"private",
"function",
"doDetectByInterfaces",
"(",
"$",
"className",
")",
"{",
"$",
"interfaces",
"=",
"$",
"this",
"->",
"getOrderedInterfaces",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"interface",
")",
"{",
"$",
"candidate",
"=",
"$",
"this",
"->",
"doDetectByRoutes",
"(",
"$",
"interface",
")",
";",
"if",
"(",
"$",
"candidate",
")",
"{",
"return",
"$",
"candidate",
";",
"}",
"}",
"return",
";",
"}"
] | Perform detection based on class interfaces.
@param string $className
@return DetectionInterface|null | [
"Perform",
"detection",
"based",
"on",
"class",
"interfaces",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L200-L211 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.getOrderedInterfaces | private function getOrderedInterfaces($className)
{
$interfacesArr = $this->prepareClassTreeInterfaces($className);
$interfaces = array();
foreach ($interfacesArr as $classInterfaces) {
foreach ($classInterfaces as $interface) {
if (array_search($interface, $interfaces) === false) {
array_unshift($interfaces, $interface);
}
}
}
return $interfaces;
} | php | private function getOrderedInterfaces($className)
{
$interfacesArr = $this->prepareClassTreeInterfaces($className);
$interfaces = array();
foreach ($interfacesArr as $classInterfaces) {
foreach ($classInterfaces as $interface) {
if (array_search($interface, $interfaces) === false) {
array_unshift($interfaces, $interface);
}
}
}
return $interfaces;
} | [
"private",
"function",
"getOrderedInterfaces",
"(",
"$",
"className",
")",
"{",
"$",
"interfacesArr",
"=",
"$",
"this",
"->",
"prepareClassTreeInterfaces",
"(",
"$",
"className",
")",
";",
"$",
"interfaces",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"interfacesArr",
"as",
"$",
"classInterfaces",
")",
"{",
"foreach",
"(",
"$",
"classInterfaces",
"as",
"$",
"interface",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"interface",
",",
"$",
"interfaces",
")",
"===",
"false",
")",
"{",
"array_unshift",
"(",
"$",
"interfaces",
",",
"$",
"interface",
")",
";",
"}",
"}",
"}",
"return",
"$",
"interfaces",
";",
"}"
] | Get a list of class interfaces ordered by plase of interface declaration.
The list is ordered by place of interface declaration. Interfaces declared on most child class are first,
while those in base class(es) - last.
@param string $className
@return array | [
"Get",
"a",
"list",
"of",
"class",
"interfaces",
"ordered",
"by",
"plase",
"of",
"interface",
"declaration",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L223-L236 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php | RouteDetector.prepareClassTreeInterfaces | private function prepareClassTreeInterfaces($className)
{
$interfacesArr = array();
$reflection = new ReflectionClass($className);
$interfacesArr[] = $reflection->getInterfaceNames();
if (empty($interfacesArr[0])) {
return array();
}
$classParents = class_parents($className);
foreach ($classParents as $parentClass) {
$reflection = new ReflectionClass($parentClass);
$tmpInterfaces = $reflection->getInterfaceNames();
if (empty($tmpInterfaces)) {
return $interfacesArr;
}
array_unshift($interfacesArr, $tmpInterfaces);
}
return $interfacesArr;
} | php | private function prepareClassTreeInterfaces($className)
{
$interfacesArr = array();
$reflection = new ReflectionClass($className);
$interfacesArr[] = $reflection->getInterfaceNames();
if (empty($interfacesArr[0])) {
return array();
}
$classParents = class_parents($className);
foreach ($classParents as $parentClass) {
$reflection = new ReflectionClass($parentClass);
$tmpInterfaces = $reflection->getInterfaceNames();
if (empty($tmpInterfaces)) {
return $interfacesArr;
}
array_unshift($interfacesArr, $tmpInterfaces);
}
return $interfacesArr;
} | [
"private",
"function",
"prepareClassTreeInterfaces",
"(",
"$",
"className",
")",
"{",
"$",
"interfacesArr",
"=",
"array",
"(",
")",
";",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"interfacesArr",
"[",
"]",
"=",
"$",
"reflection",
"->",
"getInterfaceNames",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"interfacesArr",
"[",
"0",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"classParents",
"=",
"class_parents",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"classParents",
"as",
"$",
"parentClass",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"parentClass",
")",
";",
"$",
"tmpInterfaces",
"=",
"$",
"reflection",
"->",
"getInterfaceNames",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"tmpInterfaces",
")",
")",
"{",
"return",
"$",
"interfacesArr",
";",
"}",
"array_unshift",
"(",
"$",
"interfacesArr",
",",
"$",
"tmpInterfaces",
")",
";",
"}",
"return",
"$",
"interfacesArr",
";",
"}"
] | Prepares all interfaces for given class and its parents.
@param string $className
@return array | [
"Prepares",
"all",
"interfaces",
"for",
"given",
"class",
"and",
"its",
"parents",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/RouteDetection/Detector/RouteDetector.php#L244-L262 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.findAllTreeItems | public function findAllTreeItems($publishedOnly = false)
{
$filter = $publishedOnly ? ['published' => true] : [];
return $this->repository->findBy($filter, ['lft' => 'ASC']);
} | php | public function findAllTreeItems($publishedOnly = false)
{
$filter = $publishedOnly ? ['published' => true] : [];
return $this->repository->findBy($filter, ['lft' => 'ASC']);
} | [
"public",
"function",
"findAllTreeItems",
"(",
"$",
"publishedOnly",
"=",
"false",
")",
"{",
"$",
"filter",
"=",
"$",
"publishedOnly",
"?",
"[",
"'published'",
"=>",
"true",
"]",
":",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"repository",
"->",
"findBy",
"(",
"$",
"filter",
",",
"[",
"'lft'",
"=>",
"'ASC'",
"]",
")",
";",
"}"
] | Returns all items in tree structure
@param type $publishedOnly returns only published items
@return type | [
"Returns",
"all",
"items",
"in",
"tree",
"structure"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L26-L30 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.getUniqueAlias | public function getUniqueAlias($entity,
string $titleProperty = 'title',
string $titleValue = null,
string $aliasColumn = 'seoTitle'): string
{
$alias = Strings::webalize($titleValue ?? $entity->{$titleProperty});
$id = $entity->id ?? null;
while (!$this->seoTitleIsUnique($id, $alias, $aliasColumn)) {
if (preg_match('/.*-\d{1,3}$/', $alias)) {
$dashPosition = strrpos($alias, '-');
$base = substr($alias, 0, $dashPosition);
$number = substr($alias, $dashPosition + 1);
$number++;
$alias = "$base-$number";
} else {
$alias = $alias . '-1';
}
}
return $alias;
} | php | public function getUniqueAlias($entity,
string $titleProperty = 'title',
string $titleValue = null,
string $aliasColumn = 'seoTitle'): string
{
$alias = Strings::webalize($titleValue ?? $entity->{$titleProperty});
$id = $entity->id ?? null;
while (!$this->seoTitleIsUnique($id, $alias, $aliasColumn)) {
if (preg_match('/.*-\d{1,3}$/', $alias)) {
$dashPosition = strrpos($alias, '-');
$base = substr($alias, 0, $dashPosition);
$number = substr($alias, $dashPosition + 1);
$number++;
$alias = "$base-$number";
} else {
$alias = $alias . '-1';
}
}
return $alias;
} | [
"public",
"function",
"getUniqueAlias",
"(",
"$",
"entity",
",",
"string",
"$",
"titleProperty",
"=",
"'title'",
",",
"string",
"$",
"titleValue",
"=",
"null",
",",
"string",
"$",
"aliasColumn",
"=",
"'seoTitle'",
")",
":",
"string",
"{",
"$",
"alias",
"=",
"Strings",
"::",
"webalize",
"(",
"$",
"titleValue",
"??",
"$",
"entity",
"->",
"{",
"$",
"titleProperty",
"}",
")",
";",
"$",
"id",
"=",
"$",
"entity",
"->",
"id",
"??",
"null",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"seoTitleIsUnique",
"(",
"$",
"id",
",",
"$",
"alias",
",",
"$",
"aliasColumn",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/.*-\\d{1,3}$/'",
",",
"$",
"alias",
")",
")",
"{",
"$",
"dashPosition",
"=",
"strrpos",
"(",
"$",
"alias",
",",
"'-'",
")",
";",
"$",
"base",
"=",
"substr",
"(",
"$",
"alias",
",",
"0",
",",
"$",
"dashPosition",
")",
";",
"$",
"number",
"=",
"substr",
"(",
"$",
"alias",
",",
"$",
"dashPosition",
"+",
"1",
")",
";",
"$",
"number",
"++",
";",
"$",
"alias",
"=",
"\"$base-$number\"",
";",
"}",
"else",
"{",
"$",
"alias",
"=",
"$",
"alias",
".",
"'-1'",
";",
"}",
"}",
"return",
"$",
"alias",
";",
"}"
] | Returns unique seo alias for entity
@param entity $entity
@param string $titleProperty
@param string $titleValue
@param string $aliasColumn
@return string entity seo title | [
"Returns",
"unique",
"seo",
"alias",
"for",
"entity"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L80-L99 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.seoTitleIsUnique | private function seoTitleIsUnique($id,
string $generatedAlias,
string $aliasColumn = 'seoTitle'): bool
{
$alias = Strings::webalize($generatedAlias);
if ($id === null) {
$results = $this->repository->findBy([$aliasColumn => $alias]);
} else {
$results = $this->repository->findBy([$aliasColumn => $alias, 'id !=' => $id]);
}
return count($results) === 0;
} | php | private function seoTitleIsUnique($id,
string $generatedAlias,
string $aliasColumn = 'seoTitle'): bool
{
$alias = Strings::webalize($generatedAlias);
if ($id === null) {
$results = $this->repository->findBy([$aliasColumn => $alias]);
} else {
$results = $this->repository->findBy([$aliasColumn => $alias, 'id !=' => $id]);
}
return count($results) === 0;
} | [
"private",
"function",
"seoTitleIsUnique",
"(",
"$",
"id",
",",
"string",
"$",
"generatedAlias",
",",
"string",
"$",
"aliasColumn",
"=",
"'seoTitle'",
")",
":",
"bool",
"{",
"$",
"alias",
"=",
"Strings",
"::",
"webalize",
"(",
"$",
"generatedAlias",
")",
";",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"repository",
"->",
"findBy",
"(",
"[",
"$",
"aliasColumn",
"=>",
"$",
"alias",
"]",
")",
";",
"}",
"else",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"repository",
"->",
"findBy",
"(",
"[",
"$",
"aliasColumn",
"=>",
"$",
"alias",
",",
"'id !='",
"=>",
"$",
"id",
"]",
")",
";",
"}",
"return",
"count",
"(",
"$",
"results",
")",
"===",
"0",
";",
"}"
] | Checks if seo title is unique.
@param int|NULL $id
@param string $generatedAlias
@param string $aliasColumn
@return boolean | [
"Checks",
"if",
"seo",
"title",
"is",
"unique",
"."
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L108-L119 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.removeImage | public function removeImage($entityId)
{
if (!$entityId) {
return false;
}
$delete = '
UPDATE ' . $this->repository->getClassName() . ' a
SET a.image = NULL
WHERE a.id = ' . $entityId . '
';
$q = $this->query($delete);
$q->execute();
} | php | public function removeImage($entityId)
{
if (!$entityId) {
return false;
}
$delete = '
UPDATE ' . $this->repository->getClassName() . ' a
SET a.image = NULL
WHERE a.id = ' . $entityId . '
';
$q = $this->query($delete);
$q->execute();
} | [
"public",
"function",
"removeImage",
"(",
"$",
"entityId",
")",
"{",
"if",
"(",
"!",
"$",
"entityId",
")",
"{",
"return",
"false",
";",
"}",
"$",
"delete",
"=",
"'\n UPDATE '",
".",
"$",
"this",
"->",
"repository",
"->",
"getClassName",
"(",
")",
".",
"' a\n SET a.image = NULL\n WHERE a.id = '",
".",
"$",
"entityId",
".",
"'\n '",
";",
"$",
"q",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"delete",
")",
";",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"}"
] | Sets image to NULL
@param string $entityId | [
"Sets",
"image",
"to",
"NULL"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L125-L138 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.getNewMaxId | public function getNewMaxId($entityClassname): int
{
$maxId = $this->em->createQueryBuilder()
->select('MAX(e.id) + 1')
->from($entityClassname, 'e')
->getQuery()
->getSingleScalarResult();
return (int) $maxId;
} | php | public function getNewMaxId($entityClassname): int
{
$maxId = $this->em->createQueryBuilder()
->select('MAX(e.id) + 1')
->from($entityClassname, 'e')
->getQuery()
->getSingleScalarResult();
return (int) $maxId;
} | [
"public",
"function",
"getNewMaxId",
"(",
"$",
"entityClassname",
")",
":",
"int",
"{",
"$",
"maxId",
"=",
"$",
"this",
"->",
"em",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'MAX(e.id) + 1'",
")",
"->",
"from",
"(",
"$",
"entityClassname",
",",
"'e'",
")",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"return",
"(",
"int",
")",
"$",
"maxId",
";",
"}"
] | Returns new MAX ID for entity
@param string $entityClassname
@return int | [
"Returns",
"new",
"MAX",
"ID",
"for",
"entity"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L145-L153 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.rebuildTree | public function rebuildTree($entityClass = '',
$parentEntity)
{
if ($entityClass === '') {
throw new Exception('messages.error.classNameNotProvided');
}
if ($parentEntity === null) {
throw new Exception('messages.error.cantRemakeTree');
}
$dqlLft = '
UPDATE ' . $entityClass . ' a
SET a.lft = a.lft + 2
WHERE a.lft > ' . $parentEntity->rgt . '
';
$q = $this->query($dqlLft);
$q->execute();
$dqlRgt = '
UPDATE ' . $entityClass . ' a
SET a.rgt = a.rgt + 2
WHERE a.rgt >= ' . $parentEntity->rgt . '
';
$q2 = $this->query($dqlRgt);
$q2->execute();
} | php | public function rebuildTree($entityClass = '',
$parentEntity)
{
if ($entityClass === '') {
throw new Exception('messages.error.classNameNotProvided');
}
if ($parentEntity === null) {
throw new Exception('messages.error.cantRemakeTree');
}
$dqlLft = '
UPDATE ' . $entityClass . ' a
SET a.lft = a.lft + 2
WHERE a.lft > ' . $parentEntity->rgt . '
';
$q = $this->query($dqlLft);
$q->execute();
$dqlRgt = '
UPDATE ' . $entityClass . ' a
SET a.rgt = a.rgt + 2
WHERE a.rgt >= ' . $parentEntity->rgt . '
';
$q2 = $this->query($dqlRgt);
$q2->execute();
} | [
"public",
"function",
"rebuildTree",
"(",
"$",
"entityClass",
"=",
"''",
",",
"$",
"parentEntity",
")",
"{",
"if",
"(",
"$",
"entityClass",
"===",
"''",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'messages.error.classNameNotProvided'",
")",
";",
"}",
"if",
"(",
"$",
"parentEntity",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'messages.error.cantRemakeTree'",
")",
";",
"}",
"$",
"dqlLft",
"=",
"'\n UPDATE '",
".",
"$",
"entityClass",
".",
"' a\n SET a.lft = a.lft + 2\n WHERE a.lft > '",
".",
"$",
"parentEntity",
"->",
"rgt",
".",
"'\n '",
";",
"$",
"q",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"dqlLft",
")",
";",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"$",
"dqlRgt",
"=",
"'\n UPDATE '",
".",
"$",
"entityClass",
".",
"' a\n SET a.rgt = a.rgt + 2\n WHERE a.rgt >= '",
".",
"$",
"parentEntity",
"->",
"rgt",
".",
"'\n '",
";",
"$",
"q2",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"dqlRgt",
")",
";",
"$",
"q2",
"->",
"execute",
"(",
")",
";",
"}"
] | Rebuilds a tree structure by setting lft and rgt values across the rest of the tree
@param type $entityClass Class with defined entity
@param type $parentEntity Entity object
@throws Exception | [
"Rebuilds",
"a",
"tree",
"structure",
"by",
"setting",
"lft",
"and",
"rgt",
"values",
"across",
"the",
"rest",
"of",
"the",
"tree"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L196-L220 | train |
WellBloud/sovacore-core | src/model/AdminModule/repository/BaseRepository.php | BaseRepository.deleteTreeItem | public function deleteTreeItem($entityClass = '',
$id)
{
if ($entityClass === '') {
throw new Exception('messages.error.classNameNotProvided');
}
$entity = $this->findById($id);
$difference = $entity->rgt - $entity->lft + 1;
$deleteTree = '
DELETE FROM ' . $entityClass . ' a
WHERE a.lft >= ' . $entity->lft . '
AND a.rgt <= ' . $entity->rgt . '
';
$qTree = $this->query($deleteTree);
$qTree->execute();
$updateLft = '
UPDATE ' . $entityClass . ' a
SET a.lft = a.lft - ' . $difference . '
WHERE a.lft > ' . $entity->rgt . '
';
$qLft = $this->query($updateLft);
$qLft->execute();
$updateRgt = '
UPDATE ' . $entityClass . ' a
SET a.rgt = a.rgt - ' . $difference . '
WHERE a.rgt > ' . $entity->rgt . '
';
$qRgt = $this->query($updateRgt);
$qRgt->execute();
} | php | public function deleteTreeItem($entityClass = '',
$id)
{
if ($entityClass === '') {
throw new Exception('messages.error.classNameNotProvided');
}
$entity = $this->findById($id);
$difference = $entity->rgt - $entity->lft + 1;
$deleteTree = '
DELETE FROM ' . $entityClass . ' a
WHERE a.lft >= ' . $entity->lft . '
AND a.rgt <= ' . $entity->rgt . '
';
$qTree = $this->query($deleteTree);
$qTree->execute();
$updateLft = '
UPDATE ' . $entityClass . ' a
SET a.lft = a.lft - ' . $difference . '
WHERE a.lft > ' . $entity->rgt . '
';
$qLft = $this->query($updateLft);
$qLft->execute();
$updateRgt = '
UPDATE ' . $entityClass . ' a
SET a.rgt = a.rgt - ' . $difference . '
WHERE a.rgt > ' . $entity->rgt . '
';
$qRgt = $this->query($updateRgt);
$qRgt->execute();
} | [
"public",
"function",
"deleteTreeItem",
"(",
"$",
"entityClass",
"=",
"''",
",",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"entityClass",
"===",
"''",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'messages.error.classNameNotProvided'",
")",
";",
"}",
"$",
"entity",
"=",
"$",
"this",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"$",
"difference",
"=",
"$",
"entity",
"->",
"rgt",
"-",
"$",
"entity",
"->",
"lft",
"+",
"1",
";",
"$",
"deleteTree",
"=",
"'\n DELETE FROM '",
".",
"$",
"entityClass",
".",
"' a\n WHERE a.lft >= '",
".",
"$",
"entity",
"->",
"lft",
".",
"'\n AND a.rgt <= '",
".",
"$",
"entity",
"->",
"rgt",
".",
"'\n '",
";",
"$",
"qTree",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"deleteTree",
")",
";",
"$",
"qTree",
"->",
"execute",
"(",
")",
";",
"$",
"updateLft",
"=",
"'\n UPDATE '",
".",
"$",
"entityClass",
".",
"' a\n SET a.lft = a.lft - '",
".",
"$",
"difference",
".",
"'\n WHERE a.lft > '",
".",
"$",
"entity",
"->",
"rgt",
".",
"'\n '",
";",
"$",
"qLft",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"updateLft",
")",
";",
"$",
"qLft",
"->",
"execute",
"(",
")",
";",
"$",
"updateRgt",
"=",
"'\n UPDATE '",
".",
"$",
"entityClass",
".",
"' a\n SET a.rgt = a.rgt - '",
".",
"$",
"difference",
".",
"'\n WHERE a.rgt > '",
".",
"$",
"entity",
"->",
"rgt",
".",
"'\n '",
";",
"$",
"qRgt",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"updateRgt",
")",
";",
"$",
"qRgt",
"->",
"execute",
"(",
")",
";",
"}"
] | Deletes a tree node and updates rest of the tree
@param type $entityClass Class with defined entity
@param type $id | [
"Deletes",
"a",
"tree",
"node",
"and",
"updates",
"rest",
"of",
"the",
"tree"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/AdminModule/repository/BaseRepository.php#L227-L259 | train |
aztech-labs/skwal | src/Query/Select.php | Select.deriveColumn | public function deriveColumn($index)
{
$this->validateColumnIndex($index);
$column = new DerivedColumn($this->columns[$index]->getAlias());
return $column->setTable($this);
} | php | public function deriveColumn($index)
{
$this->validateColumnIndex($index);
$column = new DerivedColumn($this->columns[$index]->getAlias());
return $column->setTable($this);
} | [
"public",
"function",
"deriveColumn",
"(",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"validateColumnIndex",
"(",
"$",
"index",
")",
";",
"$",
"column",
"=",
"new",
"DerivedColumn",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"index",
"]",
"->",
"getAlias",
"(",
")",
")",
";",
"return",
"$",
"column",
"->",
"setTable",
"(",
"$",
"this",
")",
";",
"}"
] | Derives an expression in the query's select clause as a column of the query's associated resultset.
@param int $index
@throws \OutOfRangeException
@return multitype:\Aztech\Skwal\Expression\AliasExpression | [
"Derives",
"an",
"expression",
"in",
"the",
"query",
"s",
"select",
"clause",
"as",
"a",
"column",
"of",
"the",
"query",
"s",
"associated",
"resultset",
"."
] | cf637c5ddb69f6579ba28a61af9c39639081dc16 | https://github.com/aztech-labs/skwal/blob/cf637c5ddb69f6579ba28a61af9c39639081dc16/src/Query/Select.php#L196-L203 | train |
aztech-labs/skwal | src/Query/Select.php | Select.deriveColumns | public function deriveColumns()
{
$derived = array();
for ($i = 0; $i < count($this->columns); $i ++) {
$derived[] = $this->deriveColumn($i);
}
return $derived;
} | php | public function deriveColumns()
{
$derived = array();
for ($i = 0; $i < count($this->columns); $i ++) {
$derived[] = $this->deriveColumn($i);
}
return $derived;
} | [
"public",
"function",
"deriveColumns",
"(",
")",
"{",
"$",
"derived",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"derived",
"[",
"]",
"=",
"$",
"this",
"->",
"deriveColumn",
"(",
"$",
"i",
")",
";",
"}",
"return",
"$",
"derived",
";",
"}"
] | Derives all expressions in the query's select clause as columns of the query's associated resultset.
@return multitype:Ambigous <\Aztech\Skwal\Query\multitype:\Aztech\Skwal\Expression\AliasExpression, \Aztech\Skwal\Expression\DerivedColumn> | [
"Derives",
"all",
"expressions",
"in",
"the",
"query",
"s",
"select",
"clause",
"as",
"columns",
"of",
"the",
"query",
"s",
"associated",
"resultset",
"."
] | cf637c5ddb69f6579ba28a61af9c39639081dc16 | https://github.com/aztech-labs/skwal/blob/cf637c5ddb69f6579ba28a61af9c39639081dc16/src/Query/Select.php#L210-L219 | train |
valu-digital/valusetup | src/ValuSetup/Setup/SetupUtilsOptions.php | SetupUtilsOptions.setModuleDirs | public function setModuleDirs($dirs) {
if(!is_array($dirs) && !($dirs instanceof \Traversable)){
throw new \InvalidArgumentException('Invalid argument $dirs; array or instance of Traversable expected');
}
$this->moduleDirs = array();
foreach($dirs as $dir){
if(!is_dir($dir) || !is_readable($dir)){
throw new \Exception('Illegal module directory specified: '.$dir);
}
$this->moduleDirs[] = $dir;
}
} | php | public function setModuleDirs($dirs) {
if(!is_array($dirs) && !($dirs instanceof \Traversable)){
throw new \InvalidArgumentException('Invalid argument $dirs; array or instance of Traversable expected');
}
$this->moduleDirs = array();
foreach($dirs as $dir){
if(!is_dir($dir) || !is_readable($dir)){
throw new \Exception('Illegal module directory specified: '.$dir);
}
$this->moduleDirs[] = $dir;
}
} | [
"public",
"function",
"setModuleDirs",
"(",
"$",
"dirs",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dirs",
")",
"&&",
"!",
"(",
"$",
"dirs",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid argument $dirs; array or instance of Traversable expected'",
")",
";",
"}",
"$",
"this",
"->",
"moduleDirs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
"||",
"!",
"is_readable",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Illegal module directory specified: '",
".",
"$",
"dir",
")",
";",
"}",
"$",
"this",
"->",
"moduleDirs",
"[",
"]",
"=",
"$",
"dir",
";",
"}",
"}"
] | Set module directories
@param array $moduleDirs | [
"Set",
"module",
"directories"
] | db1a0bfe1262d555eb11cd0d99625b9ee43d6744 | https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Setup/SetupUtilsOptions.php#L56-L71 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.isValidFieldOccurrence | public static function isValidFieldOccurrence ($arg)
{
if ($arg === null || ctype_digit($arg)) {
$arg = (int)$arg;
}
return is_int($arg) && $arg >= 0 && $arg < 100;
} | php | public static function isValidFieldOccurrence ($arg)
{
if ($arg === null || ctype_digit($arg)) {
$arg = (int)$arg;
}
return is_int($arg) && $arg >= 0 && $arg < 100;
} | [
"public",
"static",
"function",
"isValidFieldOccurrence",
"(",
"$",
"arg",
")",
"{",
"if",
"(",
"$",
"arg",
"===",
"null",
"||",
"ctype_digit",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"arg",
"=",
"(",
"int",
")",
"$",
"arg",
";",
"}",
"return",
"is_int",
"(",
"$",
"arg",
")",
"&&",
"$",
"arg",
">=",
"0",
"&&",
"$",
"arg",
"<",
"100",
";",
"}"
] | Return TRUE if argument is a valid field occurrence.
Argument is casted to int iff it is either null or a numeric string.
@param mixed $arg Variable to check
@return boolean TRUE if argument is a valid field occurrence | [
"Return",
"TRUE",
"if",
"argument",
"is",
"a",
"valid",
"field",
"occurrence",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L60-L66 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.match | public static function match ($reBody)
{
if (strpos($reBody, '#') !== false) {
$reBody = str_replace('#', '\#', $reBody);
}
$regexp = "#{$reBody}#D";
return function (Field $field) use ($regexp) {
return (bool)preg_match($regexp, $field->getShorthand());
};
} | php | public static function match ($reBody)
{
if (strpos($reBody, '#') !== false) {
$reBody = str_replace('#', '\#', $reBody);
}
$regexp = "#{$reBody}#D";
return function (Field $field) use ($regexp) {
return (bool)preg_match($regexp, $field->getShorthand());
};
} | [
"public",
"static",
"function",
"match",
"(",
"$",
"reBody",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"reBody",
",",
"'#'",
")",
"!==",
"false",
")",
"{",
"$",
"reBody",
"=",
"str_replace",
"(",
"'#'",
",",
"'\\#'",
",",
"$",
"reBody",
")",
";",
"}",
"$",
"regexp",
"=",
"\"#{$reBody}#D\"",
";",
"return",
"function",
"(",
"Field",
"$",
"field",
")",
"use",
"(",
"$",
"regexp",
")",
"{",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"field",
"->",
"getShorthand",
"(",
")",
")",
";",
"}",
";",
"}"
] | Return predicate that matches a field shorthand against a regular
expression.
@param string $reBody Body of regular expression
@return callback Predicate | [
"Return",
"predicate",
"that",
"matches",
"a",
"field",
"shorthand",
"against",
"a",
"regular",
"expression",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L75-L84 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.factory | public static function factory (array $field)
{
foreach (array('tag', 'occurrence', 'subfields') as $index) {
if (!array_key_exists($index, $field)) {
throw new InvalidArgumentException("Missing '{$index}' index in field array");
}
}
return new Field($field['tag'],
$field['occurrence'],
array_map(array('HAB\Pica\Record\Subfield', 'factory'), $field['subfields']));
} | php | public static function factory (array $field)
{
foreach (array('tag', 'occurrence', 'subfields') as $index) {
if (!array_key_exists($index, $field)) {
throw new InvalidArgumentException("Missing '{$index}' index in field array");
}
}
return new Field($field['tag'],
$field['occurrence'],
array_map(array('HAB\Pica\Record\Subfield', 'factory'), $field['subfields']));
} | [
"public",
"static",
"function",
"factory",
"(",
"array",
"$",
"field",
")",
"{",
"foreach",
"(",
"array",
"(",
"'tag'",
",",
"'occurrence'",
",",
"'subfields'",
")",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Missing '{$index}' index in field array\"",
")",
";",
"}",
"}",
"return",
"new",
"Field",
"(",
"$",
"field",
"[",
"'tag'",
"]",
",",
"$",
"field",
"[",
"'occurrence'",
"]",
",",
"array_map",
"(",
"array",
"(",
"'HAB\\Pica\\Record\\Subfield'",
",",
"'factory'",
")",
",",
"$",
"field",
"[",
"'subfields'",
"]",
")",
")",
";",
"}"
] | Return a new field based on its array representation.
@throws InvalidArgumentException Missing `tag', `occurrene', or `subfields' index
@param array $field Array representation of a field
@return \HAB\Pica\Record\Field A shiny new field | [
"Return",
"a",
"new",
"field",
"based",
"on",
"its",
"array",
"representation",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L93-L103 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.setSubfields | public function setSubfields (array $subfields)
{
$this->_subfields = array();
foreach ($subfields as $subfield) {
$this->addSubfield($subfield);
}
} | php | public function setSubfields (array $subfields)
{
$this->_subfields = array();
foreach ($subfields as $subfield) {
$this->addSubfield($subfield);
}
} | [
"public",
"function",
"setSubfields",
"(",
"array",
"$",
"subfields",
")",
"{",
"$",
"this",
"->",
"_subfields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"subfields",
"as",
"$",
"subfield",
")",
"{",
"$",
"this",
"->",
"addSubfield",
"(",
"$",
"subfield",
")",
";",
"}",
"}"
] | Set the field subfields.
Replaces the subfield list with subfields in argument.
@param array $subfields Subfields
@return void | [
"Set",
"the",
"field",
"subfields",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L174-L180 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.addSubfield | public function addSubfield (\HAB\Pica\Record\Subfield $subfield)
{
if (in_array($subfield, $this->getSubfields(), true)) {
throw new InvalidArgumentException("Cannot add subfield: Subfield already part of the subfield list");
}
$this->_subfields []= $subfield;
} | php | public function addSubfield (\HAB\Pica\Record\Subfield $subfield)
{
if (in_array($subfield, $this->getSubfields(), true)) {
throw new InvalidArgumentException("Cannot add subfield: Subfield already part of the subfield list");
}
$this->_subfields []= $subfield;
} | [
"public",
"function",
"addSubfield",
"(",
"\\",
"HAB",
"\\",
"Pica",
"\\",
"Record",
"\\",
"Subfield",
"$",
"subfield",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"subfield",
",",
"$",
"this",
"->",
"getSubfields",
"(",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Cannot add subfield: Subfield already part of the subfield list\"",
")",
";",
"}",
"$",
"this",
"->",
"_subfields",
"[",
"]",
"=",
"$",
"subfield",
";",
"}"
] | Add a subfield to the end of the subfield list.
@throws InvalidArgumentException Subfield already present in subfield list
@param \HAB\Pica\Record\Subfield $subfield Subfield to add
@return void | [
"Add",
"a",
"subfield",
"to",
"the",
"end",
"of",
"the",
"subfield",
"list",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L189-L195 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.removeSubfield | public function removeSubfield (\HAB\Pica\Record\Subfield $subfield)
{
$index = array_search($subfield, $this->_subfields, true);
if ($index === false) {
throw new InvalidArgumentException("Cannot remove subfield: Subfield not part of the subfield list");
}
unset($this->_subfields[$index]);
} | php | public function removeSubfield (\HAB\Pica\Record\Subfield $subfield)
{
$index = array_search($subfield, $this->_subfields, true);
if ($index === false) {
throw new InvalidArgumentException("Cannot remove subfield: Subfield not part of the subfield list");
}
unset($this->_subfields[$index]);
} | [
"public",
"function",
"removeSubfield",
"(",
"\\",
"HAB",
"\\",
"Pica",
"\\",
"Record",
"\\",
"Subfield",
"$",
"subfield",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"subfield",
",",
"$",
"this",
"->",
"_subfields",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Cannot remove subfield: Subfield not part of the subfield list\"",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_subfields",
"[",
"$",
"index",
"]",
")",
";",
"}"
] | Remove a subfield.
@throws InvalidArgumentException Subfield is not part of the subfield list
@param \HAB\Pica\Record\Subfield $subfield Subfield to delete
@return void | [
"Remove",
"a",
"subfield",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L204-L211 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.getSubfields | public function getSubfields ()
{
if (func_num_args() === 0) {
return $this->_subfields;
} else {
$selected = array();
$codes = array();
$subfields = $this->getSubfields();
array_walk($subfields, function ($value, $index) use (&$codes) { $codes[$index] = $value->getCode(); });
foreach (func_get_args() as $arg) {
$index = array_search($arg, $codes, true);
if ($index === false) {
$selected []= null;
} else {
$selected []= $subfields[$index];
unset($codes[$index]);
}
}
return $selected;
}
} | php | public function getSubfields ()
{
if (func_num_args() === 0) {
return $this->_subfields;
} else {
$selected = array();
$codes = array();
$subfields = $this->getSubfields();
array_walk($subfields, function ($value, $index) use (&$codes) { $codes[$index] = $value->getCode(); });
foreach (func_get_args() as $arg) {
$index = array_search($arg, $codes, true);
if ($index === false) {
$selected []= null;
} else {
$selected []= $subfields[$index];
unset($codes[$index]);
}
}
return $selected;
}
} | [
"public",
"function",
"getSubfields",
"(",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"_subfields",
";",
"}",
"else",
"{",
"$",
"selected",
"=",
"array",
"(",
")",
";",
"$",
"codes",
"=",
"array",
"(",
")",
";",
"$",
"subfields",
"=",
"$",
"this",
"->",
"getSubfields",
"(",
")",
";",
"array_walk",
"(",
"$",
"subfields",
",",
"function",
"(",
"$",
"value",
",",
"$",
"index",
")",
"use",
"(",
"&",
"$",
"codes",
")",
"{",
"$",
"codes",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
"->",
"getCode",
"(",
")",
";",
"}",
")",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"arg",
",",
"$",
"codes",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"$",
"selected",
"[",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"selected",
"[",
"]",
"=",
"$",
"subfields",
"[",
"$",
"index",
"]",
";",
"unset",
"(",
"$",
"codes",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"return",
"$",
"selected",
";",
"}",
"}"
] | Return the field's subfields.
Returns all subfields when called with no arguments.
Otherwise the returned array is constructed as follows:
Each argument is interpreted as a subfield code. The nth element of the
returned array maps to the nth argument in the function call and contains
NULL if the field does not have a subfield with the selected code, or the
subfield if it exists. In order to retrieve multiple subfields with an
identical code you repeat the subfield code in the argument list.
@return array Subfields | [
"Return",
"the",
"field",
"s",
"subfields",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L228-L248 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.getNthSubfield | public function getNthSubfield ($code, $n)
{
$count = 0;
foreach ($this->getSubfields() as $subfield) {
if ($subfield->getCode() == $code) {
if ($count == $n) {
return $subfield;
}
$count++;
}
}
return null;
} | php | public function getNthSubfield ($code, $n)
{
$count = 0;
foreach ($this->getSubfields() as $subfield) {
if ($subfield->getCode() == $code) {
if ($count == $n) {
return $subfield;
}
$count++;
}
}
return null;
} | [
"public",
"function",
"getNthSubfield",
"(",
"$",
"code",
",",
"$",
"n",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"getSubfields",
"(",
")",
"as",
"$",
"subfield",
")",
"{",
"if",
"(",
"$",
"subfield",
"->",
"getCode",
"(",
")",
"==",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"count",
"==",
"$",
"n",
")",
"{",
"return",
"$",
"subfield",
";",
"}",
"$",
"count",
"++",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Return the nth occurrence of a subfield with specified code.
@param string $code Subfield code
@param integer $n Zero-based subfield index
@return \HAB\Pica\record\Subfield|null The requested subfield or NULL if
none exists | [
"Return",
"the",
"nth",
"occurrence",
"of",
"a",
"subfield",
"with",
"specified",
"code",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L258-L270 | train |
dmj/PicaRecord | src/HAB/Pica/Record/Field.php | Field.getSubfieldsWithCode | public function getSubfieldsWithCode ($code)
{
return array_filter($this->_subfields, function (Subfield $s) use ($code) { return $s->getCode() == $code; });
} | php | public function getSubfieldsWithCode ($code)
{
return array_filter($this->_subfields, function (Subfield $s) use ($code) { return $s->getCode() == $code; });
} | [
"public",
"function",
"getSubfieldsWithCode",
"(",
"$",
"code",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"_subfields",
",",
"function",
"(",
"Subfield",
"$",
"s",
")",
"use",
"(",
"$",
"code",
")",
"{",
"return",
"$",
"s",
"->",
"getCode",
"(",
")",
"==",
"$",
"code",
";",
"}",
")",
";",
"}"
] | Return all subfields with the specified code.
@param string $code Subfield code
@return array | [
"Return",
"all",
"subfields",
"with",
"the",
"specified",
"code",
"."
] | bd5577b9a4333aa6156398b94cc870a9377061b8 | https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Field.php#L293-L296 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Check.php | Check.setDefinition | public function setDefinition($definition)
{
if ($definition instanceof Expression) {
$definition = (string) $definition;
}
$this->definition = $definition;
} | php | public function setDefinition($definition)
{
if ($definition instanceof Expression) {
$definition = (string) $definition;
}
$this->definition = $definition;
} | [
"public",
"function",
"setDefinition",
"(",
"$",
"definition",
")",
"{",
"if",
"(",
"$",
"definition",
"instanceof",
"Expression",
")",
"{",
"$",
"definition",
"=",
"(",
"string",
")",
"$",
"definition",
";",
"}",
"$",
"this",
"->",
"definition",
"=",
"$",
"definition",
";",
"}"
] | Set the definition.
@param string|\Fridge\DBAL\Query\Expression\Expression $definition The definition. | [
"Set",
"the",
"definition",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Check.php#L58-L65 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Client.php | Client.getDefaultAdapter | private function getDefaultAdapter()
{
if (extension_loaded('curl')) {
$this->parallelAdapter = new MultiAdapter($this->messageFactory);
$this->adapter = function_exists('curl_reset')
? new CurlAdapter($this->messageFactory)
: $this->parallelAdapter;
if (ini_get('allow_url_fopen')) {
$this->adapter = new StreamingProxyAdapter(
$this->adapter,
new StreamAdapter($this->messageFactory)
);
}
} elseif (ini_get('allow_url_fopen')) {
$this->adapter = new StreamAdapter($this->messageFactory);
} else {
throw new \RuntimeException('Guzzle requires cURL, the '
. 'allow_url_fopen ini setting, or a custom HTTP adapter.');
}
} | php | private function getDefaultAdapter()
{
if (extension_loaded('curl')) {
$this->parallelAdapter = new MultiAdapter($this->messageFactory);
$this->adapter = function_exists('curl_reset')
? new CurlAdapter($this->messageFactory)
: $this->parallelAdapter;
if (ini_get('allow_url_fopen')) {
$this->adapter = new StreamingProxyAdapter(
$this->adapter,
new StreamAdapter($this->messageFactory)
);
}
} elseif (ini_get('allow_url_fopen')) {
$this->adapter = new StreamAdapter($this->messageFactory);
} else {
throw new \RuntimeException('Guzzle requires cURL, the '
. 'allow_url_fopen ini setting, or a custom HTTP adapter.');
}
} | [
"private",
"function",
"getDefaultAdapter",
"(",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"'curl'",
")",
")",
"{",
"$",
"this",
"->",
"parallelAdapter",
"=",
"new",
"MultiAdapter",
"(",
"$",
"this",
"->",
"messageFactory",
")",
";",
"$",
"this",
"->",
"adapter",
"=",
"function_exists",
"(",
"'curl_reset'",
")",
"?",
"new",
"CurlAdapter",
"(",
"$",
"this",
"->",
"messageFactory",
")",
":",
"$",
"this",
"->",
"parallelAdapter",
";",
"if",
"(",
"ini_get",
"(",
"'allow_url_fopen'",
")",
")",
"{",
"$",
"this",
"->",
"adapter",
"=",
"new",
"StreamingProxyAdapter",
"(",
"$",
"this",
"->",
"adapter",
",",
"new",
"StreamAdapter",
"(",
"$",
"this",
"->",
"messageFactory",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"ini_get",
"(",
"'allow_url_fopen'",
")",
")",
"{",
"$",
"this",
"->",
"adapter",
"=",
"new",
"StreamAdapter",
"(",
"$",
"this",
"->",
"messageFactory",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Guzzle requires cURL, the '",
".",
"'allow_url_fopen ini setting, or a custom HTTP adapter.'",
")",
";",
"}",
"}"
] | Create a default adapter to use based on the environment
@throws \RuntimeException | [
"Create",
"a",
"default",
"adapter",
"to",
"use",
"based",
"on",
"the",
"environment"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Client.php#L292-L311 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Client.php | Client.mergeDefaults | private function mergeDefaults(&$options)
{
// Merging optimization for when no headers are present
if (!isset($options['headers'])
|| !isset($this->defaults['headers'])) {
$options = array_replace_recursive($this->defaults, $options);
return null;
}
$defaults = $this->defaults;
unset($defaults['headers']);
$options = array_replace_recursive($defaults, $options);
return $this->defaults['headers'];
} | php | private function mergeDefaults(&$options)
{
// Merging optimization for when no headers are present
if (!isset($options['headers'])
|| !isset($this->defaults['headers'])) {
$options = array_replace_recursive($this->defaults, $options);
return null;
}
$defaults = $this->defaults;
unset($defaults['headers']);
$options = array_replace_recursive($defaults, $options);
return $this->defaults['headers'];
} | [
"private",
"function",
"mergeDefaults",
"(",
"&",
"$",
"options",
")",
"{",
"// Merging optimization for when no headers are present",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'headers'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'headers'",
"]",
")",
")",
"{",
"$",
"options",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"defaults",
",",
"$",
"options",
")",
";",
"return",
"null",
";",
"}",
"$",
"defaults",
"=",
"$",
"this",
"->",
"defaults",
";",
"unset",
"(",
"$",
"defaults",
"[",
"'headers'",
"]",
")",
";",
"$",
"options",
"=",
"array_replace_recursive",
"(",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"defaults",
"[",
"'headers'",
"]",
";",
"}"
] | Merges default options into the array passed by reference and returns
an array of headers that need to be merged in after the request is
created.
@param array $options Options to modify by reference
@return array|null | [
"Merges",
"default",
"options",
"into",
"the",
"array",
"passed",
"by",
"reference",
"and",
"returns",
"an",
"array",
"of",
"headers",
"that",
"need",
"to",
"be",
"merged",
"in",
"after",
"the",
"request",
"is",
"created",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Client.php#L382-L396 | train |
mrbase/Smesg | src/Smesg/Adapter/PhpStreamAdapter.php | PhpStreamAdapter.build | protected function build()
{
$content = '';
if (isset($this->parameters) && is_array($this->parameters)) {
$content = http_build_query($this->parameters);
}
if (isset($this->body)) {
$content = $this->body;
}
$content_type = 'application/x-www-form-urlencoded; charset=utf-8';
if (substr($content, 0, 6) == '<?xml ') {
$content_type = 'text/xml; charset=utf-8';
}
$this->request = array(
'http' => array(
'header' => 'Content-type: ' . $content_type,
'method' => 'POST',
'timeout' => 5,
'max_redirects' => 0,
'ignore_errors' => 1,
'content' => $content,
)
);
return $this;
} | php | protected function build()
{
$content = '';
if (isset($this->parameters) && is_array($this->parameters)) {
$content = http_build_query($this->parameters);
}
if (isset($this->body)) {
$content = $this->body;
}
$content_type = 'application/x-www-form-urlencoded; charset=utf-8';
if (substr($content, 0, 6) == '<?xml ') {
$content_type = 'text/xml; charset=utf-8';
}
$this->request = array(
'http' => array(
'header' => 'Content-type: ' . $content_type,
'method' => 'POST',
'timeout' => 5,
'max_redirects' => 0,
'ignore_errors' => 1,
'content' => $content,
)
);
return $this;
} | [
"protected",
"function",
"build",
"(",
")",
"{",
"$",
"content",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parameters",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"parameters",
")",
")",
"{",
"$",
"content",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"body",
")",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"body",
";",
"}",
"$",
"content_type",
"=",
"'application/x-www-form-urlencoded; charset=utf-8'",
";",
"if",
"(",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"6",
")",
"==",
"'<?xml '",
")",
"{",
"$",
"content_type",
"=",
"'text/xml; charset=utf-8'",
";",
"}",
"$",
"this",
"->",
"request",
"=",
"array",
"(",
"'http'",
"=>",
"array",
"(",
"'header'",
"=>",
"'Content-type: '",
".",
"$",
"content_type",
",",
"'method'",
"=>",
"'POST'",
",",
"'timeout'",
"=>",
"5",
",",
"'max_redirects'",
"=>",
"0",
",",
"'ignore_errors'",
"=>",
"1",
",",
"'content'",
"=>",
"$",
"content",
",",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Ready the request for transport
@return PhpStreamAdapter | [
"Ready",
"the",
"request",
"for",
"transport"
] | e9692ed5915f5a9cd4dca0df875935a2c528e128 | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Adapter/PhpStreamAdapter.php#L159-L186 | train |
mrbase/Smesg | src/Smesg/Adapter/PhpStreamAdapter.php | PhpStreamAdapter.sendRequest | protected function sendRequest()
{
$context = stream_context_create($this->request);
$response = trim(file_get_contents($this->endpoint, FALSE, $context));
$this->response = new Response($http_response_header, $response, $this->request);
return $this->response;
} | php | protected function sendRequest()
{
$context = stream_context_create($this->request);
$response = trim(file_get_contents($this->endpoint, FALSE, $context));
$this->response = new Response($http_response_header, $response, $this->request);
return $this->response;
} | [
"protected",
"function",
"sendRequest",
"(",
")",
"{",
"$",
"context",
"=",
"stream_context_create",
"(",
"$",
"this",
"->",
"request",
")",
";",
"$",
"response",
"=",
"trim",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"endpoint",
",",
"FALSE",
",",
"$",
"context",
")",
")",
";",
"$",
"this",
"->",
"response",
"=",
"new",
"Response",
"(",
"$",
"http_response_header",
",",
"$",
"response",
",",
"$",
"this",
"->",
"request",
")",
";",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] | Sends the actual request and returns the response.
@param array $request The stream_wraper options from wich to build the request
@return mixed | [
"Sends",
"the",
"actual",
"request",
"and",
"returns",
"the",
"response",
"."
] | e9692ed5915f5a9cd4dca0df875935a2c528e128 | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Adapter/PhpStreamAdapter.php#L195-L202 | train |
geoffadams/bedrest-core | library/BedRest/Resource/Mapping/ResourceMetadata.php | ResourceMetadata.setSubResources | public function setSubResources(array $subResources)
{
foreach ($subResources as $name => $mapping) {
if (!is_string($name) || !is_array($mapping)) {
throw Exception::invalidSubResources($this->className);
}
if (!isset($mapping['fieldName'])) {
throw Exception::invalidSubResources($this->className);
}
if (!isset($mapping['service'])) {
$mapping['service'] = null;
}
$this->subResources[$name] = $mapping;
}
} | php | public function setSubResources(array $subResources)
{
foreach ($subResources as $name => $mapping) {
if (!is_string($name) || !is_array($mapping)) {
throw Exception::invalidSubResources($this->className);
}
if (!isset($mapping['fieldName'])) {
throw Exception::invalidSubResources($this->className);
}
if (!isset($mapping['service'])) {
$mapping['service'] = null;
}
$this->subResources[$name] = $mapping;
}
} | [
"public",
"function",
"setSubResources",
"(",
"array",
"$",
"subResources",
")",
"{",
"foreach",
"(",
"$",
"subResources",
"as",
"$",
"name",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
"||",
"!",
"is_array",
"(",
"$",
"mapping",
")",
")",
"{",
"throw",
"Exception",
"::",
"invalidSubResources",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
")",
"{",
"throw",
"Exception",
"::",
"invalidSubResources",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'service'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'service'",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"subResources",
"[",
"$",
"name",
"]",
"=",
"$",
"mapping",
";",
"}",
"}"
] | Sets the set of allowable sub-resources.
@param array $subResources
@throws \BedRest\Resource\Mapping\Exception | [
"Sets",
"the",
"set",
"of",
"allowable",
"sub",
"-",
"resources",
"."
] | a77bf8b7492dfbfb720b201f7ec91a4f03417b5c | https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Resource/Mapping/ResourceMetadata.php#L131-L148 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/MediaQuery.php | MediaQuery.format | public function format(array $response)
{
$car = '<br />';
$format = '';
foreach ($response as $media) {
$format .= '<div class="media">'
. '<img src="' . $media->getThumburl() . '"'
. ' width="' . $media->getThumbwidth() . '"'
. ' height="' . $media->getThumbheight() . '"'
. ' title="'.ApiTools::safeString(print_r($media, true)).'">'
. $car . '<span class="pageid">' . $media->getPageid() . '</span>'
. $car . '<span class="title">' . ApiTools::safeString($media->getTitle()) . '</span>'
. '</div>';
}
return $format;
} | php | public function format(array $response)
{
$car = '<br />';
$format = '';
foreach ($response as $media) {
$format .= '<div class="media">'
. '<img src="' . $media->getThumburl() . '"'
. ' width="' . $media->getThumbwidth() . '"'
. ' height="' . $media->getThumbheight() . '"'
. ' title="'.ApiTools::safeString(print_r($media, true)).'">'
. $car . '<span class="pageid">' . $media->getPageid() . '</span>'
. $car . '<span class="title">' . ApiTools::safeString($media->getTitle()) . '</span>'
. '</div>';
}
return $format;
} | [
"public",
"function",
"format",
"(",
"array",
"$",
"response",
")",
"{",
"$",
"car",
"=",
"'<br />'",
";",
"$",
"format",
"=",
"''",
";",
"foreach",
"(",
"$",
"response",
"as",
"$",
"media",
")",
"{",
"$",
"format",
".=",
"'<div class=\"media\">'",
".",
"'<img src=\"'",
".",
"$",
"media",
"->",
"getThumburl",
"(",
")",
".",
"'\"'",
".",
"' width=\"'",
".",
"$",
"media",
"->",
"getThumbwidth",
"(",
")",
".",
"'\"'",
".",
"' height=\"'",
".",
"$",
"media",
"->",
"getThumbheight",
"(",
")",
".",
"'\"'",
".",
"' title=\"'",
".",
"ApiTools",
"::",
"safeString",
"(",
"print_r",
"(",
"$",
"media",
",",
"true",
")",
")",
".",
"'\">'",
".",
"$",
"car",
".",
"'<span class=\"pageid\">'",
".",
"$",
"media",
"->",
"getPageid",
"(",
")",
".",
"'</span>'",
".",
"$",
"car",
".",
"'<span class=\"title\">'",
".",
"ApiTools",
"::",
"safeString",
"(",
"$",
"media",
"->",
"getTitle",
"(",
")",
")",
".",
"'</span>'",
".",
"'</div>'",
";",
"}",
"return",
"$",
"format",
";",
"}"
] | format a media response as an HTML string
@param array $response
@return string | [
"format",
"a",
"media",
"response",
"as",
"an",
"HTML",
"string"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/MediaQuery.php#L109-L124 | train |
ZFrapid/zfrapid-core | src/Task/AbstractTask.php | AbstractTask.filterCamelCaseToUnderscore | public function filterCamelCaseToUnderscore($text)
{
$text = StaticFilter::execute($text, 'Word\CamelCaseToUnderscore');
$text = StaticFilter::execute($text, 'StringToLower');
return $text;
} | php | public function filterCamelCaseToUnderscore($text)
{
$text = StaticFilter::execute($text, 'Word\CamelCaseToUnderscore');
$text = StaticFilter::execute($text, 'StringToLower');
return $text;
} | [
"public",
"function",
"filterCamelCaseToUnderscore",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"text",
",",
"'Word\\CamelCaseToUnderscore'",
")",
";",
"$",
"text",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"text",
",",
"'StringToLower'",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Filter camel case to underscore
@param string $text
@return string | [
"Filter",
"camel",
"case",
"to",
"underscore"
] | 8be56b82f9f5a687619a2b2175fcaa66ad3d2233 | https://github.com/ZFrapid/zfrapid-core/blob/8be56b82f9f5a687619a2b2175fcaa66ad3d2233/src/Task/AbstractTask.php#L86-L92 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php | AbstractDoctrineDriver.doLoadClassMetadata | protected function doLoadClassMetadata($type)
{
if (false === $this->classMetadataExists($type)) {
return null;
}
$className = $this->getClassNameForType($type);
return $this->mf->getMetadataFor($className);
} | php | protected function doLoadClassMetadata($type)
{
if (false === $this->classMetadataExists($type)) {
return null;
}
$className = $this->getClassNameForType($type);
return $this->mf->getMetadataFor($className);
} | [
"protected",
"function",
"doLoadClassMetadata",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"classMetadataExists",
"(",
"$",
"type",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"className",
"=",
"$",
"this",
"->",
"getClassNameForType",
"(",
"$",
"type",
")",
";",
"return",
"$",
"this",
"->",
"mf",
"->",
"getMetadataFor",
"(",
"$",
"className",
")",
";",
"}"
] | Loads Doctrine ClassMetadata for an entity type.
@param string $type
@return ClassMetadata|null | [
"Loads",
"Doctrine",
"ClassMetadata",
"for",
"an",
"entity",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php#L64-L72 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php | AbstractDoctrineDriver.classMetadataExists | protected function classMetadataExists($type)
{
$className = $this->getClassNameForType($type);
try {
$metadata = $this->mf->getMetadataFor($className);
return true;
} catch (MappingException $e) {
return false;
}
return false === $this->shouldFilterClassMetadata($metadata);
} | php | protected function classMetadataExists($type)
{
$className = $this->getClassNameForType($type);
try {
$metadata = $this->mf->getMetadataFor($className);
return true;
} catch (MappingException $e) {
return false;
}
return false === $this->shouldFilterClassMetadata($metadata);
} | [
"protected",
"function",
"classMetadataExists",
"(",
"$",
"type",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"getClassNameForType",
"(",
"$",
"type",
")",
";",
"try",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"mf",
"->",
"getMetadataFor",
"(",
"$",
"className",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"MappingException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"false",
"===",
"$",
"this",
"->",
"shouldFilterClassMetadata",
"(",
"$",
"metadata",
")",
";",
"}"
] | Determines if Doctrine ClassMetadata exists for an entity type.
@param string $type
@return bool | [
"Determines",
"if",
"Doctrine",
"ClassMetadata",
"exists",
"for",
"an",
"entity",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php#L80-L90 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php | AbstractDoctrineDriver.getTypeForClassName | protected function getTypeForClassName($className)
{
if (empty($this->rootNamespace)) {
return $className;
}
return $this->stripNamespace($this->rootNamespace, $className);
} | php | protected function getTypeForClassName($className)
{
if (empty($this->rootNamespace)) {
return $className;
}
return $this->stripNamespace($this->rootNamespace, $className);
} | [
"protected",
"function",
"getTypeForClassName",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"rootNamespace",
")",
")",
"{",
"return",
"$",
"className",
";",
"}",
"return",
"$",
"this",
"->",
"stripNamespace",
"(",
"$",
"this",
"->",
"rootNamespace",
",",
"$",
"className",
")",
";",
"}"
] | Gets the entity type from a Doctrine class name.
@param string $className
@return string | [
"Gets",
"the",
"entity",
"type",
"from",
"a",
"Doctrine",
"class",
"name",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php#L142-L148 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php | AbstractDoctrineDriver.getClassNameForType | protected function getClassNameForType($type)
{
if (!empty($this->rootNamespace) && strstr($type, $this->rootNamespace)) {
$type = $this->stripNamespace($this->rootNamespace, $type);
}
if (!empty($this->rootNamespace)) {
return sprintf('%s\\%s', $this->rootNamespace, $type);
}
return $type;
} | php | protected function getClassNameForType($type)
{
if (!empty($this->rootNamespace) && strstr($type, $this->rootNamespace)) {
$type = $this->stripNamespace($this->rootNamespace, $type);
}
if (!empty($this->rootNamespace)) {
return sprintf('%s\\%s', $this->rootNamespace, $type);
}
return $type;
} | [
"protected",
"function",
"getClassNameForType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"rootNamespace",
")",
"&&",
"strstr",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"rootNamespace",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"stripNamespace",
"(",
"$",
"this",
"->",
"rootNamespace",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"rootNamespace",
")",
")",
"{",
"return",
"sprintf",
"(",
"'%s\\\\%s'",
",",
"$",
"this",
"->",
"rootNamespace",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Gets the Doctrine class name from an entity type.
@param string $type
@return string | [
"Gets",
"the",
"Doctrine",
"class",
"name",
"from",
"an",
"entity",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Driver/AbstractDoctrineDriver.php#L161-L170 | train |
AnonymPHP/Anonym-Route | ActionDispatcher.php | ActionDispatcher.dispatch | public function dispatch($action = [], $group = null)
{
// convert string type to array
if (is_string($action)) {
$action = [
'_controller' => $action
];
}
// find and register route group
$this->registerGroup($group, $action);
// find and run middleware
if ($middleware = $this->findMiddleware($action)) {
app()->call([$this, 'middleware'], $middleware);
}
if (is_array($action)) {
list($controller, $method, $namespace) = $this->findControllerAndMethod($action);
// register the namespace
isset($namespace) ? $this->setNamespace($namespace) : null;
// create a controller instance
$controller = $this->createControllerInstance($controller);
// call the method
$response = $this->callControllerMethod($controller, $method);
return $this->handleResponse($response);
} elseif ($action instanceof Closure) {
return $this->handleResponse(app()->call($action, ParameterBag::getParameters()));
} else {
return false;
}
} | php | public function dispatch($action = [], $group = null)
{
// convert string type to array
if (is_string($action)) {
$action = [
'_controller' => $action
];
}
// find and register route group
$this->registerGroup($group, $action);
// find and run middleware
if ($middleware = $this->findMiddleware($action)) {
app()->call([$this, 'middleware'], $middleware);
}
if (is_array($action)) {
list($controller, $method, $namespace) = $this->findControllerAndMethod($action);
// register the namespace
isset($namespace) ? $this->setNamespace($namespace) : null;
// create a controller instance
$controller = $this->createControllerInstance($controller);
// call the method
$response = $this->callControllerMethod($controller, $method);
return $this->handleResponse($response);
} elseif ($action instanceof Closure) {
return $this->handleResponse(app()->call($action, ParameterBag::getParameters()));
} else {
return false;
}
} | [
"public",
"function",
"dispatch",
"(",
"$",
"action",
"=",
"[",
"]",
",",
"$",
"group",
"=",
"null",
")",
"{",
"// convert string type to array",
"if",
"(",
"is_string",
"(",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"[",
"'_controller'",
"=>",
"$",
"action",
"]",
";",
"}",
"// find and register route group",
"$",
"this",
"->",
"registerGroup",
"(",
"$",
"group",
",",
"$",
"action",
")",
";",
"// find and run middleware",
"if",
"(",
"$",
"middleware",
"=",
"$",
"this",
"->",
"findMiddleware",
"(",
"$",
"action",
")",
")",
"{",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'middleware'",
"]",
",",
"$",
"middleware",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"list",
"(",
"$",
"controller",
",",
"$",
"method",
",",
"$",
"namespace",
")",
"=",
"$",
"this",
"->",
"findControllerAndMethod",
"(",
"$",
"action",
")",
";",
"// register the namespace",
"isset",
"(",
"$",
"namespace",
")",
"?",
"$",
"this",
"->",
"setNamespace",
"(",
"$",
"namespace",
")",
":",
"null",
";",
"// create a controller instance",
"$",
"controller",
"=",
"$",
"this",
"->",
"createControllerInstance",
"(",
"$",
"controller",
")",
";",
"// call the method",
"$",
"response",
"=",
"$",
"this",
"->",
"callControllerMethod",
"(",
"$",
"controller",
",",
"$",
"method",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
"$",
"response",
")",
";",
"}",
"elseif",
"(",
"$",
"action",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
"app",
"(",
")",
"->",
"call",
"(",
"$",
"action",
",",
"ParameterBag",
"::",
"getParameters",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Dispatch a action from array
@param array|string $action
@param array|null $group
@return mixed | [
"Dispatch",
"a",
"action",
"from",
"array"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/ActionDispatcher.php#L85-L123 | train |
AnonymPHP/Anonym-Route | ActionDispatcher.php | ActionDispatcher.findMiddleware | protected function findMiddleware($action)
{
if (is_array($action) && isset($action['_middleware'])) {
return $action['_middleware'];
} elseif (isset($this->group['_middleware'])) {
return $this->group['_middleware'];
}
return false;
} | php | protected function findMiddleware($action)
{
if (is_array($action) && isset($action['_middleware'])) {
return $action['_middleware'];
} elseif (isset($this->group['_middleware'])) {
return $this->group['_middleware'];
}
return false;
} | [
"protected",
"function",
"findMiddleware",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
"&&",
"isset",
"(",
"$",
"action",
"[",
"'_middleware'",
"]",
")",
")",
"{",
"return",
"$",
"action",
"[",
"'_middleware'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"group",
"[",
"'_middleware'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"group",
"[",
"'_middleware'",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | find and return middleware
@param array $action
@return mixed | [
"find",
"and",
"return",
"middleware"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/ActionDispatcher.php#L131-L140 | train |
AnonymPHP/Anonym-Route | ActionDispatcher.php | ActionDispatcher.findControllerAndMethod | protected function findControllerAndMethod(array $action)
{
if (isset($action['_controller']) || $action['uses']) {
$controller = isset($action['_controller']) ? $action['_controller'] : $action['uses'];
if (strstr($controller, ':')) {
list($controller, $method) = explode(':', $controller);
} elseif ($action['_method']) {
$method = $action['_method'];
}
$namespace = $this->findNamespaceInController($controller);
return [$controller, $method, $namespace];
} else {
throw new ControllerException('Your controller variable could not found in your route');
}
} | php | protected function findControllerAndMethod(array $action)
{
if (isset($action['_controller']) || $action['uses']) {
$controller = isset($action['_controller']) ? $action['_controller'] : $action['uses'];
if (strstr($controller, ':')) {
list($controller, $method) = explode(':', $controller);
} elseif ($action['_method']) {
$method = $action['_method'];
}
$namespace = $this->findNamespaceInController($controller);
return [$controller, $method, $namespace];
} else {
throw new ControllerException('Your controller variable could not found in your route');
}
} | [
"protected",
"function",
"findControllerAndMethod",
"(",
"array",
"$",
"action",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"action",
"[",
"'_controller'",
"]",
")",
"||",
"$",
"action",
"[",
"'uses'",
"]",
")",
"{",
"$",
"controller",
"=",
"isset",
"(",
"$",
"action",
"[",
"'_controller'",
"]",
")",
"?",
"$",
"action",
"[",
"'_controller'",
"]",
":",
"$",
"action",
"[",
"'uses'",
"]",
";",
"if",
"(",
"strstr",
"(",
"$",
"controller",
",",
"':'",
")",
")",
"{",
"list",
"(",
"$",
"controller",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"controller",
")",
";",
"}",
"elseif",
"(",
"$",
"action",
"[",
"'_method'",
"]",
")",
"{",
"$",
"method",
"=",
"$",
"action",
"[",
"'_method'",
"]",
";",
"}",
"$",
"namespace",
"=",
"$",
"this",
"->",
"findNamespaceInController",
"(",
"$",
"controller",
")",
";",
"return",
"[",
"$",
"controller",
",",
"$",
"method",
",",
"$",
"namespace",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"ControllerException",
"(",
"'Your controller variable could not found in your route'",
")",
";",
"}",
"}"
] | find controller, method and namespace in action variable
@param array $action
@return array
@throws ControllerException | [
"find",
"controller",
"method",
"and",
"namespace",
"in",
"action",
"variable"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/ActionDispatcher.php#L160-L179 | train |
AnonymPHP/Anonym-Route | ActionDispatcher.php | ActionDispatcher.findNamespaceInController | protected function findNamespaceInController(&$controller)
{
if (strstr($controller, '\\')) {
$namespace = explode('\\', $controller);
$controller = end($namespace);
$namespace = rtrim(join('\\', array_slice($namespace, 0, count($namespace) - 1)), '\\');
} else {
$namespace = isset($this->group['_namespace']) ? $this->group['namespace'] : null;
}
return $namespace;
} | php | protected function findNamespaceInController(&$controller)
{
if (strstr($controller, '\\')) {
$namespace = explode('\\', $controller);
$controller = end($namespace);
$namespace = rtrim(join('\\', array_slice($namespace, 0, count($namespace) - 1)), '\\');
} else {
$namespace = isset($this->group['_namespace']) ? $this->group['namespace'] : null;
}
return $namespace;
} | [
"protected",
"function",
"findNamespaceInController",
"(",
"&",
"$",
"controller",
")",
"{",
"if",
"(",
"strstr",
"(",
"$",
"controller",
",",
"'\\\\'",
")",
")",
"{",
"$",
"namespace",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"controller",
")",
";",
"$",
"controller",
"=",
"end",
"(",
"$",
"namespace",
")",
";",
"$",
"namespace",
"=",
"rtrim",
"(",
"join",
"(",
"'\\\\'",
",",
"array_slice",
"(",
"$",
"namespace",
",",
"0",
",",
"count",
"(",
"$",
"namespace",
")",
"-",
"1",
")",
")",
",",
"'\\\\'",
")",
";",
"}",
"else",
"{",
"$",
"namespace",
"=",
"isset",
"(",
"$",
"this",
"->",
"group",
"[",
"'_namespace'",
"]",
")",
"?",
"$",
"this",
"->",
"group",
"[",
"'namespace'",
"]",
":",
"null",
";",
"}",
"return",
"$",
"namespace",
";",
"}"
] | find namespace in controller
@param string $controller
@return array|string | [
"find",
"namespace",
"in",
"controller"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/ActionDispatcher.php#L187-L198 | train |
AnonymPHP/Anonym-Route | ActionDispatcher.php | ActionDispatcher.handleResponse | private function handleResponse($response)
{
if ($response instanceof View) {
$content = $response->render();
} elseif ($response instanceof Response) {
$content = $response->getContent();
} elseif ($response instanceof Request) {
$content = $response->getResponse()->getContent();
} elseif (is_string($response)) {
$content = $response;
} else {
$content = false;
}
return $content;
} | php | private function handleResponse($response)
{
if ($response instanceof View) {
$content = $response->render();
} elseif ($response instanceof Response) {
$content = $response->getContent();
} elseif ($response instanceof Request) {
$content = $response->getResponse()->getContent();
} elseif (is_string($response)) {
$content = $response;
} else {
$content = false;
}
return $content;
} | [
"private",
"function",
"handleResponse",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"response",
"instanceof",
"View",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"render",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"response",
"instanceof",
"Response",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"response",
"instanceof",
"Request",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"getResponse",
"(",
")",
"->",
"getContent",
"(",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"response",
")",
")",
"{",
"$",
"content",
"=",
"$",
"response",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"false",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Handler the controller returned value
@param ViewExecuteInterface|Response|Request|string $response
@return string|bool | [
"Handler",
"the",
"controller",
"returned",
"value"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/ActionDispatcher.php#L206-L222 | train |
itkg/core | src/Itkg/Core/Command/DatabaseUpdateCommand.php | DatabaseUpdateCommand.setup | protected function setup(InputInterface $input)
{
return $this->setup
->setForcedRollback($input->getOption('force-rollback'))
->setExecuteQueries($input->getOption('execute'))
->setRollbackedFirst($input->getOption('rollback-first'))
->run();
} | php | protected function setup(InputInterface $input)
{
return $this->setup
->setForcedRollback($input->getOption('force-rollback'))
->setExecuteQueries($input->getOption('execute'))
->setRollbackedFirst($input->getOption('rollback-first'))
->run();
} | [
"protected",
"function",
"setup",
"(",
"InputInterface",
"$",
"input",
")",
"{",
"return",
"$",
"this",
"->",
"setup",
"->",
"setForcedRollback",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'force-rollback'",
")",
")",
"->",
"setExecuteQueries",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'execute'",
")",
")",
"->",
"setRollbackedFirst",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'rollback-first'",
")",
")",
"->",
"run",
"(",
")",
";",
"}"
] | Start migration setup
@param \Symfony\Component\Console\Input\InputInterface $input
@return array | [
"Start",
"migration",
"setup"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdateCommand.php#L141-L148 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/ClassUtility/MethodObject/PhpMethodObject.php | PhpMethodObject.getDocComment | public function getDocComment ( $withCommentMark = false ) {
$docComment = $this->_reflectionMethod->getDocComment();
if ( $withCommentMark === true ) {
$docComment = PhpDocCommentObject::ltrim($docComment);
} else {
$docComment = PhpDocCommentObject::stripCommentMarks($docComment);
}
return $docComment;
} | php | public function getDocComment ( $withCommentMark = false ) {
$docComment = $this->_reflectionMethod->getDocComment();
if ( $withCommentMark === true ) {
$docComment = PhpDocCommentObject::ltrim($docComment);
} else {
$docComment = PhpDocCommentObject::stripCommentMarks($docComment);
}
return $docComment;
} | [
"public",
"function",
"getDocComment",
"(",
"$",
"withCommentMark",
"=",
"false",
")",
"{",
"$",
"docComment",
"=",
"$",
"this",
"->",
"_reflectionMethod",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"$",
"withCommentMark",
"===",
"true",
")",
"{",
"$",
"docComment",
"=",
"PhpDocCommentObject",
"::",
"ltrim",
"(",
"$",
"docComment",
")",
";",
"}",
"else",
"{",
"$",
"docComment",
"=",
"PhpDocCommentObject",
"::",
"stripCommentMarks",
"(",
"$",
"docComment",
")",
";",
"}",
"return",
"$",
"docComment",
";",
"}"
] | Get DocComment of method
@param bool $withCommentMark
@return string DocComment | [
"Get",
"DocComment",
"of",
"method"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/ClassUtility/MethodObject/PhpMethodObject.php#L72-L80 | train |
koolkode/view-express | src/Tree/ExpressionNode.php | ExpressionNode.compile | public function compile(ExpressCompiler $compiler, $flags = 0)
{
try
{
if($flags & self::FLAG_RAW)
{
$compiler->write($this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp'));
}
else
{
$compiler->write("\t\ttry {\n");
if($this->stringify)
{
if($this->expression->hasPipedFilter('raw'))
{
$contents = '$out->write(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
}
else
{
$contents = '$out->writeEscaped(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
}
}
else
{
$contents = 'return ' . $this->expression->compile($compiler->getExpressionContextFactory(), false, $this->exp) . ';';
}
$compiler->write("\t\t" . $contents . "\n");
$compiler->write("\t\t} catch(ExpressViewException \$ex) {\n");
$compiler->write("\t\t\tthrow \$ex;\n");
$compiler->write("\t\t} catch(\Exception \$ex) {\n");
$compiler->write("\t\t\tthrow new ExpressViewException(");
$compiler->write(var_export('Error during evaluation of expression "' . $this->expression . '"', true));
$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
$compiler->write("\t\t}\n");
}
}
catch(ExpressViewException $e)
{
throw $e;
}
catch(\Exception $e)
{
throw new ExpressViewException(sprintf('Unable to compile expression "%s"', $this->expression), $compiler->getResource(), $this->line, $e);
}
} | php | public function compile(ExpressCompiler $compiler, $flags = 0)
{
try
{
if($flags & self::FLAG_RAW)
{
$compiler->write($this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp'));
}
else
{
$compiler->write("\t\ttry {\n");
if($this->stringify)
{
if($this->expression->hasPipedFilter('raw'))
{
$contents = '$out->write(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
}
else
{
$contents = '$out->writeEscaped(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
}
}
else
{
$contents = 'return ' . $this->expression->compile($compiler->getExpressionContextFactory(), false, $this->exp) . ';';
}
$compiler->write("\t\t" . $contents . "\n");
$compiler->write("\t\t} catch(ExpressViewException \$ex) {\n");
$compiler->write("\t\t\tthrow \$ex;\n");
$compiler->write("\t\t} catch(\Exception \$ex) {\n");
$compiler->write("\t\t\tthrow new ExpressViewException(");
$compiler->write(var_export('Error during evaluation of expression "' . $this->expression . '"', true));
$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
$compiler->write("\t\t}\n");
}
}
catch(ExpressViewException $e)
{
throw $e;
}
catch(\Exception $e)
{
throw new ExpressViewException(sprintf('Unable to compile expression "%s"', $this->expression), $compiler->getResource(), $this->line, $e);
}
} | [
"public",
"function",
"compile",
"(",
"ExpressCompiler",
"$",
"compiler",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"flags",
"&",
"self",
"::",
"FLAG_RAW",
")",
"{",
"$",
"compiler",
"->",
"write",
"(",
"$",
"this",
"->",
"expression",
"->",
"compile",
"(",
"$",
"compiler",
"->",
"getExpressionContextFactory",
"(",
")",
",",
"false",
",",
"'$this->exp'",
")",
")",
";",
"}",
"else",
"{",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\ttry {\\n\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stringify",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"expression",
"->",
"hasPipedFilter",
"(",
"'raw'",
")",
")",
"{",
"$",
"contents",
"=",
"'$out->write('",
".",
"$",
"this",
"->",
"expression",
"->",
"compile",
"(",
"$",
"compiler",
"->",
"getExpressionContextFactory",
"(",
")",
",",
"false",
",",
"'$this->exp'",
")",
".",
"');'",
";",
"}",
"else",
"{",
"$",
"contents",
"=",
"'$out->writeEscaped('",
".",
"$",
"this",
"->",
"expression",
"->",
"compile",
"(",
"$",
"compiler",
"->",
"getExpressionContextFactory",
"(",
")",
",",
"false",
",",
"'$this->exp'",
")",
".",
"');'",
";",
"}",
"}",
"else",
"{",
"$",
"contents",
"=",
"'return '",
".",
"$",
"this",
"->",
"expression",
"->",
"compile",
"(",
"$",
"compiler",
"->",
"getExpressionContextFactory",
"(",
")",
",",
"false",
",",
"$",
"this",
"->",
"exp",
")",
".",
"';'",
";",
"}",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t\"",
".",
"$",
"contents",
".",
"\"\\n\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t} catch(ExpressViewException \\$ex) {\\n\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t\\tthrow \\$ex;\\n\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t} catch(\\Exception \\$ex) {\\n\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t\\tthrow new ExpressViewException(\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"var_export",
"(",
"'Error during evaluation of expression \"'",
".",
"$",
"this",
"->",
"expression",
".",
"'\"'",
",",
"true",
")",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\", \\$this->getResource(), {$this->line}, \\$ex);\\n\"",
")",
";",
"$",
"compiler",
"->",
"write",
"(",
"\"\\t\\t}\\n\"",
")",
";",
"}",
"}",
"catch",
"(",
"ExpressViewException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"ExpressViewException",
"(",
"sprintf",
"(",
"'Unable to compile expression \"%s\"'",
",",
"$",
"this",
"->",
"expression",
")",
",",
"$",
"compiler",
"->",
"getResource",
"(",
")",
",",
"$",
"this",
"->",
"line",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Compiles an expression into PHP code.
@param ExpressCompiler $compiler
@param integer $flags Raw mode is active when an element is morphed from a TagBuilder. | [
"Compiles",
"an",
"expression",
"into",
"PHP",
"code",
"."
] | a8ebe6f373b6bfe8b8818d6264535e8fe063a596 | https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/Tree/ExpressionNode.php#L76-L122 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Inflector/Inflector.php | Inflector.normalize | public function normalize(&$data, $format)
{
if (!is_array($data)) {
return $this->$format($data);
}
foreach ($data as $key => $value) {
// already formatted ?
if ($key != ($normalizedKey = $this->$format($key))) {
if (array_key_exists($normalizedKey, $data)) {
throw new \InvalidArgumentException(sprintf(
'Both "%s" and %s("%s") keys exists, abord normalizing.',
$key, $format, $normalizedKey
));
}
unset($data[$key]);
$data[$normalizedKey] = $value;
$key = $normalizedKey;
}
// iterate over child keys
if (is_array($value)) {
$this->normalize($data[$key], $format);
}
}
return $data;
} | php | public function normalize(&$data, $format)
{
if (!is_array($data)) {
return $this->$format($data);
}
foreach ($data as $key => $value) {
// already formatted ?
if ($key != ($normalizedKey = $this->$format($key))) {
if (array_key_exists($normalizedKey, $data)) {
throw new \InvalidArgumentException(sprintf(
'Both "%s" and %s("%s") keys exists, abord normalizing.',
$key, $format, $normalizedKey
));
}
unset($data[$key]);
$data[$normalizedKey] = $value;
$key = $normalizedKey;
}
// iterate over child keys
if (is_array($value)) {
$this->normalize($data[$key], $format);
}
}
return $data;
} | [
"public",
"function",
"normalize",
"(",
"&",
"$",
"data",
",",
"$",
"format",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"format",
"(",
"$",
"data",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// already formatted ?",
"if",
"(",
"$",
"key",
"!=",
"(",
"$",
"normalizedKey",
"=",
"$",
"this",
"->",
"$",
"format",
"(",
"$",
"key",
")",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"normalizedKey",
",",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Both \"%s\" and %s(\"%s\") keys exists, abord normalizing.'",
",",
"$",
"key",
",",
"$",
"format",
",",
"$",
"normalizedKey",
")",
")",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"$",
"data",
"[",
"$",
"normalizedKey",
"]",
"=",
"$",
"value",
";",
"$",
"key",
"=",
"$",
"normalizedKey",
";",
"}",
"// iterate over child keys",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"normalize",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"format",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Normalize given data
If an array is given, normalize keys, according to given method
@param string|array &$data
@param string $format
@return string|array
@see for inspiration https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Normalizer/CamelKeysNormalizer.php | [
"Normalize",
"given",
"data",
"If",
"an",
"array",
"is",
"given",
"normalize",
"keys",
"according",
"to",
"given",
"method"
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Inflector/Inflector.php#L163-L190 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.fromCurrent | public static function fromCurrent($key = null, $default = null) {
switch(static :: getMethod()) {
case 'get' : $data = $_GET; break;
case 'post' : $data = $_POST; break;
default : $data = null;
}
return static :: from(static :: getMethod(), $key, $default, $data);
} | php | public static function fromCurrent($key = null, $default = null) {
switch(static :: getMethod()) {
case 'get' : $data = $_GET; break;
case 'post' : $data = $_POST; break;
default : $data = null;
}
return static :: from(static :: getMethod(), $key, $default, $data);
} | [
"public",
"static",
"function",
"fromCurrent",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"switch",
"(",
"static",
"::",
"getMethod",
"(",
")",
")",
"{",
"case",
"'get'",
":",
"$",
"data",
"=",
"$",
"_GET",
";",
"break",
";",
"case",
"'post'",
":",
"$",
"data",
"=",
"$",
"_POST",
";",
"break",
";",
"default",
":",
"$",
"data",
"=",
"null",
";",
"}",
"return",
"static",
"::",
"from",
"(",
"static",
"::",
"getMethod",
"(",
")",
",",
"$",
"key",
",",
"$",
"default",
",",
"$",
"data",
")",
";",
"}"
] | Get variable from the current HTTP method
@param mixed $key
@param mixed $default
@return mixed | [
"Get",
"variable",
"from",
"the",
"current",
"HTTP",
"method"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L169-L179 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.getHeader | public static function getHeader($header) {
$headers = static :: getHeaders();
if(true === isset($headers[$header])) {
return $headers[$header];
}
return null;
} | php | public static function getHeader($header) {
$headers = static :: getHeaders();
if(true === isset($headers[$header])) {
return $headers[$header];
}
return null;
} | [
"public",
"static",
"function",
"getHeader",
"(",
"$",
"header",
")",
"{",
"$",
"headers",
"=",
"static",
"::",
"getHeaders",
"(",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"headers",
"[",
"$",
"header",
"]",
")",
")",
"{",
"return",
"$",
"headers",
"[",
"$",
"header",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get request header by key
@param string $header
@return string | [
"Get",
"request",
"header",
"by",
"key"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L367-L376 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.all | public static function all() {
if(true === isset(static :: $method['data'])) {
return static :: $method['data'];
}
parse_str(static :: getBody(), $vars);
return [
'get' => $_GET,
'post' => $_POST,
'put' => static :: isMethod('put') ? $vars : [],
'delete' => static :: isMethod('delete') ? $vars : [],
'patch' => static :: isMethod('patch') ? $vars : [],
'connect' => static :: isMethod('connect') ? $vars : [],
'head' => static :: isMethod('head') ? $vars : [],
'options' => static :: isMethod('options') ? $vars : [],
'trace' => static :: isMethod('trace') ? $vars : []
];
} | php | public static function all() {
if(true === isset(static :: $method['data'])) {
return static :: $method['data'];
}
parse_str(static :: getBody(), $vars);
return [
'get' => $_GET,
'post' => $_POST,
'put' => static :: isMethod('put') ? $vars : [],
'delete' => static :: isMethod('delete') ? $vars : [],
'patch' => static :: isMethod('patch') ? $vars : [],
'connect' => static :: isMethod('connect') ? $vars : [],
'head' => static :: isMethod('head') ? $vars : [],
'options' => static :: isMethod('options') ? $vars : [],
'trace' => static :: isMethod('trace') ? $vars : []
];
} | [
"public",
"static",
"function",
"all",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"method",
"[",
"'data'",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"method",
"[",
"'data'",
"]",
";",
"}",
"parse_str",
"(",
"static",
"::",
"getBody",
"(",
")",
",",
"$",
"vars",
")",
";",
"return",
"[",
"'get'",
"=>",
"$",
"_GET",
",",
"'post'",
"=>",
"$",
"_POST",
",",
"'put'",
"=>",
"static",
"::",
"isMethod",
"(",
"'put'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'delete'",
"=>",
"static",
"::",
"isMethod",
"(",
"'delete'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'patch'",
"=>",
"static",
"::",
"isMethod",
"(",
"'patch'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'connect'",
"=>",
"static",
"::",
"isMethod",
"(",
"'connect'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'head'",
"=>",
"static",
"::",
"isMethod",
"(",
"'head'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'options'",
"=>",
"static",
"::",
"isMethod",
"(",
"'options'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
",",
"'trace'",
"=>",
"static",
"::",
"isMethod",
"(",
"'trace'",
")",
"?",
"$",
"vars",
":",
"[",
"]",
"]",
";",
"}"
] | Return all the data from get, post, put, delete, patch, connect, head, options and trace
@return array | [
"Return",
"all",
"the",
"data",
"from",
"get",
"post",
"put",
"delete",
"patch",
"connect",
"head",
"options",
"and",
"trace"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L396-L416 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.getIp | public static function getIp() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if(isset($_SERVER['HTTP-X-FORWARDED-FOR'])) {
return $_SERVER['HTTP-X-FORWARDED-FOR'];
}
if(isset($_SERVER['HTTP_VIA'])) {
return $_SERVER['HTTP_VIA'];
}
if(isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
} | php | public static function getIp() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if(isset($_SERVER['HTTP-X-FORWARDED-FOR'])) {
return $_SERVER['HTTP-X-FORWARDED-FOR'];
}
if(isset($_SERVER['HTTP_VIA'])) {
return $_SERVER['HTTP_VIA'];
}
if(isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
} | [
"public",
"static",
"function",
"getIp",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP-X-FORWARDED-FOR'",
"]",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'HTTP-X-FORWARDED-FOR'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_VIA'",
"]",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'HTTP_VIA'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"}",
"}"
] | Returns the request IP address
@return string | [
"Returns",
"the",
"request",
"IP",
"address"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L579-L596 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.parseUrl | public static function parseUrl($key = null) {
if(null !== $key && false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
$url = [];
$types = [
'host' => 'HTTP_HOST',
'port' => 'SERVER_PORT',
'protocol' => 'REQUEST_SCHEME',
'path' => 'REQUEST_URI',
'query' => 'QUERY_STRING'
];
foreach($types as $type => $value) {
if(true === isset($_SERVER[$value])) {
$url[$type] = $_SERVER[$value];
}
}
if(true === isset($url['path'], $url['query']) && '' !== $url['query']) {
$url['path'] = str_replace('?' . $url['query'], '', $url['path']);
}
if(true === isset($url[$key])) {
return $url[$key];
}
if(null === $key) {
return $url;
}
return null;
} | php | public static function parseUrl($key = null) {
if(null !== $key && false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
$url = [];
$types = [
'host' => 'HTTP_HOST',
'port' => 'SERVER_PORT',
'protocol' => 'REQUEST_SCHEME',
'path' => 'REQUEST_URI',
'query' => 'QUERY_STRING'
];
foreach($types as $type => $value) {
if(true === isset($_SERVER[$value])) {
$url[$type] = $_SERVER[$value];
}
}
if(true === isset($url['path'], $url['query']) && '' !== $url['query']) {
$url['path'] = str_replace('?' . $url['query'], '', $url['path']);
}
if(true === isset($url[$key])) {
return $url[$key];
}
if(null === $key) {
return $url;
}
return null;
} | [
"public",
"static",
"function",
"parseUrl",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"key",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"key",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"url",
"=",
"[",
"]",
";",
"$",
"types",
"=",
"[",
"'host'",
"=>",
"'HTTP_HOST'",
",",
"'port'",
"=>",
"'SERVER_PORT'",
",",
"'protocol'",
"=>",
"'REQUEST_SCHEME'",
",",
"'path'",
"=>",
"'REQUEST_URI'",
",",
"'query'",
"=>",
"'QUERY_STRING'",
"]",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"_SERVER",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"url",
"[",
"$",
"type",
"]",
"=",
"$",
"_SERVER",
"[",
"$",
"value",
"]",
";",
"}",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"url",
"[",
"'path'",
"]",
",",
"$",
"url",
"[",
"'query'",
"]",
")",
"&&",
"''",
"!==",
"$",
"url",
"[",
"'query'",
"]",
")",
"{",
"$",
"url",
"[",
"'path'",
"]",
"=",
"str_replace",
"(",
"'?'",
".",
"$",
"url",
"[",
"'query'",
"]",
",",
"''",
",",
"$",
"url",
"[",
"'path'",
"]",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"url",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"url",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"return",
"$",
"url",
";",
"}",
"return",
"null",
";",
"}"
] | Returns parsed url by giving an option key for only the value of that key to return
@param string $key
@return array|string|null | [
"Returns",
"parsed",
"url",
"by",
"giving",
"an",
"option",
"key",
"for",
"only",
"the",
"value",
"of",
"that",
"key",
"to",
"return"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L604-L640 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.get | private static function get($key = null, $default = null) {
if(null !== $key && isset(static :: $method['method'], static :: $method['data'])) {
if(static :: isMethod(static :: $method['method'])) {
$helper = new StringToArray();
$data = $helper -> execute($key, $default, static :: $method['data']);
//Trim string
if(true === isset(static :: $options[self :: TRIM_STRING])) {
if(is_string($data) === 0) {
$data = trim($data);
}
}
//Convert empty string to NULL
if(true === isset(static :: $options[self :: EMPTY_STRING_TO_NULL])) {
if(is_string($data) && strlen($data) === 0) {
$data = null;
}
}
//Convert empty array to NULL
if(true === isset(static :: $options[self :: EMPTY_ARRAY_TO_NULL])) {
if(is_array($data) && count($data) === 0) {
$data = null;
}
}
$default = null === $data ? $default : $data;
}
static :: $method = [];
}
return $default;
} | php | private static function get($key = null, $default = null) {
if(null !== $key && isset(static :: $method['method'], static :: $method['data'])) {
if(static :: isMethod(static :: $method['method'])) {
$helper = new StringToArray();
$data = $helper -> execute($key, $default, static :: $method['data']);
//Trim string
if(true === isset(static :: $options[self :: TRIM_STRING])) {
if(is_string($data) === 0) {
$data = trim($data);
}
}
//Convert empty string to NULL
if(true === isset(static :: $options[self :: EMPTY_STRING_TO_NULL])) {
if(is_string($data) && strlen($data) === 0) {
$data = null;
}
}
//Convert empty array to NULL
if(true === isset(static :: $options[self :: EMPTY_ARRAY_TO_NULL])) {
if(is_array($data) && count($data) === 0) {
$data = null;
}
}
$default = null === $data ? $default : $data;
}
static :: $method = [];
}
return $default;
} | [
"private",
"static",
"function",
"get",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"key",
"&&",
"isset",
"(",
"static",
"::",
"$",
"method",
"[",
"'method'",
"]",
",",
"static",
"::",
"$",
"method",
"[",
"'data'",
"]",
")",
")",
"{",
"if",
"(",
"static",
"::",
"isMethod",
"(",
"static",
"::",
"$",
"method",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"$",
"data",
"=",
"$",
"helper",
"->",
"execute",
"(",
"$",
"key",
",",
"$",
"default",
",",
"static",
"::",
"$",
"method",
"[",
"'data'",
"]",
")",
";",
"//Trim string\r",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"options",
"[",
"self",
"::",
"TRIM_STRING",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
"===",
"0",
")",
"{",
"$",
"data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"}",
"}",
"//Convert empty string to NULL\r",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"options",
"[",
"self",
"::",
"EMPTY_STRING_TO_NULL",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
"&&",
"strlen",
"(",
"$",
"data",
")",
"===",
"0",
")",
"{",
"$",
"data",
"=",
"null",
";",
"}",
"}",
"//Convert empty array to NULL\r",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"options",
"[",
"self",
"::",
"EMPTY_ARRAY_TO_NULL",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"count",
"(",
"$",
"data",
")",
"===",
"0",
")",
"{",
"$",
"data",
"=",
"null",
";",
"}",
"}",
"$",
"default",
"=",
"null",
"===",
"$",
"data",
"?",
"$",
"default",
":",
"$",
"data",
";",
"}",
"static",
"::",
"$",
"method",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Returns variable from source while converting an array from string
@param mixed $key
@param mixed $default
@return mixed | [
"Returns",
"variable",
"from",
"source",
"while",
"converting",
"an",
"array",
"from",
"string"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L649-L689 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.from | private static function from($type, $key, $default, &$source = null) {
if(null === $source) {
if(static :: isMethod($type)) {
$source = [];
static :: parseRawHttpRequest($source);
}
}
static :: $method = ['method' => $type, 'data' => &$source];
if(null !== $key) {
return static :: get($key, $default);
}
return $source;
} | php | private static function from($type, $key, $default, &$source = null) {
if(null === $source) {
if(static :: isMethod($type)) {
$source = [];
static :: parseRawHttpRequest($source);
}
}
static :: $method = ['method' => $type, 'data' => &$source];
if(null !== $key) {
return static :: get($key, $default);
}
return $source;
} | [
"private",
"static",
"function",
"from",
"(",
"$",
"type",
",",
"$",
"key",
",",
"$",
"default",
",",
"&",
"$",
"source",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"source",
")",
"{",
"if",
"(",
"static",
"::",
"isMethod",
"(",
"$",
"type",
")",
")",
"{",
"$",
"source",
"=",
"[",
"]",
";",
"static",
"::",
"parseRawHttpRequest",
"(",
"$",
"source",
")",
";",
"}",
"}",
"static",
"::",
"$",
"method",
"=",
"[",
"'method'",
"=>",
"$",
"type",
",",
"'data'",
"=>",
"&",
"$",
"source",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"key",
")",
"{",
"return",
"static",
"::",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"source",
";",
"}"
] | Get variable from variable source
@param string $type
@param mixed $key
@param mixed $default
@param array $source
@return mixed | [
"Get",
"variable",
"from",
"variable",
"source"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L700-L718 | train |
Kris-Kuiper/sFire-Framework | src/HTTP/Request.php | Request.parseRawHttpRequest | private static function parseRawHttpRequest(array &$data) {
if(false === isset($_SERVER['CONTENT_TYPE'])) {
$_SERVER['CONTENT_TYPE'] = '';
}
$input = static :: getBody();
preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);
if(0 === count($matches)) {
$json = @json_decode($input, true);
if(true === (json_last_error() == JSON_ERROR_NONE)) {
$data = $json;
return $json;
}
parse_str(urldecode($input), $data);
return $data;
}
$boundary = $matches[1];
$blocks = preg_split("/-+$boundary/", $input);
array_pop($blocks);
foreach($blocks as $id => $block) {
if('' === $block) {
continue;
}
if(false !== strpos($block, 'application/octet-stream')) {
preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches);
$data['files'][$matches[1]] = $matches[2];
}
else {
preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches);
$data[$matches[1]] = $matches[2];
}
}
} | php | private static function parseRawHttpRequest(array &$data) {
if(false === isset($_SERVER['CONTENT_TYPE'])) {
$_SERVER['CONTENT_TYPE'] = '';
}
$input = static :: getBody();
preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);
if(0 === count($matches)) {
$json = @json_decode($input, true);
if(true === (json_last_error() == JSON_ERROR_NONE)) {
$data = $json;
return $json;
}
parse_str(urldecode($input), $data);
return $data;
}
$boundary = $matches[1];
$blocks = preg_split("/-+$boundary/", $input);
array_pop($blocks);
foreach($blocks as $id => $block) {
if('' === $block) {
continue;
}
if(false !== strpos($block, 'application/octet-stream')) {
preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches);
$data['files'][$matches[1]] = $matches[2];
}
else {
preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches);
$data[$matches[1]] = $matches[2];
}
}
} | [
"private",
"static",
"function",
"parseRawHttpRequest",
"(",
"array",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"_SERVER",
"[",
"'CONTENT_TYPE'",
"]",
")",
")",
"{",
"$",
"_SERVER",
"[",
"'CONTENT_TYPE'",
"]",
"=",
"''",
";",
"}",
"$",
"input",
"=",
"static",
"::",
"getBody",
"(",
")",
";",
"preg_match",
"(",
"'/boundary=(.*)$/'",
",",
"$",
"_SERVER",
"[",
"'CONTENT_TYPE'",
"]",
",",
"$",
"matches",
")",
";",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"matches",
")",
")",
"{",
"$",
"json",
"=",
"@",
"json_decode",
"(",
"$",
"input",
",",
"true",
")",
";",
"if",
"(",
"true",
"===",
"(",
"json_last_error",
"(",
")",
"==",
"JSON_ERROR_NONE",
")",
")",
"{",
"$",
"data",
"=",
"$",
"json",
";",
"return",
"$",
"json",
";",
"}",
"parse_str",
"(",
"urldecode",
"(",
"$",
"input",
")",
",",
"$",
"data",
")",
";",
"return",
"$",
"data",
";",
"}",
"$",
"boundary",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"blocks",
"=",
"preg_split",
"(",
"\"/-+$boundary/\"",
",",
"$",
"input",
")",
";",
"array_pop",
"(",
"$",
"blocks",
")",
";",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"id",
"=>",
"$",
"block",
")",
"{",
"if",
"(",
"''",
"===",
"$",
"block",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"block",
",",
"'application/octet-stream'",
")",
")",
"{",
"preg_match",
"(",
"\"/name=\\\"([^\\\"]*)\\\".*stream[\\n|\\r]+([^\\n\\r].*)?$/s\"",
",",
"$",
"block",
",",
"$",
"matches",
")",
";",
"$",
"data",
"[",
"'files'",
"]",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"else",
"{",
"preg_match",
"(",
"'/name=\\\"([^\\\"]*)\\\"[\\n|\\r]+([^\\n\\r].*)?\\r$/s'",
",",
"$",
"block",
",",
"$",
"matches",
")",
";",
"$",
"data",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"}",
"}"
] | Parses raw HTTP request string
@param array $data | [
"Parses",
"raw",
"HTTP",
"request",
"string"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/HTTP/Request.php#L725-L771 | train |
melisplatform/melis-calendar | src/Controller/CalendarController.php | CalendarController.renderCalendarLeftmenuAction | public function renderCalendarLeftmenuAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | php | public function renderCalendarLeftmenuAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | [
"public",
"function",
"renderCalendarLeftmenuAction",
"(",
")",
"{",
"$",
"melisKey",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'melisKey'",
",",
"''",
")",
";",
"$",
"view",
"=",
"new",
"ViewModel",
"(",
")",
";",
"$",
"view",
"->",
"melisKey",
"=",
"$",
"melisKey",
";",
"return",
"$",
"view",
";",
"}"
] | Render the leftmenu | [
"Render",
"the",
"leftmenu"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/CalendarController.php#L21-L27 | train |
eureka-framework/component-http | src/Http/Session.php | Session.set | public function set($name, $value)
{
parent::set($name, $value);
$_SESSION[$name] = $value;
return $this;
} | php | public function set($name, $value)
{
parent::set($name, $value);
$_SESSION[$name] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"parent",
"::",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set value in session.
@param string $name
@param mixed $value
@return self | [
"Set",
"value",
"in",
"session",
"."
] | 698c3b73581a9703a9c932890c57e50f8774607a | https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/Session.php#L86-L93 | train |
pixelpolishers/resolver-php-server | src/PixelPolishers/Resolver/Server/Router/Router.php | Router.find | public function find($url)
{
if (!array_key_exists($url, $this->controllerMap)) {
return null;
}
return $this->controllerMap[$url];
} | php | public function find($url)
{
if (!array_key_exists($url, $this->controllerMap)) {
return null;
}
return $this->controllerMap[$url];
} | [
"public",
"function",
"find",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"controllerMap",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"controllerMap",
"[",
"$",
"url",
"]",
";",
"}"
] | Finds the controller for the given url.
@param string $url The url to parse.
@return ControllerInterface | [
"Finds",
"the",
"controller",
"for",
"the",
"given",
"url",
"."
] | c07505a768b32b30c7c300b3fb7e41d1776cb6e9 | https://github.com/pixelpolishers/resolver-php-server/blob/c07505a768b32b30c7c300b3fb7e41d1776cb6e9/src/PixelPolishers/Resolver/Server/Router/Router.php#L60-L67 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/PipedToken.php | PipedToken.parse | public function parse() {
$name_without_parens = preg_replace('/[{}]/', '', $this->full_name);
$parts = explode('|', $name_without_parens);
$name_without_pipes = trim($parts[0]);
$parts = explode('::', $name_without_pipes);
$name_without_case_keys = trim($parts[0]);
array_shift($parts);
$this->case_keys = array_map('trim', $parts);
$parts = explode(':', $name_without_case_keys);
$this->short_name = trim($parts[0]);
array_shift($parts);
$this->context_keys = array_map('trim', $parts);
$this->separator = (strpos($this->full_name,'||') !== false) ? '||' : '|';
$this->parameters = array();
$parts = explode($this->separator, $name_without_parens);
if (count($parts) > 1) {
$parts = explode(',', $parts[1]);
foreach($parts as $part) {
array_push($this->parameters, trim($part));
}
}
} | php | public function parse() {
$name_without_parens = preg_replace('/[{}]/', '', $this->full_name);
$parts = explode('|', $name_without_parens);
$name_without_pipes = trim($parts[0]);
$parts = explode('::', $name_without_pipes);
$name_without_case_keys = trim($parts[0]);
array_shift($parts);
$this->case_keys = array_map('trim', $parts);
$parts = explode(':', $name_without_case_keys);
$this->short_name = trim($parts[0]);
array_shift($parts);
$this->context_keys = array_map('trim', $parts);
$this->separator = (strpos($this->full_name,'||') !== false) ? '||' : '|';
$this->parameters = array();
$parts = explode($this->separator, $name_without_parens);
if (count($parts) > 1) {
$parts = explode(',', $parts[1]);
foreach($parts as $part) {
array_push($this->parameters, trim($part));
}
}
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"name_without_parens",
"=",
"preg_replace",
"(",
"'/[{}]/'",
",",
"''",
",",
"$",
"this",
"->",
"full_name",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'|'",
",",
"$",
"name_without_parens",
")",
";",
"$",
"name_without_pipes",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'::'",
",",
"$",
"name_without_pipes",
")",
";",
"$",
"name_without_case_keys",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"this",
"->",
"case_keys",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"parts",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"name_without_case_keys",
")",
";",
"$",
"this",
"->",
"short_name",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"this",
"->",
"context_keys",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"parts",
")",
";",
"$",
"this",
"->",
"separator",
"=",
"(",
"strpos",
"(",
"$",
"this",
"->",
"full_name",
",",
"'||'",
")",
"!==",
"false",
")",
"?",
"'||'",
":",
"'|'",
";",
"$",
"this",
"->",
"parameters",
"=",
"array",
"(",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"name_without_parens",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"parameters",
",",
"trim",
"(",
"$",
"part",
")",
")",
";",
"}",
"}",
"}"
] | Parses token elements | [
"Parses",
"token",
"elements"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/PipedToken.php#L83-L109 | train |
mossphp/moss-storage | Moss/Storage/Query/AbstractRelational.php | AbstractRelational.with | public function with($relation)
{
foreach ((array) $relation as $node) {
$instance = $this->factory->build($this->model(), $node);
$this->relations[$instance->name()] = $instance;
}
return $this;
} | php | public function with($relation)
{
foreach ((array) $relation as $node) {
$instance = $this->factory->build($this->model(), $node);
$this->relations[$instance->name()] = $instance;
}
return $this;
} | [
"public",
"function",
"with",
"(",
"$",
"relation",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"relation",
"as",
"$",
"node",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"factory",
"->",
"build",
"(",
"$",
"this",
"->",
"model",
"(",
")",
",",
"$",
"node",
")",
";",
"$",
"this",
"->",
"relations",
"[",
"$",
"instance",
"->",
"name",
"(",
")",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds relation to query
@param string|array $relation
@return $this
@throws QueryException | [
"Adds",
"relation",
"to",
"query"
] | 0d123e7ae6bbfce1e2a18e73bf70997277b430c1 | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/AbstractRelational.php#L51-L59 | train |
mossphp/moss-storage | Moss/Storage/Query/AbstractRelational.php | AbstractRelational.relation | public function relation($relation)
{
list($name, $furtherRelations) = $this->factory->splitRelationName($relation);
if (!isset($this->relations[$name])) {
throw new QueryException(sprintf('Unable to retrieve relation "%s" query, relation does not exists in query "%s"', $name, $this->model()->entity()));
}
if ($furtherRelations) {
return $this->relations[$name]->relation($furtherRelations);
}
return $this->relations[$name];
} | php | public function relation($relation)
{
list($name, $furtherRelations) = $this->factory->splitRelationName($relation);
if (!isset($this->relations[$name])) {
throw new QueryException(sprintf('Unable to retrieve relation "%s" query, relation does not exists in query "%s"', $name, $this->model()->entity()));
}
if ($furtherRelations) {
return $this->relations[$name]->relation($furtherRelations);
}
return $this->relations[$name];
} | [
"public",
"function",
"relation",
"(",
"$",
"relation",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"furtherRelations",
")",
"=",
"$",
"this",
"->",
"factory",
"->",
"splitRelationName",
"(",
"$",
"relation",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"QueryException",
"(",
"sprintf",
"(",
"'Unable to retrieve relation \"%s\" query, relation does not exists in query \"%s\"'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"model",
"(",
")",
"->",
"entity",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"furtherRelations",
")",
"{",
"return",
"$",
"this",
"->",
"relations",
"[",
"$",
"name",
"]",
"->",
"relation",
"(",
"$",
"furtherRelations",
")",
";",
"}",
"return",
"$",
"this",
"->",
"relations",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns relation instance
@param string $relation
@return RelationInterface
@throws QueryException | [
"Returns",
"relation",
"instance"
] | 0d123e7ae6bbfce1e2a18e73bf70997277b430c1 | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/AbstractRelational.php#L69-L82 | train |
Stinger-Soft/PlatformBundle | Entity/User.php | User.getRealName | public function getRealName() {
if($this->firstname || $this->surname) {
return trim($this->getFirstname() . ' ' . $this->getSurname());
}
return null;
} | php | public function getRealName() {
if($this->firstname || $this->surname) {
return trim($this->getFirstname() . ' ' . $this->getSurname());
}
return null;
} | [
"public",
"function",
"getRealName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"firstname",
"||",
"$",
"this",
"->",
"surname",
")",
"{",
"return",
"trim",
"(",
"$",
"this",
"->",
"getFirstname",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getSurname",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get realname "Firstname Surname"
@return string | [
"Get",
"realname",
"Firstname",
"Surname"
] | 922b9405e5ddc474f288b6be84af2de9a335ac28 | https://github.com/Stinger-Soft/PlatformBundle/blob/922b9405e5ddc474f288b6be84af2de9a335ac28/Entity/User.php#L91-L96 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/interfaces/TemplateCache.php | TemplateCache.putTemplate | public function putTemplate($cacheKey, Template $template)
{
if ($template->getCacheTime() == null && !is_numeric($template->getCacheTime()))
$template->setCacheTime($this->defaultCacheTime);
$this->put($cacheKey, $template, (int)$template->getCacheTime());
return true;
} | php | public function putTemplate($cacheKey, Template $template)
{
if ($template->getCacheTime() == null && !is_numeric($template->getCacheTime()))
$template->setCacheTime($this->defaultCacheTime);
$this->put($cacheKey, $template, (int)$template->getCacheTime());
return true;
} | [
"public",
"function",
"putTemplate",
"(",
"$",
"cacheKey",
",",
"Template",
"$",
"template",
")",
"{",
"if",
"(",
"$",
"template",
"->",
"getCacheTime",
"(",
")",
"==",
"null",
"&&",
"!",
"is_numeric",
"(",
"$",
"template",
"->",
"getCacheTime",
"(",
")",
")",
")",
"$",
"template",
"->",
"setCacheTime",
"(",
"$",
"this",
"->",
"defaultCacheTime",
")",
";",
"$",
"this",
"->",
"put",
"(",
"$",
"cacheKey",
",",
"$",
"template",
",",
"(",
"int",
")",
"$",
"template",
"->",
"getCacheTime",
"(",
")",
")",
";",
"return",
"true",
";",
"}"
] | Stores the specified template to cache using the cacheKey specified.
@param string $cacheKey The cacheKey for the Template
@param Template $template The template to store in the cache
@return true | [
"Stores",
"the",
"specified",
"template",
"to",
"cache",
"using",
"the",
"cacheKey",
"specified",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/TemplateCache.php#L169-L177 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/caching/interfaces/TemplateCache.php | TemplateCache.getTemplateCacheKey | public function getTemplateCacheKey(Template $template, $globals)
{
$locals = $template->getLocals();
$cachekey = '';
if($template->isTopTemplate())
$cachekey .= $this->Request->getAdjustedRequestURI();
else
$cachekey .= $template->getContentType().$template->getName();
$cacheParams = array();
// any locals that aren't globals
foreach ($locals as $name => $value) {
if (!is_array($value) && !array_key_exists($name, $globals) &&
!preg_match("/^[A-Z\-\_0-9]+$/", $name) &&
!preg_match("/\-\d+$/", $name)) {
$cacheParams[$name] = $value;
}
}
if(isset($cacheParams['UseQueryStringInCacheKey']) && StringUtils::strToBool($cacheParams['UseQueryStringInCacheKey']) == true)
{
foreach ($_GET as $name => $value) {
if (!is_array($value))
$cacheParams['q_'.$name] = $value;
}
}
$cachekey .= '?';
if (!empty($cacheParams)) {
ksort($cacheParams);
foreach ($cacheParams as $n => $v) {
$cachekey .= $n.'='.substr($v,0,255).'&';
}
}
$cachekey = rtrim($cachekey, '&');
$this->Logger->debug('Cache Key ['.$cachekey.']');
return $cachekey;
} | php | public function getTemplateCacheKey(Template $template, $globals)
{
$locals = $template->getLocals();
$cachekey = '';
if($template->isTopTemplate())
$cachekey .= $this->Request->getAdjustedRequestURI();
else
$cachekey .= $template->getContentType().$template->getName();
$cacheParams = array();
// any locals that aren't globals
foreach ($locals as $name => $value) {
if (!is_array($value) && !array_key_exists($name, $globals) &&
!preg_match("/^[A-Z\-\_0-9]+$/", $name) &&
!preg_match("/\-\d+$/", $name)) {
$cacheParams[$name] = $value;
}
}
if(isset($cacheParams['UseQueryStringInCacheKey']) && StringUtils::strToBool($cacheParams['UseQueryStringInCacheKey']) == true)
{
foreach ($_GET as $name => $value) {
if (!is_array($value))
$cacheParams['q_'.$name] = $value;
}
}
$cachekey .= '?';
if (!empty($cacheParams)) {
ksort($cacheParams);
foreach ($cacheParams as $n => $v) {
$cachekey .= $n.'='.substr($v,0,255).'&';
}
}
$cachekey = rtrim($cachekey, '&');
$this->Logger->debug('Cache Key ['.$cachekey.']');
return $cachekey;
} | [
"public",
"function",
"getTemplateCacheKey",
"(",
"Template",
"$",
"template",
",",
"$",
"globals",
")",
"{",
"$",
"locals",
"=",
"$",
"template",
"->",
"getLocals",
"(",
")",
";",
"$",
"cachekey",
"=",
"''",
";",
"if",
"(",
"$",
"template",
"->",
"isTopTemplate",
"(",
")",
")",
"$",
"cachekey",
".=",
"$",
"this",
"->",
"Request",
"->",
"getAdjustedRequestURI",
"(",
")",
";",
"else",
"$",
"cachekey",
".=",
"$",
"template",
"->",
"getContentType",
"(",
")",
".",
"$",
"template",
"->",
"getName",
"(",
")",
";",
"$",
"cacheParams",
"=",
"array",
"(",
")",
";",
"// any locals that aren't globals",
"foreach",
"(",
"$",
"locals",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"globals",
")",
"&&",
"!",
"preg_match",
"(",
"\"/^[A-Z\\-\\_0-9]+$/\"",
",",
"$",
"name",
")",
"&&",
"!",
"preg_match",
"(",
"\"/\\-\\d+$/\"",
",",
"$",
"name",
")",
")",
"{",
"$",
"cacheParams",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"cacheParams",
"[",
"'UseQueryStringInCacheKey'",
"]",
")",
"&&",
"StringUtils",
"::",
"strToBool",
"(",
"$",
"cacheParams",
"[",
"'UseQueryStringInCacheKey'",
"]",
")",
"==",
"true",
")",
"{",
"foreach",
"(",
"$",
"_GET",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"$",
"cacheParams",
"[",
"'q_'",
".",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"cachekey",
".=",
"'?'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cacheParams",
")",
")",
"{",
"ksort",
"(",
"$",
"cacheParams",
")",
";",
"foreach",
"(",
"$",
"cacheParams",
"as",
"$",
"n",
"=>",
"$",
"v",
")",
"{",
"$",
"cachekey",
".=",
"$",
"n",
".",
"'='",
".",
"substr",
"(",
"$",
"v",
",",
"0",
",",
"255",
")",
".",
"'&'",
";",
"}",
"}",
"$",
"cachekey",
"=",
"rtrim",
"(",
"$",
"cachekey",
",",
"'&'",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"'Cache Key ['",
".",
"$",
"cachekey",
".",
"']'",
")",
";",
"return",
"$",
"cachekey",
";",
"}"
] | Returns a cacheKey for the specified Template
@param Template $template The template to generate the cacheKey for
@param array $globals An array of globals set on this template
@return string The cache key | [
"Returns",
"a",
"cacheKey",
"for",
"the",
"specified",
"Template"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/TemplateCache.php#L187-L229 | train |
siriusSupreme/sirius-support | src/Traits/InteractsWithConfig.php | InteractsWithConfig.ensureRepository | protected function ensureRepository( $repository ) {
if ( $repository === null ) {
return new Repository();
}
if ( $repository instanceof RepostoryContract ) {
return $repository;
}
if ( is_array( $repository ) ) {
return new Repository( $repository );
}
throw new \LogicException( 'A repository should either be an array or a Flysystem\Repository object.' );
} | php | protected function ensureRepository( $repository ) {
if ( $repository === null ) {
return new Repository();
}
if ( $repository instanceof RepostoryContract ) {
return $repository;
}
if ( is_array( $repository ) ) {
return new Repository( $repository );
}
throw new \LogicException( 'A repository should either be an array or a Flysystem\Repository object.' );
} | [
"protected",
"function",
"ensureRepository",
"(",
"$",
"repository",
")",
"{",
"if",
"(",
"$",
"repository",
"===",
"null",
")",
"{",
"return",
"new",
"Repository",
"(",
")",
";",
"}",
"if",
"(",
"$",
"repository",
"instanceof",
"RepostoryContract",
")",
"{",
"return",
"$",
"repository",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"repository",
")",
")",
"{",
"return",
"new",
"Repository",
"(",
"$",
"repository",
")",
";",
"}",
"throw",
"new",
"\\",
"LogicException",
"(",
"'A repository should either be an array or a Flysystem\\Repository object.'",
")",
";",
"}"
] | Ensure a Repository instance.
@param null|array|Repository $repository
@return Repository repository instance
@throw LogicException | [
"Ensure",
"a",
"Repository",
"instance",
"."
] | 80436cf8ae7b95d96bb34cd7297be00c77fc1033 | https://github.com/siriusSupreme/sirius-support/blob/80436cf8ae7b95d96bb34cd7297be00c77fc1033/src/Traits/InteractsWithConfig.php#L60-L74 | train |
Wedeto/DB | src/Query/ConstantValue.php | ConstantValue.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($key = $this->getKey())
{
try
{
$params->get($key);
}
catch (\OutOfRangeException $e)
{
$key = null;
}
}
if ($key === null)
{
$val = $this->getValue();
if (is_bool($val))
$val = $val ? 1 : 0;
$key = $params->assign($val, $this->getParameterType());
}
$this->bind($params, $key, null);
return ':' . $key;
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($key = $this->getKey())
{
try
{
$params->get($key);
}
catch (\OutOfRangeException $e)
{
$key = null;
}
}
if ($key === null)
{
$val = $this->getValue();
if (is_bool($val))
$val = $val ? 1 : 0;
$key = $params->assign($val, $this->getParameterType());
}
$this->bind($params, $key, null);
return ':' . $key;
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"if",
"(",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
"{",
"try",
"{",
"$",
"params",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"\\",
"OutOfRangeException",
"$",
"e",
")",
"{",
"$",
"key",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"is_bool",
"(",
"$",
"val",
")",
")",
"$",
"val",
"=",
"$",
"val",
"?",
"1",
":",
"0",
";",
"$",
"key",
"=",
"$",
"params",
"->",
"assign",
"(",
"$",
"val",
",",
"$",
"this",
"->",
"getParameterType",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"bind",
"(",
"$",
"params",
",",
"$",
"key",
",",
"null",
")",
";",
"return",
"':'",
".",
"$",
"key",
";",
"}"
] | Write a constant as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@return string The generated SQL | [
"Write",
"a",
"constant",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/ConstantValue.php#L111-L135 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.getChildren | public function getChildren()
{
$output = new BaseContainer();
foreach( $this->getRelation()->getChildren() as $childRelation ) {
$childAttribute = $childRelation->getAttributeByName($this->name);
$output->add(
$childAttribute,
$childAttribute->getChildren()
);
}
return $output;
} | php | public function getChildren()
{
$output = new BaseContainer();
foreach( $this->getRelation()->getChildren() as $childRelation ) {
$childAttribute = $childRelation->getAttributeByName($this->name);
$output->add(
$childAttribute,
$childAttribute->getChildren()
);
}
return $output;
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"output",
"=",
"new",
"BaseContainer",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getRelation",
"(",
")",
"->",
"getChildren",
"(",
")",
"as",
"$",
"childRelation",
")",
"{",
"$",
"childAttribute",
"=",
"$",
"childRelation",
"->",
"getAttributeByName",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"output",
"->",
"add",
"(",
"$",
"childAttribute",
",",
"$",
"childAttribute",
"->",
"getChildren",
"(",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Get all inherited Attributes
@return Container | [
"Get",
"all",
"inherited",
"Attributes"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L111-L126 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.isInherited | public function isInherited( &$originalColumn = null )
{
$inhcount = $this->attinhcount;
if( $inhcount == 0 ) {
$originalColumn = null;
return false;
}
// short cut to prevent the work of finding the original column
if( func_num_args() === 0 ) {
return true;
}
// keep knocking off the parents until we reach the root
$originalRelation = $this->getRelation();
do {
$originalRelation = $originalRelation->getParent();
} while( --$inhcount > 0 );
$originalColumn = $originalRelation->getAttributeByName( $this->name );
return true;
} | php | public function isInherited( &$originalColumn = null )
{
$inhcount = $this->attinhcount;
if( $inhcount == 0 ) {
$originalColumn = null;
return false;
}
// short cut to prevent the work of finding the original column
if( func_num_args() === 0 ) {
return true;
}
// keep knocking off the parents until we reach the root
$originalRelation = $this->getRelation();
do {
$originalRelation = $originalRelation->getParent();
} while( --$inhcount > 0 );
$originalColumn = $originalRelation->getAttributeByName( $this->name );
return true;
} | [
"public",
"function",
"isInherited",
"(",
"&",
"$",
"originalColumn",
"=",
"null",
")",
"{",
"$",
"inhcount",
"=",
"$",
"this",
"->",
"attinhcount",
";",
"if",
"(",
"$",
"inhcount",
"==",
"0",
")",
"{",
"$",
"originalColumn",
"=",
"null",
";",
"return",
"false",
";",
"}",
"// short cut to prevent the work of finding the original column",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"// keep knocking off the parents until we reach the root",
"$",
"originalRelation",
"=",
"$",
"this",
"->",
"getRelation",
"(",
")",
";",
"do",
"{",
"$",
"originalRelation",
"=",
"$",
"originalRelation",
"->",
"getParent",
"(",
")",
";",
"}",
"while",
"(",
"--",
"$",
"inhcount",
">",
"0",
")",
";",
"$",
"originalColumn",
"=",
"$",
"originalRelation",
"->",
"getAttributeByName",
"(",
"$",
"this",
"->",
"name",
")",
";",
"return",
"true",
";",
"}"
] | Is this column inheritied from another relation
@param Column The original inherited column.
@return bool | [
"Is",
"this",
"column",
"inheritied",
"from",
"another",
"relation"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L150-L174 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.addReference | public function addReference( PgAttribute $primaryKey, $includeChildTables = true )
{
$this->references->add( $primaryKey );
$primaryKey->isReferencedBy->add( $this );
if( $includeChildTables || true ) {
foreach( $primaryKey->getRelation()->getChildren() as $child ) {
$this->addReference($child->getAttributeByName($primaryKey->name), true);
}
}
return;
// TODO. Add support for inheritance
$query = new Query(
"SELECT oid::text || '.' || %attnum:int%::text FROM dev.relationDescendants( %oid:int%::oid ) as _ ( oid );",
array(
'attnum' => $pk->get('attnum'),
'oid' => $pk->get('relation')->get('oid')
)
);
} | php | public function addReference( PgAttribute $primaryKey, $includeChildTables = true )
{
$this->references->add( $primaryKey );
$primaryKey->isReferencedBy->add( $this );
if( $includeChildTables || true ) {
foreach( $primaryKey->getRelation()->getChildren() as $child ) {
$this->addReference($child->getAttributeByName($primaryKey->name), true);
}
}
return;
// TODO. Add support for inheritance
$query = new Query(
"SELECT oid::text || '.' || %attnum:int%::text FROM dev.relationDescendants( %oid:int%::oid ) as _ ( oid );",
array(
'attnum' => $pk->get('attnum'),
'oid' => $pk->get('relation')->get('oid')
)
);
} | [
"public",
"function",
"addReference",
"(",
"PgAttribute",
"$",
"primaryKey",
",",
"$",
"includeChildTables",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"references",
"->",
"add",
"(",
"$",
"primaryKey",
")",
";",
"$",
"primaryKey",
"->",
"isReferencedBy",
"->",
"add",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"includeChildTables",
"||",
"true",
")",
"{",
"foreach",
"(",
"$",
"primaryKey",
"->",
"getRelation",
"(",
")",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"addReference",
"(",
"$",
"child",
"->",
"getAttributeByName",
"(",
"$",
"primaryKey",
"->",
"name",
")",
",",
"true",
")",
";",
"}",
"}",
"return",
";",
"// TODO. Add support for inheritance",
"$",
"query",
"=",
"new",
"Query",
"(",
"\"SELECT oid::text || '.' || %attnum:int%::text FROM dev.relationDescendants( %oid:int%::oid ) as _ ( oid );\"",
",",
"array",
"(",
"'attnum'",
"=>",
"$",
"pk",
"->",
"get",
"(",
"'attnum'",
")",
",",
"'oid'",
"=>",
"$",
"pk",
"->",
"get",
"(",
"'relation'",
")",
"->",
"get",
"(",
"'oid'",
")",
")",
")",
";",
"}"
] | Add a reference to this attribute
@param Attribute $primaryKey The attribute we're referencing | [
"Add",
"a",
"reference",
"to",
"this",
"attribute"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L180-L203 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.getSequence | public function getSequence()
{
if( preg_match( "/^nextval\\('([^']+)'::regclass\\)$/", $this->default, $matches ) ) {
return $this->catalog->pgClasses->findOneByName($matches[1]);
}
return null;
} | php | public function getSequence()
{
if( preg_match( "/^nextval\\('([^']+)'::regclass\\)$/", $this->default, $matches ) ) {
return $this->catalog->pgClasses->findOneByName($matches[1]);
}
return null;
} | [
"public",
"function",
"getSequence",
"(",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/^nextval\\\\('([^']+)'::regclass\\\\)$/\"",
",",
"$",
"this",
"->",
"default",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"this",
"->",
"catalog",
"->",
"pgClasses",
"->",
"findOneByName",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Is this column a sequence
@return Sequence|null | [
"Is",
"this",
"column",
"a",
"sequence"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L209-L215 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.getEntity | public function getEntity()
{
// primary key only
$references = $this->getReferences();
// debug // print_r( $references->map(function($e){ return $e->get('fullyQualifiedName');}) );
foreach( $references as $reference ) {
// only manage references where the reference column is the primary key
if( $reference->isPrimaryKey() ) {
return array(
'entity' => 'normality',
'normality' => $reference->getRelation()->getEntityName(),
);
}
}
// datatypes we understand and have defined objects for
// have a helper method in Entity::staticHelper
switch( $this->getType()->name ) {
case 'StockState':
return array (
'entity' => 'StockState',
);
case 'hstore':
return array(
'entity' => 'Hstore',
);
case 'json':
return array(
'entity' => 'Json',
);
case 'inet':
return array(
'entity' => 'Inet',
);
case 'timestamp':
return array(
'entity' => 'DateTime',
);
case 'tsrange':
return array(
'entity' => 'DateRange',
);
case 'oid':
return array(
'entity' => 'PgLargeObject',
);
}
return array();
} | php | public function getEntity()
{
// primary key only
$references = $this->getReferences();
// debug // print_r( $references->map(function($e){ return $e->get('fullyQualifiedName');}) );
foreach( $references as $reference ) {
// only manage references where the reference column is the primary key
if( $reference->isPrimaryKey() ) {
return array(
'entity' => 'normality',
'normality' => $reference->getRelation()->getEntityName(),
);
}
}
// datatypes we understand and have defined objects for
// have a helper method in Entity::staticHelper
switch( $this->getType()->name ) {
case 'StockState':
return array (
'entity' => 'StockState',
);
case 'hstore':
return array(
'entity' => 'Hstore',
);
case 'json':
return array(
'entity' => 'Json',
);
case 'inet':
return array(
'entity' => 'Inet',
);
case 'timestamp':
return array(
'entity' => 'DateTime',
);
case 'tsrange':
return array(
'entity' => 'DateRange',
);
case 'oid':
return array(
'entity' => 'PgLargeObject',
);
}
return array();
} | [
"public",
"function",
"getEntity",
"(",
")",
"{",
"// primary key only",
"$",
"references",
"=",
"$",
"this",
"->",
"getReferences",
"(",
")",
";",
"// debug // print_r( $references->map(function($e){ return $e->get('fullyQualifiedName');}) );",
"foreach",
"(",
"$",
"references",
"as",
"$",
"reference",
")",
"{",
"// only manage references where the reference column is the primary key",
"if",
"(",
"$",
"reference",
"->",
"isPrimaryKey",
"(",
")",
")",
"{",
"return",
"array",
"(",
"'entity'",
"=>",
"'normality'",
",",
"'normality'",
"=>",
"$",
"reference",
"->",
"getRelation",
"(",
")",
"->",
"getEntityName",
"(",
")",
",",
")",
";",
"}",
"}",
"// datatypes we understand and have defined objects for",
"// have a helper method in Entity::staticHelper",
"switch",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"->",
"name",
")",
"{",
"case",
"'StockState'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'StockState'",
",",
")",
";",
"case",
"'hstore'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'Hstore'",
",",
")",
";",
"case",
"'json'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'Json'",
",",
")",
";",
"case",
"'inet'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'Inet'",
",",
")",
";",
"case",
"'timestamp'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'DateTime'",
",",
")",
";",
"case",
"'tsrange'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'DateRange'",
",",
")",
";",
"case",
"'oid'",
":",
"return",
"array",
"(",
"'entity'",
"=>",
"'PgLargeObject'",
",",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Return a reference to the entity
@return string | [
"Return",
"a",
"reference",
"to",
"the",
"entity"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L221-L290 | train |
squareproton/Bond | src/Bond/Pg/Catalog/PgAttribute.php | PgAttribute.isZombie | public function isZombie()
{
$ref = $this->getReferences();
if( $this->isPrimaryKey() and !$ref->isEmpty() ) {
return true;
}
if( $this->notNull and !$ref->isEmpty() ) {
return true;
}
// comment
// if( \Bond\extract_tags( $this->get('comment') )
return false;
} | php | public function isZombie()
{
$ref = $this->getReferences();
if( $this->isPrimaryKey() and !$ref->isEmpty() ) {
return true;
}
if( $this->notNull and !$ref->isEmpty() ) {
return true;
}
// comment
// if( \Bond\extract_tags( $this->get('comment') )
return false;
} | [
"public",
"function",
"isZombie",
"(",
")",
"{",
"$",
"ref",
"=",
"$",
"this",
"->",
"getReferences",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPrimaryKey",
"(",
")",
"and",
"!",
"$",
"ref",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"notNull",
"and",
"!",
"$",
"ref",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// comment",
"// if( \\Bond\\extract_tags( $this->get('comment') )",
"return",
"false",
";",
"}"
] | Is this column a zombie-column candidate?
Happens when at least one of the following is true,
1. A column is a primary key fragment and references something else. [Pete. This is essentially the same as 2. because primary key fragments have to be not null]
2. A column references something and is not null
TODO 3. A column is marked zombie by a normality attribute
@return bool | [
"Is",
"this",
"column",
"a",
"zombie",
"-",
"column",
"candidate?",
"Happens",
"when",
"at",
"least",
"one",
"of",
"the",
"following",
"is",
"true"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/PgAttribute.php#L302-L317 | train |
andela-doladosu/liteorm | src/Helpers/BaseModelHelper.php | BaseModelHelper.getTableFields | protected function getTableFields()
{
$connection = Connection::connect();
$driver = getenv('P_DRIVER');
if ($driver == 'pgsql') {
$describe = '\d ';
}
$describe = 'describe ';
$q = $connection->prepare($describe.$this->getTableName($this->className));
$q->execute();
return $q->fetchAll(PDO::FETCH_COLUMN);
} | php | protected function getTableFields()
{
$connection = Connection::connect();
$driver = getenv('P_DRIVER');
if ($driver == 'pgsql') {
$describe = '\d ';
}
$describe = 'describe ';
$q = $connection->prepare($describe.$this->getTableName($this->className));
$q->execute();
return $q->fetchAll(PDO::FETCH_COLUMN);
} | [
"protected",
"function",
"getTableFields",
"(",
")",
"{",
"$",
"connection",
"=",
"Connection",
"::",
"connect",
"(",
")",
";",
"$",
"driver",
"=",
"getenv",
"(",
"'P_DRIVER'",
")",
";",
"if",
"(",
"$",
"driver",
"==",
"'pgsql'",
")",
"{",
"$",
"describe",
"=",
"'\\d '",
";",
"}",
"$",
"describe",
"=",
"'describe '",
";",
"$",
"q",
"=",
"$",
"connection",
"->",
"prepare",
"(",
"$",
"describe",
".",
"$",
"this",
"->",
"getTableName",
"(",
"$",
"this",
"->",
"className",
")",
")",
";",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"q",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_COLUMN",
")",
";",
"}"
] | Get all the column names in a table
@return array | [
"Get",
"all",
"the",
"column",
"names",
"in",
"a",
"table"
] | e97f69e20be4ce0c078a0c25a9a777307d85e9e4 | https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Helpers/BaseModelHelper.php#L18-L33 | train |
andela-doladosu/liteorm | src/Helpers/BaseModelHelper.php | BaseModelHelper.getAssignedValues | protected function getAssignedValues()
{
$tableFields = $this->getTableFields();
$newPropertiesArray = get_object_vars($this);
$columns = $values = $tableData = [];
foreach ($newPropertiesArray as $index => $value) {
if (in_array($index, $tableFields)) {
array_push($columns, $index);
array_push( $values, $value);
}
}
$tableData['columns'] = $columns;
$tableData['values'] = $values;
return $tableData;
} | php | protected function getAssignedValues()
{
$tableFields = $this->getTableFields();
$newPropertiesArray = get_object_vars($this);
$columns = $values = $tableData = [];
foreach ($newPropertiesArray as $index => $value) {
if (in_array($index, $tableFields)) {
array_push($columns, $index);
array_push( $values, $value);
}
}
$tableData['columns'] = $columns;
$tableData['values'] = $values;
return $tableData;
} | [
"protected",
"function",
"getAssignedValues",
"(",
")",
"{",
"$",
"tableFields",
"=",
"$",
"this",
"->",
"getTableFields",
"(",
")",
";",
"$",
"newPropertiesArray",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"$",
"columns",
"=",
"$",
"values",
"=",
"$",
"tableData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"newPropertiesArray",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"index",
",",
"$",
"tableFields",
")",
")",
"{",
"array_push",
"(",
"$",
"columns",
",",
"$",
"index",
")",
";",
"array_push",
"(",
"$",
"values",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"tableData",
"[",
"'columns'",
"]",
"=",
"$",
"columns",
";",
"$",
"tableData",
"[",
"'values'",
"]",
"=",
"$",
"values",
";",
"return",
"$",
"tableData",
";",
"}"
] | Get user assigned column values
@return array | [
"Get",
"user",
"assigned",
"column",
"values"
] | e97f69e20be4ce0c078a0c25a9a777307d85e9e4 | https://github.com/andela-doladosu/liteorm/blob/e97f69e20be4ce0c078a0c25a9a777307d85e9e4/src/Helpers/BaseModelHelper.php#L65-L83 | train |
g4code/utility | src/Tools.php | Tools.getSpinnerCombinations | public static function getSpinnerCombinations($text)
{
$matches = self::getSpinnerMatches($text);
foreach ($matches as $row) {
if(!preg_match('/[{}]/', $row)) {
$all[] = explode('|', $row);
}
}
$combinations = call_user_func_array(__CLASS__ . '::arrayCartesian', $all);
foreach($combinations as $item) {
$out[] = implode('', $item);
}
return array_values($out);
} | php | public static function getSpinnerCombinations($text)
{
$matches = self::getSpinnerMatches($text);
foreach ($matches as $row) {
if(!preg_match('/[{}]/', $row)) {
$all[] = explode('|', $row);
}
}
$combinations = call_user_func_array(__CLASS__ . '::arrayCartesian', $all);
foreach($combinations as $item) {
$out[] = implode('', $item);
}
return array_values($out);
} | [
"public",
"static",
"function",
"getSpinnerCombinations",
"(",
"$",
"text",
")",
"{",
"$",
"matches",
"=",
"self",
"::",
"getSpinnerMatches",
"(",
"$",
"text",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/[{}]/'",
",",
"$",
"row",
")",
")",
"{",
"$",
"all",
"[",
"]",
"=",
"explode",
"(",
"'|'",
",",
"$",
"row",
")",
";",
"}",
"}",
"$",
"combinations",
"=",
"call_user_func_array",
"(",
"__CLASS__",
".",
"'::arrayCartesian'",
",",
"$",
"all",
")",
";",
"foreach",
"(",
"$",
"combinations",
"as",
"$",
"item",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"implode",
"(",
"''",
",",
"$",
"item",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"out",
")",
";",
"}"
] | Get all combinations for spinner sentence
@param string $text
@return array | [
"Get",
"all",
"combinations",
"for",
"spinner",
"sentence"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L57-L73 | train |
g4code/utility | src/Tools.php | Tools.arrayCartesian | public static function arrayCartesian() {
$args = func_get_args();
if(count($args) == 0) {
return [[]]; // array with empty array is expected "empty" result
}
$work = array_shift($args);
$cartesian = call_user_func_array(__METHOD__, $args);
$result = [];
foreach($work as $value) {
foreach($cartesian as $product) {
$result[] = array_merge([$value], $product);
}
}
return $result;
} | php | public static function arrayCartesian() {
$args = func_get_args();
if(count($args) == 0) {
return [[]]; // array with empty array is expected "empty" result
}
$work = array_shift($args);
$cartesian = call_user_func_array(__METHOD__, $args);
$result = [];
foreach($work as $value) {
foreach($cartesian as $product) {
$result[] = array_merge([$value], $product);
}
}
return $result;
} | [
"public",
"static",
"function",
"arrayCartesian",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"return",
"[",
"[",
"]",
"]",
";",
"// array with empty array is expected \"empty\" result",
"}",
"$",
"work",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"cartesian",
"=",
"call_user_func_array",
"(",
"__METHOD__",
",",
"$",
"args",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"work",
"as",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"cartesian",
"as",
"$",
"product",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"array_merge",
"(",
"[",
"$",
"value",
"]",
",",
"$",
"product",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Calculate cartesian product of multiple arrays
@return multitype:multitype: | [
"Calculate",
"cartesian",
"product",
"of",
"multiple",
"arrays"
] | e0c9138aab61a53d88f32bb66201b075f3f44f1d | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Tools.php#L79-L97 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.