repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
webforge-labs/psc-cms | lib/Psc/URL/RequestBundle.php | RequestBundle.createRequest | public function createRequest($url, File $cookieJar = NULL) {
$loaded = FALSE;
$request = $this->requestsCache->load(array($url), $loaded);
if (!$loaded) {
$request = new Request($url, $cookieJar);
$request->getManager()->bind($this, Request::EVENT_PROCESSED); // stored dann wenn process() aufgerufen wurde
}
return $request;
} | php | public function createRequest($url, File $cookieJar = NULL) {
$loaded = FALSE;
$request = $this->requestsCache->load(array($url), $loaded);
if (!$loaded) {
$request = new Request($url, $cookieJar);
$request->getManager()->bind($this, Request::EVENT_PROCESSED); // stored dann wenn process() aufgerufen wurde
}
return $request;
} | [
"public",
"function",
"createRequest",
"(",
"$",
"url",
",",
"File",
"$",
"cookieJar",
"=",
"NULL",
")",
"{",
"$",
"loaded",
"=",
"FALSE",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"requestsCache",
"->",
"load",
"(",
"array",
"(",
"$",
"url",
")",
",",
"$",
"loaded",
")",
";",
"if",
"(",
"!",
"$",
"loaded",
")",
"{",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"url",
",",
"$",
"cookieJar",
")",
";",
"$",
"request",
"->",
"getManager",
"(",
")",
"->",
"bind",
"(",
"$",
"this",
",",
"Request",
"::",
"EVENT_PROCESSED",
")",
";",
"// stored dann wenn process() aufgerufen wurde",
"}",
"return",
"$",
"request",
";",
"}"
] | Gibt entweder einen gecachten oder einen echten Request zurück | [
"Gibt",
"entweder",
"einen",
"gecachten",
"oder",
"einen",
"echten",
"Request",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/URL/RequestBundle.php#L44-L54 |
webforge-labs/psc-cms | lib/Psc/URL/RequestBundle.php | RequestBundle.trigger | public function trigger(Event $event) {
$request = $event->getTarget();
$cachedRequest = new CachedRequest($request->getURL());
$cachedRequest->setCachedResponse($event->getData()->response);
$cachedRequest->setHeaders($event->getData()->headers);
$this->addCachedRequest($cachedRequest);
} | php | public function trigger(Event $event) {
$request = $event->getTarget();
$cachedRequest = new CachedRequest($request->getURL());
$cachedRequest->setCachedResponse($event->getData()->response);
$cachedRequest->setHeaders($event->getData()->headers);
$this->addCachedRequest($cachedRequest);
} | [
"public",
"function",
"trigger",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getTarget",
"(",
")",
";",
"$",
"cachedRequest",
"=",
"new",
"CachedRequest",
"(",
"$",
"request",
"->",
"getURL",
"(",
")",
")",
";",
"$",
"cachedRequest",
"->",
"setCachedResponse",
"(",
"$",
"event",
"->",
"getData",
"(",
")",
"->",
"response",
")",
";",
"$",
"cachedRequest",
"->",
"setHeaders",
"(",
"$",
"event",
"->",
"getData",
"(",
")",
"->",
"headers",
")",
";",
"$",
"this",
"->",
"addCachedRequest",
"(",
"$",
"cachedRequest",
")",
";",
"}"
] | Bei processed fügt das bundle den Request alse Cache-Request hinzu | [
"Bei",
"processed",
"fügt",
"das",
"bundle",
"den",
"Request",
"alse",
"Cache",
"-",
"Request",
"hinzu"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/URL/RequestBundle.php#L60-L68 |
yuncms/framework | src/widgets/BootstrapTypeAhead.php | BootstrapTypeAhead.registerClientScript | protected function registerClientScript()
{
$view = $this->getView();
BootstrapTypeAheadAsset::register($view);
$id = $this->options['id'];
$options = $this->clientOptions !== false && !empty($this->clientOptions) ? Json::encode($this->clientOptions) : 'null';
foreach($this->dataSets as $dataSet) {
if(empty($dataSet)) {
continue;
}
$dataSets[] = Json::encode($dataSet);
}
$dataSets = !empty($dataSets) ? implode(", ", $dataSets) : '{}';
foreach ($this->engines as $bloodhound) {
if ($bloodhound instanceof BootstrapTypeAheadBloodhound) {
$js[] = $bloodhound->getClientScript();
}
}
$js[] = "jQuery('#$id').typeahead($options, $dataSets);";
foreach ($this->clientEvents as $eventName => $handler) {
$js[] = "jQuery('#$id').on('$eventName', $handler);";
}
$view->registerJs(implode("\n", $js));
} | php | protected function registerClientScript()
{
$view = $this->getView();
BootstrapTypeAheadAsset::register($view);
$id = $this->options['id'];
$options = $this->clientOptions !== false && !empty($this->clientOptions) ? Json::encode($this->clientOptions) : 'null';
foreach($this->dataSets as $dataSet) {
if(empty($dataSet)) {
continue;
}
$dataSets[] = Json::encode($dataSet);
}
$dataSets = !empty($dataSets) ? implode(", ", $dataSets) : '{}';
foreach ($this->engines as $bloodhound) {
if ($bloodhound instanceof BootstrapTypeAheadBloodhound) {
$js[] = $bloodhound->getClientScript();
}
}
$js[] = "jQuery('#$id').typeahead($options, $dataSets);";
foreach ($this->clientEvents as $eventName => $handler) {
$js[] = "jQuery('#$id').on('$eventName', $handler);";
}
$view->registerJs(implode("\n", $js));
} | [
"protected",
"function",
"registerClientScript",
"(",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"BootstrapTypeAheadAsset",
"::",
"register",
"(",
"$",
"view",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"options",
"[",
"'id'",
"]",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"clientOptions",
"!==",
"false",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"clientOptions",
")",
"?",
"Json",
"::",
"encode",
"(",
"$",
"this",
"->",
"clientOptions",
")",
":",
"'null'",
";",
"foreach",
"(",
"$",
"this",
"->",
"dataSets",
"as",
"$",
"dataSet",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"dataSet",
")",
")",
"{",
"continue",
";",
"}",
"$",
"dataSets",
"[",
"]",
"=",
"Json",
"::",
"encode",
"(",
"$",
"dataSet",
")",
";",
"}",
"$",
"dataSets",
"=",
"!",
"empty",
"(",
"$",
"dataSets",
")",
"?",
"implode",
"(",
"\", \"",
",",
"$",
"dataSets",
")",
":",
"'{}'",
";",
"foreach",
"(",
"$",
"this",
"->",
"engines",
"as",
"$",
"bloodhound",
")",
"{",
"if",
"(",
"$",
"bloodhound",
"instanceof",
"BootstrapTypeAheadBloodhound",
")",
"{",
"$",
"js",
"[",
"]",
"=",
"$",
"bloodhound",
"->",
"getClientScript",
"(",
")",
";",
"}",
"}",
"$",
"js",
"[",
"]",
"=",
"\"jQuery('#$id').typeahead($options, $dataSets);\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"clientEvents",
"as",
"$",
"eventName",
"=>",
"$",
"handler",
")",
"{",
"$",
"js",
"[",
"]",
"=",
"\"jQuery('#$id').on('$eventName', $handler);\"",
";",
"}",
"$",
"view",
"->",
"registerJs",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"js",
")",
")",
";",
"}"
] | Registers Twitter TypeAhead Bootstrap plugin and the related events | [
"Registers",
"Twitter",
"TypeAhead",
"Bootstrap",
"plugin",
"and",
"the",
"related",
"events"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/widgets/BootstrapTypeAhead.php#L80-L109 |
magnus-eriksson/entity | src/Entity.php | Entity.setParam | protected function setParam($key, $value)
{
if (!array_key_exists($key, $this->_params)) {
if ($this->_ignoreExisting || $this->arrayGet($this->_setup, 'suppress_errors') === true) {
return;
}
throw new UnknownPropertyException("Unknown property: '{$key}'");
}
switch ($this->_types[$key]) {
case "boolean":
$this->_params[$key] = (bool)$value;
break;
case "integer":
$this->_params[$key] = (integer)$value;
break;
case "float":
$this->_params[$key] = (float)$value;
break;
case "string":
$this->_params[$key] = (string)$value;
break;
case "array":
$this->_params[$key] = (array)$value;
break;
default:
$this->_params[$key] = $value;
break;
}
} | php | protected function setParam($key, $value)
{
if (!array_key_exists($key, $this->_params)) {
if ($this->_ignoreExisting || $this->arrayGet($this->_setup, 'suppress_errors') === true) {
return;
}
throw new UnknownPropertyException("Unknown property: '{$key}'");
}
switch ($this->_types[$key]) {
case "boolean":
$this->_params[$key] = (bool)$value;
break;
case "integer":
$this->_params[$key] = (integer)$value;
break;
case "float":
$this->_params[$key] = (float)$value;
break;
case "string":
$this->_params[$key] = (string)$value;
break;
case "array":
$this->_params[$key] = (array)$value;
break;
default:
$this->_params[$key] = $value;
break;
}
} | [
"protected",
"function",
"setParam",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_params",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ignoreExisting",
"||",
"$",
"this",
"->",
"arrayGet",
"(",
"$",
"this",
"->",
"_setup",
",",
"'suppress_errors'",
")",
"===",
"true",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"UnknownPropertyException",
"(",
"\"Unknown property: '{$key}'\"",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
")",
"{",
"case",
"\"boolean\"",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"(",
"bool",
")",
"$",
"value",
";",
"break",
";",
"case",
"\"integer\"",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"(",
"integer",
")",
"$",
"value",
";",
"break",
";",
"case",
"\"float\"",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"(",
"float",
")",
"$",
"value",
";",
"break",
";",
"case",
"\"string\"",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"break",
";",
"case",
"\"array\"",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"(",
"array",
")",
"$",
"value",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}"
] | Set a value in the parameter pool and cast it to the same type as
the default value
@param string $key
@param mixed $value
@throws UnknownPropertyException | [
"Set",
"a",
"value",
"in",
"the",
"parameter",
"pool",
"and",
"cast",
"it",
"to",
"the",
"same",
"type",
"as",
"the",
"default",
"value"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L159-L189 |
magnus-eriksson/entity | src/Entity.php | Entity.setDefaultDataTypes | protected function setDefaultDataTypes()
{
foreach ($this->_params as $key => $value) {
switch (gettype($value)) {
case "boolean":
$this->_types[$key] = 'boolean';
break;
case "integer":
$this->_types[$key] = 'integer';
break;
case "double":
$this->_types[$key] = 'float';
break;
case "string":
$this->_types[$key] = 'string';
break;
case "array":
$this->_types[$key] = 'array';
break;
default:
$this->_types[$key] = null;
break;
}
}
} | php | protected function setDefaultDataTypes()
{
foreach ($this->_params as $key => $value) {
switch (gettype($value)) {
case "boolean":
$this->_types[$key] = 'boolean';
break;
case "integer":
$this->_types[$key] = 'integer';
break;
case "double":
$this->_types[$key] = 'float';
break;
case "string":
$this->_types[$key] = 'string';
break;
case "array":
$this->_types[$key] = 'array';
break;
default:
$this->_types[$key] = null;
break;
}
}
} | [
"protected",
"function",
"setDefaultDataTypes",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"\"boolean\"",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"'boolean'",
";",
"break",
";",
"case",
"\"integer\"",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"'integer'",
";",
"break",
";",
"case",
"\"double\"",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"'float'",
";",
"break",
";",
"case",
"\"string\"",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"'string'",
";",
"break",
";",
"case",
"\"array\"",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"'array'",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"_types",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"break",
";",
"}",
"}",
"}"
] | Get the default data types | [
"Get",
"the",
"default",
"data",
"types"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L195-L219 |
magnus-eriksson/entity | src/Entity.php | Entity.toArray | public function toArray($protect = null)
{
$protect = is_array($protect)
? $protect
: $this->_protect;
if ($protect) {
$new = $this->_params;
foreach ($protect as $key) {
unset($new[$key]);
}
// Do json encode and decode to convert all levels to arrays
return json_decode(json_encode($new), true, 512);
}
// Do json encode and decode to convert all levels to arrays
return json_decode(json_encode($this->_params), true, 512);
} | php | public function toArray($protect = null)
{
$protect = is_array($protect)
? $protect
: $this->_protect;
if ($protect) {
$new = $this->_params;
foreach ($protect as $key) {
unset($new[$key]);
}
// Do json encode and decode to convert all levels to arrays
return json_decode(json_encode($new), true, 512);
}
// Do json encode and decode to convert all levels to arrays
return json_decode(json_encode($this->_params), true, 512);
} | [
"public",
"function",
"toArray",
"(",
"$",
"protect",
"=",
"null",
")",
"{",
"$",
"protect",
"=",
"is_array",
"(",
"$",
"protect",
")",
"?",
"$",
"protect",
":",
"$",
"this",
"->",
"_protect",
";",
"if",
"(",
"$",
"protect",
")",
"{",
"$",
"new",
"=",
"$",
"this",
"->",
"_params",
";",
"foreach",
"(",
"$",
"protect",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"new",
"[",
"$",
"key",
"]",
")",
";",
"}",
"// Do json encode and decode to convert all levels to arrays",
"return",
"json_decode",
"(",
"json_encode",
"(",
"$",
"new",
")",
",",
"true",
",",
"512",
")",
";",
"}",
"// Do json encode and decode to convert all levels to arrays",
"return",
"json_decode",
"(",
"json_encode",
"(",
"$",
"this",
"->",
"_params",
")",
",",
"true",
",",
"512",
")",
";",
"}"
] | Return the params as array and remove the protected keys
@param array|null $protect
@return array | [
"Return",
"the",
"params",
"as",
"array",
"and",
"remove",
"the",
"protected",
"keys"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L258-L278 |
magnus-eriksson/entity | src/Entity.php | Entity.date | public function date($key, $format = "F j, Y")
{
if (is_numeric($this->_params[$key])) {
return date($format, $this->_params[$key]);
}
return date($format, strtotime($this->_params[$key]));
} | php | public function date($key, $format = "F j, Y")
{
if (is_numeric($this->_params[$key])) {
return date($format, $this->_params[$key]);
}
return date($format, strtotime($this->_params[$key]));
} | [
"public",
"function",
"date",
"(",
"$",
"key",
",",
"$",
"format",
"=",
"\"F j, Y\"",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"date",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"date",
"(",
"$",
"format",
",",
"strtotime",
"(",
"$",
"this",
"->",
"_params",
"[",
"$",
"key",
"]",
")",
")",
";",
"}"
] | Return a parameter as a formatted date string
@param string $key
@param string $format
@return string | [
"Return",
"a",
"parameter",
"as",
"a",
"formatted",
"date",
"string"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L300-L307 |
magnus-eriksson/entity | src/Entity.php | Entity.make | public static function make($data = null, $index = null, Closure $modifier = null)
{
if ($data instanceof Traversable) {
$data = iterator_to_array($data);
}
if (!is_array($data)) {
return null;
}
if (count($data) < 1) {
return [];
}
// Check if it is a multi dimensional array
$values = array_values($data);
$multi = array_key_exists(0, $values) && is_array($values[0]);
if ($multi) {
$list = [];
foreach ($data as $item) {
if ($index && array_key_exists($index, $item)) {
$key = $item[$index];
$list[$key] = static::populate($item, $modifier);
continue;
}
$list[] = static::populate($item, $modifier);
}
return $list;
}
return static::populate($data, $modifier);
} | php | public static function make($data = null, $index = null, Closure $modifier = null)
{
if ($data instanceof Traversable) {
$data = iterator_to_array($data);
}
if (!is_array($data)) {
return null;
}
if (count($data) < 1) {
return [];
}
// Check if it is a multi dimensional array
$values = array_values($data);
$multi = array_key_exists(0, $values) && is_array($values[0]);
if ($multi) {
$list = [];
foreach ($data as $item) {
if ($index && array_key_exists($index, $item)) {
$key = $item[$index];
$list[$key] = static::populate($item, $modifier);
continue;
}
$list[] = static::populate($item, $modifier);
}
return $list;
}
return static::populate($data, $modifier);
} | [
"public",
"static",
"function",
"make",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"index",
"=",
"null",
",",
"Closure",
"$",
"modifier",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"Traversable",
")",
"{",
"$",
"data",
"=",
"iterator_to_array",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"<",
"1",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// Check if it is a multi dimensional array",
"$",
"values",
"=",
"array_values",
"(",
"$",
"data",
")",
";",
"$",
"multi",
"=",
"array_key_exists",
"(",
"0",
",",
"$",
"values",
")",
"&&",
"is_array",
"(",
"$",
"values",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"multi",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"index",
"&&",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"item",
")",
")",
"{",
"$",
"key",
"=",
"$",
"item",
"[",
"$",
"index",
"]",
";",
"$",
"list",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"populate",
"(",
"$",
"item",
",",
"$",
"modifier",
")",
";",
"continue",
";",
"}",
"$",
"list",
"[",
"]",
"=",
"static",
"::",
"populate",
"(",
"$",
"item",
",",
"$",
"modifier",
")",
";",
"}",
"return",
"$",
"list",
";",
"}",
"return",
"static",
"::",
"populate",
"(",
"$",
"data",
",",
"$",
"modifier",
")",
";",
"}"
] | Convert array to entities
@param array $data
@param string $index Set the value in this key as index
@param Closure $modifier Executed before the entity gets populated
@return Entity|array | [
"Convert",
"array",
"to",
"entities"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L332-L366 |
magnus-eriksson/entity | src/Entity.php | Entity.arrayGet | protected function arrayGet(&$source, $key, $default = null)
{
if (!$key) {
return $default;
}
if (array_key_exists($key, $source)) {
return $source[$key];
}
$current =& $source;
foreach (explode('.', $key) as $segment) {
if (!array_key_exists($segment, $current)) {
return $default;
}
$current =& $current[$segment];
}
return $current;
} | php | protected function arrayGet(&$source, $key, $default = null)
{
if (!$key) {
return $default;
}
if (array_key_exists($key, $source)) {
return $source[$key];
}
$current =& $source;
foreach (explode('.', $key) as $segment) {
if (!array_key_exists($segment, $current)) {
return $default;
}
$current =& $current[$segment];
}
return $current;
} | [
"protected",
"function",
"arrayGet",
"(",
"&",
"$",
"source",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"source",
")",
")",
"{",
"return",
"$",
"source",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"current",
"=",
"&",
"$",
"source",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"segment",
",",
"$",
"current",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"current",
"=",
"&",
"$",
"current",
"[",
"$",
"segment",
"]",
";",
"}",
"return",
"$",
"current",
";",
"}"
] | Get a key value, using dot notation
@param array &$source
@param string $key
@param mixed $default
@return mixed | [
"Get",
"a",
"key",
"value",
"using",
"dot",
"notation"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L392-L411 |
magnus-eriksson/entity | src/Entity.php | Entity.arrayHasKey | protected function arrayHasKey(&$source, $key)
{
if (!$key || !is_array($source)) {
return false;
}
if (array_key_exists($key, $source)) {
return true;
}
$current =& $source;
foreach (explode('.', $key) as $segment) {
if (!array_key_exists($segment, $current)) {
return false;
}
$current =& $current[$segment];
}
return true;
} | php | protected function arrayHasKey(&$source, $key)
{
if (!$key || !is_array($source)) {
return false;
}
if (array_key_exists($key, $source)) {
return true;
}
$current =& $source;
foreach (explode('.', $key) as $segment) {
if (!array_key_exists($segment, $current)) {
return false;
}
$current =& $current[$segment];
}
return true;
} | [
"protected",
"function",
"arrayHasKey",
"(",
"&",
"$",
"source",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"key",
"||",
"!",
"is_array",
"(",
"$",
"source",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"source",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"current",
"=",
"&",
"$",
"source",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"segment",
",",
"$",
"current",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"current",
"=",
"&",
"$",
"current",
"[",
"$",
"segment",
"]",
";",
"}",
"return",
"true",
";",
"}"
] | Check if a key exists, using dot notation
@param array &$source
@param string $key
@return boolean | [
"Check",
"if",
"a",
"key",
"exists",
"using",
"dot",
"notation"
] | train | https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L422-L441 |
GrahamDeprecated/CMS-Core | src/Seeds/UsersTableSeeder.php | UsersTableSeeder.run | public function run()
{
DB::table('users')->delete();
$user = array(
'first_name' => 'CMS',
'last_name' => 'Admin',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Semi-Admin',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Moderator',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Blogger',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Editor',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'User',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
} | php | public function run()
{
DB::table('users')->delete();
$user = array(
'first_name' => 'CMS',
'last_name' => 'Admin',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Semi-Admin',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Moderator',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Blogger',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'Editor',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
$user = array(
'first_name' => 'CMS',
'last_name' => 'User',
'email' => '[email protected]',
'password' => 'password',
'activated' => 1,
'activated_at' => new DateTime
);
Credentials::getUserProvider()->create($user);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"DB",
"::",
"table",
"(",
"'users'",
")",
"->",
"delete",
"(",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'Admin'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'Semi-Admin'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'Moderator'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'Blogger'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'Editor'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"$",
"user",
"=",
"array",
"(",
"'first_name'",
"=>",
"'CMS'",
",",
"'last_name'",
"=>",
"'User'",
",",
"'email'",
"=>",
"'[email protected]'",
",",
"'password'",
"=>",
"'password'",
",",
"'activated'",
"=>",
"1",
",",
"'activated_at'",
"=>",
"new",
"DateTime",
")",
";",
"Credentials",
"::",
"getUserProvider",
"(",
")",
"->",
"create",
"(",
"$",
"user",
")",
";",
"}"
] | Run the database seeding.
@return void | [
"Run",
"the",
"database",
"seeding",
"."
] | train | https://github.com/GrahamDeprecated/CMS-Core/blob/5603e2bfa2fac6cf46ca3ed62d21518f2f653675/src/Seeds/UsersTableSeeder.php#L40-L103 |
haldayne/boost | src/MapOfStrings.php | MapOfStrings.join | public function join($separator)
{
return $this->reduce(
function ($joined, $string) use ($separator) {
return ('' === $joined ? '' : $joined . $separator) . $string;
},
''
);
} | php | public function join($separator)
{
return $this->reduce(
function ($joined, $string) use ($separator) {
return ('' === $joined ? '' : $joined . $separator) . $string;
},
''
);
} | [
"public",
"function",
"join",
"(",
"$",
"separator",
")",
"{",
"return",
"$",
"this",
"->",
"reduce",
"(",
"function",
"(",
"$",
"joined",
",",
"$",
"string",
")",
"use",
"(",
"$",
"separator",
")",
"{",
"return",
"(",
"''",
"===",
"$",
"joined",
"?",
"''",
":",
"$",
"joined",
".",
"$",
"separator",
")",
".",
"$",
"string",
";",
"}",
",",
"''",
")",
";",
"}"
] | Join all the strings in this map with the separator between them.
@param string $separator
@return string
@api | [
"Join",
"all",
"the",
"strings",
"in",
"this",
"map",
"with",
"the",
"separator",
"between",
"them",
"."
] | train | https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/MapOfStrings.php#L17-L25 |
haldayne/boost | src/MapOfStrings.php | MapOfStrings.letter_frequency | public function letter_frequency()
{
return $this->transform(
function ($frequencies, $word) {
foreach (count_chars($word, 1) as $byte => $frequency) {
$letter = chr($byte);
if ($frequencies->has($letter)) {
$frequencies->set($letter, $frequencies->get($letter)+1);
} else {
$frequencies->set($letter, 1);
}
}
},
function (Map $original) { return new MapOfInts(); }
);
} | php | public function letter_frequency()
{
return $this->transform(
function ($frequencies, $word) {
foreach (count_chars($word, 1) as $byte => $frequency) {
$letter = chr($byte);
if ($frequencies->has($letter)) {
$frequencies->set($letter, $frequencies->get($letter)+1);
} else {
$frequencies->set($letter, 1);
}
}
},
function (Map $original) { return new MapOfInts(); }
);
} | [
"public",
"function",
"letter_frequency",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"transform",
"(",
"function",
"(",
"$",
"frequencies",
",",
"$",
"word",
")",
"{",
"foreach",
"(",
"count_chars",
"(",
"$",
"word",
",",
"1",
")",
"as",
"$",
"byte",
"=>",
"$",
"frequency",
")",
"{",
"$",
"letter",
"=",
"chr",
"(",
"$",
"byte",
")",
";",
"if",
"(",
"$",
"frequencies",
"->",
"has",
"(",
"$",
"letter",
")",
")",
"{",
"$",
"frequencies",
"->",
"set",
"(",
"$",
"letter",
",",
"$",
"frequencies",
"->",
"get",
"(",
"$",
"letter",
")",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"frequencies",
"->",
"set",
"(",
"$",
"letter",
",",
"1",
")",
";",
"}",
"}",
"}",
",",
"function",
"(",
"Map",
"$",
"original",
")",
"{",
"return",
"new",
"MapOfInts",
"(",
")",
";",
"}",
")",
";",
"}"
] | Calculate frequency of letters in all strings.
Counts how many times each letter occurs within every string in this
map. Returns a new Map of letter to number of occurrences. Only
letters that appear will be in the resulting map.
@return \Haldayne\Boost\MapOfIntegers
@api | [
"Calculate",
"frequency",
"of",
"letters",
"in",
"all",
"strings",
"."
] | train | https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/MapOfStrings.php#L37-L52 |
AymDev/PPRR | src/PPRR.php | PPRR.buildRegex | private static function buildRegex(string $expression, bool $is_prefix = false) : string
{
$regex = self::REGEX_DELIMITER . '^';
$regex .= preg_replace(array_keys(self::$datatypes), self::$datatypes, $expression);
$regex .= $is_prefix ? '(.*)' : '';
$regex .= '$' . self::REGEX_DELIMITER;
return $regex;
} | php | private static function buildRegex(string $expression, bool $is_prefix = false) : string
{
$regex = self::REGEX_DELIMITER . '^';
$regex .= preg_replace(array_keys(self::$datatypes), self::$datatypes, $expression);
$regex .= $is_prefix ? '(.*)' : '';
$regex .= '$' . self::REGEX_DELIMITER;
return $regex;
} | [
"private",
"static",
"function",
"buildRegex",
"(",
"string",
"$",
"expression",
",",
"bool",
"$",
"is_prefix",
"=",
"false",
")",
":",
"string",
"{",
"$",
"regex",
"=",
"self",
"::",
"REGEX_DELIMITER",
".",
"'^'",
";",
"$",
"regex",
".=",
"preg_replace",
"(",
"array_keys",
"(",
"self",
"::",
"$",
"datatypes",
")",
",",
"self",
"::",
"$",
"datatypes",
",",
"$",
"expression",
")",
";",
"$",
"regex",
".=",
"$",
"is_prefix",
"?",
"'(.*)'",
":",
"''",
";",
"$",
"regex",
".=",
"'$'",
".",
"self",
"::",
"REGEX_DELIMITER",
";",
"return",
"$",
"regex",
";",
"}"
] | Build a complete regular expression
@param string $expression the route to evaluate
@param bool $is_prefix is the route a route prefix
@return string the complete regular expression | [
"Build",
"a",
"complete",
"regular",
"expression"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L63-L70 |
AymDev/PPRR | src/PPRR.php | PPRR.getParsingMode | private function getParsingMode(string &$route) : int
{
// Explicit regex mode
if (strpos($route, 'R>') === 0) {
$route = str_replace('R>', '', $route);
return self::MODE_REGEX;
}
// Explicit string mode
if (strpos($route, 'S>') === 0) {
$route = str_replace('S>', '', $route);
return self::MODE_STRING;
}
// Use default mode
return self::$mode;
} | php | private function getParsingMode(string &$route) : int
{
// Explicit regex mode
if (strpos($route, 'R>') === 0) {
$route = str_replace('R>', '', $route);
return self::MODE_REGEX;
}
// Explicit string mode
if (strpos($route, 'S>') === 0) {
$route = str_replace('S>', '', $route);
return self::MODE_STRING;
}
// Use default mode
return self::$mode;
} | [
"private",
"function",
"getParsingMode",
"(",
"string",
"&",
"$",
"route",
")",
":",
"int",
"{",
"// Explicit regex mode",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"'R>'",
")",
"===",
"0",
")",
"{",
"$",
"route",
"=",
"str_replace",
"(",
"'R>'",
",",
"''",
",",
"$",
"route",
")",
";",
"return",
"self",
"::",
"MODE_REGEX",
";",
"}",
"// Explicit string mode",
"if",
"(",
"strpos",
"(",
"$",
"route",
",",
"'S>'",
")",
"===",
"0",
")",
"{",
"$",
"route",
"=",
"str_replace",
"(",
"'S>'",
",",
"''",
",",
"$",
"route",
")",
";",
"return",
"self",
"::",
"MODE_STRING",
";",
"}",
"// Use default mode",
"return",
"self",
"::",
"$",
"mode",
";",
"}"
] | Detect route parsing mode for specific route
@param string &$route route to check
@return int class constant mode | [
"Detect",
"route",
"parsing",
"mode",
"for",
"specific",
"route"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L83-L98 |
AymDev/PPRR | src/PPRR.php | PPRR.matchRoute | private function matchRoute(string $route, string $url, &$matches, $value = null)
{
switch ($this->getParsingMode($route)) {
case self::MODE_REGEX:
// Evaluate & remove first match (full route)
$matched = preg_match(self::buildRegex($route, !is_null($value)), $url, $matches);
array_shift($matches);
break;
case self::MODE_STRING:
// final route
if (is_null($value)) {
$matched = $route === $url;
$matches = [];
// route prefix
} else {
$matched = empty($route) ? empty($url) : strpos($url, $route) === 0;
$matches = [str_replace($route, '', $url)];
}
break;
}
// Route matches
if (is_null($value)) {
return $matched;
}
// value is sub-routes array
$sub_routes = !is_callable($value) && is_array($value);
return $matched && $sub_routes;
} | php | private function matchRoute(string $route, string $url, &$matches, $value = null)
{
switch ($this->getParsingMode($route)) {
case self::MODE_REGEX:
// Evaluate & remove first match (full route)
$matched = preg_match(self::buildRegex($route, !is_null($value)), $url, $matches);
array_shift($matches);
break;
case self::MODE_STRING:
// final route
if (is_null($value)) {
$matched = $route === $url;
$matches = [];
// route prefix
} else {
$matched = empty($route) ? empty($url) : strpos($url, $route) === 0;
$matches = [str_replace($route, '', $url)];
}
break;
}
// Route matches
if (is_null($value)) {
return $matched;
}
// value is sub-routes array
$sub_routes = !is_callable($value) && is_array($value);
return $matched && $sub_routes;
} | [
"private",
"function",
"matchRoute",
"(",
"string",
"$",
"route",
",",
"string",
"$",
"url",
",",
"&",
"$",
"matches",
",",
"$",
"value",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getParsingMode",
"(",
"$",
"route",
")",
")",
"{",
"case",
"self",
"::",
"MODE_REGEX",
":",
"// Evaluate & remove first match (full route)",
"$",
"matched",
"=",
"preg_match",
"(",
"self",
"::",
"buildRegex",
"(",
"$",
"route",
",",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
",",
"$",
"url",
",",
"$",
"matches",
")",
";",
"array_shift",
"(",
"$",
"matches",
")",
";",
"break",
";",
"case",
"self",
"::",
"MODE_STRING",
":",
"// final route",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"matched",
"=",
"$",
"route",
"===",
"$",
"url",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"// route prefix",
"}",
"else",
"{",
"$",
"matched",
"=",
"empty",
"(",
"$",
"route",
")",
"?",
"empty",
"(",
"$",
"url",
")",
":",
"strpos",
"(",
"$",
"url",
",",
"$",
"route",
")",
"===",
"0",
";",
"$",
"matches",
"=",
"[",
"str_replace",
"(",
"$",
"route",
",",
"''",
",",
"$",
"url",
")",
"]",
";",
"}",
"break",
";",
"}",
"// Route matches",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"matched",
";",
"}",
"// value is sub-routes array",
"$",
"sub_routes",
"=",
"!",
"is_callable",
"(",
"$",
"value",
")",
"&&",
"is_array",
"(",
"$",
"value",
")",
";",
"return",
"$",
"matched",
"&&",
"$",
"sub_routes",
";",
"}"
] | Match url against route
@param string $route route to match against
@param string $url url to test
@param mixed &$matches variable to fill with matches
@param mixed $value route value (sub routes or callback) | [
"Match",
"url",
"against",
"route"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L111-L142 |
AymDev/PPRR | src/PPRR.php | PPRR.route | private function route() : void
{
// Parse route
$parsed = $this->parseRoute();
// Run error controller when no route matched
if (!$parsed && isset($this->error_controller)) {
call_user_func($this->error_controller);
}
} | php | private function route() : void
{
// Parse route
$parsed = $this->parseRoute();
// Run error controller when no route matched
if (!$parsed && isset($this->error_controller)) {
call_user_func($this->error_controller);
}
} | [
"private",
"function",
"route",
"(",
")",
":",
"void",
"{",
"// Parse route",
"$",
"parsed",
"=",
"$",
"this",
"->",
"parseRoute",
"(",
")",
";",
"// Run error controller when no route matched",
"if",
"(",
"!",
"$",
"parsed",
"&&",
"isset",
"(",
"$",
"this",
"->",
"error_controller",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"error_controller",
")",
";",
"}",
"}"
] | Try to parse routes or call the error controller
@return void | [
"Try",
"to",
"parse",
"routes",
"or",
"call",
"the",
"error",
"controller"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L153-L162 |
AymDev/PPRR | src/PPRR.php | PPRR.parseRoute | private function parseRoute(?array $routes = null, ?string $to_parse = null, string ...$args) : bool
{
// Set variables in 1st call
$routes = $routes ?? $this->routes;
$url = $to_parse ?? $this->current_route;
// Loop through routes
foreach ($routes as $expr => $callback) {
// Route prefix matches
if ($this->matchRoute($expr, $url, $matches, $callback)) {
// Extract sub route & merge arguments
$sub_route = array_pop($matches);
$sub_args = array_merge($args, $matches);
// Parse sub routes
if ($this->parseRoute($callback, $sub_route, ...$sub_args) === true) {
return true;
}
// Route matches
} elseif ($this->matchRoute($expr, $url, $matches)) {
if (!is_callable($callback)) {
throw new \BadMethodCallException("Value for $expr route expression is not a valid callback", 2);
}
// Call the controller with merged arguments
call_user_func_array($callback, array_merge($args, $matches));
return true;
}
}
return false;
} | php | private function parseRoute(?array $routes = null, ?string $to_parse = null, string ...$args) : bool
{
// Set variables in 1st call
$routes = $routes ?? $this->routes;
$url = $to_parse ?? $this->current_route;
// Loop through routes
foreach ($routes as $expr => $callback) {
// Route prefix matches
if ($this->matchRoute($expr, $url, $matches, $callback)) {
// Extract sub route & merge arguments
$sub_route = array_pop($matches);
$sub_args = array_merge($args, $matches);
// Parse sub routes
if ($this->parseRoute($callback, $sub_route, ...$sub_args) === true) {
return true;
}
// Route matches
} elseif ($this->matchRoute($expr, $url, $matches)) {
if (!is_callable($callback)) {
throw new \BadMethodCallException("Value for $expr route expression is not a valid callback", 2);
}
// Call the controller with merged arguments
call_user_func_array($callback, array_merge($args, $matches));
return true;
}
}
return false;
} | [
"private",
"function",
"parseRoute",
"(",
"?",
"array",
"$",
"routes",
"=",
"null",
",",
"?",
"string",
"$",
"to_parse",
"=",
"null",
",",
"string",
"...",
"$",
"args",
")",
":",
"bool",
"{",
"// Set variables in 1st call",
"$",
"routes",
"=",
"$",
"routes",
"??",
"$",
"this",
"->",
"routes",
";",
"$",
"url",
"=",
"$",
"to_parse",
"??",
"$",
"this",
"->",
"current_route",
";",
"// Loop through routes",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"expr",
"=>",
"$",
"callback",
")",
"{",
"// Route prefix matches",
"if",
"(",
"$",
"this",
"->",
"matchRoute",
"(",
"$",
"expr",
",",
"$",
"url",
",",
"$",
"matches",
",",
"$",
"callback",
")",
")",
"{",
"// Extract sub route & merge arguments",
"$",
"sub_route",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"sub_args",
"=",
"array_merge",
"(",
"$",
"args",
",",
"$",
"matches",
")",
";",
"// Parse sub routes",
"if",
"(",
"$",
"this",
"->",
"parseRoute",
"(",
"$",
"callback",
",",
"$",
"sub_route",
",",
"...",
"$",
"sub_args",
")",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"// Route matches",
"}",
"elseif",
"(",
"$",
"this",
"->",
"matchRoute",
"(",
"$",
"expr",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"Value for $expr route expression is not a valid callback\"",
",",
"2",
")",
";",
"}",
"// Call the controller with merged arguments",
"call_user_func_array",
"(",
"$",
"callback",
",",
"array_merge",
"(",
"$",
"args",
",",
"$",
"matches",
")",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Parse routes (recursively) and call the matching controller
@param null|array $routes routes array to loop through
@param null|string $to_parse the URL part to parse
@param array[string] $args arguments fetched from the URL
@return bool true if a route matched
@throws \UnexpectedValueException when route value is not a valid callback | [
"Parse",
"routes",
"(",
"recursively",
")",
"and",
"call",
"the",
"matching",
"controller"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L179-L212 |
AymDev/PPRR | src/PPRR.php | PPRR.setDataTypes | public static function setDataTypes(array $types) : void
{
// Datatypes key validation
foreach ($types as $key => $value) {
if (!preg_match('/^[A-Za-z0-9-_]+$/', $key)) {
throw new \UnexpectedValueException("<b>$key</b> is not a valid datatype key", 1);
} elseif (!is_string($value)) {
throw new \LogicException("<b>$key</b> must have a string value", 1);
}
}
// Put keys between brackets
self::$datatypes = array_combine(
array_map(function ($t) {
return '/\{' . $t . '\}/';
}, array_keys($types)),
$types
);
} | php | public static function setDataTypes(array $types) : void
{
// Datatypes key validation
foreach ($types as $key => $value) {
if (!preg_match('/^[A-Za-z0-9-_]+$/', $key)) {
throw new \UnexpectedValueException("<b>$key</b> is not a valid datatype key", 1);
} elseif (!is_string($value)) {
throw new \LogicException("<b>$key</b> must have a string value", 1);
}
}
// Put keys between brackets
self::$datatypes = array_combine(
array_map(function ($t) {
return '/\{' . $t . '\}/';
}, array_keys($types)),
$types
);
} | [
"public",
"static",
"function",
"setDataTypes",
"(",
"array",
"$",
"types",
")",
":",
"void",
"{",
"// Datatypes key validation",
"foreach",
"(",
"$",
"types",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[A-Za-z0-9-_]+$/'",
",",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"<b>$key</b> is not a valid datatype key\"",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"<b>$key</b> must have a string value\"",
",",
"1",
")",
";",
"}",
"}",
"// Put keys between brackets",
"self",
"::",
"$",
"datatypes",
"=",
"array_combine",
"(",
"array_map",
"(",
"function",
"(",
"$",
"t",
")",
"{",
"return",
"'/\\{'",
".",
"$",
"t",
".",
"'\\}/'",
";",
"}",
",",
"array_keys",
"(",
"$",
"types",
")",
")",
",",
"$",
"types",
")",
";",
"}"
] | Define data types (Regex shortcuts)
@param array $types the Regex shortcuts
@return void
@throws \UnexpectedValueException when datatype key is invalid
@throws \LogicException when datatype value is not a string | [
"Define",
"data",
"types",
"(",
"Regex",
"shortcuts",
")"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L228-L247 |
AymDev/PPRR | src/PPRR.php | PPRR.setDefaultMode | public static function setDefaultMode(int $mode) : void
{
if (in_array($mode, [self::MODE_REGEX, self::MODE_STRING])) {
self::$mode = $mode;
return;
}
// Unknown mode
throw new \UnexpectedValueException('Invalid route mode');
} | php | public static function setDefaultMode(int $mode) : void
{
if (in_array($mode, [self::MODE_REGEX, self::MODE_STRING])) {
self::$mode = $mode;
return;
}
// Unknown mode
throw new \UnexpectedValueException('Invalid route mode');
} | [
"public",
"static",
"function",
"setDefaultMode",
"(",
"int",
"$",
"mode",
")",
":",
"void",
"{",
"if",
"(",
"in_array",
"(",
"$",
"mode",
",",
"[",
"self",
"::",
"MODE_REGEX",
",",
"self",
"::",
"MODE_STRING",
"]",
")",
")",
"{",
"self",
"::",
"$",
"mode",
"=",
"$",
"mode",
";",
"return",
";",
"}",
"// Unknown mode",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Invalid route mode'",
")",
";",
"}"
] | Set the route parsing mode
@param int $mode a class MODE_* constant
@return void
@throws \UnexpectedValueException for unknown modes | [
"Set",
"the",
"route",
"parsing",
"mode"
] | train | https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L262-L271 |
cohesion/cohesion-core | src/Util/Autoloader.php | Autoloader.addClassPath | public function addClassPath($path) {
if(!is_array($path)) {
$path = array($path);
}
foreach($path as $item) {
$this->classPaths[] = $item;
}
} | php | public function addClassPath($path) {
if(!is_array($path)) {
$path = array($path);
}
foreach($path as $item) {
$this->classPaths[] = $item;
}
} | [
"public",
"function",
"addClassPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"array",
"(",
"$",
"path",
")",
";",
"}",
"foreach",
"(",
"$",
"path",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"classPaths",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}"
] | Adds a path to search in when looking for a class.
@param string $path
@return void | [
"Adds",
"a",
"path",
"to",
"search",
"in",
"when",
"looking",
"for",
"a",
"class",
"."
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L96-L103 |
cohesion/cohesion-core | src/Util/Autoloader.php | Autoloader.getCache | public function getCache() {
if($this->cacheBackend == null) {
$this->cacheBackend = Zend_Cache::factory('Core', 'Apc', array('automatic_serialization' => true));
}
return $this->cacheBackend;
} | php | public function getCache() {
if($this->cacheBackend == null) {
$this->cacheBackend = Zend_Cache::factory('Core', 'Apc', array('automatic_serialization' => true));
}
return $this->cacheBackend;
} | [
"public",
"function",
"getCache",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheBackend",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"cacheBackend",
"=",
"Zend_Cache",
"::",
"factory",
"(",
"'Core'",
",",
"'Apc'",
",",
"array",
"(",
"'automatic_serialization'",
"=>",
"true",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cacheBackend",
";",
"}"
] | Return caching backend used; or create new one if none already defined
(Zend_Cache_Frontend_Core with APC backend). | [
"Return",
"caching",
"backend",
"used",
";",
"or",
"create",
"new",
"one",
"if",
"none",
"already",
"defined",
"(",
"Zend_Cache_Frontend_Core",
"with",
"APC",
"backend",
")",
"."
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L123-L128 |
cohesion/cohesion-core | src/Util/Autoloader.php | Autoloader.tryAndLoadClass | protected function tryAndLoadClass($name, $list) {
if(in_array($name, array_keys($list))) {
include_once $list[$name];
if(class_exists($name) || interface_exists($name)) {
//echo "Successfully loaded $name\n";
return true;
}
}
return false;
} | php | protected function tryAndLoadClass($name, $list) {
if(in_array($name, array_keys($list))) {
include_once $list[$name];
if(class_exists($name) || interface_exists($name)) {
//echo "Successfully loaded $name\n";
return true;
}
}
return false;
} | [
"protected",
"function",
"tryAndLoadClass",
"(",
"$",
"name",
",",
"$",
"list",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"array_keys",
"(",
"$",
"list",
")",
")",
")",
"{",
"include_once",
"$",
"list",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"class_exists",
"(",
"$",
"name",
")",
"||",
"interface_exists",
"(",
"$",
"name",
")",
")",
"{",
"//echo \"Successfully loaded $name\\n\";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Given a map of class names to absolute file paths, try and load the class.
If we get to including the file, we ensure that the class_exists after doing
so, otherwise we'll return false.
Also return false if we don't know where the class ($name) could be.
@param string $name the name of the class we wish to load.
@param array $list - map of known classnames to absolute file paths. | [
"Given",
"a",
"map",
"of",
"class",
"names",
"to",
"absolute",
"file",
"paths",
"try",
"and",
"load",
"the",
"class",
".",
"If",
"we",
"get",
"to",
"including",
"the",
"file",
"we",
"ensure",
"that",
"the",
"class_exists",
"after",
"doing",
"so",
"otherwise",
"we",
"ll",
"return",
"false",
".",
"Also",
"return",
"false",
"if",
"we",
"don",
"t",
"know",
"where",
"the",
"class",
"(",
"$name",
")",
"could",
"be",
"."
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L163-L172 |
cohesion/cohesion-core | src/Util/Autoloader.php | Autoloader.loadClass | public function loadClass($className) {
$cache = $this->getCache();
$entries = $cache->load($this->cacheKey);
if($entries == false) {
$entries = array();
}
$status = $this->tryAndLoadClass($className, $entries);
if($status) {
// class loaded
return true;
}
if(preg_match($this->ignoreClassNamesRegexp, $className)) {
return false;
}
foreach($this->classPaths as $path) {
// Scan for file
$realPath = $this->searchForClassFile($className, $path);
if($realPath !== false) {
$entries[$className] = $realPath;
break;
}
}
$cache->save($entries, $this->cacheKey);
$status = $this->tryAndLoadClass($className, $entries);
return $status;
} | php | public function loadClass($className) {
$cache = $this->getCache();
$entries = $cache->load($this->cacheKey);
if($entries == false) {
$entries = array();
}
$status = $this->tryAndLoadClass($className, $entries);
if($status) {
// class loaded
return true;
}
if(preg_match($this->ignoreClassNamesRegexp, $className)) {
return false;
}
foreach($this->classPaths as $path) {
// Scan for file
$realPath = $this->searchForClassFile($className, $path);
if($realPath !== false) {
$entries[$className] = $realPath;
break;
}
}
$cache->save($entries, $this->cacheKey);
$status = $this->tryAndLoadClass($className, $entries);
return $status;
} | [
"public",
"function",
"loadClass",
"(",
"$",
"className",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
";",
"$",
"entries",
"=",
"$",
"cache",
"->",
"load",
"(",
"$",
"this",
"->",
"cacheKey",
")",
";",
"if",
"(",
"$",
"entries",
"==",
"false",
")",
"{",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"}",
"$",
"status",
"=",
"$",
"this",
"->",
"tryAndLoadClass",
"(",
"$",
"className",
",",
"$",
"entries",
")",
";",
"if",
"(",
"$",
"status",
")",
"{",
"// class loaded",
"return",
"true",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"ignoreClassNamesRegexp",
",",
"$",
"className",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"classPaths",
"as",
"$",
"path",
")",
"{",
"// Scan for file",
"$",
"realPath",
"=",
"$",
"this",
"->",
"searchForClassFile",
"(",
"$",
"className",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"realPath",
"!==",
"false",
")",
"{",
"$",
"entries",
"[",
"$",
"className",
"]",
"=",
"$",
"realPath",
";",
"break",
";",
"}",
"}",
"$",
"cache",
"->",
"save",
"(",
"$",
"entries",
",",
"$",
"this",
"->",
"cacheKey",
")",
";",
"$",
"status",
"=",
"$",
"this",
"->",
"tryAndLoadClass",
"(",
"$",
"className",
",",
"$",
"entries",
")",
";",
"return",
"$",
"status",
";",
"}"
] | Returns true if the class file was found and included, false if not.
@return boolean | [
"Returns",
"true",
"if",
"the",
"class",
"file",
"was",
"found",
"and",
"included",
"false",
"if",
"not",
"."
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L179-L205 |
cohesion/cohesion-core | src/Util/Autoloader.php | Autoloader.searchForClassFile | protected function searchForClassFile($className, $directory) {
if(is_dir($directory) && is_readable($directory)) {
$d = dir($directory);
while($f = $d->read()) {
$subPath = realpath($directory . DIRECTORY_SEPARATOR . $f);
//echo "Looking in $subPath for $className{$this->classFileSuffix}\n";
if(is_dir($subPath)) {
// Found a subdirectory
if(!preg_match($this->excludeFolderNames, $f)) {
if($filePath = $this->searchForClassFile($className, $subPath . '/')) {
return $filePath;
}
}
}
else { // it's a file... so does the name match ?
if($f == $className . $this->classFileSuffix) {
return $subPath;
}
}
}
}
return false;
} | php | protected function searchForClassFile($className, $directory) {
if(is_dir($directory) && is_readable($directory)) {
$d = dir($directory);
while($f = $d->read()) {
$subPath = realpath($directory . DIRECTORY_SEPARATOR . $f);
//echo "Looking in $subPath for $className{$this->classFileSuffix}\n";
if(is_dir($subPath)) {
// Found a subdirectory
if(!preg_match($this->excludeFolderNames, $f)) {
if($filePath = $this->searchForClassFile($className, $subPath . '/')) {
return $filePath;
}
}
}
else { // it's a file... so does the name match ?
if($f == $className . $this->classFileSuffix) {
return $subPath;
}
}
}
}
return false;
} | [
"protected",
"function",
"searchForClassFile",
"(",
"$",
"className",
",",
"$",
"directory",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"directory",
")",
"&&",
"is_readable",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"d",
"=",
"dir",
"(",
"$",
"directory",
")",
";",
"while",
"(",
"$",
"f",
"=",
"$",
"d",
"->",
"read",
"(",
")",
")",
"{",
"$",
"subPath",
"=",
"realpath",
"(",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"f",
")",
";",
"//echo \"Looking in $subPath for $className{$this->classFileSuffix}\\n\";",
"if",
"(",
"is_dir",
"(",
"$",
"subPath",
")",
")",
"{",
"// Found a subdirectory",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"this",
"->",
"excludeFolderNames",
",",
"$",
"f",
")",
")",
"{",
"if",
"(",
"$",
"filePath",
"=",
"$",
"this",
"->",
"searchForClassFile",
"(",
"$",
"className",
",",
"$",
"subPath",
".",
"'/'",
")",
")",
"{",
"return",
"$",
"filePath",
";",
"}",
"}",
"}",
"else",
"{",
"// it's a file... so does the name match ?",
"if",
"(",
"$",
"f",
"==",
"$",
"className",
".",
"$",
"this",
"->",
"classFileSuffix",
")",
"{",
"return",
"$",
"subPath",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Rummage recursively through all directories found within $directory for a
file matching ClassName.$suffix
@return string class name if one found; otherwise false. | [
"Rummage",
"recursively",
"through",
"all",
"directories",
"found",
"within",
"$directory",
"for",
"a",
"file",
"matching",
"ClassName",
".",
"$suffix"
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L212-L234 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildCreateIndex | public function buildCreateIndex(Query $query) {
return $this->renderStatement(Query::CREATE_INDEX, [
'index' => $this->formatTable($query->getAlias()),
'table' => $this->formatTable($query->getTable()),
'fields' => $this->formatFields($query)
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildCreateIndex(Query $query) {
return $this->renderStatement(Query::CREATE_INDEX, [
'index' => $this->formatTable($query->getAlias()),
'table' => $this->formatTable($query->getTable()),
'fields' => $this->formatFields($query)
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildCreateIndex",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"CREATE_INDEX",
",",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getAlias",
"(",
")",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
")",
",",
"'fields'",
"=>",
"$",
"this",
"->",
"formatFields",
"(",
"$",
"query",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the CREATE INDEX query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"CREATE",
"INDEX",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L26-L32 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildCreateTable | public function buildCreateTable(Query $query) {
$schema = $query->getSchema();
if (!$schema) {
throw new InvalidSchemaException('Table creation requires a valid schema object');
}
return $this->renderStatement(Query::CREATE_TABLE, [
'table' => $this->formatTable($schema->getTable()),
'columns' => $this->formatColumns($schema),
'keys' => $this->formatTableKeys($schema),
'options' => $this->formatTableOptions($schema->getOptions())
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildCreateTable(Query $query) {
$schema = $query->getSchema();
if (!$schema) {
throw new InvalidSchemaException('Table creation requires a valid schema object');
}
return $this->renderStatement(Query::CREATE_TABLE, [
'table' => $this->formatTable($schema->getTable()),
'columns' => $this->formatColumns($schema),
'keys' => $this->formatTableKeys($schema),
'options' => $this->formatTableOptions($schema->getOptions())
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildCreateTable",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"schema",
"=",
"$",
"query",
"->",
"getSchema",
"(",
")",
";",
"if",
"(",
"!",
"$",
"schema",
")",
"{",
"throw",
"new",
"InvalidSchemaException",
"(",
"'Table creation requires a valid schema object'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"CREATE_TABLE",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
")",
",",
"'columns'",
"=>",
"$",
"this",
"->",
"formatColumns",
"(",
"$",
"schema",
")",
",",
"'keys'",
"=>",
"$",
"this",
"->",
"formatTableKeys",
"(",
"$",
"schema",
")",
",",
"'options'",
"=>",
"$",
"this",
"->",
"formatTableOptions",
"(",
"$",
"schema",
"->",
"getOptions",
"(",
")",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the CREATE TABLE query. Requires a table schema object.
@param \Titon\Db\Query $query
@return string
@throws \Titon\Db\Exception\InvalidSchemaException | [
"Build",
"the",
"CREATE",
"TABLE",
"query",
".",
"Requires",
"a",
"table",
"schema",
"object",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L41-L54 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildDelete | public function buildDelete(Query $query) {
return $this->renderStatement(Query::DELETE, [
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimit($query->getLimit()),
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildDelete(Query $query) {
return $this->renderStatement(Query::DELETE, [
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimit($query->getLimit()),
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildDelete",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"DELETE",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
",",
"$",
"query",
"->",
"getAlias",
"(",
")",
")",
",",
"'joins'",
"=>",
"$",
"this",
"->",
"formatJoins",
"(",
"$",
"query",
"->",
"getJoins",
"(",
")",
")",
",",
"'where'",
"=>",
"$",
"this",
"->",
"formatWhere",
"(",
"$",
"query",
"->",
"getWhere",
"(",
")",
")",
",",
"'orderBy'",
"=>",
"$",
"this",
"->",
"formatOrderBy",
"(",
"$",
"query",
"->",
"getOrderBy",
"(",
")",
")",
",",
"'limit'",
"=>",
"$",
"this",
"->",
"formatLimit",
"(",
"$",
"query",
"->",
"getLimit",
"(",
")",
")",
",",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the DELETE query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"DELETE",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L62-L70 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildDropIndex | public function buildDropIndex(Query $query) {
return $this->renderStatement(Query::DROP_INDEX, [
'index' => $this->formatTable($query->getAlias()),
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildDropIndex(Query $query) {
return $this->renderStatement(Query::DROP_INDEX, [
'index' => $this->formatTable($query->getAlias()),
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildDropIndex",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"DROP_INDEX",
",",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getAlias",
"(",
")",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the DROP INDEX query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"DROP",
"INDEX",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L78-L83 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildDropTable | public function buildDropTable(Query $query) {
return $this->renderStatement(Query::DROP_TABLE, [
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildDropTable(Query $query) {
return $this->renderStatement(Query::DROP_TABLE, [
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildDropTable",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"DROP_TABLE",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the DROP TABLE query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"DROP",
"TABLE",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L91-L95 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildMultiInsert | public function buildMultiInsert(Query $query) {
return $this->renderStatement(Query::INSERT, [
'table' => $this->formatTable($query->getTable()),
'fields' => $this->formatFields($query),
'values' => $this->formatValues($query)
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildMultiInsert(Query $query) {
return $this->renderStatement(Query::INSERT, [
'table' => $this->formatTable($query->getTable()),
'fields' => $this->formatFields($query),
'values' => $this->formatValues($query)
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildMultiInsert",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"INSERT",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
")",
",",
"'fields'",
"=>",
"$",
"this",
"->",
"formatFields",
"(",
"$",
"query",
")",
",",
"'values'",
"=>",
"$",
"this",
"->",
"formatValues",
"(",
"$",
"query",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the INSERT query with multiple record support.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"INSERT",
"query",
"with",
"multiple",
"record",
"support",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L117-L123 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildSelect | public function buildSelect(Query $query) {
return $this->renderStatement(Query::SELECT, [
'fields' => $this->formatFields($query),
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'groupBy' => $this->formatGroupBy($query->getGroupBy()),
'having' => $this->formatHaving($query->getHaving()),
'compounds' => $this->formatCompounds($query->getCompounds()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimitOffset($query->getLimit(), $query->getOffset()),
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildSelect(Query $query) {
return $this->renderStatement(Query::SELECT, [
'fields' => $this->formatFields($query),
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'groupBy' => $this->formatGroupBy($query->getGroupBy()),
'having' => $this->formatHaving($query->getHaving()),
'compounds' => $this->formatCompounds($query->getCompounds()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimitOffset($query->getLimit(), $query->getOffset()),
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildSelect",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"SELECT",
",",
"[",
"'fields'",
"=>",
"$",
"this",
"->",
"formatFields",
"(",
"$",
"query",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
",",
"$",
"query",
"->",
"getAlias",
"(",
")",
")",
",",
"'joins'",
"=>",
"$",
"this",
"->",
"formatJoins",
"(",
"$",
"query",
"->",
"getJoins",
"(",
")",
")",
",",
"'where'",
"=>",
"$",
"this",
"->",
"formatWhere",
"(",
"$",
"query",
"->",
"getWhere",
"(",
")",
")",
",",
"'groupBy'",
"=>",
"$",
"this",
"->",
"formatGroupBy",
"(",
"$",
"query",
"->",
"getGroupBy",
"(",
")",
")",
",",
"'having'",
"=>",
"$",
"this",
"->",
"formatHaving",
"(",
"$",
"query",
"->",
"getHaving",
"(",
")",
")",
",",
"'compounds'",
"=>",
"$",
"this",
"->",
"formatCompounds",
"(",
"$",
"query",
"->",
"getCompounds",
"(",
")",
")",
",",
"'orderBy'",
"=>",
"$",
"this",
"->",
"formatOrderBy",
"(",
"$",
"query",
"->",
"getOrderBy",
"(",
")",
")",
",",
"'limit'",
"=>",
"$",
"this",
"->",
"formatLimitOffset",
"(",
"$",
"query",
"->",
"getLimit",
"(",
")",
",",
"$",
"query",
"->",
"getOffset",
"(",
")",
")",
",",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the SELECT query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"SELECT",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L131-L143 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildTruncate | public function buildTruncate(Query $query) {
return $this->renderStatement(Query::TRUNCATE, [
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildTruncate(Query $query) {
return $this->renderStatement(Query::TRUNCATE, [
'table' => $this->formatTable($query->getTable())
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildTruncate",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"TRUNCATE",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
")",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the TRUNCATE query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"TRUNCATE",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L151-L155 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php | AbstractPdoDialect.buildUpdate | public function buildUpdate(Query $query) {
return $this->renderStatement(Query::UPDATE, [
'fields' => $this->formatFields($query),
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimit($query->getLimit()),
] + $this->formatAttributes($query->getAttributes()));
} | php | public function buildUpdate(Query $query) {
return $this->renderStatement(Query::UPDATE, [
'fields' => $this->formatFields($query),
'table' => $this->formatTable($query->getTable(), $query->getAlias()),
'joins' => $this->formatJoins($query->getJoins()),
'where' => $this->formatWhere($query->getWhere()),
'orderBy' => $this->formatOrderBy($query->getOrderBy()),
'limit' => $this->formatLimit($query->getLimit()),
] + $this->formatAttributes($query->getAttributes()));
} | [
"public",
"function",
"buildUpdate",
"(",
"Query",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"renderStatement",
"(",
"Query",
"::",
"UPDATE",
",",
"[",
"'fields'",
"=>",
"$",
"this",
"->",
"formatFields",
"(",
"$",
"query",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"query",
"->",
"getTable",
"(",
")",
",",
"$",
"query",
"->",
"getAlias",
"(",
")",
")",
",",
"'joins'",
"=>",
"$",
"this",
"->",
"formatJoins",
"(",
"$",
"query",
"->",
"getJoins",
"(",
")",
")",
",",
"'where'",
"=>",
"$",
"this",
"->",
"formatWhere",
"(",
"$",
"query",
"->",
"getWhere",
"(",
")",
")",
",",
"'orderBy'",
"=>",
"$",
"this",
"->",
"formatOrderBy",
"(",
"$",
"query",
"->",
"getOrderBy",
"(",
")",
")",
",",
"'limit'",
"=>",
"$",
"this",
"->",
"formatLimit",
"(",
"$",
"query",
"->",
"getLimit",
"(",
")",
")",
",",
"]",
"+",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"query",
"->",
"getAttributes",
"(",
")",
")",
")",
";",
"}"
] | Build the UPDATE query.
@param \Titon\Db\Query $query
@return string | [
"Build",
"the",
"UPDATE",
"query",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L163-L172 |
whisller/IrcBotBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('whisnet_irc_bot');
$rootNode
->children()
->scalarNode('connection_class')->defaultValue('Whisnet\IrcBotBundle\Connection\Socket')->end()
->scalarNode('host')->defaultValue('irc.freenode.net')->end()
->scalarNode('port')->defaultValue('6667')->end()
->scalarNode('command_prefix')
->defaultValue('!bot')
->beforeNormalization()
->ifString()->then(function($v){ return preg_quote($v); })
->end()
->end()
->arrayNode('user')
->isRequired()
->children()
->scalarNode('username')->defaultValue('IrcBotBundle')->end()
->scalarNode('mode')->defaultValue(0)->end()
->scalarNode('realname')->defaultValue('IrcBotBundle')->end()
->end()
->end()
->arrayNode('channels')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('scalar')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('whisnet_irc_bot');
$rootNode
->children()
->scalarNode('connection_class')->defaultValue('Whisnet\IrcBotBundle\Connection\Socket')->end()
->scalarNode('host')->defaultValue('irc.freenode.net')->end()
->scalarNode('port')->defaultValue('6667')->end()
->scalarNode('command_prefix')
->defaultValue('!bot')
->beforeNormalization()
->ifString()->then(function($v){ return preg_quote($v); })
->end()
->end()
->arrayNode('user')
->isRequired()
->children()
->scalarNode('username')->defaultValue('IrcBotBundle')->end()
->scalarNode('mode')->defaultValue(0)->end()
->scalarNode('realname')->defaultValue('IrcBotBundle')->end()
->end()
->end()
->arrayNode('channels')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('scalar')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'whisnet_irc_bot'",
")",
";",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'connection_class'",
")",
"->",
"defaultValue",
"(",
"'Whisnet\\IrcBotBundle\\Connection\\Socket'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'host'",
")",
"->",
"defaultValue",
"(",
"'irc.freenode.net'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'port'",
")",
"->",
"defaultValue",
"(",
"'6667'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'command_prefix'",
")",
"->",
"defaultValue",
"(",
"'!bot'",
")",
"->",
"beforeNormalization",
"(",
")",
"->",
"ifString",
"(",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"preg_quote",
"(",
"$",
"v",
")",
";",
"}",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'user'",
")",
"->",
"isRequired",
"(",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'username'",
")",
"->",
"defaultValue",
"(",
"'IrcBotBundle'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'mode'",
")",
"->",
"defaultValue",
"(",
"0",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'realname'",
")",
"->",
"defaultValue",
"(",
"'IrcBotBundle'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'channels'",
")",
"->",
"isRequired",
"(",
")",
"->",
"requiresAtLeastOneElement",
"(",
")",
"->",
"useAttributeAsKey",
"(",
"'name'",
")",
"->",
"prototype",
"(",
"'scalar'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/whisller/IrcBotBundle/blob/d8bcafc1599cbbc7756b0a59f51ee988a2de0f2e/DependencyInjection/Configuration.php#L18-L53 |
php-rise/rise | src/Template/Blocks/Block.php | Block.extend | public function extend($template, $data = [], $paramName = 'body') {
$this->extendedTemplate = $this->resolveTemplatePath($template);
if (is_array($data)) {
$this->extendedData = $data;
}
if (is_string($paramName) && $paramName) {
$this->extendedParamName = $paramName;
}
} | php | public function extend($template, $data = [], $paramName = 'body') {
$this->extendedTemplate = $this->resolveTemplatePath($template);
if (is_array($data)) {
$this->extendedData = $data;
}
if (is_string($paramName) && $paramName) {
$this->extendedParamName = $paramName;
}
} | [
"public",
"function",
"extend",
"(",
"$",
"template",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"paramName",
"=",
"'body'",
")",
"{",
"$",
"this",
"->",
"extendedTemplate",
"=",
"$",
"this",
"->",
"resolveTemplatePath",
"(",
"$",
"template",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"extendedData",
"=",
"$",
"data",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"paramName",
")",
"&&",
"$",
"paramName",
")",
"{",
"$",
"this",
"->",
"extendedParamName",
"=",
"$",
"paramName",
";",
"}",
"}"
] | Set extended template and data.
@param string $template
@param array $data Optional.
@param string $paramName Optional. Variable name of the variable storing the content of this block, default to "body". | [
"Set",
"extended",
"template",
"and",
"data",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L111-L119 |
php-rise/rise | src/Template/Blocks/Block.php | Block.translate | public function translate($key, $defaultValue = '', $locale = null) {
return $this->translation->translate($key, $defaultValue, $locale);
} | php | public function translate($key, $defaultValue = '', $locale = null) {
return $this->translation->translate($key, $defaultValue, $locale);
} | [
"public",
"function",
"translate",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"''",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"translation",
"->",
"translate",
"(",
"$",
"key",
",",
"$",
"defaultValue",
",",
"$",
"locale",
")",
";",
"}"
] | Helper function for translation.
@param string $key
@param string $defaultValue
@param string $locale
@return string | [
"Helper",
"function",
"for",
"translation",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L176-L178 |
php-rise/rise | src/Template/Blocks/Block.php | Block.render | public function render() {
$html = $this->renderToHtml();
if (!empty($this->extendedTemplate)) {
$data = [$this->extendedParamName => $html] + $this->extendedData + $this->data;
$html = $this->templateService->render($this->extendedTemplate, $data);
}
return $html;
} | php | public function render() {
$html = $this->renderToHtml();
if (!empty($this->extendedTemplate)) {
$data = [$this->extendedParamName => $html] + $this->extendedData + $this->data;
$html = $this->templateService->render($this->extendedTemplate, $data);
}
return $html;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"renderToHtml",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"extendedTemplate",
")",
")",
"{",
"$",
"data",
"=",
"[",
"$",
"this",
"->",
"extendedParamName",
"=>",
"$",
"html",
"]",
"+",
"$",
"this",
"->",
"extendedData",
"+",
"$",
"this",
"->",
"data",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"templateService",
"->",
"render",
"(",
"$",
"this",
"->",
"extendedTemplate",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Render a template.
@return self | [
"Render",
"a",
"template",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L185-L194 |
php-rise/rise | src/Template/Blocks/Block.php | Block.resolveTemplatePath | protected function resolveTemplatePath($path) {
switch ($path[0]) {
case '/':
break;
case '.':
$path = realpath(dirname($this->template) . '/' . $path . '.phtml');
break;
default:
$path = realpath($this->pathService->getTemplatesPath() . '/' . $path . '.phtml');
break;
}
if ($path === false) {
throw new NotFoundException($this->template . ' file not found');
}
return $path;
} | php | protected function resolveTemplatePath($path) {
switch ($path[0]) {
case '/':
break;
case '.':
$path = realpath(dirname($this->template) . '/' . $path . '.phtml');
break;
default:
$path = realpath($this->pathService->getTemplatesPath() . '/' . $path . '.phtml');
break;
}
if ($path === false) {
throw new NotFoundException($this->template . ' file not found');
}
return $path;
} | [
"protected",
"function",
"resolveTemplatePath",
"(",
"$",
"path",
")",
"{",
"switch",
"(",
"$",
"path",
"[",
"0",
"]",
")",
"{",
"case",
"'/'",
":",
"break",
";",
"case",
"'.'",
":",
"$",
"path",
"=",
"realpath",
"(",
"dirname",
"(",
"$",
"this",
"->",
"template",
")",
".",
"'/'",
".",
"$",
"path",
".",
"'.phtml'",
")",
";",
"break",
";",
"default",
":",
"$",
"path",
"=",
"realpath",
"(",
"$",
"this",
"->",
"pathService",
"->",
"getTemplatesPath",
"(",
")",
".",
"'/'",
".",
"$",
"path",
".",
"'.phtml'",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"path",
"===",
"false",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"$",
"this",
"->",
"template",
".",
"' file not found'",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Resolve template path.
@param string $path
@return string | [
"Resolve",
"template",
"path",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L222-L239 |
php-rise/rise | src/Template/Blocks/Block.php | Block.renderToHtml | protected function renderToHtml() {
extract($this->data, EXTR_SKIP);
ob_start();
set_error_handler([$this, 'handleError']);
include $this->template;
restore_error_handler();
$html = ob_get_clean();
return $html;
} | php | protected function renderToHtml() {
extract($this->data, EXTR_SKIP);
ob_start();
set_error_handler([$this, 'handleError']);
include $this->template;
restore_error_handler();
$html = ob_get_clean();
return $html;
} | [
"protected",
"function",
"renderToHtml",
"(",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"data",
",",
"EXTR_SKIP",
")",
";",
"ob_start",
"(",
")",
";",
"set_error_handler",
"(",
"[",
"$",
"this",
",",
"'handleError'",
"]",
")",
";",
"include",
"$",
"this",
"->",
"template",
";",
"restore_error_handler",
"(",
")",
";",
"$",
"html",
"=",
"ob_get_clean",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] | Render this block to HTML string.
@return string | [
"Render",
"this",
"block",
"to",
"HTML",
"string",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L246-L254 |
php-rise/rise | src/Template/Blocks/Block.php | Block.handleError | protected function handleError($errno, $errstr, $errfile, $errline) {
ob_end_clean();
throw new BlockException($errstr, 0, $errno, $errfile, $errline);
} | php | protected function handleError($errno, $errstr, $errfile, $errline) {
ob_end_clean();
throw new BlockException($errstr, 0, $errno, $errfile, $errline);
} | [
"protected",
"function",
"handleError",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"throw",
"new",
"BlockException",
"(",
"$",
"errstr",
",",
"0",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"}"
] | Error handler. | [
"Error",
"handler",
"."
] | train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L259-L262 |
OwlyCode/StreamingBird | src/StreamReader.php | StreamReader.consume | public function consume(callable $handler)
{
$this->running = true;
while ($this->running) {
$this->consumeOnce($handler);
}
} | php | public function consume(callable $handler)
{
$this->running = true;
while ($this->running) {
$this->consumeOnce($handler);
}
} | [
"public",
"function",
"consume",
"(",
"callable",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"running",
"=",
"true",
";",
"while",
"(",
"$",
"this",
"->",
"running",
")",
"{",
"$",
"this",
"->",
"consumeOnce",
"(",
"$",
"handler",
")",
";",
"}",
"}"
] | Consume from the streaming API.
Will retry on any connection loss.
@param callable $handler | [
"Consume",
"from",
"the",
"streaming",
"API",
"."
] | train | https://github.com/OwlyCode/StreamingBird/blob/177fc8a9dc8f911865a5abd9ac8d4ef85cef4003/src/StreamReader.php#L86-L93 |
OwlyCode/StreamingBird | src/StreamReader.php | StreamReader.consumeOnce | protected function consumeOnce(callable $handler)
{
$this->connection = $this->connect();
$lastStreamActivity = time();
$this->connection->read(function ($tweet) use (&$lastStreamActivity, $handler) {
$idle = (time() - $lastStreamActivity);
$this->monitor->stat('max_idle_time', $idle);
$this->monitor->stat('idle_time', $idle);
$this->monitor->stat('tweets', 1);
$lastStreamActivity = time();
call_user_func($handler, $tweet, $this->monitor);
});
$this->connection->close();
} | php | protected function consumeOnce(callable $handler)
{
$this->connection = $this->connect();
$lastStreamActivity = time();
$this->connection->read(function ($tweet) use (&$lastStreamActivity, $handler) {
$idle = (time() - $lastStreamActivity);
$this->monitor->stat('max_idle_time', $idle);
$this->monitor->stat('idle_time', $idle);
$this->monitor->stat('tweets', 1);
$lastStreamActivity = time();
call_user_func($handler, $tweet, $this->monitor);
});
$this->connection->close();
} | [
"protected",
"function",
"consumeOnce",
"(",
"callable",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"lastStreamActivity",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"read",
"(",
"function",
"(",
"$",
"tweet",
")",
"use",
"(",
"&",
"$",
"lastStreamActivity",
",",
"$",
"handler",
")",
"{",
"$",
"idle",
"=",
"(",
"time",
"(",
")",
"-",
"$",
"lastStreamActivity",
")",
";",
"$",
"this",
"->",
"monitor",
"->",
"stat",
"(",
"'max_idle_time'",
",",
"$",
"idle",
")",
";",
"$",
"this",
"->",
"monitor",
"->",
"stat",
"(",
"'idle_time'",
",",
"$",
"idle",
")",
";",
"$",
"this",
"->",
"monitor",
"->",
"stat",
"(",
"'tweets'",
",",
"1",
")",
";",
"$",
"lastStreamActivity",
"=",
"time",
"(",
")",
";",
"call_user_func",
"(",
"$",
"handler",
",",
"$",
"tweet",
",",
"$",
"this",
"->",
"monitor",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"close",
"(",
")",
";",
"}"
] | Consume from the streaming API.
Will not retry on connection loss.
@param callable $handler | [
"Consume",
"from",
"the",
"streaming",
"API",
"."
] | train | https://github.com/OwlyCode/StreamingBird/blob/177fc8a9dc8f911865a5abd9ac8d4ef85cef4003/src/StreamReader.php#L108-L127 |
OwlyCode/StreamingBird | src/StreamReader.php | StreamReader.connect | protected function connect($timeout = 5, $attempts = 10)
{
$url = $this->endpoints[$this->method];
$urlParts = parse_url($url);
$scheme = $urlParts['scheme'] == 'https' ? 'ssl://' : 'tcp://';
$port = $urlParts['scheme'] == 'https' ? 443 : 80;
$requestParams = [];
if ($this->lang) {
$requestParams['language'] = $this->lang;
}
if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_USER) && count($this->trackWords) > 0) {
$requestParams['track'] = implode(',', $this->trackWords);
}
if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_SITE) && count($this->followIds) > 0) {
$requestParams['follow'] = implode(',', $this->followIds);
}
if ($this->method === self::METHOD_FILTER && $this->location) {
$requestParams['locations'] = implode(',', $this->location->getBoundingBox());
}
if ($this->count <> 0) {
$requestParams['count'] = $this->count;
}
$this->connection->open($scheme . $urlParts['host'], $port, $timeout, $attempts);
$this->connection->authenticate($url, $requestParams, $this->oauth->getAuthorizationHeader($url, $requestParams));
return $this->connection;
} | php | protected function connect($timeout = 5, $attempts = 10)
{
$url = $this->endpoints[$this->method];
$urlParts = parse_url($url);
$scheme = $urlParts['scheme'] == 'https' ? 'ssl://' : 'tcp://';
$port = $urlParts['scheme'] == 'https' ? 443 : 80;
$requestParams = [];
if ($this->lang) {
$requestParams['language'] = $this->lang;
}
if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_USER) && count($this->trackWords) > 0) {
$requestParams['track'] = implode(',', $this->trackWords);
}
if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_SITE) && count($this->followIds) > 0) {
$requestParams['follow'] = implode(',', $this->followIds);
}
if ($this->method === self::METHOD_FILTER && $this->location) {
$requestParams['locations'] = implode(',', $this->location->getBoundingBox());
}
if ($this->count <> 0) {
$requestParams['count'] = $this->count;
}
$this->connection->open($scheme . $urlParts['host'], $port, $timeout, $attempts);
$this->connection->authenticate($url, $requestParams, $this->oauth->getAuthorizationHeader($url, $requestParams));
return $this->connection;
} | [
"protected",
"function",
"connect",
"(",
"$",
"timeout",
"=",
"5",
",",
"$",
"attempts",
"=",
"10",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"endpoints",
"[",
"$",
"this",
"->",
"method",
"]",
";",
"$",
"urlParts",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"scheme",
"=",
"$",
"urlParts",
"[",
"'scheme'",
"]",
"==",
"'https'",
"?",
"'ssl://'",
":",
"'tcp://'",
";",
"$",
"port",
"=",
"$",
"urlParts",
"[",
"'scheme'",
"]",
"==",
"'https'",
"?",
"443",
":",
"80",
";",
"$",
"requestParams",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"lang",
")",
"{",
"$",
"requestParams",
"[",
"'language'",
"]",
"=",
"$",
"this",
"->",
"lang",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_FILTER",
"||",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_USER",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"trackWords",
")",
">",
"0",
")",
"{",
"$",
"requestParams",
"[",
"'track'",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"trackWords",
")",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_FILTER",
"||",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_SITE",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"followIds",
")",
">",
"0",
")",
"{",
"$",
"requestParams",
"[",
"'follow'",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"followIds",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_FILTER",
"&&",
"$",
"this",
"->",
"location",
")",
"{",
"$",
"requestParams",
"[",
"'locations'",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"location",
"->",
"getBoundingBox",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"count",
"<>",
"0",
")",
"{",
"$",
"requestParams",
"[",
"'count'",
"]",
"=",
"$",
"this",
"->",
"count",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"open",
"(",
"$",
"scheme",
".",
"$",
"urlParts",
"[",
"'host'",
"]",
",",
"$",
"port",
",",
"$",
"timeout",
",",
"$",
"attempts",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"authenticate",
"(",
"$",
"url",
",",
"$",
"requestParams",
",",
"$",
"this",
"->",
"oauth",
"->",
"getAuthorizationHeader",
"(",
"$",
"url",
",",
"$",
"requestParams",
")",
")",
";",
"return",
"$",
"this",
"->",
"connection",
";",
"}"
] | @param int $timeout
@param int $attempts
@return Connection | [
"@param",
"int",
"$timeout",
"@param",
"int",
"$attempts"
] | train | https://github.com/OwlyCode/StreamingBird/blob/177fc8a9dc8f911865a5abd9ac8d4ef85cef4003/src/StreamReader.php#L135-L167 |
Ocramius/OcraDiCompiler | src/OcraDiCompiler/Generator/DiProxyGenerator.php | DiProxyGenerator.compile | public function compile()
{
$indent = ' ';
$caseStatements = array();
$getters = array();
$instances = $this->dumper->getAllInjectedDefinitions();
/* @var $instance GeneratorInstance */
foreach ($instances as $name => $instance) {
$getter = $this->normalizeAlias($name);
$constructor = $instance->getConstructor();
$instantiatorParams = $this->buildParams($instance->getParams());
if ('__construct' !== $constructor) {
// Constructor callback
if (is_callable($constructor)) {
$callback = $constructor;
if (is_array($callback)) {
$class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
$method = $callback[1];
} elseif (is_string($callback) && strpos($callback, '::') !== false) {
list($class, $method) = explode('::', $callback, 2);
}
$callback = var_export(array($class, $method), true);
if (count($instantiatorParams)) {
$creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = call_user_func(%s);', $callback);
}
} else if (is_string($constructor) && strpos($constructor, '->') !== false) {
list($class, $method) = explode('->', $constructor, 2);
if (!class_exists($class)) {
throw new InvalidArgumentException('No class found: ' . $class);
}
$factoryGetter = $this->normalizeAlias($class);
if (count($instantiatorParams)) {
$creation = sprintf('$object = $this->' . $factoryGetter . '()->%s(%s);', $method, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = $this->' . $factoryGetter . '()->%s();', $method);
}
} else {
throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
}
} else {
$className = '\\' . trim($this->reduceAlias($name), '\\');
if (count($instantiatorParams)) {
$creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = new %s();', $className);
}
}
// Create method call code
if ($instance->isShared()) {
$creation .= "\n\nif (\$isShared) {\n" . $indent
. '$this->instanceManager->addSharedInstance($object, \'' . $instance->getName() . '\');'
. "\n}\n";
}
$methods = '';
foreach ($instance->getMethods() as $methodData) {
$methodName = $methodData['method'];
$methodParams = $methodData['params'];
// Create method parameter representation
$params = $this->buildParams($methodParams);
if (count($params)) {
$methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
}
}
$storage = '';
// Start creating getter
$getterBody = '';
// Creation and method calls
$getterBody .= sprintf("%s\n", $creation);
$getterBody .= $methods;
// Stored service
$getterBody .= $storage;
// End getter body
$getterBody .= "return \$object;\n";
$getterDef = new MethodGenerator();
$getterDef->setName($getter);
$getterDef->setParameter('isShared');
$getterDef->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
$getterDef->setBody($getterBody);
$getters[] = $getterDef;
// Build case statement and store
$statement = '';
$statement .= sprintf("%scase '%s':\n", $indent, $name);
$statement .= sprintf("%sreturn \$this->%s(%s);\n", str_repeat($indent, 2), $getter, '$isShared');
$caseStatements[] = $statement;
}
// Build switch statement
$switch = sprintf(
"if (%s) {\n%sreturn parent::newInstance(%s, %s, %s);\n}\n",
'$params',
$indent,
'$name',
'$params',
'$isShared'
);
$switch .= sprintf(
"switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements)
);
$switch .= sprintf(
"%sdefault:\n%sreturn parent::newInstance(%s, %s, %s);\n",
$indent,
str_repeat($indent, 2),
'$name',
'$params',
'$isShared'
);
$switch .= "}\n\n";
// Build newInstance() method
$nameParam = new ParameterGenerator();
$nameParam->setName('name');
$paramsParam = new ParameterGenerator();
$paramsParam
->setName('params')
->setType('array')
->setDefaultValue(array());
$isSharedParam = new ParameterGenerator();
$isSharedParam
->setName('isShared')
->setDefaultValue(true);
$get = new MethodGenerator();
$get->setName('newInstance');
$get->setParameters(array(
$nameParam,
$paramsParam,
$isSharedParam,
));
$get->setBody($switch);
// Create class code generation object
$container = $this->getClassGenerator();
$container
->setName($this->containerClass)
->setExtendedClass('Di')
->addMethods(array($get))
->addMEthods($getters);
// Create PHP file code generation object
$classFile = $this->getFileGenerator();
$classFile->setClass($container);
$classFile->setUse('Zend\Di\Di');
if (null !== $this->namespace) {
$classFile->setNamespace($this->namespace);
}
return $classFile;
} | php | public function compile()
{
$indent = ' ';
$caseStatements = array();
$getters = array();
$instances = $this->dumper->getAllInjectedDefinitions();
/* @var $instance GeneratorInstance */
foreach ($instances as $name => $instance) {
$getter = $this->normalizeAlias($name);
$constructor = $instance->getConstructor();
$instantiatorParams = $this->buildParams($instance->getParams());
if ('__construct' !== $constructor) {
// Constructor callback
if (is_callable($constructor)) {
$callback = $constructor;
if (is_array($callback)) {
$class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
$method = $callback[1];
} elseif (is_string($callback) && strpos($callback, '::') !== false) {
list($class, $method) = explode('::', $callback, 2);
}
$callback = var_export(array($class, $method), true);
if (count($instantiatorParams)) {
$creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = call_user_func(%s);', $callback);
}
} else if (is_string($constructor) && strpos($constructor, '->') !== false) {
list($class, $method) = explode('->', $constructor, 2);
if (!class_exists($class)) {
throw new InvalidArgumentException('No class found: ' . $class);
}
$factoryGetter = $this->normalizeAlias($class);
if (count($instantiatorParams)) {
$creation = sprintf('$object = $this->' . $factoryGetter . '()->%s(%s);', $method, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = $this->' . $factoryGetter . '()->%s();', $method);
}
} else {
throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
}
} else {
$className = '\\' . trim($this->reduceAlias($name), '\\');
if (count($instantiatorParams)) {
$creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
} else {
$creation = sprintf('$object = new %s();', $className);
}
}
// Create method call code
if ($instance->isShared()) {
$creation .= "\n\nif (\$isShared) {\n" . $indent
. '$this->instanceManager->addSharedInstance($object, \'' . $instance->getName() . '\');'
. "\n}\n";
}
$methods = '';
foreach ($instance->getMethods() as $methodData) {
$methodName = $methodData['method'];
$methodParams = $methodData['params'];
// Create method parameter representation
$params = $this->buildParams($methodParams);
if (count($params)) {
$methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
}
}
$storage = '';
// Start creating getter
$getterBody = '';
// Creation and method calls
$getterBody .= sprintf("%s\n", $creation);
$getterBody .= $methods;
// Stored service
$getterBody .= $storage;
// End getter body
$getterBody .= "return \$object;\n";
$getterDef = new MethodGenerator();
$getterDef->setName($getter);
$getterDef->setParameter('isShared');
$getterDef->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
$getterDef->setBody($getterBody);
$getters[] = $getterDef;
// Build case statement and store
$statement = '';
$statement .= sprintf("%scase '%s':\n", $indent, $name);
$statement .= sprintf("%sreturn \$this->%s(%s);\n", str_repeat($indent, 2), $getter, '$isShared');
$caseStatements[] = $statement;
}
// Build switch statement
$switch = sprintf(
"if (%s) {\n%sreturn parent::newInstance(%s, %s, %s);\n}\n",
'$params',
$indent,
'$name',
'$params',
'$isShared'
);
$switch .= sprintf(
"switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements)
);
$switch .= sprintf(
"%sdefault:\n%sreturn parent::newInstance(%s, %s, %s);\n",
$indent,
str_repeat($indent, 2),
'$name',
'$params',
'$isShared'
);
$switch .= "}\n\n";
// Build newInstance() method
$nameParam = new ParameterGenerator();
$nameParam->setName('name');
$paramsParam = new ParameterGenerator();
$paramsParam
->setName('params')
->setType('array')
->setDefaultValue(array());
$isSharedParam = new ParameterGenerator();
$isSharedParam
->setName('isShared')
->setDefaultValue(true);
$get = new MethodGenerator();
$get->setName('newInstance');
$get->setParameters(array(
$nameParam,
$paramsParam,
$isSharedParam,
));
$get->setBody($switch);
// Create class code generation object
$container = $this->getClassGenerator();
$container
->setName($this->containerClass)
->setExtendedClass('Di')
->addMethods(array($get))
->addMEthods($getters);
// Create PHP file code generation object
$classFile = $this->getFileGenerator();
$classFile->setClass($container);
$classFile->setUse('Zend\Di\Di');
if (null !== $this->namespace) {
$classFile->setNamespace($this->namespace);
}
return $classFile;
} | [
"public",
"function",
"compile",
"(",
")",
"{",
"$",
"indent",
"=",
"' '",
";",
"$",
"caseStatements",
"=",
"array",
"(",
")",
";",
"$",
"getters",
"=",
"array",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"dumper",
"->",
"getAllInjectedDefinitions",
"(",
")",
";",
"/* @var $instance GeneratorInstance */",
"foreach",
"(",
"$",
"instances",
"as",
"$",
"name",
"=>",
"$",
"instance",
")",
"{",
"$",
"getter",
"=",
"$",
"this",
"->",
"normalizeAlias",
"(",
"$",
"name",
")",
";",
"$",
"constructor",
"=",
"$",
"instance",
"->",
"getConstructor",
"(",
")",
";",
"$",
"instantiatorParams",
"=",
"$",
"this",
"->",
"buildParams",
"(",
"$",
"instance",
"->",
"getParams",
"(",
")",
")",
";",
"if",
"(",
"'__construct'",
"!==",
"$",
"constructor",
")",
"{",
"// Constructor callback",
"if",
"(",
"is_callable",
"(",
"$",
"constructor",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"constructor",
";",
"if",
"(",
"is_array",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"class",
"=",
"(",
"is_object",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
")",
"?",
"get_class",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
":",
"$",
"callback",
"[",
"0",
"]",
";",
"$",
"method",
"=",
"$",
"callback",
"[",
"1",
"]",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"callback",
")",
"&&",
"strpos",
"(",
"$",
"callback",
",",
"'::'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"callback",
",",
"2",
")",
";",
"}",
"$",
"callback",
"=",
"var_export",
"(",
"array",
"(",
"$",
"class",
",",
"$",
"method",
")",
",",
"true",
")",
";",
"if",
"(",
"count",
"(",
"$",
"instantiatorParams",
")",
")",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = call_user_func(%s, %s);'",
",",
"$",
"callback",
",",
"implode",
"(",
"', '",
",",
"$",
"instantiatorParams",
")",
")",
";",
"}",
"else",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = call_user_func(%s);'",
",",
"$",
"callback",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"constructor",
")",
"&&",
"strpos",
"(",
"$",
"constructor",
",",
"'->'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'->'",
",",
"$",
"constructor",
",",
"2",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'No class found: '",
".",
"$",
"class",
")",
";",
"}",
"$",
"factoryGetter",
"=",
"$",
"this",
"->",
"normalizeAlias",
"(",
"$",
"class",
")",
";",
"if",
"(",
"count",
"(",
"$",
"instantiatorParams",
")",
")",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = $this->'",
".",
"$",
"factoryGetter",
".",
"'()->%s(%s);'",
",",
"$",
"method",
",",
"implode",
"(",
"', '",
",",
"$",
"instantiatorParams",
")",
")",
";",
"}",
"else",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = $this->'",
".",
"$",
"factoryGetter",
".",
"'()->%s();'",
",",
"$",
"method",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid instantiator supplied for class: '",
".",
"$",
"name",
")",
";",
"}",
"}",
"else",
"{",
"$",
"className",
"=",
"'\\\\'",
".",
"trim",
"(",
"$",
"this",
"->",
"reduceAlias",
"(",
"$",
"name",
")",
",",
"'\\\\'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"instantiatorParams",
")",
")",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = new %s(%s);'",
",",
"$",
"className",
",",
"implode",
"(",
"', '",
",",
"$",
"instantiatorParams",
")",
")",
";",
"}",
"else",
"{",
"$",
"creation",
"=",
"sprintf",
"(",
"'$object = new %s();'",
",",
"$",
"className",
")",
";",
"}",
"}",
"// Create method call code",
"if",
"(",
"$",
"instance",
"->",
"isShared",
"(",
")",
")",
"{",
"$",
"creation",
".=",
"\"\\n\\nif (\\$isShared) {\\n\"",
".",
"$",
"indent",
".",
"'$this->instanceManager->addSharedInstance($object, \\''",
".",
"$",
"instance",
"->",
"getName",
"(",
")",
".",
"'\\');'",
".",
"\"\\n}\\n\"",
";",
"}",
"$",
"methods",
"=",
"''",
";",
"foreach",
"(",
"$",
"instance",
"->",
"getMethods",
"(",
")",
"as",
"$",
"methodData",
")",
"{",
"$",
"methodName",
"=",
"$",
"methodData",
"[",
"'method'",
"]",
";",
"$",
"methodParams",
"=",
"$",
"methodData",
"[",
"'params'",
"]",
";",
"// Create method parameter representation",
"$",
"params",
"=",
"$",
"this",
"->",
"buildParams",
"(",
"$",
"methodParams",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
")",
"{",
"$",
"methods",
".=",
"sprintf",
"(",
"\"\\$object->%s(%s);\\n\"",
",",
"$",
"methodName",
",",
"implode",
"(",
"', '",
",",
"$",
"params",
")",
")",
";",
"}",
"}",
"$",
"storage",
"=",
"''",
";",
"// Start creating getter",
"$",
"getterBody",
"=",
"''",
";",
"// Creation and method calls",
"$",
"getterBody",
".=",
"sprintf",
"(",
"\"%s\\n\"",
",",
"$",
"creation",
")",
";",
"$",
"getterBody",
".=",
"$",
"methods",
";",
"// Stored service",
"$",
"getterBody",
".=",
"$",
"storage",
";",
"// End getter body",
"$",
"getterBody",
".=",
"\"return \\$object;\\n\"",
";",
"$",
"getterDef",
"=",
"new",
"MethodGenerator",
"(",
")",
";",
"$",
"getterDef",
"->",
"setName",
"(",
"$",
"getter",
")",
";",
"$",
"getterDef",
"->",
"setParameter",
"(",
"'isShared'",
")",
";",
"$",
"getterDef",
"->",
"setVisibility",
"(",
"MethodGenerator",
"::",
"VISIBILITY_PROTECTED",
")",
";",
"$",
"getterDef",
"->",
"setBody",
"(",
"$",
"getterBody",
")",
";",
"$",
"getters",
"[",
"]",
"=",
"$",
"getterDef",
";",
"// Build case statement and store",
"$",
"statement",
"=",
"''",
";",
"$",
"statement",
".=",
"sprintf",
"(",
"\"%scase '%s':\\n\"",
",",
"$",
"indent",
",",
"$",
"name",
")",
";",
"$",
"statement",
".=",
"sprintf",
"(",
"\"%sreturn \\$this->%s(%s);\\n\"",
",",
"str_repeat",
"(",
"$",
"indent",
",",
"2",
")",
",",
"$",
"getter",
",",
"'$isShared'",
")",
";",
"$",
"caseStatements",
"[",
"]",
"=",
"$",
"statement",
";",
"}",
"// Build switch statement",
"$",
"switch",
"=",
"sprintf",
"(",
"\"if (%s) {\\n%sreturn parent::newInstance(%s, %s, %s);\\n}\\n\"",
",",
"'$params'",
",",
"$",
"indent",
",",
"'$name'",
",",
"'$params'",
",",
"'$isShared'",
")",
";",
"$",
"switch",
".=",
"sprintf",
"(",
"\"switch (%s) {\\n%s\\n\"",
",",
"'$name'",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"caseStatements",
")",
")",
";",
"$",
"switch",
".=",
"sprintf",
"(",
"\"%sdefault:\\n%sreturn parent::newInstance(%s, %s, %s);\\n\"",
",",
"$",
"indent",
",",
"str_repeat",
"(",
"$",
"indent",
",",
"2",
")",
",",
"'$name'",
",",
"'$params'",
",",
"'$isShared'",
")",
";",
"$",
"switch",
".=",
"\"}\\n\\n\"",
";",
"// Build newInstance() method",
"$",
"nameParam",
"=",
"new",
"ParameterGenerator",
"(",
")",
";",
"$",
"nameParam",
"->",
"setName",
"(",
"'name'",
")",
";",
"$",
"paramsParam",
"=",
"new",
"ParameterGenerator",
"(",
")",
";",
"$",
"paramsParam",
"->",
"setName",
"(",
"'params'",
")",
"->",
"setType",
"(",
"'array'",
")",
"->",
"setDefaultValue",
"(",
"array",
"(",
")",
")",
";",
"$",
"isSharedParam",
"=",
"new",
"ParameterGenerator",
"(",
")",
";",
"$",
"isSharedParam",
"->",
"setName",
"(",
"'isShared'",
")",
"->",
"setDefaultValue",
"(",
"true",
")",
";",
"$",
"get",
"=",
"new",
"MethodGenerator",
"(",
")",
";",
"$",
"get",
"->",
"setName",
"(",
"'newInstance'",
")",
";",
"$",
"get",
"->",
"setParameters",
"(",
"array",
"(",
"$",
"nameParam",
",",
"$",
"paramsParam",
",",
"$",
"isSharedParam",
",",
")",
")",
";",
"$",
"get",
"->",
"setBody",
"(",
"$",
"switch",
")",
";",
"// Create class code generation object",
"$",
"container",
"=",
"$",
"this",
"->",
"getClassGenerator",
"(",
")",
";",
"$",
"container",
"->",
"setName",
"(",
"$",
"this",
"->",
"containerClass",
")",
"->",
"setExtendedClass",
"(",
"'Di'",
")",
"->",
"addMethods",
"(",
"array",
"(",
"$",
"get",
")",
")",
"->",
"addMEthods",
"(",
"$",
"getters",
")",
";",
"// Create PHP file code generation object",
"$",
"classFile",
"=",
"$",
"this",
"->",
"getFileGenerator",
"(",
")",
";",
"$",
"classFile",
"->",
"setClass",
"(",
"$",
"container",
")",
";",
"$",
"classFile",
"->",
"setUse",
"(",
"'Zend\\Di\\Di'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"namespace",
")",
"{",
"$",
"classFile",
"->",
"setNamespace",
"(",
"$",
"this",
"->",
"namespace",
")",
";",
"}",
"return",
"$",
"classFile",
";",
"}"
] | Compiles a Di Definitions to a in a service locator, that extends Zend\Di\Di and writes it to disk
It uses Zend\Code\Generator\FileGenerator
@return FileGenerator
@throws InvalidArgumentException | [
"Compiles",
"a",
"Di",
"Definitions",
"to",
"a",
"in",
"a",
"service",
"locator",
"that",
"extends",
"Zend",
"\\",
"Di",
"\\",
"Di",
"and",
"writes",
"it",
"to",
"disk"
] | train | https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Generator/DiProxyGenerator.php#L176-L350 |
Ocramius/OcraDiCompiler | src/OcraDiCompiler/Generator/DiProxyGenerator.php | DiProxyGenerator.normalizeAlias | protected function normalizeAlias($alias)
{
$normalized = preg_replace('/[^a-zA-Z0-9]/', ' ', $alias);
$normalized = 'new' . str_replace(' ', '', ucwords($normalized));
return $normalized;
} | php | protected function normalizeAlias($alias)
{
$normalized = preg_replace('/[^a-zA-Z0-9]/', ' ', $alias);
$normalized = 'new' . str_replace(' ', '', ucwords($normalized));
return $normalized;
} | [
"protected",
"function",
"normalizeAlias",
"(",
"$",
"alias",
")",
"{",
"$",
"normalized",
"=",
"preg_replace",
"(",
"'/[^a-zA-Z0-9]/'",
",",
"' '",
",",
"$",
"alias",
")",
";",
"$",
"normalized",
"=",
"'new'",
".",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"$",
"normalized",
")",
")",
";",
"return",
"$",
"normalized",
";",
"}"
] | Normalize an alias to a new instance method name
@param string $alias
@return string | [
"Normalize",
"an",
"alias",
"to",
"a",
"new",
"instance",
"method",
"name"
] | train | https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Generator/DiProxyGenerator.php#L375-L380 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Style.php | Style.addStyleId | public function addStyleId($styleId)
{
$styleId = (string)$styleId;
if (!in_array($styleId, $this->styleIds)) {
array_push($this->styleIds, $styleId);
}
return $this;
} | php | public function addStyleId($styleId)
{
$styleId = (string)$styleId;
if (!in_array($styleId, $this->styleIds)) {
array_push($this->styleIds, $styleId);
}
return $this;
} | [
"public",
"function",
"addStyleId",
"(",
"$",
"styleId",
")",
"{",
"$",
"styleId",
"=",
"(",
"string",
")",
"$",
"styleId",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"styleId",
",",
"$",
"this",
"->",
"styleIds",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"styleIds",
",",
"$",
"styleId",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add style Id
@api
@param string $styleId Style Id
@return static | [
"Add",
"style",
"Id"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Style.php#L114-L121 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Style.php | Style.addStyleClass | public function addStyleClass($styleClass)
{
$styleClass = (string)$styleClass;
if (!in_array($styleClass, $this->styleClasses)) {
array_push($this->styleClasses, $styleClass);
}
return $this;
} | php | public function addStyleClass($styleClass)
{
$styleClass = (string)$styleClass;
if (!in_array($styleClass, $this->styleClasses)) {
array_push($this->styleClasses, $styleClass);
}
return $this;
} | [
"public",
"function",
"addStyleClass",
"(",
"$",
"styleClass",
")",
"{",
"$",
"styleClass",
"=",
"(",
"string",
")",
"$",
"styleClass",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"styleClass",
",",
"$",
"this",
"->",
"styleClasses",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"styleClasses",
",",
"$",
"styleClass",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add style class
@api
@param string $styleClass Style class
@return static | [
"Add",
"style",
"class"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Style.php#L193-L200 |
webforge-labs/psc-cms | lib/Psc/Code/MultiValueCounter.php | MultiValueCounter.& | public function &c() {
$args = func_get_args();
if (count($args) > $this->argsCount) {
$rel = array_pop($args); // rel ist übergeben worden
} else {
$rel = 0;
}
for ($i=0; $i < $this->argsCount; $i++) {
$this->values[$i][] = $args[$i];
}
$key = $this->getKey($args);
if (!array_key_exists($key,$this->counts)) {
$this->counts[$key] = $this->initCount;
}
$ref =& $this->counts[$key];
$ref += $rel;
return $ref;
} | php | public function &c() {
$args = func_get_args();
if (count($args) > $this->argsCount) {
$rel = array_pop($args); // rel ist übergeben worden
} else {
$rel = 0;
}
for ($i=0; $i < $this->argsCount; $i++) {
$this->values[$i][] = $args[$i];
}
$key = $this->getKey($args);
if (!array_key_exists($key,$this->counts)) {
$this->counts[$key] = $this->initCount;
}
$ref =& $this->counts[$key];
$ref += $rel;
return $ref;
} | [
"public",
"function",
"&",
"c",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"$",
"this",
"->",
"argsCount",
")",
"{",
"$",
"rel",
"=",
"array_pop",
"(",
"$",
"args",
")",
";",
"// rel ist übergeben worden",
"}",
"else",
"{",
"$",
"rel",
"=",
"0",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"argsCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"i",
"]",
"[",
"]",
"=",
"$",
"args",
"[",
"$",
"i",
"]",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"counts",
")",
")",
"{",
"$",
"this",
"->",
"counts",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"initCount",
";",
"}",
"$",
"ref",
"=",
"&",
"$",
"this",
"->",
"counts",
"[",
"$",
"key",
"]",
";",
"$",
"ref",
"+=",
"$",
"rel",
";",
"return",
"$",
"ref",
";",
"}"
] | Gibt die Referenz auf den Counter für die genannte Dimension zurück
example:
$v =& $mv->c('foo','bar');
$v++;
$mv->c('foo','bar'); // ist jetzt eins höher | [
"Gibt",
"die",
"Referenz",
"auf",
"den",
"Counter",
"für",
"die",
"genannte",
"Dimension",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/MultiValueCounter.php#L34-L52 |
webforge-labs/psc-cms | lib/Psc/Doctrine/CollectionSynchronizer.php | CollectionSynchronizer.init | public function init(Entity $entity, Closure $adder = NULL, Closure $remover = NULL) {
parent::init($entity);
list($add, $remove) = $this->getRelationInterface();
if (!$adder) {
$adder = function ($entity, $toEntity, $repository) use ($add) {
$repository->persist($toEntity);
$entity->$add($toEntity);
};
}
if (!$remover) {
$remover = function ($entity, $fromEntity, $repository) use ($remove) {
$repository->persist($fromEntity);
$entity->$remove($fromEntity);
};
}
$repository = $this->collectionRepository;
// insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war
$this->innerSynchronizer->onInsert(function ($toEntity) use ($repository, $entity, $adder) {
$adder($entity, $toEntity, $repository);
});
// update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection
$this->innerSynchronizer->onUpdate(function ($toEntity) use ($repository, $entity, $adder) {
$adder($entity, $toEntity, $repository, $isUpdate = TRUE);
});
// delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection
$this->innerSynchronizer->onDelete(function (Entity $fromEntity) use ($entity, $remover, $repository) {
$remover($entity, $fromEntity, $repository);
// wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface
});
return $this;
} | php | public function init(Entity $entity, Closure $adder = NULL, Closure $remover = NULL) {
parent::init($entity);
list($add, $remove) = $this->getRelationInterface();
if (!$adder) {
$adder = function ($entity, $toEntity, $repository) use ($add) {
$repository->persist($toEntity);
$entity->$add($toEntity);
};
}
if (!$remover) {
$remover = function ($entity, $fromEntity, $repository) use ($remove) {
$repository->persist($fromEntity);
$entity->$remove($fromEntity);
};
}
$repository = $this->collectionRepository;
// insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war
$this->innerSynchronizer->onInsert(function ($toEntity) use ($repository, $entity, $adder) {
$adder($entity, $toEntity, $repository);
});
// update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection
$this->innerSynchronizer->onUpdate(function ($toEntity) use ($repository, $entity, $adder) {
$adder($entity, $toEntity, $repository, $isUpdate = TRUE);
});
// delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection
$this->innerSynchronizer->onDelete(function (Entity $fromEntity) use ($entity, $remover, $repository) {
$remover($entity, $fromEntity, $repository);
// wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface
});
return $this;
} | [
"public",
"function",
"init",
"(",
"Entity",
"$",
"entity",
",",
"Closure",
"$",
"adder",
"=",
"NULL",
",",
"Closure",
"$",
"remover",
"=",
"NULL",
")",
"{",
"parent",
"::",
"init",
"(",
"$",
"entity",
")",
";",
"list",
"(",
"$",
"add",
",",
"$",
"remove",
")",
"=",
"$",
"this",
"->",
"getRelationInterface",
"(",
")",
";",
"if",
"(",
"!",
"$",
"adder",
")",
"{",
"$",
"adder",
"=",
"function",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
")",
"use",
"(",
"$",
"add",
")",
"{",
"$",
"repository",
"->",
"persist",
"(",
"$",
"toEntity",
")",
";",
"$",
"entity",
"->",
"$",
"add",
"(",
"$",
"toEntity",
")",
";",
"}",
";",
"}",
"if",
"(",
"!",
"$",
"remover",
")",
"{",
"$",
"remover",
"=",
"function",
"(",
"$",
"entity",
",",
"$",
"fromEntity",
",",
"$",
"repository",
")",
"use",
"(",
"$",
"remove",
")",
"{",
"$",
"repository",
"->",
"persist",
"(",
"$",
"fromEntity",
")",
";",
"$",
"entity",
"->",
"$",
"remove",
"(",
"$",
"fromEntity",
")",
";",
"}",
";",
"}",
"$",
"repository",
"=",
"$",
"this",
"->",
"collectionRepository",
";",
"// insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war",
"$",
"this",
"->",
"innerSynchronizer",
"->",
"onInsert",
"(",
"function",
"(",
"$",
"toEntity",
")",
"use",
"(",
"$",
"repository",
",",
"$",
"entity",
",",
"$",
"adder",
")",
"{",
"$",
"adder",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
")",
";",
"}",
")",
";",
"// update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection",
"$",
"this",
"->",
"innerSynchronizer",
"->",
"onUpdate",
"(",
"function",
"(",
"$",
"toEntity",
")",
"use",
"(",
"$",
"repository",
",",
"$",
"entity",
",",
"$",
"adder",
")",
"{",
"$",
"adder",
"(",
"$",
"entity",
",",
"$",
"toEntity",
",",
"$",
"repository",
",",
"$",
"isUpdate",
"=",
"TRUE",
")",
";",
"}",
")",
";",
"// delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection",
"$",
"this",
"->",
"innerSynchronizer",
"->",
"onDelete",
"(",
"function",
"(",
"Entity",
"$",
"fromEntity",
")",
"use",
"(",
"$",
"entity",
",",
"$",
"remover",
",",
"$",
"repository",
")",
"{",
"$",
"remover",
"(",
"$",
"entity",
",",
"$",
"fromEntity",
",",
"$",
"repository",
")",
";",
"// wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Kompiliert den Synchronizer und initialisiert
wenn angegeben $add angegben wird, wird diese Closure mit $entity (der Parameter der init() Funktion) und $otherEntity aufgerufen
bei $add ist $otherEntity ein Entity aus der $toCollection welches nicht in der $fromColleciton ist
bei $remove ist $otherEntity ein Entity aus der $fromCollection welches nicht in der $toCollection ist
als dritter parameter wird das $repository des Entities in der Collection übergeben (also nicht das von $entity)
die Standard-Adder sind nur für den Fall, dass diese Klasse auch die owning Side ist
sie rufen also $entity->addXXX($toEntity) auf
bzw
$entity->removeXXX($fromEntity)
@param Closure $adder function ($entity, $toEntity, $collectionRepository) persist nicht vergesen!
@param Closure $remover function ($entity, $fromEntity, $collectionRepository) | [
"Kompiliert",
"den",
"Synchronizer",
"und",
"initialisiert"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/CollectionSynchronizer.php#L51-L89 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php | ServerPublisher.postPublicNotification | function postPublicNotification($message, $link = null, $iconStyle = null, $iconSubstyle = null, $titleIdString = null, $mediaURL = null, $group = null)
{
$n = new Notification();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$n->message = $message;
$n->link = $link;
$n->iconStyle = $iconStyle;
$n->iconSubStyle = $iconSubstyle;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
$n->group = $group;
return $this->execute('POST', '/maniahome/notification/public/', array($n));
} | php | function postPublicNotification($message, $link = null, $iconStyle = null, $iconSubstyle = null, $titleIdString = null, $mediaURL = null, $group = null)
{
$n = new Notification();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$n->message = $message;
$n->link = $link;
$n->iconStyle = $iconStyle;
$n->iconSubStyle = $iconSubstyle;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
$n->group = $group;
return $this->execute('POST', '/maniahome/notification/public/', array($n));
} | [
"function",
"postPublicNotification",
"(",
"$",
"message",
",",
"$",
"link",
"=",
"null",
",",
"$",
"iconStyle",
"=",
"null",
",",
"$",
"iconSubstyle",
"=",
"null",
",",
"$",
"titleIdString",
"=",
"null",
",",
"$",
"mediaURL",
"=",
"null",
",",
"$",
"group",
"=",
"null",
")",
"{",
"$",
"n",
"=",
"new",
"Notification",
"(",
")",
";",
"$",
"n",
"->",
"senderName",
"=",
"(",
"object",
")",
"array",
"(",
"'serverLogin'",
"=>",
"$",
"this",
"->",
"serverLogin",
")",
";",
"$",
"n",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"n",
"->",
"link",
"=",
"$",
"link",
";",
"$",
"n",
"->",
"iconStyle",
"=",
"$",
"iconStyle",
";",
"$",
"n",
"->",
"iconSubStyle",
"=",
"$",
"iconSubstyle",
";",
"$",
"n",
"->",
"titleId",
"=",
"$",
"titleIdString",
";",
"$",
"n",
"->",
"mediaURL",
"=",
"$",
"mediaURL",
";",
"$",
"n",
"->",
"group",
"=",
"$",
"group",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"'POST'",
",",
"'/maniahome/notification/public/'",
",",
"array",
"(",
"$",
"n",
")",
")",
";",
"}"
] | Send a public notification to every player that bookmarked your server.
@param string $message The message itself. If you send a public notification to a player, the
message will be prepended with its nickname. Max length is 255 chars, you
can use Maniaplanet special chars.
@param string $link Link when the player clicks on the notification
@param string $iconStyle Icon style (from the Manialink styles)
@param string $iconSubstyle Icon substyle (from the Manialink styles)
@param string $titleIdString the titleIdString where the notification will be visible. Leave empty to post for ManiaPlanet
@param string $mediaURL Link to a picture (jpg,png or dds) or a video (webm)
@param string $group Group on the notification (http://maniapla.net/maniahome-group)
@return int | [
"Send",
"a",
"public",
"notification",
"to",
"every",
"player",
"that",
"bookmarked",
"your",
"server",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L48-L60 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php | ServerPublisher.postPrivateNotification | function postPrivateNotification($message, $receiverName, $link = null, $titleIdString = null)
{
$n = new Notification();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$n->message = $message;
$n->link = $link;
$n->receiverName = $receiverName;
$n->isPrivate = true;
$n->titleId = $titleIdString;
return $this->execute('POST', '/maniahome/notification/private/', array($n));
} | php | function postPrivateNotification($message, $receiverName, $link = null, $titleIdString = null)
{
$n = new Notification();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$n->message = $message;
$n->link = $link;
$n->receiverName = $receiverName;
$n->isPrivate = true;
$n->titleId = $titleIdString;
return $this->execute('POST', '/maniahome/notification/private/', array($n));
} | [
"function",
"postPrivateNotification",
"(",
"$",
"message",
",",
"$",
"receiverName",
",",
"$",
"link",
"=",
"null",
",",
"$",
"titleIdString",
"=",
"null",
")",
"{",
"$",
"n",
"=",
"new",
"Notification",
"(",
")",
";",
"$",
"n",
"->",
"senderName",
"=",
"(",
"object",
")",
"array",
"(",
"'serverLogin'",
"=>",
"$",
"this",
"->",
"serverLogin",
")",
";",
"$",
"n",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"n",
"->",
"link",
"=",
"$",
"link",
";",
"$",
"n",
"->",
"receiverName",
"=",
"$",
"receiverName",
";",
"$",
"n",
"->",
"isPrivate",
"=",
"true",
";",
"$",
"n",
"->",
"titleId",
"=",
"$",
"titleIdString",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"'POST'",
",",
"'/maniahome/notification/private/'",
",",
"array",
"(",
"$",
"n",
")",
")",
";",
"}"
] | Send a private message to a player (specified in
Notification::$receiverName).
@param string $message The message itself. If you send a public notification to a player, the
message will be prepended with its nickname. Max length is 255 chars, you
can use Maniaplanet special chars.
@param string $receiverName The receiver of the notification.
@param string $link Link when the player clicks on the notification
@return int | [
"Send",
"a",
"private",
"message",
"to",
"a",
"player",
"(",
"specified",
"in",
"Notification",
"::",
"$receiverName",
")",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L103-L113 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php | ServerPublisher.postPrivateEvent | function postPrivateEvent($message, $eventDate, $receiverName, $link = null, $titleIdString = null, $mediaURL = null)
{
$e = new Event();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$e->message = $message;
$e->link = $link;
$e->receiverName = $receiverName;
$e->eventDate = $eventDate;
$e->isPrivate = true;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
return $this->execute('POST', '/maniahome/event/private/', array($e));
} | php | function postPrivateEvent($message, $eventDate, $receiverName, $link = null, $titleIdString = null, $mediaURL = null)
{
$e = new Event();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$e->message = $message;
$e->link = $link;
$e->receiverName = $receiverName;
$e->eventDate = $eventDate;
$e->isPrivate = true;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
return $this->execute('POST', '/maniahome/event/private/', array($e));
} | [
"function",
"postPrivateEvent",
"(",
"$",
"message",
",",
"$",
"eventDate",
",",
"$",
"receiverName",
",",
"$",
"link",
"=",
"null",
",",
"$",
"titleIdString",
"=",
"null",
",",
"$",
"mediaURL",
"=",
"null",
")",
"{",
"$",
"e",
"=",
"new",
"Event",
"(",
")",
";",
"$",
"n",
"->",
"senderName",
"=",
"(",
"object",
")",
"array",
"(",
"'serverLogin'",
"=>",
"$",
"this",
"->",
"serverLogin",
")",
";",
"$",
"e",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"e",
"->",
"link",
"=",
"$",
"link",
";",
"$",
"e",
"->",
"receiverName",
"=",
"$",
"receiverName",
";",
"$",
"e",
"->",
"eventDate",
"=",
"$",
"eventDate",
";",
"$",
"e",
"->",
"isPrivate",
"=",
"true",
";",
"$",
"n",
"->",
"titleId",
"=",
"$",
"titleIdString",
";",
"$",
"n",
"->",
"mediaURL",
"=",
"$",
"mediaURL",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"'POST'",
",",
"'/maniahome/event/private/'",
",",
"array",
"(",
"$",
"e",
")",
")",
";",
"}"
] | Create an event visible only by the receivers. To create an event for many players just give an array of login as
receiverName.
@param string $message The message itself. If you send a public notification to a player, the
message will be prepended with its nickname. Max length is 255 chars, you
can use Maniaplanet special chars.
@param string|string[] $receiverName The receiver(s) of the notification.
@param int $eventDate The UNIX Timestamp of the date of the event
@param string $link Link when the player clicks on the notification
@return int | [
"Create",
"an",
"event",
"visible",
"only",
"by",
"the",
"receivers",
".",
"To",
"create",
"an",
"event",
"for",
"many",
"players",
"just",
"give",
"an",
"array",
"of",
"login",
"as",
"receiverName",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L127-L139 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php | ServerPublisher.postPublicEvent | function postPublicEvent($message, $eventDate, $link = null, $titleIdString = null, $mediaURL = null)
{
$e = new Event();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$e->message = $message;
$e->link = $link;
$e->eventDate = $eventDate;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
return $this->execute('POST', '/maniahome/event/public/', array($e));
} | php | function postPublicEvent($message, $eventDate, $link = null, $titleIdString = null, $mediaURL = null)
{
$e = new Event();
$n->senderName = (object) array('serverLogin' => $this->serverLogin);
$e->message = $message;
$e->link = $link;
$e->eventDate = $eventDate;
$n->titleId = $titleIdString;
$n->mediaURL = $mediaURL;
return $this->execute('POST', '/maniahome/event/public/', array($e));
} | [
"function",
"postPublicEvent",
"(",
"$",
"message",
",",
"$",
"eventDate",
",",
"$",
"link",
"=",
"null",
",",
"$",
"titleIdString",
"=",
"null",
",",
"$",
"mediaURL",
"=",
"null",
")",
"{",
"$",
"e",
"=",
"new",
"Event",
"(",
")",
";",
"$",
"n",
"->",
"senderName",
"=",
"(",
"object",
")",
"array",
"(",
"'serverLogin'",
"=>",
"$",
"this",
"->",
"serverLogin",
")",
";",
"$",
"e",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"e",
"->",
"link",
"=",
"$",
"link",
";",
"$",
"e",
"->",
"eventDate",
"=",
"$",
"eventDate",
";",
"$",
"n",
"->",
"titleId",
"=",
"$",
"titleIdString",
";",
"$",
"n",
"->",
"mediaURL",
"=",
"$",
"mediaURL",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"'POST'",
",",
"'/maniahome/event/public/'",
",",
"array",
"(",
"$",
"e",
")",
")",
";",
"}"
] | Create an event visible by all players who bookmarked your server
@param string $message The message itself. If you send a public notification to a player, the
@param string message will be prepended with its nickname. Max length is 255 chars, you
can use Maniaplanet special chars.
@param int $eventDate The UNIX Timestamp of the date of the event
@param string $link Link when the player clicks on the notification
@return int | [
"Create",
"an",
"event",
"visible",
"by",
"all",
"players",
"who",
"bookmarked",
"your",
"server"
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L150-L160 |
devmobgroup/postcodes | src/Util/Uri.php | Uri.create | public static function create(string $baseUri, array $query = []): string
{
if (count($query) === 0) {
return $baseUri;
}
return sprintf('%s/?%s', $baseUri, http_build_query($query));
} | php | public static function create(string $baseUri, array $query = []): string
{
if (count($query) === 0) {
return $baseUri;
}
return sprintf('%s/?%s', $baseUri, http_build_query($query));
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"baseUri",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
":",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"query",
")",
"===",
"0",
")",
"{",
"return",
"$",
"baseUri",
";",
"}",
"return",
"sprintf",
"(",
"'%s/?%s'",
",",
"$",
"baseUri",
",",
"http_build_query",
"(",
"$",
"query",
")",
")",
";",
"}"
] | Create request url based on base uri and request parameters.
@param string $baseUri
@param array $query
@return string | [
"Create",
"request",
"url",
"based",
"on",
"base",
"uri",
"and",
"request",
"parameters",
"."
] | train | https://github.com/devmobgroup/postcodes/blob/1a8438fd960a8f50ec28d61af94560892b529f12/src/Util/Uri.php#L14-L21 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper.file | public function file($fieldName, array $options = [])
{
$errorSuffix = null;
$error = $this->error($fieldName);
$content = parent::file($fieldName, $options);
if ($this->getConfig('materializeCss', false) === false) {
return $content;
}
$options = $this->_parseOptions($fieldName, $options);
$options['type'] = __FUNCTION__;
if ($error !== '') {
$options['error'] = $error;
$errorSuffix = 'Error';
}
$result = $this->_inputContainerTemplate([
'error' => $error,
'content' => $content,
'options' => $options,
'errorSuffix' => $errorSuffix
]);
return $result;
} | php | public function file($fieldName, array $options = [])
{
$errorSuffix = null;
$error = $this->error($fieldName);
$content = parent::file($fieldName, $options);
if ($this->getConfig('materializeCss', false) === false) {
return $content;
}
$options = $this->_parseOptions($fieldName, $options);
$options['type'] = __FUNCTION__;
if ($error !== '') {
$options['error'] = $error;
$errorSuffix = 'Error';
}
$result = $this->_inputContainerTemplate([
'error' => $error,
'content' => $content,
'options' => $options,
'errorSuffix' => $errorSuffix
]);
return $result;
} | [
"public",
"function",
"file",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"errorSuffix",
"=",
"null",
";",
"$",
"error",
"=",
"$",
"this",
"->",
"error",
"(",
"$",
"fieldName",
")",
";",
"$",
"content",
"=",
"parent",
"::",
"file",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'materializeCss'",
",",
"false",
")",
"===",
"false",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"_parseOptions",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"$",
"options",
"[",
"'type'",
"]",
"=",
"__FUNCTION__",
";",
"if",
"(",
"$",
"error",
"!==",
"''",
")",
"{",
"$",
"options",
"[",
"'error'",
"]",
"=",
"$",
"error",
";",
"$",
"errorSuffix",
"=",
"'Error'",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"_inputContainerTemplate",
"(",
"[",
"'error'",
"=>",
"$",
"error",
",",
"'content'",
"=>",
"$",
"content",
",",
"'options'",
"=>",
"$",
"options",
",",
"'errorSuffix'",
"=>",
"$",
"errorSuffix",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Creates file input widget.
@param string $fieldName Name of a field, in the form "modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated file input. | [
"Creates",
"file",
"input",
"widget",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L112-L138 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper.switcher | public function switcher($fieldName, array $options = [])
{
$input = parent::checkbox($fieldName, $options);
if ($this->getConfig('materializeCss', false) === false) {
return $input;
}
$options += [
'before' => __d('backend', 'Off'),
'after' => __d('backend', 'On')
];
$title = (Arr::key('title', $options)) ? $options['title'] : $fieldName;
if (!empty($title)) {
$title = $this->Html->div('switch-title', $title);
}
$content = $this->formatTemplate(__FUNCTION__, [
'input' => $input,
'title' => $title,
'after' => $options['after'],
'before' => $options['before'],
'lever' => '<span class="lever"></span>'
]);
return $content;
} | php | public function switcher($fieldName, array $options = [])
{
$input = parent::checkbox($fieldName, $options);
if ($this->getConfig('materializeCss', false) === false) {
return $input;
}
$options += [
'before' => __d('backend', 'Off'),
'after' => __d('backend', 'On')
];
$title = (Arr::key('title', $options)) ? $options['title'] : $fieldName;
if (!empty($title)) {
$title = $this->Html->div('switch-title', $title);
}
$content = $this->formatTemplate(__FUNCTION__, [
'input' => $input,
'title' => $title,
'after' => $options['after'],
'before' => $options['before'],
'lever' => '<span class="lever"></span>'
]);
return $content;
} | [
"public",
"function",
"switcher",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"parent",
"::",
"checkbox",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'materializeCss'",
",",
"false",
")",
"===",
"false",
")",
"{",
"return",
"$",
"input",
";",
"}",
"$",
"options",
"+=",
"[",
"'before'",
"=>",
"__d",
"(",
"'backend'",
",",
"'Off'",
")",
",",
"'after'",
"=>",
"__d",
"(",
"'backend'",
",",
"'On'",
")",
"]",
";",
"$",
"title",
"=",
"(",
"Arr",
"::",
"key",
"(",
"'title'",
",",
"$",
"options",
")",
")",
"?",
"$",
"options",
"[",
"'title'",
"]",
":",
"$",
"fieldName",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"title",
")",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"Html",
"->",
"div",
"(",
"'switch-title'",
",",
"$",
"title",
")",
";",
"}",
"$",
"content",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"__FUNCTION__",
",",
"[",
"'input'",
"=>",
"$",
"input",
",",
"'title'",
"=>",
"$",
"title",
",",
"'after'",
"=>",
"$",
"options",
"[",
"'after'",
"]",
",",
"'before'",
"=>",
"$",
"options",
"[",
"'before'",
"]",
",",
"'lever'",
"=>",
"'<span class=\"lever\"></span>'",
"]",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Form switcher.
@param string $fieldName
@param array $options
@return string | [
"Form",
"switcher",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L147-L175 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper.button | public function button($title, array $options = [])
{
$options = $this->addClass($options, $this->_class(__FUNCTION__));
$options = $this->_getBtnClass($options);
$options = $this->_getToolTipAttr($options);
list($title, $options) = $this->_createIcon($this->Html, $title, $options);
return parent::button($title, $options);
} | php | public function button($title, array $options = [])
{
$options = $this->addClass($options, $this->_class(__FUNCTION__));
$options = $this->_getBtnClass($options);
$options = $this->_getToolTipAttr($options);
list($title, $options) = $this->_createIcon($this->Html, $title, $options);
return parent::button($title, $options);
} | [
"public",
"function",
"button",
"(",
"$",
"title",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"options",
",",
"$",
"this",
"->",
"_class",
"(",
"__FUNCTION__",
")",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_getBtnClass",
"(",
"$",
"options",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_getToolTipAttr",
"(",
"$",
"options",
")",
";",
"list",
"(",
"$",
"title",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"_createIcon",
"(",
"$",
"this",
"->",
"Html",
",",
"$",
"title",
",",
"$",
"options",
")",
";",
"return",
"parent",
"::",
"button",
"(",
"$",
"title",
",",
"$",
"options",
")",
";",
"}"
] | Creates a `<button>` tag.
@param string $title
@param array $options
@return string | [
"Creates",
"a",
"<button",
">",
"tag",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L184-L193 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper.create | public function create($model = null, array $options = [])
{
$options += ['process' => false, 'jsForm' => false];
$options = $this->addClass($options, $this->_class('form'));
$isProcess = $options['process'];
if ($isProcess !== false) {
$_options = [
'url' => [
'plugin' => $this->request->getParam('plugin'),
'controller' => $this->request->getParam('controller'),
'action' => 'process'
]
];
$options['jsForm'] = true;
$options = Hash::merge($_options, $options);
}
$isJsForm = $options['jsForm'];
if ($isJsForm) {
$this->_isJsForm = true;
$options = $this->addClass($options, 'jsForm');
}
unset($options['process'], $options['jsForm']);
return parent::create($model, $options);
} | php | public function create($model = null, array $options = [])
{
$options += ['process' => false, 'jsForm' => false];
$options = $this->addClass($options, $this->_class('form'));
$isProcess = $options['process'];
if ($isProcess !== false) {
$_options = [
'url' => [
'plugin' => $this->request->getParam('plugin'),
'controller' => $this->request->getParam('controller'),
'action' => 'process'
]
];
$options['jsForm'] = true;
$options = Hash::merge($_options, $options);
}
$isJsForm = $options['jsForm'];
if ($isJsForm) {
$this->_isJsForm = true;
$options = $this->addClass($options, 'jsForm');
}
unset($options['process'], $options['jsForm']);
return parent::create($model, $options);
} | [
"public",
"function",
"create",
"(",
"$",
"model",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'process'",
"=>",
"false",
",",
"'jsForm'",
"=>",
"false",
"]",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"options",
",",
"$",
"this",
"->",
"_class",
"(",
"'form'",
")",
")",
";",
"$",
"isProcess",
"=",
"$",
"options",
"[",
"'process'",
"]",
";",
"if",
"(",
"$",
"isProcess",
"!==",
"false",
")",
"{",
"$",
"_options",
"=",
"[",
"'url'",
"=>",
"[",
"'plugin'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getParam",
"(",
"'plugin'",
")",
",",
"'controller'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getParam",
"(",
"'controller'",
")",
",",
"'action'",
"=>",
"'process'",
"]",
"]",
";",
"$",
"options",
"[",
"'jsForm'",
"]",
"=",
"true",
";",
"$",
"options",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"_options",
",",
"$",
"options",
")",
";",
"}",
"$",
"isJsForm",
"=",
"$",
"options",
"[",
"'jsForm'",
"]",
";",
"if",
"(",
"$",
"isJsForm",
")",
"{",
"$",
"this",
"->",
"_isJsForm",
"=",
"true",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"options",
",",
"'jsForm'",
")",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'process'",
"]",
",",
"$",
"options",
"[",
"'jsForm'",
"]",
")",
";",
"return",
"parent",
"::",
"create",
"(",
"$",
"model",
",",
"$",
"options",
")",
";",
"}"
] | Create html form.
@param mixed $model
@param array $options
@return string | [
"Create",
"html",
"form",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L212-L241 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper.end | public function end(array $secureAttributes = [])
{
if ($this->_isJsForm) {
return implode('', [
$this->hidden('action', ['value' => '', 'class' => 'jsFormAction']),
parent::end($secureAttributes)
]);
}
return parent::end($secureAttributes);
} | php | public function end(array $secureAttributes = [])
{
if ($this->_isJsForm) {
return implode('', [
$this->hidden('action', ['value' => '', 'class' => 'jsFormAction']),
parent::end($secureAttributes)
]);
}
return parent::end($secureAttributes);
} | [
"public",
"function",
"end",
"(",
"array",
"$",
"secureAttributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isJsForm",
")",
"{",
"return",
"implode",
"(",
"''",
",",
"[",
"$",
"this",
"->",
"hidden",
"(",
"'action'",
",",
"[",
"'value'",
"=>",
"''",
",",
"'class'",
"=>",
"'jsFormAction'",
"]",
")",
",",
"parent",
"::",
"end",
"(",
"$",
"secureAttributes",
")",
"]",
")",
";",
"}",
"return",
"parent",
"::",
"end",
"(",
"$",
"secureAttributes",
")",
";",
"}"
] | End html form.
@param array $secureAttributes
@return string | [
"End",
"html",
"form",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L249-L259 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper._addDefaultContextProviders | protected function _addDefaultContextProviders()
{
$this->addContextProvider('orm', function ($request, $data) {
if (is_array($data['entity']) || $data['entity'] instanceof \Traversable) {
$pass = (new Collection($data['entity']))->first() !== null;
if ($pass) {
return new EntityContext($request, $data);
}
}
return $this->_addEntityContent($request, $data);
});
$this->_addFormContextProvider();
$this->_addFormArrayProvider();
} | php | protected function _addDefaultContextProviders()
{
$this->addContextProvider('orm', function ($request, $data) {
if (is_array($data['entity']) || $data['entity'] instanceof \Traversable) {
$pass = (new Collection($data['entity']))->first() !== null;
if ($pass) {
return new EntityContext($request, $data);
}
}
return $this->_addEntityContent($request, $data);
});
$this->_addFormContextProvider();
$this->_addFormArrayProvider();
} | [
"protected",
"function",
"_addDefaultContextProviders",
"(",
")",
"{",
"$",
"this",
"->",
"addContextProvider",
"(",
"'orm'",
",",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"||",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"\\",
"Traversable",
")",
"{",
"$",
"pass",
"=",
"(",
"new",
"Collection",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
")",
"->",
"first",
"(",
")",
"!==",
"null",
";",
"if",
"(",
"$",
"pass",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_addEntityContent",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"_addFormContextProvider",
"(",
")",
";",
"$",
"this",
"->",
"_addFormArrayProvider",
"(",
")",
";",
"}"
] | Add the default suite of context providers provided.
@return void | [
"Add",
"the",
"default",
"suite",
"of",
"context",
"providers",
"provided",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L278-L293 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper._inputContainerTemplate | protected function _inputContainerTemplate($options)
{
$inputContainerTemplate = $options['options']['type'] . 'Container' . $options['errorSuffix'];
if (!$this->templater()->get($inputContainerTemplate)) {
$inputContainerTemplate = 'inputContainer' . $options['errorSuffix'];
}
$_options = new Data($options['options']);
$before = $this->_prepareBeforeAfterContainer('before', $_options->get('before'));
$after = $this->_prepareBeforeAfterContainer('after', $_options->get('after'));
return $this->formatTemplate($inputContainerTemplate, [
'after' => $after,
'before' => $before,
'error' => $options['error'],
'content' => $options['content'],
'type' => $options['options']['type'],
'required' => $options['options']['required'] ? ' required' : '',
'templateVars' => isset($options['options']['templateVars']) ? $options['options']['templateVars'] : []
]);
} | php | protected function _inputContainerTemplate($options)
{
$inputContainerTemplate = $options['options']['type'] . 'Container' . $options['errorSuffix'];
if (!$this->templater()->get($inputContainerTemplate)) {
$inputContainerTemplate = 'inputContainer' . $options['errorSuffix'];
}
$_options = new Data($options['options']);
$before = $this->_prepareBeforeAfterContainer('before', $_options->get('before'));
$after = $this->_prepareBeforeAfterContainer('after', $_options->get('after'));
return $this->formatTemplate($inputContainerTemplate, [
'after' => $after,
'before' => $before,
'error' => $options['error'],
'content' => $options['content'],
'type' => $options['options']['type'],
'required' => $options['options']['required'] ? ' required' : '',
'templateVars' => isset($options['options']['templateVars']) ? $options['options']['templateVars'] : []
]);
} | [
"protected",
"function",
"_inputContainerTemplate",
"(",
"$",
"options",
")",
"{",
"$",
"inputContainerTemplate",
"=",
"$",
"options",
"[",
"'options'",
"]",
"[",
"'type'",
"]",
".",
"'Container'",
".",
"$",
"options",
"[",
"'errorSuffix'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"get",
"(",
"$",
"inputContainerTemplate",
")",
")",
"{",
"$",
"inputContainerTemplate",
"=",
"'inputContainer'",
".",
"$",
"options",
"[",
"'errorSuffix'",
"]",
";",
"}",
"$",
"_options",
"=",
"new",
"Data",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
";",
"$",
"before",
"=",
"$",
"this",
"->",
"_prepareBeforeAfterContainer",
"(",
"'before'",
",",
"$",
"_options",
"->",
"get",
"(",
"'before'",
")",
")",
";",
"$",
"after",
"=",
"$",
"this",
"->",
"_prepareBeforeAfterContainer",
"(",
"'after'",
",",
"$",
"_options",
"->",
"get",
"(",
"'after'",
")",
")",
";",
"return",
"$",
"this",
"->",
"formatTemplate",
"(",
"$",
"inputContainerTemplate",
",",
"[",
"'after'",
"=>",
"$",
"after",
",",
"'before'",
"=>",
"$",
"before",
",",
"'error'",
"=>",
"$",
"options",
"[",
"'error'",
"]",
",",
"'content'",
"=>",
"$",
"options",
"[",
"'content'",
"]",
",",
"'type'",
"=>",
"$",
"options",
"[",
"'options'",
"]",
"[",
"'type'",
"]",
",",
"'required'",
"=>",
"$",
"options",
"[",
"'options'",
"]",
"[",
"'required'",
"]",
"?",
"' required'",
":",
"''",
",",
"'templateVars'",
"=>",
"isset",
"(",
"$",
"options",
"[",
"'options'",
"]",
"[",
"'templateVars'",
"]",
")",
"?",
"$",
"options",
"[",
"'options'",
"]",
"[",
"'templateVars'",
"]",
":",
"[",
"]",
"]",
")",
";",
"}"
] | Generates an input container template
@param array $options The options for input container template
@return string The generated input container template | [
"Generates",
"an",
"input",
"container",
"template"
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L301-L321 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper._addEntityContent | protected function _addEntityContent($request, $data)
{
if ($data['entity'] instanceof EntityInterface) {
return new EntityContext($request, $data);
}
if (is_array($data['entity']) && empty($data['entity']['schema'])) {
return new EntityContext($request, $data);
}
} | php | protected function _addEntityContent($request, $data)
{
if ($data['entity'] instanceof EntityInterface) {
return new EntityContext($request, $data);
}
if (is_array($data['entity']) && empty($data['entity']['schema'])) {
return new EntityContext($request, $data);
}
} | [
"protected",
"function",
"_addEntityContent",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"EntityInterface",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"&&",
"empty",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"[",
"'schema'",
"]",
")",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}"
] | Add the entity suite of context providers provided.
@param $request
@param $data
@return EntityContext | [
"Add",
"the",
"entity",
"suite",
"of",
"context",
"providers",
"provided",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L330-L339 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper._addFormArrayProvider | protected function _addFormArrayProvider()
{
$this->addContextProvider('array', function ($request, $data) {
if (is_array($data['entity']) && isset($data['entity']['schema'])) {
return new ArrayContext($request, $data['entity']);
}
});
} | php | protected function _addFormArrayProvider()
{
$this->addContextProvider('array', function ($request, $data) {
if (is_array($data['entity']) && isset($data['entity']['schema'])) {
return new ArrayContext($request, $data['entity']);
}
});
} | [
"protected",
"function",
"_addFormArrayProvider",
"(",
")",
"{",
"$",
"this",
"->",
"addContextProvider",
"(",
"'array'",
",",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"[",
"'schema'",
"]",
")",
")",
"{",
"return",
"new",
"ArrayContext",
"(",
"$",
"request",
",",
"$",
"data",
"[",
"'entity'",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | Add the array suite of context providers provided.
@return void | [
"Add",
"the",
"array",
"suite",
"of",
"context",
"providers",
"provided",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L346-L353 |
CakeCMS/Core | src/View/Helper/FormHelper.php | FormHelper._addFormContextProvider | protected function _addFormContextProvider()
{
$this->addContextProvider('form', function ($request, $data) {
if ($data['entity'] instanceof Form) {
return new FormContext($request, $data);
}
});
} | php | protected function _addFormContextProvider()
{
$this->addContextProvider('form', function ($request, $data) {
if ($data['entity'] instanceof Form) {
return new FormContext($request, $data);
}
});
} | [
"protected",
"function",
"_addFormContextProvider",
"(",
")",
"{",
"$",
"this",
"->",
"addContextProvider",
"(",
"'form'",
",",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"Form",
")",
"{",
"return",
"new",
"FormContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}",
")",
";",
"}"
] | Add the form suite of context providers provided.
@return void | [
"Add",
"the",
"form",
"suite",
"of",
"context",
"providers",
"provided",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L360-L367 |
iocaste/microservice-foundation | src/Http/Requests/Parameter/ValidatesParameters.php | ValidatesParameters.rules | public function rules(): array
{
$input = array_keys($this->request->all());
return Parameter::whereIn('id', $input)
->get()
->mapWithKeys(function ($item) {
return [$item['id'] => $item->rules];
})->all();
} | php | public function rules(): array
{
$input = array_keys($this->request->all());
return Parameter::whereIn('id', $input)
->get()
->mapWithKeys(function ($item) {
return [$item['id'] => $item->rules];
})->all();
} | [
"public",
"function",
"rules",
"(",
")",
":",
"array",
"{",
"$",
"input",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"Parameter",
"::",
"whereIn",
"(",
"'id'",
",",
"$",
"input",
")",
"->",
"get",
"(",
")",
"->",
"mapWithKeys",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"[",
"$",
"item",
"[",
"'id'",
"]",
"=>",
"$",
"item",
"->",
"rules",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Get the validation rules that apply to the request.
@return array | [
"Get",
"the",
"validation",
"rules",
"that",
"apply",
"to",
"the",
"request",
"."
] | train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Requests/Parameter/ValidatesParameters.php#L28-L37 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.defineTask | public function defineTask($name, $object)
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
if ($this->started)
throw new \Exception("Define tasks before start()ing the daemon not after");
if (! $object instanceof AbstractTask)
throw new \Exception("Task must implement AbstractTask");
$object->setDaemon($this);
$this->tasks[$name] = $object;
if ($debug)
echo "==> Task defined: $name" . PHP_EOL;
return $this;
} | php | public function defineTask($name, $object)
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
if ($this->started)
throw new \Exception("Define tasks before start()ing the daemon not after");
if (! $object instanceof AbstractTask)
throw new \Exception("Task must implement AbstractTask");
$object->setDaemon($this);
$this->tasks[$name] = $object;
if ($debug)
echo "==> Task defined: $name" . PHP_EOL;
return $this;
} | [
"public",
"function",
"defineTask",
"(",
"$",
"name",
",",
"$",
"object",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Define tasks before start()ing the daemon not after\"",
")",
";",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"AbstractTask",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Task must implement AbstractTask\"",
")",
";",
"$",
"object",
"->",
"setDaemon",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"tasks",
"[",
"$",
"name",
"]",
"=",
"$",
"object",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Task defined: $name\"",
".",
"PHP_EOL",
";",
"return",
"$",
"this",
";",
"}"
] | Add task to the list of known tasks
@param string $name
@param AbstractTask $object
@return TaskDaemon | [
"Add",
"task",
"to",
"the",
"list",
"of",
"known",
"tasks"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L94-L112 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.runTask | public function runTask($name, $data = null, $allowDuplicates = false)
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
if ($debug)
echo "==> Trying to run task: $name" . PHP_EOL;
$function = $options['namespace'] . '-' . $name;
$data = json_encode($data);
if ($allowDuplicates)
$unique = self::generateUnique();
else
$unique = md5($function . '-' . $data);
$gmClient = new GearmanClient();
$gmClient->addServer($options['gearman']['host'], $options['gearman']['port']);
$gmClient->doBackground($function, $data, $unique);
$code = $gmClient->returnCode();
if ($code != GEARMAN_SUCCESS)
throw new \Exception("Could not run task: $name ($code)");
return $this;
} | php | public function runTask($name, $data = null, $allowDuplicates = false)
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
if ($debug)
echo "==> Trying to run task: $name" . PHP_EOL;
$function = $options['namespace'] . '-' . $name;
$data = json_encode($data);
if ($allowDuplicates)
$unique = self::generateUnique();
else
$unique = md5($function . '-' . $data);
$gmClient = new GearmanClient();
$gmClient->addServer($options['gearman']['host'], $options['gearman']['port']);
$gmClient->doBackground($function, $data, $unique);
$code = $gmClient->returnCode();
if ($code != GEARMAN_SUCCESS)
throw new \Exception("Could not run task: $name ($code)");
return $this;
} | [
"public",
"function",
"runTask",
"(",
"$",
"name",
",",
"$",
"data",
"=",
"null",
",",
"$",
"allowDuplicates",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Trying to run task: $name\"",
".",
"PHP_EOL",
";",
"$",
"function",
"=",
"$",
"options",
"[",
"'namespace'",
"]",
".",
"'-'",
".",
"$",
"name",
";",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"allowDuplicates",
")",
"$",
"unique",
"=",
"self",
"::",
"generateUnique",
"(",
")",
";",
"else",
"$",
"unique",
"=",
"md5",
"(",
"$",
"function",
".",
"'-'",
".",
"$",
"data",
")",
";",
"$",
"gmClient",
"=",
"new",
"GearmanClient",
"(",
")",
";",
"$",
"gmClient",
"->",
"addServer",
"(",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'host'",
"]",
",",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'port'",
"]",
")",
";",
"$",
"gmClient",
"->",
"doBackground",
"(",
"$",
"function",
",",
"$",
"data",
",",
"$",
"unique",
")",
";",
"$",
"code",
"=",
"$",
"gmClient",
"->",
"returnCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
"!=",
"GEARMAN_SUCCESS",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not run task: $name ($code)\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add known task to the run queue
@param string $name
@param mixed $data
@param boolean $allowDuplicates
@return TaskDaemon | [
"Add",
"known",
"task",
"to",
"the",
"run",
"queue"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L122-L146 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.ping | public function ping()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$gmClient = new GearmanClient();
$gmClient->addServer($options['gearman']['host'], $options['gearman']['port']);
$ping = $gmClient->ping(self::generateUnique());
if ($debug)
echo "==> Pinging job server: " . ($ping ? 'Success' : 'Failure') . PHP_EOL;
$code = $gmClient->returnCode();
if ($code != GEARMAN_SUCCESS)
throw new \Exception("Ping failed ($code)");
return $ping;
} | php | public function ping()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$gmClient = new GearmanClient();
$gmClient->addServer($options['gearman']['host'], $options['gearman']['port']);
$ping = $gmClient->ping(self::generateUnique());
if ($debug)
echo "==> Pinging job server: " . ($ping ? 'Success' : 'Failure') . PHP_EOL;
$code = $gmClient->returnCode();
if ($code != GEARMAN_SUCCESS)
throw new \Exception("Ping failed ($code)");
return $ping;
} | [
"public",
"function",
"ping",
"(",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"$",
"gmClient",
"=",
"new",
"GearmanClient",
"(",
")",
";",
"$",
"gmClient",
"->",
"addServer",
"(",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'host'",
"]",
",",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'port'",
"]",
")",
";",
"$",
"ping",
"=",
"$",
"gmClient",
"->",
"ping",
"(",
"self",
"::",
"generateUnique",
"(",
")",
")",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Pinging job server: \"",
".",
"(",
"$",
"ping",
"?",
"'Success'",
":",
"'Failure'",
")",
".",
"PHP_EOL",
";",
"$",
"code",
"=",
"$",
"gmClient",
"->",
"returnCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
"!=",
"GEARMAN_SUCCESS",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Ping failed ($code)\"",
")",
";",
"return",
"$",
"ping",
";",
"}"
] | Ping job servers
@return TaskDaemon | [
"Ping",
"job",
"servers"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L153-L171 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.getPid | public function getPid()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
fclose($fpPid);
return (int)file_get_contents($pidFile);
}
flock($fpPid, LOCK_UN);
fclose($fpPid);
@unlink($pidFile);
return false;
} | php | public function getPid()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
fclose($fpPid);
return (int)file_get_contents($pidFile);
}
flock($fpPid, LOCK_UN);
fclose($fpPid);
@unlink($pidFile);
return false;
} | [
"public",
"function",
"getPid",
"(",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"$",
"pidFile",
"=",
"$",
"options",
"[",
"'pid_file'",
"]",
";",
"if",
"(",
"!",
"$",
"pidFile",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No pid_file in the config\"",
")",
";",
"$",
"fpPid",
"=",
"fopen",
"(",
"$",
"pidFile",
",",
"\"c\"",
")",
";",
"if",
"(",
"!",
"$",
"fpPid",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not open \"",
".",
"$",
"pidFile",
")",
";",
"if",
"(",
"!",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_EX",
"|",
"LOCK_NB",
")",
")",
"{",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"return",
"(",
"int",
")",
"file_get_contents",
"(",
"$",
"pidFile",
")",
";",
"}",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"@",
"unlink",
"(",
"$",
"pidFile",
")",
";",
"return",
"false",
";",
"}"
] | Get daemon PID
@return integer|false Returns false if there is no daemon running | [
"Get",
"daemon",
"PID"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L178-L200 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.start | public function start()
{
if (count($this->tasks) == 0)
throw new \Exception("There are no tasks defined - can not start");
$this->started = true;
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
fclose($fpPid);
if ($debug)
echo "==> Daemon already running" . PHP_EOL;
return $this;
}
if ($debug)
echo "==> Starting the daemon... " . PHP_EOL;
$fork = pcntl_fork();
if ($fork < 0)
throw new \Exception("fork() failed: $fork");
else if ($fork)
return $this;
ftruncate($fpPid, 0);
fwrite($fpPid, getmypid() . PHP_EOL);
fflush($fpPid);
chmod($pidFile, 0666);
declare(ticks = 1);
$exitCallback = function ($signo) use ($fpPid, $pidFile, $debug) {
if ($debug)
echo "==> Cleaning and exiting" . PHP_EOL;
foreach ($this->pids as $pid) {
if ($debug)
echo "==> Terminating worker PID $pid" . PHP_EOL;
posix_kill($pid, SIGTERM);
}
foreach ($this->pids as $pid)
pcntl_waitpid($pid, $status);
flock($fpPid, LOCK_UN);
fclose($fpPid);
@unlink($pidFile);
if ($debug)
echo "==> Daemon is shut down" . PHP_EOL;
exit;
};
pcntl_signal(SIGTERM, $exitCallback);
pcntl_signal(SIGINT, $exitCallback);
pcntl_signal_dispatch();
$sid = posix_setsid();
if ($sid < 0)
throw new \Exception("setsid() failed: $sid");
$gmWorker = new GearmanWorker();
$gmWorker->addServer($options['gearman']['host'], $options['gearman']['port']);
foreach ($this->tasks as $name => $object) {
$function = $options['namespace'] . '-' . $name;
$task = function ($job) use ($name, $function, $object, $options) {
if (@$options['debug'] === true)
echo "==> Running worker for: $function (PID " . getmypid() . ")" . PHP_EOL;
$worker = clone $object;
$data = json_decode($job->workload(), true);
$worker->setData($data);
if (@$options['debug'] !== true)
ob_start();
$worker->run($this->exitRequested);
if (@$options['debug'] !== true)
ob_end_clean();
};
$gmWorker->addFunction($function, $task);
}
while (true) {
$dead = pcntl_waitpid(-1, $status, WNOHANG);
while ($dead > 0) {
if (@$options['debug'] === true)
echo "==> Worker PID $dead terminated" . PHP_EOL;
$index = array_search($dead, $this->pids);
if ($index !== false)
unset($this->pids[$index]);
$dead = pcntl_waitpid(-1, $status, WNOHANG);
}
while (count($this->pids) < $options['num_workers']) {
$pid = pcntl_fork();
if ($pid == 0) {
declare(ticks = 1);
$exitCallback = function ($signo) {
$this->exitRequested = true;
};
pcntl_signal(SIGTERM, $exitCallback);
pcntl_signal(SIGINT, $exitCallback);
pcntl_signal_dispatch();
$this->pids = [];
$gmWorker->setTimeout(1000);
while (!$this->exitRequested) {
$gmWorker->work();
$code = $gmWorker->returnCode();
switch ($code) {
case GEARMAN_TIMEOUT:
sleep(1);
break;
case GEARMAN_SUCCESS:
$this->exitRequested = true;
break;
default:
if (@$options['debug'] === true)
echo "==> Worker failed: $code";
exit(1);
}
}
exit;
} else if ($pid > 0) {
$this->pids[] = $pid;
}
}
sleep(1);
}
} | php | public function start()
{
if (count($this->tasks) == 0)
throw new \Exception("There are no tasks defined - can not start");
$this->started = true;
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
fclose($fpPid);
if ($debug)
echo "==> Daemon already running" . PHP_EOL;
return $this;
}
if ($debug)
echo "==> Starting the daemon... " . PHP_EOL;
$fork = pcntl_fork();
if ($fork < 0)
throw new \Exception("fork() failed: $fork");
else if ($fork)
return $this;
ftruncate($fpPid, 0);
fwrite($fpPid, getmypid() . PHP_EOL);
fflush($fpPid);
chmod($pidFile, 0666);
declare(ticks = 1);
$exitCallback = function ($signo) use ($fpPid, $pidFile, $debug) {
if ($debug)
echo "==> Cleaning and exiting" . PHP_EOL;
foreach ($this->pids as $pid) {
if ($debug)
echo "==> Terminating worker PID $pid" . PHP_EOL;
posix_kill($pid, SIGTERM);
}
foreach ($this->pids as $pid)
pcntl_waitpid($pid, $status);
flock($fpPid, LOCK_UN);
fclose($fpPid);
@unlink($pidFile);
if ($debug)
echo "==> Daemon is shut down" . PHP_EOL;
exit;
};
pcntl_signal(SIGTERM, $exitCallback);
pcntl_signal(SIGINT, $exitCallback);
pcntl_signal_dispatch();
$sid = posix_setsid();
if ($sid < 0)
throw new \Exception("setsid() failed: $sid");
$gmWorker = new GearmanWorker();
$gmWorker->addServer($options['gearman']['host'], $options['gearman']['port']);
foreach ($this->tasks as $name => $object) {
$function = $options['namespace'] . '-' . $name;
$task = function ($job) use ($name, $function, $object, $options) {
if (@$options['debug'] === true)
echo "==> Running worker for: $function (PID " . getmypid() . ")" . PHP_EOL;
$worker = clone $object;
$data = json_decode($job->workload(), true);
$worker->setData($data);
if (@$options['debug'] !== true)
ob_start();
$worker->run($this->exitRequested);
if (@$options['debug'] !== true)
ob_end_clean();
};
$gmWorker->addFunction($function, $task);
}
while (true) {
$dead = pcntl_waitpid(-1, $status, WNOHANG);
while ($dead > 0) {
if (@$options['debug'] === true)
echo "==> Worker PID $dead terminated" . PHP_EOL;
$index = array_search($dead, $this->pids);
if ($index !== false)
unset($this->pids[$index]);
$dead = pcntl_waitpid(-1, $status, WNOHANG);
}
while (count($this->pids) < $options['num_workers']) {
$pid = pcntl_fork();
if ($pid == 0) {
declare(ticks = 1);
$exitCallback = function ($signo) {
$this->exitRequested = true;
};
pcntl_signal(SIGTERM, $exitCallback);
pcntl_signal(SIGINT, $exitCallback);
pcntl_signal_dispatch();
$this->pids = [];
$gmWorker->setTimeout(1000);
while (!$this->exitRequested) {
$gmWorker->work();
$code = $gmWorker->returnCode();
switch ($code) {
case GEARMAN_TIMEOUT:
sleep(1);
break;
case GEARMAN_SUCCESS:
$this->exitRequested = true;
break;
default:
if (@$options['debug'] === true)
echo "==> Worker failed: $code";
exit(1);
}
}
exit;
} else if ($pid > 0) {
$this->pids[] = $pid;
}
}
sleep(1);
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"tasks",
")",
"==",
"0",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There are no tasks defined - can not start\"",
")",
";",
"$",
"this",
"->",
"started",
"=",
"true",
";",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"$",
"pidFile",
"=",
"$",
"options",
"[",
"'pid_file'",
"]",
";",
"if",
"(",
"!",
"$",
"pidFile",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No pid_file in the config\"",
")",
";",
"$",
"fpPid",
"=",
"fopen",
"(",
"$",
"pidFile",
",",
"\"c\"",
")",
";",
"if",
"(",
"!",
"$",
"fpPid",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not open \"",
".",
"$",
"pidFile",
")",
";",
"if",
"(",
"!",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_EX",
"|",
"LOCK_NB",
")",
")",
"{",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Daemon already running\"",
".",
"PHP_EOL",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Starting the daemon... \"",
".",
"PHP_EOL",
";",
"$",
"fork",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"fork",
"<",
"0",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"fork() failed: $fork\"",
")",
";",
"else",
"if",
"(",
"$",
"fork",
")",
"return",
"$",
"this",
";",
"ftruncate",
"(",
"$",
"fpPid",
",",
"0",
")",
";",
"fwrite",
"(",
"$",
"fpPid",
",",
"getmypid",
"(",
")",
".",
"PHP_EOL",
")",
";",
"fflush",
"(",
"$",
"fpPid",
")",
";",
"chmod",
"(",
"$",
"pidFile",
",",
"0666",
")",
";",
"declare",
"(",
"ticks",
"=",
"1",
")",
";",
"$",
"exitCallback",
"=",
"function",
"(",
"$",
"signo",
")",
"use",
"(",
"$",
"fpPid",
",",
"$",
"pidFile",
",",
"$",
"debug",
")",
"{",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Cleaning and exiting\"",
".",
"PHP_EOL",
";",
"foreach",
"(",
"$",
"this",
"->",
"pids",
"as",
"$",
"pid",
")",
"{",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Terminating worker PID $pid\"",
".",
"PHP_EOL",
";",
"posix_kill",
"(",
"$",
"pid",
",",
"SIGTERM",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"pids",
"as",
"$",
"pid",
")",
"pcntl_waitpid",
"(",
"$",
"pid",
",",
"$",
"status",
")",
";",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"@",
"unlink",
"(",
"$",
"pidFile",
")",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Daemon is shut down\"",
".",
"PHP_EOL",
";",
"exit",
";",
"}",
";",
"pcntl_signal",
"(",
"SIGTERM",
",",
"$",
"exitCallback",
")",
";",
"pcntl_signal",
"(",
"SIGINT",
",",
"$",
"exitCallback",
")",
";",
"pcntl_signal_dispatch",
"(",
")",
";",
"$",
"sid",
"=",
"posix_setsid",
"(",
")",
";",
"if",
"(",
"$",
"sid",
"<",
"0",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"setsid() failed: $sid\"",
")",
";",
"$",
"gmWorker",
"=",
"new",
"GearmanWorker",
"(",
")",
";",
"$",
"gmWorker",
"->",
"addServer",
"(",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'host'",
"]",
",",
"$",
"options",
"[",
"'gearman'",
"]",
"[",
"'port'",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"tasks",
"as",
"$",
"name",
"=>",
"$",
"object",
")",
"{",
"$",
"function",
"=",
"$",
"options",
"[",
"'namespace'",
"]",
".",
"'-'",
".",
"$",
"name",
";",
"$",
"task",
"=",
"function",
"(",
"$",
"job",
")",
"use",
"(",
"$",
"name",
",",
"$",
"function",
",",
"$",
"object",
",",
"$",
"options",
")",
"{",
"if",
"(",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
")",
"echo",
"\"==> Running worker for: $function (PID \"",
".",
"getmypid",
"(",
")",
".",
"\")\"",
".",
"PHP_EOL",
";",
"$",
"worker",
"=",
"clone",
"$",
"object",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"job",
"->",
"workload",
"(",
")",
",",
"true",
")",
";",
"$",
"worker",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"if",
"(",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"!==",
"true",
")",
"ob_start",
"(",
")",
";",
"$",
"worker",
"->",
"run",
"(",
"$",
"this",
"->",
"exitRequested",
")",
";",
"if",
"(",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"!==",
"true",
")",
"ob_end_clean",
"(",
")",
";",
"}",
";",
"$",
"gmWorker",
"->",
"addFunction",
"(",
"$",
"function",
",",
"$",
"task",
")",
";",
"}",
"while",
"(",
"true",
")",
"{",
"$",
"dead",
"=",
"pcntl_waitpid",
"(",
"-",
"1",
",",
"$",
"status",
",",
"WNOHANG",
")",
";",
"while",
"(",
"$",
"dead",
">",
"0",
")",
"{",
"if",
"(",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
")",
"echo",
"\"==> Worker PID $dead terminated\"",
".",
"PHP_EOL",
";",
"$",
"index",
"=",
"array_search",
"(",
"$",
"dead",
",",
"$",
"this",
"->",
"pids",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"unset",
"(",
"$",
"this",
"->",
"pids",
"[",
"$",
"index",
"]",
")",
";",
"$",
"dead",
"=",
"pcntl_waitpid",
"(",
"-",
"1",
",",
"$",
"status",
",",
"WNOHANG",
")",
";",
"}",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"pids",
")",
"<",
"$",
"options",
"[",
"'num_workers'",
"]",
")",
"{",
"$",
"pid",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"$",
"pid",
"==",
"0",
")",
"{",
"declare",
"(",
"ticks",
"=",
"1",
")",
";",
"$",
"exitCallback",
"=",
"function",
"(",
"$",
"signo",
")",
"{",
"$",
"this",
"->",
"exitRequested",
"=",
"true",
";",
"}",
";",
"pcntl_signal",
"(",
"SIGTERM",
",",
"$",
"exitCallback",
")",
";",
"pcntl_signal",
"(",
"SIGINT",
",",
"$",
"exitCallback",
")",
";",
"pcntl_signal_dispatch",
"(",
")",
";",
"$",
"this",
"->",
"pids",
"=",
"[",
"]",
";",
"$",
"gmWorker",
"->",
"setTimeout",
"(",
"1000",
")",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"exitRequested",
")",
"{",
"$",
"gmWorker",
"->",
"work",
"(",
")",
";",
"$",
"code",
"=",
"$",
"gmWorker",
"->",
"returnCode",
"(",
")",
";",
"switch",
"(",
"$",
"code",
")",
"{",
"case",
"GEARMAN_TIMEOUT",
":",
"sleep",
"(",
"1",
")",
";",
"break",
";",
"case",
"GEARMAN_SUCCESS",
":",
"$",
"this",
"->",
"exitRequested",
"=",
"true",
";",
"break",
";",
"default",
":",
"if",
"(",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
")",
"echo",
"\"==> Worker failed: $code\"",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}",
"exit",
";",
"}",
"else",
"if",
"(",
"$",
"pid",
">",
"0",
")",
"{",
"$",
"this",
"->",
"pids",
"[",
"]",
"=",
"$",
"pid",
";",
"}",
"}",
"sleep",
"(",
"1",
")",
";",
"}",
"}"
] | Start the daemon with workers (by fork()ing)
@return TaskDaemon | [
"Start",
"the",
"daemon",
"with",
"workers",
"(",
"by",
"fork",
"()",
"ing",
")"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L207-L351 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.stop | public function stop()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (flock($fpPid, LOCK_EX | LOCK_NB)) {
flock($fpPid, LOCK_UN);
fclose($fpPid);
if ($debug)
echo "==> Daemon not running" . PHP_EOL;
return;
}
fclose($fpPid);
$pid = (int)file_get_contents($pidFile);
if ($debug)
echo "==> Killing the daemon (PID $pid)..." . PHP_EOL;
posix_kill($pid, SIGTERM);
pcntl_waitpid($pid, $status);
} | php | public function stop()
{
$options = static::getOptions();
$debug = @$options['debug'] === true;
$pidFile = $options['pid_file'];
if (!$pidFile)
throw new \Exception("No pid_file in the config");
$fpPid = fopen($pidFile, "c");
if (!$fpPid)
throw new \Exception("Could not open " . $pidFile);
if (flock($fpPid, LOCK_EX | LOCK_NB)) {
flock($fpPid, LOCK_UN);
fclose($fpPid);
if ($debug)
echo "==> Daemon not running" . PHP_EOL;
return;
}
fclose($fpPid);
$pid = (int)file_get_contents($pidFile);
if ($debug)
echo "==> Killing the daemon (PID $pid)..." . PHP_EOL;
posix_kill($pid, SIGTERM);
pcntl_waitpid($pid, $status);
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
")",
";",
"$",
"debug",
"=",
"@",
"$",
"options",
"[",
"'debug'",
"]",
"===",
"true",
";",
"$",
"pidFile",
"=",
"$",
"options",
"[",
"'pid_file'",
"]",
";",
"if",
"(",
"!",
"$",
"pidFile",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No pid_file in the config\"",
")",
";",
"$",
"fpPid",
"=",
"fopen",
"(",
"$",
"pidFile",
",",
"\"c\"",
")",
";",
"if",
"(",
"!",
"$",
"fpPid",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not open \"",
".",
"$",
"pidFile",
")",
";",
"if",
"(",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_EX",
"|",
"LOCK_NB",
")",
")",
"{",
"flock",
"(",
"$",
"fpPid",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Daemon not running\"",
".",
"PHP_EOL",
";",
"return",
";",
"}",
"fclose",
"(",
"$",
"fpPid",
")",
";",
"$",
"pid",
"=",
"(",
"int",
")",
"file_get_contents",
"(",
"$",
"pidFile",
")",
";",
"if",
"(",
"$",
"debug",
")",
"echo",
"\"==> Killing the daemon (PID $pid)...\"",
".",
"PHP_EOL",
";",
"posix_kill",
"(",
"$",
"pid",
",",
"SIGTERM",
")",
";",
"pcntl_waitpid",
"(",
"$",
"pid",
",",
"$",
"status",
")",
";",
"}"
] | Stop the daemon
@return TaskDaemon | [
"Stop",
"the",
"daemon"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L358-L386 |
basarevych/task-daemon | library/TaskDaemon/TaskDaemon.php | TaskDaemon.restart | public function restart()
{
if (count($this->tasks) == 0)
throw new \Exception("There are no tasks defined - can not restart");
$this->stop();
do {
sleep(1);
} while ($this->getPid() !== false);
$this->start();
} | php | public function restart()
{
if (count($this->tasks) == 0)
throw new \Exception("There are no tasks defined - can not restart");
$this->stop();
do {
sleep(1);
} while ($this->getPid() !== false);
$this->start();
} | [
"public",
"function",
"restart",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"tasks",
")",
"==",
"0",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There are no tasks defined - can not restart\"",
")",
";",
"$",
"this",
"->",
"stop",
"(",
")",
";",
"do",
"{",
"sleep",
"(",
"1",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"getPid",
"(",
")",
"!==",
"false",
")",
";",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}"
] | Restart the daemon
@return TaskDaemon | [
"Restart",
"the",
"daemon"
] | train | https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L393-L405 |
sparwelt/imgix-lib | src/Components/CdnSelector.php | CdnSelector.getCdnForImage | public function getCdnForImage($originalUr)
{
if (0 === strpos($originalUr, 'data:')) {
throw new ResolutionException('Encoded image are not resolvable');
}
foreach ($this->cdnConfigurations as $configuration) {
$originalPath = parse_url($originalUr, PHP_URL_PATH);
$originalHost = parse_url($originalUr, PHP_URL_HOST);
if (null === $originalPath) {
throw new ResolutionException('Image has no path');
}
if (!$this->isDomainMatch($originalHost, $configuration->getSourceDomains())) {
continue;
}
if (!$this->isPatternMatch($configuration, $originalPath)) {
continue;
}
return $configuration;
}
throw new ResolutionException(sprintf('Cannot find cdn configuration match for image %s', $originalUr));
} | php | public function getCdnForImage($originalUr)
{
if (0 === strpos($originalUr, 'data:')) {
throw new ResolutionException('Encoded image are not resolvable');
}
foreach ($this->cdnConfigurations as $configuration) {
$originalPath = parse_url($originalUr, PHP_URL_PATH);
$originalHost = parse_url($originalUr, PHP_URL_HOST);
if (null === $originalPath) {
throw new ResolutionException('Image has no path');
}
if (!$this->isDomainMatch($originalHost, $configuration->getSourceDomains())) {
continue;
}
if (!$this->isPatternMatch($configuration, $originalPath)) {
continue;
}
return $configuration;
}
throw new ResolutionException(sprintf('Cannot find cdn configuration match for image %s', $originalUr));
} | [
"public",
"function",
"getCdnForImage",
"(",
"$",
"originalUr",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"originalUr",
",",
"'data:'",
")",
")",
"{",
"throw",
"new",
"ResolutionException",
"(",
"'Encoded image are not resolvable'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"cdnConfigurations",
"as",
"$",
"configuration",
")",
"{",
"$",
"originalPath",
"=",
"parse_url",
"(",
"$",
"originalUr",
",",
"PHP_URL_PATH",
")",
";",
"$",
"originalHost",
"=",
"parse_url",
"(",
"$",
"originalUr",
",",
"PHP_URL_HOST",
")",
";",
"if",
"(",
"null",
"===",
"$",
"originalPath",
")",
"{",
"throw",
"new",
"ResolutionException",
"(",
"'Image has no path'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isDomainMatch",
"(",
"$",
"originalHost",
",",
"$",
"configuration",
"->",
"getSourceDomains",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isPatternMatch",
"(",
"$",
"configuration",
",",
"$",
"originalPath",
")",
")",
"{",
"continue",
";",
"}",
"return",
"$",
"configuration",
";",
"}",
"throw",
"new",
"ResolutionException",
"(",
"sprintf",
"(",
"'Cannot find cdn configuration match for image %s'",
",",
"$",
"originalUr",
")",
")",
";",
"}"
] | @param string $originalUr
@return CdnConfiguration
@throws \Sparwelt\ImgixLib\Exception\ResolutionException | [
"@param",
"string",
"$originalUr"
] | train | https://github.com/sparwelt/imgix-lib/blob/330e1db2bed71bc283e5a2da6246528f240939ec/src/Components/CdnSelector.php#L32-L58 |
sparwelt/imgix-lib | src/Components/CdnSelector.php | CdnSelector.isDomainMatch | private function isDomainMatch($imageHost, array $sourceDomains)
{
if (null === $imageHost) {
return empty($sourceDomains) || in_array(null, $sourceDomains);
}
if (in_array($imageHost, $sourceDomains)) {
return true;
}
// check sub domain
$imageDomainParts = explode('.', $imageHost, 2);
if (isset($imageDomainParts[1]) && in_array($imageDomainParts[1], $sourceDomains)) {
return true;
}
return false;
} | php | private function isDomainMatch($imageHost, array $sourceDomains)
{
if (null === $imageHost) {
return empty($sourceDomains) || in_array(null, $sourceDomains);
}
if (in_array($imageHost, $sourceDomains)) {
return true;
}
// check sub domain
$imageDomainParts = explode('.', $imageHost, 2);
if (isset($imageDomainParts[1]) && in_array($imageDomainParts[1], $sourceDomains)) {
return true;
}
return false;
} | [
"private",
"function",
"isDomainMatch",
"(",
"$",
"imageHost",
",",
"array",
"$",
"sourceDomains",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"imageHost",
")",
"{",
"return",
"empty",
"(",
"$",
"sourceDomains",
")",
"||",
"in_array",
"(",
"null",
",",
"$",
"sourceDomains",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"imageHost",
",",
"$",
"sourceDomains",
")",
")",
"{",
"return",
"true",
";",
"}",
"// check sub domain",
"$",
"imageDomainParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"imageHost",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"imageDomainParts",
"[",
"1",
"]",
")",
"&&",
"in_array",
"(",
"$",
"imageDomainParts",
"[",
"1",
"]",
",",
"$",
"sourceDomains",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | @param string $imageHost
@param array $sourceDomains
@return bool | [
"@param",
"string",
"$imageHost",
"@param",
"array",
"$sourceDomains"
] | train | https://github.com/sparwelt/imgix-lib/blob/330e1db2bed71bc283e5a2da6246528f240939ec/src/Components/CdnSelector.php#L66-L83 |
sparwelt/imgix-lib | src/Components/CdnSelector.php | CdnSelector.isPatternMatch | protected function isPatternMatch(CdnConfiguration $configuration, $imagePath)
{
if (empty($configuration->getPathPatterns())) {
return true;
}
foreach ($configuration->getPathPatterns() as $pattern) {
if (preg_match(sprintf('~%s~', $pattern), $imagePath)) {
return true;
}
}
return false;
} | php | protected function isPatternMatch(CdnConfiguration $configuration, $imagePath)
{
if (empty($configuration->getPathPatterns())) {
return true;
}
foreach ($configuration->getPathPatterns() as $pattern) {
if (preg_match(sprintf('~%s~', $pattern), $imagePath)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"isPatternMatch",
"(",
"CdnConfiguration",
"$",
"configuration",
",",
"$",
"imagePath",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"configuration",
"->",
"getPathPatterns",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"configuration",
"->",
"getPathPatterns",
"(",
")",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"sprintf",
"(",
"'~%s~'",
",",
"$",
"pattern",
")",
",",
"$",
"imagePath",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param CdnConfiguration $configuration
@param string $imagePath
@return bool | [
"@param",
"CdnConfiguration",
"$configuration",
"@param",
"string",
"$imagePath"
] | train | https://github.com/sparwelt/imgix-lib/blob/330e1db2bed71bc283e5a2da6246528f240939ec/src/Components/CdnSelector.php#L91-L104 |
ruvents/ruwork-upload-bundle | Form/Saver/Saver.php | Saver.save | public function save(): void
{
/** @var FormInterface $form */
foreach ($this->storage as $key => [$form, $saver]) {
unset($this->storage[$key]);
$upload = $form->getData();
if (null === $upload || !$form->isValid() || $form->getRoot()->isValid()) {
continue;
}
$saver($upload, $form);
}
} | php | public function save(): void
{
/** @var FormInterface $form */
foreach ($this->storage as $key => [$form, $saver]) {
unset($this->storage[$key]);
$upload = $form->getData();
if (null === $upload || !$form->isValid() || $form->getRoot()->isValid()) {
continue;
}
$saver($upload, $form);
}
} | [
"public",
"function",
"save",
"(",
")",
":",
"void",
"{",
"/** @var FormInterface $form */",
"foreach",
"(",
"$",
"this",
"->",
"storage",
"as",
"$",
"key",
"=>",
"[",
"$",
"form",
",",
"$",
"saver",
"]",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"storage",
"[",
"$",
"key",
"]",
")",
";",
"$",
"upload",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"upload",
"||",
"!",
"$",
"form",
"->",
"isValid",
"(",
")",
"||",
"$",
"form",
"->",
"getRoot",
"(",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"saver",
"(",
"$",
"upload",
",",
"$",
"form",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/Form/Saver/Saver.php#L24-L38 |
inpsyde/inpsyde-filter | src/WordPress/SanitizeTextField.php | SanitizeTextField.filter | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return sanitize_text_field( $value );
} | php | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
return sanitize_text_field( $value );
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not string or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"return",
"sanitize_text_field",
"(",
"$",
"value",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/SanitizeTextField.php#L18-L27 |
phpmob/changmin | src/PhpMob/CmsBundle/Twig/TemplateLoader.php | TemplateLoader.exists | public function exists($name)
{
$name = (string)$name;
if (isset($this->hits[$name])) {
return true;
}
try {
$this->hits[$name] = $this->findTemplate($name);
} catch (\Twig_Error_Loader $e) {
return false;
}
return true;
} | php | public function exists($name)
{
$name = (string)$name;
if (isset($this->hits[$name])) {
return true;
}
try {
$this->hits[$name] = $this->findTemplate($name);
} catch (\Twig_Error_Loader $e) {
return false;
}
return true;
} | [
"public",
"function",
"exists",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"(",
"string",
")",
"$",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hits",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"hits",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"findTemplate",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"\\",
"Twig_Error_Loader",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Twig/TemplateLoader.php#L80-L95 |
phpmob/changmin | src/PhpMob/CmsBundle/Twig/TemplateLoader.php | TemplateLoader.getLastUpdated | private function getLastUpdated(string $name)
{
if (!isset($this->hits[$name])) {
$this->hits[$name] = $this->findTemplate($name);
}
return $this->hits[$name]
->getUpdatedAt()
->getTimestamp();
} | php | private function getLastUpdated(string $name)
{
if (!isset($this->hits[$name])) {
$this->hits[$name] = $this->findTemplate($name);
}
return $this->hits[$name]
->getUpdatedAt()
->getTimestamp();
} | [
"private",
"function",
"getLastUpdated",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"hits",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"hits",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"findTemplate",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"hits",
"[",
"$",
"name",
"]",
"->",
"getUpdatedAt",
"(",
")",
"->",
"getTimestamp",
"(",
")",
";",
"}"
] | @param $name
@return integer | [
"@param",
"$name"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Twig/TemplateLoader.php#L102-L111 |
phpmob/changmin | src/PhpMob/CmsBundle/Twig/TemplateLoader.php | TemplateLoader.findTemplate | private function findTemplate(string $name)
{
if (!preg_match(sprintf('|^%s|', preg_quote(self::PREFIX)), $name)) {
$prefix = self::PREFIX;
throw new \Twig_Error_Loader("Only supported template starts with $prefix.");
}
if ($template = $this->repository->findTemplate($this->getTemplateName($name))) {
$this->definedTranslation->addTranslations($template);
return $template;
}
throw new \Twig_Error_Loader("Not found template named $name.");
} | php | private function findTemplate(string $name)
{
if (!preg_match(sprintf('|^%s|', preg_quote(self::PREFIX)), $name)) {
$prefix = self::PREFIX;
throw new \Twig_Error_Loader("Only supported template starts with $prefix.");
}
if ($template = $this->repository->findTemplate($this->getTemplateName($name))) {
$this->definedTranslation->addTranslations($template);
return $template;
}
throw new \Twig_Error_Loader("Not found template named $name.");
} | [
"private",
"function",
"findTemplate",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"sprintf",
"(",
"'|^%s|'",
",",
"preg_quote",
"(",
"self",
"::",
"PREFIX",
")",
")",
",",
"$",
"name",
")",
")",
"{",
"$",
"prefix",
"=",
"self",
"::",
"PREFIX",
";",
"throw",
"new",
"\\",
"Twig_Error_Loader",
"(",
"\"Only supported template starts with $prefix.\"",
")",
";",
"}",
"if",
"(",
"$",
"template",
"=",
"$",
"this",
"->",
"repository",
"->",
"findTemplate",
"(",
"$",
"this",
"->",
"getTemplateName",
"(",
"$",
"name",
")",
")",
")",
"{",
"$",
"this",
"->",
"definedTranslation",
"->",
"addTranslations",
"(",
"$",
"template",
")",
";",
"return",
"$",
"template",
";",
"}",
"throw",
"new",
"\\",
"Twig_Error_Loader",
"(",
"\"Not found template named $name.\"",
")",
";",
"}"
] | @param string $name
@return null|object|TemplateInterface
@throws \Twig_Error_Loader | [
"@param",
"string",
"$name"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Twig/TemplateLoader.php#L129-L143 |
PortaText/php-sdk | src/PortaText/Command/Api/Campaigns.php | Campaigns.getEndpoint | protected function getEndpoint($method)
{
$endpoint = "campaigns";
$campaignId = $this->getArgument("id");
if (!is_null($campaignId)) {
$endpoint .= "/$campaignId";
$this->delArgument("id");
$this->delArgument("type");
}
$contacts = $this->getArgument("contacts");
if (!is_null($contacts)) {
$endpoint .= "/contacts";
$this->delArgument("contacts");
}
$file = $this->getArgument("file");
if (!is_null($file)) {
$args = $this->getArguments();
unset($args['file']);
$args = array(
'settings' => json_encode($args)
);
$endpoint = $endpoint . '?' . http_build_query($args);
}
$contact = $this->getArgument("contact");
if (!is_null($contact)) {
$endpoint .= "/contacts/$contact";
$this->delArgument("contact");
}
$queryString = array();
$page = $this->getArgument("page");
if (!is_null($page)) {
$queryString['page'] = $page;
$this->delArgument("page");
}
if (!empty($queryString)) {
$queryString = http_build_query($queryString);
return "$endpoint?$queryString";
}
return $endpoint;
} | php | protected function getEndpoint($method)
{
$endpoint = "campaigns";
$campaignId = $this->getArgument("id");
if (!is_null($campaignId)) {
$endpoint .= "/$campaignId";
$this->delArgument("id");
$this->delArgument("type");
}
$contacts = $this->getArgument("contacts");
if (!is_null($contacts)) {
$endpoint .= "/contacts";
$this->delArgument("contacts");
}
$file = $this->getArgument("file");
if (!is_null($file)) {
$args = $this->getArguments();
unset($args['file']);
$args = array(
'settings' => json_encode($args)
);
$endpoint = $endpoint . '?' . http_build_query($args);
}
$contact = $this->getArgument("contact");
if (!is_null($contact)) {
$endpoint .= "/contacts/$contact";
$this->delArgument("contact");
}
$queryString = array();
$page = $this->getArgument("page");
if (!is_null($page)) {
$queryString['page'] = $page;
$this->delArgument("page");
}
if (!empty($queryString)) {
$queryString = http_build_query($queryString);
return "$endpoint?$queryString";
}
return $endpoint;
} | [
"protected",
"function",
"getEndpoint",
"(",
"$",
"method",
")",
"{",
"$",
"endpoint",
"=",
"\"campaigns\"",
";",
"$",
"campaignId",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"id\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"campaignId",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/$campaignId\"",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"id\"",
")",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"type\"",
")",
";",
"}",
"$",
"contacts",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"contacts\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"contacts",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/contacts\"",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"contacts\"",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"file\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"unset",
"(",
"$",
"args",
"[",
"'file'",
"]",
")",
";",
"$",
"args",
"=",
"array",
"(",
"'settings'",
"=>",
"json_encode",
"(",
"$",
"args",
")",
")",
";",
"$",
"endpoint",
"=",
"$",
"endpoint",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"args",
")",
";",
"}",
"$",
"contact",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"contact\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"contact",
")",
")",
"{",
"$",
"endpoint",
".=",
"\"/contacts/$contact\"",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"contact\"",
")",
";",
"}",
"$",
"queryString",
"=",
"array",
"(",
")",
";",
"$",
"page",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"page\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"$",
"queryString",
"[",
"'page'",
"]",
"=",
"$",
"page",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"page\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"queryString",
")",
")",
"{",
"$",
"queryString",
"=",
"http_build_query",
"(",
"$",
"queryString",
")",
";",
"return",
"\"$endpoint?$queryString\"",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
] | Returns a string with the endpoint for the given command.
@param string $method Method for this command.
@return string | [
"Returns",
"a",
"string",
"with",
"the",
"endpoint",
"for",
"the",
"given",
"command",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Campaigns.php#L173-L212 |
PortaText/php-sdk | src/PortaText/Command/Api/Campaigns.php | Campaigns.setSetting | protected function setSetting($name, $value)
{
$args = $this->getArgument("settings");
if (is_null($args)) {
$args = array();
}
$args[$name] = $value;
return $this->setArgument("settings", $args);
} | php | protected function setSetting($name, $value)
{
$args = $this->getArgument("settings");
if (is_null($args)) {
$args = array();
}
$args[$name] = $value;
return $this->setArgument("settings", $args);
} | [
"protected",
"function",
"setSetting",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"settings\"",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"}",
"$",
"args",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"setArgument",
"(",
"\"settings\"",
",",
"$",
"args",
")",
";",
"}"
] | Set a campaign setting.
@param string $name Setting name.
@param mixed $value Setting value.
@return PortaText\Command\ICommand | [
"Set",
"a",
"campaign",
"setting",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Campaigns.php#L222-L230 |
cordoval/TodoList | lib/Fazer/TodoList.php | TodoList.initSQLs | private function initSQLs($listName)
{
$this->create = 'CREATE TABLE IF NOT EXISTS '.$listName.' (name VARCHAR(32) PRIMARY KEY, status INT)';
$this->select = 'SELECT * FROM '.$listName;
$this->insert = 'INSERT INTO '.$listName.' VALUES (?,?)';
$this->update = 'UPDATE '.$listName.' SET status = ? WHERE name = ?';
$this->delete = 'DELETE FROM '.$listName.' WHERE name = ?';
} | php | private function initSQLs($listName)
{
$this->create = 'CREATE TABLE IF NOT EXISTS '.$listName.' (name VARCHAR(32) PRIMARY KEY, status INT)';
$this->select = 'SELECT * FROM '.$listName;
$this->insert = 'INSERT INTO '.$listName.' VALUES (?,?)';
$this->update = 'UPDATE '.$listName.' SET status = ? WHERE name = ?';
$this->delete = 'DELETE FROM '.$listName.' WHERE name = ?';
} | [
"private",
"function",
"initSQLs",
"(",
"$",
"listName",
")",
"{",
"$",
"this",
"->",
"create",
"=",
"'CREATE TABLE IF NOT EXISTS '",
".",
"$",
"listName",
".",
"' (name VARCHAR(32) PRIMARY KEY, status INT)'",
";",
"$",
"this",
"->",
"select",
"=",
"'SELECT * FROM '",
".",
"$",
"listName",
";",
"$",
"this",
"->",
"insert",
"=",
"'INSERT INTO '",
".",
"$",
"listName",
".",
"' VALUES (?,?)'",
";",
"$",
"this",
"->",
"update",
"=",
"'UPDATE '",
".",
"$",
"listName",
".",
"' SET status = ? WHERE name = ?'",
";",
"$",
"this",
"->",
"delete",
"=",
"'DELETE FROM '",
".",
"$",
"listName",
".",
"' WHERE name = ?'",
";",
"}"
] | initialize SQLs
@param $listName | [
"initialize",
"SQLs"
] | train | https://github.com/cordoval/TodoList/blob/a7864768e99c0c2f7ea1f7b6a5186cfeed1c0011/lib/Fazer/TodoList.php#L47-L54 |
phpmob/changmin | src/PhpMob/MediaBundle/Model/File.php | File.setFile | public function setFile(\SplFileInfo $file)
{
$this->file = $file;
$this->updatedAt = new \DateTime();
if ($this->owner) {
$this->owner->setUpdatedAt($this->updatedAt);
$this->basePath = $this->owner->getFileBasePath();
}
} | php | public function setFile(\SplFileInfo $file)
{
$this->file = $file;
$this->updatedAt = new \DateTime();
if ($this->owner) {
$this->owner->setUpdatedAt($this->updatedAt);
$this->basePath = $this->owner->getFileBasePath();
}
} | [
"public",
"function",
"setFile",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"updatedAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"owner",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"setUpdatedAt",
"(",
"$",
"this",
"->",
"updatedAt",
")",
";",
"$",
"this",
"->",
"basePath",
"=",
"$",
"this",
"->",
"owner",
"->",
"getFileBasePath",
"(",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/MediaBundle/Model/File.php#L84-L93 |
phpmob/changmin | src/PhpMob/MediaBundle/Model/File.php | File.setOwner | public function setOwner(FileAwareInterface $owner)
{
$this->owner = $owner;
$this->basePath = $owner->getFileBasePath();
$owner->setUpdatedAt($this->updatedAt = new \DateTime());
} | php | public function setOwner(FileAwareInterface $owner)
{
$this->owner = $owner;
$this->basePath = $owner->getFileBasePath();
$owner->setUpdatedAt($this->updatedAt = new \DateTime());
} | [
"public",
"function",
"setOwner",
"(",
"FileAwareInterface",
"$",
"owner",
")",
"{",
"$",
"this",
"->",
"owner",
"=",
"$",
"owner",
";",
"$",
"this",
"->",
"basePath",
"=",
"$",
"owner",
"->",
"getFileBasePath",
"(",
")",
";",
"$",
"owner",
"->",
"setUpdatedAt",
"(",
"$",
"this",
"->",
"updatedAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/MediaBundle/Model/File.php#L154-L159 |
benmanu/silverstripe-knowledgebase | code/controller/KnowledgebasePage_Controller.php | KnowledgebasePage_Controller.getSearchQuery | protected function getSearchQuery($keywords)
{
$query = parent::getSearchQuery($keywords);
// add hook to modify search query
$this->extend('updateSearchQuery', $query);
return $query;
} | php | protected function getSearchQuery($keywords)
{
$query = parent::getSearchQuery($keywords);
// add hook to modify search query
$this->extend('updateSearchQuery', $query);
return $query;
} | [
"protected",
"function",
"getSearchQuery",
"(",
"$",
"keywords",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"getSearchQuery",
"(",
"$",
"keywords",
")",
";",
"// add hook to modify search query",
"$",
"this",
"->",
"extend",
"(",
"'updateSearchQuery'",
",",
"$",
"query",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Builds a search query from a given search term.
Also has an extension hook which allows you to modify the parameters
of the query.
@param string $keywords
@return SearchQuery | [
"Builds",
"a",
"search",
"query",
"from",
"a",
"given",
"search",
"term",
"."
] | train | https://github.com/benmanu/silverstripe-knowledgebase/blob/db19bfd4836f43da17ab52e8b53e72a11be64210/code/controller/KnowledgebasePage_Controller.php#L34-L42 |
benmanu/silverstripe-knowledgebase | code/controller/KnowledgebasePage_Controller.php | KnowledgebasePage_Controller.parseSearchResults | protected function parseSearchResults($results, $suggestion, $keywords)
{
$renderData = parent::parseSearchResults($results, $suggestion, $keywords);
// adding hook to allow checks or additional data to be passed to the Search Results
$this->extend('updateParseSearchResults', $renderData);
return $renderData;
} | php | protected function parseSearchResults($results, $suggestion, $keywords)
{
$renderData = parent::parseSearchResults($results, $suggestion, $keywords);
// adding hook to allow checks or additional data to be passed to the Search Results
$this->extend('updateParseSearchResults', $renderData);
return $renderData;
} | [
"protected",
"function",
"parseSearchResults",
"(",
"$",
"results",
",",
"$",
"suggestion",
",",
"$",
"keywords",
")",
"{",
"$",
"renderData",
"=",
"parent",
"::",
"parseSearchResults",
"(",
"$",
"results",
",",
"$",
"suggestion",
",",
"$",
"keywords",
")",
";",
"// adding hook to allow checks or additional data to be passed to the Search Results",
"$",
"this",
"->",
"extend",
"(",
"'updateParseSearchResults'",
",",
"$",
"renderData",
")",
";",
"return",
"$",
"renderData",
";",
"}"
] | Overloading view method purely to provide a hook for others to add extra
checks or pass additional data to the Search Results.
@param array $results
@param array $suggestion
@param string $keywords
@return array | [
"Overloading",
"view",
"method",
"purely",
"to",
"provide",
"a",
"hook",
"for",
"others",
"to",
"add",
"extra",
"checks",
"or",
"pass",
"additional",
"data",
"to",
"the",
"Search",
"Results",
"."
] | train | https://github.com/benmanu/silverstripe-knowledgebase/blob/db19bfd4836f43da17ab52e8b53e72a11be64210/code/controller/KnowledgebasePage_Controller.php#L70-L78 |
ruvents/ruwork-upload-bundle | Metadata/MetadataFactory.php | MetadataFactory.getMetadata | public function getMetadata(string $class): Metadata
{
$reflection = new \ReflectionClass($class);
$pathProperty = null;
$attributes = [];
foreach ($reflection->getProperties() as $reflectionProperty) {
$property = $reflectionProperty->getName();
foreach ($this->annotationsReader->getPropertyAnnotations($reflectionProperty) as $annotation) {
if ($annotation instanceof Path) {
$pathProperty = $property;
} elseif ($annotation instanceof Attribute) {
$attributes[$property] = $annotation;
}
}
}
if (null === $pathProperty) {
throw new NotMappedException(sprintf('Upload class "%s" must have a @Path property.', $class));
}
return new Metadata($class, $pathProperty, $attributes);
} | php | public function getMetadata(string $class): Metadata
{
$reflection = new \ReflectionClass($class);
$pathProperty = null;
$attributes = [];
foreach ($reflection->getProperties() as $reflectionProperty) {
$property = $reflectionProperty->getName();
foreach ($this->annotationsReader->getPropertyAnnotations($reflectionProperty) as $annotation) {
if ($annotation instanceof Path) {
$pathProperty = $property;
} elseif ($annotation instanceof Attribute) {
$attributes[$property] = $annotation;
}
}
}
if (null === $pathProperty) {
throw new NotMappedException(sprintf('Upload class "%s" must have a @Path property.', $class));
}
return new Metadata($class, $pathProperty, $attributes);
} | [
"public",
"function",
"getMetadata",
"(",
"string",
"$",
"class",
")",
":",
"Metadata",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"pathProperty",
"=",
"null",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"reflection",
"->",
"getProperties",
"(",
")",
"as",
"$",
"reflectionProperty",
")",
"{",
"$",
"property",
"=",
"$",
"reflectionProperty",
"->",
"getName",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"annotationsReader",
"->",
"getPropertyAnnotations",
"(",
"$",
"reflectionProperty",
")",
"as",
"$",
"annotation",
")",
"{",
"if",
"(",
"$",
"annotation",
"instanceof",
"Path",
")",
"{",
"$",
"pathProperty",
"=",
"$",
"property",
";",
"}",
"elseif",
"(",
"$",
"annotation",
"instanceof",
"Attribute",
")",
"{",
"$",
"attributes",
"[",
"$",
"property",
"]",
"=",
"$",
"annotation",
";",
"}",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"pathProperty",
")",
"{",
"throw",
"new",
"NotMappedException",
"(",
"sprintf",
"(",
"'Upload class \"%s\" must have a @Path property.'",
",",
"$",
"class",
")",
")",
";",
"}",
"return",
"new",
"Metadata",
"(",
"$",
"class",
",",
"$",
"pathProperty",
",",
"$",
"attributes",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/Metadata/MetadataFactory.php#L24-L47 |
phrest/sdk | src/PhrestSDK.php | PhrestSDK.setApp | public function setApp(PhrestAPI $app)
{
$this->app = $app;
$this->app->isInternalRequest = true;
return $this;
} | php | public function setApp(PhrestAPI $app)
{
$this->app = $app;
$this->app->isInternalRequest = true;
return $this;
} | [
"public",
"function",
"setApp",
"(",
"PhrestAPI",
"$",
"app",
")",
"{",
"$",
"this",
"->",
"app",
"=",
"$",
"app",
";",
"$",
"this",
"->",
"app",
"->",
"isInternalRequest",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] | Set the API instance
@param PhrestAPI $app
@return $this | [
"Set",
"the",
"API",
"instance"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L87-L93 |
phrest/sdk | src/PhrestSDK.php | PhrestSDK.getRawResponse | private function getRawResponse(
$method,
$path,
RequestOptions $options = null
)
{
// Backup super globals
$request = $_REQUEST;
$post = $_POST;
$get = $_GET;
$server = $_SERVER;
// Override the request params
$_GET = $options ? $options->getGetParams() : [];
$_POST = $options ? $options->getPostParams() : [];
// Set HTTP method in GET
$_GET['method'] = $method;
$_GET['_url'] = $path;
$_REQUEST = ['type' => 'raw']; // todo is this requred?
// This is required for phalcon 3
$_SERVER['REQUEST_METHOD'] = $method;
// Get current DI
$defaultDI = DI::getDefault();
if ($defaultDI instanceof PhrestDI)
{
$apiDI = $defaultDI;
}
else
{
// Set API DI to the default, this is required for models etc.
// As Phalcon will get the default DI to perform actions
$apiDI = self::getInstance()->app->getDI();
DI::setDefault($apiDI);
}
// Cache the URI & method
self::$uri = $path;
self::$method = $method;
// Get response from API
// todo post not picked up
try
{
$response = $this->app->handle($path);
}
catch (\Exception $e)
{
DI::setDefault($defaultDI);
throw $e;
}
// Remove cached uri & method
self::$uri = null;
self::$method = null;
// Restore default DI
if (!$defaultDI instanceof PhrestDI)
{
DI::setDefault($defaultDI);
}
// Restore super globals
$_REQUEST = $request;
$_POST = $post;
$_GET = $get;
$_SERVER = $server;
return $response;
} | php | private function getRawResponse(
$method,
$path,
RequestOptions $options = null
)
{
// Backup super globals
$request = $_REQUEST;
$post = $_POST;
$get = $_GET;
$server = $_SERVER;
// Override the request params
$_GET = $options ? $options->getGetParams() : [];
$_POST = $options ? $options->getPostParams() : [];
// Set HTTP method in GET
$_GET['method'] = $method;
$_GET['_url'] = $path;
$_REQUEST = ['type' => 'raw']; // todo is this requred?
// This is required for phalcon 3
$_SERVER['REQUEST_METHOD'] = $method;
// Get current DI
$defaultDI = DI::getDefault();
if ($defaultDI instanceof PhrestDI)
{
$apiDI = $defaultDI;
}
else
{
// Set API DI to the default, this is required for models etc.
// As Phalcon will get the default DI to perform actions
$apiDI = self::getInstance()->app->getDI();
DI::setDefault($apiDI);
}
// Cache the URI & method
self::$uri = $path;
self::$method = $method;
// Get response from API
// todo post not picked up
try
{
$response = $this->app->handle($path);
}
catch (\Exception $e)
{
DI::setDefault($defaultDI);
throw $e;
}
// Remove cached uri & method
self::$uri = null;
self::$method = null;
// Restore default DI
if (!$defaultDI instanceof PhrestDI)
{
DI::setDefault($defaultDI);
}
// Restore super globals
$_REQUEST = $request;
$_POST = $post;
$_GET = $get;
$_SERVER = $server;
return $response;
} | [
"private",
"function",
"getRawResponse",
"(",
"$",
"method",
",",
"$",
"path",
",",
"RequestOptions",
"$",
"options",
"=",
"null",
")",
"{",
"// Backup super globals",
"$",
"request",
"=",
"$",
"_REQUEST",
";",
"$",
"post",
"=",
"$",
"_POST",
";",
"$",
"get",
"=",
"$",
"_GET",
";",
"$",
"server",
"=",
"$",
"_SERVER",
";",
"// Override the request params",
"$",
"_GET",
"=",
"$",
"options",
"?",
"$",
"options",
"->",
"getGetParams",
"(",
")",
":",
"[",
"]",
";",
"$",
"_POST",
"=",
"$",
"options",
"?",
"$",
"options",
"->",
"getPostParams",
"(",
")",
":",
"[",
"]",
";",
"// Set HTTP method in GET",
"$",
"_GET",
"[",
"'method'",
"]",
"=",
"$",
"method",
";",
"$",
"_GET",
"[",
"'_url'",
"]",
"=",
"$",
"path",
";",
"$",
"_REQUEST",
"=",
"[",
"'type'",
"=>",
"'raw'",
"]",
";",
"// todo is this requred?",
"// This is required for phalcon 3",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"=",
"$",
"method",
";",
"// Get current DI",
"$",
"defaultDI",
"=",
"DI",
"::",
"getDefault",
"(",
")",
";",
"if",
"(",
"$",
"defaultDI",
"instanceof",
"PhrestDI",
")",
"{",
"$",
"apiDI",
"=",
"$",
"defaultDI",
";",
"}",
"else",
"{",
"// Set API DI to the default, this is required for models etc.",
"// As Phalcon will get the default DI to perform actions",
"$",
"apiDI",
"=",
"self",
"::",
"getInstance",
"(",
")",
"->",
"app",
"->",
"getDI",
"(",
")",
";",
"DI",
"::",
"setDefault",
"(",
"$",
"apiDI",
")",
";",
"}",
"// Cache the URI & method",
"self",
"::",
"$",
"uri",
"=",
"$",
"path",
";",
"self",
"::",
"$",
"method",
"=",
"$",
"method",
";",
"// Get response from API",
"// todo post not picked up",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"app",
"->",
"handle",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"DI",
"::",
"setDefault",
"(",
"$",
"defaultDI",
")",
";",
"throw",
"$",
"e",
";",
"}",
"// Remove cached uri & method",
"self",
"::",
"$",
"uri",
"=",
"null",
";",
"self",
"::",
"$",
"method",
"=",
"null",
";",
"// Restore default DI",
"if",
"(",
"!",
"$",
"defaultDI",
"instanceof",
"PhrestDI",
")",
"{",
"DI",
"::",
"setDefault",
"(",
"$",
"defaultDI",
")",
";",
"}",
"// Restore super globals",
"$",
"_REQUEST",
"=",
"$",
"request",
";",
"$",
"_POST",
"=",
"$",
"post",
";",
"$",
"_GET",
"=",
"$",
"get",
";",
"$",
"_SERVER",
"=",
"$",
"server",
";",
"return",
"$",
"response",
";",
"}"
] | Gets a raw response from the internal API
This will trick Phalcon into thinking its a
real PUT, POST, PATCH, GET or DELETE request
It will override the Default DI (Which will be the current site)
and will restore everything after the request
It seems hacky, but I am not sure if there is any better way, please
submit a pull request if you can improve! :)
todo test if the below does in fact require a new instance of DI
if it is being called from within the API
@param $method
@param $path
@param RequestOptions $options
@return Response | [
"Gets",
"a",
"raw",
"response",
"from",
"the",
"internal",
"API",
"This",
"will",
"trick",
"Phalcon",
"into",
"thinking",
"its",
"a",
"real",
"PUT",
"POST",
"PATCH",
"GET",
"or",
"DELETE",
"request",
"It",
"will",
"override",
"the",
"Default",
"DI",
"(",
"Which",
"will",
"be",
"the",
"current",
"site",
")",
"and",
"will",
"restore",
"everything",
"after",
"the",
"request",
"It",
"seems",
"hacky",
"but",
"I",
"am",
"not",
"sure",
"if",
"there",
"is",
"any",
"better",
"way",
"please",
"submit",
"a",
"pull",
"request",
"if",
"you",
"can",
"improve!",
":",
")",
"todo",
"test",
"if",
"the",
"below",
"does",
"in",
"fact",
"require",
"a",
"new",
"instance",
"of",
"DI",
"if",
"it",
"is",
"being",
"called",
"from",
"within",
"the",
"API"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L126-L198 |
phrest/sdk | src/PhrestSDK.php | PhrestSDK.getResponse | public static function getResponse(
$method,
$path,
RequestOptions $options = null
)
{
$instance = static::getInstance();
if ($options)
{
// Get via HTTP
if (isset($instance->url) && $options->isHttp())
{
return $instance->getHTTPResponse($method, $path, $options);
}
}
// Get from the internal call if available
if (isset($instance->app))
{
return $instance->getRawResponse($method, $path, $options);
}
// todo better exception message with link
throw new Exception(
'No app configured for internal calls,
and no URL supplied for HTTP based calls'
);
} | php | public static function getResponse(
$method,
$path,
RequestOptions $options = null
)
{
$instance = static::getInstance();
if ($options)
{
// Get via HTTP
if (isset($instance->url) && $options->isHttp())
{
return $instance->getHTTPResponse($method, $path, $options);
}
}
// Get from the internal call if available
if (isset($instance->app))
{
return $instance->getRawResponse($method, $path, $options);
}
// todo better exception message with link
throw new Exception(
'No app configured for internal calls,
and no URL supplied for HTTP based calls'
);
} | [
"public",
"static",
"function",
"getResponse",
"(",
"$",
"method",
",",
"$",
"path",
",",
"RequestOptions",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"instance",
"=",
"static",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"$",
"options",
")",
"{",
"// Get via HTTP",
"if",
"(",
"isset",
"(",
"$",
"instance",
"->",
"url",
")",
"&&",
"$",
"options",
"->",
"isHttp",
"(",
")",
")",
"{",
"return",
"$",
"instance",
"->",
"getHTTPResponse",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"options",
")",
";",
"}",
"}",
"// Get from the internal call if available",
"if",
"(",
"isset",
"(",
"$",
"instance",
"->",
"app",
")",
")",
"{",
"return",
"$",
"instance",
"->",
"getRawResponse",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"options",
")",
";",
"}",
"// todo better exception message with link",
"throw",
"new",
"Exception",
"(",
"'No app configured for internal calls,\n and no URL supplied for HTTP based calls'",
")",
";",
"}"
] | @param $method
@param $path
@param RequestOptions $options
@return Response|string
@throws \Phalcon\Exception | [
"@param",
"$method",
"@param",
"$path",
"@param",
"RequestOptions",
"$options"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L208-L236 |
phrest/sdk | src/PhrestSDK.php | PhrestSDK.get | public static function get($path, RequestOptions $options = null)
{
return self::getResponse(RequestMethodEnum::GET, $path, $options);
} | php | public static function get($path, RequestOptions $options = null)
{
return self::getResponse(RequestMethodEnum::GET, $path, $options);
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"path",
",",
"RequestOptions",
"$",
"options",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"getResponse",
"(",
"RequestMethodEnum",
"::",
"GET",
",",
"$",
"path",
",",
"$",
"options",
")",
";",
"}"
] | Makes a GET call based on path/url
@param $path
@return Response | [
"Makes",
"a",
"GET",
"call",
"based",
"on",
"path",
"/",
"url"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L245-L248 |
phrest/sdk | src/PhrestSDK.php | PhrestSDK.getHTTPResponse | private function getHTTPResponse(
$method,
$path,
RequestOptions $options = null
)
{
$client = new Client();
// Build body
$body = new PostBody();
if ($options)
{
foreach ($options->getPostParams() as $name => $value)
{
$body->setField($name, $value);
}
}
// Prepare the request
$request = new Request(
$method,
$this->url . $path,
[],
$body,
[]
);
// Get response
$response = $client->send($request);
$body = json_decode($response->getBody());
if (isset($body->data))
{
return $body->data;
}
else
{
throw new \Exception('Error calling ' . $method . ' to: ' . $path);
}
} | php | private function getHTTPResponse(
$method,
$path,
RequestOptions $options = null
)
{
$client = new Client();
// Build body
$body = new PostBody();
if ($options)
{
foreach ($options->getPostParams() as $name => $value)
{
$body->setField($name, $value);
}
}
// Prepare the request
$request = new Request(
$method,
$this->url . $path,
[],
$body,
[]
);
// Get response
$response = $client->send($request);
$body = json_decode($response->getBody());
if (isset($body->data))
{
return $body->data;
}
else
{
throw new \Exception('Error calling ' . $method . ' to: ' . $path);
}
} | [
"private",
"function",
"getHTTPResponse",
"(",
"$",
"method",
",",
"$",
"path",
",",
"RequestOptions",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"// Build body",
"$",
"body",
"=",
"new",
"PostBody",
"(",
")",
";",
"if",
"(",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"->",
"getPostParams",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"body",
"->",
"setField",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"// Prepare the request",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"url",
".",
"$",
"path",
",",
"[",
"]",
",",
"$",
"body",
",",
"[",
"]",
")",
";",
"// Get response",
"$",
"response",
"=",
"$",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"$",
"body",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"body",
"->",
"data",
")",
")",
"{",
"return",
"$",
"body",
"->",
"data",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Error calling '",
".",
"$",
"method",
".",
"' to: '",
".",
"$",
"path",
")",
";",
"}",
"}"
] | Makes a cURL HTTP request to the API and returns the response
todo this needs to also handle PUT, POST, DELETE
@param string $method
@param $path
@param RequestOptions $options
@throws \Exception
@return string | [
"Makes",
"a",
"cURL",
"HTTP",
"request",
"to",
"the",
"API",
"and",
"returns",
"the",
"response",
"todo",
"this",
"needs",
"to",
"also",
"handle",
"PUT",
"POST",
"DELETE"
] | train | https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L314-L354 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.getARN | public function getARN()
{
if (!$this->arn) {
$this->arn = $this->sqs->getClient()->getQueueArn($this->url);
}
return $this->arn;
} | php | public function getARN()
{
if (!$this->arn) {
$this->arn = $this->sqs->getClient()->getQueueArn($this->url);
}
return $this->arn;
} | [
"public",
"function",
"getARN",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"arn",
")",
"{",
"$",
"this",
"->",
"arn",
"=",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"getQueueArn",
"(",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"arn",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L66-L73 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.getUrl | public function getUrl()
{
if (!$this->url) {
$this->url = trim($this->sqs->getClient()->getQueueUrl(array(
'QueueName' => $this->getName(),
))->get('QueueUrl'));
}
return $this->url;
} | php | public function getUrl()
{
if (!$this->url) {
$this->url = trim($this->sqs->getClient()->getQueueUrl(array(
'QueueName' => $this->getName(),
))->get('QueueUrl'));
}
return $this->url;
} | [
"public",
"function",
"getUrl",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"url",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"trim",
"(",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"getQueueUrl",
"(",
"array",
"(",
"'QueueName'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
")",
")",
"->",
"get",
"(",
"'QueueUrl'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"url",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L88-L97 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.addPermission | public function addPermission($label, array $awsAccountId, array $actionName)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Label' => $label,
'AWSAccountIds' => $awsAccountId,
'Actions' => $actionName,
);
$this->sqs->getClient()->addPermission($arguments);
return $this;
} | php | public function addPermission($label, array $awsAccountId, array $actionName)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Label' => $label,
'AWSAccountIds' => $awsAccountId,
'Actions' => $actionName,
);
$this->sqs->getClient()->addPermission($arguments);
return $this;
} | [
"public",
"function",
"addPermission",
"(",
"$",
"label",
",",
"array",
"$",
"awsAccountId",
",",
"array",
"$",
"actionName",
")",
"{",
"$",
"arguments",
"=",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"'Label'",
"=>",
"$",
"label",
",",
"'AWSAccountIds'",
"=>",
"$",
"awsAccountId",
",",
"'Actions'",
"=>",
"$",
"actionName",
",",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"addPermission",
"(",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L112-L125 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.removePermission | public function removePermission($label)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Label' => $label
);
$this->sqs->getClient()->removePermission($arguments);
return $this;
} | php | public function removePermission($label)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Label' => $label
);
$this->sqs->getClient()->removePermission($arguments);
return $this;
} | [
"public",
"function",
"removePermission",
"(",
"$",
"label",
")",
"{",
"$",
"arguments",
"=",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"'Label'",
"=>",
"$",
"label",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"removePermission",
"(",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L130-L141 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.deleteMessage | public function deleteMessage(MessageInterface $message)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'ReceiptHandle' => $message->getReceiptHandle()
);
$this->sqs->getClient()
->deleteMessage($arguments);
return $this;
} | php | public function deleteMessage(MessageInterface $message)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'ReceiptHandle' => $message->getReceiptHandle()
);
$this->sqs->getClient()
->deleteMessage($arguments);
return $this;
} | [
"public",
"function",
"deleteMessage",
"(",
"MessageInterface",
"$",
"message",
")",
"{",
"$",
"arguments",
"=",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"'ReceiptHandle'",
"=>",
"$",
"message",
"->",
"getReceiptHandle",
"(",
")",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"deleteMessage",
"(",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L146-L157 |
lelivrescolaire/SQSBundle | Model/Queue.php | Queue.setAttributes | public function setAttributes(array $attributes)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Attributes' => $attributes
);
$this->sqs->getClient()->setQueueAttributes($arguments);
return $this;
} | php | public function setAttributes(array $attributes)
{
$arguments = array(
'QueueUrl' => $this->getUrl(),
'Attributes' => $attributes
);
$this->sqs->getClient()->setQueueAttributes($arguments);
return $this;
} | [
"public",
"function",
"setAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"arguments",
"=",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"'Attributes'",
"=>",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"getClient",
"(",
")",
"->",
"setQueueAttributes",
"(",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lelivrescolaire/SQSBundle/blob/bba3fa6d63d0ae1bddbc7b2fe3c2e737f49d6559/Model/Queue.php#L162-L172 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.