repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
m6w6/pq-gateway | lib/pq/Gateway/Rowset.php | Rowset.filter | function filter(callable $cb) {
$rowset = clone $this;
$rowset->index = 0;
$rowset->rows = array_filter($this->rows, $cb);
return $rowset;
} | php | function filter(callable $cb) {
$rowset = clone $this;
$rowset->index = 0;
$rowset->rows = array_filter($this->rows, $cb);
return $rowset;
} | [
"function",
"filter",
"(",
"callable",
"$",
"cb",
")",
"{",
"$",
"rowset",
"=",
"clone",
"$",
"this",
";",
"$",
"rowset",
"->",
"index",
"=",
"0",
";",
"$",
"rowset",
"->",
"rows",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"rows",
",",
"$",
"cb",
")",
";",
"return",
"$",
"rowset",
";",
"}"
] | Filter by callback
@param callable $cb
@return \pq\Gateway\Rowset | [
"Filter",
"by",
"callback"
] | 58233722a06fd742f531f8f012ea540b309303da | https://github.com/m6w6/pq-gateway/blob/58233722a06fd742f531f8f012ea540b309303da/lib/pq/Gateway/Rowset.php#L274-L279 | train |
thienhungho/yii2-contact-management | src/modules/ContactManage/controllers/ContactController.php | ContactController.actionIndex | public function actionIndex()
{
$searchModel = new ContactSearch();
$dataProvider = $searchModel->search(request()->queryParams);
$dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | php | public function actionIndex()
{
$searchModel = new ContactSearch();
$dataProvider = $searchModel->search(request()->queryParams);
$dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"searchModel",
"=",
"new",
"ContactSearch",
"(",
")",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"request",
"(",
")",
"->",
"queryParams",
")",
";",
"$",
"dataProvider",
"->",
"sort",
"->",
"defaultOrder",
"=",
"[",
"'id'",
"=>",
"SORT_DESC",
"]",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'searchModel'",
"=>",
"$",
"searchModel",
",",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}"
] | Lists all Contact models.
@return mixed | [
"Lists",
"all",
"Contact",
"models",
"."
] | 652d7b0ee628eb924e197ad956ce3c6045b878eb | https://github.com/thienhungho/yii2-contact-management/blob/652d7b0ee628eb924e197ad956ce3c6045b878eb/src/modules/ContactManage/controllers/ContactController.php#L33-L43 | train |
thienhungho/yii2-contact-management | src/modules/ContactManage/controllers/ContactController.php | ContactController.findModel | protected function findModel($id)
{
if (($model = Contact::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
}
} | php | protected function findModel($id)
{
if (($model = Contact::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException(t('app', 'The requested page does not exist.'));
}
} | [
"protected",
"function",
"findModel",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"(",
"$",
"model",
"=",
"Contact",
"::",
"findOne",
"(",
"$",
"id",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"model",
";",
"}",
"else",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"t",
"(",
"'app'",
",",
"'The requested page does not exist.'",
")",
")",
";",
"}",
"}"
] | Finds the Contact model based on its primary key value.
If the model is not found, a 404 HTTP exception will be thrown.
@param integer $id
@return Contact the loaded model
@throws NotFoundHttpException if the model cannot be found | [
"Finds",
"the",
"Contact",
"model",
"based",
"on",
"its",
"primary",
"key",
"value",
".",
"If",
"the",
"model",
"is",
"not",
"found",
"a",
"404",
"HTTP",
"exception",
"will",
"be",
"thrown",
"."
] | 652d7b0ee628eb924e197ad956ce3c6045b878eb | https://github.com/thienhungho/yii2-contact-management/blob/652d7b0ee628eb924e197ad956ce3c6045b878eb/src/modules/ContactManage/controllers/ContactController.php#L174-L181 | train |
schpill/thin | src/Queuespl.php | Queuespl.insert | public function insert($data, $priority = 1)
{
$priority = (int) $priority;
$this->items[] = array(
'data' => $data,
'priority' => $priority,
);
$this->getQueue()->insert($data, $priority);
return $this;
} | php | public function insert($data, $priority = 1)
{
$priority = (int) $priority;
$this->items[] = array(
'data' => $data,
'priority' => $priority,
);
$this->getQueue()->insert($data, $priority);
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"data",
",",
"$",
"priority",
"=",
"1",
")",
"{",
"$",
"priority",
"=",
"(",
"int",
")",
"$",
"priority",
";",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"array",
"(",
"'data'",
"=>",
"$",
"data",
",",
"'priority'",
"=>",
"$",
"priority",
",",
")",
";",
"$",
"this",
"->",
"getQueue",
"(",
")",
"->",
"insert",
"(",
"$",
"data",
",",
"$",
"priority",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Insert an item into the queue
Priority defaults to 1 (low priority) if none provided.
@param mixed $data
@param int $priority
@return Queue | [
"Insert",
"an",
"item",
"into",
"the",
"queue"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Queuespl.php#L56-L66 | train |
schpill/thin | src/Queuespl.php | Queuespl.getQueue | protected function getQueue()
{
if (null === $this->queue) {
$this->queue = new $this->queueClass();
if (!$this->queue instanceof SplPriorityQueue) {
throw new Exception(sprintf(
'Queue expects an internal queue of type SplPriorityQueue; received "%s"',
get_class($this->queue)
));
}
}
return $this->queue;
} | php | protected function getQueue()
{
if (null === $this->queue) {
$this->queue = new $this->queueClass();
if (!$this->queue instanceof SplPriorityQueue) {
throw new Exception(sprintf(
'Queue expects an internal queue of type SplPriorityQueue; received "%s"',
get_class($this->queue)
));
}
}
return $this->queue;
} | [
"protected",
"function",
"getQueue",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"queue",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"new",
"$",
"this",
"->",
"queueClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
"instanceof",
"SplPriorityQueue",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Queue expects an internal queue of type SplPriorityQueue; received \"%s\"'",
",",
"get_class",
"(",
"$",
"this",
"->",
"queue",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"queue",
";",
"}"
] | Get the inner priority queue instance
@throws Exception\DomainException
@return SplQueue | [
"Get",
"the",
"inner",
"priority",
"queue",
"instance"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Queuespl.php#L283-L297 | train |
alaa-almaliki/property-setter-config | src/PropertySetterConfig.php | PropertySetterConfig.setObjectProperties | static public function setObjectProperties($object, array $config = [])
{
foreach (static::createSetterMethods($config) as $method => $value) {
if (method_exists($object, $method)) {
call_user_func_array([$object, $method], [$value]);
}
}
} | php | static public function setObjectProperties($object, array $config = [])
{
foreach (static::createSetterMethods($config) as $method => $value) {
if (method_exists($object, $method)) {
call_user_func_array([$object, $method], [$value]);
}
}
} | [
"static",
"public",
"function",
"setObjectProperties",
"(",
"$",
"object",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"static",
"::",
"createSetterMethods",
"(",
"$",
"config",
")",
"as",
"$",
"method",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"method",
"]",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"}",
"}"
] | Sets object properties by a given array
@param $object
@param array $config | [
"Sets",
"object",
"properties",
"by",
"a",
"given",
"array"
] | 0dd77d0a206d927990b708e0e935284d8a5d4116 | https://github.com/alaa-almaliki/property-setter-config/blob/0dd77d0a206d927990b708e0e935284d8a5d4116/src/PropertySetterConfig.php#L16-L23 | train |
IftekherSunny/Planet-Framework | src/Sun/Validation/Form/Request.php | Request.validate | public function validate()
{
foreach($this->rules() as $key => $value) {
$this->rules[$key] = [$this->input($key), $value];
}
$validate = $this->validator->validate($this->rules);
if ($validate->fails()) {
if($this->isAjax()) {
return $this->response->json(['errors' => $validate->errors()->all()], 403);
}
return $this->redirect->backWith('errors', $validate->errors()->all());
}
} | php | public function validate()
{
foreach($this->rules() as $key => $value) {
$this->rules[$key] = [$this->input($key), $value];
}
$validate = $this->validator->validate($this->rules);
if ($validate->fails()) {
if($this->isAjax()) {
return $this->response->json(['errors' => $validate->errors()->all()], 403);
}
return $this->redirect->backWith('errors', $validate->errors()->all());
}
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"this",
"->",
"input",
"(",
"$",
"key",
")",
",",
"$",
"value",
"]",
";",
"}",
"$",
"validate",
"=",
"$",
"this",
"->",
"validator",
"->",
"validate",
"(",
"$",
"this",
"->",
"rules",
")",
";",
"if",
"(",
"$",
"validate",
"->",
"fails",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAjax",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"json",
"(",
"[",
"'errors'",
"=>",
"$",
"validate",
"->",
"errors",
"(",
")",
"->",
"all",
"(",
")",
"]",
",",
"403",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"->",
"backWith",
"(",
"'errors'",
",",
"$",
"validate",
"->",
"errors",
"(",
")",
"->",
"all",
"(",
")",
")",
";",
"}",
"}"
] | Validate requested form.
@return string | [
"Validate",
"requested",
"form",
"."
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Validation/Form/Request.php#L56-L71 | train |
armazon/armazon | src/Armazon/Http/Peticion.php | Peticion.prepararArchivos | public static function prepararArchivos(array $archivos, $inicio = true)
{
$final = [];
foreach ($archivos as $nombre => $archivo) {
// Definimos sub nombre
$subNombre = $nombre;
if ($inicio) {
$subNombre = $archivo['name'];
}
$final[$nombre] = $archivo;
if (is_array($subNombre)) {
foreach (array_keys($subNombre) as $llave) {
$final[$nombre][$llave] = array(
'name' => $archivo['name'][$llave],
'type' => $archivo['type'][$llave],
'tmp_name' => $archivo['tmp_name'][$llave],
'error' => $archivo['error'][$llave],
'size' => $archivo['size'][$llave],
);
$final[$nombre] = self::prepararArchivos($final[$nombre], false);
}
}
}
return $final;
} | php | public static function prepararArchivos(array $archivos, $inicio = true)
{
$final = [];
foreach ($archivos as $nombre => $archivo) {
// Definimos sub nombre
$subNombre = $nombre;
if ($inicio) {
$subNombre = $archivo['name'];
}
$final[$nombre] = $archivo;
if (is_array($subNombre)) {
foreach (array_keys($subNombre) as $llave) {
$final[$nombre][$llave] = array(
'name' => $archivo['name'][$llave],
'type' => $archivo['type'][$llave],
'tmp_name' => $archivo['tmp_name'][$llave],
'error' => $archivo['error'][$llave],
'size' => $archivo['size'][$llave],
);
$final[$nombre] = self::prepararArchivos($final[$nombre], false);
}
}
}
return $final;
} | [
"public",
"static",
"function",
"prepararArchivos",
"(",
"array",
"$",
"archivos",
",",
"$",
"inicio",
"=",
"true",
")",
"{",
"$",
"final",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"archivos",
"as",
"$",
"nombre",
"=>",
"$",
"archivo",
")",
"{",
"// Definimos sub nombre",
"$",
"subNombre",
"=",
"$",
"nombre",
";",
"if",
"(",
"$",
"inicio",
")",
"{",
"$",
"subNombre",
"=",
"$",
"archivo",
"[",
"'name'",
"]",
";",
"}",
"$",
"final",
"[",
"$",
"nombre",
"]",
"=",
"$",
"archivo",
";",
"if",
"(",
"is_array",
"(",
"$",
"subNombre",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"subNombre",
")",
"as",
"$",
"llave",
")",
"{",
"$",
"final",
"[",
"$",
"nombre",
"]",
"[",
"$",
"llave",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"archivo",
"[",
"'name'",
"]",
"[",
"$",
"llave",
"]",
",",
"'type'",
"=>",
"$",
"archivo",
"[",
"'type'",
"]",
"[",
"$",
"llave",
"]",
",",
"'tmp_name'",
"=>",
"$",
"archivo",
"[",
"'tmp_name'",
"]",
"[",
"$",
"llave",
"]",
",",
"'error'",
"=>",
"$",
"archivo",
"[",
"'error'",
"]",
"[",
"$",
"llave",
"]",
",",
"'size'",
"=>",
"$",
"archivo",
"[",
"'size'",
"]",
"[",
"$",
"llave",
"]",
",",
")",
";",
"$",
"final",
"[",
"$",
"nombre",
"]",
"=",
"self",
"::",
"prepararArchivos",
"(",
"$",
"final",
"[",
"$",
"nombre",
"]",
",",
"false",
")",
";",
"}",
"}",
"}",
"return",
"$",
"final",
";",
"}"
] | Prepara el formato en que se presenta los archivos subidos.
@link http://php.net/manual/es/reserved.variables.files.php#106608
@param array $archivos
@param bool $inicio
@return array | [
"Prepara",
"el",
"formato",
"en",
"que",
"se",
"presenta",
"los",
"archivos",
"subidos",
"."
] | ec76385ff80ce1659d81bc4050ef9483ab0ebe52 | https://github.com/armazon/armazon/blob/ec76385ff80ce1659d81bc4050ef9483ab0ebe52/src/Armazon/Http/Peticion.php#L94-L120 | train |
phore/phore-system | src/PhoreProc.php | PhoreProc.wait | public function wait(bool $throwExceptionOnError=true) : PhoreProcResult
{
if ($this->proc === null)
$this->exec();
$buf = null;
if ($buf === null) {
$buf = [];
foreach ($this->listener as $chanId => $listener) {
$buf[$chanId] = "";
}
}
while(true) {
$allPipesClosed = true;
$noData = true;
foreach ($buf as $chanId => &$buffer) {
if ( ! feof($this->pipes[$chanId])) {
$allPipesClosed = false;
$dataRead = fread($this->pipes[$chanId], 1024 * 32);
$dataReadLen = strlen($dataRead);
if ($dataReadLen > 0) {
$noData = false;
if ($this->listener[$chanId] !== null) {
($this->listener[$chanId])($dataRead, $dataReadLen, $this);
} else {
$buffer .= $dataRead;
}
}
}
}
if ($allPipesClosed) {
break;
}
if ($noData) {
usleep(500);
}
}
foreach ($this->listener as $chanId => $listener) {
if ($listener === null)
continue;
$listener(null, null, $this);
fclose($this->pipes[$chanId]);
}
fclose($this->pipes[0]);
$exitStatus = proc_close($this->proc);
$errmsg = "";
if (isset ($buf[2]))
$errmsg = $buf[2];
if ($exitStatus !== 0) {
throw new PhoreExecException("Command '$this->cmd' returned with exit-code $exitStatus: $errmsg", $exitStatus);
}
return new PhoreProcResult($exitStatus, $buf);
} | php | public function wait(bool $throwExceptionOnError=true) : PhoreProcResult
{
if ($this->proc === null)
$this->exec();
$buf = null;
if ($buf === null) {
$buf = [];
foreach ($this->listener as $chanId => $listener) {
$buf[$chanId] = "";
}
}
while(true) {
$allPipesClosed = true;
$noData = true;
foreach ($buf as $chanId => &$buffer) {
if ( ! feof($this->pipes[$chanId])) {
$allPipesClosed = false;
$dataRead = fread($this->pipes[$chanId], 1024 * 32);
$dataReadLen = strlen($dataRead);
if ($dataReadLen > 0) {
$noData = false;
if ($this->listener[$chanId] !== null) {
($this->listener[$chanId])($dataRead, $dataReadLen, $this);
} else {
$buffer .= $dataRead;
}
}
}
}
if ($allPipesClosed) {
break;
}
if ($noData) {
usleep(500);
}
}
foreach ($this->listener as $chanId => $listener) {
if ($listener === null)
continue;
$listener(null, null, $this);
fclose($this->pipes[$chanId]);
}
fclose($this->pipes[0]);
$exitStatus = proc_close($this->proc);
$errmsg = "";
if (isset ($buf[2]))
$errmsg = $buf[2];
if ($exitStatus !== 0) {
throw new PhoreExecException("Command '$this->cmd' returned with exit-code $exitStatus: $errmsg", $exitStatus);
}
return new PhoreProcResult($exitStatus, $buf);
} | [
"public",
"function",
"wait",
"(",
"bool",
"$",
"throwExceptionOnError",
"=",
"true",
")",
":",
"PhoreProcResult",
"{",
"if",
"(",
"$",
"this",
"->",
"proc",
"===",
"null",
")",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"$",
"buf",
"=",
"null",
";",
"if",
"(",
"$",
"buf",
"===",
"null",
")",
"{",
"$",
"buf",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"listener",
"as",
"$",
"chanId",
"=>",
"$",
"listener",
")",
"{",
"$",
"buf",
"[",
"$",
"chanId",
"]",
"=",
"\"\"",
";",
"}",
"}",
"while",
"(",
"true",
")",
"{",
"$",
"allPipesClosed",
"=",
"true",
";",
"$",
"noData",
"=",
"true",
";",
"foreach",
"(",
"$",
"buf",
"as",
"$",
"chanId",
"=>",
"&",
"$",
"buffer",
")",
"{",
"if",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"pipes",
"[",
"$",
"chanId",
"]",
")",
")",
"{",
"$",
"allPipesClosed",
"=",
"false",
";",
"$",
"dataRead",
"=",
"fread",
"(",
"$",
"this",
"->",
"pipes",
"[",
"$",
"chanId",
"]",
",",
"1024",
"*",
"32",
")",
";",
"$",
"dataReadLen",
"=",
"strlen",
"(",
"$",
"dataRead",
")",
";",
"if",
"(",
"$",
"dataReadLen",
">",
"0",
")",
"{",
"$",
"noData",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"listener",
"[",
"$",
"chanId",
"]",
"!==",
"null",
")",
"{",
"(",
"$",
"this",
"->",
"listener",
"[",
"$",
"chanId",
"]",
")",
"(",
"$",
"dataRead",
",",
"$",
"dataReadLen",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"buffer",
".=",
"$",
"dataRead",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"allPipesClosed",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"noData",
")",
"{",
"usleep",
"(",
"500",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"listener",
"as",
"$",
"chanId",
"=>",
"$",
"listener",
")",
"{",
"if",
"(",
"$",
"listener",
"===",
"null",
")",
"continue",
";",
"$",
"listener",
"(",
"null",
",",
"null",
",",
"$",
"this",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"pipes",
"[",
"$",
"chanId",
"]",
")",
";",
"}",
"fclose",
"(",
"$",
"this",
"->",
"pipes",
"[",
"0",
"]",
")",
";",
"$",
"exitStatus",
"=",
"proc_close",
"(",
"$",
"this",
"->",
"proc",
")",
";",
"$",
"errmsg",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"buf",
"[",
"2",
"]",
")",
")",
"$",
"errmsg",
"=",
"$",
"buf",
"[",
"2",
"]",
";",
"if",
"(",
"$",
"exitStatus",
"!==",
"0",
")",
"{",
"throw",
"new",
"PhoreExecException",
"(",
"\"Command '$this->cmd' returned with exit-code $exitStatus: $errmsg\"",
",",
"$",
"exitStatus",
")",
";",
"}",
"return",
"new",
"PhoreProcResult",
"(",
"$",
"exitStatus",
",",
"$",
"buf",
")",
";",
"}"
] | Wait for the process to exit.
This will call exec() if not done before.
@param bool $throwExceptionOnError
@return PhoreProcResult
@throws PhoreExecException | [
"Wait",
"for",
"the",
"process",
"to",
"exit",
"."
] | 564f41ea790d4fb564d65f1533a4aeb9f05dabf0 | https://github.com/phore/phore-system/blob/564f41ea790d4fb564d65f1533a4aeb9f05dabf0/src/PhoreProc.php#L105-L162 | train |
IftekherSunny/Planet-Framework | src/Sun/Support/Alien.php | Alien.execute | protected static function execute()
{
try {
$instance = static::getInstance();
$reflectionMethod = new ReflectionMethod($instance, static::$method);
return $reflectionMethod->invokeArgs($instance, static::$arguments);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
} | php | protected static function execute()
{
try {
$instance = static::getInstance();
$reflectionMethod = new ReflectionMethod($instance, static::$method);
return $reflectionMethod->invokeArgs($instance, static::$arguments);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
} | [
"protected",
"static",
"function",
"execute",
"(",
")",
"{",
"try",
"{",
"$",
"instance",
"=",
"static",
"::",
"getInstance",
"(",
")",
";",
"$",
"reflectionMethod",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"instance",
",",
"static",
"::",
"$",
"method",
")",
";",
"return",
"$",
"reflectionMethod",
"->",
"invokeArgs",
"(",
"$",
"instance",
",",
"static",
"::",
"$",
"arguments",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Execute method of the registered alien
@return mixed
@throws Exception | [
"Execute",
"method",
"of",
"the",
"registered",
"alien"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Support/Alien.php#L46-L57 | train |
IftekherSunny/Planet-Framework | src/Sun/Support/Alien.php | Alien.shouldReceive | public static function shouldReceive()
{
if(!isset(static::$mocked[static::registerAlien()])) {
static::$mocked[static::registerAlien()] = Mockery::mock(static::registerAlien());
}
return call_user_func_array([static::$mocked[static::registerAlien()], 'shouldReceive'], func_get_args());
} | php | public static function shouldReceive()
{
if(!isset(static::$mocked[static::registerAlien()])) {
static::$mocked[static::registerAlien()] = Mockery::mock(static::registerAlien());
}
return call_user_func_array([static::$mocked[static::registerAlien()], 'shouldReceive'], func_get_args());
} | [
"public",
"static",
"function",
"shouldReceive",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"mocked",
"[",
"static",
"::",
"registerAlien",
"(",
")",
"]",
")",
")",
"{",
"static",
"::",
"$",
"mocked",
"[",
"static",
"::",
"registerAlien",
"(",
")",
"]",
"=",
"Mockery",
"::",
"mock",
"(",
"static",
"::",
"registerAlien",
"(",
")",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"[",
"static",
"::",
"$",
"mocked",
"[",
"static",
"::",
"registerAlien",
"(",
")",
"]",
",",
"'shouldReceive'",
"]",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] | Initiate mock expectation for the registered alien
@return mixed
@throws Exception | [
"Initiate",
"mock",
"expectation",
"for",
"the",
"registered",
"alien"
] | 530e772fb97695c1c4e1af73f81675f189474d9f | https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Support/Alien.php#L84-L91 | train |
lrezek/Arachnid | src/LRezek/Arachnid/Meta/Repository.php | Repository.findMeta | private function findMeta($className)
{
$class = new \ReflectionClass($className);
//If it's a proxy class, use the parent for meta
if($class->implementsInterface('LRezek\\Arachnid\\Proxy\\Entity'))
{
$class = $class->getParentClass();
}
$node = $this->reader->getClassAnnotation($class, 'LRezek\\Arachnid\\Annotation\\Node');
$relation = $this->reader->getClassAnnotation($class, 'LRezek\\Arachnid\\Annotation\\Relation');
//Throw an error if it has both annotations
if($node && $relation)
{
throw new Exception("Class $className is defined as both a node and relation.");
}
//Handle nodes
if($node)
{
//Save the node to common object
$entity = $node;
//Create the node
$object = new Node($class->getName());
}
//Handle Relations
else if($relation)
{
//Save the relation to a common object
$entity = $relation;
//Create the relation
$object = new Relation($class->getName());
}
//Unknown annotation
else
{
$className = $class->getName();
throw new Exception("Class $className is not declared as a node or relation.");
}
//Set the objects repo class
$object->setRepositoryClass($entity->repositoryClass);
//Load object properties, and validate it
$object->loadProperties($this->reader, $class->getProperties());
$object->validate();
return $object;
} | php | private function findMeta($className)
{
$class = new \ReflectionClass($className);
//If it's a proxy class, use the parent for meta
if($class->implementsInterface('LRezek\\Arachnid\\Proxy\\Entity'))
{
$class = $class->getParentClass();
}
$node = $this->reader->getClassAnnotation($class, 'LRezek\\Arachnid\\Annotation\\Node');
$relation = $this->reader->getClassAnnotation($class, 'LRezek\\Arachnid\\Annotation\\Relation');
//Throw an error if it has both annotations
if($node && $relation)
{
throw new Exception("Class $className is defined as both a node and relation.");
}
//Handle nodes
if($node)
{
//Save the node to common object
$entity = $node;
//Create the node
$object = new Node($class->getName());
}
//Handle Relations
else if($relation)
{
//Save the relation to a common object
$entity = $relation;
//Create the relation
$object = new Relation($class->getName());
}
//Unknown annotation
else
{
$className = $class->getName();
throw new Exception("Class $className is not declared as a node or relation.");
}
//Set the objects repo class
$object->setRepositoryClass($entity->repositoryClass);
//Load object properties, and validate it
$object->loadProperties($this->reader, $class->getProperties());
$object->validate();
return $object;
} | [
"private",
"function",
"findMeta",
"(",
"$",
"className",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"//If it's a proxy class, use the parent for meta",
"if",
"(",
"$",
"class",
"->",
"implementsInterface",
"(",
"'LRezek\\\\Arachnid\\\\Proxy\\\\Entity'",
")",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"->",
"getParentClass",
"(",
")",
";",
"}",
"$",
"node",
"=",
"$",
"this",
"->",
"reader",
"->",
"getClassAnnotation",
"(",
"$",
"class",
",",
"'LRezek\\\\Arachnid\\\\Annotation\\\\Node'",
")",
";",
"$",
"relation",
"=",
"$",
"this",
"->",
"reader",
"->",
"getClassAnnotation",
"(",
"$",
"class",
",",
"'LRezek\\\\Arachnid\\\\Annotation\\\\Relation'",
")",
";",
"//Throw an error if it has both annotations",
"if",
"(",
"$",
"node",
"&&",
"$",
"relation",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class $className is defined as both a node and relation.\"",
")",
";",
"}",
"//Handle nodes",
"if",
"(",
"$",
"node",
")",
"{",
"//Save the node to common object",
"$",
"entity",
"=",
"$",
"node",
";",
"//Create the node",
"$",
"object",
"=",
"new",
"Node",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
")",
";",
"}",
"//Handle Relations",
"else",
"if",
"(",
"$",
"relation",
")",
"{",
"//Save the relation to a common object",
"$",
"entity",
"=",
"$",
"relation",
";",
"//Create the relation",
"$",
"object",
"=",
"new",
"Relation",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
")",
";",
"}",
"//Unknown annotation",
"else",
"{",
"$",
"className",
"=",
"$",
"class",
"->",
"getName",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Class $className is not declared as a node or relation.\"",
")",
";",
"}",
"//Set the objects repo class",
"$",
"object",
"->",
"setRepositoryClass",
"(",
"$",
"entity",
"->",
"repositoryClass",
")",
";",
"//Load object properties, and validate it",
"$",
"object",
"->",
"loadProperties",
"(",
"$",
"this",
"->",
"reader",
",",
"$",
"class",
"->",
"getProperties",
"(",
")",
")",
";",
"$",
"object",
"->",
"validate",
"(",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Does the actual annotation parsing to get meta information for a given class.
@param string $className The class name to get meta for.
@return Node|Relation A node/relation meta object.
@throws \LRezek\Arachnid\Exception Thrown if the class is not a node or relation. | [
"Does",
"the",
"actual",
"annotation",
"parsing",
"to",
"get",
"meta",
"information",
"for",
"a",
"given",
"class",
"."
] | fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a | https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Repository.php#L74-L128 | train |
mojopollo/laravel-helpers | src/Mojopollo/Helpers/StringHelper.php | StringHelper.limitByWords | public static function limitByWords($str, $wordCount = 10)
{
// Reads amount of words in paragraph
$words = preg_split("/[\s]+/", $str, $wordCount + 1);
// limit paragraph to $wordCount value
$words = array_slice($words, 0, $wordCount);
// Return the words back
return join(' ', $words);
} | php | public static function limitByWords($str, $wordCount = 10)
{
// Reads amount of words in paragraph
$words = preg_split("/[\s]+/", $str, $wordCount + 1);
// limit paragraph to $wordCount value
$words = array_slice($words, 0, $wordCount);
// Return the words back
return join(' ', $words);
} | [
"public",
"static",
"function",
"limitByWords",
"(",
"$",
"str",
",",
"$",
"wordCount",
"=",
"10",
")",
"{",
"// Reads amount of words in paragraph",
"$",
"words",
"=",
"preg_split",
"(",
"\"/[\\s]+/\"",
",",
"$",
"str",
",",
"$",
"wordCount",
"+",
"1",
")",
";",
"// limit paragraph to $wordCount value",
"$",
"words",
"=",
"array_slice",
"(",
"$",
"words",
",",
"0",
",",
"$",
"wordCount",
")",
";",
"// Return the words back",
"return",
"join",
"(",
"' '",
",",
"$",
"words",
")",
";",
"}"
] | Returns a string limited by the word count specified
logic borrowed from StackOverflow
@see http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara#answer-10026115
@param string $str paragraph to limit by words
@param integer $wordCount amount to wordCount paragraph to
@return string string with int limitation set | [
"Returns",
"a",
"string",
"limited",
"by",
"the",
"word",
"count",
"specified",
"logic",
"borrowed",
"from",
"StackOverflow"
] | 0becb5e0f4202a0f489fb5e384c01dacb8f29dc5 | https://github.com/mojopollo/laravel-helpers/blob/0becb5e0f4202a0f489fb5e384c01dacb8f29dc5/src/Mojopollo/Helpers/StringHelper.php#L63-L73 | train |
gregorybesson/AdfabCore | src/AdfabCore/Service/Cron.php | Cron.process | public function process()
{
$em = $this->getEm();
$cronRegistry = $this->getCronjobs();
$pending = $this->getPending();
$scheduleLifetime = $this->scheduleLifetime * 60; //convert min to sec
$now = new \DateTime;
foreach ($pending as $job) {
$scheduleTime = $job->getScheduleTime();
if ($scheduleTime > $now) {
continue;
}
try {
$errorStatus = Mapper\Cronjob::STATUS_ERROR;
$missedTime = clone $now;
$timestamp = $missedTime->getTimestamp();
$timestamp -= $scheduleLifetime;
$missedTime->setTimestamp($timestamp);
if ($scheduleTime < $missedTime) {
$errorStatus = Mapper\Cronjob::STATUS_MISSED;
throw new Exception\RuntimeException(
'too late for job'
);
}
$code = $job->getCode();
if (!isset($cronRegistry[$code])) {
throw new Exception\RuntimeException(sprintf(
'job "%s" undefined in cron registry',
$code
));
}
if (!$this->tryLockJob($job)) {
//another cron started this job intermittently. skip.
continue;
}
//run job now
$callback = $cronRegistry[$code]['callback'];
$args = $cronRegistry[$code]['args'];
$job->setExecuteTime(new \DateTime);
$em->persist($job);
$em->flush();
call_user_func_array($callback, $args);
$job
->setStatus(Mapper\Cronjob::STATUS_SUCCESS)
->setFinishTime(new \DateTime);
} catch (\Exception $e) {
$job
->setStatus($errorStatus)
->setErrorMsg($e->getMessage())
->setStackTrace($e->getTraceAsString());
}
$em->persist($job);
$em->flush();
}
return $this;
} | php | public function process()
{
$em = $this->getEm();
$cronRegistry = $this->getCronjobs();
$pending = $this->getPending();
$scheduleLifetime = $this->scheduleLifetime * 60; //convert min to sec
$now = new \DateTime;
foreach ($pending as $job) {
$scheduleTime = $job->getScheduleTime();
if ($scheduleTime > $now) {
continue;
}
try {
$errorStatus = Mapper\Cronjob::STATUS_ERROR;
$missedTime = clone $now;
$timestamp = $missedTime->getTimestamp();
$timestamp -= $scheduleLifetime;
$missedTime->setTimestamp($timestamp);
if ($scheduleTime < $missedTime) {
$errorStatus = Mapper\Cronjob::STATUS_MISSED;
throw new Exception\RuntimeException(
'too late for job'
);
}
$code = $job->getCode();
if (!isset($cronRegistry[$code])) {
throw new Exception\RuntimeException(sprintf(
'job "%s" undefined in cron registry',
$code
));
}
if (!$this->tryLockJob($job)) {
//another cron started this job intermittently. skip.
continue;
}
//run job now
$callback = $cronRegistry[$code]['callback'];
$args = $cronRegistry[$code]['args'];
$job->setExecuteTime(new \DateTime);
$em->persist($job);
$em->flush();
call_user_func_array($callback, $args);
$job
->setStatus(Mapper\Cronjob::STATUS_SUCCESS)
->setFinishTime(new \DateTime);
} catch (\Exception $e) {
$job
->setStatus($errorStatus)
->setErrorMsg($e->getMessage())
->setStackTrace($e->getTraceAsString());
}
$em->persist($job);
$em->flush();
}
return $this;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEm",
"(",
")",
";",
"$",
"cronRegistry",
"=",
"$",
"this",
"->",
"getCronjobs",
"(",
")",
";",
"$",
"pending",
"=",
"$",
"this",
"->",
"getPending",
"(",
")",
";",
"$",
"scheduleLifetime",
"=",
"$",
"this",
"->",
"scheduleLifetime",
"*",
"60",
";",
"//convert min to sec",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
";",
"foreach",
"(",
"$",
"pending",
"as",
"$",
"job",
")",
"{",
"$",
"scheduleTime",
"=",
"$",
"job",
"->",
"getScheduleTime",
"(",
")",
";",
"if",
"(",
"$",
"scheduleTime",
">",
"$",
"now",
")",
"{",
"continue",
";",
"}",
"try",
"{",
"$",
"errorStatus",
"=",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_ERROR",
";",
"$",
"missedTime",
"=",
"clone",
"$",
"now",
";",
"$",
"timestamp",
"=",
"$",
"missedTime",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"timestamp",
"-=",
"$",
"scheduleLifetime",
";",
"$",
"missedTime",
"->",
"setTimestamp",
"(",
"$",
"timestamp",
")",
";",
"if",
"(",
"$",
"scheduleTime",
"<",
"$",
"missedTime",
")",
"{",
"$",
"errorStatus",
"=",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_MISSED",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"'too late for job'",
")",
";",
"}",
"$",
"code",
"=",
"$",
"job",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"cronRegistry",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'job \"%s\" undefined in cron registry'",
",",
"$",
"code",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"tryLockJob",
"(",
"$",
"job",
")",
")",
"{",
"//another cron started this job intermittently. skip.",
"continue",
";",
"}",
"//run job now",
"$",
"callback",
"=",
"$",
"cronRegistry",
"[",
"$",
"code",
"]",
"[",
"'callback'",
"]",
";",
"$",
"args",
"=",
"$",
"cronRegistry",
"[",
"$",
"code",
"]",
"[",
"'args'",
"]",
";",
"$",
"job",
"->",
"setExecuteTime",
"(",
"new",
"\\",
"DateTime",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"job",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"call_user_func_array",
"(",
"$",
"callback",
",",
"$",
"args",
")",
";",
"$",
"job",
"->",
"setStatus",
"(",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_SUCCESS",
")",
"->",
"setFinishTime",
"(",
"new",
"\\",
"DateTime",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"job",
"->",
"setStatus",
"(",
"$",
"errorStatus",
")",
"->",
"setErrorMsg",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"setStackTrace",
"(",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"}",
"$",
"em",
"->",
"persist",
"(",
"$",
"job",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | run cron jobs
@return self | [
"run",
"cron",
"jobs"
] | 94078662dae092c2782829bd1554e1426acdf671 | https://github.com/gregorybesson/AdfabCore/blob/94078662dae092c2782829bd1554e1426acdf671/src/AdfabCore/Service/Cron.php#L160-L230 | train |
gregorybesson/AdfabCore | src/AdfabCore/Service/Cron.php | Cron.cleanLog | public function cleanLog()
{
$em = $this->getEm();
$lifetime = array(
Mapper\Cronjob::STATUS_SUCCESS =>
$this->getSuccessLogLifetime() * 60,
Mapper\Cronjob::STATUS_MISSED =>
$this->getFailureLogLifetime() * 60,
Mapper\Cronjob::STATUS_ERROR =>
$this->getFailureLogLifetime() * 60,
);
$history = $em->getRepository('AdfabCore\Entity\Cronjob')
->getHistory();
$now = time();
foreach ($history as $job) {
if ($job->getExecuteTime()
&& $job->getExecuteTime()->getTimestamp()
< $now - $lifetime[$job->getStatus()]) {
$em->remove($job);
}
}
$em->flush();
return $this;
} | php | public function cleanLog()
{
$em = $this->getEm();
$lifetime = array(
Mapper\Cronjob::STATUS_SUCCESS =>
$this->getSuccessLogLifetime() * 60,
Mapper\Cronjob::STATUS_MISSED =>
$this->getFailureLogLifetime() * 60,
Mapper\Cronjob::STATUS_ERROR =>
$this->getFailureLogLifetime() * 60,
);
$history = $em->getRepository('AdfabCore\Entity\Cronjob')
->getHistory();
$now = time();
foreach ($history as $job) {
if ($job->getExecuteTime()
&& $job->getExecuteTime()->getTimestamp()
< $now - $lifetime[$job->getStatus()]) {
$em->remove($job);
}
}
$em->flush();
return $this;
} | [
"public",
"function",
"cleanLog",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEm",
"(",
")",
";",
"$",
"lifetime",
"=",
"array",
"(",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_SUCCESS",
"=>",
"$",
"this",
"->",
"getSuccessLogLifetime",
"(",
")",
"*",
"60",
",",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_MISSED",
"=>",
"$",
"this",
"->",
"getFailureLogLifetime",
"(",
")",
"*",
"60",
",",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_ERROR",
"=>",
"$",
"this",
"->",
"getFailureLogLifetime",
"(",
")",
"*",
"60",
",",
")",
";",
"$",
"history",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AdfabCore\\Entity\\Cronjob'",
")",
"->",
"getHistory",
"(",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"history",
"as",
"$",
"job",
")",
"{",
"if",
"(",
"$",
"job",
"->",
"getExecuteTime",
"(",
")",
"&&",
"$",
"job",
"->",
"getExecuteTime",
"(",
")",
"->",
"getTimestamp",
"(",
")",
"<",
"$",
"now",
"-",
"$",
"lifetime",
"[",
"$",
"job",
"->",
"getStatus",
"(",
")",
"]",
")",
"{",
"$",
"em",
"->",
"remove",
"(",
"$",
"job",
")",
";",
"}",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | delete old cron job logs
@return self | [
"delete",
"old",
"cron",
"job",
"logs"
] | 94078662dae092c2782829bd1554e1426acdf671 | https://github.com/gregorybesson/AdfabCore/blob/94078662dae092c2782829bd1554e1426acdf671/src/AdfabCore/Service/Cron.php#L333-L360 | train |
gregorybesson/AdfabCore | src/AdfabCore/Service/Cron.php | Cron.tryLockJob | public function tryLockJob(Entity\Cronjob $job)
{
$em = $this->getEm();
$repo = $em->getRepository('AdfabCore\Entity\Cronjob');
if ($job->getStatus() === Mapper\Cronjob::STATUS_PENDING) {
$job->setStatus(Mapper\Cronjob::STATUS_RUNNING);
$em->persist($job);
$em->flush();
// flush() succeeded if reached here;
// otherwise an Exception would have been thrown
return true;
}
return false;
} | php | public function tryLockJob(Entity\Cronjob $job)
{
$em = $this->getEm();
$repo = $em->getRepository('AdfabCore\Entity\Cronjob');
if ($job->getStatus() === Mapper\Cronjob::STATUS_PENDING) {
$job->setStatus(Mapper\Cronjob::STATUS_RUNNING);
$em->persist($job);
$em->flush();
// flush() succeeded if reached here;
// otherwise an Exception would have been thrown
return true;
}
return false;
} | [
"public",
"function",
"tryLockJob",
"(",
"Entity",
"\\",
"Cronjob",
"$",
"job",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEm",
"(",
")",
";",
"$",
"repo",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'AdfabCore\\Entity\\Cronjob'",
")",
";",
"if",
"(",
"$",
"job",
"->",
"getStatus",
"(",
")",
"===",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_PENDING",
")",
"{",
"$",
"job",
"->",
"setStatus",
"(",
"Mapper",
"\\",
"Cronjob",
"::",
"STATUS_RUNNING",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"job",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"// flush() succeeded if reached here;",
"// otherwise an Exception would have been thrown",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | try to acquire a lock on a cron job
set a job to 'running' only if it is currently 'pending'
@param Entity\Cronjob $job
@return bool | [
"try",
"to",
"acquire",
"a",
"lock",
"on",
"a",
"cron",
"job"
] | 94078662dae092c2782829bd1554e1426acdf671 | https://github.com/gregorybesson/AdfabCore/blob/94078662dae092c2782829bd1554e1426acdf671/src/AdfabCore/Service/Cron.php#L380-L395 | train |
gregorybesson/AdfabCore | src/AdfabCore/Service/Cron.php | Cron.matchTime | public static function matchTime($time, $expr)
{
//ArgValidator::assert($time, array('string', 'numeric'));
//ArgValidator::assert($expr, 'string');
$cronExpr = preg_split('/\s+/', $expr, null, PREG_SPLIT_NO_EMPTY);
if (count($cronExpr) !== 5) {
throw new Exception\InvalidArgumentException(sprintf(
'cron expression should have exactly 5 arguments, "%s" given',
$expr
));
}
if (is_string($time)) $time = strtotime($time);
$date = getdate($time);
return self::matchTimeComponent($cronExpr[0], $date['minutes'])
&& self::matchTimeComponent($cronExpr[1], $date['hours'])
&& self::matchTimeComponent($cronExpr[2], $date['mday'])
&& self::matchTimeComponent($cronExpr[3], $date['mon'])
&& self::matchTimeComponent($cronExpr[4], $date['wday']);
} | php | public static function matchTime($time, $expr)
{
//ArgValidator::assert($time, array('string', 'numeric'));
//ArgValidator::assert($expr, 'string');
$cronExpr = preg_split('/\s+/', $expr, null, PREG_SPLIT_NO_EMPTY);
if (count($cronExpr) !== 5) {
throw new Exception\InvalidArgumentException(sprintf(
'cron expression should have exactly 5 arguments, "%s" given',
$expr
));
}
if (is_string($time)) $time = strtotime($time);
$date = getdate($time);
return self::matchTimeComponent($cronExpr[0], $date['minutes'])
&& self::matchTimeComponent($cronExpr[1], $date['hours'])
&& self::matchTimeComponent($cronExpr[2], $date['mday'])
&& self::matchTimeComponent($cronExpr[3], $date['mon'])
&& self::matchTimeComponent($cronExpr[4], $date['wday']);
} | [
"public",
"static",
"function",
"matchTime",
"(",
"$",
"time",
",",
"$",
"expr",
")",
"{",
"//ArgValidator::assert($time, array('string', 'numeric'));",
"//ArgValidator::assert($expr, 'string');",
"$",
"cronExpr",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"expr",
",",
"null",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"if",
"(",
"count",
"(",
"$",
"cronExpr",
")",
"!==",
"5",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'cron expression should have exactly 5 arguments, \"%s\" given'",
",",
"$",
"expr",
")",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"time",
")",
")",
"$",
"time",
"=",
"strtotime",
"(",
"$",
"time",
")",
";",
"$",
"date",
"=",
"getdate",
"(",
"$",
"time",
")",
";",
"return",
"self",
"::",
"matchTimeComponent",
"(",
"$",
"cronExpr",
"[",
"0",
"]",
",",
"$",
"date",
"[",
"'minutes'",
"]",
")",
"&&",
"self",
"::",
"matchTimeComponent",
"(",
"$",
"cronExpr",
"[",
"1",
"]",
",",
"$",
"date",
"[",
"'hours'",
"]",
")",
"&&",
"self",
"::",
"matchTimeComponent",
"(",
"$",
"cronExpr",
"[",
"2",
"]",
",",
"$",
"date",
"[",
"'mday'",
"]",
")",
"&&",
"self",
"::",
"matchTimeComponent",
"(",
"$",
"cronExpr",
"[",
"3",
"]",
",",
"$",
"date",
"[",
"'mon'",
"]",
")",
"&&",
"self",
"::",
"matchTimeComponent",
"(",
"$",
"cronExpr",
"[",
"4",
"]",
",",
"$",
"date",
"[",
"'wday'",
"]",
")",
";",
"}"
] | determine whether a given time falls within the given cron expr
@param string|numeric $time
timestamp or strtotime()-compatible string
@param string $expr
any valid cron expression, in addition supporting:
range: '0-5'
range + interval: '10-59/5'
comma-separated combinations of these: '1,4,7,10-20'
English months: 'january'
English months (abbreviated to three letters): 'jan'
English weekdays: 'monday'
English weekdays (abbreviated to three letters): 'mon'
These text counterparts can be used in all places where their
numerical counterparts are allowed, e.g. 'jan-jun/2'
A full example:
'0-5,10-59/5 * 2-10,15-25 january-june/2 mon-fri' -
every minute between minute 0-5 + every 5th min between 10-59
every hour
every day between day 2-10 and day 15-25
every 2nd month between January-June
Monday-Friday
@throws Exception\InvalidArgumentException on invalid cron expression
@return bool | [
"determine",
"whether",
"a",
"given",
"time",
"falls",
"within",
"the",
"given",
"cron",
"expr"
] | 94078662dae092c2782829bd1554e1426acdf671 | https://github.com/gregorybesson/AdfabCore/blob/94078662dae092c2782829bd1554e1426acdf671/src/AdfabCore/Service/Cron.php#L423-L445 | train |
schpill/thin | src/Minify/Html.php | Html.process | public function process()
{
if ($this->_isXhtml === null) {
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
}
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
$this->_placeholders = array();
// replace SCRIPTs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
, array($this, '_removeScriptCB')
, $this->_html);
// replace STYLEs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
, array($this, '_removeStyleCB')
, $this->_html);
// remove HTML comments (not containing IE conditional comments).
$this->_html = preg_replace_callback(
'/<!--([\\s\\S]*?)-->/'
, array($this, '_commentCB')
, $this->_html);
// replace PREs with placeholders
$this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
, array($this, '_removePreCB')
, $this->_html);
// replace TEXTAREAs with placeholders
$this->_html = preg_replace_callback(
'/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
, array($this, '_removeTextareaCB')
, $this->_html);
// trim each line.
// @todo take into account attribute values that span multiple lines.
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
// remove ws around block/undisplayed elements
$this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
. '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
. '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
. '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
. '|ul)\\b[^>]*>)/i', '$1', $this->_html);
// remove ws outside of all elements
$this->_html = preg_replace_callback(
'/>([^<]+)</'
, array($this, '_outsideTagCB')
, $this->_html);
// use newlines before 1st attribute in open tags (to limit line lengths)
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
// fill placeholders
$this->_html = str_replace(
array_keys($this->_placeholders)
, array_values($this->_placeholders)
, $this->_html
);
return $this->_html;
} | php | public function process()
{
if ($this->_isXhtml === null) {
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
}
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
$this->_placeholders = array();
// replace SCRIPTs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
, array($this, '_removeScriptCB')
, $this->_html);
// replace STYLEs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
, array($this, '_removeStyleCB')
, $this->_html);
// remove HTML comments (not containing IE conditional comments).
$this->_html = preg_replace_callback(
'/<!--([\\s\\S]*?)-->/'
, array($this, '_commentCB')
, $this->_html);
// replace PREs with placeholders
$this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
, array($this, '_removePreCB')
, $this->_html);
// replace TEXTAREAs with placeholders
$this->_html = preg_replace_callback(
'/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
, array($this, '_removeTextareaCB')
, $this->_html);
// trim each line.
// @todo take into account attribute values that span multiple lines.
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
// remove ws around block/undisplayed elements
$this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
. '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
. '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
. '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
. '|ul)\\b[^>]*>)/i', '$1', $this->_html);
// remove ws outside of all elements
$this->_html = preg_replace_callback(
'/>([^<]+)</'
, array($this, '_outsideTagCB')
, $this->_html);
// use newlines before 1st attribute in open tags (to limit line lengths)
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
// fill placeholders
$this->_html = str_replace(
array_keys($this->_placeholders)
, array_values($this->_placeholders)
, $this->_html
);
return $this->_html;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_isXhtml",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_isXhtml",
"=",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"this",
"->",
"_html",
",",
"'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_replacementHash",
"=",
"'MINIFYHTML'",
".",
"md5",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_TIME'",
"]",
")",
";",
"$",
"this",
"->",
"_placeholders",
"=",
"array",
"(",
")",
";",
"// replace SCRIPTs (and minify) with placeholders",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/(\\\\s*)(<script\\\\b[^>]*?>)([\\\\s\\\\S]*?)<\\\\/script>(\\\\s*)/i'",
",",
"array",
"(",
"$",
"this",
",",
"'_removeScriptCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// replace STYLEs (and minify) with placeholders",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/\\\\s*(<style\\\\b[^>]*?>)([\\\\s\\\\S]*?)<\\\\/style>\\\\s*/i'",
",",
"array",
"(",
"$",
"this",
",",
"'_removeStyleCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// remove HTML comments (not containing IE conditional comments).",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/<!--([\\\\s\\\\S]*?)-->/'",
",",
"array",
"(",
"$",
"this",
",",
"'_commentCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// replace PREs with placeholders",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/\\\\s*(<pre\\\\b[^>]*?>[\\\\s\\\\S]*?<\\\\/pre>)\\\\s*/i'",
",",
"array",
"(",
"$",
"this",
",",
"'_removePreCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// replace TEXTAREAs with placeholders",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/\\\\s*(<textarea\\\\b[^>]*?>[\\\\s\\\\S]*?<\\\\/textarea>)\\\\s*/i'",
",",
"array",
"(",
"$",
"this",
",",
"'_removeTextareaCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// trim each line.",
"// @todo take into account attribute values that span multiple lines.",
"$",
"this",
"->",
"_html",
"=",
"preg_replace",
"(",
"'/^\\\\s+|\\\\s+$/m'",
",",
"''",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// remove ws around block/undisplayed elements",
"$",
"this",
"->",
"_html",
"=",
"preg_replace",
"(",
"'/\\\\s+(<\\\\/?(?:area|base(?:font)?|blockquote|body'",
".",
"'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'",
".",
"'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'",
".",
"'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'",
".",
"'|ul)\\\\b[^>]*>)/i'",
",",
"'$1'",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// remove ws outside of all elements",
"$",
"this",
"->",
"_html",
"=",
"preg_replace_callback",
"(",
"'/>([^<]+)</'",
",",
"array",
"(",
"$",
"this",
",",
"'_outsideTagCB'",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// use newlines before 1st attribute in open tags (to limit line lengths)",
"$",
"this",
"->",
"_html",
"=",
"preg_replace",
"(",
"'/(<[a-z\\\\-]+)\\\\s+([^>]+>)/i'",
",",
"\"$1\\n$2\"",
",",
"$",
"this",
"->",
"_html",
")",
";",
"// fill placeholders",
"$",
"this",
"->",
"_html",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_placeholders",
")",
",",
"array_values",
"(",
"$",
"this",
"->",
"_placeholders",
")",
",",
"$",
"this",
"->",
"_html",
")",
";",
"return",
"$",
"this",
"->",
"_html",
";",
"}"
] | Minify the markeup given in the constructor
@return string | [
"Minify",
"the",
"markeup",
"given",
"in",
"the",
"constructor"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Minify/Html.php#L37-L103 | train |
hametuha/pattern | app/Hametuha/Pattern/Command.php | Command.sql | public function sql( $args ) {
list( $table_name ) = $args;
$rows = Model::$list;
if ( ! isset( $rows[ $table_name ] ) ) {
\WP_CLI::error( sprintf( '%s: table is not registered.', $table_name ) );
}
$model = $rows[ $table_name ];
if ( ! class_exists( $model ) ) {
\WP_CLI::error( sprintf( '%s: Model class does not exist.', $model ) );
}
if ( ! $this->is_sub_class_of( $model, Model::class ) ) {
\WP_CLI::error( sprintf( '%s is not sub class of %s.', $model, Model::class ) );
}
/** @var Model $instance */
$instance = $model::get_instance();
\WP_CLI::line( sprintf( '%s: Version %s', $instance->table, $instance->version ) );
$query = $instance->get_tables_schema( $instance->current_version() );
echo "\n" . $query . "\n\n";
\WP_CLI::success( sprintf( '%s letters', number_format_i18n( strlen( $query ) ) ) );
} | php | public function sql( $args ) {
list( $table_name ) = $args;
$rows = Model::$list;
if ( ! isset( $rows[ $table_name ] ) ) {
\WP_CLI::error( sprintf( '%s: table is not registered.', $table_name ) );
}
$model = $rows[ $table_name ];
if ( ! class_exists( $model ) ) {
\WP_CLI::error( sprintf( '%s: Model class does not exist.', $model ) );
}
if ( ! $this->is_sub_class_of( $model, Model::class ) ) {
\WP_CLI::error( sprintf( '%s is not sub class of %s.', $model, Model::class ) );
}
/** @var Model $instance */
$instance = $model::get_instance();
\WP_CLI::line( sprintf( '%s: Version %s', $instance->table, $instance->version ) );
$query = $instance->get_tables_schema( $instance->current_version() );
echo "\n" . $query . "\n\n";
\WP_CLI::success( sprintf( '%s letters', number_format_i18n( strlen( $query ) ) ) );
} | [
"public",
"function",
"sql",
"(",
"$",
"args",
")",
"{",
"list",
"(",
"$",
"table_name",
")",
"=",
"$",
"args",
";",
"$",
"rows",
"=",
"Model",
"::",
"$",
"list",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"rows",
"[",
"$",
"table_name",
"]",
")",
")",
"{",
"\\",
"WP_CLI",
"::",
"error",
"(",
"sprintf",
"(",
"'%s: table is not registered.'",
",",
"$",
"table_name",
")",
")",
";",
"}",
"$",
"model",
"=",
"$",
"rows",
"[",
"$",
"table_name",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"model",
")",
")",
"{",
"\\",
"WP_CLI",
"::",
"error",
"(",
"sprintf",
"(",
"'%s: Model class does not exist.'",
",",
"$",
"model",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is_sub_class_of",
"(",
"$",
"model",
",",
"Model",
"::",
"class",
")",
")",
"{",
"\\",
"WP_CLI",
"::",
"error",
"(",
"sprintf",
"(",
"'%s is not sub class of %s.'",
",",
"$",
"model",
",",
"Model",
"::",
"class",
")",
")",
";",
"}",
"/** @var Model $instance */",
"$",
"instance",
"=",
"$",
"model",
"::",
"get_instance",
"(",
")",
";",
"\\",
"WP_CLI",
"::",
"line",
"(",
"sprintf",
"(",
"'%s: Version %s'",
",",
"$",
"instance",
"->",
"table",
",",
"$",
"instance",
"->",
"version",
")",
")",
";",
"$",
"query",
"=",
"$",
"instance",
"->",
"get_tables_schema",
"(",
"$",
"instance",
"->",
"current_version",
"(",
")",
")",
";",
"echo",
"\"\\n\"",
".",
"$",
"query",
".",
"\"\\n\\n\"",
";",
"\\",
"WP_CLI",
"::",
"success",
"(",
"sprintf",
"(",
"'%s letters'",
",",
"number_format_i18n",
"(",
"strlen",
"(",
"$",
"query",
")",
")",
")",
")",
";",
"}"
] | Display table schema SQL
## OPTIONS
<model_class>
: Model class name of Hametuha\Pattern\Model
## EXAMPLES
wp schema wp_custom_table
@synopsis <table_name>
@param array $args | [
"Display",
"table",
"schema",
"SQL"
] | 562d18f8e750d1c4e52c537839679807a0e3d055 | https://github.com/hametuha/pattern/blob/562d18f8e750d1c4e52c537839679807a0e3d055/app/Hametuha/Pattern/Command.php#L31-L50 | train |
hametuha/pattern | app/Hametuha/Pattern/Command.php | Command.tables | public function tables() {
$table = new \cli\Table();
$rows = Model::$list;
if ( ! $rows ) {
\WP_CLI::error( 'No model is regsitered.' );
}
$table->setHeaders( [ 'Table Name', 'Model Class' ] );
foreach ( $rows as $table_name => $class) {
$table->addRow( [ $table_name, $class ] );
}
$table->display();
} | php | public function tables() {
$table = new \cli\Table();
$rows = Model::$list;
if ( ! $rows ) {
\WP_CLI::error( 'No model is regsitered.' );
}
$table->setHeaders( [ 'Table Name', 'Model Class' ] );
foreach ( $rows as $table_name => $class) {
$table->addRow( [ $table_name, $class ] );
}
$table->display();
} | [
"public",
"function",
"tables",
"(",
")",
"{",
"$",
"table",
"=",
"new",
"\\",
"cli",
"\\",
"Table",
"(",
")",
";",
"$",
"rows",
"=",
"Model",
"::",
"$",
"list",
";",
"if",
"(",
"!",
"$",
"rows",
")",
"{",
"\\",
"WP_CLI",
"::",
"error",
"(",
"'No model is regsitered.'",
")",
";",
"}",
"$",
"table",
"->",
"setHeaders",
"(",
"[",
"'Table Name'",
",",
"'Model Class'",
"]",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"table_name",
"=>",
"$",
"class",
")",
"{",
"$",
"table",
"->",
"addRow",
"(",
"[",
"$",
"table_name",
",",
"$",
"class",
"]",
")",
";",
"}",
"$",
"table",
"->",
"display",
"(",
")",
";",
"}"
] | Get list of tables which generated by Hametuha\Pattern\Model | [
"Get",
"list",
"of",
"tables",
"which",
"generated",
"by",
"Hametuha",
"\\",
"Pattern",
"\\",
"Model"
] | 562d18f8e750d1c4e52c537839679807a0e3d055 | https://github.com/hametuha/pattern/blob/562d18f8e750d1c4e52c537839679807a0e3d055/app/Hametuha/Pattern/Command.php#L55-L66 | train |
alphacomm/alpharpc | src/AlphaRPC/Client/ManagerList.php | ManagerList.add | public function add($manager)
{
if (!is_string($manager)) {
throw new \InvalidArgumentException('ManagerList::add requires $manager to be a string.');
}
$this->managerList[$manager] = $manager;
$this->managerStatus[self::FLAG_AVAILABLE][$manager] = $manager;
return $this;
} | php | public function add($manager)
{
if (!is_string($manager)) {
throw new \InvalidArgumentException('ManagerList::add requires $manager to be a string.');
}
$this->managerList[$manager] = $manager;
$this->managerStatus[self::FLAG_AVAILABLE][$manager] = $manager;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"manager",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"manager",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'ManagerList::add requires $manager to be a string.'",
")",
";",
"}",
"$",
"this",
"->",
"managerList",
"[",
"$",
"manager",
"]",
"=",
"$",
"manager",
";",
"$",
"this",
"->",
"managerStatus",
"[",
"self",
"::",
"FLAG_AVAILABLE",
"]",
"[",
"$",
"manager",
"]",
"=",
"$",
"manager",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a manager dsn to the list.
@param string $manager
@return ManagerList
@throws \InvalidArgumentException | [
"Adds",
"a",
"manager",
"dsn",
"to",
"the",
"list",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/ManagerList.php#L71-L81 | train |
alphacomm/alpharpc | src/AlphaRPC/Client/ManagerList.php | ManagerList.toPrioritizedArray | public function toPrioritizedArray()
{
// Reset the available managers every $this->unavailableCheckAt requests.
if (($this->resetCounter % $this->resetAt) == 0) {
$this->resetAvailableManagers();
}
$this->resetCounter++;
$available =& $this->managerStatus[self::FLAG_AVAILABLE];
$unavailable =& $this->managerStatus[self::FLAG_UNAVAILABLE];
// Shuffle the available managers to distribute load.
shuffle($available);
// Add the unavailable managers at the end.
$managerList = array_merge($available, $unavailable);
return $managerList;
} | php | public function toPrioritizedArray()
{
// Reset the available managers every $this->unavailableCheckAt requests.
if (($this->resetCounter % $this->resetAt) == 0) {
$this->resetAvailableManagers();
}
$this->resetCounter++;
$available =& $this->managerStatus[self::FLAG_AVAILABLE];
$unavailable =& $this->managerStatus[self::FLAG_UNAVAILABLE];
// Shuffle the available managers to distribute load.
shuffle($available);
// Add the unavailable managers at the end.
$managerList = array_merge($available, $unavailable);
return $managerList;
} | [
"public",
"function",
"toPrioritizedArray",
"(",
")",
"{",
"// Reset the available managers every $this->unavailableCheckAt requests.",
"if",
"(",
"(",
"$",
"this",
"->",
"resetCounter",
"%",
"$",
"this",
"->",
"resetAt",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"resetAvailableManagers",
"(",
")",
";",
"}",
"$",
"this",
"->",
"resetCounter",
"++",
";",
"$",
"available",
"=",
"&",
"$",
"this",
"->",
"managerStatus",
"[",
"self",
"::",
"FLAG_AVAILABLE",
"]",
";",
"$",
"unavailable",
"=",
"&",
"$",
"this",
"->",
"managerStatus",
"[",
"self",
"::",
"FLAG_UNAVAILABLE",
"]",
";",
"// Shuffle the available managers to distribute load.",
"shuffle",
"(",
"$",
"available",
")",
";",
"// Add the unavailable managers at the end.",
"$",
"managerList",
"=",
"array_merge",
"(",
"$",
"available",
",",
"$",
"unavailable",
")",
";",
"return",
"$",
"managerList",
";",
"}"
] | Returns an array or manager dsns, sorted by priority.
Available managers get priority over unavailable managers.
Once every x calls all managers will be flagged as available.
This makes sure managers that where unavailable for a period of
time will receive jobs once they get up.
@return array[] | [
"Returns",
"an",
"array",
"or",
"manager",
"dsns",
"sorted",
"by",
"priority",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/ManagerList.php#L106-L124 | train |
alphacomm/alpharpc | src/AlphaRPC/Client/ManagerList.php | ManagerList.resetAvailableManagers | protected function resetAvailableManagers()
{
$this->managerStatus[self::FLAG_AVAILABLE] = $this->managerList;
$this->managerStatus[self::FLAG_UNAVAILABLE] = array();
} | php | protected function resetAvailableManagers()
{
$this->managerStatus[self::FLAG_AVAILABLE] = $this->managerList;
$this->managerStatus[self::FLAG_UNAVAILABLE] = array();
} | [
"protected",
"function",
"resetAvailableManagers",
"(",
")",
"{",
"$",
"this",
"->",
"managerStatus",
"[",
"self",
"::",
"FLAG_AVAILABLE",
"]",
"=",
"$",
"this",
"->",
"managerList",
";",
"$",
"this",
"->",
"managerStatus",
"[",
"self",
"::",
"FLAG_UNAVAILABLE",
"]",
"=",
"array",
"(",
")",
";",
"}"
] | Makes all managers available. | [
"Makes",
"all",
"managers",
"available",
"."
] | cf162854500554c4ba8d39f2675de35a49c30ed0 | https://github.com/alphacomm/alpharpc/blob/cf162854500554c4ba8d39f2675de35a49c30ed0/src/AlphaRPC/Client/ManagerList.php#L156-L160 | train |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Api/Validator.php | Radial_Core_Helper_Api_Validator.returnClientErrorResponse | public function returnClientErrorResponse(Zend_Http_Response $response)
{
$status = $response->getStatus();
switch ($status) {
case 401:
$message = self::INVALID_API_KEY;
break;
case 403:
$message = self::INVALID_STORE_ID;
break;
case 408:
$message = self::NETWORK_TIMEOUT;
break;
default:
$message = self::UNKNOWN_FAILURE;
break;
}
return array(
'message' => Mage::helper('radial_core')->__($message), 'success' => false
);
} | php | public function returnClientErrorResponse(Zend_Http_Response $response)
{
$status = $response->getStatus();
switch ($status) {
case 401:
$message = self::INVALID_API_KEY;
break;
case 403:
$message = self::INVALID_STORE_ID;
break;
case 408:
$message = self::NETWORK_TIMEOUT;
break;
default:
$message = self::UNKNOWN_FAILURE;
break;
}
return array(
'message' => Mage::helper('radial_core')->__($message), 'success' => false
);
} | [
"public",
"function",
"returnClientErrorResponse",
"(",
"Zend_Http_Response",
"$",
"response",
")",
"{",
"$",
"status",
"=",
"$",
"response",
"->",
"getStatus",
"(",
")",
";",
"switch",
"(",
"$",
"status",
")",
"{",
"case",
"401",
":",
"$",
"message",
"=",
"self",
"::",
"INVALID_API_KEY",
";",
"break",
";",
"case",
"403",
":",
"$",
"message",
"=",
"self",
"::",
"INVALID_STORE_ID",
";",
"break",
";",
"case",
"408",
":",
"$",
"message",
"=",
"self",
"::",
"NETWORK_TIMEOUT",
";",
"break",
";",
"default",
":",
"$",
"message",
"=",
"self",
"::",
"UNKNOWN_FAILURE",
";",
"break",
";",
"}",
"return",
"array",
"(",
"'message'",
"=>",
"Mage",
"::",
"helper",
"(",
"'radial_core'",
")",
"->",
"__",
"(",
"$",
"message",
")",
",",
"'success'",
"=>",
"false",
")",
";",
"}"
] | Return the response data for client errors - 4XX range errors.
@param Zend_Http_Response $response
@return array | [
"Return",
"the",
"response",
"data",
"for",
"client",
"errors",
"-",
"4XX",
"range",
"errors",
"."
] | 9bb5f218d9caf79eab8598f4f8447037a0cc6355 | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Api/Validator.php#L58-L78 | train |
schpill/thin | src/Env.php | Env.load | public static function load($path, $file = '.env')
{
if (!is_string($file)) {
$file = '.env';
}
$filePath = rtrim($path, '/') . '/' . $file;
if (!is_readable($filePath) || !is_file($filePath)) {
throw new \InvalidArgumentException(
sprintf(
"Dotenv: Environment file %s not found or not readable. " .
"Create file with your environment settings at %s",
$file,
$filePath
)
);
}
// Read file into an array of lines with auto-detected line endings
$autodetect = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', '1');
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
ini_set('auto_detect_line_endings', $autodetect);
foreach ($lines as $line) {
// Disregard comments
if (strpos(trim($line), '#') === 0) {
continue;
}
// Only use non-empty lines that look like setters
if (strpos($line, '=') !== false) {
static::setEnvironmentVariable($line);
}
}
} | php | public static function load($path, $file = '.env')
{
if (!is_string($file)) {
$file = '.env';
}
$filePath = rtrim($path, '/') . '/' . $file;
if (!is_readable($filePath) || !is_file($filePath)) {
throw new \InvalidArgumentException(
sprintf(
"Dotenv: Environment file %s not found or not readable. " .
"Create file with your environment settings at %s",
$file,
$filePath
)
);
}
// Read file into an array of lines with auto-detected line endings
$autodetect = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', '1');
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
ini_set('auto_detect_line_endings', $autodetect);
foreach ($lines as $line) {
// Disregard comments
if (strpos(trim($line), '#') === 0) {
continue;
}
// Only use non-empty lines that look like setters
if (strpos($line, '=') !== false) {
static::setEnvironmentVariable($line);
}
}
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"path",
",",
"$",
"file",
"=",
"'.env'",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"'.env'",
";",
"}",
"$",
"filePath",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"file",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"filePath",
")",
"||",
"!",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Dotenv: Environment file %s not found or not readable. \"",
".",
"\"Create file with your environment settings at %s\"",
",",
"$",
"file",
",",
"$",
"filePath",
")",
")",
";",
"}",
"// Read file into an array of lines with auto-detected line endings",
"$",
"autodetect",
"=",
"ini_get",
"(",
"'auto_detect_line_endings'",
")",
";",
"ini_set",
"(",
"'auto_detect_line_endings'",
",",
"'1'",
")",
";",
"$",
"lines",
"=",
"file",
"(",
"$",
"filePath",
",",
"FILE_IGNORE_NEW_LINES",
"|",
"FILE_SKIP_EMPTY_LINES",
")",
";",
"ini_set",
"(",
"'auto_detect_line_endings'",
",",
"$",
"autodetect",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"// Disregard comments",
"if",
"(",
"strpos",
"(",
"trim",
"(",
"$",
"line",
")",
",",
"'#'",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"// Only use non-empty lines that look like setters",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"'='",
")",
"!==",
"false",
")",
"{",
"static",
"::",
"setEnvironmentVariable",
"(",
"$",
"line",
")",
";",
"}",
"}",
"}"
] | Load `.env` file in given directory | [
"Load",
".",
"env",
"file",
"in",
"given",
"directory"
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Env.php#L15-L53 | train |
schpill/thin | src/Env.php | Env.required | public static function required($environmentVariables, array $allowedValues = array())
{
$environmentVariables = (array) $environmentVariables;
$missingEnvironmentVariables = [];
foreach ($environmentVariables as $environmentVariable) {
$value = static::findEnvironmentVariable($environmentVariable);
if (is_null($value)) {
$missingEnvironmentVariables[] = $environmentVariable;
} elseif ($allowedValues) {
if (!Arrays::in($value, $allowedValues)) {
// may differentiate in the future, but for now this does the job
$missingEnvironmentVariables[] = $environmentVariable;
}
}
}
if ($missingEnvironmentVariables) {
throw new \RuntimeException(
sprintf(
"Required environment variable missing, or value not allowed: '%s'",
implode("', '", $missingEnvironmentVariables)
)
);
}
return true;
} | php | public static function required($environmentVariables, array $allowedValues = array())
{
$environmentVariables = (array) $environmentVariables;
$missingEnvironmentVariables = [];
foreach ($environmentVariables as $environmentVariable) {
$value = static::findEnvironmentVariable($environmentVariable);
if (is_null($value)) {
$missingEnvironmentVariables[] = $environmentVariable;
} elseif ($allowedValues) {
if (!Arrays::in($value, $allowedValues)) {
// may differentiate in the future, but for now this does the job
$missingEnvironmentVariables[] = $environmentVariable;
}
}
}
if ($missingEnvironmentVariables) {
throw new \RuntimeException(
sprintf(
"Required environment variable missing, or value not allowed: '%s'",
implode("', '", $missingEnvironmentVariables)
)
);
}
return true;
} | [
"public",
"static",
"function",
"required",
"(",
"$",
"environmentVariables",
",",
"array",
"$",
"allowedValues",
"=",
"array",
"(",
")",
")",
"{",
"$",
"environmentVariables",
"=",
"(",
"array",
")",
"$",
"environmentVariables",
";",
"$",
"missingEnvironmentVariables",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"environmentVariables",
"as",
"$",
"environmentVariable",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"findEnvironmentVariable",
"(",
"$",
"environmentVariable",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"missingEnvironmentVariables",
"[",
"]",
"=",
"$",
"environmentVariable",
";",
"}",
"elseif",
"(",
"$",
"allowedValues",
")",
"{",
"if",
"(",
"!",
"Arrays",
"::",
"in",
"(",
"$",
"value",
",",
"$",
"allowedValues",
")",
")",
"{",
"// may differentiate in the future, but for now this does the job",
"$",
"missingEnvironmentVariables",
"[",
"]",
"=",
"$",
"environmentVariable",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"missingEnvironmentVariables",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"\"Required environment variable missing, or value not allowed: '%s'\"",
",",
"implode",
"(",
"\"', '\"",
",",
"$",
"missingEnvironmentVariables",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Require specified ENV vars to be present, or throw Exception.
You can also pass through an set of allowed values for the environment variable.
@throws \RuntimeException
@param mixed $environmentVariables the name of the environment variable or an array of names
@param string[] $allowedValues
@return true (or throws exception on error) | [
"Require",
"specified",
"ENV",
"vars",
"to",
"be",
"present",
"or",
"throw",
"Exception",
".",
"You",
"can",
"also",
"pass",
"through",
"an",
"set",
"of",
"allowed",
"values",
"for",
"the",
"environment",
"variable",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Env.php#L91-L119 | train |
schpill/thin | src/Env.php | Env.sanitiseVariableValue | protected static function sanitiseVariableValue($value)
{
$value = trim($value);
if (!$value) {
return '';
}
if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
$quote = $value[0];
$regexPattern = sprintf('/^
%1$s # match a quote at the start of the value
( # capturing sub-pattern used
(?: # we do not need to capture this
[^%1$s\\\\] # any character other than a quote or backslash
|\\\\\\\\ # or two backslashes together
|\\\\%1$s # or an escaped quote e.g \"
)* # as many characters that match the previous rules
) # end of the capturing sub-pattern
%1$s # and the closing quote
.*$ # and discard any string after the closing quote
/mx',
$quote
);
$value = preg_replace($regexPattern, '$1', $value);
$value = str_replace("\\$quote", $quote, $value);
$value = str_replace('\\\\', '\\', $value);
} else {
$parts = explode(' #', $value, 2);
$value = $parts[0];
}
return trim($value);
} | php | protected static function sanitiseVariableValue($value)
{
$value = trim($value);
if (!$value) {
return '';
}
if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
$quote = $value[0];
$regexPattern = sprintf('/^
%1$s # match a quote at the start of the value
( # capturing sub-pattern used
(?: # we do not need to capture this
[^%1$s\\\\] # any character other than a quote or backslash
|\\\\\\\\ # or two backslashes together
|\\\\%1$s # or an escaped quote e.g \"
)* # as many characters that match the previous rules
) # end of the capturing sub-pattern
%1$s # and the closing quote
.*$ # and discard any string after the closing quote
/mx',
$quote
);
$value = preg_replace($regexPattern, '$1', $value);
$value = str_replace("\\$quote", $quote, $value);
$value = str_replace('\\\\', '\\', $value);
} else {
$parts = explode(' #', $value, 2);
$value = $parts[0];
}
return trim($value);
} | [
"protected",
"static",
"function",
"sanitiseVariableValue",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"strpbrk",
"(",
"$",
"value",
"[",
"0",
"]",
",",
"'\"\\''",
")",
"!==",
"false",
")",
"{",
"// value starts with a quote",
"$",
"quote",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"$",
"regexPattern",
"=",
"sprintf",
"(",
"'/^\n %1$s # match a quote at the start of the value\n ( # capturing sub-pattern used\n (?: # we do not need to capture this\n [^%1$s\\\\\\\\] # any character other than a quote or backslash\n |\\\\\\\\\\\\\\\\ # or two backslashes together\n |\\\\\\\\%1$s # or an escaped quote e.g \\\"\n )* # as many characters that match the previous rules\n ) # end of the capturing sub-pattern\n %1$s # and the closing quote\n .*$ # and discard any string after the closing quote\n /mx'",
",",
"$",
"quote",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"$",
"regexPattern",
",",
"'$1'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"\"\\\\$quote\"",
",",
"$",
"quote",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"'\\\\\\\\'",
",",
"'\\\\'",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' #'",
",",
"$",
"value",
",",
"2",
")",
";",
"$",
"value",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"}",
"return",
"trim",
"(",
"$",
"value",
")",
";",
"}"
] | Strips quotes from the environment variable value.
@param $value
@return string | [
"Strips",
"quotes",
"from",
"the",
"environment",
"variable",
"value",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Env.php#L165-L200 | train |
ScreamingDev/phpsemver | lib/PHPSemVer/Trigger/Functions/BodyChanged.php | BodyChanged.handle | public function handle($old, $new)
{
if ( ! $this->canHandle($old) || ! $this->canHandle($new)) {
return null;
}
if ($this->equals($old, $new)) {
return false;
}
$this->lastException = new FailedConstraint(
sprintf(
'%s() body changed',
$new->name
)
);
return true;
} | php | public function handle($old, $new)
{
if ( ! $this->canHandle($old) || ! $this->canHandle($new)) {
return null;
}
if ($this->equals($old, $new)) {
return false;
}
$this->lastException = new FailedConstraint(
sprintf(
'%s() body changed',
$new->name
)
);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"old",
",",
"$",
"new",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canHandle",
"(",
"$",
"old",
")",
"||",
"!",
"$",
"this",
"->",
"canHandle",
"(",
"$",
"new",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"equals",
"(",
"$",
"old",
",",
"$",
"new",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"lastException",
"=",
"new",
"FailedConstraint",
"(",
"sprintf",
"(",
"'%s() body changed'",
",",
"$",
"new",
"->",
"name",
")",
")",
";",
"return",
"true",
";",
"}"
] | Check if body of function has changed.
@param Function_ $old
@param Function_ $new
@return bool | [
"Check",
"if",
"body",
"of",
"function",
"has",
"changed",
"."
] | 11a4bc508f71dee73d4f5fee2e9d39e7984d3e15 | https://github.com/ScreamingDev/phpsemver/blob/11a4bc508f71dee73d4f5fee2e9d39e7984d3e15/lib/PHPSemVer/Trigger/Functions/BodyChanged.php#L51-L69 | train |
ScreamingDev/phpsemver | lib/PHPSemVer/Trigger/Functions/BodyChanged.php | BodyChanged.equals | protected function equals($old, $new)
{
if (is_array($old)) {
// compare arrays
if (array_keys($old) != array_keys($new)) {
return false;
}
foreach (array_keys($old) as $key) {
if ( ! $this->equals($old[$key], $new[$key])) {
return false;
}
}
return true;
}
if ( ! is_object($old) ) {
// compare non-array scalars
return ($old == $new);
}
if (get_class($old) != get_class($new)) {
// compare object by class name
return false;
}
// compare each sub-node
foreach ($old->getSubNodeNames() as $property) {
if ( ! $this->equals($old->$property, $new->$property)) {
return false;
}
}
return true;
} | php | protected function equals($old, $new)
{
if (is_array($old)) {
// compare arrays
if (array_keys($old) != array_keys($new)) {
return false;
}
foreach (array_keys($old) as $key) {
if ( ! $this->equals($old[$key], $new[$key])) {
return false;
}
}
return true;
}
if ( ! is_object($old) ) {
// compare non-array scalars
return ($old == $new);
}
if (get_class($old) != get_class($new)) {
// compare object by class name
return false;
}
// compare each sub-node
foreach ($old->getSubNodeNames() as $property) {
if ( ! $this->equals($old->$property, $new->$property)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"equals",
"(",
"$",
"old",
",",
"$",
"new",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"old",
")",
")",
"{",
"// compare arrays",
"if",
"(",
"array_keys",
"(",
"$",
"old",
")",
"!=",
"array_keys",
"(",
"$",
"new",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"old",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"equals",
"(",
"$",
"old",
"[",
"$",
"key",
"]",
",",
"$",
"new",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"old",
")",
")",
"{",
"// compare non-array scalars",
"return",
"(",
"$",
"old",
"==",
"$",
"new",
")",
";",
"}",
"if",
"(",
"get_class",
"(",
"$",
"old",
")",
"!=",
"get_class",
"(",
"$",
"new",
")",
")",
"{",
"// compare object by class name",
"return",
"false",
";",
"}",
"// compare each sub-node",
"foreach",
"(",
"$",
"old",
"->",
"getSubNodeNames",
"(",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"equals",
"(",
"$",
"old",
"->",
"$",
"property",
",",
"$",
"new",
"->",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check if two Node trees are equal.
@param Node $old
@param Node $new
@return bool | [
"Check",
"if",
"two",
"Node",
"trees",
"are",
"equal",
"."
] | 11a4bc508f71dee73d4f5fee2e9d39e7984d3e15 | https://github.com/ScreamingDev/phpsemver/blob/11a4bc508f71dee73d4f5fee2e9d39e7984d3e15/lib/PHPSemVer/Trigger/Functions/BodyChanged.php#L84-L119 | train |
ElMijo/php-html-dom | src/PHPHtmlDom/Core/PHPHtmlDomLog.php | PHPHtmlDomLog.logError | final public function logError($msg_code,$data = array())
{
self::write(self::compileMessage(self::$error_msg[$msg_code],$data), PEL_ERROR);
} | php | final public function logError($msg_code,$data = array())
{
self::write(self::compileMessage(self::$error_msg[$msg_code],$data), PEL_ERROR);
} | [
"final",
"public",
"function",
"logError",
"(",
"$",
"msg_code",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"self",
"::",
"write",
"(",
"self",
"::",
"compileMessage",
"(",
"self",
"::",
"$",
"error_msg",
"[",
"$",
"msg_code",
"]",
",",
"$",
"data",
")",
",",
"PEL_ERROR",
")",
";",
"}"
] | Metodo que permite escribir un log de Error.
@param string $msg_code Cadena de texto con el codigo del mensaje de error.
@param array $data arreglo con los parametros necesarios para escribir el log.
@return void | [
"Metodo",
"que",
"permite",
"escribir",
"un",
"log",
"de",
"Error",
"."
] | 6f294e26f37571e100b885e32b76245c144da6e2 | https://github.com/ElMijo/php-html-dom/blob/6f294e26f37571e100b885e32b76245c144da6e2/src/PHPHtmlDom/Core/PHPHtmlDomLog.php#L43-L46 | train |
ElMijo/php-html-dom | src/PHPHtmlDom/Core/PHPHtmlDomLog.php | PHPHtmlDomLog.logWarn | final public function logWarn($msg_code,$data = array())
{
self::write(self::compileMessage(self::$warn_msg[$msg_code],$data), PEL_WARNING);
} | php | final public function logWarn($msg_code,$data = array())
{
self::write(self::compileMessage(self::$warn_msg[$msg_code],$data), PEL_WARNING);
} | [
"final",
"public",
"function",
"logWarn",
"(",
"$",
"msg_code",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"self",
"::",
"write",
"(",
"self",
"::",
"compileMessage",
"(",
"self",
"::",
"$",
"warn_msg",
"[",
"$",
"msg_code",
"]",
",",
"$",
"data",
")",
",",
"PEL_WARNING",
")",
";",
"}"
] | Metodo que permite escribir un log de Advertencia.
@param string $msg_code Cadena de texto con el codigo del mensaje de advertencia.
@param array $data arreglo con los parametros necesarios para escribir el log.
@return void | [
"Metodo",
"que",
"permite",
"escribir",
"un",
"log",
"de",
"Advertencia",
"."
] | 6f294e26f37571e100b885e32b76245c144da6e2 | https://github.com/ElMijo/php-html-dom/blob/6f294e26f37571e100b885e32b76245c144da6e2/src/PHPHtmlDom/Core/PHPHtmlDomLog.php#L54-L57 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.session | public function session ()
{
if (!($this->session instanceof Session))
{
$this->session = Session::singleton ($this->sessionID);
}
return $this->session;
} | php | public function session ()
{
if (!($this->session instanceof Session))
{
$this->session = Session::singleton ($this->sessionID);
}
return $this->session;
} | [
"public",
"function",
"session",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"session",
"instanceof",
"Session",
")",
")",
"{",
"$",
"this",
"->",
"session",
"=",
"Session",
"::",
"singleton",
"(",
"$",
"this",
"->",
"sessionID",
")",
";",
"}",
"return",
"$",
"this",
"->",
"session",
";",
"}"
] | Return user session
@return \Sonic\Resource\Session | [
"Return",
"user",
"session"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L295-L305 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.setSessionData | public function setSessionData ()
{
$arr = $this->toArray ();
$arr['login_timestamp'] = $this->loginTimestamp;
$arr['last_action'] = $this->lastAction;
$this->session ()->set (get_called_class (), serialize ($arr));
} | php | public function setSessionData ()
{
$arr = $this->toArray ();
$arr['login_timestamp'] = $this->loginTimestamp;
$arr['last_action'] = $this->lastAction;
$this->session ()->set (get_called_class (), serialize ($arr));
} | [
"public",
"function",
"setSessionData",
"(",
")",
"{",
"$",
"arr",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"$",
"arr",
"[",
"'login_timestamp'",
"]",
"=",
"$",
"this",
"->",
"loginTimestamp",
";",
"$",
"arr",
"[",
"'last_action'",
"]",
"=",
"$",
"this",
"->",
"lastAction",
";",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"set",
"(",
"get_called_class",
"(",
")",
",",
"serialize",
"(",
"$",
"arr",
")",
")",
";",
"}"
] | Set user data in a session
@return void | [
"Set",
"user",
"data",
"in",
"a",
"session"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L353-L363 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.updateLastAction | public function updateLastAction ()
{
$arr = $this->getSessionData ();
$this->lastAction = time ();
$arr['last_action'] = $this->lastAction;
$this->session ()->set (get_called_class (), serialize ($arr));
} | php | public function updateLastAction ()
{
$arr = $this->getSessionData ();
$this->lastAction = time ();
$arr['last_action'] = $this->lastAction;
$this->session ()->set (get_called_class (), serialize ($arr));
} | [
"public",
"function",
"updateLastAction",
"(",
")",
"{",
"$",
"arr",
"=",
"$",
"this",
"->",
"getSessionData",
"(",
")",
";",
"$",
"this",
"->",
"lastAction",
"=",
"time",
"(",
")",
";",
"$",
"arr",
"[",
"'last_action'",
"]",
"=",
"$",
"this",
"->",
"lastAction",
";",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"set",
"(",
"get_called_class",
"(",
")",
",",
"serialize",
"(",
"$",
"arr",
")",
")",
";",
"}"
] | Update the last action time to the current time
@return void | [
"Update",
"the",
"last",
"action",
"time",
"to",
"the",
"current",
"time"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L371-L381 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.initSession | public function initSession ()
{
// Get session
$session = $this->getSessionData ();
// Check session is valid
if ($this->checkSession ($session) !== TRUE)
{
return $this->Logout ('invalid_session');
}
// Load user from session
$this->fromSessionData ();
// Read user
if (!$this->Read ())
{
return $this->Logout ('user_read_error');
}
// Reset password
$this->reset ('password');
// If the user is not active or the active status has changed
if ($session['active'] != $this->iget ('active') || !$this->iget ('active'))
{
return $this->Logout ('inactive');
}
// Check if the session has timed out
if ($this->session ()->timedOut ($session['last_action']))
{
return $this->Logout ('timeout');
}
// Update action time
$this->updateLastAction ();
// Set login status
$this->loggedIn = TRUE;
// Redirect to originally requested URL
if ($this->session ()->get ('requested_url'))
{
$url = $this->session ()->get ('requested_url');
$this->session ()->set ('requested_url', FALSE);
new Redirect ($url);
}
// return TRUE
return TRUE;
} | php | public function initSession ()
{
// Get session
$session = $this->getSessionData ();
// Check session is valid
if ($this->checkSession ($session) !== TRUE)
{
return $this->Logout ('invalid_session');
}
// Load user from session
$this->fromSessionData ();
// Read user
if (!$this->Read ())
{
return $this->Logout ('user_read_error');
}
// Reset password
$this->reset ('password');
// If the user is not active or the active status has changed
if ($session['active'] != $this->iget ('active') || !$this->iget ('active'))
{
return $this->Logout ('inactive');
}
// Check if the session has timed out
if ($this->session ()->timedOut ($session['last_action']))
{
return $this->Logout ('timeout');
}
// Update action time
$this->updateLastAction ();
// Set login status
$this->loggedIn = TRUE;
// Redirect to originally requested URL
if ($this->session ()->get ('requested_url'))
{
$url = $this->session ()->get ('requested_url');
$this->session ()->set ('requested_url', FALSE);
new Redirect ($url);
}
// return TRUE
return TRUE;
} | [
"public",
"function",
"initSession",
"(",
")",
"{",
"// Get session",
"$",
"session",
"=",
"$",
"this",
"->",
"getSessionData",
"(",
")",
";",
"// Check session is valid",
"if",
"(",
"$",
"this",
"->",
"checkSession",
"(",
"$",
"session",
")",
"!==",
"TRUE",
")",
"{",
"return",
"$",
"this",
"->",
"Logout",
"(",
"'invalid_session'",
")",
";",
"}",
"// Load user from session",
"$",
"this",
"->",
"fromSessionData",
"(",
")",
";",
"// Read user",
"if",
"(",
"!",
"$",
"this",
"->",
"Read",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Logout",
"(",
"'user_read_error'",
")",
";",
"}",
"// Reset password",
"$",
"this",
"->",
"reset",
"(",
"'password'",
")",
";",
"// If the user is not active or the active status has changed",
"if",
"(",
"$",
"session",
"[",
"'active'",
"]",
"!=",
"$",
"this",
"->",
"iget",
"(",
"'active'",
")",
"||",
"!",
"$",
"this",
"->",
"iget",
"(",
"'active'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Logout",
"(",
"'inactive'",
")",
";",
"}",
"// Check if the session has timed out",
"if",
"(",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"timedOut",
"(",
"$",
"session",
"[",
"'last_action'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Logout",
"(",
"'timeout'",
")",
";",
"}",
"// Update action time",
"$",
"this",
"->",
"updateLastAction",
"(",
")",
";",
"// Set login status",
"$",
"this",
"->",
"loggedIn",
"=",
"TRUE",
";",
"// Redirect to originally requested URL",
"if",
"(",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'requested_url'",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'requested_url'",
")",
";",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"set",
"(",
"'requested_url'",
",",
"FALSE",
")",
";",
"new",
"Redirect",
"(",
"$",
"url",
")",
";",
"}",
"// return TRUE",
"return",
"TRUE",
";",
"}"
] | Initialise a user session and check it is valid
@return string|boolean Error | [
"Initialise",
"a",
"user",
"session",
"and",
"check",
"it",
"is",
"valid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L389-L453 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.validSession | public function validSession ()
{
// Get session
$session = $this->getSessionData ();
// Check session is valid
if ($this->checkSession ($session) !== TRUE)
{
$this->loggedIn = FALSE;
return FALSE;
}
// If the user is not active or the active status has changed
if ($session['active'] !== $this->iget ('active') || !$this->iget ('active'))
{
$this->loggedIn = FALSE;
return FALSE;
}
// Check if the session has timed out
if ($this->session ()->timedOut ($session['last_action']))
{
$this->loggedIn = FALSE;
return FALSE;
}
// Set login status
$this->loggedIn = TRUE;
// Return TRUE
return TRUE;
} | php | public function validSession ()
{
// Get session
$session = $this->getSessionData ();
// Check session is valid
if ($this->checkSession ($session) !== TRUE)
{
$this->loggedIn = FALSE;
return FALSE;
}
// If the user is not active or the active status has changed
if ($session['active'] !== $this->iget ('active') || !$this->iget ('active'))
{
$this->loggedIn = FALSE;
return FALSE;
}
// Check if the session has timed out
if ($this->session ()->timedOut ($session['last_action']))
{
$this->loggedIn = FALSE;
return FALSE;
}
// Set login status
$this->loggedIn = TRUE;
// Return TRUE
return TRUE;
} | [
"public",
"function",
"validSession",
"(",
")",
"{",
"// Get session",
"$",
"session",
"=",
"$",
"this",
"->",
"getSessionData",
"(",
")",
";",
"// Check session is valid",
"if",
"(",
"$",
"this",
"->",
"checkSession",
"(",
"$",
"session",
")",
"!==",
"TRUE",
")",
"{",
"$",
"this",
"->",
"loggedIn",
"=",
"FALSE",
";",
"return",
"FALSE",
";",
"}",
"// If the user is not active or the active status has changed",
"if",
"(",
"$",
"session",
"[",
"'active'",
"]",
"!==",
"$",
"this",
"->",
"iget",
"(",
"'active'",
")",
"||",
"!",
"$",
"this",
"->",
"iget",
"(",
"'active'",
")",
")",
"{",
"$",
"this",
"->",
"loggedIn",
"=",
"FALSE",
";",
"return",
"FALSE",
";",
"}",
"// Check if the session has timed out",
"if",
"(",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"timedOut",
"(",
"$",
"session",
"[",
"'last_action'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"loggedIn",
"=",
"FALSE",
";",
"return",
"FALSE",
";",
"}",
"// Set login status",
"$",
"this",
"->",
"loggedIn",
"=",
"TRUE",
";",
"// Return TRUE",
"return",
"TRUE",
";",
"}"
] | Whether the user has a valid session
@return boolean | [
"Whether",
"the",
"user",
"has",
"a",
"valid",
"session"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L461-L500 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.checkSession | public function checkSession ($session = FALSE)
{
// If there is no session, get it
if ($session === FALSE)
{
$session = $this->getSessionData ();
}
// No id
if (!Parser::_ak ($session, 'id', FALSE))
{
return 'no_id';
}
// No email
if (!Parser::_ak ($session, 'email', FALSE))
{
return 'no_email';
}
// No login timestamp
if (!Parser::_ak ($session, 'login_timestamp', FALSE))
{
return 'no_login_timestamp';
}
// No last action
if (!Parser::_ak ($session, 'last_action', FALSE))
{
return 'no_last_action';
}
// No active status
if (!Parser::_ak ($session, 'active', FALSE))
{
return 'no_active';
}
// return TRUE
return TRUE;
} | php | public function checkSession ($session = FALSE)
{
// If there is no session, get it
if ($session === FALSE)
{
$session = $this->getSessionData ();
}
// No id
if (!Parser::_ak ($session, 'id', FALSE))
{
return 'no_id';
}
// No email
if (!Parser::_ak ($session, 'email', FALSE))
{
return 'no_email';
}
// No login timestamp
if (!Parser::_ak ($session, 'login_timestamp', FALSE))
{
return 'no_login_timestamp';
}
// No last action
if (!Parser::_ak ($session, 'last_action', FALSE))
{
return 'no_last_action';
}
// No active status
if (!Parser::_ak ($session, 'active', FALSE))
{
return 'no_active';
}
// return TRUE
return TRUE;
} | [
"public",
"function",
"checkSession",
"(",
"$",
"session",
"=",
"FALSE",
")",
"{",
"// If there is no session, get it",
"if",
"(",
"$",
"session",
"===",
"FALSE",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"getSessionData",
"(",
")",
";",
"}",
"// No id",
"if",
"(",
"!",
"Parser",
"::",
"_ak",
"(",
"$",
"session",
",",
"'id'",
",",
"FALSE",
")",
")",
"{",
"return",
"'no_id'",
";",
"}",
"// No email",
"if",
"(",
"!",
"Parser",
"::",
"_ak",
"(",
"$",
"session",
",",
"'email'",
",",
"FALSE",
")",
")",
"{",
"return",
"'no_email'",
";",
"}",
"// No login timestamp",
"if",
"(",
"!",
"Parser",
"::",
"_ak",
"(",
"$",
"session",
",",
"'login_timestamp'",
",",
"FALSE",
")",
")",
"{",
"return",
"'no_login_timestamp'",
";",
"}",
"// No last action",
"if",
"(",
"!",
"Parser",
"::",
"_ak",
"(",
"$",
"session",
",",
"'last_action'",
",",
"FALSE",
")",
")",
"{",
"return",
"'no_last_action'",
";",
"}",
"// No active status",
"if",
"(",
"!",
"Parser",
"::",
"_ak",
"(",
"$",
"session",
",",
"'active'",
",",
"FALSE",
")",
")",
"{",
"return",
"'no_active'",
";",
"}",
"// return TRUE",
"return",
"TRUE",
";",
"}"
] | Check that a session is valid
@param array $session Session data to check
@return string|boolean Error | [
"Check",
"that",
"a",
"session",
"is",
"valid"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L509-L558 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User.Logout | public function Logout ($reason = FALSE)
{
// Set login status
$this->loggedIn = FALSE;
// Destroy session
$this->session ()->Destroy ();
// Remove session data
$this->_sessionData = FALSE;
// Create a new session
$this->session ()->Create ();
$this->session ()->Refresh ();
// Store requested URL if there is a reason we're logging out
// If no reason then just a logout request, so we dont want to store
// it else we'll create a loop should they try to log back in.
if ($reason !== FALSE)
{
$this->session ()->set ('requested_url', $_SERVER['REQUEST_URI']);
}
// Return
return $reason;
} | php | public function Logout ($reason = FALSE)
{
// Set login status
$this->loggedIn = FALSE;
// Destroy session
$this->session ()->Destroy ();
// Remove session data
$this->_sessionData = FALSE;
// Create a new session
$this->session ()->Create ();
$this->session ()->Refresh ();
// Store requested URL if there is a reason we're logging out
// If no reason then just a logout request, so we dont want to store
// it else we'll create a loop should they try to log back in.
if ($reason !== FALSE)
{
$this->session ()->set ('requested_url', $_SERVER['REQUEST_URI']);
}
// Return
return $reason;
} | [
"public",
"function",
"Logout",
"(",
"$",
"reason",
"=",
"FALSE",
")",
"{",
"// Set login status",
"$",
"this",
"->",
"loggedIn",
"=",
"FALSE",
";",
"// Destroy session",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"Destroy",
"(",
")",
";",
"// Remove session data",
"$",
"this",
"->",
"_sessionData",
"=",
"FALSE",
";",
"// Create a new session",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"Create",
"(",
")",
";",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"Refresh",
"(",
")",
";",
"// Store requested URL if there is a reason we're logging out",
"// If no reason then just a logout request, so we dont want to store",
"// it else we'll create a loop should they try to log back in.",
"if",
"(",
"$",
"reason",
"!==",
"FALSE",
")",
"{",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"set",
"(",
"'requested_url'",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"}",
"// Return",
"return",
"$",
"reason",
";",
"}"
] | Logout the user
return string Reason | [
"Logout",
"the",
"user",
"return",
"string",
"Reason"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L577-L610 | train |
andyburton/Sonic-Framework | src/Resource/User.php | User._Authenticate | public static function _Authenticate ($email, $password)
{
// Get user
$user = static::_readFromEmail ($email);
if (!$user)
{
return FALSE;
}
// Check password
return $user->checkPassword ($password);
} | php | public static function _Authenticate ($email, $password)
{
// Get user
$user = static::_readFromEmail ($email);
if (!$user)
{
return FALSE;
}
// Check password
return $user->checkPassword ($password);
} | [
"public",
"static",
"function",
"_Authenticate",
"(",
"$",
"email",
",",
"$",
"password",
")",
"{",
"// Get user",
"$",
"user",
"=",
"static",
"::",
"_readFromEmail",
"(",
"$",
"email",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"FALSE",
";",
"}",
"// Check password",
"return",
"$",
"user",
"->",
"checkPassword",
"(",
"$",
"password",
")",
";",
"}"
] | Authenticate and attempt to login a user
@param string $email User email address
@param string $password User password
@return boolean | [
"Authenticate",
"and",
"attempt",
"to",
"login",
"a",
"user"
] | a5999448a0abab4d542413002a780ede391e7374 | https://github.com/andyburton/Sonic-Framework/blob/a5999448a0abab4d542413002a780ede391e7374/src/Resource/User.php#L666-L682 | train |
slickframework/form | src/Element/AbstractElement.php | AbstractElement.setValue | public function setValue($value)
{
$this->value = $value;
if ($value instanceof ValueAwareInterface) {
$this->value = $value->getFormValue();
}
return $this;
} | php | public function setValue($value)
{
$this->value = $value;
if ($value instanceof ValueAwareInterface) {
$this->value = $value->getFormValue();
}
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"instanceof",
"ValueAwareInterface",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
"->",
"getFormValue",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the value or content of the element
@param mixed $value
@return mixed | [
"Sets",
"the",
"value",
"or",
"content",
"of",
"the",
"element"
] | e7d536b3bad49194e246ff93587da2589e31a003 | https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Element/AbstractElement.php#L88-L95 | train |
slickframework/form | src/Element/AbstractElement.php | AbstractElement.getRenderer | protected function getRenderer()
{
if (null === $this->renderer) {
$this->setRenderer(new $this->rendererClass());
}
return $this->renderer;
} | php | protected function getRenderer()
{
if (null === $this->renderer) {
$this->setRenderer(new $this->rendererClass());
}
return $this->renderer;
} | [
"protected",
"function",
"getRenderer",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"renderer",
")",
"{",
"$",
"this",
"->",
"setRenderer",
"(",
"new",
"$",
"this",
"->",
"rendererClass",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"renderer",
";",
"}"
] | Gets the HTML renderer for this element
@return RendererInterface | [
"Gets",
"the",
"HTML",
"renderer",
"for",
"this",
"element"
] | e7d536b3bad49194e246ff93587da2589e31a003 | https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Element/AbstractElement.php#L125-L131 | train |
DBRisinajumi/d2company | models/CcmpCompany.php | CcmpCompany.getAllGroupCompanies | public static function getAllGroupCompanies($ccgr_id) {
$sql = "
SELECT
ccmp_id,
ccmp_name
FROM
ccxg_company_x_group
INNER JOIN ccmp_company
ON ccxg_ccmp_id = ccmp_id
WHERE ccxg_ccgr_id = :ccgr_id
ORDER BY ccmp_name
";
return Yii::app()->db
->createCommand($sql)
->bindParam(":ccgr_id", $ccgr_id, PDO::PARAM_INT)
->queryAll();
} | php | public static function getAllGroupCompanies($ccgr_id) {
$sql = "
SELECT
ccmp_id,
ccmp_name
FROM
ccxg_company_x_group
INNER JOIN ccmp_company
ON ccxg_ccmp_id = ccmp_id
WHERE ccxg_ccgr_id = :ccgr_id
ORDER BY ccmp_name
";
return Yii::app()->db
->createCommand($sql)
->bindParam(":ccgr_id", $ccgr_id, PDO::PARAM_INT)
->queryAll();
} | [
"public",
"static",
"function",
"getAllGroupCompanies",
"(",
"$",
"ccgr_id",
")",
"{",
"$",
"sql",
"=",
"\"\n SELECT \n ccmp_id,\n ccmp_name \n FROM\n ccxg_company_x_group \n INNER JOIN ccmp_company \n ON ccxg_ccmp_id = ccmp_id \n WHERE ccxg_ccgr_id = :ccgr_id\n ORDER BY ccmp_name\n \"",
";",
"return",
"Yii",
"::",
"app",
"(",
")",
"->",
"db",
"->",
"createCommand",
"(",
"$",
"sql",
")",
"->",
"bindParam",
"(",
"\":ccgr_id\"",
",",
"$",
"ccgr_id",
",",
"PDO",
"::",
"PARAM_INT",
")",
"->",
"queryAll",
"(",
")",
";",
"}"
] | get all syscomanies array without access control
@param int $ccgr_id
@return array [
['ccmp_id' => 1, ccmp_name=>'company name1'],
['ccmp_id' => 2, ccmp_name=>'company name2'],
] | [
"get",
"all",
"syscomanies",
"array",
"without",
"access",
"control"
] | 20df0db96ac2c8e73471c4bab7d487b67ef4ed0a | https://github.com/DBRisinajumi/d2company/blob/20df0db96ac2c8e73471c4bab7d487b67ef4ed0a/models/CcmpCompany.php#L439-L455 | train |
SpoonX/SxMail | src/SxMail/SxMail.php | SxMail.setLayout | public function setLayout($layout = null)
{
if (null !== $layout && !is_string($layout) && !($layout instanceof ViewModel)) {
throw new InvalidArgumentException(
'Invalid value supplied for setLayout.'.
'Expected null, string, or Zend\View\Model\ViewModel.'
);
}
if (null === $layout && empty($this->config['message']['layout'])) {
return;
}
if (null === $layout) {
$layout = (string) $this->config['message']['layout'];
unset($this->config['message']['layout']);
}
if (is_string($layout)) {
$template = $layout;
$layout = new ViewModel;
$layout->setTemplate($template);
}
$this->layout = $layout;
} | php | public function setLayout($layout = null)
{
if (null !== $layout && !is_string($layout) && !($layout instanceof ViewModel)) {
throw new InvalidArgumentException(
'Invalid value supplied for setLayout.'.
'Expected null, string, or Zend\View\Model\ViewModel.'
);
}
if (null === $layout && empty($this->config['message']['layout'])) {
return;
}
if (null === $layout) {
$layout = (string) $this->config['message']['layout'];
unset($this->config['message']['layout']);
}
if (is_string($layout)) {
$template = $layout;
$layout = new ViewModel;
$layout->setTemplate($template);
}
$this->layout = $layout;
} | [
"public",
"function",
"setLayout",
"(",
"$",
"layout",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"layout",
"&&",
"!",
"is_string",
"(",
"$",
"layout",
")",
"&&",
"!",
"(",
"$",
"layout",
"instanceof",
"ViewModel",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid value supplied for setLayout.'",
".",
"'Expected null, string, or Zend\\View\\Model\\ViewModel.'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"layout",
"&&",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'layout'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"layout",
")",
"{",
"$",
"layout",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'layout'",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'layout'",
"]",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"layout",
")",
")",
"{",
"$",
"template",
"=",
"$",
"layout",
";",
"$",
"layout",
"=",
"new",
"ViewModel",
";",
"$",
"layout",
"->",
"setTemplate",
"(",
"$",
"template",
")",
";",
"}",
"$",
"this",
"->",
"layout",
"=",
"$",
"layout",
";",
"}"
] | Set the layout.
@param mixed $layout Either null (looks in config), ViewModel, or string.
@throws \SxMail\Exception\InvalidArgumentException | [
"Set",
"the",
"layout",
"."
] | b0663169cd246ba091f7c84785c69d051a652385 | https://github.com/SpoonX/SxMail/blob/b0663169cd246ba091f7c84785c69d051a652385/src/SxMail/SxMail.php#L58-L86 | train |
SpoonX/SxMail | src/SxMail/SxMail.php | SxMail.manipulateBody | protected function manipulateBody($body, $mimeType = null)
{
// Make sure we have a string.
if ($body instanceof ViewModel) {
$body = $this->viewRenderer->render($body);
$detectedMimeType = 'text/html';
} elseif (null === $body) {
$detectedMimeType = 'text/plain';
$body = '';
}
if (null !== ($layout = $this->getLayout())) {
$layout->setVariables(array(
'content' => $body,
));
$detectedMimeType = 'text/html';
$body = $this->viewRenderer->render($layout);
}
if (null === $mimeType && !isset($detectedMimeType)) {
$mimeType = preg_match("/<[^<]+>/", $body) ? 'text/html' : 'text/plain';
} elseif (null === $mimeType) {
$mimeType = $detectedMimeType;
}
$mimePart = new MimePart($body);
$mimePart->type = $mimeType;
if (!empty($this->config['charset'])) {
$mimePart->charset = $this->config['charset'];
}
$message = new MimeMessage();
if (!isset($this->config['message']['generate_alternative_body'])) {
$this->config['message']['generate_alternative_body'] = true;
}
if ($this->config['message']['generate_alternative_body'] && $mimeType === 'text/html') {
$generatedBody = $this->renderTextBody($body);
$altPart = new MimePart($generatedBody);
$altPart->type = 'text/plain';
if (!empty($this->config['charset'])) {
$altPart->charset = $this->config['charset'];
}
$message->addPart($altPart);
}
$message->addPart($mimePart);
return $message;
} | php | protected function manipulateBody($body, $mimeType = null)
{
// Make sure we have a string.
if ($body instanceof ViewModel) {
$body = $this->viewRenderer->render($body);
$detectedMimeType = 'text/html';
} elseif (null === $body) {
$detectedMimeType = 'text/plain';
$body = '';
}
if (null !== ($layout = $this->getLayout())) {
$layout->setVariables(array(
'content' => $body,
));
$detectedMimeType = 'text/html';
$body = $this->viewRenderer->render($layout);
}
if (null === $mimeType && !isset($detectedMimeType)) {
$mimeType = preg_match("/<[^<]+>/", $body) ? 'text/html' : 'text/plain';
} elseif (null === $mimeType) {
$mimeType = $detectedMimeType;
}
$mimePart = new MimePart($body);
$mimePart->type = $mimeType;
if (!empty($this->config['charset'])) {
$mimePart->charset = $this->config['charset'];
}
$message = new MimeMessage();
if (!isset($this->config['message']['generate_alternative_body'])) {
$this->config['message']['generate_alternative_body'] = true;
}
if ($this->config['message']['generate_alternative_body'] && $mimeType === 'text/html') {
$generatedBody = $this->renderTextBody($body);
$altPart = new MimePart($generatedBody);
$altPart->type = 'text/plain';
if (!empty($this->config['charset'])) {
$altPart->charset = $this->config['charset'];
}
$message->addPart($altPart);
}
$message->addPart($mimePart);
return $message;
} | [
"protected",
"function",
"manipulateBody",
"(",
"$",
"body",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"// Make sure we have a string.",
"if",
"(",
"$",
"body",
"instanceof",
"ViewModel",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"viewRenderer",
"->",
"render",
"(",
"$",
"body",
")",
";",
"$",
"detectedMimeType",
"=",
"'text/html'",
";",
"}",
"elseif",
"(",
"null",
"===",
"$",
"body",
")",
"{",
"$",
"detectedMimeType",
"=",
"'text/plain'",
";",
"$",
"body",
"=",
"''",
";",
"}",
"if",
"(",
"null",
"!==",
"(",
"$",
"layout",
"=",
"$",
"this",
"->",
"getLayout",
"(",
")",
")",
")",
"{",
"$",
"layout",
"->",
"setVariables",
"(",
"array",
"(",
"'content'",
"=>",
"$",
"body",
",",
")",
")",
";",
"$",
"detectedMimeType",
"=",
"'text/html'",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"viewRenderer",
"->",
"render",
"(",
"$",
"layout",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"mimeType",
"&&",
"!",
"isset",
"(",
"$",
"detectedMimeType",
")",
")",
"{",
"$",
"mimeType",
"=",
"preg_match",
"(",
"\"/<[^<]+>/\"",
",",
"$",
"body",
")",
"?",
"'text/html'",
":",
"'text/plain'",
";",
"}",
"elseif",
"(",
"null",
"===",
"$",
"mimeType",
")",
"{",
"$",
"mimeType",
"=",
"$",
"detectedMimeType",
";",
"}",
"$",
"mimePart",
"=",
"new",
"MimePart",
"(",
"$",
"body",
")",
";",
"$",
"mimePart",
"->",
"type",
"=",
"$",
"mimeType",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'charset'",
"]",
")",
")",
"{",
"$",
"mimePart",
"->",
"charset",
"=",
"$",
"this",
"->",
"config",
"[",
"'charset'",
"]",
";",
"}",
"$",
"message",
"=",
"new",
"MimeMessage",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'generate_alternative_body'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'generate_alternative_body'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'generate_alternative_body'",
"]",
"&&",
"$",
"mimeType",
"===",
"'text/html'",
")",
"{",
"$",
"generatedBody",
"=",
"$",
"this",
"->",
"renderTextBody",
"(",
"$",
"body",
")",
";",
"$",
"altPart",
"=",
"new",
"MimePart",
"(",
"$",
"generatedBody",
")",
";",
"$",
"altPart",
"->",
"type",
"=",
"'text/plain'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'charset'",
"]",
")",
")",
"{",
"$",
"altPart",
"->",
"charset",
"=",
"$",
"this",
"->",
"config",
"[",
"'charset'",
"]",
";",
"}",
"$",
"message",
"->",
"addPart",
"(",
"$",
"altPart",
")",
";",
"}",
"$",
"message",
"->",
"addPart",
"(",
"$",
"mimePart",
")",
";",
"return",
"$",
"message",
";",
"}"
] | Manipulate the body based on configuration options.
@param mixed $body
@param string $mimeType
@return string | [
"Manipulate",
"the",
"body",
"based",
"on",
"configuration",
"options",
"."
] | b0663169cd246ba091f7c84785c69d051a652385 | https://github.com/SpoonX/SxMail/blob/b0663169cd246ba091f7c84785c69d051a652385/src/SxMail/SxMail.php#L106-L161 | train |
SpoonX/SxMail | src/SxMail/SxMail.php | SxMail.renderTextBody | protected function renderTextBody($body)
{
$body = html_entity_decode(
trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $body))), ENT_QUOTES
);
if (empty($body)) {
$body = 'To view this email, open it an email client that supports HTML.';
}
return $body;
} | php | protected function renderTextBody($body)
{
$body = html_entity_decode(
trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $body))), ENT_QUOTES
);
if (empty($body)) {
$body = 'To view this email, open it an email client that supports HTML.';
}
return $body;
} | [
"protected",
"function",
"renderTextBody",
"(",
"$",
"body",
")",
"{",
"$",
"body",
"=",
"html_entity_decode",
"(",
"trim",
"(",
"strip_tags",
"(",
"preg_replace",
"(",
"'/<(head|title|style|script)[^>]*>.*?<\\/\\\\1>/s'",
",",
"''",
",",
"$",
"body",
")",
")",
")",
",",
"ENT_QUOTES",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"'To view this email, open it an email client that supports HTML.'",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | Strip html tags and render a text-only version.
@param string $body
@return string | [
"Strip",
"html",
"tags",
"and",
"render",
"a",
"text",
"-",
"only",
"version",
"."
] | b0663169cd246ba091f7c84785c69d051a652385 | https://github.com/SpoonX/SxMail/blob/b0663169cd246ba091f7c84785c69d051a652385/src/SxMail/SxMail.php#L170-L181 | train |
SpoonX/SxMail | src/SxMail/SxMail.php | SxMail.compose | public function compose($body = null, $mimeType = null)
{
// Supported types are null, ViewModel and string.
if (null !== $body && !is_string($body) && !($body instanceof ViewModel)) {
throw new InvalidArgumentException(
'Invalid value supplied. Expected null, string or instance of Zend\View\Model\ViewModel.'
);
}
$body = $this->manipulateBody($body, $mimeType);
$message = new Message;
$message->setBody($body);
if ($this->config['message']['generate_alternative_body'] && count($body->getParts()) > 1) {
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
}
$this->applyMessageHeaders($message);
$this->applyMessageOptions($message);
return $message;
} | php | public function compose($body = null, $mimeType = null)
{
// Supported types are null, ViewModel and string.
if (null !== $body && !is_string($body) && !($body instanceof ViewModel)) {
throw new InvalidArgumentException(
'Invalid value supplied. Expected null, string or instance of Zend\View\Model\ViewModel.'
);
}
$body = $this->manipulateBody($body, $mimeType);
$message = new Message;
$message->setBody($body);
if ($this->config['message']['generate_alternative_body'] && count($body->getParts()) > 1) {
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
}
$this->applyMessageHeaders($message);
$this->applyMessageOptions($message);
return $message;
} | [
"public",
"function",
"compose",
"(",
"$",
"body",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"// Supported types are null, ViewModel and string.",
"if",
"(",
"null",
"!==",
"$",
"body",
"&&",
"!",
"is_string",
"(",
"$",
"body",
")",
"&&",
"!",
"(",
"$",
"body",
"instanceof",
"ViewModel",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid value supplied. Expected null, string or instance of Zend\\View\\Model\\ViewModel.'",
")",
";",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"manipulateBody",
"(",
"$",
"body",
",",
"$",
"mimeType",
")",
";",
"$",
"message",
"=",
"new",
"Message",
";",
"$",
"message",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'message'",
"]",
"[",
"'generate_alternative_body'",
"]",
"&&",
"count",
"(",
"$",
"body",
"->",
"getParts",
"(",
")",
")",
">",
"1",
")",
"{",
"$",
"message",
"->",
"getHeaders",
"(",
")",
"->",
"get",
"(",
"'content-type'",
")",
"->",
"setType",
"(",
"'multipart/alternative'",
")",
";",
"}",
"$",
"this",
"->",
"applyMessageHeaders",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"applyMessageOptions",
"(",
"$",
"message",
")",
";",
"return",
"$",
"message",
";",
"}"
] | Compose a new message.
@param mixed $body Accepts instance of ViewModel, string and null.
@param string $mimeType
@return \Zend\Mail\Message
@throws \SxMail\Exception\InvalidArgumentException | [
"Compose",
"a",
"new",
"message",
"."
] | b0663169cd246ba091f7c84785c69d051a652385 | https://github.com/SpoonX/SxMail/blob/b0663169cd246ba091f7c84785c69d051a652385/src/SxMail/SxMail.php#L234-L256 | train |
interactivesolutions/honeycomb-scripts | src/app/commands/HCRoutes.php | HCRoutes.generateRoutes | private function generateRoutes($directory)
{
$dirPath = $directory . 'app/routes/';
if( ! file_exists($dirPath) )
return;
// get all files recursively
/** @var \Iterator $iterator */
$iterator = Finder::create()
->files()
->ignoreDotFiles(true)
->sortByName()
->in($dirPath);
// iterate to array
$files = iterator_to_array($iterator, true);
$finalContent = '<?php' . "\r\n";
foreach ( $files as $file ) {
$finalContent .= "\r\n";
$finalContent .= '//' . implode('/', array_slice(explode('/', $file), -6)) . "\r\n";
$finalContent .= str_replace('<?php', '', file_get_contents((string)$file)) . "\r\n";
}
file_put_contents($directory . HCRoutes::ROUTES_PATH, $finalContent);
$this->comment($directory . HCRoutes::ROUTES_PATH . ' file generated');
} | php | private function generateRoutes($directory)
{
$dirPath = $directory . 'app/routes/';
if( ! file_exists($dirPath) )
return;
// get all files recursively
/** @var \Iterator $iterator */
$iterator = Finder::create()
->files()
->ignoreDotFiles(true)
->sortByName()
->in($dirPath);
// iterate to array
$files = iterator_to_array($iterator, true);
$finalContent = '<?php' . "\r\n";
foreach ( $files as $file ) {
$finalContent .= "\r\n";
$finalContent .= '//' . implode('/', array_slice(explode('/', $file), -6)) . "\r\n";
$finalContent .= str_replace('<?php', '', file_get_contents((string)$file)) . "\r\n";
}
file_put_contents($directory . HCRoutes::ROUTES_PATH, $finalContent);
$this->comment($directory . HCRoutes::ROUTES_PATH . ' file generated');
} | [
"private",
"function",
"generateRoutes",
"(",
"$",
"directory",
")",
"{",
"$",
"dirPath",
"=",
"$",
"directory",
".",
"'app/routes/'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dirPath",
")",
")",
"return",
";",
"// get all files recursively",
"/** @var \\Iterator $iterator */",
"$",
"iterator",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"ignoreDotFiles",
"(",
"true",
")",
"->",
"sortByName",
"(",
")",
"->",
"in",
"(",
"$",
"dirPath",
")",
";",
"// iterate to array",
"$",
"files",
"=",
"iterator_to_array",
"(",
"$",
"iterator",
",",
"true",
")",
";",
"$",
"finalContent",
"=",
"'<?php'",
".",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"finalContent",
".=",
"\"\\r\\n\"",
";",
"$",
"finalContent",
".=",
"'//'",
".",
"implode",
"(",
"'/'",
",",
"array_slice",
"(",
"explode",
"(",
"'/'",
",",
"$",
"file",
")",
",",
"-",
"6",
")",
")",
".",
"\"\\r\\n\"",
";",
"$",
"finalContent",
".=",
"str_replace",
"(",
"'<?php'",
",",
"''",
",",
"file_get_contents",
"(",
"(",
"string",
")",
"$",
"file",
")",
")",
".",
"\"\\r\\n\"",
";",
"}",
"file_put_contents",
"(",
"$",
"directory",
".",
"HCRoutes",
"::",
"ROUTES_PATH",
",",
"$",
"finalContent",
")",
";",
"$",
"this",
"->",
"comment",
"(",
"$",
"directory",
".",
"HCRoutes",
"::",
"ROUTES_PATH",
".",
"' file generated'",
")",
";",
"}"
] | Generating final routes file for package
@param $directory | [
"Generating",
"final",
"routes",
"file",
"for",
"package"
] | be2428ded5219dc612ecc51f43aa4dedff3d034d | https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/HCRoutes.php#L51-L81 | train |
makinacorpus/drupal-plusql | src/ConstraintRegistry.php | ConstraintRegistry.createInstance | protected function createInstance(Connection $connection, string $type): ConstraintInterface
{
$driver = $connection->driver();
if (!isset($this->registry[$driver][$type])) {
throw new \InvalidArgumentException(sprintf("'%s' constraint is not supported by '%s' driver"));
}
$className = $this->registry[$driver][$type];
// Consider that if the user did not register an instance, then he is
// using the ConstraintTrait and its constructor, I do hope anyway.
// @todo provide other means of registration
if (!class_exists($className)) {
throw new \InvalidArgumentException(sprintf("'%s' class does not exist", $className));
}
return new $className($connection, $type);
} | php | protected function createInstance(Connection $connection, string $type): ConstraintInterface
{
$driver = $connection->driver();
if (!isset($this->registry[$driver][$type])) {
throw new \InvalidArgumentException(sprintf("'%s' constraint is not supported by '%s' driver"));
}
$className = $this->registry[$driver][$type];
// Consider that if the user did not register an instance, then he is
// using the ConstraintTrait and its constructor, I do hope anyway.
// @todo provide other means of registration
if (!class_exists($className)) {
throw new \InvalidArgumentException(sprintf("'%s' class does not exist", $className));
}
return new $className($connection, $type);
} | [
"protected",
"function",
"createInstance",
"(",
"Connection",
"$",
"connection",
",",
"string",
"$",
"type",
")",
":",
"ConstraintInterface",
"{",
"$",
"driver",
"=",
"$",
"connection",
"->",
"driver",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"driver",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"'%s' constraint is not supported by '%s' driver\"",
")",
")",
";",
"}",
"$",
"className",
"=",
"$",
"this",
"->",
"registry",
"[",
"$",
"driver",
"]",
"[",
"$",
"type",
"]",
";",
"// Consider that if the user did not register an instance, then he is",
"// using the ConstraintTrait and its constructor, I do hope anyway.",
"// @todo provide other means of registration",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"'%s' class does not exist\"",
",",
"$",
"className",
")",
")",
";",
"}",
"return",
"new",
"$",
"className",
"(",
"$",
"connection",
",",
"$",
"type",
")",
";",
"}"
] | Create instance for the given connection | [
"Create",
"instance",
"for",
"the",
"given",
"connection"
] | 7182d653a117d53b6bb3e3edd53f07af11ff5d43 | https://github.com/makinacorpus/drupal-plusql/blob/7182d653a117d53b6bb3e3edd53f07af11ff5d43/src/ConstraintRegistry.php#L28-L46 | train |
makinacorpus/drupal-plusql | src/ConstraintRegistry.php | ConstraintRegistry.get | public function get(Connection $connection, string $type): ConstraintInterface
{
$driver = $connection->driver();
if (isset($this->instances[$driver][$type])) {
return $this->instances[$driver][$type];
}
return $this->instances[$driver][$type] = $this->createInstance($connection, $type);
} | php | public function get(Connection $connection, string $type): ConstraintInterface
{
$driver = $connection->driver();
if (isset($this->instances[$driver][$type])) {
return $this->instances[$driver][$type];
}
return $this->instances[$driver][$type] = $this->createInstance($connection, $type);
} | [
"public",
"function",
"get",
"(",
"Connection",
"$",
"connection",
",",
"string",
"$",
"type",
")",
":",
"ConstraintInterface",
"{",
"$",
"driver",
"=",
"$",
"connection",
"->",
"driver",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"driver",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"driver",
"]",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"driver",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"connection",
",",
"$",
"type",
")",
";",
"}"
] | Get constraint type handler for driver | [
"Get",
"constraint",
"type",
"handler",
"for",
"driver"
] | 7182d653a117d53b6bb3e3edd53f07af11ff5d43 | https://github.com/makinacorpus/drupal-plusql/blob/7182d653a117d53b6bb3e3edd53f07af11ff5d43/src/ConstraintRegistry.php#L51-L60 | train |
makinacorpus/drupal-plusql | src/ConstraintRegistry.php | ConstraintRegistry.getAll | public function getAll(Connection $connection): array
{
foreach ($this->registry as $types) {
foreach (array_keys($types) as $type) {
$this->get($connection, $type);
}
}
return $this->instances[$connection->driver()];
} | php | public function getAll(Connection $connection): array
{
foreach ($this->registry as $types) {
foreach (array_keys($types) as $type) {
$this->get($connection, $type);
}
}
return $this->instances[$connection->driver()];
} | [
"public",
"function",
"getAll",
"(",
"Connection",
"$",
"connection",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"registry",
"as",
"$",
"types",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"types",
")",
"as",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"$",
"connection",
",",
"$",
"type",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"connection",
"->",
"driver",
"(",
")",
"]",
";",
"}"
] | Get all defined handlers
@return ConstraintInterface[] | [
"Get",
"all",
"defined",
"handlers"
] | 7182d653a117d53b6bb3e3edd53f07af11ff5d43 | https://github.com/makinacorpus/drupal-plusql/blob/7182d653a117d53b6bb3e3edd53f07af11ff5d43/src/ConstraintRegistry.php#L67-L76 | train |
pmdevelopment/tool-bundle | Twig/Vendor/PicqerBarcodeGeneratorExtension.php | PicqerBarcodeGeneratorExtension.getHtml128 | public function getHtml128($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_CODE_128, $pixelPerByte, $height);
} | php | public function getHtml128($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_CODE_128, $pixelPerByte, $height);
} | [
"public",
"function",
"getHtml128",
"(",
"$",
"string",
",",
"$",
"pixelPerByte",
"=",
"2",
",",
"$",
"height",
"=",
"30",
")",
"{",
"$",
"generator",
"=",
"new",
"BarcodeGeneratorHTML",
"(",
")",
";",
"return",
"$",
"generator",
"->",
"getBarcode",
"(",
"$",
"string",
",",
"BarcodeGeneratorHTML",
"::",
"TYPE_CODE_128",
",",
"$",
"pixelPerByte",
",",
"$",
"height",
")",
";",
"}"
] | Get HTML as CODE-128
@param string $string
@return string | [
"Get",
"HTML",
"as",
"CODE",
"-",
"128"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Twig/Vendor/PicqerBarcodeGeneratorExtension.php#L51-L56 | train |
pmdevelopment/tool-bundle | Twig/Vendor/PicqerBarcodeGeneratorExtension.php | PicqerBarcodeGeneratorExtension.getHtmlEan13 | public function getHtmlEan13($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_EAN_13, $pixelPerByte, $height);
} | php | public function getHtmlEan13($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_EAN_13, $pixelPerByte, $height);
} | [
"public",
"function",
"getHtmlEan13",
"(",
"$",
"string",
",",
"$",
"pixelPerByte",
"=",
"2",
",",
"$",
"height",
"=",
"30",
")",
"{",
"$",
"generator",
"=",
"new",
"BarcodeGeneratorHTML",
"(",
")",
";",
"return",
"$",
"generator",
"->",
"getBarcode",
"(",
"$",
"string",
",",
"BarcodeGeneratorHTML",
"::",
"TYPE_EAN_13",
",",
"$",
"pixelPerByte",
",",
"$",
"height",
")",
";",
"}"
] | Get HTML as EAN-13
@param string $string
@return string | [
"Get",
"HTML",
"as",
"EAN",
"-",
"13"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Twig/Vendor/PicqerBarcodeGeneratorExtension.php#L65-L70 | train |
pmdevelopment/tool-bundle | Twig/Vendor/PicqerBarcodeGeneratorExtension.php | PicqerBarcodeGeneratorExtension.getHtmlUpcA | public function getHtmlUpcA($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_UPC_A, $pixelPerByte, $height);
} | php | public function getHtmlUpcA($string, $pixelPerByte = 2, $height = 30)
{
$generator = new BarcodeGeneratorHTML();
return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_UPC_A, $pixelPerByte, $height);
} | [
"public",
"function",
"getHtmlUpcA",
"(",
"$",
"string",
",",
"$",
"pixelPerByte",
"=",
"2",
",",
"$",
"height",
"=",
"30",
")",
"{",
"$",
"generator",
"=",
"new",
"BarcodeGeneratorHTML",
"(",
")",
";",
"return",
"$",
"generator",
"->",
"getBarcode",
"(",
"$",
"string",
",",
"BarcodeGeneratorHTML",
"::",
"TYPE_UPC_A",
",",
"$",
"pixelPerByte",
",",
"$",
"height",
")",
";",
"}"
] | Get HTML as UPC
@param string $string
@return string | [
"Get",
"HTML",
"as",
"UPC"
] | 2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129 | https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Twig/Vendor/PicqerBarcodeGeneratorExtension.php#L79-L84 | train |
phPoirot/Client-OAuth2 | mod/Authenticate/IdentifierHttpToken.php | IdentifierHttpToken._parseTokenFromRequest | private function _parseTokenFromRequest()
{
if ($this->_c_parsedToken)
// From Cached
return $this->_c_parsedToken;
$this->_c_parsedToken = $r = $this->assertion->parseTokenStrFromRequest(
new ServerRequestBridgeInPsr( $this->request() )
);
return $r;
} | php | private function _parseTokenFromRequest()
{
if ($this->_c_parsedToken)
// From Cached
return $this->_c_parsedToken;
$this->_c_parsedToken = $r = $this->assertion->parseTokenStrFromRequest(
new ServerRequestBridgeInPsr( $this->request() )
);
return $r;
} | [
"private",
"function",
"_parseTokenFromRequest",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_c_parsedToken",
")",
"// From Cached",
"return",
"$",
"this",
"->",
"_c_parsedToken",
";",
"$",
"this",
"->",
"_c_parsedToken",
"=",
"$",
"r",
"=",
"$",
"this",
"->",
"assertion",
"->",
"parseTokenStrFromRequest",
"(",
"new",
"ServerRequestBridgeInPsr",
"(",
"$",
"this",
"->",
"request",
"(",
")",
")",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Parse Token From Request
@return null|string | [
"Parse",
"Token",
"From",
"Request"
] | 8745fd54afbbb185669b9e38b1241ecc8ffc7268 | https://github.com/phPoirot/Client-OAuth2/blob/8745fd54afbbb185669b9e38b1241ecc8ffc7268/mod/Authenticate/IdentifierHttpToken.php#L141-L153 | train |
Synapse-Cmf/synapse-cmf | src/Synapse/Cmf/Framework/Media/File/Action/Dal/UploadAction.php | UploadAction.resolve | public function resolve()
{
if ($this->sourceFile instanceof UploadedFile) {
$extension = $this->sourceFile->guessExtension();
$name = preg_filter('/^php(.+)/', '$1', $this->sourceFile->getBasename());
$this->originalName = $this->sourceFile->getClientOriginalName();
} else {
$extension = $this->sourceFile->getExtension();
$this->originalName = $name = $this->sourceFile->getBasename('.'.$extension);
}
$this->setPhysicalFile(
$this->sourceFile->move(
$this->storePath,
sprintf('%s%s.%s',
strtolower($name),
base_convert(microtime(), 10, 36),
$extension
)
)
);
return parent::resolve();
} | php | public function resolve()
{
if ($this->sourceFile instanceof UploadedFile) {
$extension = $this->sourceFile->guessExtension();
$name = preg_filter('/^php(.+)/', '$1', $this->sourceFile->getBasename());
$this->originalName = $this->sourceFile->getClientOriginalName();
} else {
$extension = $this->sourceFile->getExtension();
$this->originalName = $name = $this->sourceFile->getBasename('.'.$extension);
}
$this->setPhysicalFile(
$this->sourceFile->move(
$this->storePath,
sprintf('%s%s.%s',
strtolower($name),
base_convert(microtime(), 10, 36),
$extension
)
)
);
return parent::resolve();
} | [
"public",
"function",
"resolve",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sourceFile",
"instanceof",
"UploadedFile",
")",
"{",
"$",
"extension",
"=",
"$",
"this",
"->",
"sourceFile",
"->",
"guessExtension",
"(",
")",
";",
"$",
"name",
"=",
"preg_filter",
"(",
"'/^php(.+)/'",
",",
"'$1'",
",",
"$",
"this",
"->",
"sourceFile",
"->",
"getBasename",
"(",
")",
")",
";",
"$",
"this",
"->",
"originalName",
"=",
"$",
"this",
"->",
"sourceFile",
"->",
"getClientOriginalName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"extension",
"=",
"$",
"this",
"->",
"sourceFile",
"->",
"getExtension",
"(",
")",
";",
"$",
"this",
"->",
"originalName",
"=",
"$",
"name",
"=",
"$",
"this",
"->",
"sourceFile",
"->",
"getBasename",
"(",
"'.'",
".",
"$",
"extension",
")",
";",
"}",
"$",
"this",
"->",
"setPhysicalFile",
"(",
"$",
"this",
"->",
"sourceFile",
"->",
"move",
"(",
"$",
"this",
"->",
"storePath",
",",
"sprintf",
"(",
"'%s%s.%s'",
",",
"strtolower",
"(",
"$",
"name",
")",
",",
"base_convert",
"(",
"microtime",
"(",
")",
",",
"10",
",",
"36",
")",
",",
"$",
"extension",
")",
")",
")",
";",
"return",
"parent",
"::",
"resolve",
"(",
")",
";",
"}"
] | Override to handle upload before normal creation. | [
"Override",
"to",
"handle",
"upload",
"before",
"normal",
"creation",
"."
] | d8122a4150a83d5607289724425cf35c56a5e880 | https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Media/File/Action/Dal/UploadAction.php#L21-L44 | train |
makinacorpus/drupal-plusql | src/ConstraintTrait.php | ConstraintTrait.getSqlName | public function getSqlName(string $table, string $name): string
{
return $table . '_' . $this->getType() . '_' . $name;
} | php | public function getSqlName(string $table, string $name): string
{
return $table . '_' . $this->getType() . '_' . $name;
} | [
"public",
"function",
"getSqlName",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"name",
")",
":",
"string",
"{",
"return",
"$",
"table",
".",
"'_'",
".",
"$",
"this",
"->",
"getType",
"(",
")",
".",
"'_'",
".",
"$",
"name",
";",
"}"
] | Get SQL constraint name | [
"Get",
"SQL",
"constraint",
"name"
] | 7182d653a117d53b6bb3e3edd53f07af11ff5d43 | https://github.com/makinacorpus/drupal-plusql/blob/7182d653a117d53b6bb3e3edd53f07af11ff5d43/src/ConstraintTrait.php#L43-L46 | train |
noizu/fragmented-keys | src/NoizuLabs/FragmentedKeys/Key/Standard.php | Standard.getKeyStr | public function getKeyStr($hash = true)
{
$key = $this->key . self::$INDEX_SEPERATOR . $this->groupId . self::$TAG_SEPERATOR . implode(self::$TAG_SEPERATOR, $this->gatherTags());
if($hash) {
$key = md5($key);
}
return $key;
} | php | public function getKeyStr($hash = true)
{
$key = $this->key . self::$INDEX_SEPERATOR . $this->groupId . self::$TAG_SEPERATOR . implode(self::$TAG_SEPERATOR, $this->gatherTags());
if($hash) {
$key = md5($key);
}
return $key;
} | [
"public",
"function",
"getKeyStr",
"(",
"$",
"hash",
"=",
"true",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
".",
"self",
"::",
"$",
"INDEX_SEPERATOR",
".",
"$",
"this",
"->",
"groupId",
".",
"self",
"::",
"$",
"TAG_SEPERATOR",
".",
"implode",
"(",
"self",
"::",
"$",
"TAG_SEPERATOR",
",",
"$",
"this",
"->",
"gatherTags",
"(",
")",
")",
";",
"if",
"(",
"$",
"hash",
")",
"{",
"$",
"key",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | calculate composite key
@param bool $hash use true to return md5 (memcache friendly) key or use false to return raw key for visual inspection.
@return string | [
"calculate",
"composite",
"key"
] | 5eccc8553ba11920d6d84e20e89b50c28d941b45 | https://github.com/noizu/fragmented-keys/blob/5eccc8553ba11920d6d84e20e89b50c28d941b45/src/NoizuLabs/FragmentedKeys/Key/Standard.php#L44-L51 | train |
ekyna/AdminBundle | Pool/ConfigurationFactory.php | ConfigurationFactory.createConfiguration | public function createConfiguration($prefix, $resourceName, $resourceClass, array $templateList, $eventClass = null, $parentId = null)
{
return new Configuration(
$prefix,
$resourceName,
$resourceClass,
$templateList,
$eventClass,
$parentId
);
} | php | public function createConfiguration($prefix, $resourceName, $resourceClass, array $templateList, $eventClass = null, $parentId = null)
{
return new Configuration(
$prefix,
$resourceName,
$resourceClass,
$templateList,
$eventClass,
$parentId
);
} | [
"public",
"function",
"createConfiguration",
"(",
"$",
"prefix",
",",
"$",
"resourceName",
",",
"$",
"resourceClass",
",",
"array",
"$",
"templateList",
",",
"$",
"eventClass",
"=",
"null",
",",
"$",
"parentId",
"=",
"null",
")",
"{",
"return",
"new",
"Configuration",
"(",
"$",
"prefix",
",",
"$",
"resourceName",
",",
"$",
"resourceClass",
",",
"$",
"templateList",
",",
"$",
"eventClass",
",",
"$",
"parentId",
")",
";",
"}"
] | Creates and register a configuration
@param string $prefix
@param string $resourceName
@param string $resourceClass
@param array $templateList
@param string $eventClass
@param string $parentId
@return \Ekyna\Bundle\AdminBundle\Pool\Configuration | [
"Creates",
"and",
"register",
"a",
"configuration"
] | 3f58e253ae9cf651add7f3d587caec80eaea459a | https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Pool/ConfigurationFactory.php#L24-L34 | train |
anklimsk/cakephp-console-installer | Controller/CheckController.php | CheckController.index | public function index() {
$isAppInstalled = $this->Installer->isAppInstalled();
$isAppReadyInstall = $this->InstallerCheck->isAppReadyToInstall();
$phpVesion = $this->InstallerCheck->checkPhpVersion();
$phpModules = $this->InstallerCheck->checkPhpExtensions();
$filesWritable = $this->InstallerCheck->checkFilesWritable();
$connectDB = $this->InstallerCheck->checkConnectDb();
$this->set(compact(
'isAppInstalled',
'isAppReadyInstall',
'phpVesion',
'phpModules',
'filesWritable',
'connectDB'
));
} | php | public function index() {
$isAppInstalled = $this->Installer->isAppInstalled();
$isAppReadyInstall = $this->InstallerCheck->isAppReadyToInstall();
$phpVesion = $this->InstallerCheck->checkPhpVersion();
$phpModules = $this->InstallerCheck->checkPhpExtensions();
$filesWritable = $this->InstallerCheck->checkFilesWritable();
$connectDB = $this->InstallerCheck->checkConnectDb();
$this->set(compact(
'isAppInstalled',
'isAppReadyInstall',
'phpVesion',
'phpModules',
'filesWritable',
'connectDB'
));
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"isAppInstalled",
"=",
"$",
"this",
"->",
"Installer",
"->",
"isAppInstalled",
"(",
")",
";",
"$",
"isAppReadyInstall",
"=",
"$",
"this",
"->",
"InstallerCheck",
"->",
"isAppReadyToInstall",
"(",
")",
";",
"$",
"phpVesion",
"=",
"$",
"this",
"->",
"InstallerCheck",
"->",
"checkPhpVersion",
"(",
")",
";",
"$",
"phpModules",
"=",
"$",
"this",
"->",
"InstallerCheck",
"->",
"checkPhpExtensions",
"(",
")",
";",
"$",
"filesWritable",
"=",
"$",
"this",
"->",
"InstallerCheck",
"->",
"checkFilesWritable",
"(",
")",
";",
"$",
"connectDB",
"=",
"$",
"this",
"->",
"InstallerCheck",
"->",
"checkConnectDb",
"(",
")",
";",
"$",
"this",
"->",
"set",
"(",
"compact",
"(",
"'isAppInstalled'",
",",
"'isAppReadyInstall'",
",",
"'phpVesion'",
",",
"'phpModules'",
",",
"'filesWritable'",
",",
"'connectDB'",
")",
")",
";",
"}"
] | Action `index`. Used to view state of installation for application.
@return void | [
"Action",
"index",
".",
"Used",
"to",
"view",
"state",
"of",
"installation",
"for",
"application",
"."
] | 76136550e856ff4f8fd3634b77633f86510f63e9 | https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Controller/CheckController.php#L102-L118 | train |
infusephp/auth | src/Libs/ResetPassword.php | ResetPassword.getUserFromToken | public function getUserFromToken($token)
{
$expiration = U::unixToDb(time() - UserLink::$forgotLinkTimeframe);
$link = UserLink::where('link', $token)
->where('type', UserLink::FORGOT_PASSWORD)
->where('created_at', $expiration, '>')
->first();
if (!$link) {
throw new AuthException('This link has expired or is invalid.');
}
$userClass = $this->auth->getUserClass();
return $userClass::find($link->user_id);
} | php | public function getUserFromToken($token)
{
$expiration = U::unixToDb(time() - UserLink::$forgotLinkTimeframe);
$link = UserLink::where('link', $token)
->where('type', UserLink::FORGOT_PASSWORD)
->where('created_at', $expiration, '>')
->first();
if (!$link) {
throw new AuthException('This link has expired or is invalid.');
}
$userClass = $this->auth->getUserClass();
return $userClass::find($link->user_id);
} | [
"public",
"function",
"getUserFromToken",
"(",
"$",
"token",
")",
"{",
"$",
"expiration",
"=",
"U",
"::",
"unixToDb",
"(",
"time",
"(",
")",
"-",
"UserLink",
"::",
"$",
"forgotLinkTimeframe",
")",
";",
"$",
"link",
"=",
"UserLink",
"::",
"where",
"(",
"'link'",
",",
"$",
"token",
")",
"->",
"where",
"(",
"'type'",
",",
"UserLink",
"::",
"FORGOT_PASSWORD",
")",
"->",
"where",
"(",
"'created_at'",
",",
"$",
"expiration",
",",
"'>'",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"$",
"link",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"'This link has expired or is invalid.'",
")",
";",
"}",
"$",
"userClass",
"=",
"$",
"this",
"->",
"auth",
"->",
"getUserClass",
"(",
")",
";",
"return",
"$",
"userClass",
"::",
"find",
"(",
"$",
"link",
"->",
"user_id",
")",
";",
"}"
] | Looks up a user from a given forgot token.
@param string $token
@throws AuthException when the token is invalid.
@return \Infuse\Auth\Interfaces\UserInterface | [
"Looks",
"up",
"a",
"user",
"from",
"a",
"given",
"forgot",
"token",
"."
] | 720280b4b2635572f331afe8d082e3e88cf54eb7 | https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Libs/ResetPassword.php#L47-L62 | train |
infusephp/auth | src/Libs/ResetPassword.php | ResetPassword.buildLink | public function buildLink($userId, $ip, $userAgent)
{
$link = new UserLink();
$link->user_id = $userId;
$link->type = UserLink::FORGOT_PASSWORD;
try {
$link->save();
} catch (\Exception $e) {
throw new \Exception("Could not create reset password link for user # $userId: ".$e->getMessage());
}
// record the reset password request event
$event = new AccountSecurityEvent();
$event->user_id = $userId;
$event->type = AccountSecurityEvent::RESET_PASSWORD_REQUEST;
$event->ip = $ip;
$event->user_agent = $userAgent;
$event->save();
return $link;
} | php | public function buildLink($userId, $ip, $userAgent)
{
$link = new UserLink();
$link->user_id = $userId;
$link->type = UserLink::FORGOT_PASSWORD;
try {
$link->save();
} catch (\Exception $e) {
throw new \Exception("Could not create reset password link for user # $userId: ".$e->getMessage());
}
// record the reset password request event
$event = new AccountSecurityEvent();
$event->user_id = $userId;
$event->type = AccountSecurityEvent::RESET_PASSWORD_REQUEST;
$event->ip = $ip;
$event->user_agent = $userAgent;
$event->save();
return $link;
} | [
"public",
"function",
"buildLink",
"(",
"$",
"userId",
",",
"$",
"ip",
",",
"$",
"userAgent",
")",
"{",
"$",
"link",
"=",
"new",
"UserLink",
"(",
")",
";",
"$",
"link",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"link",
"->",
"type",
"=",
"UserLink",
"::",
"FORGOT_PASSWORD",
";",
"try",
"{",
"$",
"link",
"->",
"save",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not create reset password link for user # $userId: \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// record the reset password request event",
"$",
"event",
"=",
"new",
"AccountSecurityEvent",
"(",
")",
";",
"$",
"event",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"event",
"->",
"type",
"=",
"AccountSecurityEvent",
"::",
"RESET_PASSWORD_REQUEST",
";",
"$",
"event",
"->",
"ip",
"=",
"$",
"ip",
";",
"$",
"event",
"->",
"user_agent",
"=",
"$",
"userAgent",
";",
"$",
"event",
"->",
"save",
"(",
")",
";",
"return",
"$",
"link",
";",
"}"
] | Builds a reset password link.
@param int $userId
@param string $ip
@param string $userAgent
@return UserLink | [
"Builds",
"a",
"reset",
"password",
"link",
"."
] | 720280b4b2635572f331afe8d082e3e88cf54eb7 | https://github.com/infusephp/auth/blob/720280b4b2635572f331afe8d082e3e88cf54eb7/src/Libs/ResetPassword.php#L155-L176 | train |
wdbo/webdocbook | src/WebDocBook/Helper.php | Helper.fetchArguments | public static function fetchArguments($_class = null, $_method = null, $args = null)
{
if (empty($_class) || empty($_method)) {
return null;
}
$args_def = array();
if (!empty($args)) {
$analyze = new ReflectionMethod($_class, $_method);
foreach($analyze->getParameters() as $_param) {
$arg_index = $_param->getName();
$args_def[$_param->getPosition()] = isset($args[$arg_index]) ?
$args[$arg_index] : ( $_param->isOptional() ? $_param->getDefaultValue() : null );
}
}
return call_user_func_array( array($_class, $_method), $args_def );
} | php | public static function fetchArguments($_class = null, $_method = null, $args = null)
{
if (empty($_class) || empty($_method)) {
return null;
}
$args_def = array();
if (!empty($args)) {
$analyze = new ReflectionMethod($_class, $_method);
foreach($analyze->getParameters() as $_param) {
$arg_index = $_param->getName();
$args_def[$_param->getPosition()] = isset($args[$arg_index]) ?
$args[$arg_index] : ( $_param->isOptional() ? $_param->getDefaultValue() : null );
}
}
return call_user_func_array( array($_class, $_method), $args_def );
} | [
"public",
"static",
"function",
"fetchArguments",
"(",
"$",
"_class",
"=",
"null",
",",
"$",
"_method",
"=",
"null",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_class",
")",
"||",
"empty",
"(",
"$",
"_method",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"args_def",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"$",
"analyze",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"_class",
",",
"$",
"_method",
")",
";",
"foreach",
"(",
"$",
"analyze",
"->",
"getParameters",
"(",
")",
"as",
"$",
"_param",
")",
"{",
"$",
"arg_index",
"=",
"$",
"_param",
"->",
"getName",
"(",
")",
";",
"$",
"args_def",
"[",
"$",
"_param",
"->",
"getPosition",
"(",
")",
"]",
"=",
"isset",
"(",
"$",
"args",
"[",
"$",
"arg_index",
"]",
")",
"?",
"$",
"args",
"[",
"$",
"arg_index",
"]",
":",
"(",
"$",
"_param",
"->",
"isOptional",
"(",
")",
"?",
"$",
"_param",
"->",
"getDefaultValue",
"(",
")",
":",
"null",
")",
";",
"}",
"}",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"_class",
",",
"$",
"_method",
")",
",",
"$",
"args_def",
")",
";",
"}"
] | Launch a class's method fetching arguments
@param string $_class The class name
@param string $_method The class method name
@param mixed $args A set of arguments to fetch
@return mixed | [
"Launch",
"a",
"class",
"s",
"method",
"fetching",
"arguments"
] | 7d4e806f674b6222c9a3e85bfed34e72bc9d584e | https://github.com/wdbo/webdocbook/blob/7d4e806f674b6222c9a3e85bfed34e72bc9d584e/src/WebDocBook/Helper.php#L60-L75 | train |
rhosocial/helpers | BaseTimezone.php | BaseTimezone.generateList | public static function generateList($region = DateTimeZone::ALL)
{
$regions = array(
DateTimeZone::AFRICA,
DateTimeZone::AMERICA,
DateTimeZone::ANTARCTICA,
DateTimeZone::ASIA,
DateTimeZone::ATLANTIC,
DateTimeZone::AUSTRALIA,
DateTimeZone::EUROPE,
DateTimeZone::INDIAN,
DateTimeZone::PACIFIC,
);
if ($region !== DateTimeZone::ALL && !in_array($region, $regions)) {
$region = DateTimeZone::ALL;
}
$timezones = array();
if ($region == DateTimeZone::ALL) {
foreach ($regions as $r) {
$timezones = array_merge($timezones, DateTimeZone::listIdentifiers($r));
}
} else {
$timezones = DateTimeZone::listIdentifiers($region);
}
$timezone_offsets = array();
foreach ($timezones as $timezone) {
$tz = new DateTimeZone($timezone);
$timezone_offsets[$timezone] = $tz->getOffset(new DateTime);
}
asort($timezone_offsets);
$timezone_list = array();
foreach ($timezone_offsets as $timezone => $offset) {
$offset_prefix = $offset < 0 ? '-' : '+';
$offset_formatted = gmdate('H:i', abs($offset));
$pretty_offset = "UTC${offset_prefix}${offset_formatted}";
$t = new DateTimeZone($timezone);
$c = new DateTime(null, $t);
$timezone_list[$timezone] = $pretty_offset . " - " . $timezone;
}
return $timezone_list;
} | php | public static function generateList($region = DateTimeZone::ALL)
{
$regions = array(
DateTimeZone::AFRICA,
DateTimeZone::AMERICA,
DateTimeZone::ANTARCTICA,
DateTimeZone::ASIA,
DateTimeZone::ATLANTIC,
DateTimeZone::AUSTRALIA,
DateTimeZone::EUROPE,
DateTimeZone::INDIAN,
DateTimeZone::PACIFIC,
);
if ($region !== DateTimeZone::ALL && !in_array($region, $regions)) {
$region = DateTimeZone::ALL;
}
$timezones = array();
if ($region == DateTimeZone::ALL) {
foreach ($regions as $r) {
$timezones = array_merge($timezones, DateTimeZone::listIdentifiers($r));
}
} else {
$timezones = DateTimeZone::listIdentifiers($region);
}
$timezone_offsets = array();
foreach ($timezones as $timezone) {
$tz = new DateTimeZone($timezone);
$timezone_offsets[$timezone] = $tz->getOffset(new DateTime);
}
asort($timezone_offsets);
$timezone_list = array();
foreach ($timezone_offsets as $timezone => $offset) {
$offset_prefix = $offset < 0 ? '-' : '+';
$offset_formatted = gmdate('H:i', abs($offset));
$pretty_offset = "UTC${offset_prefix}${offset_formatted}";
$t = new DateTimeZone($timezone);
$c = new DateTime(null, $t);
$timezone_list[$timezone] = $pretty_offset . " - " . $timezone;
}
return $timezone_list;
} | [
"public",
"static",
"function",
"generateList",
"(",
"$",
"region",
"=",
"DateTimeZone",
"::",
"ALL",
")",
"{",
"$",
"regions",
"=",
"array",
"(",
"DateTimeZone",
"::",
"AFRICA",
",",
"DateTimeZone",
"::",
"AMERICA",
",",
"DateTimeZone",
"::",
"ANTARCTICA",
",",
"DateTimeZone",
"::",
"ASIA",
",",
"DateTimeZone",
"::",
"ATLANTIC",
",",
"DateTimeZone",
"::",
"AUSTRALIA",
",",
"DateTimeZone",
"::",
"EUROPE",
",",
"DateTimeZone",
"::",
"INDIAN",
",",
"DateTimeZone",
"::",
"PACIFIC",
",",
")",
";",
"if",
"(",
"$",
"region",
"!==",
"DateTimeZone",
"::",
"ALL",
"&&",
"!",
"in_array",
"(",
"$",
"region",
",",
"$",
"regions",
")",
")",
"{",
"$",
"region",
"=",
"DateTimeZone",
"::",
"ALL",
";",
"}",
"$",
"timezones",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"region",
"==",
"DateTimeZone",
"::",
"ALL",
")",
"{",
"foreach",
"(",
"$",
"regions",
"as",
"$",
"r",
")",
"{",
"$",
"timezones",
"=",
"array_merge",
"(",
"$",
"timezones",
",",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
"$",
"r",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"timezones",
"=",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
"$",
"region",
")",
";",
"}",
"$",
"timezone_offsets",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"timezones",
"as",
"$",
"timezone",
")",
"{",
"$",
"tz",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"$",
"timezone_offsets",
"[",
"$",
"timezone",
"]",
"=",
"$",
"tz",
"->",
"getOffset",
"(",
"new",
"DateTime",
")",
";",
"}",
"asort",
"(",
"$",
"timezone_offsets",
")",
";",
"$",
"timezone_list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"timezone_offsets",
"as",
"$",
"timezone",
"=>",
"$",
"offset",
")",
"{",
"$",
"offset_prefix",
"=",
"$",
"offset",
"<",
"0",
"?",
"'-'",
":",
"'+'",
";",
"$",
"offset_formatted",
"=",
"gmdate",
"(",
"'H:i'",
",",
"abs",
"(",
"$",
"offset",
")",
")",
";",
"$",
"pretty_offset",
"=",
"\"UTC${offset_prefix}${offset_formatted}\"",
";",
"$",
"t",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"$",
"c",
"=",
"new",
"DateTime",
"(",
"null",
",",
"$",
"t",
")",
";",
"$",
"timezone_list",
"[",
"$",
"timezone",
"]",
"=",
"$",
"pretty_offset",
".",
"\" - \"",
".",
"$",
"timezone",
";",
"}",
"return",
"$",
"timezone_list",
";",
"}"
] | Generate Time Zone List.
@param int $region
@return array | [
"Generate",
"Time",
"Zone",
"List",
"."
] | 547ee6bca153bd35ed21d27606a40748bffcd726 | https://github.com/rhosocial/helpers/blob/547ee6bca153bd35ed21d27606a40748bffcd726/BaseTimezone.php#L31-L73 | train |
slickframework/form | src/Renderer/TextArea.php | TextArea.render | public function render($context = [])
{
if ($this->getElement()->hasAttribute('value')) {
$this->getElement()->getAttributes()->remove('value');
}
return parent::render($context);
} | php | public function render($context = [])
{
if ($this->getElement()->hasAttribute('value')) {
$this->getElement()->getAttributes()->remove('value');
}
return parent::render($context);
} | [
"public",
"function",
"render",
"(",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getElement",
"(",
")",
"->",
"hasAttribute",
"(",
"'value'",
")",
")",
"{",
"$",
"this",
"->",
"getElement",
"(",
")",
"->",
"getAttributes",
"(",
")",
"->",
"remove",
"(",
"'value'",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"context",
")",
";",
"}"
] | Overrides to remove the unnecessary value attribute
@param array $context
@return string | [
"Overrides",
"to",
"remove",
"the",
"unnecessary",
"value",
"attribute"
] | e7d536b3bad49194e246ff93587da2589e31a003 | https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Renderer/TextArea.php#L25-L31 | train |
as3io/modlr | src/Store/Cache.php | Cache.clearType | public function clearType($typeKey)
{
if (isset($this->models[$typeKey])) {
unset($this->models[$typeKey]);
}
return $this;
} | php | public function clearType($typeKey)
{
if (isset($this->models[$typeKey])) {
unset($this->models[$typeKey]);
}
return $this;
} | [
"public",
"function",
"clearType",
"(",
"$",
"typeKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"typeKey",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"typeKey",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Clears all models in the memory cache for a specific type.
@param string $typeKey
@return self | [
"Clears",
"all",
"models",
"in",
"the",
"memory",
"cache",
"for",
"a",
"specific",
"type",
"."
] | 7e684b88bb22a2e18397df9402075c6533084b16 | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Store/Cache.php#L53-L59 | train |
as3io/modlr | src/Store/Cache.php | Cache.push | public function push(Model $model)
{
$this->models[$model->getType()][$model->getId()] = $model;
return $this;
} | php | public function push(Model $model)
{
$this->models[$model->getType()][$model->getId()] = $model;
return $this;
} | [
"public",
"function",
"push",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"models",
"[",
"$",
"model",
"->",
"getType",
"(",
")",
"]",
"[",
"$",
"model",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"model",
";",
"return",
"$",
"this",
";",
"}"
] | Pushes a model into the memory cache.
@param Model $model
@return self | [
"Pushes",
"a",
"model",
"into",
"the",
"memory",
"cache",
"."
] | 7e684b88bb22a2e18397df9402075c6533084b16 | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Store/Cache.php#L78-L82 | train |
as3io/modlr | src/Store/Cache.php | Cache.remove | public function remove($typeKey, $identifier)
{
if (isset($this->models[$typeKey][$identifier])) {
unset($this->models[$typeKey][$identifier]);
}
return $this;
} | php | public function remove($typeKey, $identifier)
{
if (isset($this->models[$typeKey][$identifier])) {
unset($this->models[$typeKey][$identifier]);
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"typeKey",
",",
"$",
"identifier",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"typeKey",
"]",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"typeKey",
"]",
"[",
"$",
"identifier",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes a model from the memory cache, based on type and identifier.
@param string $typeKey
@param string $identifier
@return self | [
"Removes",
"a",
"model",
"from",
"the",
"memory",
"cache",
"based",
"on",
"type",
"and",
"identifier",
"."
] | 7e684b88bb22a2e18397df9402075c6533084b16 | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Store/Cache.php#L91-L97 | train |
as3io/modlr | src/Store/Cache.php | Cache.get | public function get($typeKey, $identifier)
{
$map = $this->getAllForType($typeKey);
if (isset($map[$identifier])) {
return $map[$identifier];
}
return null;
} | php | public function get($typeKey, $identifier)
{
$map = $this->getAllForType($typeKey);
if (isset($map[$identifier])) {
return $map[$identifier];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"typeKey",
",",
"$",
"identifier",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"getAllForType",
"(",
"$",
"typeKey",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"map",
"[",
"$",
"identifier",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Gets a model from the memory cache, based on type and identifier.
@param string $typeKey
@param string $identifier
@return Model|null | [
"Gets",
"a",
"model",
"from",
"the",
"memory",
"cache",
"based",
"on",
"type",
"and",
"identifier",
"."
] | 7e684b88bb22a2e18397df9402075c6533084b16 | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Store/Cache.php#L106-L113 | train |
CampaignChain/activity-ezplatform | Controller/EZPlatformScheduleHandler.php | EZPlatformScheduleHandler.createContent | public function createContent(Location $location = null, Campaign $campaign = null)
{
$connection = $this->getRestApiConnectionByLocation($location);
$remoteContentTypes = $connection->getContentTypes();
foreach($remoteContentTypes as $remoteContentType){
$id = $location->getId().'-'.$remoteContentType['id'];
$name = $remoteContentType['names']['value'][0]['#text'];
$contentTypes[$id] = $name;
}
return $contentTypes;
} | php | public function createContent(Location $location = null, Campaign $campaign = null)
{
$connection = $this->getRestApiConnectionByLocation($location);
$remoteContentTypes = $connection->getContentTypes();
foreach($remoteContentTypes as $remoteContentType){
$id = $location->getId().'-'.$remoteContentType['id'];
$name = $remoteContentType['names']['value'][0]['#text'];
$contentTypes[$id] = $name;
}
return $contentTypes;
} | [
"public",
"function",
"createContent",
"(",
"Location",
"$",
"location",
"=",
"null",
",",
"Campaign",
"$",
"campaign",
"=",
"null",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"getRestApiConnectionByLocation",
"(",
"$",
"location",
")",
";",
"$",
"remoteContentTypes",
"=",
"$",
"connection",
"->",
"getContentTypes",
"(",
")",
";",
"foreach",
"(",
"$",
"remoteContentTypes",
"as",
"$",
"remoteContentType",
")",
"{",
"$",
"id",
"=",
"$",
"location",
"->",
"getId",
"(",
")",
".",
"'-'",
".",
"$",
"remoteContentType",
"[",
"'id'",
"]",
";",
"$",
"name",
"=",
"$",
"remoteContentType",
"[",
"'names'",
"]",
"[",
"'value'",
"]",
"[",
"0",
"]",
"[",
"'#text'",
"]",
";",
"$",
"contentTypes",
"[",
"$",
"id",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"contentTypes",
";",
"}"
] | When a new Activity is being created, this handler method will be called
to retrieve a new Content object for the Activity.
Called in these views:
- new
@param Location $location
@param Campaign $campaign
@return null | [
"When",
"a",
"new",
"Activity",
"is",
"being",
"created",
"this",
"handler",
"method",
"will",
"be",
"called",
"to",
"retrieve",
"a",
"new",
"Content",
"object",
"for",
"the",
"Activity",
"."
] | bf965121bda47d90bcdcf4ef1d651fd9ec42113e | https://github.com/CampaignChain/activity-ezplatform/blob/bf965121bda47d90bcdcf4ef1d651fd9ec42113e/Controller/EZPlatformScheduleHandler.php#L67-L79 | train |
uiii/tense | src/Console/BoxOutputFormatterStyle.php | BoxOutputFormatterStyle.setPadding | public function setPadding($padding = 0) {
$padding = $this->parseSizes($padding);
foreach ($padding as $side => $value) {
if (! is_int($value) || $value < 0) {
throw new InvalidArgumentException(sprintf(
'Invalid %s padding: "%s". Must be a positive integer value.',
$side, $value
));
}
$this->padding[$side] = $value;
}
} | php | public function setPadding($padding = 0) {
$padding = $this->parseSizes($padding);
foreach ($padding as $side => $value) {
if (! is_int($value) || $value < 0) {
throw new InvalidArgumentException(sprintf(
'Invalid %s padding: "%s". Must be a positive integer value.',
$side, $value
));
}
$this->padding[$side] = $value;
}
} | [
"public",
"function",
"setPadding",
"(",
"$",
"padding",
"=",
"0",
")",
"{",
"$",
"padding",
"=",
"$",
"this",
"->",
"parseSizes",
"(",
"$",
"padding",
")",
";",
"foreach",
"(",
"$",
"padding",
"as",
"$",
"side",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid %s padding: \"%s\". Must be a positive integer value.'",
",",
"$",
"side",
",",
"$",
"value",
")",
")",
";",
"}",
"$",
"this",
"->",
"padding",
"[",
"$",
"side",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Sets style padding.
@param array|int $padding The padding value/s | [
"Sets",
"style",
"padding",
"."
] | e5fb4d123f41dbf23796b445389b966c8de2bae1 | https://github.com/uiii/tense/blob/e5fb4d123f41dbf23796b445389b966c8de2bae1/src/Console/BoxOutputFormatterStyle.php#L102-L115 | train |
uiii/tense | src/Console/BoxOutputFormatterStyle.php | BoxOutputFormatterStyle.setMargin | public function setMargin($margin = 0) {
$margin = $this->parseSizes($margin);
foreach ($margin as $side => $value) {
if (! is_int($value) || $value < 0) {
throw new InvalidArgumentException(sprintf(
'Invalid %s margin: "%s". Must be a positive integer value.',
$side, $value
));
}
$this->margin[$side] = $value;
}
} | php | public function setMargin($margin = 0) {
$margin = $this->parseSizes($margin);
foreach ($margin as $side => $value) {
if (! is_int($value) || $value < 0) {
throw new InvalidArgumentException(sprintf(
'Invalid %s margin: "%s". Must be a positive integer value.',
$side, $value
));
}
$this->margin[$side] = $value;
}
} | [
"public",
"function",
"setMargin",
"(",
"$",
"margin",
"=",
"0",
")",
"{",
"$",
"margin",
"=",
"$",
"this",
"->",
"parseSizes",
"(",
"$",
"margin",
")",
";",
"foreach",
"(",
"$",
"margin",
"as",
"$",
"side",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid %s margin: \"%s\". Must be a positive integer value.'",
",",
"$",
"side",
",",
"$",
"value",
")",
")",
";",
"}",
"$",
"this",
"->",
"margin",
"[",
"$",
"side",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Sets style margin.
@param array|int $margin The margin value/s | [
"Sets",
"style",
"margin",
"."
] | e5fb4d123f41dbf23796b445389b966c8de2bae1 | https://github.com/uiii/tense/blob/e5fb4d123f41dbf23796b445389b966c8de2bae1/src/Console/BoxOutputFormatterStyle.php#L122-L135 | train |
wigedev/farm | src/Validator/Validator/Validator.php | Validator.quickValidate | public static function quickValidate(?string $value, array $constraints = [])
{
// Initialize the validator
$validator = new static('quickValidate function', InputFieldTypes::PASSED, [], $value, null);
// Add the constraints
if (is_array($constraints) && count($constraints) > 0) {
foreach ($constraints as $constraint) {
/** @var Constraint|array $constraint */
if (is_array($constraint) && count($constraint) > 0) {
$validator->addConstraint(Constraint::factory($constraint));
} elseif (!is_array($constraint)) {
$validator->addConstraint($constraint);
}
}
}
// Return the value or throw an exception
if ($validator->isValid()) {
return $validator->getValue();
} else {
throw new InvalidInputException('The value is not valid.');
}
} | php | public static function quickValidate(?string $value, array $constraints = [])
{
// Initialize the validator
$validator = new static('quickValidate function', InputFieldTypes::PASSED, [], $value, null);
// Add the constraints
if (is_array($constraints) && count($constraints) > 0) {
foreach ($constraints as $constraint) {
/** @var Constraint|array $constraint */
if (is_array($constraint) && count($constraint) > 0) {
$validator->addConstraint(Constraint::factory($constraint));
} elseif (!is_array($constraint)) {
$validator->addConstraint($constraint);
}
}
}
// Return the value or throw an exception
if ($validator->isValid()) {
return $validator->getValue();
} else {
throw new InvalidInputException('The value is not valid.');
}
} | [
"public",
"static",
"function",
"quickValidate",
"(",
"?",
"string",
"$",
"value",
",",
"array",
"$",
"constraints",
"=",
"[",
"]",
")",
"{",
"// Initialize the validator",
"$",
"validator",
"=",
"new",
"static",
"(",
"'quickValidate function'",
",",
"InputFieldTypes",
"::",
"PASSED",
",",
"[",
"]",
",",
"$",
"value",
",",
"null",
")",
";",
"// Add the constraints",
"if",
"(",
"is_array",
"(",
"$",
"constraints",
")",
"&&",
"count",
"(",
"$",
"constraints",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"/** @var Constraint|array $constraint */",
"if",
"(",
"is_array",
"(",
"$",
"constraint",
")",
"&&",
"count",
"(",
"$",
"constraint",
")",
">",
"0",
")",
"{",
"$",
"validator",
"->",
"addConstraint",
"(",
"Constraint",
"::",
"factory",
"(",
"$",
"constraint",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"constraint",
")",
")",
"{",
"$",
"validator",
"->",
"addConstraint",
"(",
"$",
"constraint",
")",
";",
"}",
"}",
"}",
"// Return the value or throw an exception",
"if",
"(",
"$",
"validator",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"$",
"validator",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidInputException",
"(",
"'The value is not valid.'",
")",
";",
"}",
"}"
] | Validates input as a one-off. Allows quick and dirty validation. Returns null if the value is not valid.
TODO: Decide should this just return true/false if the value is/not valid?
@param string $value The value to test
@param array $constraints The definition of the constraints
@return mixed The value if valid
@throws InvalidInputException If the value is not valid | [
"Validates",
"input",
"as",
"a",
"one",
"-",
"off",
".",
"Allows",
"quick",
"and",
"dirty",
"validation",
".",
"Returns",
"null",
"if",
"the",
"value",
"is",
"not",
"valid",
"."
] | 7a1729ec78628b7e5435e4a42e42d547a07af851 | https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/Validator/Validator/Validator.php#L51-L73 | train |
wigedev/farm | src/Validator/Validator/Validator.php | Validator.addConstraint | public function addConstraint(Constraint $constraint) : void
{
$constraint->setValidator($this);
array_push($this->constraints, $constraint);
} | php | public function addConstraint(Constraint $constraint) : void
{
$constraint->setValidator($this);
array_push($this->constraints, $constraint);
} | [
"public",
"function",
"addConstraint",
"(",
"Constraint",
"$",
"constraint",
")",
":",
"void",
"{",
"$",
"constraint",
"->",
"setValidator",
"(",
"$",
"this",
")",
";",
"array_push",
"(",
"$",
"this",
"->",
"constraints",
",",
"$",
"constraint",
")",
";",
"}"
] | Add a constraint to the validator
@param Constraint $constraint | [
"Add",
"a",
"constraint",
"to",
"the",
"validator"
] | 7a1729ec78628b7e5435e4a42e42d547a07af851 | https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/Validator/Validator/Validator.php#L125-L129 | train |
wigedev/farm | src/Validator/Validator/Validator.php | Validator.reportError | public function reportError(string $error_message) : void
{
$error_message = sprintf($error_message, $this->field_name);
if (null != $this->validation_set) {
$this->validation_set->addValidationError(new ValidationError($this->field_name, $error_message));
}
} | php | public function reportError(string $error_message) : void
{
$error_message = sprintf($error_message, $this->field_name);
if (null != $this->validation_set) {
$this->validation_set->addValidationError(new ValidationError($this->field_name, $error_message));
}
} | [
"public",
"function",
"reportError",
"(",
"string",
"$",
"error_message",
")",
":",
"void",
"{",
"$",
"error_message",
"=",
"sprintf",
"(",
"$",
"error_message",
",",
"$",
"this",
"->",
"field_name",
")",
";",
"if",
"(",
"null",
"!=",
"$",
"this",
"->",
"validation_set",
")",
"{",
"$",
"this",
"->",
"validation_set",
"->",
"addValidationError",
"(",
"new",
"ValidationError",
"(",
"$",
"this",
"->",
"field_name",
",",
"$",
"error_message",
")",
")",
";",
"}",
"}"
] | Report the error message to validation set
@param string $error_message The error message to report | [
"Report",
"the",
"error",
"message",
"to",
"validation",
"set"
] | 7a1729ec78628b7e5435e4a42e42d547a07af851 | https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/Validator/Validator/Validator.php#L164-L170 | train |
wigedev/farm | src/Validator/Validator/Validator.php | Validator.validate | public function validate() : void
{
$this->value = null;
$value = $this->filter($this->raw_value);
if (true === $this->checkValidity($value)) {
$this->is_valid = true;
} else {
$this->is_valid = false;
$this->reportError($this->error_message);
$error_message = sprintf($this->error_message, $this->field_name);
$this->the_message = $error_message;
}
// If no issues have been found, check the constraints.
if ($this->is_valid) {
foreach ($this->constraints as $constraint) {
if (false === $constraint->check($value)) {
$this->is_valid = false;
$this->the_message = sprintf($constraint->getErrorMessage(), $this->field_name);
}
}
}
// Set the value for retrieval
if ($this->is_valid) {
$this->value = $value;
}
} | php | public function validate() : void
{
$this->value = null;
$value = $this->filter($this->raw_value);
if (true === $this->checkValidity($value)) {
$this->is_valid = true;
} else {
$this->is_valid = false;
$this->reportError($this->error_message);
$error_message = sprintf($this->error_message, $this->field_name);
$this->the_message = $error_message;
}
// If no issues have been found, check the constraints.
if ($this->is_valid) {
foreach ($this->constraints as $constraint) {
if (false === $constraint->check($value)) {
$this->is_valid = false;
$this->the_message = sprintf($constraint->getErrorMessage(), $this->field_name);
}
}
}
// Set the value for retrieval
if ($this->is_valid) {
$this->value = $value;
}
} | [
"public",
"function",
"validate",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"value",
"=",
"null",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"this",
"->",
"raw_value",
")",
";",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"checkValidity",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"is_valid",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"is_valid",
"=",
"false",
";",
"$",
"this",
"->",
"reportError",
"(",
"$",
"this",
"->",
"error_message",
")",
";",
"$",
"error_message",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"error_message",
",",
"$",
"this",
"->",
"field_name",
")",
";",
"$",
"this",
"->",
"the_message",
"=",
"$",
"error_message",
";",
"}",
"// If no issues have been found, check the constraints.",
"if",
"(",
"$",
"this",
"->",
"is_valid",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"constraint",
"->",
"check",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"is_valid",
"=",
"false",
";",
"$",
"this",
"->",
"the_message",
"=",
"sprintf",
"(",
"$",
"constraint",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"this",
"->",
"field_name",
")",
";",
"}",
"}",
"}",
"// Set the value for retrieval",
"if",
"(",
"$",
"this",
"->",
"is_valid",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"}",
"}"
] | Do the validation. This process starts by filtering the value, then checks the validity, and finally checks
the constraints. | [
"Do",
"the",
"validation",
".",
"This",
"process",
"starts",
"by",
"filtering",
"the",
"value",
"then",
"checks",
"the",
"validity",
"and",
"finally",
"checks",
"the",
"constraints",
"."
] | 7a1729ec78628b7e5435e4a42e42d547a07af851 | https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/Validator/Validator/Validator.php#L223-L248 | train |
yii2lab/yii2-rbac | src/domain/repositories/traits/AssignmentTrait.php | AssignmentTrait.getAssignments | public function getAssignments($userId) {
if(empty($userId)) {
return [];
}
$roles = $this->allRoleNamesByUserId($userId);
return AssignmentHelper::forge($userId, $roles);
} | php | public function getAssignments($userId) {
if(empty($userId)) {
return [];
}
$roles = $this->allRoleNamesByUserId($userId);
return AssignmentHelper::forge($userId, $roles);
} | [
"public",
"function",
"getAssignments",
"(",
"$",
"userId",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"roles",
"=",
"$",
"this",
"->",
"allRoleNamesByUserId",
"(",
"$",
"userId",
")",
";",
"return",
"AssignmentHelper",
"::",
"forge",
"(",
"$",
"userId",
",",
"$",
"roles",
")",
";",
"}"
] | Returns all role assignment information for the specified user.
@param string|int $userId the user ID (see [[\yii\web\User::id]])
@return Assignment[] the assignments indexed by role names. An empty array will be
returned if there is no role assigned to the user. | [
"Returns",
"all",
"role",
"assignment",
"information",
"for",
"the",
"specified",
"user",
"."
] | e72ac0359af660690c161451f864208b2d20919d | https://github.com/yii2lab/yii2-rbac/blob/e72ac0359af660690c161451f864208b2d20919d/src/domain/repositories/traits/AssignmentTrait.php#L114-L120 | train |
yii2lab/yii2-rbac | src/domain/repositories/traits/AssignmentTrait.php | AssignmentTrait.revoke | public function revoke($role, $userId) {
$userId = $this->getId($userId);
$entity = \App::$domain->account->login->oneById($userId);
$this->model->deleteAll(['user_id' => $userId, 'item_name' => $role]);
} | php | public function revoke($role, $userId) {
$userId = $this->getId($userId);
$entity = \App::$domain->account->login->oneById($userId);
$this->model->deleteAll(['user_id' => $userId, 'item_name' => $role]);
} | [
"public",
"function",
"revoke",
"(",
"$",
"role",
",",
"$",
"userId",
")",
"{",
"$",
"userId",
"=",
"$",
"this",
"->",
"getId",
"(",
"$",
"userId",
")",
";",
"$",
"entity",
"=",
"\\",
"App",
"::",
"$",
"domain",
"->",
"account",
"->",
"login",
"->",
"oneById",
"(",
"$",
"userId",
")",
";",
"$",
"this",
"->",
"model",
"->",
"deleteAll",
"(",
"[",
"'user_id'",
"=>",
"$",
"userId",
",",
"'item_name'",
"=>",
"$",
"role",
"]",
")",
";",
"}"
] | Revokes a role from a user.
@param Role|Permission $role
@param string|int $userId the user ID (see [[\yii\web\User::id]])
@return bool whether the revoking is successful | [
"Revokes",
"a",
"role",
"from",
"a",
"user",
"."
] | e72ac0359af660690c161451f864208b2d20919d | https://github.com/yii2lab/yii2-rbac/blob/e72ac0359af660690c161451f864208b2d20919d/src/domain/repositories/traits/AssignmentTrait.php#L151-L155 | train |
cyberspectrum/i18n-contao | src/Mapping/Terminal42ChangeLanguage/MapBuilder.php | MapBuilder.getPageMap | private function getPageMap(string $sourceLanguage, string $targetLanguage): PageMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->pageMaps)) {
return $this->pageMaps[$key] = new PageMap(
$sourceLanguage,
$targetLanguage,
$this->database,
$this->logger
);
}
return $this->pageMaps[$key];
} | php | private function getPageMap(string $sourceLanguage, string $targetLanguage): PageMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->pageMaps)) {
return $this->pageMaps[$key] = new PageMap(
$sourceLanguage,
$targetLanguage,
$this->database,
$this->logger
);
}
return $this->pageMaps[$key];
} | [
"private",
"function",
"getPageMap",
"(",
"string",
"$",
"sourceLanguage",
",",
"string",
"$",
"targetLanguage",
")",
":",
"PageMap",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
"=",
"$",
"sourceLanguage",
".",
"'->'",
".",
"$",
"targetLanguage",
",",
"$",
"this",
"->",
"pageMaps",
")",
")",
"{",
"return",
"$",
"this",
"->",
"pageMaps",
"[",
"$",
"key",
"]",
"=",
"new",
"PageMap",
"(",
"$",
"sourceLanguage",
",",
"$",
"targetLanguage",
",",
"$",
"this",
"->",
"database",
",",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pageMaps",
"[",
"$",
"key",
"]",
";",
"}"
] | Retrieve pageMap.
@param string $sourceLanguage The source language.
@param string $targetLanguage The target language.
@return PageMap | [
"Retrieve",
"pageMap",
"."
] | 038cf6ea9c609a734d7476fba256bc4b0db236b7 | https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/MapBuilder.php#L133-L145 | train |
cyberspectrum/i18n-contao | src/Mapping/Terminal42ChangeLanguage/MapBuilder.php | MapBuilder.getArticleMap | private function getArticleMap(string $sourceLanguage, string $targetLanguage): ArticleMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->articleMaps)) {
return $this->articleMaps[$key] = new ArticleMap(
$this->getPageMap($sourceLanguage, $targetLanguage),
$this->logger
);
}
return $this->articleMaps[$key];
} | php | private function getArticleMap(string $sourceLanguage, string $targetLanguage): ArticleMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->articleMaps)) {
return $this->articleMaps[$key] = new ArticleMap(
$this->getPageMap($sourceLanguage, $targetLanguage),
$this->logger
);
}
return $this->articleMaps[$key];
} | [
"private",
"function",
"getArticleMap",
"(",
"string",
"$",
"sourceLanguage",
",",
"string",
"$",
"targetLanguage",
")",
":",
"ArticleMap",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
"=",
"$",
"sourceLanguage",
".",
"'->'",
".",
"$",
"targetLanguage",
",",
"$",
"this",
"->",
"articleMaps",
")",
")",
"{",
"return",
"$",
"this",
"->",
"articleMaps",
"[",
"$",
"key",
"]",
"=",
"new",
"ArticleMap",
"(",
"$",
"this",
"->",
"getPageMap",
"(",
"$",
"sourceLanguage",
",",
"$",
"targetLanguage",
")",
",",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"return",
"$",
"this",
"->",
"articleMaps",
"[",
"$",
"key",
"]",
";",
"}"
] | Retrieve article map.
@param string $sourceLanguage The source language.
@param string $targetLanguage The target language.
@return ArticleMap | [
"Retrieve",
"article",
"map",
"."
] | 038cf6ea9c609a734d7476fba256bc4b0db236b7 | https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/MapBuilder.php#L155-L165 | train |
cyberspectrum/i18n-contao | src/Mapping/Terminal42ChangeLanguage/MapBuilder.php | MapBuilder.getArticleContentMap | private function getArticleContentMap(string $sourceLanguage, string $targetLanguage): ArticleContentMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->articleContentMaps)) {
return $this->articleContentMaps[$key] = new ArticleContentMap(
$this->getArticleMap($sourceLanguage, $targetLanguage),
$this->logger
);
}
return $this->articleContentMaps[$key];
} | php | private function getArticleContentMap(string $sourceLanguage, string $targetLanguage): ArticleContentMap
{
if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->articleContentMaps)) {
return $this->articleContentMaps[$key] = new ArticleContentMap(
$this->getArticleMap($sourceLanguage, $targetLanguage),
$this->logger
);
}
return $this->articleContentMaps[$key];
} | [
"private",
"function",
"getArticleContentMap",
"(",
"string",
"$",
"sourceLanguage",
",",
"string",
"$",
"targetLanguage",
")",
":",
"ArticleContentMap",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
"=",
"$",
"sourceLanguage",
".",
"'->'",
".",
"$",
"targetLanguage",
",",
"$",
"this",
"->",
"articleContentMaps",
")",
")",
"{",
"return",
"$",
"this",
"->",
"articleContentMaps",
"[",
"$",
"key",
"]",
"=",
"new",
"ArticleContentMap",
"(",
"$",
"this",
"->",
"getArticleMap",
"(",
"$",
"sourceLanguage",
",",
"$",
"targetLanguage",
")",
",",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"return",
"$",
"this",
"->",
"articleContentMaps",
"[",
"$",
"key",
"]",
";",
"}"
] | Retrieve article content map.
@param string $sourceLanguage The source language.
@param string $targetLanguage The target language.
@return ArticleContentMap | [
"Retrieve",
"article",
"content",
"map",
"."
] | 038cf6ea9c609a734d7476fba256bc4b0db236b7 | https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/MapBuilder.php#L175-L185 | train |
3ev/wordpress-core | src/Tev/Field/Model/TaxonomyField.php | TaxonomyField.getValue | public function getValue()
{
$terms = $this->base['value'];
if (is_array($terms)) {
$ret = array();
foreach ($terms as $t) {
$ret[] = $this->termFactory->create($t, $this->taxonomy());
}
return $ret;
} elseif (is_object($terms)) {
return $this->termFactory->create($terms, $this->taxonomy());
} else {
if ($this->base['multiple'] || $this->base['field_type'] === 'multi_select' || $this->base['field_type'] === 'checkbox') {
return array();
} else {
return null;
}
}
} | php | public function getValue()
{
$terms = $this->base['value'];
if (is_array($terms)) {
$ret = array();
foreach ($terms as $t) {
$ret[] = $this->termFactory->create($t, $this->taxonomy());
}
return $ret;
} elseif (is_object($terms)) {
return $this->termFactory->create($terms, $this->taxonomy());
} else {
if ($this->base['multiple'] || $this->base['field_type'] === 'multi_select' || $this->base['field_type'] === 'checkbox') {
return array();
} else {
return null;
}
}
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"$",
"terms",
"=",
"$",
"this",
"->",
"base",
"[",
"'value'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"terms",
")",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"terms",
"as",
"$",
"t",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"this",
"->",
"termFactory",
"->",
"create",
"(",
"$",
"t",
",",
"$",
"this",
"->",
"taxonomy",
"(",
")",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"terms",
")",
")",
"{",
"return",
"$",
"this",
"->",
"termFactory",
"->",
"create",
"(",
"$",
"terms",
",",
"$",
"this",
"->",
"taxonomy",
"(",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"base",
"[",
"'multiple'",
"]",
"||",
"$",
"this",
"->",
"base",
"[",
"'field_type'",
"]",
"===",
"'multi_select'",
"||",
"$",
"this",
"->",
"base",
"[",
"'field_type'",
"]",
"===",
"'checkbox'",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"}"
] | Get Term or array of Terms.
@return \Tev\Term\Model\Term|\Tev\Term\Model\Term[]|null | [
"Get",
"Term",
"or",
"array",
"of",
"Terms",
"."
] | da674fbec5bf3d5bd2a2141680a4c141113eb6b0 | https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Model/TaxonomyField.php#L59-L80 | train |
3ev/wordpress-core | src/Tev/Field/Model/TaxonomyField.php | TaxonomyField.taxonomy | public function taxonomy()
{
if ($this->_taxonomy === null) {
$this->_taxonomy = $this->taxonomyFactory->create($this->base['taxonomy']);
}
return $this->_taxonomy;
} | php | public function taxonomy()
{
if ($this->_taxonomy === null) {
$this->_taxonomy = $this->taxonomyFactory->create($this->base['taxonomy']);
}
return $this->_taxonomy;
} | [
"public",
"function",
"taxonomy",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_taxonomy",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_taxonomy",
"=",
"$",
"this",
"->",
"taxonomyFactory",
"->",
"create",
"(",
"$",
"this",
"->",
"base",
"[",
"'taxonomy'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_taxonomy",
";",
"}"
] | Get Term Taxonomy.
@return \Tev\Taxonomy\Model\Taxonomy | [
"Get",
"Term",
"Taxonomy",
"."
] | da674fbec5bf3d5bd2a2141680a4c141113eb6b0 | https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Model/TaxonomyField.php#L87-L94 | train |
as3io/symfony-data-importer | src/Import/Persister.php | Persister.getWriteMode | final public function getWriteMode()
{
switch ($this->getDataMode()) {
case Configuration::DATA_MODE_WIPE:
case Configuration::DATA_MODE_PROGRESSIVE:
$this->setWriteMode(static::WRITE_MODE_INSERT);
break;
default:
$this->setWriteMode(static::WRITE_MODE_UPSERT);
}
return $this->writeMode;
} | php | final public function getWriteMode()
{
switch ($this->getDataMode()) {
case Configuration::DATA_MODE_WIPE:
case Configuration::DATA_MODE_PROGRESSIVE:
$this->setWriteMode(static::WRITE_MODE_INSERT);
break;
default:
$this->setWriteMode(static::WRITE_MODE_UPSERT);
}
return $this->writeMode;
} | [
"final",
"public",
"function",
"getWriteMode",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getDataMode",
"(",
")",
")",
"{",
"case",
"Configuration",
"::",
"DATA_MODE_WIPE",
":",
"case",
"Configuration",
"::",
"DATA_MODE_PROGRESSIVE",
":",
"$",
"this",
"->",
"setWriteMode",
"(",
"static",
"::",
"WRITE_MODE_INSERT",
")",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"setWriteMode",
"(",
"static",
"::",
"WRITE_MODE_UPSERT",
")",
";",
"}",
"return",
"$",
"this",
"->",
"writeMode",
";",
"}"
] | Returns the current write mode
@return string | [
"Returns",
"the",
"current",
"write",
"mode"
] | 33383e38f20f6b7a4b83da619bd028ac84ced579 | https://github.com/as3io/symfony-data-importer/blob/33383e38f20f6b7a4b83da619bd028ac84ced579/src/Import/Persister.php#L128-L139 | train |
as3io/symfony-data-importer | src/Import/Persister.php | Persister.batchUpdate | final public function batchUpdate($scn, array $criteria, array $update)
{
return $this->getCollectionForModel($scn)->update($criteria, $update, ['multiple' => true]);
} | php | final public function batchUpdate($scn, array $criteria, array $update)
{
return $this->getCollectionForModel($scn)->update($criteria, $update, ['multiple' => true]);
} | [
"final",
"public",
"function",
"batchUpdate",
"(",
"$",
"scn",
",",
"array",
"$",
"criteria",
",",
"array",
"$",
"update",
")",
"{",
"return",
"$",
"this",
"->",
"getCollectionForModel",
"(",
"$",
"scn",
")",
"->",
"update",
"(",
"$",
"criteria",
",",
"$",
"update",
",",
"[",
"'multiple'",
"=>",
"true",
"]",
")",
";",
"}"
] | Performs a batch update
@param string $scn
@param array $criteria The targeting parameters
@param array $update The modifications to make to the targeted documents | [
"Performs",
"a",
"batch",
"update"
] | 33383e38f20f6b7a4b83da619bd028ac84ced579 | https://github.com/as3io/symfony-data-importer/blob/33383e38f20f6b7a4b83da619bd028ac84ced579/src/Import/Persister.php#L197-L200 | train |
as3io/symfony-data-importer | src/Import/Persister.php | Persister.doUpsert | final protected function doUpsert($scn, array $kvs)
{
$upsertKey = isset($kvs['external']) ? 'external' : 'legacy';
$upsertNs = 'legacy' === $upsertKey ? 'source' : 'namespace';
$upsertId = 'legacy' === $upsertKey ? 'id' : 'identifier';
$update = ['$set' => $kvs];
if (!isset($kvs[$upsertKey][$upsertId]) || !isset($kvs[$upsertKey][$upsertNs])) {
throw new Exception\UpsertException(sprintf('%s.%s or %s.%s was not specified, cannot upsert!', $upsertKey, $upsertId, $upsertKey, $upsertNs));
}
if (!isset($kvs['_id'])) {
$id = $this->generateId($scn);
if (null !== $id) {
$update['$setOnInsert'] = ['_id' => $id];
}
}
$query = [
sprintf('%s.%s', $upsertKey, $upsertId) => $kvs[$upsertKey][$upsertId],
sprintf('%s.%s', $upsertKey, $upsertNs) => $kvs[$upsertKey][$upsertNs],
];
$r = $this->getCollectionForModel($scn)->update($query, $update, ['upsert' => true]);
if (true === $r['updatedExisting']) {
$id = $this->getCollectionForModel($scn)->findOne($query, ['_id'])['_id'];
$kvs['_id'] = $id;
} else {
if (!isset($kvs['_id'])) {
$kvs['_id'] = $r['upserted'];
}
}
return $kvs;
} | php | final protected function doUpsert($scn, array $kvs)
{
$upsertKey = isset($kvs['external']) ? 'external' : 'legacy';
$upsertNs = 'legacy' === $upsertKey ? 'source' : 'namespace';
$upsertId = 'legacy' === $upsertKey ? 'id' : 'identifier';
$update = ['$set' => $kvs];
if (!isset($kvs[$upsertKey][$upsertId]) || !isset($kvs[$upsertKey][$upsertNs])) {
throw new Exception\UpsertException(sprintf('%s.%s or %s.%s was not specified, cannot upsert!', $upsertKey, $upsertId, $upsertKey, $upsertNs));
}
if (!isset($kvs['_id'])) {
$id = $this->generateId($scn);
if (null !== $id) {
$update['$setOnInsert'] = ['_id' => $id];
}
}
$query = [
sprintf('%s.%s', $upsertKey, $upsertId) => $kvs[$upsertKey][$upsertId],
sprintf('%s.%s', $upsertKey, $upsertNs) => $kvs[$upsertKey][$upsertNs],
];
$r = $this->getCollectionForModel($scn)->update($query, $update, ['upsert' => true]);
if (true === $r['updatedExisting']) {
$id = $this->getCollectionForModel($scn)->findOne($query, ['_id'])['_id'];
$kvs['_id'] = $id;
} else {
if (!isset($kvs['_id'])) {
$kvs['_id'] = $r['upserted'];
}
}
return $kvs;
} | [
"final",
"protected",
"function",
"doUpsert",
"(",
"$",
"scn",
",",
"array",
"$",
"kvs",
")",
"{",
"$",
"upsertKey",
"=",
"isset",
"(",
"$",
"kvs",
"[",
"'external'",
"]",
")",
"?",
"'external'",
":",
"'legacy'",
";",
"$",
"upsertNs",
"=",
"'legacy'",
"===",
"$",
"upsertKey",
"?",
"'source'",
":",
"'namespace'",
";",
"$",
"upsertId",
"=",
"'legacy'",
"===",
"$",
"upsertKey",
"?",
"'id'",
":",
"'identifier'",
";",
"$",
"update",
"=",
"[",
"'$set'",
"=>",
"$",
"kvs",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"kvs",
"[",
"$",
"upsertKey",
"]",
"[",
"$",
"upsertId",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"kvs",
"[",
"$",
"upsertKey",
"]",
"[",
"$",
"upsertNs",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UpsertException",
"(",
"sprintf",
"(",
"'%s.%s or %s.%s was not specified, cannot upsert!'",
",",
"$",
"upsertKey",
",",
"$",
"upsertId",
",",
"$",
"upsertKey",
",",
"$",
"upsertNs",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"kvs",
"[",
"'_id'",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"generateId",
"(",
"$",
"scn",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"id",
")",
"{",
"$",
"update",
"[",
"'$setOnInsert'",
"]",
"=",
"[",
"'_id'",
"=>",
"$",
"id",
"]",
";",
"}",
"}",
"$",
"query",
"=",
"[",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"upsertKey",
",",
"$",
"upsertId",
")",
"=>",
"$",
"kvs",
"[",
"$",
"upsertKey",
"]",
"[",
"$",
"upsertId",
"]",
",",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"upsertKey",
",",
"$",
"upsertNs",
")",
"=>",
"$",
"kvs",
"[",
"$",
"upsertKey",
"]",
"[",
"$",
"upsertNs",
"]",
",",
"]",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"getCollectionForModel",
"(",
"$",
"scn",
")",
"->",
"update",
"(",
"$",
"query",
",",
"$",
"update",
",",
"[",
"'upsert'",
"=>",
"true",
"]",
")",
";",
"if",
"(",
"true",
"===",
"$",
"r",
"[",
"'updatedExisting'",
"]",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getCollectionForModel",
"(",
"$",
"scn",
")",
"->",
"findOne",
"(",
"$",
"query",
",",
"[",
"'_id'",
"]",
")",
"[",
"'_id'",
"]",
";",
"$",
"kvs",
"[",
"'_id'",
"]",
"=",
"$",
"id",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"kvs",
"[",
"'_id'",
"]",
")",
")",
"{",
"$",
"kvs",
"[",
"'_id'",
"]",
"=",
"$",
"r",
"[",
"'upserted'",
"]",
";",
"}",
"}",
"return",
"$",
"kvs",
";",
"}"
] | Handles a single document upsert
@param string $scn The model type
@param array $kvs The model's keyValues.
@return array The upserted modelValues | [
"Handles",
"a",
"single",
"document",
"upsert"
] | 33383e38f20f6b7a4b83da619bd028ac84ced579 | https://github.com/as3io/symfony-data-importer/blob/33383e38f20f6b7a4b83da619bd028ac84ced579/src/Import/Persister.php#L259-L293 | train |
as3io/symfony-data-importer | src/Import/Persister.php | Persister.setWriteMode | final protected function setWriteMode($mode)
{
if (!in_array($mode, [static::WRITE_MODE_INSERT, static::WRITE_MODE_UPSERT, static::WRITE_MODE_UPDATE])) {
throw new \InvalidArgumentException(sprintf('Passed write mode "%s" is invalid!', $mode));
}
$this->writeMode = $mode;
} | php | final protected function setWriteMode($mode)
{
if (!in_array($mode, [static::WRITE_MODE_INSERT, static::WRITE_MODE_UPSERT, static::WRITE_MODE_UPDATE])) {
throw new \InvalidArgumentException(sprintf('Passed write mode "%s" is invalid!', $mode));
}
$this->writeMode = $mode;
} | [
"final",
"protected",
"function",
"setWriteMode",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"mode",
",",
"[",
"static",
"::",
"WRITE_MODE_INSERT",
",",
"static",
"::",
"WRITE_MODE_UPSERT",
",",
"static",
"::",
"WRITE_MODE_UPDATE",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Passed write mode \"%s\" is invalid!'",
",",
"$",
"mode",
")",
")",
";",
"}",
"$",
"this",
"->",
"writeMode",
"=",
"$",
"mode",
";",
"}"
] | Sets the current write mode
@param string $mode The write mode to use. | [
"Sets",
"the",
"current",
"write",
"mode"
] | 33383e38f20f6b7a4b83da619bd028ac84ced579 | https://github.com/as3io/symfony-data-importer/blob/33383e38f20f6b7a4b83da619bd028ac84ced579/src/Import/Persister.php#L311-L317 | train |
Phpillip/phpillip | src/EventListener/ContentConverterListener.php | ContentConverterListener.onKernelController | public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $route->hasContent()) {
$this->populateContent($route, $request);
}
} | php | public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $route->hasContent()) {
$this->populateContent($route, $request);
}
} | [
"public",
"function",
"onKernelController",
"(",
"FilterControllerEvent",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"routes",
"->",
"get",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route'",
")",
")",
";",
"if",
"(",
"$",
"route",
"&&",
"$",
"route",
"->",
"hasContent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"populateContent",
"(",
"$",
"route",
",",
"$",
"request",
")",
";",
"}",
"}"
] | Handler Kernel Controller events
@param FilterControllerEvent $event | [
"Handler",
"Kernel",
"Controller",
"events"
] | c37afaafb536361e7e0b564659f1cd5b80b98be9 | https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/ContentConverterListener.php#L60-L68 | train |
tarsana/syntax | src/ObjectSyntax.php | ObjectSyntax.fields | public function fields($value = null)
{
if (null === $value) {
return $this->fields;
}
$this->fields = $value;
return $this;
} | php | public function fields($value = null)
{
if (null === $value) {
return $this->fields;
}
$this->fields = $value;
return $this;
} | [
"public",
"function",
"fields",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"$",
"this",
"->",
"fields",
";",
"}",
"$",
"this",
"->",
"fields",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Fields getter and setter.
@param array $value
@return mixed | [
"Fields",
"getter",
"and",
"setter",
"."
] | fd3f8a25e3be0e391c8fd486ccfcffe913ade534 | https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ObjectSyntax.php#L81-L88 | train |
tarsana/syntax | src/ObjectSyntax.php | ObjectSyntax.field | public function field(string $name, Syntax $value = null)
{
if ($value === null) {
$names = explode('.', $name);
$syntax = $this;
foreach ($names as $field) {
while (method_exists($syntax, 'syntax')) {
$syntax = $syntax->syntax();
}
if ($syntax instanceof ObjectSyntax && array_key_exists($field, $syntax->fields)) {
$syntax = $syntax->fields[$field];
} else {
throw new \InvalidArgumentException("field '{$name}' not found");
}
}
return $syntax;
}
$this->fields[$name] = $value;
return $this;
} | php | public function field(string $name, Syntax $value = null)
{
if ($value === null) {
$names = explode('.', $name);
$syntax = $this;
foreach ($names as $field) {
while (method_exists($syntax, 'syntax')) {
$syntax = $syntax->syntax();
}
if ($syntax instanceof ObjectSyntax && array_key_exists($field, $syntax->fields)) {
$syntax = $syntax->fields[$field];
} else {
throw new \InvalidArgumentException("field '{$name}' not found");
}
}
return $syntax;
}
$this->fields[$name] = $value;
return $this;
} | [
"public",
"function",
"field",
"(",
"string",
"$",
"name",
",",
"Syntax",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"names",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"syntax",
"=",
"$",
"this",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"field",
")",
"{",
"while",
"(",
"method_exists",
"(",
"$",
"syntax",
",",
"'syntax'",
")",
")",
"{",
"$",
"syntax",
"=",
"$",
"syntax",
"->",
"syntax",
"(",
")",
";",
"}",
"if",
"(",
"$",
"syntax",
"instanceof",
"ObjectSyntax",
"&&",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"syntax",
"->",
"fields",
")",
")",
"{",
"$",
"syntax",
"=",
"$",
"syntax",
"->",
"fields",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"field '{$name}' not found\"",
")",
";",
"}",
"}",
"return",
"$",
"syntax",
";",
"}",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Setter and getter of a specific field.
@param string $name
@param Tarsana\Syntax\Syntax|null $value
@return Tarsana\Syntax\Syntax|self
@throws InvalidArgumentException | [
"Setter",
"and",
"getter",
"of",
"a",
"specific",
"field",
"."
] | fd3f8a25e3be0e391c8fd486ccfcffe913ade534 | https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ObjectSyntax.php#L99-L119 | train |
tarsana/syntax | src/ObjectSyntax.php | ObjectSyntax.clearValues | protected function clearValues()
{
$this->values = [];
foreach ($this->fields as $name => $syntax) {
$this->values[$name] = (object) [
'value' => null,
'error' => static::MISSING_FIELD
];
}
} | php | protected function clearValues()
{
$this->values = [];
foreach ($this->fields as $name => $syntax) {
$this->values[$name] = (object) [
'value' => null,
'error' => static::MISSING_FIELD
];
}
} | [
"protected",
"function",
"clearValues",
"(",
")",
"{",
"$",
"this",
"->",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"name",
"=>",
"$",
"syntax",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"(",
"object",
")",
"[",
"'value'",
"=>",
"null",
",",
"'error'",
"=>",
"static",
"::",
"MISSING_FIELD",
"]",
";",
"}",
"}"
] | Clears the parsed values.
@return void | [
"Clears",
"the",
"parsed",
"values",
"."
] | fd3f8a25e3be0e391c8fd486ccfcffe913ade534 | https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ObjectSyntax.php#L152-L161 | train |
tarsana/syntax | src/ObjectSyntax.php | ObjectSyntax.dump | public function dump($value) : string
{
$value = (array) $value;
$result = [];
$current = '';
$missingField = false;
try {
foreach ($this->fields as $name => $syntax) {
$current = $name;
if (!array_key_exists($name, $value)) {
$missingField = true;
break;
}
$result[] = $syntax->dump($value[$name]);
}
} catch (DumpException $e) {
throw new DumpException($this, $value, "Unable to dump the field '{$current}'", [], $e);
}
if ($missingField)
throw new DumpException($this, $value, "Missing field '{$name}'");
return Text::join($result, $this->separator);
} | php | public function dump($value) : string
{
$value = (array) $value;
$result = [];
$current = '';
$missingField = false;
try {
foreach ($this->fields as $name => $syntax) {
$current = $name;
if (!array_key_exists($name, $value)) {
$missingField = true;
break;
}
$result[] = $syntax->dump($value[$name]);
}
} catch (DumpException $e) {
throw new DumpException($this, $value, "Unable to dump the field '{$current}'", [], $e);
}
if ($missingField)
throw new DumpException($this, $value, "Missing field '{$name}'");
return Text::join($result, $this->separator);
} | [
"public",
"function",
"dump",
"(",
"$",
"value",
")",
":",
"string",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"current",
"=",
"''",
";",
"$",
"missingField",
"=",
"false",
";",
"try",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"name",
"=>",
"$",
"syntax",
")",
"{",
"$",
"current",
"=",
"$",
"name",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"value",
")",
")",
"{",
"$",
"missingField",
"=",
"true",
";",
"break",
";",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"syntax",
"->",
"dump",
"(",
"$",
"value",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"DumpException",
"$",
"e",
")",
"{",
"throw",
"new",
"DumpException",
"(",
"$",
"this",
",",
"$",
"value",
",",
"\"Unable to dump the field '{$current}'\"",
",",
"[",
"]",
",",
"$",
"e",
")",
";",
"}",
"if",
"(",
"$",
"missingField",
")",
"throw",
"new",
"DumpException",
"(",
"$",
"this",
",",
"$",
"value",
",",
"\"Missing field '{$name}'\"",
")",
";",
"return",
"Text",
"::",
"join",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"separator",
")",
";",
"}"
] | Transforms an object to a string based
on the fields or throws a DumpException.
@param mixed $value
@return string
@throws Tarsana\Syntax\Exceptions\DumpException | [
"Transforms",
"an",
"object",
"to",
"a",
"string",
"based",
"on",
"the",
"fields",
"or",
"throws",
"a",
"DumpException",
"."
] | fd3f8a25e3be0e391c8fd486ccfcffe913ade534 | https://github.com/tarsana/syntax/blob/fd3f8a25e3be0e391c8fd486ccfcffe913ade534/src/ObjectSyntax.php#L250-L273 | train |
valu-digital/valuso | src/ValuSo/Feature/OptionsTrait.php | OptionsTrait.setOptions | public function setOptions($options)
{
if (!is_array($options) && !$options instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf(
'Parameter provided to %s must be an array or Traversable',
__METHOD__
));
}
foreach ($options as $key => $value){
$this->setOption($key, $value);
}
return $this;
} | php | public function setOptions($options)
{
if (!is_array($options) && !$options instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf(
'Parameter provided to %s must be an array or Traversable',
__METHOD__
));
}
foreach ($options as $key => $value){
$this->setOption($key, $value);
}
return $this;
} | [
"public",
"function",
"setOptions",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
"&&",
"!",
"$",
"options",
"instanceof",
"\\",
"Traversable",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Parameter provided to %s must be an array or Traversable'",
",",
"__METHOD__",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set service options from array or traversable object
@param array|Traversable $options
@return \stdClass
@ValuSo\Exclude | [
"Set",
"service",
"options",
"from",
"array",
"or",
"traversable",
"object"
] | c96bed0f6bd21551822334fe6cfe913a7436dd17 | https://github.com/valu-digital/valuso/blob/c96bed0f6bd21551822334fe6cfe913a7436dd17/src/ValuSo/Feature/OptionsTrait.php#L22-L36 | train |
valu-digital/valuso | src/ValuSo/Feature/OptionsTrait.php | OptionsTrait.getOptions | public function getOptions()
{
if(!$this->options){
if (isset($this->optionsClass)) {
$this->options = new $this->optionsClass(array());
} else {
$this->options = new Options(array());
}
}
return $this->options;
} | php | public function getOptions()
{
if(!$this->options){
if (isset($this->optionsClass)) {
$this->options = new $this->optionsClass(array());
} else {
$this->options = new Options(array());
}
}
return $this->options;
} | [
"public",
"function",
"getOptions",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"optionsClass",
")",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"new",
"$",
"this",
"->",
"optionsClass",
"(",
"array",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"options",
"=",
"new",
"Options",
"(",
"array",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"options",
";",
"}"
] | Retrieve service options
@return \Zend\Stdlib\ParameterObjectInterface
@ValuSo\Exclude | [
"Retrieve",
"service",
"options"
] | c96bed0f6bd21551822334fe6cfe913a7436dd17 | https://github.com/valu-digital/valuso/blob/c96bed0f6bd21551822334fe6cfe913a7436dd17/src/ValuSo/Feature/OptionsTrait.php#L45-L56 | train |
valu-digital/valuso | src/ValuSo/Feature/OptionsTrait.php | OptionsTrait.getOption | public function getOption($key, $default = null)
{
if ($this->hasOption($key)) {
return $this->getOptions()->__get($key);
}
return $default;
} | php | public function getOption($key, $default = null)
{
if ($this->hasOption($key)) {
return $this->getOptions()->__get($key);
}
return $default;
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasOption",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"__get",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Retrieve a single option
@param string $key
@return mixed
@ValuSo\Exclude | [
"Retrieve",
"a",
"single",
"option"
] | c96bed0f6bd21551822334fe6cfe913a7436dd17 | https://github.com/valu-digital/valuso/blob/c96bed0f6bd21551822334fe6cfe913a7436dd17/src/ValuSo/Feature/OptionsTrait.php#L94-L101 | train |
valu-digital/valuso | src/ValuSo/Feature/OptionsTrait.php | OptionsTrait.setConfig | public function setConfig($config)
{
if(is_string($config)){
if (file_exists($config)) {
$config = \Zend\Config\Factory::fromFile($config);
} else {
throw new \InvalidArgumentException(
sprintf('Unable to read configurations from file %s',$config));
}
}
if(!is_array($config) && !($config instanceof \Traversable)){
throw new \InvalidArgumentException(
sprintf('Config must be an array, Traversable object or filename; %s received',
is_object($config) ? get_class($config) : gettype($config)));
}
$this->setOptions($config);
} | php | public function setConfig($config)
{
if(is_string($config)){
if (file_exists($config)) {
$config = \Zend\Config\Factory::fromFile($config);
} else {
throw new \InvalidArgumentException(
sprintf('Unable to read configurations from file %s',$config));
}
}
if(!is_array($config) && !($config instanceof \Traversable)){
throw new \InvalidArgumentException(
sprintf('Config must be an array, Traversable object or filename; %s received',
is_object($config) ? get_class($config) : gettype($config)));
}
$this->setOptions($config);
} | [
"public",
"function",
"setConfig",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"\\",
"Zend",
"\\",
"Config",
"\\",
"Factory",
"::",
"fromFile",
"(",
"$",
"config",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unable to read configurations from file %s'",
",",
"$",
"config",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
"&&",
"!",
"(",
"$",
"config",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Config must be an array, Traversable object or filename; %s received'",
",",
"is_object",
"(",
"$",
"config",
")",
"?",
"get_class",
"(",
"$",
"config",
")",
":",
"gettype",
"(",
"$",
"config",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"config",
")",
";",
"}"
] | Set options as config file, array or traversable
object
@param string|array|\Traversable $config
@ValuSo\Exclude | [
"Set",
"options",
"as",
"config",
"file",
"array",
"or",
"traversable",
"object"
] | c96bed0f6bd21551822334fe6cfe913a7436dd17 | https://github.com/valu-digital/valuso/blob/c96bed0f6bd21551822334fe6cfe913a7436dd17/src/ValuSo/Feature/OptionsTrait.php#L124-L142 | train |
JDGrimes/wp-filesystem-mock | src/wp-mock-filesystem.php | WP_Mock_Filesystem.normalize_path | protected function normalize_path( $path ) {
$path = str_replace( '\\', '/', $path );
$path = preg_replace( '|/+|','/', $path );
return rtrim( $path, '/' );
} | php | protected function normalize_path( $path ) {
$path = str_replace( '\\', '/', $path );
$path = preg_replace( '|/+|','/', $path );
return rtrim( $path, '/' );
} | [
"protected",
"function",
"normalize_path",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"preg_replace",
"(",
"'|/+|'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"return",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}"
] | Normalize a path.
@since 0.1.0
@param string $path The path to normalize.
@return string The normalized path. | [
"Normalize",
"a",
"path",
"."
] | 986df3bfeb1554ae19856537dfeb558037275c25 | https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L53-L59 | train |
JDGrimes/wp-filesystem-mock | src/wp-mock-filesystem.php | WP_Mock_Filesystem.get_file | protected function get_file( $file ) {
$path_parts = $this->parse_path( $file );
if ( '' === $path_parts[0] ) {
$file = $this->root;
unset( $path_parts[0] );
} else {
$file = $this->cwd;
}
foreach ( $path_parts as $part ) {
if ( '' === $part ) {
continue;
}
if ( 'dir' !== $file->type || false === isset( $file->contents->$part ) ) {
return false;
}
$file = $file->contents->$part;
}
return $file;
} | php | protected function get_file( $file ) {
$path_parts = $this->parse_path( $file );
if ( '' === $path_parts[0] ) {
$file = $this->root;
unset( $path_parts[0] );
} else {
$file = $this->cwd;
}
foreach ( $path_parts as $part ) {
if ( '' === $part ) {
continue;
}
if ( 'dir' !== $file->type || false === isset( $file->contents->$part ) ) {
return false;
}
$file = $file->contents->$part;
}
return $file;
} | [
"protected",
"function",
"get_file",
"(",
"$",
"file",
")",
"{",
"$",
"path_parts",
"=",
"$",
"this",
"->",
"parse_path",
"(",
"$",
"file",
")",
";",
"if",
"(",
"''",
"===",
"$",
"path_parts",
"[",
"0",
"]",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"root",
";",
"unset",
"(",
"$",
"path_parts",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"cwd",
";",
"}",
"foreach",
"(",
"$",
"path_parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"''",
"===",
"$",
"part",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'dir'",
"!==",
"$",
"file",
"->",
"type",
"||",
"false",
"===",
"isset",
"(",
"$",
"file",
"->",
"contents",
"->",
"$",
"part",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"file",
"=",
"$",
"file",
"->",
"contents",
"->",
"$",
"part",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | Get the data for a file.
@since 0.1.0
@param string $file The file to retrieve.
@return object|false The file data, or false if it does't exist. | [
"Get",
"the",
"data",
"for",
"a",
"file",
"."
] | 986df3bfeb1554ae19856537dfeb558037275c25 | https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L84-L109 | train |
JDGrimes/wp-filesystem-mock | src/wp-mock-filesystem.php | WP_Mock_Filesystem.get_default_atts | protected function get_default_atts( $atts ) {
if ( false === isset( $atts['type'] ) ) {
$atts['type'] = 'file';
}
if ( 'file' === $atts['type'] ) {
$defaults = array( 'contents' => '', 'mode' => 0644, 'size' => 0, );
} elseif ( 'dir' === $atts['type'] ) {
$defaults = array( 'contents' => new stdClass(), 'mode' => 0755 );
} else {
$defaults = array();
}
$atts = array_merge(
array(
'atime' => time(),
'mtime' => time(),
'owner' => '',
'group' => '',
)
, $defaults
, $atts
);
if ( ! empty( $atts['contents'] ) && 'file' === $atts['type'] ) {
$atts['size'] = mb_strlen( $atts['contents'], '8bit' );
}
return (object) $atts;
} | php | protected function get_default_atts( $atts ) {
if ( false === isset( $atts['type'] ) ) {
$atts['type'] = 'file';
}
if ( 'file' === $atts['type'] ) {
$defaults = array( 'contents' => '', 'mode' => 0644, 'size' => 0, );
} elseif ( 'dir' === $atts['type'] ) {
$defaults = array( 'contents' => new stdClass(), 'mode' => 0755 );
} else {
$defaults = array();
}
$atts = array_merge(
array(
'atime' => time(),
'mtime' => time(),
'owner' => '',
'group' => '',
)
, $defaults
, $atts
);
if ( ! empty( $atts['contents'] ) && 'file' === $atts['type'] ) {
$atts['size'] = mb_strlen( $atts['contents'], '8bit' );
}
return (object) $atts;
} | [
"protected",
"function",
"get_default_atts",
"(",
"$",
"atts",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"atts",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"atts",
"[",
"'type'",
"]",
"=",
"'file'",
";",
"}",
"if",
"(",
"'file'",
"===",
"$",
"atts",
"[",
"'type'",
"]",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
"'contents'",
"=>",
"''",
",",
"'mode'",
"=>",
"0644",
",",
"'size'",
"=>",
"0",
",",
")",
";",
"}",
"elseif",
"(",
"'dir'",
"===",
"$",
"atts",
"[",
"'type'",
"]",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
"'contents'",
"=>",
"new",
"stdClass",
"(",
")",
",",
"'mode'",
"=>",
"0755",
")",
";",
"}",
"else",
"{",
"$",
"defaults",
"=",
"array",
"(",
")",
";",
"}",
"$",
"atts",
"=",
"array_merge",
"(",
"array",
"(",
"'atime'",
"=>",
"time",
"(",
")",
",",
"'mtime'",
"=>",
"time",
"(",
")",
",",
"'owner'",
"=>",
"''",
",",
"'group'",
"=>",
"''",
",",
")",
",",
"$",
"defaults",
",",
"$",
"atts",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"atts",
"[",
"'contents'",
"]",
")",
"&&",
"'file'",
"===",
"$",
"atts",
"[",
"'type'",
"]",
")",
"{",
"$",
"atts",
"[",
"'size'",
"]",
"=",
"mb_strlen",
"(",
"$",
"atts",
"[",
"'contents'",
"]",
",",
"'8bit'",
")",
";",
"}",
"return",
"(",
"object",
")",
"$",
"atts",
";",
"}"
] | Get the default attributes for a file.
@since 0.1.0
@param string $atts
@return object The attributes. | [
"Get",
"the",
"default",
"attributes",
"for",
"a",
"file",
"."
] | 986df3bfeb1554ae19856537dfeb558037275c25 | https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L120-L150 | train |
JDGrimes/wp-filesystem-mock | src/wp-mock-filesystem.php | WP_Mock_Filesystem.add_file | public function add_file( $file, array $atts = array() ) {
$parent = $this->get_file( dirname( $file ) );
$filename = basename( $file );
if ( false === $parent || true === isset( $parent->contents->$filename ) ) {
return false;
}
$parent->contents->$filename = $this->get_default_atts( $atts );
return true;
} | php | public function add_file( $file, array $atts = array() ) {
$parent = $this->get_file( dirname( $file ) );
$filename = basename( $file );
if ( false === $parent || true === isset( $parent->contents->$filename ) ) {
return false;
}
$parent->contents->$filename = $this->get_default_atts( $atts );
return true;
} | [
"public",
"function",
"add_file",
"(",
"$",
"file",
",",
"array",
"$",
"atts",
"=",
"array",
"(",
")",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"get_file",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
";",
"$",
"filename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"if",
"(",
"false",
"===",
"$",
"parent",
"||",
"true",
"===",
"isset",
"(",
"$",
"parent",
"->",
"contents",
"->",
"$",
"filename",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"parent",
"->",
"contents",
"->",
"$",
"filename",
"=",
"$",
"this",
"->",
"get_default_atts",
"(",
"$",
"atts",
")",
";",
"return",
"true",
";",
"}"
] | Create a file or directory.
@since 0.1.0
@param string $file The path of the file/directory to create.
@param array $atts The attributes of the file/directory.
@return bool True if the file was added, false otherwise. | [
"Create",
"a",
"file",
"or",
"directory",
"."
] | 986df3bfeb1554ae19856537dfeb558037275c25 | https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L175-L187 | train |
JDGrimes/wp-filesystem-mock | src/wp-mock-filesystem.php | WP_Mock_Filesystem.mkdir_p | public function mkdir_p( $file, array $atts = array() ) {
$dir_levels = $this->parse_path( $file );
$path = '';
$atts['type'] = 'dir';
foreach ( $dir_levels as $level ) {
$path .= '/' . $level;
if ( $this->exists( $path ) ) {
continue;
}
if ( ! $this->add_file( $path, $atts ) ) {
return false;
}
}
return true;
} | php | public function mkdir_p( $file, array $atts = array() ) {
$dir_levels = $this->parse_path( $file );
$path = '';
$atts['type'] = 'dir';
foreach ( $dir_levels as $level ) {
$path .= '/' . $level;
if ( $this->exists( $path ) ) {
continue;
}
if ( ! $this->add_file( $path, $atts ) ) {
return false;
}
}
return true;
} | [
"public",
"function",
"mkdir_p",
"(",
"$",
"file",
",",
"array",
"$",
"atts",
"=",
"array",
"(",
")",
")",
"{",
"$",
"dir_levels",
"=",
"$",
"this",
"->",
"parse_path",
"(",
"$",
"file",
")",
";",
"$",
"path",
"=",
"''",
";",
"$",
"atts",
"[",
"'type'",
"]",
"=",
"'dir'",
";",
"foreach",
"(",
"$",
"dir_levels",
"as",
"$",
"level",
")",
"{",
"$",
"path",
".=",
"'/'",
".",
"$",
"level",
";",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"add_file",
"(",
"$",
"path",
",",
"$",
"atts",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Create a deep directory.
@since 0.1.0
@param string $file The path of the file/directory to create.
@param array $atts The attributes of the file/directory.
@return bool True if the file was added, false otherwise. | [
"Create",
"a",
"deep",
"directory",
"."
] | 986df3bfeb1554ae19856537dfeb558037275c25 | https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L199-L220 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.