id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
31,300 | czim/laravel-listify | src/Listify.php | Listify.updateListifyPositions | protected function updateListifyPositions()
{
$newPosition = $this->getListifyPosition();
// check for duplicate positions and resolve them if required
if (null === $newPosition) return;
$count = $this->listifyScopedQuery()
->where($this->positionColumn(), $newPosition)
->count();
if ($count < 2) return;
$oldPosition = Arr::get($this->getOriginal(), $this->positionColumn(), false);
if (false === $oldPosition) return;
// reorder positions while excluding the current model
$this->reorderPositionsOnItemsBetween($oldPosition, $newPosition, $this->id);
} | php | protected function updateListifyPositions()
{
$newPosition = $this->getListifyPosition();
// check for duplicate positions and resolve them if required
if (null === $newPosition) return;
$count = $this->listifyScopedQuery()
->where($this->positionColumn(), $newPosition)
->count();
if ($count < 2) return;
$oldPosition = Arr::get($this->getOriginal(), $this->positionColumn(), false);
if (false === $oldPosition) return;
// reorder positions while excluding the current model
$this->reorderPositionsOnItemsBetween($oldPosition, $newPosition, $this->id);
} | [
"protected",
"function",
"updateListifyPositions",
"(",
")",
"{",
"$",
"newPosition",
"=",
"$",
"this",
"->",
"getListifyPosition",
"(",
")",
";",
"// check for duplicate positions and resolve them if required",
"if",
"(",
"null",
"===",
"$",
"newPosition",
")",
"return",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"$",
"newPosition",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"count",
"<",
"2",
")",
"return",
";",
"$",
"oldPosition",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"getOriginal",
"(",
")",
",",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"false",
")",
";",
"if",
"(",
"false",
"===",
"$",
"oldPosition",
")",
"return",
";",
"// reorder positions while excluding the current model",
"$",
"this",
"->",
"reorderPositionsOnItemsBetween",
"(",
"$",
"oldPosition",
",",
"$",
"newPosition",
",",
"$",
"this",
"->",
"id",
")",
";",
"}"
] | Updates all record positions based on changed position of the record in the current list. | [
"Updates",
"all",
"record",
"positions",
"based",
"on",
"changed",
"position",
"of",
"the",
"record",
"in",
"the",
"current",
"list",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L920-L939 |
31,301 | czim/laravel-listify | src/Listify.php | Listify.getBottomPositionValue | protected function getBottomPositionValue($exclude = null)
{
$item = $this->getBottomItem($exclude);
if ( ! $item) return null;
return $item->getListifyPosition();
} | php | protected function getBottomPositionValue($exclude = null)
{
$item = $this->getBottomItem($exclude);
if ( ! $item) return null;
return $item->getListifyPosition();
} | [
"protected",
"function",
"getBottomPositionValue",
"(",
"$",
"exclude",
"=",
"null",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"getBottomItem",
"(",
"$",
"exclude",
")",
";",
"if",
"(",
"!",
"$",
"item",
")",
"return",
"null",
";",
"return",
"$",
"item",
"->",
"getListifyPosition",
"(",
")",
";",
"}"
] | Returns the value of the bottom position.
@param null|Model|Listify $exclude a model whose value to exclude in determining the position
@return integer|null | [
"Returns",
"the",
"value",
"of",
"the",
"bottom",
"position",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L948-L955 |
31,302 | czim/laravel-listify | src/Listify.php | Listify.getBottomItem | protected function getBottomItem(Model $exclude = null)
{
$query = $this->listifyScopedQuery()
->whereNotNull($this->getTable() . '.' . $this->positionColumn())
->orderBy($this->getTable() . "." . $this->positionColumn(), "DESC")
->take(1);
if ($exclude) {
$query->where($this->getPrimaryKey(), '!=', $exclude->id);
}
return $query->first();
} | php | protected function getBottomItem(Model $exclude = null)
{
$query = $this->listifyScopedQuery()
->whereNotNull($this->getTable() . '.' . $this->positionColumn())
->orderBy($this->getTable() . "." . $this->positionColumn(), "DESC")
->take(1);
if ($exclude) {
$query->where($this->getPrimaryKey(), '!=', $exclude->id);
}
return $query->first();
} | [
"protected",
"function",
"getBottomItem",
"(",
"Model",
"$",
"exclude",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"listifyScopedQuery",
"(",
")",
"->",
"whereNotNull",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"positionColumn",
"(",
")",
")",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"\".\"",
".",
"$",
"this",
"->",
"positionColumn",
"(",
")",
",",
"\"DESC\"",
")",
"->",
"take",
"(",
"1",
")",
";",
"if",
"(",
"$",
"exclude",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"'!='",
",",
"$",
"exclude",
"->",
"id",
")",
";",
"}",
"return",
"$",
"query",
"->",
"first",
"(",
")",
";",
"}"
] | Returns the bottom item.
@param null|Model|Listify $exclude a model to exclude as a match
@return null|Model|Listify | [
"Returns",
"the",
"bottom",
"item",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L963-L975 |
31,303 | czim/laravel-listify | src/Listify.php | Listify.getConditionStringFromQueryBuilder | protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
{
$initialQueryChunks = explode('where ', $query->toSql());
if (count($initialQueryChunks) == 1) {
throw new InvalidArgumentException(
'The query builder instance must have a where clause to build a condition string from'
);
}
$queryChunks = explode('?', $initialQueryChunks[1]);
$chunkCount = count($queryChunks);
$bindings = $query->getBindings();
$whereString = '';
for ($i = 0; $i < $chunkCount; $i++) {
$whereString .= $queryChunks[ $i ];
if (isset($bindings[ $i ])) {
if (gettype($bindings[ $i ]) === 'string') {
$whereString .= '"' . $bindings[ $i ] . '"';
}
}
}
return $whereString;
} | php | protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
{
$initialQueryChunks = explode('where ', $query->toSql());
if (count($initialQueryChunks) == 1) {
throw new InvalidArgumentException(
'The query builder instance must have a where clause to build a condition string from'
);
}
$queryChunks = explode('?', $initialQueryChunks[1]);
$chunkCount = count($queryChunks);
$bindings = $query->getBindings();
$whereString = '';
for ($i = 0; $i < $chunkCount; $i++) {
$whereString .= $queryChunks[ $i ];
if (isset($bindings[ $i ])) {
if (gettype($bindings[ $i ]) === 'string') {
$whereString .= '"' . $bindings[ $i ] . '"';
}
}
}
return $whereString;
} | [
"protected",
"function",
"getConditionStringFromQueryBuilder",
"(",
"QueryBuilder",
"$",
"query",
")",
"{",
"$",
"initialQueryChunks",
"=",
"explode",
"(",
"'where '",
",",
"$",
"query",
"->",
"toSql",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"initialQueryChunks",
")",
"==",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The query builder instance must have a where clause to build a condition string from'",
")",
";",
"}",
"$",
"queryChunks",
"=",
"explode",
"(",
"'?'",
",",
"$",
"initialQueryChunks",
"[",
"1",
"]",
")",
";",
"$",
"chunkCount",
"=",
"count",
"(",
"$",
"queryChunks",
")",
";",
"$",
"bindings",
"=",
"$",
"query",
"->",
"getBindings",
"(",
")",
";",
"$",
"whereString",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"chunkCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"whereString",
".=",
"$",
"queryChunks",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"bindings",
"[",
"$",
"i",
"]",
")",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"bindings",
"[",
"$",
"i",
"]",
")",
"===",
"'string'",
")",
"{",
"$",
"whereString",
".=",
"'\"'",
".",
"$",
"bindings",
"[",
"$",
"i",
"]",
".",
"'\"'",
";",
"}",
"}",
"}",
"return",
"$",
"whereString",
";",
"}"
] | Extracts a raw WHERE clause string from a QueryBuilder instance.
Note that this is practically identical to the original Listify.
@param QueryBuilder $query A Query Builder instance
@return string | [
"Extracts",
"a",
"raw",
"WHERE",
"clause",
"string",
"from",
"a",
"QueryBuilder",
"instance",
".",
"Note",
"that",
"this",
"is",
"practically",
"identical",
"to",
"the",
"original",
"Listify",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L990-L1018 |
31,304 | czim/laravel-listify | src/Listify.php | Listify.getConditionStringFromBelongsTo | protected function getConditionStringFromBelongsTo(BelongsTo $relation)
{
$id = $this->getAttribute( $relation->getForeignKeyName() );
// an empty foreign key will, as a null-scope, remove the item from any list
if (null === $id) return null;
return '`' . $relation->getForeignKeyName() . '` = ' . (int) $id;
} | php | protected function getConditionStringFromBelongsTo(BelongsTo $relation)
{
$id = $this->getAttribute( $relation->getForeignKeyName() );
// an empty foreign key will, as a null-scope, remove the item from any list
if (null === $id) return null;
return '`' . $relation->getForeignKeyName() . '` = ' . (int) $id;
} | [
"protected",
"function",
"getConditionStringFromBelongsTo",
"(",
"BelongsTo",
"$",
"relation",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"relation",
"->",
"getForeignKeyName",
"(",
")",
")",
";",
"// an empty foreign key will, as a null-scope, remove the item from any list",
"if",
"(",
"null",
"===",
"$",
"id",
")",
"return",
"null",
";",
"return",
"'`'",
".",
"$",
"relation",
"->",
"getForeignKeyName",
"(",
")",
".",
"'` = '",
".",
"(",
"int",
")",
"$",
"id",
";",
"}"
] | Makes a raw where condition string from a BelongsTo relation instance.
@param BelongsTo $relation
@return string | [
"Makes",
"a",
"raw",
"where",
"condition",
"string",
"from",
"a",
"BelongsTo",
"relation",
"instance",
"."
] | c7c12faacf43de1c024a7b39cb44183d2711a838 | https://github.com/czim/laravel-listify/blob/c7c12faacf43de1c024a7b39cb44183d2711a838/src/Listify.php#L1026-L1034 |
31,305 | EmchBerger/cube-custom-fields-bundle | src/Form/DataTransformer/EntityCustomFieldTransformer.php | EntityCustomFieldTransformer.transform | public function transform($collection)
{
if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
// in case of single entity, we have to make sure it's managed
if (!$this->er->getManager()->contains($collection)) {
$collection = $this->er->getManager()->merge($collection);
}
}
return $collection;
} | php | public function transform($collection)
{
if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
// in case of single entity, we have to make sure it's managed
if (!$this->er->getManager()->contains($collection)) {
$collection = $this->er->getManager()->merge($collection);
}
}
return $collection;
} | [
"public",
"function",
"transform",
"(",
"$",
"collection",
")",
"{",
"if",
"(",
"$",
"collection",
"&&",
"!",
"is_array",
"(",
"$",
"collection",
")",
"&&",
"!",
"(",
"$",
"collection",
"instanceof",
"\\",
"ArrayAccess",
")",
")",
"{",
"// in case of single entity, we have to make sure it's managed",
"if",
"(",
"!",
"$",
"this",
"->",
"er",
"->",
"getManager",
"(",
")",
"->",
"contains",
"(",
"$",
"collection",
")",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"er",
"->",
"getManager",
"(",
")",
"->",
"merge",
"(",
"$",
"collection",
")",
";",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] | No real transformation required in forward direction
@return mixed An array of entities
@throws TransformationFailedException | [
"No",
"real",
"transformation",
"required",
"in",
"forward",
"direction"
] | 7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414 | https://github.com/EmchBerger/cube-custom-fields-bundle/blob/7c87f9e8e0f7a5f50536d0d801c04a0ba6de3414/src/Form/DataTransformer/EntityCustomFieldTransformer.php#L32-L41 |
31,306 | bearcms/bearframework-addon | classes/BearCMS/Themes.php | Themes.register | public function register(string $id, callable $callback): self
{
Internal\Themes::$registrations[$id] = $callback;
if (Config::$initialized) { // Initialize to add asset dirs
$currentThemeID = Internal\CurrentTheme::getID();
if ($currentThemeID === $id) {
Internal\Themes::initialize($currentThemeID);
}
}
return $this;
} | php | public function register(string $id, callable $callback): self
{
Internal\Themes::$registrations[$id] = $callback;
if (Config::$initialized) { // Initialize to add asset dirs
$currentThemeID = Internal\CurrentTheme::getID();
if ($currentThemeID === $id) {
Internal\Themes::initialize($currentThemeID);
}
}
return $this;
} | [
"public",
"function",
"register",
"(",
"string",
"$",
"id",
",",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"Internal",
"\\",
"Themes",
"::",
"$",
"registrations",
"[",
"$",
"id",
"]",
"=",
"$",
"callback",
";",
"if",
"(",
"Config",
"::",
"$",
"initialized",
")",
"{",
"// Initialize to add asset dirs",
"$",
"currentThemeID",
"=",
"Internal",
"\\",
"CurrentTheme",
"::",
"getID",
"(",
")",
";",
"if",
"(",
"$",
"currentThemeID",
"===",
"$",
"id",
")",
"{",
"Internal",
"\\",
"Themes",
"::",
"initialize",
"(",
"$",
"currentThemeID",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Register a new theme.
@param string $id The theme ID.
@param callable $callback A function to define theme parameters.
@return self Returns a reference to itself. | [
"Register",
"a",
"new",
"theme",
"."
] | 7ef131b81aac26070a2b937dd67f530a6caa02f0 | https://github.com/bearcms/bearframework-addon/blob/7ef131b81aac26070a2b937dd67f530a6caa02f0/classes/BearCMS/Themes.php#L29-L41 |
31,307 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.init | public function init ()
{
if (session_status() == PHP_SESSION_NONE)
session_start();
if (isset($_SESSION[ 'notification' ]))
{
$notification = $_SESSION[ 'notification' ];
foreach ($notification as $type => $data)
foreach ($data as $message)
$this->_data[] = new Notification($message, $type, true);
$_SESSION[ 'notification' ] = [];
}
parent::init();
} | php | public function init ()
{
if (session_status() == PHP_SESSION_NONE)
session_start();
if (isset($_SESSION[ 'notification' ]))
{
$notification = $_SESSION[ 'notification' ];
foreach ($notification as $type => $data)
foreach ($data as $message)
$this->_data[] = new Notification($message, $type, true);
$_SESSION[ 'notification' ] = [];
}
parent::init();
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"session_status",
"(",
")",
"==",
"PHP_SESSION_NONE",
")",
"session_start",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"'notification'",
"]",
")",
")",
"{",
"$",
"notification",
"=",
"$",
"_SESSION",
"[",
"'notification'",
"]",
";",
"foreach",
"(",
"$",
"notification",
"as",
"$",
"type",
"=>",
"$",
"data",
")",
"foreach",
"(",
"$",
"data",
"as",
"$",
"message",
")",
"$",
"this",
"->",
"_data",
"[",
"]",
"=",
"new",
"Notification",
"(",
"$",
"message",
",",
"$",
"type",
",",
"true",
")",
";",
"$",
"_SESSION",
"[",
"'notification'",
"]",
"=",
"[",
"]",
";",
"}",
"parent",
"::",
"init",
"(",
")",
";",
"}"
] | Initialization method for checking if there are some notification
stored in session. If so the list of notifications is populated and
the list of notifications stored in session is cleared.
@return void | [
"Initialization",
"method",
"for",
"checking",
"if",
"there",
"are",
"some",
"notification",
"stored",
"in",
"session",
".",
"If",
"so",
"the",
"list",
"of",
"notifications",
"is",
"populated",
"and",
"the",
"list",
"of",
"notifications",
"stored",
"in",
"session",
"is",
"cleared",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L70-L84 |
31,308 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.error | public function error ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::ERROR, $isRaw, $canHide);
} | php | public function error ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::ERROR, $isRaw, $canHide);
} | [
"public",
"function",
"error",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"message",
",",
"Notification",
"::",
"ERROR",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Adds notification of type 'error' to list.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Adds",
"notification",
"of",
"type",
"error",
"to",
"list",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L134-L137 |
31,309 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.errorToSession | public function errorToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::ERROR, $isRaw, $canHide);
} | php | public function errorToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::ERROR, $isRaw, $canHide);
} | [
"public",
"function",
"errorToSession",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"toSession",
"(",
"$",
"message",
",",
"Notification",
"::",
"ERROR",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Saves notification of type 'error' type to session.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Saves",
"notification",
"of",
"type",
"error",
"type",
"to",
"session",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L147-L150 |
31,310 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.message | public function message ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::MESSAGE, $isRaw, $canHide);
} | php | public function message ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::MESSAGE, $isRaw, $canHide);
} | [
"public",
"function",
"message",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"message",
",",
"Notification",
"::",
"MESSAGE",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Adds notification of type 'message' to list.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Adds",
"notification",
"of",
"type",
"message",
"to",
"list",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L160-L163 |
31,311 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.messageToSession | public function messageToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::MESSAGE, $isRaw, $canHide);
} | php | public function messageToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::MESSAGE, $isRaw, $canHide);
} | [
"public",
"function",
"messageToSession",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"toSession",
"(",
"$",
"message",
",",
"Notification",
"::",
"MESSAGE",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Saves notification of type 'message' type to session.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Saves",
"notification",
"of",
"type",
"message",
"type",
"to",
"session",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L173-L176 |
31,312 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.warning | public function warning ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::WARNING, $isRaw, $canHide);
} | php | public function warning ($message, $isRaw = false, $canHide = true)
{
$this->add($message, Notification::WARNING, $isRaw, $canHide);
} | [
"public",
"function",
"warning",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"message",
",",
"Notification",
"::",
"WARNING",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Adds notification of type 'warning' to list.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Adds",
"notification",
"of",
"type",
"warning",
"to",
"list",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L186-L189 |
31,313 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.warningToSession | public function warningToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::WARNING, $isRaw, $canHide);
} | php | public function warningToSession ($message, $isRaw = false, $canHide = true)
{
$this->toSession($message, Notification::WARNING, $isRaw, $canHide);
} | [
"public",
"function",
"warningToSession",
"(",
"$",
"message",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"toSession",
"(",
"$",
"message",
",",
"Notification",
"::",
"WARNING",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Saves notification of type 'warning' type to session.
@param string $message Message.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Saves",
"notification",
"of",
"type",
"warning",
"type",
"to",
"session",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L199-L202 |
31,314 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.add | private function add ($message, $type = Notification::ERROR, $isRaw = false, $canHide = true)
{
$this->_data[] = new Notification ($message, $type, $isRaw, $canHide);
} | php | private function add ($message, $type = Notification::ERROR, $isRaw = false, $canHide = true)
{
$this->_data[] = new Notification ($message, $type, $isRaw, $canHide);
} | [
"private",
"function",
"add",
"(",
"$",
"message",
",",
"$",
"type",
"=",
"Notification",
"::",
"ERROR",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"]",
"=",
"new",
"Notification",
"(",
"$",
"message",
",",
"$",
"type",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"}"
] | Adds notification to list.
@param string $message Message.
@param integer $type Message type.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Adds",
"notification",
"to",
"list",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L213-L216 |
31,315 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.getNotifications | private function getNotifications ($type)
{
$data = [];
/** @var Notification $notification */
foreach ($this->_data as $notification)
{
if ($notification->type == $type)
$data[] = $notification;
}
return $data;
} | php | private function getNotifications ($type)
{
$data = [];
/** @var Notification $notification */
foreach ($this->_data as $notification)
{
if ($notification->type == $type)
$data[] = $notification;
}
return $data;
} | [
"private",
"function",
"getNotifications",
"(",
"$",
"type",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"/** @var Notification $notification */",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"notification",
")",
"{",
"if",
"(",
"$",
"notification",
"->",
"type",
"==",
"$",
"type",
")",
"$",
"data",
"[",
"]",
"=",
"$",
"notification",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Finds all notifications of given type.
@param int $type
@return array | [
"Finds",
"all",
"notifications",
"of",
"given",
"type",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L224-L235 |
31,316 | pulsarvp/vps-tools | src/modules/notification/components/NotificationManager.php | NotificationManager.toSession | private function toSession ($message, $type = Notification::ERROR, $isRaw = false, $canHide = true)
{
$ntf = new Notification($message, $type, $isRaw, $canHide);
$notification = isset($_SESSION[ 'notification' ]) ? $_SESSION[ 'notification' ] : [];
$notification[ $type ][] = $ntf->message;
$_SESSION[ 'notification' ] = $notification;
} | php | private function toSession ($message, $type = Notification::ERROR, $isRaw = false, $canHide = true)
{
$ntf = new Notification($message, $type, $isRaw, $canHide);
$notification = isset($_SESSION[ 'notification' ]) ? $_SESSION[ 'notification' ] : [];
$notification[ $type ][] = $ntf->message;
$_SESSION[ 'notification' ] = $notification;
} | [
"private",
"function",
"toSession",
"(",
"$",
"message",
",",
"$",
"type",
"=",
"Notification",
"::",
"ERROR",
",",
"$",
"isRaw",
"=",
"false",
",",
"$",
"canHide",
"=",
"true",
")",
"{",
"$",
"ntf",
"=",
"new",
"Notification",
"(",
"$",
"message",
",",
"$",
"type",
",",
"$",
"isRaw",
",",
"$",
"canHide",
")",
";",
"$",
"notification",
"=",
"isset",
"(",
"$",
"_SESSION",
"[",
"'notification'",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"'notification'",
"]",
":",
"[",
"]",
";",
"$",
"notification",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"ntf",
"->",
"message",
";",
"$",
"_SESSION",
"[",
"'notification'",
"]",
"=",
"$",
"notification",
";",
"}"
] | Saves notification to session.
@param string $message Message.
@param integer $type Message type.
@param boolean $isRaw Whether given message is raw text or should be translated.
@param boolean $canHide viewed button close.
@return void | [
"Saves",
"notification",
"to",
"session",
"."
] | bb51fd5f68669edbd2801b52a9edeebaa756eec2 | https://github.com/pulsarvp/vps-tools/blob/bb51fd5f68669edbd2801b52a9edeebaa756eec2/src/modules/notification/components/NotificationManager.php#L246-L254 |
31,317 | radig/auditable | Lib/QueryLogSource.php | QueryLogSource.getModelQueries | public function getModelQueries(Model $Model, $action = 'create', $associateds = false)
{
$queries = $this->getCleanLog($Model);
$valids = array();
$table = $Model->tablePrefix . $Model->table;
foreach ($queries as $query) {
// Guarda apenas queries do modelo atual que representam a ação executada
if (strpos($query, $table) !== false && strpos($query, $this->mapActionSql[$action]) !== false) {
$valids[] = $query;
}
}
return $valids;
} | php | public function getModelQueries(Model $Model, $action = 'create', $associateds = false)
{
$queries = $this->getCleanLog($Model);
$valids = array();
$table = $Model->tablePrefix . $Model->table;
foreach ($queries as $query) {
// Guarda apenas queries do modelo atual que representam a ação executada
if (strpos($query, $table) !== false && strpos($query, $this->mapActionSql[$action]) !== false) {
$valids[] = $query;
}
}
return $valids;
} | [
"public",
"function",
"getModelQueries",
"(",
"Model",
"$",
"Model",
",",
"$",
"action",
"=",
"'create'",
",",
"$",
"associateds",
"=",
"false",
")",
"{",
"$",
"queries",
"=",
"$",
"this",
"->",
"getCleanLog",
"(",
"$",
"Model",
")",
";",
"$",
"valids",
"=",
"array",
"(",
")",
";",
"$",
"table",
"=",
"$",
"Model",
"->",
"tablePrefix",
".",
"$",
"Model",
"->",
"table",
";",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"// Guarda apenas queries do modelo atual que representam a ação executada",
"if",
"(",
"strpos",
"(",
"$",
"query",
",",
"$",
"table",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"mapActionSql",
"[",
"$",
"action",
"]",
")",
"!==",
"false",
")",
"{",
"$",
"valids",
"[",
"]",
"=",
"$",
"query",
";",
"}",
"}",
"return",
"$",
"valids",
";",
"}"
] | Recupera todas as queries que foram registradas
pelo datasource para um determinado modelo.
@param Model $Model Instancia do modelo que terá
as queries retornadas.
@param string $action 'create' | 'modify' | 'delete'
@param bool $associateds Habilita ou não o retorno
de queries geradas por modelos relacionados. Não
implementado ainda.
@return array | [
"Recupera",
"todas",
"as",
"queries",
"que",
"foram",
"registradas",
"pelo",
"datasource",
"para",
"um",
"determinado",
"modelo",
"."
] | af8b5031522ebd6d69daa0e694a65c1cb2935b48 | https://github.com/radig/auditable/blob/af8b5031522ebd6d69daa0e694a65c1cb2935b48/Lib/QueryLogSource.php#L90-L104 |
31,318 | gdbots/ncr-php | src/PbjxHelperTrait.php | PbjxHelperTrait.bindFromNode | protected function bindFromNode(Message $message, Node $node, Pbjx $pbjx): void
{
$node->freeze();
$pbjxEvent = new BindFromNodeEvent($message, $node);
$pbjx->trigger($message, 'bind_from_node', $pbjxEvent, false);
} | php | protected function bindFromNode(Message $message, Node $node, Pbjx $pbjx): void
{
$node->freeze();
$pbjxEvent = new BindFromNodeEvent($message, $node);
$pbjx->trigger($message, 'bind_from_node', $pbjxEvent, false);
} | [
"protected",
"function",
"bindFromNode",
"(",
"Message",
"$",
"message",
",",
"Node",
"$",
"node",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"void",
"{",
"$",
"node",
"->",
"freeze",
"(",
")",
";",
"$",
"pbjxEvent",
"=",
"new",
"BindFromNodeEvent",
"(",
"$",
"message",
",",
"$",
"node",
")",
";",
"$",
"pbjx",
"->",
"trigger",
"(",
"$",
"message",
",",
"'bind_from_node'",
",",
"$",
"pbjxEvent",
",",
"false",
")",
";",
"}"
] | The handler generally has the current node which provides
an opportunity to bind data to the event, response, etc.
@param Message $message
@param Node $node
@param Pbjx $pbjx | [
"The",
"handler",
"generally",
"has",
"the",
"current",
"node",
"which",
"provides",
"an",
"opportunity",
"to",
"bind",
"data",
"to",
"the",
"event",
"response",
"etc",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/PbjxHelperTrait.php#L61-L66 |
31,319 | gdbots/ncr-php | src/PbjxHelperTrait.php | PbjxHelperTrait.createGetNodeRequest | protected function createGetNodeRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetNodeRequest
{
$curie = $message::schema()->getCurie();
/** @var GetNodeRequest $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString(
"{$curie->getVendor()}:{$curie->getPackage()}:request:get-{$nodeRef->getLabel()}-request"
));
return $class::create();
} | php | protected function createGetNodeRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetNodeRequest
{
$curie = $message::schema()->getCurie();
/** @var GetNodeRequest $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString(
"{$curie->getVendor()}:{$curie->getPackage()}:request:get-{$nodeRef->getLabel()}-request"
));
return $class::create();
} | [
"protected",
"function",
"createGetNodeRequest",
"(",
"Message",
"$",
"message",
",",
"NodeRef",
"$",
"nodeRef",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"GetNodeRequest",
"{",
"$",
"curie",
"=",
"$",
"message",
"::",
"schema",
"(",
")",
"->",
"getCurie",
"(",
")",
";",
"/** @var GetNodeRequest $class */",
"$",
"class",
"=",
"MessageResolver",
"::",
"resolveCurie",
"(",
"SchemaCurie",
"::",
"fromString",
"(",
"\"{$curie->getVendor()}:{$curie->getPackage()}:request:get-{$nodeRef->getLabel()}-request\"",
")",
")",
";",
"return",
"$",
"class",
"::",
"create",
"(",
")",
";",
"}"
] | A conventional factory to create a get node request from an existing message
and node ref. Various pbjx lifecycle events need to fetch the node for the
operation currently executing. For example, when attempting to update a node
we fetch the current node in order to make some validations possible.
Override this method if the convention doesn't match or needs to have a special
case handled. You can also override when you need to populate data on the
get node request before it's processed (multi-tenant apps sometimes need this).
@param Message $message
@param NodeRef $nodeRef
@param Pbjx $pbjx
@return GetNodeRequest | [
"A",
"conventional",
"factory",
"to",
"create",
"a",
"get",
"node",
"request",
"from",
"an",
"existing",
"message",
"and",
"node",
"ref",
".",
"Various",
"pbjx",
"lifecycle",
"events",
"need",
"to",
"fetch",
"the",
"node",
"for",
"the",
"operation",
"currently",
"executing",
".",
"For",
"example",
"when",
"attempting",
"to",
"update",
"a",
"node",
"we",
"fetch",
"the",
"current",
"node",
"in",
"order",
"to",
"make",
"some",
"validations",
"possible",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/PbjxHelperTrait.php#L84-L94 |
31,320 | gdbots/ncr-php | src/PbjxHelperTrait.php | PbjxHelperTrait.createResponseFromRequest | protected function createResponseFromRequest(Request $request, Pbjx $pbjx): Response
{
$curie = str_replace('-request', '-response', $request::schema()->getCurie()->toString());
/** @var Response $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString($curie));
return $class::create();
} | php | protected function createResponseFromRequest(Request $request, Pbjx $pbjx): Response
{
$curie = str_replace('-request', '-response', $request::schema()->getCurie()->toString());
/** @var Response $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString($curie));
return $class::create();
} | [
"protected",
"function",
"createResponseFromRequest",
"(",
"Request",
"$",
"request",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"Response",
"{",
"$",
"curie",
"=",
"str_replace",
"(",
"'-request'",
",",
"'-response'",
",",
"$",
"request",
"::",
"schema",
"(",
")",
"->",
"getCurie",
"(",
")",
"->",
"toString",
"(",
")",
")",
";",
"/** @var Response $class */",
"$",
"class",
"=",
"MessageResolver",
"::",
"resolveCurie",
"(",
"SchemaCurie",
"::",
"fromString",
"(",
"$",
"curie",
")",
")",
";",
"return",
"$",
"class",
"::",
"create",
"(",
")",
";",
"}"
] | Conventionally the response messages are named the same as the request but
with a "-response" suffix. Override when needed.
@param Request $request
@param Pbjx $pbjx
@return Response | [
"Conventionally",
"the",
"response",
"messages",
"are",
"named",
"the",
"same",
"as",
"the",
"request",
"but",
"with",
"a",
"-",
"response",
"suffix",
".",
"Override",
"when",
"needed",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/PbjxHelperTrait.php#L105-L111 |
31,321 | gdbots/ncr-php | src/Validator/NodeIdempotencyValidator.php | NodeIdempotencyValidator.onCreateNodeAfterHandle | public function onCreateNodeAfterHandle(PbjxEvent $pbjxEvent): void
{
$command = $pbjxEvent->getMessage();
if (!$command->has('node')) {
return;
}
/** @var Node $node */
$node = $command->get('node');
if ($this->shouldIgnoreNode($node)) {
return;
}
/** @var CacheItemInterface[] $cacheItems */
$cacheItems = $this->cache->getItems($this->getIdempotencyKeys($node));
foreach ($cacheItems as $cacheItem) {
$cacheItem->set(true)->expiresAfter($this->getCacheTtl($node));
$this->cache->saveDeferred($cacheItem);
}
} | php | public function onCreateNodeAfterHandle(PbjxEvent $pbjxEvent): void
{
$command = $pbjxEvent->getMessage();
if (!$command->has('node')) {
return;
}
/** @var Node $node */
$node = $command->get('node');
if ($this->shouldIgnoreNode($node)) {
return;
}
/** @var CacheItemInterface[] $cacheItems */
$cacheItems = $this->cache->getItems($this->getIdempotencyKeys($node));
foreach ($cacheItems as $cacheItem) {
$cacheItem->set(true)->expiresAfter($this->getCacheTtl($node));
$this->cache->saveDeferred($cacheItem);
}
} | [
"public",
"function",
"onCreateNodeAfterHandle",
"(",
"PbjxEvent",
"$",
"pbjxEvent",
")",
":",
"void",
"{",
"$",
"command",
"=",
"$",
"pbjxEvent",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"!",
"$",
"command",
"->",
"has",
"(",
"'node'",
")",
")",
"{",
"return",
";",
"}",
"/** @var Node $node */",
"$",
"node",
"=",
"$",
"command",
"->",
"get",
"(",
"'node'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shouldIgnoreNode",
"(",
"$",
"node",
")",
")",
"{",
"return",
";",
"}",
"/** @var CacheItemInterface[] $cacheItems */",
"$",
"cacheItems",
"=",
"$",
"this",
"->",
"cache",
"->",
"getItems",
"(",
"$",
"this",
"->",
"getIdempotencyKeys",
"(",
"$",
"node",
")",
")",
";",
"foreach",
"(",
"$",
"cacheItems",
"as",
"$",
"cacheItem",
")",
"{",
"$",
"cacheItem",
"->",
"set",
"(",
"true",
")",
"->",
"expiresAfter",
"(",
"$",
"this",
"->",
"getCacheTtl",
"(",
"$",
"node",
")",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"saveDeferred",
"(",
"$",
"cacheItem",
")",
";",
"}",
"}"
] | Populates cache keys so idempotency check can reject duplicates
after nodes are successfully created.
@param PbjxEvent $pbjxEvent | [
"Populates",
"cache",
"keys",
"so",
"idempotency",
"check",
"can",
"reject",
"duplicates",
"after",
"nodes",
"are",
"successfully",
"created",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Validator/NodeIdempotencyValidator.php#L89-L109 |
31,322 | gdbots/ncr-php | src/Validator/NodeIdempotencyValidator.php | NodeIdempotencyValidator.getIdempotencyKeys | public function getIdempotencyKeys(Node $node): array
{
$qname = $node::schema()->getQName();
$keys = [];
if ($node->has('title')) {
$keys[$this->getCacheKey($qname, SlugUtils::create($node->get('title')))] = true;
}
if ($node->has('slug')) {
$keys[$this->getCacheKey($qname, $node->get('slug'))] = true;
}
if ($node instanceof User && $node->has('email')) {
$keys[$this->getCacheKey($qname, $node->get('email'))] = true;
}
return array_keys($keys);
} | php | public function getIdempotencyKeys(Node $node): array
{
$qname = $node::schema()->getQName();
$keys = [];
if ($node->has('title')) {
$keys[$this->getCacheKey($qname, SlugUtils::create($node->get('title')))] = true;
}
if ($node->has('slug')) {
$keys[$this->getCacheKey($qname, $node->get('slug'))] = true;
}
if ($node instanceof User && $node->has('email')) {
$keys[$this->getCacheKey($qname, $node->get('email'))] = true;
}
return array_keys($keys);
} | [
"public",
"function",
"getIdempotencyKeys",
"(",
"Node",
"$",
"node",
")",
":",
"array",
"{",
"$",
"qname",
"=",
"$",
"node",
"::",
"schema",
"(",
")",
"->",
"getQName",
"(",
")",
";",
"$",
"keys",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"node",
"->",
"has",
"(",
"'title'",
")",
")",
"{",
"$",
"keys",
"[",
"$",
"this",
"->",
"getCacheKey",
"(",
"$",
"qname",
",",
"SlugUtils",
"::",
"create",
"(",
"$",
"node",
"->",
"get",
"(",
"'title'",
")",
")",
")",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"has",
"(",
"'slug'",
")",
")",
"{",
"$",
"keys",
"[",
"$",
"this",
"->",
"getCacheKey",
"(",
"$",
"qname",
",",
"$",
"node",
"->",
"get",
"(",
"'slug'",
")",
")",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"User",
"&&",
"$",
"node",
"->",
"has",
"(",
"'email'",
")",
")",
"{",
"$",
"keys",
"[",
"$",
"this",
"->",
"getCacheKey",
"(",
"$",
"qname",
",",
"$",
"node",
"->",
"get",
"(",
"'email'",
")",
")",
"]",
"=",
"true",
";",
"}",
"return",
"array_keys",
"(",
"$",
"keys",
")",
";",
"}"
] | Derives the keys to use for the idempotency check from the node itself.
@param Node $node
@return array | [
"Derives",
"the",
"keys",
"to",
"use",
"for",
"the",
"idempotency",
"check",
"from",
"the",
"node",
"itself",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Validator/NodeIdempotencyValidator.php#L118-L136 |
31,323 | starweb/starlit-db | src/BasicDbEntityService.php | BasicDbEntityService.load | public function load(AbstractDbEntity $dbEntity)
{
// Check that the primary key is set
if (!$dbEntity->getPrimaryDbValue()) {
throw new \InvalidArgumentException(
'Database entity can not be loaded because primary value is not set'
);
}
// Fetch ad from db
$row = $this->db->fetchRow(
'
SELECT *
FROM `' . $dbEntity->getDbTableName() . '`
WHERE ' . $this->getPrimaryKeyWhereSql($dbEntity) . '
',
$this->getPrimaryKeyWhereParameters($dbEntity)
);
if (!$row) {
throw new Exception\EntityNotFoundException("Db entity[{$dbEntity->getPrimaryDbValue()}] does not exist");
}
$dbEntity->setDbDataFromRow($row);
} | php | public function load(AbstractDbEntity $dbEntity)
{
// Check that the primary key is set
if (!$dbEntity->getPrimaryDbValue()) {
throw new \InvalidArgumentException(
'Database entity can not be loaded because primary value is not set'
);
}
// Fetch ad from db
$row = $this->db->fetchRow(
'
SELECT *
FROM `' . $dbEntity->getDbTableName() . '`
WHERE ' . $this->getPrimaryKeyWhereSql($dbEntity) . '
',
$this->getPrimaryKeyWhereParameters($dbEntity)
);
if (!$row) {
throw new Exception\EntityNotFoundException("Db entity[{$dbEntity->getPrimaryDbValue()}] does not exist");
}
$dbEntity->setDbDataFromRow($row);
} | [
"public",
"function",
"load",
"(",
"AbstractDbEntity",
"$",
"dbEntity",
")",
"{",
"// Check that the primary key is set",
"if",
"(",
"!",
"$",
"dbEntity",
"->",
"getPrimaryDbValue",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Database entity can not be loaded because primary value is not set'",
")",
";",
"}",
"// Fetch ad from db",
"$",
"row",
"=",
"$",
"this",
"->",
"db",
"->",
"fetchRow",
"(",
"'\n SELECT *\n FROM `'",
".",
"$",
"dbEntity",
"->",
"getDbTableName",
"(",
")",
".",
"'`\n WHERE '",
".",
"$",
"this",
"->",
"getPrimaryKeyWhereSql",
"(",
"$",
"dbEntity",
")",
".",
"'\n '",
",",
"$",
"this",
"->",
"getPrimaryKeyWhereParameters",
"(",
"$",
"dbEntity",
")",
")",
";",
"if",
"(",
"!",
"$",
"row",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"EntityNotFoundException",
"(",
"\"Db entity[{$dbEntity->getPrimaryDbValue()}] does not exist\"",
")",
";",
"}",
"$",
"dbEntity",
"->",
"setDbDataFromRow",
"(",
"$",
"row",
")",
";",
"}"
] | Load object's values from database table.
@param AbstractDbEntity $dbEntity
@throws Exception\EntityNotFoundException | [
"Load",
"object",
"s",
"values",
"from",
"database",
"table",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/BasicDbEntityService.php#L44-L68 |
31,324 | starweb/starlit-db | src/BasicDbEntityService.php | BasicDbEntityService.save | public function save(AbstractDbEntity $dbEntity)
{
if ($dbEntity->shouldBeDeletedFromDbOnSave()) {
// Only delete if previously saved to db
if ($dbEntity->getPrimaryDbValue()) {
$this->delete($dbEntity);
}
return false;
}
if ($dbEntity->shouldInsertOnDbSave()) {
// Note that database data always contains all properties,
// with defaults for non set properties
$dataToSave = $dbEntity->getDbData();
} else {
if ($dbEntity->hasModifiedDbProperties()) {
$dataToSave = $dbEntity->getModifiedDbData();
} else {
// Return if no value has been modified and it's not an insert
// (we always want to insert if no id exist, since some child objects might
// depend on the this primary id being available)
return false;
}
}
// Check data
$sqlData = [];
foreach ($dataToSave as $propertyName => $value) {
if (!empty($value) && is_scalar($value)
&& $dbEntity->getDbPropertyMaxLength($propertyName)
&& mb_strlen($value) > $dbEntity->getDbPropertyMaxLength($propertyName)
) {
throw new \RuntimeException(
"Database field \"{$propertyName}\" exceeds field max length (value: \"{$value}\")"
);
} elseif (empty($value) && $dbEntity->getDbPropertyNonEmpty($propertyName)) {
throw new \RuntimeException("Database field \"{$propertyName}\" is empty and required");
} elseif (((is_scalar($value) && ((string) $value) === '') || (!is_scalar($value) && empty($value)))
&& $dbEntity->getDbPropertyRequired($propertyName)
) {
throw new \RuntimeException("Database field \"{$propertyName}\" is required to be set");
}
// Set data keys db field format
$fieldName = $dbEntity->getDbFieldName($propertyName);
$sqlData[$fieldName] = $value;
}
// Insert new database row
if ($dbEntity->shouldInsertOnDbSave()) {
$this->db->insert(
$dbEntity->getDbTableName(),
$sqlData
);
// Update entity with auto increment value
if (!is_array($dbEntity->getPrimaryDbPropertyKey())
&& !empty($lastInsertId = $this->db->getLastInsertId())
) {
$dbEntity->setPrimaryDbValue($lastInsertId);
} else {
// For entities with for example string primary keys, we update primary value
// with value/values from db data, indicating that the entity is now
// in database/loaded.
$dbEntity->updatePrimaryDbValueFromDbData();
}
// Update existing database row
} else {
$this->db->update(
$dbEntity->getDbTableName(),
$sqlData,
$this->getPrimaryKeyWhereSql($dbEntity),
$this->getPrimaryKeyWhereParameters($dbEntity)
);
}
$dbEntity->clearModifiedDbProperties();
$dbEntity->setForceDbInsertOnSave(false);
return true;
} | php | public function save(AbstractDbEntity $dbEntity)
{
if ($dbEntity->shouldBeDeletedFromDbOnSave()) {
// Only delete if previously saved to db
if ($dbEntity->getPrimaryDbValue()) {
$this->delete($dbEntity);
}
return false;
}
if ($dbEntity->shouldInsertOnDbSave()) {
// Note that database data always contains all properties,
// with defaults for non set properties
$dataToSave = $dbEntity->getDbData();
} else {
if ($dbEntity->hasModifiedDbProperties()) {
$dataToSave = $dbEntity->getModifiedDbData();
} else {
// Return if no value has been modified and it's not an insert
// (we always want to insert if no id exist, since some child objects might
// depend on the this primary id being available)
return false;
}
}
// Check data
$sqlData = [];
foreach ($dataToSave as $propertyName => $value) {
if (!empty($value) && is_scalar($value)
&& $dbEntity->getDbPropertyMaxLength($propertyName)
&& mb_strlen($value) > $dbEntity->getDbPropertyMaxLength($propertyName)
) {
throw new \RuntimeException(
"Database field \"{$propertyName}\" exceeds field max length (value: \"{$value}\")"
);
} elseif (empty($value) && $dbEntity->getDbPropertyNonEmpty($propertyName)) {
throw new \RuntimeException("Database field \"{$propertyName}\" is empty and required");
} elseif (((is_scalar($value) && ((string) $value) === '') || (!is_scalar($value) && empty($value)))
&& $dbEntity->getDbPropertyRequired($propertyName)
) {
throw new \RuntimeException("Database field \"{$propertyName}\" is required to be set");
}
// Set data keys db field format
$fieldName = $dbEntity->getDbFieldName($propertyName);
$sqlData[$fieldName] = $value;
}
// Insert new database row
if ($dbEntity->shouldInsertOnDbSave()) {
$this->db->insert(
$dbEntity->getDbTableName(),
$sqlData
);
// Update entity with auto increment value
if (!is_array($dbEntity->getPrimaryDbPropertyKey())
&& !empty($lastInsertId = $this->db->getLastInsertId())
) {
$dbEntity->setPrimaryDbValue($lastInsertId);
} else {
// For entities with for example string primary keys, we update primary value
// with value/values from db data, indicating that the entity is now
// in database/loaded.
$dbEntity->updatePrimaryDbValueFromDbData();
}
// Update existing database row
} else {
$this->db->update(
$dbEntity->getDbTableName(),
$sqlData,
$this->getPrimaryKeyWhereSql($dbEntity),
$this->getPrimaryKeyWhereParameters($dbEntity)
);
}
$dbEntity->clearModifiedDbProperties();
$dbEntity->setForceDbInsertOnSave(false);
return true;
} | [
"public",
"function",
"save",
"(",
"AbstractDbEntity",
"$",
"dbEntity",
")",
"{",
"if",
"(",
"$",
"dbEntity",
"->",
"shouldBeDeletedFromDbOnSave",
"(",
")",
")",
"{",
"// Only delete if previously saved to db",
"if",
"(",
"$",
"dbEntity",
"->",
"getPrimaryDbValue",
"(",
")",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"dbEntity",
")",
";",
"}",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"dbEntity",
"->",
"shouldInsertOnDbSave",
"(",
")",
")",
"{",
"// Note that database data always contains all properties,",
"// with defaults for non set properties",
"$",
"dataToSave",
"=",
"$",
"dbEntity",
"->",
"getDbData",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"dbEntity",
"->",
"hasModifiedDbProperties",
"(",
")",
")",
"{",
"$",
"dataToSave",
"=",
"$",
"dbEntity",
"->",
"getModifiedDbData",
"(",
")",
";",
"}",
"else",
"{",
"// Return if no value has been modified and it's not an insert",
"// (we always want to insert if no id exist, since some child objects might",
"// depend on the this primary id being available)",
"return",
"false",
";",
"}",
"}",
"// Check data",
"$",
"sqlData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dataToSave",
"as",
"$",
"propertyName",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"$",
"dbEntity",
"->",
"getDbPropertyMaxLength",
"(",
"$",
"propertyName",
")",
"&&",
"mb_strlen",
"(",
"$",
"value",
")",
">",
"$",
"dbEntity",
"->",
"getDbPropertyMaxLength",
"(",
"$",
"propertyName",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Database field \\\"{$propertyName}\\\" exceeds field max length (value: \\\"{$value}\\\")\"",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"dbEntity",
"->",
"getDbPropertyNonEmpty",
"(",
"$",
"propertyName",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Database field \\\"{$propertyName}\\\" is empty and required\"",
")",
";",
"}",
"elseif",
"(",
"(",
"(",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"(",
"(",
"string",
")",
"$",
"value",
")",
"===",
"''",
")",
"||",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"empty",
"(",
"$",
"value",
")",
")",
")",
"&&",
"$",
"dbEntity",
"->",
"getDbPropertyRequired",
"(",
"$",
"propertyName",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Database field \\\"{$propertyName}\\\" is required to be set\"",
")",
";",
"}",
"// Set data keys db field format",
"$",
"fieldName",
"=",
"$",
"dbEntity",
"->",
"getDbFieldName",
"(",
"$",
"propertyName",
")",
";",
"$",
"sqlData",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"value",
";",
"}",
"// Insert new database row",
"if",
"(",
"$",
"dbEntity",
"->",
"shouldInsertOnDbSave",
"(",
")",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"dbEntity",
"->",
"getDbTableName",
"(",
")",
",",
"$",
"sqlData",
")",
";",
"// Update entity with auto increment value",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dbEntity",
"->",
"getPrimaryDbPropertyKey",
"(",
")",
")",
"&&",
"!",
"empty",
"(",
"$",
"lastInsertId",
"=",
"$",
"this",
"->",
"db",
"->",
"getLastInsertId",
"(",
")",
")",
")",
"{",
"$",
"dbEntity",
"->",
"setPrimaryDbValue",
"(",
"$",
"lastInsertId",
")",
";",
"}",
"else",
"{",
"// For entities with for example string primary keys, we update primary value",
"// with value/values from db data, indicating that the entity is now",
"// in database/loaded.",
"$",
"dbEntity",
"->",
"updatePrimaryDbValueFromDbData",
"(",
")",
";",
"}",
"// Update existing database row",
"}",
"else",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"dbEntity",
"->",
"getDbTableName",
"(",
")",
",",
"$",
"sqlData",
",",
"$",
"this",
"->",
"getPrimaryKeyWhereSql",
"(",
"$",
"dbEntity",
")",
",",
"$",
"this",
"->",
"getPrimaryKeyWhereParameters",
"(",
"$",
"dbEntity",
")",
")",
";",
"}",
"$",
"dbEntity",
"->",
"clearModifiedDbProperties",
"(",
")",
";",
"$",
"dbEntity",
"->",
"setForceDbInsertOnSave",
"(",
"false",
")",
";",
"return",
"true",
";",
"}"
] | Save entity to database table.
@param AbstractDbEntity $dbEntity
@return bool | [
"Save",
"entity",
"to",
"database",
"table",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/BasicDbEntityService.php#L76-L158 |
31,325 | starweb/starlit-db | src/BasicDbEntityService.php | BasicDbEntityService.delete | public function delete(AbstractDbEntity $dbEntity)
{
if (!$dbEntity->getPrimaryDbValue()) {
throw new \InvalidArgumentException('Primary database value not set');
}
$this->db->exec(
'DELETE FROM `' . $dbEntity->getDbTableName() . '` WHERE ' . $this->getPrimaryKeyWhereSql($dbEntity),
$this->getPrimaryKeyWhereParameters($dbEntity)
);
$dbEntity->setDeleted();
} | php | public function delete(AbstractDbEntity $dbEntity)
{
if (!$dbEntity->getPrimaryDbValue()) {
throw new \InvalidArgumentException('Primary database value not set');
}
$this->db->exec(
'DELETE FROM `' . $dbEntity->getDbTableName() . '` WHERE ' . $this->getPrimaryKeyWhereSql($dbEntity),
$this->getPrimaryKeyWhereParameters($dbEntity)
);
$dbEntity->setDeleted();
} | [
"public",
"function",
"delete",
"(",
"AbstractDbEntity",
"$",
"dbEntity",
")",
"{",
"if",
"(",
"!",
"$",
"dbEntity",
"->",
"getPrimaryDbValue",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Primary database value not set'",
")",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"exec",
"(",
"'DELETE FROM `'",
".",
"$",
"dbEntity",
"->",
"getDbTableName",
"(",
")",
".",
"'` WHERE '",
".",
"$",
"this",
"->",
"getPrimaryKeyWhereSql",
"(",
"$",
"dbEntity",
")",
",",
"$",
"this",
"->",
"getPrimaryKeyWhereParameters",
"(",
"$",
"dbEntity",
")",
")",
";",
"$",
"dbEntity",
"->",
"setDeleted",
"(",
")",
";",
"}"
] | Delete entity's corresponding database row.
@param AbstractDbEntity $dbEntity | [
"Delete",
"entity",
"s",
"corresponding",
"database",
"row",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/BasicDbEntityService.php#L165-L177 |
31,326 | gdbots/ncr-php | src/Repository/DynamoDb/BatchGetItemRequest.php | BatchGetItemRequest.addItemKey | public function addItemKey(string $table, array $key): self
{
$this->queue[] = ['table' => $table, 'key' => $key];
return $this;
} | php | public function addItemKey(string $table, array $key): self
{
$this->queue[] = ['table' => $table, 'key' => $key];
return $this;
} | [
"public",
"function",
"addItemKey",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"key",
")",
":",
"self",
"{",
"$",
"this",
"->",
"queue",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'key'",
"=>",
"$",
"key",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Adds an item key to get in this batch request.
@param string $table
@param array $key
@return self | [
"Adds",
"an",
"item",
"key",
"to",
"get",
"in",
"this",
"batch",
"request",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/BatchGetItemRequest.php#L116-L120 |
31,327 | gdbots/ncr-php | src/Repository/DynamoDb/BatchGetItemRequest.php | BatchGetItemRequest.getItems | public function getItems(): array
{
$allItems = [];
while ($this->queue) {
$commands = $this->prepareCommands();
$pool = new CommandPool($this->client, $commands, [
'concurrency' => $this->poolSize,
'fulfilled' => function (ResultInterface $result) use (&$allItems) {
if ($result->hasKey('UnprocessedKeys')) {
$this->retryUnprocessed($result['UnprocessedKeys']);
}
foreach ((array)$result->get('Responses') as $tableName => $items) {
$allItems = array_merge($allItems, $items);
}
},
'rejected' => function ($reason) {
if ($reason instanceof AwsException) {
if ('ProvisionedThroughputExceededException' === $reason->getAwsErrorCode()) {
$this->retryUnprocessed($reason->getCommand()['RequestItems']);
return;
}
if (is_callable($this->errorFunc)) {
$func = $this->errorFunc;
$func($reason);
}
}
},
]);
$pool->promise()->wait();
}
return $allItems;
} | php | public function getItems(): array
{
$allItems = [];
while ($this->queue) {
$commands = $this->prepareCommands();
$pool = new CommandPool($this->client, $commands, [
'concurrency' => $this->poolSize,
'fulfilled' => function (ResultInterface $result) use (&$allItems) {
if ($result->hasKey('UnprocessedKeys')) {
$this->retryUnprocessed($result['UnprocessedKeys']);
}
foreach ((array)$result->get('Responses') as $tableName => $items) {
$allItems = array_merge($allItems, $items);
}
},
'rejected' => function ($reason) {
if ($reason instanceof AwsException) {
if ('ProvisionedThroughputExceededException' === $reason->getAwsErrorCode()) {
$this->retryUnprocessed($reason->getCommand()['RequestItems']);
return;
}
if (is_callable($this->errorFunc)) {
$func = $this->errorFunc;
$func($reason);
}
}
},
]);
$pool->promise()->wait();
}
return $allItems;
} | [
"public",
"function",
"getItems",
"(",
")",
":",
"array",
"{",
"$",
"allItems",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"this",
"->",
"queue",
")",
"{",
"$",
"commands",
"=",
"$",
"this",
"->",
"prepareCommands",
"(",
")",
";",
"$",
"pool",
"=",
"new",
"CommandPool",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"commands",
",",
"[",
"'concurrency'",
"=>",
"$",
"this",
"->",
"poolSize",
",",
"'fulfilled'",
"=>",
"function",
"(",
"ResultInterface",
"$",
"result",
")",
"use",
"(",
"&",
"$",
"allItems",
")",
"{",
"if",
"(",
"$",
"result",
"->",
"hasKey",
"(",
"'UnprocessedKeys'",
")",
")",
"{",
"$",
"this",
"->",
"retryUnprocessed",
"(",
"$",
"result",
"[",
"'UnprocessedKeys'",
"]",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"result",
"->",
"get",
"(",
"'Responses'",
")",
"as",
"$",
"tableName",
"=>",
"$",
"items",
")",
"{",
"$",
"allItems",
"=",
"array_merge",
"(",
"$",
"allItems",
",",
"$",
"items",
")",
";",
"}",
"}",
",",
"'rejected'",
"=>",
"function",
"(",
"$",
"reason",
")",
"{",
"if",
"(",
"$",
"reason",
"instanceof",
"AwsException",
")",
"{",
"if",
"(",
"'ProvisionedThroughputExceededException'",
"===",
"$",
"reason",
"->",
"getAwsErrorCode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"retryUnprocessed",
"(",
"$",
"reason",
"->",
"getCommand",
"(",
")",
"[",
"'RequestItems'",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"errorFunc",
")",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"errorFunc",
";",
"$",
"func",
"(",
"$",
"reason",
")",
";",
"}",
"}",
"}",
",",
"]",
")",
";",
"$",
"pool",
"->",
"promise",
"(",
")",
"->",
"wait",
"(",
")",
";",
"}",
"return",
"$",
"allItems",
";",
"}"
] | Processes the batch by combining all the queued requests into
BatchGetItem commands and executing them. UnprocessedKeys
are automatically re-queued.
@return array | [
"Processes",
"the",
"batch",
"by",
"combining",
"all",
"the",
"queued",
"requests",
"into",
"BatchGetItem",
"commands",
"and",
"executing",
"them",
".",
"UnprocessedKeys",
"are",
"automatically",
"re",
"-",
"queued",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/BatchGetItemRequest.php#L129-L165 |
31,328 | gdbots/ncr-php | src/Repository/DynamoDb/BatchGetItemRequest.php | BatchGetItemRequest.prepareCommands | private function prepareCommands(): array
{
$batches = array_chunk($this->queue, $this->batchSize);
$this->queue = [];
$commands = [];
foreach ($batches as $batch) {
$requests = [];
foreach ($batch as $item) {
if (!isset($requests[$item['table']])) {
$requests[$item['table']] = ['Keys' => [], 'ConsistentRead' => $this->consistentRead];
}
$requests[$item['table']]['Keys'][] = $item['key'];
}
$commands[] = $this->client->getCommand('BatchGetItem', ['RequestItems' => $requests]);
}
return $commands;
} | php | private function prepareCommands(): array
{
$batches = array_chunk($this->queue, $this->batchSize);
$this->queue = [];
$commands = [];
foreach ($batches as $batch) {
$requests = [];
foreach ($batch as $item) {
if (!isset($requests[$item['table']])) {
$requests[$item['table']] = ['Keys' => [], 'ConsistentRead' => $this->consistentRead];
}
$requests[$item['table']]['Keys'][] = $item['key'];
}
$commands[] = $this->client->getCommand('BatchGetItem', ['RequestItems' => $requests]);
}
return $commands;
} | [
"private",
"function",
"prepareCommands",
"(",
")",
":",
"array",
"{",
"$",
"batches",
"=",
"array_chunk",
"(",
"$",
"this",
"->",
"queue",
",",
"$",
"this",
"->",
"batchSize",
")",
";",
"$",
"this",
"->",
"queue",
"=",
"[",
"]",
";",
"$",
"commands",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"batches",
"as",
"$",
"batch",
")",
"{",
"$",
"requests",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"batch",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"requests",
"[",
"$",
"item",
"[",
"'table'",
"]",
"]",
")",
")",
"{",
"$",
"requests",
"[",
"$",
"item",
"[",
"'table'",
"]",
"]",
"=",
"[",
"'Keys'",
"=>",
"[",
"]",
",",
"'ConsistentRead'",
"=>",
"$",
"this",
"->",
"consistentRead",
"]",
";",
"}",
"$",
"requests",
"[",
"$",
"item",
"[",
"'table'",
"]",
"]",
"[",
"'Keys'",
"]",
"[",
"]",
"=",
"$",
"item",
"[",
"'key'",
"]",
";",
"}",
"$",
"commands",
"[",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"getCommand",
"(",
"'BatchGetItem'",
",",
"[",
"'RequestItems'",
"=>",
"$",
"requests",
"]",
")",
";",
"}",
"return",
"$",
"commands",
";",
"}"
] | Creates BatchGetItem commands from the items in the queue.
@return CommandInterface[] | [
"Creates",
"BatchGetItem",
"commands",
"from",
"the",
"items",
"in",
"the",
"queue",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/BatchGetItemRequest.php#L172-L190 |
31,329 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.checkStaticProperties | private static function checkStaticProperties()
{
static $checkedClasses = [];
if (!in_array(static::class, $checkedClasses)) {
if (empty(static::$dbTableName)
|| empty(static::$dbProperties)
|| empty(static::$primaryDbPropertyKey)
|| (is_scalar(static::$primaryDbPropertyKey)
&& !isset(static::$dbProperties[static::$primaryDbPropertyKey]['type']))
|| (is_array(static::$primaryDbPropertyKey)
&& !Arr::allIn(static::$primaryDbPropertyKey, array_keys(static::$dbProperties)))
) {
throw new \LogicException("All db entity's static properties not set");
}
$checkedClasses[] = static::class;
}
} | php | private static function checkStaticProperties()
{
static $checkedClasses = [];
if (!in_array(static::class, $checkedClasses)) {
if (empty(static::$dbTableName)
|| empty(static::$dbProperties)
|| empty(static::$primaryDbPropertyKey)
|| (is_scalar(static::$primaryDbPropertyKey)
&& !isset(static::$dbProperties[static::$primaryDbPropertyKey]['type']))
|| (is_array(static::$primaryDbPropertyKey)
&& !Arr::allIn(static::$primaryDbPropertyKey, array_keys(static::$dbProperties)))
) {
throw new \LogicException("All db entity's static properties not set");
}
$checkedClasses[] = static::class;
}
} | [
"private",
"static",
"function",
"checkStaticProperties",
"(",
")",
"{",
"static",
"$",
"checkedClasses",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"static",
"::",
"class",
",",
"$",
"checkedClasses",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"dbTableName",
")",
"||",
"empty",
"(",
"static",
"::",
"$",
"dbProperties",
")",
"||",
"empty",
"(",
"static",
"::",
"$",
"primaryDbPropertyKey",
")",
"||",
"(",
"is_scalar",
"(",
"static",
"::",
"$",
"primaryDbPropertyKey",
")",
"&&",
"!",
"isset",
"(",
"static",
"::",
"$",
"dbProperties",
"[",
"static",
"::",
"$",
"primaryDbPropertyKey",
"]",
"[",
"'type'",
"]",
")",
")",
"||",
"(",
"is_array",
"(",
"static",
"::",
"$",
"primaryDbPropertyKey",
")",
"&&",
"!",
"Arr",
"::",
"allIn",
"(",
"static",
"::",
"$",
"primaryDbPropertyKey",
",",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"All db entity's static properties not set\"",
")",
";",
"}",
"$",
"checkedClasses",
"[",
"]",
"=",
"static",
"::",
"class",
";",
"}",
"}"
] | Make sure that class has all necessary static properties set. | [
"Make",
"sure",
"that",
"class",
"has",
"all",
"necessary",
"static",
"properties",
"set",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L142-L158 |
31,330 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.getDefaultDbData | public function getDefaultDbData()
{
$class = get_called_class();
if (!isset(self::$cachedDefaultDbData[$class])) {
self::$cachedDefaultDbData[$class] = [];
foreach (array_keys(static::$dbProperties) as $propertyName) {
self::$cachedDefaultDbData[$class][$propertyName] = $this->getDefaultDbPropertyValue($propertyName);
}
}
return self::$cachedDefaultDbData[$class];
} | php | public function getDefaultDbData()
{
$class = get_called_class();
if (!isset(self::$cachedDefaultDbData[$class])) {
self::$cachedDefaultDbData[$class] = [];
foreach (array_keys(static::$dbProperties) as $propertyName) {
self::$cachedDefaultDbData[$class][$propertyName] = $this->getDefaultDbPropertyValue($propertyName);
}
}
return self::$cachedDefaultDbData[$class];
} | [
"public",
"function",
"getDefaultDbData",
"(",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"cachedDefaultDbData",
"[",
"$",
"class",
"]",
")",
")",
"{",
"self",
"::",
"$",
"cachedDefaultDbData",
"[",
"$",
"class",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
"as",
"$",
"propertyName",
")",
"{",
"self",
"::",
"$",
"cachedDefaultDbData",
"[",
"$",
"class",
"]",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"this",
"->",
"getDefaultDbPropertyValue",
"(",
"$",
"propertyName",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"cachedDefaultDbData",
"[",
"$",
"class",
"]",
";",
"}"
] | Get all default database values.
@return array | [
"Get",
"all",
"default",
"database",
"values",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L179-L190 |
31,331 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.updatePrimaryDbValueFromDbData | public function updatePrimaryDbValueFromDbData()
{
$dbDataPrimaryValue = $this->getDbDataPrimaryValue();
if ($dbDataPrimaryValue !== $this->getDbDataPrimaryDefaultValue()) {
$this->setPrimaryDbValue($dbDataPrimaryValue);
}
} | php | public function updatePrimaryDbValueFromDbData()
{
$dbDataPrimaryValue = $this->getDbDataPrimaryValue();
if ($dbDataPrimaryValue !== $this->getDbDataPrimaryDefaultValue()) {
$this->setPrimaryDbValue($dbDataPrimaryValue);
}
} | [
"public",
"function",
"updatePrimaryDbValueFromDbData",
"(",
")",
"{",
"$",
"dbDataPrimaryValue",
"=",
"$",
"this",
"->",
"getDbDataPrimaryValue",
"(",
")",
";",
"if",
"(",
"$",
"dbDataPrimaryValue",
"!==",
"$",
"this",
"->",
"getDbDataPrimaryDefaultValue",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setPrimaryDbValue",
"(",
"$",
"dbDataPrimaryValue",
")",
";",
"}",
"}"
] | Update primary database value with data from set database data. | [
"Update",
"primary",
"database",
"value",
"with",
"data",
"from",
"set",
"database",
"data",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L254-L261 |
31,332 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.setDbValue | protected function setDbValue($property, $value, $setAsModified = true, $force = false)
{
$value = $this->getValueWithPropertyType($property, $value);
if ($this->dbData[$property] !== $value || $force) {
$this->dbData[$property] = $value;
if ($setAsModified && !$this->isDbPropertyModified($property)) {
$this->modifiedDbProperties[] = $property;
}
}
} | php | protected function setDbValue($property, $value, $setAsModified = true, $force = false)
{
$value = $this->getValueWithPropertyType($property, $value);
if ($this->dbData[$property] !== $value || $force) {
$this->dbData[$property] = $value;
if ($setAsModified && !$this->isDbPropertyModified($property)) {
$this->modifiedDbProperties[] = $property;
}
}
} | [
"protected",
"function",
"setDbValue",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"setAsModified",
"=",
"true",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValueWithPropertyType",
"(",
"$",
"property",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dbData",
"[",
"$",
"property",
"]",
"!==",
"$",
"value",
"||",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"dbData",
"[",
"$",
"property",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"setAsModified",
"&&",
"!",
"$",
"this",
"->",
"isDbPropertyModified",
"(",
"$",
"property",
")",
")",
"{",
"$",
"this",
"->",
"modifiedDbProperties",
"[",
"]",
"=",
"$",
"property",
";",
"}",
"}",
"}"
] | Set a row field value.
@param string $property
@param mixed $value
@param bool $setAsModified
@param bool $force | [
"Set",
"a",
"row",
"field",
"value",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L329-L340 |
31,333 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.setDbData | public function setDbData(array $data)
{
foreach (array_keys(static::$dbProperties) as $propertyName) {
if (array_key_exists($propertyName, $data)) {
$this->setDbValue($propertyName, $data[$propertyName], true);
}
}
} | php | public function setDbData(array $data)
{
foreach (array_keys(static::$dbProperties) as $propertyName) {
if (array_key_exists($propertyName, $data)) {
$this->setDbValue($propertyName, $data[$propertyName], true);
}
}
} | [
"public",
"function",
"setDbData",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
"as",
"$",
"propertyName",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"setDbValue",
"(",
"$",
"propertyName",
",",
"$",
"data",
"[",
"$",
"propertyName",
"]",
",",
"true",
")",
";",
"}",
"}",
"}"
] | Set database fields' data.
@param array $data | [
"Set",
"database",
"fields",
"data",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L548-L555 |
31,334 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.setDbDataFromRow | public function setDbDataFromRow(array $rowData)
{
// If there are less row data than properties, use rows as starting point (optimization)
if (count($rowData) < count(static::$dbProperties)) {
foreach ($rowData as $dbFieldName => $value) {
$propertyName = static::getDbPropertyName($dbFieldName);
if (isset(static::$dbProperties[$propertyName])) {
$this->setDbValue($propertyName, $value, false);
}
}
// If there are more row data than properties, use properties as starting point
} else {
foreach (array_keys(static::$dbProperties) as $propertyName) {
$fieldName = static::getDbFieldName($propertyName);
if (array_key_exists($fieldName, $rowData)) {
$this->setDbValue($propertyName, $rowData[$fieldName], false);
}
}
}
$this->updatePrimaryDbValueFromDbData();
} | php | public function setDbDataFromRow(array $rowData)
{
// If there are less row data than properties, use rows as starting point (optimization)
if (count($rowData) < count(static::$dbProperties)) {
foreach ($rowData as $dbFieldName => $value) {
$propertyName = static::getDbPropertyName($dbFieldName);
if (isset(static::$dbProperties[$propertyName])) {
$this->setDbValue($propertyName, $value, false);
}
}
// If there are more row data than properties, use properties as starting point
} else {
foreach (array_keys(static::$dbProperties) as $propertyName) {
$fieldName = static::getDbFieldName($propertyName);
if (array_key_exists($fieldName, $rowData)) {
$this->setDbValue($propertyName, $rowData[$fieldName], false);
}
}
}
$this->updatePrimaryDbValueFromDbData();
} | [
"public",
"function",
"setDbDataFromRow",
"(",
"array",
"$",
"rowData",
")",
"{",
"// If there are less row data than properties, use rows as starting point (optimization)",
"if",
"(",
"count",
"(",
"$",
"rowData",
")",
"<",
"count",
"(",
"static",
"::",
"$",
"dbProperties",
")",
")",
"{",
"foreach",
"(",
"$",
"rowData",
"as",
"$",
"dbFieldName",
"=>",
"$",
"value",
")",
"{",
"$",
"propertyName",
"=",
"static",
"::",
"getDbPropertyName",
"(",
"$",
"dbFieldName",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"dbProperties",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDbValue",
"(",
"$",
"propertyName",
",",
"$",
"value",
",",
"false",
")",
";",
"}",
"}",
"// If there are more row data than properties, use properties as starting point",
"}",
"else",
"{",
"foreach",
"(",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"fieldName",
"=",
"static",
"::",
"getDbFieldName",
"(",
"$",
"propertyName",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"rowData",
")",
")",
"{",
"$",
"this",
"->",
"setDbValue",
"(",
"$",
"propertyName",
",",
"$",
"rowData",
"[",
"$",
"fieldName",
"]",
",",
"false",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"updatePrimaryDbValueFromDbData",
"(",
")",
";",
"}"
] | Set db data from raw database row data with field names in database format.
@param array $rowData | [
"Set",
"db",
"data",
"from",
"raw",
"database",
"row",
"data",
"with",
"field",
"names",
"in",
"database",
"format",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L562-L583 |
31,335 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.getDbPropertyNames | public static function getDbPropertyNames(array $exclude = [])
{
$dbPropertyNames = array_keys(static::$dbProperties);
return $exclude ? array_diff($dbPropertyNames, $exclude) : $dbPropertyNames;
} | php | public static function getDbPropertyNames(array $exclude = [])
{
$dbPropertyNames = array_keys(static::$dbProperties);
return $exclude ? array_diff($dbPropertyNames, $exclude) : $dbPropertyNames;
} | [
"public",
"static",
"function",
"getDbPropertyNames",
"(",
"array",
"$",
"exclude",
"=",
"[",
"]",
")",
"{",
"$",
"dbPropertyNames",
"=",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
";",
"return",
"$",
"exclude",
"?",
"array_diff",
"(",
"$",
"dbPropertyNames",
",",
"$",
"exclude",
")",
":",
"$",
"dbPropertyNames",
";",
"}"
] | Return array with db property names.
@param array $exclude
@return array | [
"Return",
"array",
"with",
"db",
"property",
"names",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L767-L772 |
31,336 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.getDbFieldNames | public static function getDbFieldNames(array $exclude = [])
{
$fieldNames = [];
foreach (array_keys(static::$dbProperties) as $propertyName) {
$fieldNames[] = static::getDbFieldName($propertyName);
}
return $exclude ? array_diff($fieldNames, $exclude) : $fieldNames;
} | php | public static function getDbFieldNames(array $exclude = [])
{
$fieldNames = [];
foreach (array_keys(static::$dbProperties) as $propertyName) {
$fieldNames[] = static::getDbFieldName($propertyName);
}
return $exclude ? array_diff($fieldNames, $exclude) : $fieldNames;
} | [
"public",
"static",
"function",
"getDbFieldNames",
"(",
"array",
"$",
"exclude",
"=",
"[",
"]",
")",
"{",
"$",
"fieldNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"static",
"::",
"$",
"dbProperties",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"fieldNames",
"[",
"]",
"=",
"static",
"::",
"getDbFieldName",
"(",
"$",
"propertyName",
")",
";",
"}",
"return",
"$",
"exclude",
"?",
"array_diff",
"(",
"$",
"fieldNames",
",",
"$",
"exclude",
")",
":",
"$",
"fieldNames",
";",
"}"
] | Return array with raw db field names.
@param array $exclude
@return array | [
"Return",
"array",
"with",
"raw",
"db",
"field",
"names",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L780-L788 |
31,337 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.filterStripDbRowData | public static function filterStripDbRowData(array $rowData, $dbTableAlias, $skipStrip = false)
{
$columnPrefix = $dbTableAlias . '_';
$filteredAndStrippedRowData = [];
foreach ($rowData as $key => $val) {
if (strpos($key, $columnPrefix) === 0) {
$strippedKey = $skipStrip ? $key : Str::stripLeft($key, $columnPrefix);
$filteredAndStrippedRowData[$strippedKey] = $val;
}
}
return $filteredAndStrippedRowData;
} | php | public static function filterStripDbRowData(array $rowData, $dbTableAlias, $skipStrip = false)
{
$columnPrefix = $dbTableAlias . '_';
$filteredAndStrippedRowData = [];
foreach ($rowData as $key => $val) {
if (strpos($key, $columnPrefix) === 0) {
$strippedKey = $skipStrip ? $key : Str::stripLeft($key, $columnPrefix);
$filteredAndStrippedRowData[$strippedKey] = $val;
}
}
return $filteredAndStrippedRowData;
} | [
"public",
"static",
"function",
"filterStripDbRowData",
"(",
"array",
"$",
"rowData",
",",
"$",
"dbTableAlias",
",",
"$",
"skipStrip",
"=",
"false",
")",
"{",
"$",
"columnPrefix",
"=",
"$",
"dbTableAlias",
".",
"'_'",
";",
"$",
"filteredAndStrippedRowData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rowData",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"$",
"columnPrefix",
")",
"===",
"0",
")",
"{",
"$",
"strippedKey",
"=",
"$",
"skipStrip",
"?",
"$",
"key",
":",
"Str",
"::",
"stripLeft",
"(",
"$",
"key",
",",
"$",
"columnPrefix",
")",
";",
"$",
"filteredAndStrippedRowData",
"[",
"$",
"strippedKey",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"filteredAndStrippedRowData",
";",
"}"
] | Filters a full db item array by it's table alias and the strips the table alias.
@param array $rowData
@param string $dbTableAlias
@param bool $skipStrip For cases when you want to filter only (no stripping)
@return array | [
"Filters",
"a",
"full",
"db",
"item",
"array",
"by",
"it",
"s",
"table",
"alias",
"and",
"the",
"strips",
"the",
"table",
"alias",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L830-L843 |
31,338 | starweb/starlit-db | src/AbstractDbEntity.php | AbstractDbEntity.unserialize | public function unserialize($serializedObject)
{
$objectVars = unserialize($serializedObject);
foreach ($objectVars as $key => $value) {
$this->{$key} = $value;
}
} | php | public function unserialize($serializedObject)
{
$objectVars = unserialize($serializedObject);
foreach ($objectVars as $key => $value) {
$this->{$key} = $value;
}
} | [
"public",
"function",
"unserialize",
"(",
"$",
"serializedObject",
")",
"{",
"$",
"objectVars",
"=",
"unserialize",
"(",
"$",
"serializedObject",
")",
";",
"foreach",
"(",
"$",
"objectVars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"}"
] | Method to handle the unserialization of this object.
Implementation of Serializable interface. If descendant private properties
should be unserialized, they need to be visible to this parent (i.e. not private).
@param string $serializedObject | [
"Method",
"to",
"handle",
"the",
"unserialization",
"of",
"this",
"object",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntity.php#L874-L881 |
31,339 | gdbots/ncr-php | src/AbstractNodeCommandHandler.php | AbstractNodeCommandHandler.createEventFromCommand | protected function createEventFromCommand(Command $command, string $suffix): Event
{
/** @var NodeRef $nodeRef */
$nodeRef = $command->get('node_ref') ?: NodeRef::fromNode($command->get('node'));
$curie = $command::schema()->getCurie();
$eventCurie = "{$curie->getVendor()}:{$curie->getPackage()}:event:{$nodeRef->getLabel()}-{$suffix}";
/** @var Event $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString($eventCurie));
return $class::create();
} | php | protected function createEventFromCommand(Command $command, string $suffix): Event
{
/** @var NodeRef $nodeRef */
$nodeRef = $command->get('node_ref') ?: NodeRef::fromNode($command->get('node'));
$curie = $command::schema()->getCurie();
$eventCurie = "{$curie->getVendor()}:{$curie->getPackage()}:event:{$nodeRef->getLabel()}-{$suffix}";
/** @var Event $class */
$class = MessageResolver::resolveCurie(SchemaCurie::fromString($eventCurie));
return $class::create();
} | [
"protected",
"function",
"createEventFromCommand",
"(",
"Command",
"$",
"command",
",",
"string",
"$",
"suffix",
")",
":",
"Event",
"{",
"/** @var NodeRef $nodeRef */",
"$",
"nodeRef",
"=",
"$",
"command",
"->",
"get",
"(",
"'node_ref'",
")",
"?",
":",
"NodeRef",
"::",
"fromNode",
"(",
"$",
"command",
"->",
"get",
"(",
"'node'",
")",
")",
";",
"$",
"curie",
"=",
"$",
"command",
"::",
"schema",
"(",
")",
"->",
"getCurie",
"(",
")",
";",
"$",
"eventCurie",
"=",
"\"{$curie->getVendor()}:{$curie->getPackage()}:event:{$nodeRef->getLabel()}-{$suffix}\"",
";",
"/** @var Event $class */",
"$",
"class",
"=",
"MessageResolver",
"::",
"resolveCurie",
"(",
"SchemaCurie",
"::",
"fromString",
"(",
"$",
"eventCurie",
")",
")",
";",
"return",
"$",
"class",
"::",
"create",
"(",
")",
";",
"}"
] | 90% of the time this works 100% of the time. When events for common
node operations match the convention of "blah-suffix" you can use
this method to save some typing. It's always optional.
@param Command $command
@param string $suffix
@return Event | [
"90%",
"of",
"the",
"time",
"this",
"works",
"100%",
"of",
"the",
"time",
".",
"When",
"events",
"for",
"common",
"node",
"operations",
"match",
"the",
"convention",
"of",
"blah",
"-",
"suffix",
"you",
"can",
"use",
"this",
"method",
"to",
"save",
"some",
"typing",
".",
"It",
"s",
"always",
"optional",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/AbstractNodeCommandHandler.php#L58-L68 |
31,340 | gdbots/ncr-php | src/NcrLazyLoader.php | NcrLazyLoader.hasNodeRef | public function hasNodeRef(NodeRef $nodeRef): bool
{
if (null === $this->getNodeBatchRequest) {
return false;
}
return $this->getNodeBatchRequest->isInSet('node_refs', $nodeRef);
} | php | public function hasNodeRef(NodeRef $nodeRef): bool
{
if (null === $this->getNodeBatchRequest) {
return false;
}
return $this->getNodeBatchRequest->isInSet('node_refs', $nodeRef);
} | [
"public",
"function",
"hasNodeRef",
"(",
"NodeRef",
"$",
"nodeRef",
")",
":",
"bool",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getNodeBatchRequest",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getNodeBatchRequest",
"->",
"isInSet",
"(",
"'node_refs'",
",",
"$",
"nodeRef",
")",
";",
"}"
] | Returns true if the given NodeRef is in the pending lazy load request.
@param NodeRef $nodeRef
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"NodeRef",
"is",
"in",
"the",
"pending",
"lazy",
"load",
"request",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrLazyLoader.php#L45-L52 |
31,341 | gdbots/ncr-php | src/NcrLazyLoader.php | NcrLazyLoader.removeNodeRefs | public function removeNodeRefs(array $nodeRefs): void
{
if (null === $this->getNodeBatchRequest) {
return;
}
$this->getNodeBatchRequest->removeFromSet('node_refs', $nodeRefs);
} | php | public function removeNodeRefs(array $nodeRefs): void
{
if (null === $this->getNodeBatchRequest) {
return;
}
$this->getNodeBatchRequest->removeFromSet('node_refs', $nodeRefs);
} | [
"public",
"function",
"removeNodeRefs",
"(",
"array",
"$",
"nodeRefs",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getNodeBatchRequest",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"getNodeBatchRequest",
"->",
"removeFromSet",
"(",
"'node_refs'",
",",
"$",
"nodeRefs",
")",
";",
"}"
] | Removes an array of NodeRefs from the deferrered request.
@param NodeRef[] $nodeRefs | [
"Removes",
"an",
"array",
"of",
"NodeRefs",
"from",
"the",
"deferrered",
"request",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrLazyLoader.php#L138-L145 |
31,342 | gdbots/ncr-php | src/NcrLazyLoader.php | NcrLazyLoader.flush | public function flush(): void
{
if (null === $this->getNodeBatchRequest) {
return;
}
if (!$this->getNodeBatchRequest->has('node_refs')) {
return;
}
try {
$request = $this->getNodeBatchRequest;
$this->getNodeBatchRequest = null;
$this->pbjx->request($request);
} catch (\Throwable $e) {
$this->logger->error(
sprintf('%s::NcrLazyLoader::flush() could not complete.', ClassUtils::getShortName($e)),
['exception' => $e, 'pbj' => $request->toArray()]
);
}
} | php | public function flush(): void
{
if (null === $this->getNodeBatchRequest) {
return;
}
if (!$this->getNodeBatchRequest->has('node_refs')) {
return;
}
try {
$request = $this->getNodeBatchRequest;
$this->getNodeBatchRequest = null;
$this->pbjx->request($request);
} catch (\Throwable $e) {
$this->logger->error(
sprintf('%s::NcrLazyLoader::flush() could not complete.', ClassUtils::getShortName($e)),
['exception' => $e, 'pbj' => $request->toArray()]
);
}
} | [
"public",
"function",
"flush",
"(",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"getNodeBatchRequest",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getNodeBatchRequest",
"->",
"has",
"(",
"'node_refs'",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getNodeBatchRequest",
";",
"$",
"this",
"->",
"getNodeBatchRequest",
"=",
"null",
";",
"$",
"this",
"->",
"pbjx",
"->",
"request",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"sprintf",
"(",
"'%s::NcrLazyLoader::flush() could not complete.'",
",",
"ClassUtils",
"::",
"getShortName",
"(",
"$",
"e",
")",
")",
",",
"[",
"'exception'",
"=>",
"$",
"e",
",",
"'pbj'",
"=>",
"$",
"request",
"->",
"toArray",
"(",
")",
"]",
")",
";",
"}",
"}"
] | Processes the deferrered request which should populate the
NcrCache once complete. At least for any nodes that exist. | [
"Processes",
"the",
"deferrered",
"request",
"which",
"should",
"populate",
"the",
"NcrCache",
"once",
"complete",
".",
"At",
"least",
"for",
"any",
"nodes",
"that",
"exist",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrLazyLoader.php#L159-L179 |
31,343 | gdbots/ncr-php | src/Search/Elastica/QueryFactory.php | QueryFactory.filterStatuses | protected function filterStatuses(SearchNodesRequest $request, Query\BoolQuery $query): void
{
if (!$request->has('statuses')) {
return;
}
$statuses = array_map('strval', $request->get('statuses'));
$query->addFilter(new Query\Terms('status', $statuses));
} | php | protected function filterStatuses(SearchNodesRequest $request, Query\BoolQuery $query): void
{
if (!$request->has('statuses')) {
return;
}
$statuses = array_map('strval', $request->get('statuses'));
$query->addFilter(new Query\Terms('status', $statuses));
} | [
"protected",
"function",
"filterStatuses",
"(",
"SearchNodesRequest",
"$",
"request",
",",
"Query",
"\\",
"BoolQuery",
"$",
"query",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"request",
"->",
"has",
"(",
"'statuses'",
")",
")",
"{",
"return",
";",
"}",
"$",
"statuses",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"request",
"->",
"get",
"(",
"'statuses'",
")",
")",
";",
"$",
"query",
"->",
"addFilter",
"(",
"new",
"Query",
"\\",
"Terms",
"(",
"'status'",
",",
"$",
"statuses",
")",
")",
";",
"}"
] | Add the "statuses" into one terms query as it's more efficient.
@link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
@param SearchNodesRequest $request
@param Query\BoolQuery $query | [
"Add",
"the",
"statuses",
"into",
"one",
"terms",
"query",
"as",
"it",
"s",
"more",
"efficient",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Search/Elastica/QueryFactory.php#L65-L73 |
31,344 | gdbots/ncr-php | src/NcrRequestInterceptor.php | NcrRequestInterceptor.enrichGetNodeRequest | public function enrichGetNodeRequest(PbjxEvent $pbjxEvent): void
{
$request = $pbjxEvent->getMessage();
if ($request->has('node_ref')
|| $request->get('consistent_read')
|| !$request->has('qname')
|| !$request->has('slug')
) {
return;
}
$qname = SchemaQName::fromString($request->get('qname'));
$cacheKey = $this->getSlugCacheKey($qname, $request->get('slug'));
$cacheItem = $this->cache->getItem($cacheKey);
if (!$cacheItem->isHit()) {
$this->cacheItems[$cacheKey] = $cacheItem;
return;
}
try {
$nodeRef = NodeRef::fromString($cacheItem->get());
if ($nodeRef->getQName() === $qname) {
$request->set('node_ref', $nodeRef);
}
} catch (\Throwable $e) {
}
} | php | public function enrichGetNodeRequest(PbjxEvent $pbjxEvent): void
{
$request = $pbjxEvent->getMessage();
if ($request->has('node_ref')
|| $request->get('consistent_read')
|| !$request->has('qname')
|| !$request->has('slug')
) {
return;
}
$qname = SchemaQName::fromString($request->get('qname'));
$cacheKey = $this->getSlugCacheKey($qname, $request->get('slug'));
$cacheItem = $this->cache->getItem($cacheKey);
if (!$cacheItem->isHit()) {
$this->cacheItems[$cacheKey] = $cacheItem;
return;
}
try {
$nodeRef = NodeRef::fromString($cacheItem->get());
if ($nodeRef->getQName() === $qname) {
$request->set('node_ref', $nodeRef);
}
} catch (\Throwable $e) {
}
} | [
"public",
"function",
"enrichGetNodeRequest",
"(",
"PbjxEvent",
"$",
"pbjxEvent",
")",
":",
"void",
"{",
"$",
"request",
"=",
"$",
"pbjxEvent",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"has",
"(",
"'node_ref'",
")",
"||",
"$",
"request",
"->",
"get",
"(",
"'consistent_read'",
")",
"||",
"!",
"$",
"request",
"->",
"has",
"(",
"'qname'",
")",
"||",
"!",
"$",
"request",
"->",
"has",
"(",
"'slug'",
")",
")",
"{",
"return",
";",
"}",
"$",
"qname",
"=",
"SchemaQName",
"::",
"fromString",
"(",
"$",
"request",
"->",
"get",
"(",
"'qname'",
")",
")",
";",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"getSlugCacheKey",
"(",
"$",
"qname",
",",
"$",
"request",
"->",
"get",
"(",
"'slug'",
")",
")",
";",
"$",
"cacheItem",
"=",
"$",
"this",
"->",
"cache",
"->",
"getItem",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"!",
"$",
"cacheItem",
"->",
"isHit",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cacheItems",
"[",
"$",
"cacheKey",
"]",
"=",
"$",
"cacheItem",
";",
"return",
";",
"}",
"try",
"{",
"$",
"nodeRef",
"=",
"NodeRef",
"::",
"fromString",
"(",
"$",
"cacheItem",
"->",
"get",
"(",
")",
")",
";",
"if",
"(",
"$",
"nodeRef",
"->",
"getQName",
"(",
")",
"===",
"$",
"qname",
")",
"{",
"$",
"request",
"->",
"set",
"(",
"'node_ref'",
",",
"$",
"nodeRef",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"}",
"}"
] | Enrich the request with a node_ref if possible to minimize
the number of lookups against the slug secondary index.
@param PbjxEvent $pbjxEvent | [
"Enrich",
"the",
"request",
"with",
"a",
"node_ref",
"if",
"possible",
"to",
"minimize",
"the",
"number",
"of",
"lookups",
"against",
"the",
"slug",
"secondary",
"index",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrRequestInterceptor.php#L72-L99 |
31,345 | gdbots/ncr-php | src/NcrCache.php | NcrCache.pruneNodeCache | private function pruneNodeCache(): void
{
if ($this->maxItems > 0 && count($this->nodes) > $this->maxItems) {
$this->nodes = array_slice($this->nodes, (int)($this->maxItems * 0.2), null, true);
}
} | php | private function pruneNodeCache(): void
{
if ($this->maxItems > 0 && count($this->nodes) > $this->maxItems) {
$this->nodes = array_slice($this->nodes, (int)($this->maxItems * 0.2), null, true);
}
} | [
"private",
"function",
"pruneNodeCache",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"maxItems",
">",
"0",
"&&",
"count",
"(",
"$",
"this",
"->",
"nodes",
")",
">",
"$",
"this",
"->",
"maxItems",
")",
"{",
"$",
"this",
"->",
"nodes",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"nodes",
",",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"maxItems",
"*",
"0.2",
")",
",",
"null",
",",
"true",
")",
";",
"}",
"}"
] | Prunes node cache by removing 20% of the cache if it is full. | [
"Prunes",
"node",
"cache",
"by",
"removing",
"20%",
"of",
"the",
"cache",
"if",
"it",
"is",
"full",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrCache.php#L220-L225 |
31,346 | starweb/starlit-db | src/Db.php | Db.executeQuery | protected function executeQuery($sql, array $parameters = [])
{
$this->connect();
$dbParameters = $this->prepareParameters($parameters);
try {
$pdoStatement = $this->pdo->prepare($sql);
$pdoStatement->execute($dbParameters);
return $pdoStatement;
} catch (PDOException $e) {
throw new QueryException($e, $sql, $dbParameters);
}
} | php | protected function executeQuery($sql, array $parameters = [])
{
$this->connect();
$dbParameters = $this->prepareParameters($parameters);
try {
$pdoStatement = $this->pdo->prepare($sql);
$pdoStatement->execute($dbParameters);
return $pdoStatement;
} catch (PDOException $e) {
throw new QueryException($e, $sql, $dbParameters);
}
} | [
"protected",
"function",
"executeQuery",
"(",
"$",
"sql",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"dbParameters",
"=",
"$",
"this",
"->",
"prepareParameters",
"(",
"$",
"parameters",
")",
";",
"try",
"{",
"$",
"pdoStatement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"pdoStatement",
"->",
"execute",
"(",
"$",
"dbParameters",
")",
";",
"return",
"$",
"pdoStatement",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"QueryException",
"(",
"$",
"e",
",",
"$",
"sql",
",",
"$",
"dbParameters",
")",
";",
"}",
"}"
] | Creates and executes a PDO statement.
@param string $sql
@param array $parameters
@return PDOStatement | [
"Creates",
"and",
"executes",
"a",
"PDO",
"statement",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L189-L202 |
31,347 | starweb/starlit-db | src/Db.php | Db.exec | public function exec($sql, array $parameters = [])
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->rowCount();
} | php | public function exec($sql, array $parameters = [])
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->rowCount();
} | [
"public",
"function",
"exec",
"(",
"$",
"sql",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"sql",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"statement",
"->",
"rowCount",
"(",
")",
";",
"}"
] | Execute an SQL statement and return the number of affected rows.
@param string $sql
@param array $parameters
@return int The number of rows affected | [
"Execute",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"number",
"of",
"affected",
"rows",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L211-L216 |
31,348 | starweb/starlit-db | src/Db.php | Db.fetchRow | public function fetchRow($sql, array $parameters = [], $indexedKeys = false)
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetch($indexedKeys ? PDO::FETCH_NUM : PDO::FETCH_ASSOC);
} | php | public function fetchRow($sql, array $parameters = [], $indexedKeys = false)
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetch($indexedKeys ? PDO::FETCH_NUM : PDO::FETCH_ASSOC);
} | [
"public",
"function",
"fetchRow",
"(",
"$",
"sql",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"indexedKeys",
"=",
"false",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"sql",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"statement",
"->",
"fetch",
"(",
"$",
"indexedKeys",
"?",
"PDO",
"::",
"FETCH_NUM",
":",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] | Execute an SQL statement and return the first row.
@param string $sql
@param array $parameters
@param bool $indexedKeys
@return array|false | [
"Execute",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"first",
"row",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L226-L231 |
31,349 | starweb/starlit-db | src/Db.php | Db.fetchRows | public function fetchRows($sql, array $parameters = [], $indexedKeys = false)
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetchAll($indexedKeys ? PDO::FETCH_NUM : PDO::FETCH_ASSOC);
} | php | public function fetchRows($sql, array $parameters = [], $indexedKeys = false)
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetchAll($indexedKeys ? PDO::FETCH_NUM : PDO::FETCH_ASSOC);
} | [
"public",
"function",
"fetchRows",
"(",
"$",
"sql",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"indexedKeys",
"=",
"false",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"sql",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"$",
"indexedKeys",
"?",
"PDO",
"::",
"FETCH_NUM",
":",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] | Execute an SQL statement and return all rows as an array.
@param string $sql
@param array $parameters
@param bool $indexedKeys
@return array | [
"Execute",
"an",
"SQL",
"statement",
"and",
"return",
"all",
"rows",
"as",
"an",
"array",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L241-L246 |
31,350 | starweb/starlit-db | src/Db.php | Db.fetchValue | public function fetchValue($sql, array $parameters = [])
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetchColumn(0);
} | php | public function fetchValue($sql, array $parameters = [])
{
$statement = $this->executeQuery($sql, $parameters);
return $statement->fetchColumn(0);
} | [
"public",
"function",
"fetchValue",
"(",
"$",
"sql",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"sql",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"statement",
"->",
"fetchColumn",
"(",
"0",
")",
";",
"}"
] | Execute an SQL statement and return the first column of the first row.
@param string $sql
@param array $parameters
@return string|false | [
"Execute",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"first",
"column",
"of",
"the",
"first",
"row",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L255-L260 |
31,351 | starweb/starlit-db | src/Db.php | Db.prepareParameters | protected function prepareParameters(array $parameters = [])
{
foreach ($parameters as &$parameterValue) {
if (is_bool($parameterValue)) {
$parameterValue = (int) $parameterValue;
} elseif ($parameterValue instanceof \DateTimeInterface) {
$parameterValue = $parameterValue->format('Y-m-d H:i:s');
} elseif (!is_scalar($parameterValue) && $parameterValue !== null) {
throw new \InvalidArgumentException(
sprintf('Invalid db parameter type "%s"', gettype($parameterValue))
);
}
}
unset($parameterValue);
return $parameters;
} | php | protected function prepareParameters(array $parameters = [])
{
foreach ($parameters as &$parameterValue) {
if (is_bool($parameterValue)) {
$parameterValue = (int) $parameterValue;
} elseif ($parameterValue instanceof \DateTimeInterface) {
$parameterValue = $parameterValue->format('Y-m-d H:i:s');
} elseif (!is_scalar($parameterValue) && $parameterValue !== null) {
throw new \InvalidArgumentException(
sprintf('Invalid db parameter type "%s"', gettype($parameterValue))
);
}
}
unset($parameterValue);
return $parameters;
} | [
"protected",
"function",
"prepareParameters",
"(",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"&",
"$",
"parameterValue",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"parameterValue",
")",
")",
"{",
"$",
"parameterValue",
"=",
"(",
"int",
")",
"$",
"parameterValue",
";",
"}",
"elseif",
"(",
"$",
"parameterValue",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"$",
"parameterValue",
"=",
"$",
"parameterValue",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"elseif",
"(",
"!",
"is_scalar",
"(",
"$",
"parameterValue",
")",
"&&",
"$",
"parameterValue",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid db parameter type \"%s\"'",
",",
"gettype",
"(",
"$",
"parameterValue",
")",
")",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"parameterValue",
")",
";",
"return",
"$",
"parameters",
";",
"}"
] | Prepare parameters for database use.
@param array $parameters
@return array | [
"Prepare",
"parameters",
"for",
"database",
"use",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Db.php#L293-L309 |
31,352 | gdbots/ncr-php | src/Repository/DynamoDb/NodeTable.php | NodeTable.create | final public function create(DynamoDbClient $client, string $tableName): void
{
try {
$client->describeTable(['TableName' => $tableName]);
return;
} catch (DynamoDbException $e) {
// table doesn't exist, create it below
}
$this->loadIndexes();
$attributes = [];
$indexes = [];
foreach ($this->gsi as $gsi) {
foreach ($gsi->getKeyAttributes() as $definition) {
$attributes[$definition['AttributeName']] = $definition;
}
$indexName = $gsi->getName();
$indexes[$indexName] = [
'IndexName' => $indexName,
'KeySchema' => [
['AttributeName' => $gsi->getHashKeyName(), 'KeyType' => 'HASH'],
],
'Projection' => $gsi->getProjection() ?: ['ProjectionType' => 'KEYS_ONLY'],
'ProvisionedThroughput' => $this->getDefaultProvisionedThroughput(),
];
if ($gsi->getRangeKeyName()) {
$indexes[$indexName]['KeySchema'][] = ['AttributeName' => $gsi->getRangeKeyName(), 'KeyType' => 'RANGE'];
}
}
$attributes[self::HASH_KEY_NAME] = ['AttributeName' => self::HASH_KEY_NAME, 'AttributeType' => 'S'];
$attributes = array_values($attributes);
$indexes = array_values($indexes);
try {
$client->createTable([
'TableName' => $tableName,
'AttributeDefinitions' => $attributes,
'KeySchema' => [
['AttributeName' => self::HASH_KEY_NAME, 'KeyType' => 'HASH'],
],
'GlobalSecondaryIndexes' => $indexes,
'StreamSpecification' => [
'StreamEnabled' => true,
'StreamViewType' => 'NEW_AND_OLD_IMAGES',
],
'ProvisionedThroughput' => $this->getDefaultProvisionedThroughput(),
]);
$client->waitUntil('TableExists', ['TableName' => $tableName]);
} catch (\Throwable $e) {
throw new RepositoryOperationFailed(
sprintf(
'%s::Unable to create table [%s] in region [%s].',
ClassUtils::getShortName($this),
$tableName,
$client->getRegion()
),
Code::INTERNAL,
$e
);
}
} | php | final public function create(DynamoDbClient $client, string $tableName): void
{
try {
$client->describeTable(['TableName' => $tableName]);
return;
} catch (DynamoDbException $e) {
// table doesn't exist, create it below
}
$this->loadIndexes();
$attributes = [];
$indexes = [];
foreach ($this->gsi as $gsi) {
foreach ($gsi->getKeyAttributes() as $definition) {
$attributes[$definition['AttributeName']] = $definition;
}
$indexName = $gsi->getName();
$indexes[$indexName] = [
'IndexName' => $indexName,
'KeySchema' => [
['AttributeName' => $gsi->getHashKeyName(), 'KeyType' => 'HASH'],
],
'Projection' => $gsi->getProjection() ?: ['ProjectionType' => 'KEYS_ONLY'],
'ProvisionedThroughput' => $this->getDefaultProvisionedThroughput(),
];
if ($gsi->getRangeKeyName()) {
$indexes[$indexName]['KeySchema'][] = ['AttributeName' => $gsi->getRangeKeyName(), 'KeyType' => 'RANGE'];
}
}
$attributes[self::HASH_KEY_NAME] = ['AttributeName' => self::HASH_KEY_NAME, 'AttributeType' => 'S'];
$attributes = array_values($attributes);
$indexes = array_values($indexes);
try {
$client->createTable([
'TableName' => $tableName,
'AttributeDefinitions' => $attributes,
'KeySchema' => [
['AttributeName' => self::HASH_KEY_NAME, 'KeyType' => 'HASH'],
],
'GlobalSecondaryIndexes' => $indexes,
'StreamSpecification' => [
'StreamEnabled' => true,
'StreamViewType' => 'NEW_AND_OLD_IMAGES',
],
'ProvisionedThroughput' => $this->getDefaultProvisionedThroughput(),
]);
$client->waitUntil('TableExists', ['TableName' => $tableName]);
} catch (\Throwable $e) {
throw new RepositoryOperationFailed(
sprintf(
'%s::Unable to create table [%s] in region [%s].',
ClassUtils::getShortName($this),
$tableName,
$client->getRegion()
),
Code::INTERNAL,
$e
);
}
} | [
"final",
"public",
"function",
"create",
"(",
"DynamoDbClient",
"$",
"client",
",",
"string",
"$",
"tableName",
")",
":",
"void",
"{",
"try",
"{",
"$",
"client",
"->",
"describeTable",
"(",
"[",
"'TableName'",
"=>",
"$",
"tableName",
"]",
")",
";",
"return",
";",
"}",
"catch",
"(",
"DynamoDbException",
"$",
"e",
")",
"{",
"// table doesn't exist, create it below",
"}",
"$",
"this",
"->",
"loadIndexes",
"(",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"indexes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"gsi",
"as",
"$",
"gsi",
")",
"{",
"foreach",
"(",
"$",
"gsi",
"->",
"getKeyAttributes",
"(",
")",
"as",
"$",
"definition",
")",
"{",
"$",
"attributes",
"[",
"$",
"definition",
"[",
"'AttributeName'",
"]",
"]",
"=",
"$",
"definition",
";",
"}",
"$",
"indexName",
"=",
"$",
"gsi",
"->",
"getName",
"(",
")",
";",
"$",
"indexes",
"[",
"$",
"indexName",
"]",
"=",
"[",
"'IndexName'",
"=>",
"$",
"indexName",
",",
"'KeySchema'",
"=>",
"[",
"[",
"'AttributeName'",
"=>",
"$",
"gsi",
"->",
"getHashKeyName",
"(",
")",
",",
"'KeyType'",
"=>",
"'HASH'",
"]",
",",
"]",
",",
"'Projection'",
"=>",
"$",
"gsi",
"->",
"getProjection",
"(",
")",
"?",
":",
"[",
"'ProjectionType'",
"=>",
"'KEYS_ONLY'",
"]",
",",
"'ProvisionedThroughput'",
"=>",
"$",
"this",
"->",
"getDefaultProvisionedThroughput",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"gsi",
"->",
"getRangeKeyName",
"(",
")",
")",
"{",
"$",
"indexes",
"[",
"$",
"indexName",
"]",
"[",
"'KeySchema'",
"]",
"[",
"]",
"=",
"[",
"'AttributeName'",
"=>",
"$",
"gsi",
"->",
"getRangeKeyName",
"(",
")",
",",
"'KeyType'",
"=>",
"'RANGE'",
"]",
";",
"}",
"}",
"$",
"attributes",
"[",
"self",
"::",
"HASH_KEY_NAME",
"]",
"=",
"[",
"'AttributeName'",
"=>",
"self",
"::",
"HASH_KEY_NAME",
",",
"'AttributeType'",
"=>",
"'S'",
"]",
";",
"$",
"attributes",
"=",
"array_values",
"(",
"$",
"attributes",
")",
";",
"$",
"indexes",
"=",
"array_values",
"(",
"$",
"indexes",
")",
";",
"try",
"{",
"$",
"client",
"->",
"createTable",
"(",
"[",
"'TableName'",
"=>",
"$",
"tableName",
",",
"'AttributeDefinitions'",
"=>",
"$",
"attributes",
",",
"'KeySchema'",
"=>",
"[",
"[",
"'AttributeName'",
"=>",
"self",
"::",
"HASH_KEY_NAME",
",",
"'KeyType'",
"=>",
"'HASH'",
"]",
",",
"]",
",",
"'GlobalSecondaryIndexes'",
"=>",
"$",
"indexes",
",",
"'StreamSpecification'",
"=>",
"[",
"'StreamEnabled'",
"=>",
"true",
",",
"'StreamViewType'",
"=>",
"'NEW_AND_OLD_IMAGES'",
",",
"]",
",",
"'ProvisionedThroughput'",
"=>",
"$",
"this",
"->",
"getDefaultProvisionedThroughput",
"(",
")",
",",
"]",
")",
";",
"$",
"client",
"->",
"waitUntil",
"(",
"'TableExists'",
",",
"[",
"'TableName'",
"=>",
"$",
"tableName",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"RepositoryOperationFailed",
"(",
"sprintf",
"(",
"'%s::Unable to create table [%s] in region [%s].'",
",",
"ClassUtils",
"::",
"getShortName",
"(",
"$",
"this",
")",
",",
"$",
"tableName",
",",
"$",
"client",
"->",
"getRegion",
"(",
")",
")",
",",
"Code",
"::",
"INTERNAL",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Creates a DynamoDb table with the node schema.
@param DynamoDbClient $client
@param string $tableName
@throws RepositoryOperationFailed | [
"Creates",
"a",
"DynamoDb",
"table",
"with",
"the",
"node",
"schema",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/NodeTable.php#L50-L116 |
31,353 | gdbots/ncr-php | src/Repository/DynamoDb/NodeTable.php | NodeTable.hasIndex | final public function hasIndex(string $alias): bool
{
$this->loadIndexes();
return isset($this->gsi[$alias]);
} | php | final public function hasIndex(string $alias): bool
{
$this->loadIndexes();
return isset($this->gsi[$alias]);
} | [
"final",
"public",
"function",
"hasIndex",
"(",
"string",
"$",
"alias",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"loadIndexes",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"gsi",
"[",
"$",
"alias",
"]",
")",
";",
"}"
] | Returns true if this NodeTable has the given index.
@see GlobalSecondaryIndex::getAlias()
@param string $alias
@return bool | [
"Returns",
"true",
"if",
"this",
"NodeTable",
"has",
"the",
"given",
"index",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/NodeTable.php#L156-L160 |
31,354 | gdbots/ncr-php | src/Repository/DynamoDb/NodeTable.php | NodeTable.getIndex | final public function getIndex(string $alias): ?GlobalSecondaryIndex
{
$this->loadIndexes();
return $this->gsi[$alias] ?? null;
} | php | final public function getIndex(string $alias): ?GlobalSecondaryIndex
{
$this->loadIndexes();
return $this->gsi[$alias] ?? null;
} | [
"final",
"public",
"function",
"getIndex",
"(",
"string",
"$",
"alias",
")",
":",
"?",
"GlobalSecondaryIndex",
"{",
"$",
"this",
"->",
"loadIndexes",
"(",
")",
";",
"return",
"$",
"this",
"->",
"gsi",
"[",
"$",
"alias",
"]",
"??",
"null",
";",
"}"
] | Returns an index by its alias if it exists on this table.
@param string $alias
@return GlobalSecondaryIndex|null | [
"Returns",
"an",
"index",
"by",
"its",
"alias",
"if",
"it",
"exists",
"on",
"this",
"table",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/NodeTable.php#L169-L173 |
31,355 | gdbots/ncr-php | src/Repository/DynamoDb/NodeTable.php | NodeTable.beforePutItem | final public function beforePutItem(array &$item, Node $node): void
{
$this->loadIndexes();
$this->addShardAttributes($item, $node);
if ($node instanceof Indexed) {
$item[NodeTable::INDEXED_KEY_NAME] = ['BOOL' => true];
}
foreach ($this->gsi as $gsi) {
$gsi->beforePutItem($item, $node);
}
$this->doBeforePutItem($item, $node);
} | php | final public function beforePutItem(array &$item, Node $node): void
{
$this->loadIndexes();
$this->addShardAttributes($item, $node);
if ($node instanceof Indexed) {
$item[NodeTable::INDEXED_KEY_NAME] = ['BOOL' => true];
}
foreach ($this->gsi as $gsi) {
$gsi->beforePutItem($item, $node);
}
$this->doBeforePutItem($item, $node);
} | [
"final",
"public",
"function",
"beforePutItem",
"(",
"array",
"&",
"$",
"item",
",",
"Node",
"$",
"node",
")",
":",
"void",
"{",
"$",
"this",
"->",
"loadIndexes",
"(",
")",
";",
"$",
"this",
"->",
"addShardAttributes",
"(",
"$",
"item",
",",
"$",
"node",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"Indexed",
")",
"{",
"$",
"item",
"[",
"NodeTable",
"::",
"INDEXED_KEY_NAME",
"]",
"=",
"[",
"'BOOL'",
"=>",
"true",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"gsi",
"as",
"$",
"gsi",
")",
"{",
"$",
"gsi",
"->",
"beforePutItem",
"(",
"$",
"item",
",",
"$",
"node",
")",
";",
"}",
"$",
"this",
"->",
"doBeforePutItem",
"(",
"$",
"item",
",",
"$",
"node",
")",
";",
"}"
] | Calls all of the indexes on this table "beforePutItem" methods.
@param array $item
@param Node $node | [
"Calls",
"all",
"of",
"the",
"indexes",
"on",
"this",
"table",
"beforePutItem",
"methods",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/NodeTable.php#L181-L194 |
31,356 | gdbots/ncr-php | src/Repository/DynamoDb/NodeTable.php | NodeTable.loadIndexes | private function loadIndexes(): void
{
if (null !== $this->gsi) {
return;
}
$this->gsi = [];
foreach ($this->getIndexes() as $gsi) {
$this->gsi[$gsi->getAlias()] = $gsi;
}
} | php | private function loadIndexes(): void
{
if (null !== $this->gsi) {
return;
}
$this->gsi = [];
foreach ($this->getIndexes() as $gsi) {
$this->gsi[$gsi->getAlias()] = $gsi;
}
} | [
"private",
"function",
"loadIndexes",
"(",
")",
":",
"void",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"gsi",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"gsi",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"gsi",
")",
"{",
"$",
"this",
"->",
"gsi",
"[",
"$",
"gsi",
"->",
"getAlias",
"(",
")",
"]",
"=",
"$",
"gsi",
";",
"}",
"}"
] | Load the indexes for this table. | [
"Load",
"the",
"indexes",
"for",
"this",
"table",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/DynamoDb/NodeTable.php#L250-L260 |
31,357 | starweb/starlit-db | src/AbstractDbEntityFetcher.php | AbstractDbEntityFetcher.getLimitSql | protected function getLimitSql($limit, array $pageItem = [])
{
$limitSql = '';
if (!empty($limit) || !empty($pageItem)) {
$limitSql = 'LIMIT ';
if (!empty($pageItem)) {
list($pageNo, $rowsPerPage) = $pageItem;
$pageNo = (int) $pageNo;
if ($pageNo < 1) {
throw new \InvalidArgumentException("Invalid pagination page number \"{$pageNo}\"");
}
$rowsPerPage = (int) $rowsPerPage;
// Offset example: "10" skips the first 10 rows, start showing the 11th
$offset = ($pageNo - 1) * $rowsPerPage;
$limitSql .= sprintf('%d, %d', $offset, $rowsPerPage);
} else {
$limitSql .= (int) $limit;
}
}
return $limitSql;
} | php | protected function getLimitSql($limit, array $pageItem = [])
{
$limitSql = '';
if (!empty($limit) || !empty($pageItem)) {
$limitSql = 'LIMIT ';
if (!empty($pageItem)) {
list($pageNo, $rowsPerPage) = $pageItem;
$pageNo = (int) $pageNo;
if ($pageNo < 1) {
throw new \InvalidArgumentException("Invalid pagination page number \"{$pageNo}\"");
}
$rowsPerPage = (int) $rowsPerPage;
// Offset example: "10" skips the first 10 rows, start showing the 11th
$offset = ($pageNo - 1) * $rowsPerPage;
$limitSql .= sprintf('%d, %d', $offset, $rowsPerPage);
} else {
$limitSql .= (int) $limit;
}
}
return $limitSql;
} | [
"protected",
"function",
"getLimitSql",
"(",
"$",
"limit",
",",
"array",
"$",
"pageItem",
"=",
"[",
"]",
")",
"{",
"$",
"limitSql",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"limit",
")",
"||",
"!",
"empty",
"(",
"$",
"pageItem",
")",
")",
"{",
"$",
"limitSql",
"=",
"'LIMIT '",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pageItem",
")",
")",
"{",
"list",
"(",
"$",
"pageNo",
",",
"$",
"rowsPerPage",
")",
"=",
"$",
"pageItem",
";",
"$",
"pageNo",
"=",
"(",
"int",
")",
"$",
"pageNo",
";",
"if",
"(",
"$",
"pageNo",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid pagination page number \\\"{$pageNo}\\\"\"",
")",
";",
"}",
"$",
"rowsPerPage",
"=",
"(",
"int",
")",
"$",
"rowsPerPage",
";",
"// Offset example: \"10\" skips the first 10 rows, start showing the 11th",
"$",
"offset",
"=",
"(",
"$",
"pageNo",
"-",
"1",
")",
"*",
"$",
"rowsPerPage",
";",
"$",
"limitSql",
".=",
"sprintf",
"(",
"'%d, %d'",
",",
"$",
"offset",
",",
"$",
"rowsPerPage",
")",
";",
"}",
"else",
"{",
"$",
"limitSql",
".=",
"(",
"int",
")",
"$",
"limit",
";",
"}",
"}",
"return",
"$",
"limitSql",
";",
"}"
] | Helper method to get LIMIT SQL and paging flag from limit parameter.
@param int $limit A limit number (like 5)
@param array $pageItem A pagination array like [1, 10], where 1 is the page number and 10 the number of
rows per page (first page is 1).
@return string | [
"Helper",
"method",
"to",
"get",
"LIMIT",
"SQL",
"and",
"paging",
"flag",
"from",
"limit",
"parameter",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntityFetcher.php#L50-L73 |
31,358 | starweb/starlit-db | src/AbstractDbEntityFetcher.php | AbstractDbEntityFetcher.getFetchPaginationResult | protected function getFetchPaginationResult(array $objects, $pagination)
{
if ($pagination) {
$totalRowCount = $this->db->fetchValue('SELECT FOUND_ROWS()');
return [$objects, $totalRowCount];
} else {
return $objects;
}
} | php | protected function getFetchPaginationResult(array $objects, $pagination)
{
if ($pagination) {
$totalRowCount = $this->db->fetchValue('SELECT FOUND_ROWS()');
return [$objects, $totalRowCount];
} else {
return $objects;
}
} | [
"protected",
"function",
"getFetchPaginationResult",
"(",
"array",
"$",
"objects",
",",
"$",
"pagination",
")",
"{",
"if",
"(",
"$",
"pagination",
")",
"{",
"$",
"totalRowCount",
"=",
"$",
"this",
"->",
"db",
"->",
"fetchValue",
"(",
"'SELECT FOUND_ROWS()'",
")",
";",
"return",
"[",
"$",
"objects",
",",
"$",
"totalRowCount",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"objects",
";",
"}",
"}"
] | Helper method to get pagination result array if pagination is requested.
@param array $objects
@param bool $pagination
@return array | [
"Helper",
"method",
"to",
"get",
"pagination",
"result",
"array",
"if",
"pagination",
"is",
"requested",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntityFetcher.php#L82-L91 |
31,359 | starweb/starlit-db | src/AbstractDbEntityFetcher.php | AbstractDbEntityFetcher.getDbEntitiesFromRowsPaginated | protected function getDbEntitiesFromRowsPaginated(array $rows, $pagination)
{
if ($pagination) {
$totalRowCount = $this->db->fetchValue('SELECT FOUND_ROWS()');
return [$this->getDbEntitiesFromRows($rows), $totalRowCount];
}
return $this->getDbEntitiesFromRows($rows);
} | php | protected function getDbEntitiesFromRowsPaginated(array $rows, $pagination)
{
if ($pagination) {
$totalRowCount = $this->db->fetchValue('SELECT FOUND_ROWS()');
return [$this->getDbEntitiesFromRows($rows), $totalRowCount];
}
return $this->getDbEntitiesFromRows($rows);
} | [
"protected",
"function",
"getDbEntitiesFromRowsPaginated",
"(",
"array",
"$",
"rows",
",",
"$",
"pagination",
")",
"{",
"if",
"(",
"$",
"pagination",
")",
"{",
"$",
"totalRowCount",
"=",
"$",
"this",
"->",
"db",
"->",
"fetchValue",
"(",
"'SELECT FOUND_ROWS()'",
")",
";",
"return",
"[",
"$",
"this",
"->",
"getDbEntitiesFromRows",
"(",
"$",
"rows",
")",
",",
"$",
"totalRowCount",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"getDbEntitiesFromRows",
"(",
"$",
"rows",
")",
";",
"}"
] | Helper method to get pagination result as objects if pagination is requested.
@param array $rows
@param bool $pagination
@return array | [
"Helper",
"method",
"to",
"get",
"pagination",
"result",
"as",
"objects",
"if",
"pagination",
"is",
"requested",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/AbstractDbEntityFetcher.php#L100-L108 |
31,360 | gdbots/ncr-php | src/Search/Elastica/IndexManager.php | IndexManager.createIndex | final public function createIndex(Client $client, SchemaQName $qname, array $context = []): Index
{
static $created = [];
$indexName = $this->getIndexName($qname, $context);
if (isset($created[$indexName])) {
return $created[$indexName];
}
$index = $created[$indexName] = $client->getIndex($indexName);
$type = $this->types[$qname->toString()] ?? $this->types['default'];
$mapper = $this->getNodeMapper($qname);
$settings = $this->filterIndexSettings($this->indexes[$type['index_name'] ?? 'default'], $qname, $context);
unset($settings['fq_index_name']);
try {
if (!$index->exists()) {
$settings['analysis'] = [
'analyzer' => $mapper->getCustomAnalyzers(),
'normalizer' => $mapper->getCustomNormalizers(),
];
$index->create($settings);
}
} catch (\Throwable $e) {
throw new SearchOperationFailed(
sprintf(
'%s while creating index [%s] for qname [%s].',
ClassUtils::getShortName($e),
$index->getName(),
$qname
),
Code::INTERNAL,
$e
);
}
return $index;
} | php | final public function createIndex(Client $client, SchemaQName $qname, array $context = []): Index
{
static $created = [];
$indexName = $this->getIndexName($qname, $context);
if (isset($created[$indexName])) {
return $created[$indexName];
}
$index = $created[$indexName] = $client->getIndex($indexName);
$type = $this->types[$qname->toString()] ?? $this->types['default'];
$mapper = $this->getNodeMapper($qname);
$settings = $this->filterIndexSettings($this->indexes[$type['index_name'] ?? 'default'], $qname, $context);
unset($settings['fq_index_name']);
try {
if (!$index->exists()) {
$settings['analysis'] = [
'analyzer' => $mapper->getCustomAnalyzers(),
'normalizer' => $mapper->getCustomNormalizers(),
];
$index->create($settings);
}
} catch (\Throwable $e) {
throw new SearchOperationFailed(
sprintf(
'%s while creating index [%s] for qname [%s].',
ClassUtils::getShortName($e),
$index->getName(),
$qname
),
Code::INTERNAL,
$e
);
}
return $index;
} | [
"final",
"public",
"function",
"createIndex",
"(",
"Client",
"$",
"client",
",",
"SchemaQName",
"$",
"qname",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
":",
"Index",
"{",
"static",
"$",
"created",
"=",
"[",
"]",
";",
"$",
"indexName",
"=",
"$",
"this",
"->",
"getIndexName",
"(",
"$",
"qname",
",",
"$",
"context",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"created",
"[",
"$",
"indexName",
"]",
")",
")",
"{",
"return",
"$",
"created",
"[",
"$",
"indexName",
"]",
";",
"}",
"$",
"index",
"=",
"$",
"created",
"[",
"$",
"indexName",
"]",
"=",
"$",
"client",
"->",
"getIndex",
"(",
"$",
"indexName",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"types",
"[",
"$",
"qname",
"->",
"toString",
"(",
")",
"]",
"??",
"$",
"this",
"->",
"types",
"[",
"'default'",
"]",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"getNodeMapper",
"(",
"$",
"qname",
")",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"filterIndexSettings",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"type",
"[",
"'index_name'",
"]",
"??",
"'default'",
"]",
",",
"$",
"qname",
",",
"$",
"context",
")",
";",
"unset",
"(",
"$",
"settings",
"[",
"'fq_index_name'",
"]",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"index",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"settings",
"[",
"'analysis'",
"]",
"=",
"[",
"'analyzer'",
"=>",
"$",
"mapper",
"->",
"getCustomAnalyzers",
"(",
")",
",",
"'normalizer'",
"=>",
"$",
"mapper",
"->",
"getCustomNormalizers",
"(",
")",
",",
"]",
";",
"$",
"index",
"->",
"create",
"(",
"$",
"settings",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"SearchOperationFailed",
"(",
"sprintf",
"(",
"'%s while creating index [%s] for qname [%s].'",
",",
"ClassUtils",
"::",
"getShortName",
"(",
"$",
"e",
")",
",",
"$",
"index",
"->",
"getName",
"(",
")",
",",
"$",
"qname",
")",
",",
"Code",
"::",
"INTERNAL",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"index",
";",
"}"
] | Creates the index in ElasticSearch if it doesn't already exist. It will NOT
perform an update as that requires the index be closed and reopened which
is not currently supported on AWS ElasticSearch service.
@param Client $client The Elastica client
@param SchemaQName $qname QName used to derive the index name.
@param array $context Data that helps the NCR Search decide where to read/write data from.
@return Index | [
"Creates",
"the",
"index",
"in",
"ElasticSearch",
"if",
"it",
"doesn",
"t",
"already",
"exist",
".",
"It",
"will",
"NOT",
"perform",
"an",
"update",
"as",
"that",
"requires",
"the",
"index",
"be",
"closed",
"and",
"reopened",
"which",
"is",
"not",
"currently",
"supported",
"on",
"AWS",
"ElasticSearch",
"service",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Search/Elastica/IndexManager.php#L97-L135 |
31,361 | gdbots/ncr-php | src/Search/Elastica/IndexManager.php | IndexManager.createType | final public function createType(Index $index, SchemaQName $qname): Type
{
$type = new Type($index, $this->getTypeName($qname));
$mapping = $this->getNodeMapper($qname)->getMapping($qname);
$mapping->setType($type);
try {
$mapping->send();
} catch (\Throwable $e) {
throw new SearchOperationFailed(
sprintf(
'%s while putting mapping for type [%s/%s] into ElasticSearch for qname [%s].',
ClassUtils::getShortName($e),
$index->getName(),
$type->getName(),
$qname
),
Code::INTERNAL,
$e
);
}
return $type;
} | php | final public function createType(Index $index, SchemaQName $qname): Type
{
$type = new Type($index, $this->getTypeName($qname));
$mapping = $this->getNodeMapper($qname)->getMapping($qname);
$mapping->setType($type);
try {
$mapping->send();
} catch (\Throwable $e) {
throw new SearchOperationFailed(
sprintf(
'%s while putting mapping for type [%s/%s] into ElasticSearch for qname [%s].',
ClassUtils::getShortName($e),
$index->getName(),
$type->getName(),
$qname
),
Code::INTERNAL,
$e
);
}
return $type;
} | [
"final",
"public",
"function",
"createType",
"(",
"Index",
"$",
"index",
",",
"SchemaQName",
"$",
"qname",
")",
":",
"Type",
"{",
"$",
"type",
"=",
"new",
"Type",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"getTypeName",
"(",
"$",
"qname",
")",
")",
";",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getNodeMapper",
"(",
"$",
"qname",
")",
"->",
"getMapping",
"(",
"$",
"qname",
")",
";",
"$",
"mapping",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"try",
"{",
"$",
"mapping",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"SearchOperationFailed",
"(",
"sprintf",
"(",
"'%s while putting mapping for type [%s/%s] into ElasticSearch for qname [%s].'",
",",
"ClassUtils",
"::",
"getShortName",
"(",
"$",
"e",
")",
",",
"$",
"index",
"->",
"getName",
"(",
")",
",",
"$",
"type",
"->",
"getName",
"(",
")",
",",
"$",
"qname",
")",
",",
"Code",
"::",
"INTERNAL",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Creates or updates the Type in ElasticSearch. This expects the
Index to already exist and have any analyzers it needs.
@param Index $index The Elastica Index to create the Type in.
@param SchemaQName $qname QName used to derive the type name.
@return Type | [
"Creates",
"or",
"updates",
"the",
"Type",
"in",
"ElasticSearch",
".",
"This",
"expects",
"the",
"Index",
"to",
"already",
"exist",
"and",
"have",
"any",
"analyzers",
"it",
"needs",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Search/Elastica/IndexManager.php#L146-L169 |
31,362 | starweb/starlit-db | src/Migration/Migrator.php | Migrator.emptyDb | public function emptyDb()
{
if (($rows = $this->db->fetchRows('SHOW TABLES', [], true))) {
$this->db->exec('SET foreign_key_checks = 0');
foreach ($rows as $row) {
$this->db->exec('DROP TABLE `' . $row[0] . '`');
}
$this->db->exec('SET foreign_key_checks = 1');
}
} | php | public function emptyDb()
{
if (($rows = $this->db->fetchRows('SHOW TABLES', [], true))) {
$this->db->exec('SET foreign_key_checks = 0');
foreach ($rows as $row) {
$this->db->exec('DROP TABLE `' . $row[0] . '`');
}
$this->db->exec('SET foreign_key_checks = 1');
}
} | [
"public",
"function",
"emptyDb",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"rows",
"=",
"$",
"this",
"->",
"db",
"->",
"fetchRows",
"(",
"'SHOW TABLES'",
",",
"[",
"]",
",",
"true",
")",
")",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"exec",
"(",
"'SET foreign_key_checks = 0'",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"exec",
"(",
"'DROP TABLE `'",
".",
"$",
"row",
"[",
"0",
"]",
".",
"'`'",
")",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"exec",
"(",
"'SET foreign_key_checks = 1'",
")",
";",
"}",
"}"
] | Empty database. | [
"Empty",
"database",
"."
] | 521efeb4a6ffebf616b02a436575bdc1bf304e88 | https://github.com/starweb/starlit-db/blob/521efeb4a6ffebf616b02a436575bdc1bf304e88/src/Migration/Migrator.php#L286-L295 |
31,363 | gdbots/ncr-php | src/IndexQueryFilterProcessor.php | IndexQueryFilterProcessor.valueMatchesFilter | protected function valueMatchesFilter($value, IndexQueryFilter $filter): bool
{
switch ($filter->getOperator()) {
case IndexQueryFilterOperator::EQUAL_TO:
return $value == $filter->getValue();
case IndexQueryFilterOperator::NOT_EQUAL_TO:
return $value != $filter->getValue();
case IndexQueryFilterOperator::GREATER_THAN:
return $value > $filter->getValue();
case IndexQueryFilterOperator::GREATER_THAN_OR_EQUAL_TO:
return $value >= $filter->getValue();
case IndexQueryFilterOperator::LESS_THAN:
return $value < $filter->getValue();
case IndexQueryFilterOperator::LESS_THAN_OR_EQUAL_TO:
return $value <= $filter->getValue();
}
} | php | protected function valueMatchesFilter($value, IndexQueryFilter $filter): bool
{
switch ($filter->getOperator()) {
case IndexQueryFilterOperator::EQUAL_TO:
return $value == $filter->getValue();
case IndexQueryFilterOperator::NOT_EQUAL_TO:
return $value != $filter->getValue();
case IndexQueryFilterOperator::GREATER_THAN:
return $value > $filter->getValue();
case IndexQueryFilterOperator::GREATER_THAN_OR_EQUAL_TO:
return $value >= $filter->getValue();
case IndexQueryFilterOperator::LESS_THAN:
return $value < $filter->getValue();
case IndexQueryFilterOperator::LESS_THAN_OR_EQUAL_TO:
return $value <= $filter->getValue();
}
} | [
"protected",
"function",
"valueMatchesFilter",
"(",
"$",
"value",
",",
"IndexQueryFilter",
"$",
"filter",
")",
":",
"bool",
"{",
"switch",
"(",
"$",
"filter",
"->",
"getOperator",
"(",
")",
")",
"{",
"case",
"IndexQueryFilterOperator",
"::",
"EQUAL_TO",
":",
"return",
"$",
"value",
"==",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"case",
"IndexQueryFilterOperator",
"::",
"NOT_EQUAL_TO",
":",
"return",
"$",
"value",
"!=",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"case",
"IndexQueryFilterOperator",
"::",
"GREATER_THAN",
":",
"return",
"$",
"value",
">",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"case",
"IndexQueryFilterOperator",
"::",
"GREATER_THAN_OR_EQUAL_TO",
":",
"return",
"$",
"value",
">=",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"case",
"IndexQueryFilterOperator",
"::",
"LESS_THAN",
":",
"return",
"$",
"value",
"<",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"case",
"IndexQueryFilterOperator",
"::",
"LESS_THAN_OR_EQUAL_TO",
":",
"return",
"$",
"value",
"<=",
"$",
"filter",
"->",
"getValue",
"(",
")",
";",
"}",
"}"
] | Returns true if the provided value matches the filter.
@param mixed $value
@param IndexQueryFilter $filter
@return bool | [
"Returns",
"true",
"if",
"the",
"provided",
"value",
"matches",
"the",
"filter",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/IndexQueryFilterProcessor.php#L70-L91 |
31,364 | gdbots/ncr-php | src/Repository/Psr6Ncr.php | Psr6Ncr.beforeSaveCacheItem | protected function beforeSaveCacheItem(CacheItemInterface $cacheItem, Node $node): void
{
$cacheItem->expiresAfter(null)->expiresAt(null);
} | php | protected function beforeSaveCacheItem(CacheItemInterface $cacheItem, Node $node): void
{
$cacheItem->expiresAfter(null)->expiresAt(null);
} | [
"protected",
"function",
"beforeSaveCacheItem",
"(",
"CacheItemInterface",
"$",
"cacheItem",
",",
"Node",
"$",
"node",
")",
":",
"void",
"{",
"$",
"cacheItem",
"->",
"expiresAfter",
"(",
"null",
")",
"->",
"expiresAt",
"(",
"null",
")",
";",
"}"
] | Prepares the cache item before it's saved into the cache pool.
By default, all nodes are stored in cache forever, to change this behavior
either set the default ttl on the cache provider, or tweak the expiry on
a per item basis by overriding this method.
@param CacheItemInterface $cacheItem
@param Node $node | [
"Prepares",
"the",
"cache",
"item",
"before",
"it",
"s",
"saved",
"into",
"the",
"cache",
"pool",
".",
"By",
"default",
"all",
"nodes",
"are",
"stored",
"in",
"cache",
"forever",
"to",
"change",
"this",
"behavior",
"either",
"set",
"the",
"default",
"ttl",
"on",
"the",
"cache",
"provider",
"or",
"tweak",
"the",
"expiry",
"on",
"a",
"per",
"item",
"basis",
"by",
"overriding",
"this",
"method",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Repository/Psr6Ncr.php#L307-L310 |
31,365 | gdbots/ncr-php | src/NcrPreloader.php | NcrPreloader.clear | public function clear(?string $namespace = self::DEFAULT_NAMESPACE): void
{
if (null === $namespace) {
$this->nodeRefs = [];
return;
}
unset($this->nodeRefs[$namespace]);
} | php | public function clear(?string $namespace = self::DEFAULT_NAMESPACE): void
{
if (null === $namespace) {
$this->nodeRefs = [];
return;
}
unset($this->nodeRefs[$namespace]);
} | [
"public",
"function",
"clear",
"(",
"?",
"string",
"$",
"namespace",
"=",
"self",
"::",
"DEFAULT_NAMESPACE",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"namespace",
")",
"{",
"$",
"this",
"->",
"nodeRefs",
"=",
"[",
"]",
";",
"return",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"nodeRefs",
"[",
"$",
"namespace",
"]",
")",
";",
"}"
] | Clears the preloaded node refs.
@param string $namespace | [
"Clears",
"the",
"preloaded",
"node",
"refs",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/NcrPreloader.php#L209-L217 |
31,366 | gdbots/ncr-php | src/Search/Elastica/ClientManager.php | ClientManager.getClient | final public function getClient(string $cluster = 'default'): Client
{
if (isset($this->clients[$cluster])) {
return $this->clients[$cluster];
}
if (!$this->hasCluster($cluster)) {
throw new \InvalidArgumentException(
sprintf(
'The cluster [%s] is not one of the available clusters [%s].',
$cluster,
implode(',', $this->getAvailableClusters())
)
);
}
$config = $this->clusters[$cluster];
if (isset($config['debug'])) {
$config['log'] = filter_var($config['debug'], FILTER_VALIDATE_BOOLEAN);
unset($config['debug']);
} else {
$config['log'] = false;
}
if (isset($config['round_robin'])) {
$config['roundRobin'] = filter_var($config['round_robin'], FILTER_VALIDATE_BOOLEAN);
unset($config['round_robin']);
}
$config = $this->configureCluster($cluster, $config);
$servers = $config['servers'];
$configuredServers = [];
unset($config['servers']);
foreach ($servers as $server) {
$configuredServers[] = array_merge($config, $server);
}
$config['servers'] = $configuredServers;
return $this->clients[$cluster] = new Client($config, null, $config['log'] ? $this->logger : null);
} | php | final public function getClient(string $cluster = 'default'): Client
{
if (isset($this->clients[$cluster])) {
return $this->clients[$cluster];
}
if (!$this->hasCluster($cluster)) {
throw new \InvalidArgumentException(
sprintf(
'The cluster [%s] is not one of the available clusters [%s].',
$cluster,
implode(',', $this->getAvailableClusters())
)
);
}
$config = $this->clusters[$cluster];
if (isset($config['debug'])) {
$config['log'] = filter_var($config['debug'], FILTER_VALIDATE_BOOLEAN);
unset($config['debug']);
} else {
$config['log'] = false;
}
if (isset($config['round_robin'])) {
$config['roundRobin'] = filter_var($config['round_robin'], FILTER_VALIDATE_BOOLEAN);
unset($config['round_robin']);
}
$config = $this->configureCluster($cluster, $config);
$servers = $config['servers'];
$configuredServers = [];
unset($config['servers']);
foreach ($servers as $server) {
$configuredServers[] = array_merge($config, $server);
}
$config['servers'] = $configuredServers;
return $this->clients[$cluster] = new Client($config, null, $config['log'] ? $this->logger : null);
} | [
"final",
"public",
"function",
"getClient",
"(",
"string",
"$",
"cluster",
"=",
"'default'",
")",
":",
"Client",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"clients",
"[",
"$",
"cluster",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"clients",
"[",
"$",
"cluster",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCluster",
"(",
"$",
"cluster",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The cluster [%s] is not one of the available clusters [%s].'",
",",
"$",
"cluster",
",",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"getAvailableClusters",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"clusters",
"[",
"$",
"cluster",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'debug'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'log'",
"]",
"=",
"filter_var",
"(",
"$",
"config",
"[",
"'debug'",
"]",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"unset",
"(",
"$",
"config",
"[",
"'debug'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"config",
"[",
"'log'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'round_robin'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'roundRobin'",
"]",
"=",
"filter_var",
"(",
"$",
"config",
"[",
"'round_robin'",
"]",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
";",
"unset",
"(",
"$",
"config",
"[",
"'round_robin'",
"]",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"configureCluster",
"(",
"$",
"cluster",
",",
"$",
"config",
")",
";",
"$",
"servers",
"=",
"$",
"config",
"[",
"'servers'",
"]",
";",
"$",
"configuredServers",
"=",
"[",
"]",
";",
"unset",
"(",
"$",
"config",
"[",
"'servers'",
"]",
")",
";",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"server",
")",
"{",
"$",
"configuredServers",
"[",
"]",
"=",
"array_merge",
"(",
"$",
"config",
",",
"$",
"server",
")",
";",
"}",
"$",
"config",
"[",
"'servers'",
"]",
"=",
"$",
"configuredServers",
";",
"return",
"$",
"this",
"->",
"clients",
"[",
"$",
"cluster",
"]",
"=",
"new",
"Client",
"(",
"$",
"config",
",",
"null",
",",
"$",
"config",
"[",
"'log'",
"]",
"?",
"$",
"this",
"->",
"logger",
":",
"null",
")",
";",
"}"
] | Gets an elastica client using the config from the provided cluster name.
All calls with the same cluster name will return the same client instance.
@param string $cluster
@return Client | [
"Gets",
"an",
"elastica",
"client",
"using",
"the",
"config",
"from",
"the",
"provided",
"cluster",
"name",
"."
] | b31c1315144f9a5bc6c48463dd77b6c643fdf250 | https://github.com/gdbots/ncr-php/blob/b31c1315144f9a5bc6c48463dd77b6c643fdf250/src/Search/Elastica/ClientManager.php#L63-L105 |
31,367 | agroviva/egroupware-api | src/Api/Categories.php | Categories.ReadAll | public static function ReadAll($app = 'phpgw')
{
$Categories = new Api\Categories(0, $app);
return $Categories->return_array('all', 0, true, '', 'ASC', '', true, null, -1, '', null);
} | php | public static function ReadAll($app = 'phpgw')
{
$Categories = new Api\Categories(0, $app);
return $Categories->return_array('all', 0, true, '', 'ASC', '', true, null, -1, '', null);
} | [
"public",
"static",
"function",
"ReadAll",
"(",
"$",
"app",
"=",
"'phpgw'",
")",
"{",
"$",
"Categories",
"=",
"new",
"Api",
"\\",
"Categories",
"(",
"0",
",",
"$",
"app",
")",
";",
"return",
"$",
"Categories",
"->",
"return_array",
"(",
"'all'",
",",
"0",
",",
"true",
",",
"''",
",",
"'ASC'",
",",
"''",
",",
"true",
",",
"null",
",",
"-",
"1",
",",
"''",
",",
"null",
")",
";",
"}"
] | Returns all Categories.
@param string $app [If app given it will read only the categories of the app] | [
"Returns",
"all",
"Categories",
"."
] | 2dd3d94d5e06d9b4485d41af772d4e9188fd1c76 | https://github.com/agroviva/egroupware-api/blob/2dd3d94d5e06d9b4485d41af772d4e9188fd1c76/src/Api/Categories.php#L35-L40 |
31,368 | salted-herring/salted-library | code/Utilities.php | Utilities.nl2p | public static function nl2p($string, $viewer) {
$items = new \ArrayList();
foreach(explode(PHP_EOL, $string) as $item) {
if (trim($item)) {
$items->push(new \ArrayData(array(
'line' => $item
)));
}
}
return $viewer->customise(new \ArrayData(array(
'Paragraphs' => $items
)))->renderWith('Paragraphs');
} | php | public static function nl2p($string, $viewer) {
$items = new \ArrayList();
foreach(explode(PHP_EOL, $string) as $item) {
if (trim($item)) {
$items->push(new \ArrayData(array(
'line' => $item
)));
}
}
return $viewer->customise(new \ArrayData(array(
'Paragraphs' => $items
)))->renderWith('Paragraphs');
} | [
"public",
"static",
"function",
"nl2p",
"(",
"$",
"string",
",",
"$",
"viewer",
")",
"{",
"$",
"items",
"=",
"new",
"\\",
"ArrayList",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"PHP_EOL",
",",
"$",
"string",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"item",
")",
")",
"{",
"$",
"items",
"->",
"push",
"(",
"new",
"\\",
"ArrayData",
"(",
"array",
"(",
"'line'",
"=>",
"$",
"item",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"viewer",
"->",
"customise",
"(",
"new",
"\\",
"ArrayData",
"(",
"array",
"(",
"'Paragraphs'",
"=>",
"$",
"items",
")",
")",
")",
"->",
"renderWith",
"(",
"'Paragraphs'",
")",
";",
"}"
] | Take a string with new line feeds & create paragraphs. | [
"Take",
"a",
"string",
"with",
"new",
"line",
"feeds",
"&",
"create",
"paragraphs",
"."
] | bf062feaa6f11da1a5b7010c15d50976c6cbee6b | https://github.com/salted-herring/salted-library/blob/bf062feaa6f11da1a5b7010c15d50976c6cbee6b/code/Utilities.php#L314-L328 |
31,369 | salted-herring/salted-library | code/Utilities.php | Utilities.getValidKey | public static function getValidKey($pattern, $arr) {
$keys = array();
foreach($arr as $key => $value) {
if (preg_match($pattern, $key)){
$keys[] = $key;
}
}
return $keys;
} | php | public static function getValidKey($pattern, $arr) {
$keys = array();
foreach($arr as $key => $value) {
if (preg_match($pattern, $key)){
$keys[] = $key;
}
}
return $keys;
} | [
"public",
"static",
"function",
"getValidKey",
"(",
"$",
"pattern",
",",
"$",
"arr",
")",
"{",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"key",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"return",
"$",
"keys",
";",
"}"
] | find the key that matches a specific pattern.
Used primarily with dbo field tags.
e.g. UtilityFunctions::getValidKey('/*Description/', $this->db); | [
"find",
"the",
"key",
"that",
"matches",
"a",
"specific",
"pattern",
".",
"Used",
"primarily",
"with",
"dbo",
"field",
"tags",
"."
] | bf062feaa6f11da1a5b7010c15d50976c6cbee6b | https://github.com/salted-herring/salted-library/blob/bf062feaa6f11da1a5b7010c15d50976c6cbee6b/code/Utilities.php#L336-L345 |
31,370 | salted-herring/salted-library | code/Utilities.php | Utilities.getWordsWithinCharLimit | public static function getWordsWithinCharLimit($sentence, $limit = 150) {
$str = '';
$i = 1;
if(strlen($sentence) < $limit) {
return $sentence;
}
while (strlen($current = self::getWords($sentence, $i++)) < $limit) {
$str = $current;
}
return $str;
} | php | public static function getWordsWithinCharLimit($sentence, $limit = 150) {
$str = '';
$i = 1;
if(strlen($sentence) < $limit) {
return $sentence;
}
while (strlen($current = self::getWords($sentence, $i++)) < $limit) {
$str = $current;
}
return $str;
} | [
"public",
"static",
"function",
"getWordsWithinCharLimit",
"(",
"$",
"sentence",
",",
"$",
"limit",
"=",
"150",
")",
"{",
"$",
"str",
"=",
"''",
";",
"$",
"i",
"=",
"1",
";",
"if",
"(",
"strlen",
"(",
"$",
"sentence",
")",
"<",
"$",
"limit",
")",
"{",
"return",
"$",
"sentence",
";",
"}",
"while",
"(",
"strlen",
"(",
"$",
"current",
"=",
"self",
"::",
"getWords",
"(",
"$",
"sentence",
",",
"$",
"i",
"++",
")",
")",
"<",
"$",
"limit",
")",
"{",
"$",
"str",
"=",
"$",
"current",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Get max number of words within a character limit. | [
"Get",
"max",
"number",
"of",
"words",
"within",
"a",
"character",
"limit",
"."
] | bf062feaa6f11da1a5b7010c15d50976c6cbee6b | https://github.com/salted-herring/salted-library/blob/bf062feaa6f11da1a5b7010c15d50976c6cbee6b/code/Utilities.php#L371-L384 |
31,371 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.create | public function create($name, $config, $object = null, $class = null, $reformatted = false, $populated = true)
{
$defaultConfig = include __DIR__.'/../../config/form-maker.php';
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$inputConfig = [
'populated' => $populated,
'name' => $this->inputCalibrator->getName($name, $config),
'id' => $this->inputCalibrator->getId($name, $config),
'class' => $this->prepareTheClass($class, $config),
'config' => $config,
'inputTypes' => Config::get('form-maker.inputTypes', $defaultConfig['inputTypes']),
'inputs' => $this->getInput(),
'object' => $object,
'objectValue' => $this->getObjectValue($object, $name),
'placeholder' => $this->inputCalibrator->placeholder($config, $name),
];
$inputConfig = $this->refineConfigs($inputConfig, $reformatted, $name, $config);
return $this->inputStringPreparer($inputConfig);
} | php | public function create($name, $config, $object = null, $class = null, $reformatted = false, $populated = true)
{
$defaultConfig = include __DIR__.'/../../config/form-maker.php';
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$inputConfig = [
'populated' => $populated,
'name' => $this->inputCalibrator->getName($name, $config),
'id' => $this->inputCalibrator->getId($name, $config),
'class' => $this->prepareTheClass($class, $config),
'config' => $config,
'inputTypes' => Config::get('form-maker.inputTypes', $defaultConfig['inputTypes']),
'inputs' => $this->getInput(),
'object' => $object,
'objectValue' => $this->getObjectValue($object, $name),
'placeholder' => $this->inputCalibrator->placeholder($config, $name),
];
$inputConfig = $this->refineConfigs($inputConfig, $reformatted, $name, $config);
return $this->inputStringPreparer($inputConfig);
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"config",
",",
"$",
"object",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"reformatted",
"=",
"false",
",",
"$",
"populated",
"=",
"true",
")",
"{",
"$",
"defaultConfig",
"=",
"include",
"__DIR__",
".",
"'/../../config/form-maker.php'",
";",
"if",
"(",
"is_null",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"config",
"(",
"'form-maker.forms.form-class'",
",",
"'form-control'",
")",
";",
"}",
"$",
"inputConfig",
"=",
"[",
"'populated'",
"=>",
"$",
"populated",
",",
"'name'",
"=>",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getName",
"(",
"$",
"name",
",",
"$",
"config",
")",
",",
"'id'",
"=>",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getId",
"(",
"$",
"name",
",",
"$",
"config",
")",
",",
"'class'",
"=>",
"$",
"this",
"->",
"prepareTheClass",
"(",
"$",
"class",
",",
"$",
"config",
")",
",",
"'config'",
"=>",
"$",
"config",
",",
"'inputTypes'",
"=>",
"Config",
"::",
"get",
"(",
"'form-maker.inputTypes'",
",",
"$",
"defaultConfig",
"[",
"'inputTypes'",
"]",
")",
",",
"'inputs'",
"=>",
"$",
"this",
"->",
"getInput",
"(",
")",
",",
"'object'",
"=>",
"$",
"object",
",",
"'objectValue'",
"=>",
"$",
"this",
"->",
"getObjectValue",
"(",
"$",
"object",
",",
"$",
"name",
")",
",",
"'placeholder'",
"=>",
"$",
"this",
"->",
"inputCalibrator",
"->",
"placeholder",
"(",
"$",
"config",
",",
"$",
"name",
")",
",",
"]",
";",
"$",
"inputConfig",
"=",
"$",
"this",
"->",
"refineConfigs",
"(",
"$",
"inputConfig",
",",
"$",
"reformatted",
",",
"$",
"name",
",",
"$",
"config",
")",
";",
"return",
"$",
"this",
"->",
"inputStringPreparer",
"(",
"$",
"inputConfig",
")",
";",
"}"
] | Create the input HTML.
@param string $name Column/ Input name
@param array $config Array of config info for the input
@param object|array $object Object or Table Object
@param string $class CSS class
@param bool $reformatted Clean the labels and placeholder values
@param bool $populated Set the value of the input to the object's value
@return string | [
"Create",
"the",
"input",
"HTML",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L72-L96 |
31,372 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.getObjectValue | public function getObjectValue($object, $name)
{
if (is_object($object) && isset($object->$name) && !method_exists($object, $name)) {
return $object->$name;
}
// If its a nested value like meta[user[phone]]
if (strpos($name, '[') > 0) {
$nested = explode('[', str_replace(']', '', $name));
$final = $object;
foreach ($nested as $property) {
if (!empty($property) && isset($final->{$property})) {
$final = $final->{$property};
} elseif (is_object($final) && is_null($final->{$property})) {
$final = '';
}
}
return $final;
}
return '';
} | php | public function getObjectValue($object, $name)
{
if (is_object($object) && isset($object->$name) && !method_exists($object, $name)) {
return $object->$name;
}
// If its a nested value like meta[user[phone]]
if (strpos($name, '[') > 0) {
$nested = explode('[', str_replace(']', '', $name));
$final = $object;
foreach ($nested as $property) {
if (!empty($property) && isset($final->{$property})) {
$final = $final->{$property};
} elseif (is_object($final) && is_null($final->{$property})) {
$final = '';
}
}
return $final;
}
return '';
} | [
"public",
"function",
"getObjectValue",
"(",
"$",
"object",
",",
"$",
"name",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"&&",
"isset",
"(",
"$",
"object",
"->",
"$",
"name",
")",
"&&",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",
"name",
")",
")",
"{",
"return",
"$",
"object",
"->",
"$",
"name",
";",
"}",
"// If its a nested value like meta[user[phone]]",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'['",
")",
">",
"0",
")",
"{",
"$",
"nested",
"=",
"explode",
"(",
"'['",
",",
"str_replace",
"(",
"']'",
",",
"''",
",",
"$",
"name",
")",
")",
";",
"$",
"final",
"=",
"$",
"object",
";",
"foreach",
"(",
"$",
"nested",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"property",
")",
"&&",
"isset",
"(",
"$",
"final",
"->",
"{",
"$",
"property",
"}",
")",
")",
"{",
"$",
"final",
"=",
"$",
"final",
"->",
"{",
"$",
"property",
"}",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"final",
")",
"&&",
"is_null",
"(",
"$",
"final",
"->",
"{",
"$",
"property",
"}",
")",
")",
"{",
"$",
"final",
"=",
"''",
";",
"}",
"}",
"return",
"$",
"final",
";",
"}",
"return",
"''",
";",
"}"
] | Get the object value from the object with the name.
@param mixed $object
@param string $name
@return mixed | [
"Get",
"the",
"object",
"value",
"from",
"the",
"object",
"with",
"the",
"name",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L106-L128 |
31,373 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.inputStringPreparer | public function inputStringPreparer($config)
{
$inputString = '';
$beforeAfterCondition = ($this->before($config) > '' || $this->after($config) > '');
$method = $this->getGeneratorMethod($config['inputType']);
if ($beforeAfterCondition) {
$inputString .= '<div class="'.config('form-maker.form.before_after_input_wrapper', 'input-group').'">';
}
$inputString .= $this->before($config);
$inputString .= $this->inputStringGenerator($config);
$inputString .= $this->after($config);
if ($beforeAfterCondition) {
$inputString .= '</div>';
}
if (config('form-maker.form.orientation') == 'horizontal' && !in_array($method, $this->selectedMethods)) {
return '<div class="'.config('form-maker.form.input-column', '').'">'.$inputString.'</div>';
}
return $inputString;
} | php | public function inputStringPreparer($config)
{
$inputString = '';
$beforeAfterCondition = ($this->before($config) > '' || $this->after($config) > '');
$method = $this->getGeneratorMethod($config['inputType']);
if ($beforeAfterCondition) {
$inputString .= '<div class="'.config('form-maker.form.before_after_input_wrapper', 'input-group').'">';
}
$inputString .= $this->before($config);
$inputString .= $this->inputStringGenerator($config);
$inputString .= $this->after($config);
if ($beforeAfterCondition) {
$inputString .= '</div>';
}
if (config('form-maker.form.orientation') == 'horizontal' && !in_array($method, $this->selectedMethods)) {
return '<div class="'.config('form-maker.form.input-column', '').'">'.$inputString.'</div>';
}
return $inputString;
} | [
"public",
"function",
"inputStringPreparer",
"(",
"$",
"config",
")",
"{",
"$",
"inputString",
"=",
"''",
";",
"$",
"beforeAfterCondition",
"=",
"(",
"$",
"this",
"->",
"before",
"(",
"$",
"config",
")",
">",
"''",
"||",
"$",
"this",
"->",
"after",
"(",
"$",
"config",
")",
">",
"''",
")",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"getGeneratorMethod",
"(",
"$",
"config",
"[",
"'inputType'",
"]",
")",
";",
"if",
"(",
"$",
"beforeAfterCondition",
")",
"{",
"$",
"inputString",
".=",
"'<div class=\"'",
".",
"config",
"(",
"'form-maker.form.before_after_input_wrapper'",
",",
"'input-group'",
")",
".",
"'\">'",
";",
"}",
"$",
"inputString",
".=",
"$",
"this",
"->",
"before",
"(",
"$",
"config",
")",
";",
"$",
"inputString",
".=",
"$",
"this",
"->",
"inputStringGenerator",
"(",
"$",
"config",
")",
";",
"$",
"inputString",
".=",
"$",
"this",
"->",
"after",
"(",
"$",
"config",
")",
";",
"if",
"(",
"$",
"beforeAfterCondition",
")",
"{",
"$",
"inputString",
".=",
"'</div>'",
";",
"}",
"if",
"(",
"config",
"(",
"'form-maker.form.orientation'",
")",
"==",
"'horizontal'",
"&&",
"!",
"in_array",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"selectedMethods",
")",
")",
"{",
"return",
"'<div class=\"'",
".",
"config",
"(",
"'form-maker.form.input-column'",
",",
"''",
")",
".",
"'\">'",
".",
"$",
"inputString",
".",
"'</div>'",
";",
"}",
"return",
"$",
"inputString",
";",
"}"
] | Input string preparer.
@param array $config
@return string | [
"Input",
"string",
"preparer",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L137-L160 |
31,374 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.label | public function label($name, $attributes = [])
{
$attributeString = '';
if (!isset($attributes['for'])) {
$attributeString = 'for="'.$name.'"';
}
foreach ($attributes as $key => $value) {
$attributeString .= $key.'="'.$value.'" ';
}
return '<label '.$attributeString.'>'.$name.'</label>';
} | php | public function label($name, $attributes = [])
{
$attributeString = '';
if (!isset($attributes['for'])) {
$attributeString = 'for="'.$name.'"';
}
foreach ($attributes as $key => $value) {
$attributeString .= $key.'="'.$value.'" ';
}
return '<label '.$attributeString.'>'.$name.'</label>';
} | [
"public",
"function",
"label",
"(",
"$",
"name",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"attributeString",
"=",
"''",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'for'",
"]",
")",
")",
"{",
"$",
"attributeString",
"=",
"'for=\"'",
".",
"$",
"name",
".",
"'\"'",
";",
"}",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributeString",
".=",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\" '",
";",
"}",
"return",
"'<label '",
".",
"$",
"attributeString",
".",
"'>'",
".",
"$",
"name",
".",
"'</label>'",
";",
"}"
] | Create a label for an input.
@param string $name
@param array $attributes
@return string | [
"Create",
"a",
"label",
"for",
"an",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L170-L183 |
31,375 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.refineConfigs | private function refineConfigs($inputConfig, $reformatted, $name, $config)
{
// If validation inputs are available lets prepopulate the fields!
if (!empty($inputConfig['inputs']) && isset($inputConfig['inputs'][$name])) {
$inputConfig['populated'] = true;
$inputConfig['objectValue'] = $inputConfig['inputs'][$name];
} elseif (isset($inputConfig['config']['default_value'])) {
$inputConfig['objectValue'] = $inputConfig['config']['default_value'];
}
if ($reformatted) {
$inputConfig['placeholder'] = $this->inputCalibrator->cleanString($this->inputCalibrator->placeholder($config, $name));
}
if (!isset($config['type'])) {
if (is_array($config)) {
$inputConfig['inputType'] = 'string';
} else {
$inputConfig['inputType'] = $config;
}
} else {
$inputConfig['inputType'] = $config['type'];
}
return $inputConfig;
} | php | private function refineConfigs($inputConfig, $reformatted, $name, $config)
{
// If validation inputs are available lets prepopulate the fields!
if (!empty($inputConfig['inputs']) && isset($inputConfig['inputs'][$name])) {
$inputConfig['populated'] = true;
$inputConfig['objectValue'] = $inputConfig['inputs'][$name];
} elseif (isset($inputConfig['config']['default_value'])) {
$inputConfig['objectValue'] = $inputConfig['config']['default_value'];
}
if ($reformatted) {
$inputConfig['placeholder'] = $this->inputCalibrator->cleanString($this->inputCalibrator->placeholder($config, $name));
}
if (!isset($config['type'])) {
if (is_array($config)) {
$inputConfig['inputType'] = 'string';
} else {
$inputConfig['inputType'] = $config;
}
} else {
$inputConfig['inputType'] = $config['type'];
}
return $inputConfig;
} | [
"private",
"function",
"refineConfigs",
"(",
"$",
"inputConfig",
",",
"$",
"reformatted",
",",
"$",
"name",
",",
"$",
"config",
")",
"{",
"// If validation inputs are available lets prepopulate the fields!",
"if",
"(",
"!",
"empty",
"(",
"$",
"inputConfig",
"[",
"'inputs'",
"]",
")",
"&&",
"isset",
"(",
"$",
"inputConfig",
"[",
"'inputs'",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"inputConfig",
"[",
"'populated'",
"]",
"=",
"true",
";",
"$",
"inputConfig",
"[",
"'objectValue'",
"]",
"=",
"$",
"inputConfig",
"[",
"'inputs'",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"inputConfig",
"[",
"'config'",
"]",
"[",
"'default_value'",
"]",
")",
")",
"{",
"$",
"inputConfig",
"[",
"'objectValue'",
"]",
"=",
"$",
"inputConfig",
"[",
"'config'",
"]",
"[",
"'default_value'",
"]",
";",
"}",
"if",
"(",
"$",
"reformatted",
")",
"{",
"$",
"inputConfig",
"[",
"'placeholder'",
"]",
"=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"cleanString",
"(",
"$",
"this",
"->",
"inputCalibrator",
"->",
"placeholder",
"(",
"$",
"config",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'type'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"$",
"inputConfig",
"[",
"'inputType'",
"]",
"=",
"'string'",
";",
"}",
"else",
"{",
"$",
"inputConfig",
"[",
"'inputType'",
"]",
"=",
"$",
"config",
";",
"}",
"}",
"else",
"{",
"$",
"inputConfig",
"[",
"'inputType'",
"]",
"=",
"$",
"config",
"[",
"'type'",
"]",
";",
"}",
"return",
"$",
"inputConfig",
";",
"}"
] | Set the configs.
@param array $config
@param bool $reformatted
@param string $name
@param array $config
@return array | [
"Set",
"the",
"configs",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L257-L282 |
31,376 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.inputStringGenerator | private function inputStringGenerator($config)
{
$config = $this->prepareObjectValue($config);
$population = $this->inputCalibrator->getPopulation($config);
$checkType = $this->inputCalibrator->checkType($config, $this->inputGroups['checkbox']);
$selected = $this->inputCalibrator->isSelected($config, $checkType);
$custom = $this->inputCalibrator->getField($config, 'custom');
$method = $this->getGeneratorMethod($config['inputType']);
if (in_array($method, $this->standardMethods)) {
$inputString = $this->htmlGenerator->$method($config, $population, $custom);
} elseif (in_array($method, $this->selectedMethods)) {
// add extra class
$inputString = $this->htmlGenerator->$method($config, $selected, $custom);
} elseif ($method === 'makeRelationship') {
$inputString = $this->htmlGenerator->makeRelationship(
$config,
$this->inputCalibrator->getField($config, 'label', 'name'),
$this->inputCalibrator->getField($config, 'value', 'id'),
$custom
);
} else {
$config = $this->prepareType($config);
$inputString = $this->htmlGenerator->makeHTMLInputString($config);
}
return $inputString;
} | php | private function inputStringGenerator($config)
{
$config = $this->prepareObjectValue($config);
$population = $this->inputCalibrator->getPopulation($config);
$checkType = $this->inputCalibrator->checkType($config, $this->inputGroups['checkbox']);
$selected = $this->inputCalibrator->isSelected($config, $checkType);
$custom = $this->inputCalibrator->getField($config, 'custom');
$method = $this->getGeneratorMethod($config['inputType']);
if (in_array($method, $this->standardMethods)) {
$inputString = $this->htmlGenerator->$method($config, $population, $custom);
} elseif (in_array($method, $this->selectedMethods)) {
// add extra class
$inputString = $this->htmlGenerator->$method($config, $selected, $custom);
} elseif ($method === 'makeRelationship') {
$inputString = $this->htmlGenerator->makeRelationship(
$config,
$this->inputCalibrator->getField($config, 'label', 'name'),
$this->inputCalibrator->getField($config, 'value', 'id'),
$custom
);
} else {
$config = $this->prepareType($config);
$inputString = $this->htmlGenerator->makeHTMLInputString($config);
}
return $inputString;
} | [
"private",
"function",
"inputStringGenerator",
"(",
"$",
"config",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"prepareObjectValue",
"(",
"$",
"config",
")",
";",
"$",
"population",
"=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getPopulation",
"(",
"$",
"config",
")",
";",
"$",
"checkType",
"=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"checkType",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'checkbox'",
"]",
")",
";",
"$",
"selected",
"=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"isSelected",
"(",
"$",
"config",
",",
"$",
"checkType",
")",
";",
"$",
"custom",
"=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getField",
"(",
"$",
"config",
",",
"'custom'",
")",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"getGeneratorMethod",
"(",
"$",
"config",
"[",
"'inputType'",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"standardMethods",
")",
")",
"{",
"$",
"inputString",
"=",
"$",
"this",
"->",
"htmlGenerator",
"->",
"$",
"method",
"(",
"$",
"config",
",",
"$",
"population",
",",
"$",
"custom",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"selectedMethods",
")",
")",
"{",
"// add extra class",
"$",
"inputString",
"=",
"$",
"this",
"->",
"htmlGenerator",
"->",
"$",
"method",
"(",
"$",
"config",
",",
"$",
"selected",
",",
"$",
"custom",
")",
";",
"}",
"elseif",
"(",
"$",
"method",
"===",
"'makeRelationship'",
")",
"{",
"$",
"inputString",
"=",
"$",
"this",
"->",
"htmlGenerator",
"->",
"makeRelationship",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getField",
"(",
"$",
"config",
",",
"'label'",
",",
"'name'",
")",
",",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getField",
"(",
"$",
"config",
",",
"'value'",
",",
"'id'",
")",
",",
"$",
"custom",
")",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"prepareType",
"(",
"$",
"config",
")",
";",
"$",
"inputString",
"=",
"$",
"this",
"->",
"htmlGenerator",
"->",
"makeHTMLInputString",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"inputString",
";",
"}"
] | The input string generator.
@param array $config Config
@return string | [
"The",
"input",
"string",
"generator",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L291-L319 |
31,377 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.prepareType | public function prepareType($config)
{
$config['type'] = $config['inputTypes']['string'];
if (isset($config['inputTypes'][$config['inputType']])) {
$config['type'] = $config['inputTypes'][$config['inputType']];
}
return $config;
} | php | public function prepareType($config)
{
$config['type'] = $config['inputTypes']['string'];
if (isset($config['inputTypes'][$config['inputType']])) {
$config['type'] = $config['inputTypes'][$config['inputType']];
}
return $config;
} | [
"public",
"function",
"prepareType",
"(",
"$",
"config",
")",
"{",
"$",
"config",
"[",
"'type'",
"]",
"=",
"$",
"config",
"[",
"'inputTypes'",
"]",
"[",
"'string'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'inputTypes'",
"]",
"[",
"$",
"config",
"[",
"'inputType'",
"]",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'type'",
"]",
"=",
"$",
"config",
"[",
"'inputTypes'",
"]",
"[",
"$",
"config",
"[",
"'inputType'",
"]",
"]",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | prepare the type.
@param array $config
@return array | [
"prepare",
"the",
"type",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L328-L337 |
31,378 | GrafiteInc/FormMaker | src/Services/InputMaker.php | InputMaker.getGeneratorMethod | public function getGeneratorMethod($type)
{
switch ($type) {
case in_array($type, $this->inputGroups['hidden']):
return 'makeHidden';
case in_array($type, $this->inputGroups['text']):
return 'makeText';
case in_array($type, $this->inputGroups['select']):
return 'makeSelected';
case in_array($type, $this->inputGroups['checkbox']):
return 'makeCheckbox';
case in_array($type, $this->inputGroups['radio']):
return 'makeRadio';
case in_array($type, $this->inputGroups['relationship']):
return 'makeRelationship';
default:
return 'makeHTMLInputString';
}
} | php | public function getGeneratorMethod($type)
{
switch ($type) {
case in_array($type, $this->inputGroups['hidden']):
return 'makeHidden';
case in_array($type, $this->inputGroups['text']):
return 'makeText';
case in_array($type, $this->inputGroups['select']):
return 'makeSelected';
case in_array($type, $this->inputGroups['checkbox']):
return 'makeCheckbox';
case in_array($type, $this->inputGroups['radio']):
return 'makeRadio';
case in_array($type, $this->inputGroups['relationship']):
return 'makeRelationship';
default:
return 'makeHTMLInputString';
}
} | [
"public",
"function",
"getGeneratorMethod",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'hidden'",
"]",
")",
":",
"return",
"'makeHidden'",
";",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'text'",
"]",
")",
":",
"return",
"'makeText'",
";",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'select'",
"]",
")",
":",
"return",
"'makeSelected'",
";",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'checkbox'",
"]",
")",
":",
"return",
"'makeCheckbox'",
";",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'radio'",
"]",
")",
":",
"return",
"'makeRadio'",
";",
"case",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"inputGroups",
"[",
"'relationship'",
"]",
")",
":",
"return",
"'makeRelationship'",
";",
"default",
":",
"return",
"'makeHTMLInputString'",
";",
"}",
"}"
] | Get the generator method.
@param string $type
@return string | [
"Get",
"the",
"generator",
"method",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputMaker.php#L362-L386 |
31,379 | GrafiteInc/FormMaker | src/Services/InputCalibrator.php | InputCalibrator.getId | public function getId($name, $config)
{
$inputId = str_replace('[]', '', ucfirst($name));
if (isset($config['id'])) {
$inputId = $config['id'];
}
return $inputId;
} | php | public function getId($name, $config)
{
$inputId = str_replace('[]', '', ucfirst($name));
if (isset($config['id'])) {
$inputId = $config['id'];
}
return $inputId;
} | [
"public",
"function",
"getId",
"(",
"$",
"name",
",",
"$",
"config",
")",
"{",
"$",
"inputId",
"=",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"ucfirst",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"inputId",
"=",
"$",
"config",
"[",
"'id'",
"]",
";",
"}",
"return",
"$",
"inputId",
";",
"}"
] | Customizable input name
@param string $name
@param array $config
@return string | [
"Customizable",
"input",
"name"
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputCalibrator.php#L68-L77 |
31,380 | GrafiteInc/FormMaker | src/Services/InputCalibrator.php | InputCalibrator.isSelected | public function isSelected($config, $checkType)
{
$selected = false;
if (!is_object($config['objectValue'])) {
$selected = (isset($config['inputs'][$config['name']])
|| isset($config['config']['selected'])
|| $config['objectValue'] === 'on'
|| ($config['objectValue'] == 1 && $checkType == 'checked')
|| is_array(json_decode($config['objectValue']))) ? $checkType : '';
}
return $selected;
} | php | public function isSelected($config, $checkType)
{
$selected = false;
if (!is_object($config['objectValue'])) {
$selected = (isset($config['inputs'][$config['name']])
|| isset($config['config']['selected'])
|| $config['objectValue'] === 'on'
|| ($config['objectValue'] == 1 && $checkType == 'checked')
|| is_array(json_decode($config['objectValue']))) ? $checkType : '';
}
return $selected;
} | [
"public",
"function",
"isSelected",
"(",
"$",
"config",
",",
"$",
"checkType",
")",
"{",
"$",
"selected",
"=",
"false",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
")",
"{",
"$",
"selected",
"=",
"(",
"isset",
"(",
"$",
"config",
"[",
"'inputs'",
"]",
"[",
"$",
"config",
"[",
"'name'",
"]",
"]",
")",
"||",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'selected'",
"]",
")",
"||",
"$",
"config",
"[",
"'objectValue'",
"]",
"===",
"'on'",
"||",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
"==",
"1",
"&&",
"$",
"checkType",
"==",
"'checked'",
")",
"||",
"is_array",
"(",
"json_decode",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
")",
")",
"?",
"$",
"checkType",
":",
"''",
";",
"}",
"return",
"$",
"selected",
";",
"}"
] | Has been selected.
@param array $config
@param string $checkType Type of checkmark
@return bool | [
"Has",
"been",
"selected",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputCalibrator.php#L87-L100 |
31,381 | GrafiteInc/FormMaker | src/Services/InputCalibrator.php | InputCalibrator.placeholder | public function placeholder($field, $column)
{
if (!is_array($field) && !in_array($field, $this->columnTypes)) {
return ucfirst($field);
}
if (strpos($column, '[') > 0) {
$nested = explode('[', str_replace(']', '', $column));
$column = implode(' ', $nested);
}
$alt_name = (isset($field['alt_name'])) ? $field['alt_name'] : ucfirst($column);
$placeholder = (isset($field['placeholder'])) ? $field['placeholder'] : $this->cleanString($alt_name);
return $placeholder;
} | php | public function placeholder($field, $column)
{
if (!is_array($field) && !in_array($field, $this->columnTypes)) {
return ucfirst($field);
}
if (strpos($column, '[') > 0) {
$nested = explode('[', str_replace(']', '', $column));
$column = implode(' ', $nested);
}
$alt_name = (isset($field['alt_name'])) ? $field['alt_name'] : ucfirst($column);
$placeholder = (isset($field['placeholder'])) ? $field['placeholder'] : $this->cleanString($alt_name);
return $placeholder;
} | [
"public",
"function",
"placeholder",
"(",
"$",
"field",
",",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"field",
")",
"&&",
"!",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"columnTypes",
")",
")",
"{",
"return",
"ucfirst",
"(",
"$",
"field",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"column",
",",
"'['",
")",
">",
"0",
")",
"{",
"$",
"nested",
"=",
"explode",
"(",
"'['",
",",
"str_replace",
"(",
"']'",
",",
"''",
",",
"$",
"column",
")",
")",
";",
"$",
"column",
"=",
"implode",
"(",
"' '",
",",
"$",
"nested",
")",
";",
"}",
"$",
"alt_name",
"=",
"(",
"isset",
"(",
"$",
"field",
"[",
"'alt_name'",
"]",
")",
")",
"?",
"$",
"field",
"[",
"'alt_name'",
"]",
":",
"ucfirst",
"(",
"$",
"column",
")",
";",
"$",
"placeholder",
"=",
"(",
"isset",
"(",
"$",
"field",
"[",
"'placeholder'",
"]",
")",
")",
"?",
"$",
"field",
"[",
"'placeholder'",
"]",
":",
"$",
"this",
"->",
"cleanString",
"(",
"$",
"alt_name",
")",
";",
"return",
"$",
"placeholder",
";",
"}"
] | Create the placeholder.
@param array $field Field from Column Array
@param string $column Column name
@return string | [
"Create",
"the",
"placeholder",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/InputCalibrator.php#L139-L154 |
31,382 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.fromTable | public function fromTable(
$table,
$columns = null,
$class = null,
$view = null,
$reformatted = true,
$populated = false,
$idAndTimestamps = false
) {
$formBuild = [];
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$tableColumns = $this->getTableColumns($table, true);
if (is_null($columns)) {
foreach ($tableColumns as $column => $value) {
$columns[$column] = $value['type'];
}
}
if (!$idAndTimestamps) {
unset($columns['id']);
unset($columns['created_at']);
unset($columns['updated_at']);
unset($columns['deleted_at']);
}
foreach ($columns as $column => $columnConfig) {
if (is_numeric($column)) {
$column = $columnConfig;
}
$errors = $this->getFormErrors();
$input = $this->inputMaker->create($column, $columnConfig, $column, $class, $reformatted, $populated);
$formBuild[] = $this->formBuilder($view, $errors, $columnConfig, $column, $input);
}
return $this->buildUsingColumns($formBuild, config('form-maker.form.theme'));
} | php | public function fromTable(
$table,
$columns = null,
$class = null,
$view = null,
$reformatted = true,
$populated = false,
$idAndTimestamps = false
) {
$formBuild = [];
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$tableColumns = $this->getTableColumns($table, true);
if (is_null($columns)) {
foreach ($tableColumns as $column => $value) {
$columns[$column] = $value['type'];
}
}
if (!$idAndTimestamps) {
unset($columns['id']);
unset($columns['created_at']);
unset($columns['updated_at']);
unset($columns['deleted_at']);
}
foreach ($columns as $column => $columnConfig) {
if (is_numeric($column)) {
$column = $columnConfig;
}
$errors = $this->getFormErrors();
$input = $this->inputMaker->create($column, $columnConfig, $column, $class, $reformatted, $populated);
$formBuild[] = $this->formBuilder($view, $errors, $columnConfig, $column, $input);
}
return $this->buildUsingColumns($formBuild, config('form-maker.form.theme'));
} | [
"public",
"function",
"fromTable",
"(",
"$",
"table",
",",
"$",
"columns",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"view",
"=",
"null",
",",
"$",
"reformatted",
"=",
"true",
",",
"$",
"populated",
"=",
"false",
",",
"$",
"idAndTimestamps",
"=",
"false",
")",
"{",
"$",
"formBuild",
"=",
"[",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"config",
"(",
"'form-maker.forms.form-class'",
",",
"'form-control'",
")",
";",
"}",
"$",
"tableColumns",
"=",
"$",
"this",
"->",
"getTableColumns",
"(",
"$",
"table",
",",
"true",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"columns",
")",
")",
"{",
"foreach",
"(",
"$",
"tableColumns",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"columns",
"[",
"$",
"column",
"]",
"=",
"$",
"value",
"[",
"'type'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"idAndTimestamps",
")",
"{",
"unset",
"(",
"$",
"columns",
"[",
"'id'",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'created_at'",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'updated_at'",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"'deleted_at'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
"=>",
"$",
"columnConfig",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"columnConfig",
";",
"}",
"$",
"errors",
"=",
"$",
"this",
"->",
"getFormErrors",
"(",
")",
";",
"$",
"input",
"=",
"$",
"this",
"->",
"inputMaker",
"->",
"create",
"(",
"$",
"column",
",",
"$",
"columnConfig",
",",
"$",
"column",
",",
"$",
"class",
",",
"$",
"reformatted",
",",
"$",
"populated",
")",
";",
"$",
"formBuild",
"[",
"]",
"=",
"$",
"this",
"->",
"formBuilder",
"(",
"$",
"view",
",",
"$",
"errors",
",",
"$",
"columnConfig",
",",
"$",
"column",
",",
"$",
"input",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildUsingColumns",
"(",
"$",
"formBuild",
",",
"config",
"(",
"'form-maker.form.theme'",
")",
")",
";",
"}"
] | Generate a form from a table.
@param string $table Table name
@param array $columns Array of columns and details regarding them see config/forms.php for examples
@param string $class Class names to be given to the inputs
@param string $view View to use - for custom form layouts
@param bool $reformatted Corrects the table column names to clean words if no columns array provided
@param bool $populated Populates the inputs with the column names as values
@param bool $idAndTimestamps Allows id and Timestamp columns
@return string | [
"Generate",
"a",
"form",
"from",
"a",
"table",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L88-L128 |
31,383 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.fromArray | public function fromArray(
$array,
$columns = null,
$view = null,
$class = null,
$populated = true,
$reformatted = false,
$timestamps = false
) {
$formBuild = [];
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$array = $this->cleanupIdAndTimeStamps($array, $timestamps, false);
$errors = $this->getFormErrors();
if (is_null($columns)) {
$columns = $array;
}
foreach ($columns as $column => $columnConfig) {
if (is_numeric($column)) {
$column = $columnConfig;
}
if ($column === 'id') {
$columnConfig = ['type' => 'hidden'];
}
$input = $this->inputMaker->create($column, $columnConfig, $array, $class, $reformatted, $populated);
$formBuild[] = $this->formBuilder($view, $errors, $columnConfig, $column, $input);
}
return $this->buildUsingColumns($formBuild, config('form-maker.form.theme'));
} | php | public function fromArray(
$array,
$columns = null,
$view = null,
$class = null,
$populated = true,
$reformatted = false,
$timestamps = false
) {
$formBuild = [];
if (is_null($class)) {
$class = config('form-maker.forms.form-class', 'form-control');
}
$array = $this->cleanupIdAndTimeStamps($array, $timestamps, false);
$errors = $this->getFormErrors();
if (is_null($columns)) {
$columns = $array;
}
foreach ($columns as $column => $columnConfig) {
if (is_numeric($column)) {
$column = $columnConfig;
}
if ($column === 'id') {
$columnConfig = ['type' => 'hidden'];
}
$input = $this->inputMaker->create($column, $columnConfig, $array, $class, $reformatted, $populated);
$formBuild[] = $this->formBuilder($view, $errors, $columnConfig, $column, $input);
}
return $this->buildUsingColumns($formBuild, config('form-maker.form.theme'));
} | [
"public",
"function",
"fromArray",
"(",
"$",
"array",
",",
"$",
"columns",
"=",
"null",
",",
"$",
"view",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"populated",
"=",
"true",
",",
"$",
"reformatted",
"=",
"false",
",",
"$",
"timestamps",
"=",
"false",
")",
"{",
"$",
"formBuild",
"=",
"[",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"config",
"(",
"'form-maker.forms.form-class'",
",",
"'form-control'",
")",
";",
"}",
"$",
"array",
"=",
"$",
"this",
"->",
"cleanupIdAndTimeStamps",
"(",
"$",
"array",
",",
"$",
"timestamps",
",",
"false",
")",
";",
"$",
"errors",
"=",
"$",
"this",
"->",
"getFormErrors",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"$",
"array",
";",
"}",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
"=>",
"$",
"columnConfig",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"columnConfig",
";",
"}",
"if",
"(",
"$",
"column",
"===",
"'id'",
")",
"{",
"$",
"columnConfig",
"=",
"[",
"'type'",
"=>",
"'hidden'",
"]",
";",
"}",
"$",
"input",
"=",
"$",
"this",
"->",
"inputMaker",
"->",
"create",
"(",
"$",
"column",
",",
"$",
"columnConfig",
",",
"$",
"array",
",",
"$",
"class",
",",
"$",
"reformatted",
",",
"$",
"populated",
")",
";",
"$",
"formBuild",
"[",
"]",
"=",
"$",
"this",
"->",
"formBuilder",
"(",
"$",
"view",
",",
"$",
"errors",
",",
"$",
"columnConfig",
",",
"$",
"column",
",",
"$",
"input",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildUsingColumns",
"(",
"$",
"formBuild",
",",
"config",
"(",
"'form-maker.form.theme'",
")",
")",
";",
"}"
] | Build the form from an array.
@param array $array
@param array $columns
@param string $view A template to use for the rows
@param string $class Default input class
@param bool $populated Is content populated
@param bool $reformatted Are column names reformatted
@param bool $timestamps Are the timestamps available?
@return string | [
"Build",
"the",
"form",
"from",
"an",
"array",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L143-L178 |
31,384 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.cleanupIdAndTimeStamps | public function cleanupIdAndTimeStamps($collection, $timestamps, $id)
{
if (!$timestamps) {
unset($collection['created_at']);
unset($collection['updated_at']);
}
if (!$id) {
unset($collection['id']);
}
return $collection;
} | php | public function cleanupIdAndTimeStamps($collection, $timestamps, $id)
{
if (!$timestamps) {
unset($collection['created_at']);
unset($collection['updated_at']);
}
if (!$id) {
unset($collection['id']);
}
return $collection;
} | [
"public",
"function",
"cleanupIdAndTimeStamps",
"(",
"$",
"collection",
",",
"$",
"timestamps",
",",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"timestamps",
")",
"{",
"unset",
"(",
"$",
"collection",
"[",
"'created_at'",
"]",
")",
";",
"unset",
"(",
"$",
"collection",
"[",
"'updated_at'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"unset",
"(",
"$",
"collection",
"[",
"'id'",
"]",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Cleanup the ID and TimeStamp columns.
@param array $collection
@param bool $timestamps
@param bool $id
@return array | [
"Cleanup",
"the",
"ID",
"and",
"TimeStamp",
"columns",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L238-L250 |
31,385 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.formBuilder | private function formBuilder($view, $errors, $field, $column, $input)
{
$formGroupClass = config('form-maker.form.group-class', 'form-group');
$formErrorClass = config('form-maker.form.error-class', 'has-error');
$errorHighlight = '';
$errorMessage = false;
if (!empty($errors) && $errors->has($column)) {
$errorHighlight = ' '.$formErrorClass;
$errorMessage = $errors->get($column);
}
if (is_null($view)) {
$formBuild = '<div class="'.$formGroupClass.' '.$errorHighlight.'">';
$formBuild .= $this->formContentBuild($field, $column, $input, $errorMessage);
$formBuild .= '</div>';
} else {
$formBuild = View::make($view, [
'labelFor' => ucfirst($column),
'label' => $this->columnLabel($field, $column),
'input' => $input,
'field' => $field,
'errorMessage' => $this->errorMessage($errorMessage),
'errorHighlight' => $errorHighlight,
]);
}
return $formBuild;
} | php | private function formBuilder($view, $errors, $field, $column, $input)
{
$formGroupClass = config('form-maker.form.group-class', 'form-group');
$formErrorClass = config('form-maker.form.error-class', 'has-error');
$errorHighlight = '';
$errorMessage = false;
if (!empty($errors) && $errors->has($column)) {
$errorHighlight = ' '.$formErrorClass;
$errorMessage = $errors->get($column);
}
if (is_null($view)) {
$formBuild = '<div class="'.$formGroupClass.' '.$errorHighlight.'">';
$formBuild .= $this->formContentBuild($field, $column, $input, $errorMessage);
$formBuild .= '</div>';
} else {
$formBuild = View::make($view, [
'labelFor' => ucfirst($column),
'label' => $this->columnLabel($field, $column),
'input' => $input,
'field' => $field,
'errorMessage' => $this->errorMessage($errorMessage),
'errorHighlight' => $errorHighlight,
]);
}
return $formBuild;
} | [
"private",
"function",
"formBuilder",
"(",
"$",
"view",
",",
"$",
"errors",
",",
"$",
"field",
",",
"$",
"column",
",",
"$",
"input",
")",
"{",
"$",
"formGroupClass",
"=",
"config",
"(",
"'form-maker.form.group-class'",
",",
"'form-group'",
")",
";",
"$",
"formErrorClass",
"=",
"config",
"(",
"'form-maker.form.error-class'",
",",
"'has-error'",
")",
";",
"$",
"errorHighlight",
"=",
"''",
";",
"$",
"errorMessage",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
"&&",
"$",
"errors",
"->",
"has",
"(",
"$",
"column",
")",
")",
"{",
"$",
"errorHighlight",
"=",
"' '",
".",
"$",
"formErrorClass",
";",
"$",
"errorMessage",
"=",
"$",
"errors",
"->",
"get",
"(",
"$",
"column",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"view",
")",
")",
"{",
"$",
"formBuild",
"=",
"'<div class=\"'",
".",
"$",
"formGroupClass",
".",
"' '",
".",
"$",
"errorHighlight",
".",
"'\">'",
";",
"$",
"formBuild",
".=",
"$",
"this",
"->",
"formContentBuild",
"(",
"$",
"field",
",",
"$",
"column",
",",
"$",
"input",
",",
"$",
"errorMessage",
")",
";",
"$",
"formBuild",
".=",
"'</div>'",
";",
"}",
"else",
"{",
"$",
"formBuild",
"=",
"View",
"::",
"make",
"(",
"$",
"view",
",",
"[",
"'labelFor'",
"=>",
"ucfirst",
"(",
"$",
"column",
")",
",",
"'label'",
"=>",
"$",
"this",
"->",
"columnLabel",
"(",
"$",
"field",
",",
"$",
"column",
")",
",",
"'input'",
"=>",
"$",
"input",
",",
"'field'",
"=>",
"$",
"field",
",",
"'errorMessage'",
"=>",
"$",
"this",
"->",
"errorMessage",
"(",
"$",
"errorMessage",
")",
",",
"'errorHighlight'",
"=>",
"$",
"errorHighlight",
",",
"]",
")",
";",
"}",
"return",
"$",
"formBuild",
";",
"}"
] | Constructs HTML forms.
@param string $view View template
@param array|object $errors
@param array $field Array of field values
@param string $column Column name
@param string $input Input string
@return string | [
"Constructs",
"HTML",
"forms",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L279-L308 |
31,386 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.formContentBuild | public function formContentBuild($field, $column, $input, $errorMessage)
{
$labelColumn = $labelCheckableColumn = '';
$singleLineCheckType = false;
$formLabelClass = config('form-maker.form.label-class', 'control-label');
if (config('form-maker.form.orientation') == 'horizontal') {
$labelColumn = config('form-maker.form.label-column');
$labelCheckableColumn = config('form-maker.form.checkbox-column');
$singleLineCheckType = true;
}
$name = ucfirst($this->inputCalibrator->getName($column, $field));
$formBuild = '<label class="'.trim($formLabelClass.' '.$labelColumn).'" for="'.$name.'">';
$formBuild .= $this->inputCalibrator->cleanString($this->columnLabel($field, $column));
$formBuild .= '</label>'.$input.$this->errorMessage($errorMessage);
if (isset($field['type'])) {
if (in_array($field['type'], ['radio', 'checkbox'])) {
$formBuild = '<div class="'.$field['type'].'">';
if ($singleLineCheckType) {
$formBuild .= '<div class="'.$labelCheckableColumn.'">';
}
$formBuild .= '<label for="'.ucfirst($column).'" class="'.$formLabelClass.'">'.$input;
$formBuild .= $this->inputCalibrator->cleanString($this->columnLabel($field, $column));
$formBuild .= '</label>'.$this->errorMessage($errorMessage).'</div>';
if ($singleLineCheckType) {
$formBuild .= '</div>';
}
} elseif (stristr($field['type'], 'hidden')) {
$formBuild = $input;
}
}
return $formBuild;
} | php | public function formContentBuild($field, $column, $input, $errorMessage)
{
$labelColumn = $labelCheckableColumn = '';
$singleLineCheckType = false;
$formLabelClass = config('form-maker.form.label-class', 'control-label');
if (config('form-maker.form.orientation') == 'horizontal') {
$labelColumn = config('form-maker.form.label-column');
$labelCheckableColumn = config('form-maker.form.checkbox-column');
$singleLineCheckType = true;
}
$name = ucfirst($this->inputCalibrator->getName($column, $field));
$formBuild = '<label class="'.trim($formLabelClass.' '.$labelColumn).'" for="'.$name.'">';
$formBuild .= $this->inputCalibrator->cleanString($this->columnLabel($field, $column));
$formBuild .= '</label>'.$input.$this->errorMessage($errorMessage);
if (isset($field['type'])) {
if (in_array($field['type'], ['radio', 'checkbox'])) {
$formBuild = '<div class="'.$field['type'].'">';
if ($singleLineCheckType) {
$formBuild .= '<div class="'.$labelCheckableColumn.'">';
}
$formBuild .= '<label for="'.ucfirst($column).'" class="'.$formLabelClass.'">'.$input;
$formBuild .= $this->inputCalibrator->cleanString($this->columnLabel($field, $column));
$formBuild .= '</label>'.$this->errorMessage($errorMessage).'</div>';
if ($singleLineCheckType) {
$formBuild .= '</div>';
}
} elseif (stristr($field['type'], 'hidden')) {
$formBuild = $input;
}
}
return $formBuild;
} | [
"public",
"function",
"formContentBuild",
"(",
"$",
"field",
",",
"$",
"column",
",",
"$",
"input",
",",
"$",
"errorMessage",
")",
"{",
"$",
"labelColumn",
"=",
"$",
"labelCheckableColumn",
"=",
"''",
";",
"$",
"singleLineCheckType",
"=",
"false",
";",
"$",
"formLabelClass",
"=",
"config",
"(",
"'form-maker.form.label-class'",
",",
"'control-label'",
")",
";",
"if",
"(",
"config",
"(",
"'form-maker.form.orientation'",
")",
"==",
"'horizontal'",
")",
"{",
"$",
"labelColumn",
"=",
"config",
"(",
"'form-maker.form.label-column'",
")",
";",
"$",
"labelCheckableColumn",
"=",
"config",
"(",
"'form-maker.form.checkbox-column'",
")",
";",
"$",
"singleLineCheckType",
"=",
"true",
";",
"}",
"$",
"name",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"inputCalibrator",
"->",
"getName",
"(",
"$",
"column",
",",
"$",
"field",
")",
")",
";",
"$",
"formBuild",
"=",
"'<label class=\"'",
".",
"trim",
"(",
"$",
"formLabelClass",
".",
"' '",
".",
"$",
"labelColumn",
")",
".",
"'\" for=\"'",
".",
"$",
"name",
".",
"'\">'",
";",
"$",
"formBuild",
".=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"cleanString",
"(",
"$",
"this",
"->",
"columnLabel",
"(",
"$",
"field",
",",
"$",
"column",
")",
")",
";",
"$",
"formBuild",
".=",
"'</label>'",
".",
"$",
"input",
".",
"$",
"this",
"->",
"errorMessage",
"(",
"$",
"errorMessage",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'type'",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"field",
"[",
"'type'",
"]",
",",
"[",
"'radio'",
",",
"'checkbox'",
"]",
")",
")",
"{",
"$",
"formBuild",
"=",
"'<div class=\"'",
".",
"$",
"field",
"[",
"'type'",
"]",
".",
"'\">'",
";",
"if",
"(",
"$",
"singleLineCheckType",
")",
"{",
"$",
"formBuild",
".=",
"'<div class=\"'",
".",
"$",
"labelCheckableColumn",
".",
"'\">'",
";",
"}",
"$",
"formBuild",
".=",
"'<label for=\"'",
".",
"ucfirst",
"(",
"$",
"column",
")",
".",
"'\" class=\"'",
".",
"$",
"formLabelClass",
".",
"'\">'",
".",
"$",
"input",
";",
"$",
"formBuild",
".=",
"$",
"this",
"->",
"inputCalibrator",
"->",
"cleanString",
"(",
"$",
"this",
"->",
"columnLabel",
"(",
"$",
"field",
",",
"$",
"column",
")",
")",
";",
"$",
"formBuild",
".=",
"'</label>'",
".",
"$",
"this",
"->",
"errorMessage",
"(",
"$",
"errorMessage",
")",
".",
"'</div>'",
";",
"if",
"(",
"$",
"singleLineCheckType",
")",
"{",
"$",
"formBuild",
".=",
"'</div>'",
";",
"}",
"}",
"elseif",
"(",
"stristr",
"(",
"$",
"field",
"[",
"'type'",
"]",
",",
"'hidden'",
")",
")",
"{",
"$",
"formBuild",
"=",
"$",
"input",
";",
"}",
"}",
"return",
"$",
"formBuild",
";",
"}"
] | Form Content Builder.
@param array $field Array of field values
@param string $column Column name
@param string $input Input string
@param string $errorMessage
@return string | [
"Form",
"Content",
"Builder",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L320-L356 |
31,387 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.buildBootstrapColumnForm | private function buildBootstrapColumnForm($formBuild, $columns)
{
$newFormBuild = [];
$formChunks = array_chunk($formBuild, $columns);
$class = 'col-md-'.(12 / $columns);
foreach ($formChunks as $chunk) {
$newFormBuild[] = '<div class="row">';
foreach ($chunk as $element) {
$newFormBuild[] = '<div class="'.$class.'">';
$newFormBuild[] = $element;
$newFormBuild[] = '</div>';
}
$newFormBuild[] = '</div>';
}
return implode("", $newFormBuild);
} | php | private function buildBootstrapColumnForm($formBuild, $columns)
{
$newFormBuild = [];
$formChunks = array_chunk($formBuild, $columns);
$class = 'col-md-'.(12 / $columns);
foreach ($formChunks as $chunk) {
$newFormBuild[] = '<div class="row">';
foreach ($chunk as $element) {
$newFormBuild[] = '<div class="'.$class.'">';
$newFormBuild[] = $element;
$newFormBuild[] = '</div>';
}
$newFormBuild[] = '</div>';
}
return implode("", $newFormBuild);
} | [
"private",
"function",
"buildBootstrapColumnForm",
"(",
"$",
"formBuild",
",",
"$",
"columns",
")",
"{",
"$",
"newFormBuild",
"=",
"[",
"]",
";",
"$",
"formChunks",
"=",
"array_chunk",
"(",
"$",
"formBuild",
",",
"$",
"columns",
")",
";",
"$",
"class",
"=",
"'col-md-'",
".",
"(",
"12",
"/",
"$",
"columns",
")",
";",
"foreach",
"(",
"$",
"formChunks",
"as",
"$",
"chunk",
")",
"{",
"$",
"newFormBuild",
"[",
"]",
"=",
"'<div class=\"row\">'",
";",
"foreach",
"(",
"$",
"chunk",
"as",
"$",
"element",
")",
"{",
"$",
"newFormBuild",
"[",
"]",
"=",
"'<div class=\"'",
".",
"$",
"class",
".",
"'\">'",
";",
"$",
"newFormBuild",
"[",
"]",
"=",
"$",
"element",
";",
"$",
"newFormBuild",
"[",
"]",
"=",
"'</div>'",
";",
"}",
"$",
"newFormBuild",
"[",
"]",
"=",
"'</div>'",
";",
"}",
"return",
"implode",
"(",
"\"\"",
",",
"$",
"newFormBuild",
")",
";",
"}"
] | Build a two column form using standard bootstrap classes
@param array $formBuild
@return string | [
"Build",
"a",
"two",
"column",
"form",
"using",
"standard",
"bootstrap",
"classes"
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L400-L417 |
31,388 | GrafiteInc/FormMaker | src/Services/FormMaker.php | FormMaker.columnLabel | private function columnLabel($field, $column)
{
if (!is_array($field) && !in_array($field, $this->columnTypes)) {
return ucfirst($field);
}
return (isset($field['alt_name'])) ? $field['alt_name'] : ucfirst($column);
} | php | private function columnLabel($field, $column)
{
if (!is_array($field) && !in_array($field, $this->columnTypes)) {
return ucfirst($field);
}
return (isset($field['alt_name'])) ? $field['alt_name'] : ucfirst($column);
} | [
"private",
"function",
"columnLabel",
"(",
"$",
"field",
",",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"field",
")",
"&&",
"!",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"columnTypes",
")",
")",
"{",
"return",
"ucfirst",
"(",
"$",
"field",
")",
";",
"}",
"return",
"(",
"isset",
"(",
"$",
"field",
"[",
"'alt_name'",
"]",
")",
")",
"?",
"$",
"field",
"[",
"'alt_name'",
"]",
":",
"ucfirst",
"(",
"$",
"column",
")",
";",
"}"
] | Create the column label.
@param array $field Field from Column Array
@param string $column Column name
@return string | [
"Create",
"the",
"column",
"label",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Services/FormMaker.php#L445-L452 |
31,389 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeHidden | public function makeHidden($config, $population, $custom)
{
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" name="'.$config['name'].'" type="hidden" value="'.$population.'">';
} | php | public function makeHidden($config, $population, $custom)
{
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" name="'.$config['name'].'" type="hidden" value="'.$population.'">';
} | [
"public",
"function",
"makeHidden",
"(",
"$",
"config",
",",
"$",
"population",
",",
"$",
"custom",
")",
"{",
"return",
"'<input '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"'\" type=\"hidden\" value=\"'",
".",
"$",
"population",
".",
"'\">'",
";",
"}"
] | Make a hidden input.
@param array $config
@param string $population
@param mixed $custom
@return string | [
"Make",
"a",
"hidden",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L27-L30 |
31,390 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeText | public function makeText($config, $population, $custom)
{
return '<textarea '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'" placeholder="'.$config['placeholder'].'">'.$population.'</textarea>';
} | php | public function makeText($config, $population, $custom)
{
return '<textarea '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'" placeholder="'.$config['placeholder'].'">'.$population.'</textarea>';
} | [
"public",
"function",
"makeText",
"(",
"$",
"config",
",",
"$",
"population",
",",
"$",
"custom",
")",
"{",
"return",
"'<textarea '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" class=\"'",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"'\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"'\" placeholder=\"'",
".",
"$",
"config",
"[",
"'placeholder'",
"]",
".",
"'\">'",
".",
"$",
"population",
".",
"'</textarea>'",
";",
"}"
] | Make text input.
@param array $config
@param string $population
@param mixed $custom
@return string | [
"Make",
"text",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L41-L44 |
31,391 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeSelected | public function makeSelected($config, $selected, $custom)
{
$options = $prefix = $suffix = '';
if (isset($config['config']['multiple'])) {
$custom = 'multiple';
$config['name'] = $config['name'].'[]';
}
if (config('form-maker.form.orientation') === 'horizontal') {
$prefix = '<div class="'.config('form-maker.form.input-column').'">';
$suffix = '</div>';
}
foreach ($config['config']['options'] as $key => $value) {
$selectedValue = '';
if (isset($config['config']['multiple']) && is_object($selected)) {
if (in_array($value, $selected->toArray())) {
$selectedValue = 'selected';
}
} else {
if ($selected == '') {
$selectedValue = ((string) $config['objectValue'] === (string) $value) ? 'selected' : '';
} else {
if (isset($config['objectValue']) && is_array(json_decode($config['objectValue']))) {
$selectedValue = (in_array($value, json_decode($config['objectValue']))) ? 'selected' : '';
} else {
$selectedValue = ((string) $selected === (string) $value) ? 'selected' : '';
}
}
}
$options .= '<option value="'.$value.'" '.$selectedValue.'>'.$key.'</option>';
}
return $prefix.'<select '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'">'.$options.'</select>'.$suffix;
} | php | public function makeSelected($config, $selected, $custom)
{
$options = $prefix = $suffix = '';
if (isset($config['config']['multiple'])) {
$custom = 'multiple';
$config['name'] = $config['name'].'[]';
}
if (config('form-maker.form.orientation') === 'horizontal') {
$prefix = '<div class="'.config('form-maker.form.input-column').'">';
$suffix = '</div>';
}
foreach ($config['config']['options'] as $key => $value) {
$selectedValue = '';
if (isset($config['config']['multiple']) && is_object($selected)) {
if (in_array($value, $selected->toArray())) {
$selectedValue = 'selected';
}
} else {
if ($selected == '') {
$selectedValue = ((string) $config['objectValue'] === (string) $value) ? 'selected' : '';
} else {
if (isset($config['objectValue']) && is_array(json_decode($config['objectValue']))) {
$selectedValue = (in_array($value, json_decode($config['objectValue']))) ? 'selected' : '';
} else {
$selectedValue = ((string) $selected === (string) $value) ? 'selected' : '';
}
}
}
$options .= '<option value="'.$value.'" '.$selectedValue.'>'.$key.'</option>';
}
return $prefix.'<select '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" name="'.$config['name'].'">'.$options.'</select>'.$suffix;
} | [
"public",
"function",
"makeSelected",
"(",
"$",
"config",
",",
"$",
"selected",
",",
"$",
"custom",
")",
"{",
"$",
"options",
"=",
"$",
"prefix",
"=",
"$",
"suffix",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'multiple'",
"]",
")",
")",
"{",
"$",
"custom",
"=",
"'multiple'",
";",
"$",
"config",
"[",
"'name'",
"]",
"=",
"$",
"config",
"[",
"'name'",
"]",
".",
"'[]'",
";",
"}",
"if",
"(",
"config",
"(",
"'form-maker.form.orientation'",
")",
"===",
"'horizontal'",
")",
"{",
"$",
"prefix",
"=",
"'<div class=\"'",
".",
"config",
"(",
"'form-maker.form.input-column'",
")",
".",
"'\">'",
";",
"$",
"suffix",
"=",
"'</div>'",
";",
"}",
"foreach",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'options'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"selectedValue",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'multiple'",
"]",
")",
"&&",
"is_object",
"(",
"$",
"selected",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"selected",
"->",
"toArray",
"(",
")",
")",
")",
"{",
"$",
"selectedValue",
"=",
"'selected'",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"selected",
"==",
"''",
")",
"{",
"$",
"selectedValue",
"=",
"(",
"(",
"string",
")",
"$",
"config",
"[",
"'objectValue'",
"]",
"===",
"(",
"string",
")",
"$",
"value",
")",
"?",
"'selected'",
":",
"''",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
"&&",
"is_array",
"(",
"json_decode",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
")",
")",
"{",
"$",
"selectedValue",
"=",
"(",
"in_array",
"(",
"$",
"value",
",",
"json_decode",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
")",
")",
"?",
"'selected'",
":",
"''",
";",
"}",
"else",
"{",
"$",
"selectedValue",
"=",
"(",
"(",
"string",
")",
"$",
"selected",
"===",
"(",
"string",
")",
"$",
"value",
")",
"?",
"'selected'",
":",
"''",
";",
"}",
"}",
"}",
"$",
"options",
".=",
"'<option value=\"'",
".",
"$",
"value",
".",
"'\" '",
".",
"$",
"selectedValue",
".",
"'>'",
".",
"$",
"key",
".",
"'</option>'",
";",
"}",
"return",
"$",
"prefix",
".",
"'<select '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" class=\"'",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"'\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"'\">'",
".",
"$",
"options",
".",
"'</select>'",
".",
"$",
"suffix",
";",
"}"
] | Make a select input.
@param array $config
@param string $selected
@param mixed $custom
@return string | [
"Make",
"a",
"select",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L55-L92 |
31,392 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeCheckbox | public function makeCheckbox($config, $selected, $custom)
{
if (str_contains($config['class'], 'form-control')) {
if (str_contains($config['class'], 'form-check-inline')) {
$config['class'] = str_replace('form-control', '', $config['class']);
} else {
$config['class'] = str_replace('form-control', 'form-check-input', $config['class']);
}
}
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" '.$selected.' type="checkbox" name="'.$config['name'].'" class="'. $config['class'] .'">';
} | php | public function makeCheckbox($config, $selected, $custom)
{
if (str_contains($config['class'], 'form-control')) {
if (str_contains($config['class'], 'form-check-inline')) {
$config['class'] = str_replace('form-control', '', $config['class']);
} else {
$config['class'] = str_replace('form-control', 'form-check-input', $config['class']);
}
}
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" '.$selected.' type="checkbox" name="'.$config['name'].'" class="'. $config['class'] .'">';
} | [
"public",
"function",
"makeCheckbox",
"(",
"$",
"config",
",",
"$",
"selected",
",",
"$",
"custom",
")",
"{",
"if",
"(",
"str_contains",
"(",
"$",
"config",
"[",
"'class'",
"]",
",",
"'form-control'",
")",
")",
"{",
"if",
"(",
"str_contains",
"(",
"$",
"config",
"[",
"'class'",
"]",
",",
"'form-check-inline'",
")",
")",
"{",
"$",
"config",
"[",
"'class'",
"]",
"=",
"str_replace",
"(",
"'form-control'",
",",
"''",
",",
"$",
"config",
"[",
"'class'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"config",
"[",
"'class'",
"]",
"=",
"str_replace",
"(",
"'form-control'",
",",
"'form-check-input'",
",",
"$",
"config",
"[",
"'class'",
"]",
")",
";",
"}",
"}",
"return",
"'<input '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" '",
".",
"$",
"selected",
".",
"' type=\"checkbox\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"'\" class=\"'",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"'\">'",
";",
"}"
] | Make a checkbox.
@param array $config
@param string $selected
@param mixed $custom
@return string | [
"Make",
"a",
"checkbox",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L103-L114 |
31,393 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeRadio | public function makeRadio($config, $selected, $custom)
{
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" '.$selected.' type="radio" name="'.$config['name'].'" class="'. $config['class'] .'">';
} | php | public function makeRadio($config, $selected, $custom)
{
return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" '.$selected.' type="radio" name="'.$config['name'].'" class="'. $config['class'] .'">';
} | [
"public",
"function",
"makeRadio",
"(",
"$",
"config",
",",
"$",
"selected",
",",
"$",
"custom",
")",
"{",
"return",
"'<input '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" '",
".",
"$",
"selected",
".",
"' type=\"radio\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"'\" class=\"'",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"'\">'",
";",
"}"
] | Make a radio input.
@param array $config
@param string $selected
@param mixed $custom
@return string | [
"Make",
"a",
"radio",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L125-L128 |
31,394 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeRelationship | public function makeRelationship($config, $label = 'name', $value = 'id', $custom = '')
{
$object = $config['object'];
if (isset($config['config']['relationship'])) {
$relationship = $config['config']['relationship'];
} else {
$relationship = $config['name'];
}
// Removes the array indication for select multiple
$relationship = str_replace('[]', '', $relationship);
$method = 'all';
if (!is_object($config['config']['model'])) {
$class = app()->make($config['config']['model']);
} else {
$class = $config['config']['model'];
}
if (isset($config['config']['method'])) {
$method = $config['config']['method'];
}
if (isset($config['config']['params'])) {
$items = $class->$method($config['config']['params']);
} else {
$items = $class->$method();
}
if (isset($config['config']['nullable']) && $config['config']['nullable'] === true) {
$config['config']['options']['- Select -'] = null;
}
foreach ($items as $item) {
$config['config']['options'][$item->$label] = $item->$value;
}
if (!isset($config['config']['selected'])) {
if (!isset($config['config']['multiple'])) {
$selected = '';
if (is_object($object) && method_exists($object, $relationship)) {
if ($object->$relationship()->first()) {
$selected = $object->$relationship()->first()->$value;
}
}
$relationship = str_replace('_id', '', $relationship);
if (method_exists($object, $relationship)) {
if ($object->$relationship()->first()) {
$selected = $object->$relationship()->first()->$value;
}
}
} else {
$selected = $class->$method()->pluck($value, $label);
}
} else {
$selected = $config['config']['selected'];
}
return $this->makeSelected($config, $selected, $custom);
} | php | public function makeRelationship($config, $label = 'name', $value = 'id', $custom = '')
{
$object = $config['object'];
if (isset($config['config']['relationship'])) {
$relationship = $config['config']['relationship'];
} else {
$relationship = $config['name'];
}
// Removes the array indication for select multiple
$relationship = str_replace('[]', '', $relationship);
$method = 'all';
if (!is_object($config['config']['model'])) {
$class = app()->make($config['config']['model']);
} else {
$class = $config['config']['model'];
}
if (isset($config['config']['method'])) {
$method = $config['config']['method'];
}
if (isset($config['config']['params'])) {
$items = $class->$method($config['config']['params']);
} else {
$items = $class->$method();
}
if (isset($config['config']['nullable']) && $config['config']['nullable'] === true) {
$config['config']['options']['- Select -'] = null;
}
foreach ($items as $item) {
$config['config']['options'][$item->$label] = $item->$value;
}
if (!isset($config['config']['selected'])) {
if (!isset($config['config']['multiple'])) {
$selected = '';
if (is_object($object) && method_exists($object, $relationship)) {
if ($object->$relationship()->first()) {
$selected = $object->$relationship()->first()->$value;
}
}
$relationship = str_replace('_id', '', $relationship);
if (method_exists($object, $relationship)) {
if ($object->$relationship()->first()) {
$selected = $object->$relationship()->first()->$value;
}
}
} else {
$selected = $class->$method()->pluck($value, $label);
}
} else {
$selected = $config['config']['selected'];
}
return $this->makeSelected($config, $selected, $custom);
} | [
"public",
"function",
"makeRelationship",
"(",
"$",
"config",
",",
"$",
"label",
"=",
"'name'",
",",
"$",
"value",
"=",
"'id'",
",",
"$",
"custom",
"=",
"''",
")",
"{",
"$",
"object",
"=",
"$",
"config",
"[",
"'object'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'relationship'",
"]",
")",
")",
"{",
"$",
"relationship",
"=",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'relationship'",
"]",
";",
"}",
"else",
"{",
"$",
"relationship",
"=",
"$",
"config",
"[",
"'name'",
"]",
";",
"}",
"// Removes the array indication for select multiple",
"$",
"relationship",
"=",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"$",
"relationship",
")",
";",
"$",
"method",
"=",
"'all'",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'model'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"app",
"(",
")",
"->",
"make",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'model'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'model'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"method",
"=",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'method'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"items",
"=",
"$",
"class",
"->",
"$",
"method",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'params'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"items",
"=",
"$",
"class",
"->",
"$",
"method",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'nullable'",
"]",
")",
"&&",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'nullable'",
"]",
"===",
"true",
")",
"{",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'options'",
"]",
"[",
"'- Select -'",
"]",
"=",
"null",
";",
"}",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'options'",
"]",
"[",
"$",
"item",
"->",
"$",
"label",
"]",
"=",
"$",
"item",
"->",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'selected'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'multiple'",
"]",
")",
")",
"{",
"$",
"selected",
"=",
"''",
";",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"&&",
"method_exists",
"(",
"$",
"object",
",",
"$",
"relationship",
")",
")",
"{",
"if",
"(",
"$",
"object",
"->",
"$",
"relationship",
"(",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"selected",
"=",
"$",
"object",
"->",
"$",
"relationship",
"(",
")",
"->",
"first",
"(",
")",
"->",
"$",
"value",
";",
"}",
"}",
"$",
"relationship",
"=",
"str_replace",
"(",
"'_id'",
",",
"''",
",",
"$",
"relationship",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"$",
"relationship",
")",
")",
"{",
"if",
"(",
"$",
"object",
"->",
"$",
"relationship",
"(",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"selected",
"=",
"$",
"object",
"->",
"$",
"relationship",
"(",
")",
"->",
"first",
"(",
")",
"->",
"$",
"value",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"selected",
"=",
"$",
"class",
"->",
"$",
"method",
"(",
")",
"->",
"pluck",
"(",
"$",
"value",
",",
"$",
"label",
")",
";",
"}",
"}",
"else",
"{",
"$",
"selected",
"=",
"$",
"config",
"[",
"'config'",
"]",
"[",
"'selected'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"makeSelected",
"(",
"$",
"config",
",",
"$",
"selected",
",",
"$",
"custom",
")",
";",
"}"
] | Make a relationship input.
@param array $config
@param string $label
@param string $value
@param mixed $custom
@return string | [
"Make",
"a",
"relationship",
"input",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L146-L209 |
31,395 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.makeHTMLInputString | public function makeHTMLInputString($config)
{
$custom = $this->getCustom($config);
$multiple = $this->isMultiple($config, 'multiple');
$multipleArray = $this->isMultiple($config, '[]');
$floatingNumber = $this->getFloatingNumber($config);
$population = $this->getPopulation($config);
if (is_array($config['objectValue']) && $config['type'] === 'file') {
$population = '';
}
$inputString = '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" type="'.$config['type'].'" name="'.$config['name'].$multipleArray.'" '.$floatingNumber.' '.$multiple.' '.$population.' placeholder="'.$config['placeholder'].'">';
return $inputString;
} | php | public function makeHTMLInputString($config)
{
$custom = $this->getCustom($config);
$multiple = $this->isMultiple($config, 'multiple');
$multipleArray = $this->isMultiple($config, '[]');
$floatingNumber = $this->getFloatingNumber($config);
$population = $this->getPopulation($config);
if (is_array($config['objectValue']) && $config['type'] === 'file') {
$population = '';
}
$inputString = '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" class="'.$config['class'].'" type="'.$config['type'].'" name="'.$config['name'].$multipleArray.'" '.$floatingNumber.' '.$multiple.' '.$population.' placeholder="'.$config['placeholder'].'">';
return $inputString;
} | [
"public",
"function",
"makeHTMLInputString",
"(",
"$",
"config",
")",
"{",
"$",
"custom",
"=",
"$",
"this",
"->",
"getCustom",
"(",
"$",
"config",
")",
";",
"$",
"multiple",
"=",
"$",
"this",
"->",
"isMultiple",
"(",
"$",
"config",
",",
"'multiple'",
")",
";",
"$",
"multipleArray",
"=",
"$",
"this",
"->",
"isMultiple",
"(",
"$",
"config",
",",
"'[]'",
")",
";",
"$",
"floatingNumber",
"=",
"$",
"this",
"->",
"getFloatingNumber",
"(",
"$",
"config",
")",
";",
"$",
"population",
"=",
"$",
"this",
"->",
"getPopulation",
"(",
"$",
"config",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
"&&",
"$",
"config",
"[",
"'type'",
"]",
"===",
"'file'",
")",
"{",
"$",
"population",
"=",
"''",
";",
"}",
"$",
"inputString",
"=",
"'<input '",
".",
"$",
"this",
"->",
"processCustom",
"(",
"$",
"custom",
")",
".",
"' id=\"'",
".",
"$",
"this",
"->",
"getId",
"(",
"$",
"config",
")",
".",
"'\" class=\"'",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"'\" type=\"'",
".",
"$",
"config",
"[",
"'type'",
"]",
".",
"'\" name=\"'",
".",
"$",
"config",
"[",
"'name'",
"]",
".",
"$",
"multipleArray",
".",
"'\" '",
".",
"$",
"floatingNumber",
".",
"' '",
".",
"$",
"multiple",
".",
"' '",
".",
"$",
"population",
".",
"' placeholder=\"'",
".",
"$",
"config",
"[",
"'placeholder'",
"]",
".",
"'\">'",
";",
"return",
"$",
"inputString",
";",
"}"
] | Generate a standard HTML input string.
@param array $config Config array
@return string | [
"Generate",
"a",
"standard",
"HTML",
"input",
"string",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L218-L233 |
31,396 | GrafiteInc/FormMaker | src/Generators/HtmlGenerator.php | HtmlGenerator.getPopulation | public function getPopulation($config)
{
if ($config['populated'] && ($config['name'] !== $config['objectValue'])) {
if ($config['type'] == 'date' && method_exists($config['objectValue'], 'format')) {
$format = (isset($config['format'])) ? $config['format'] : 'Y-m-d';
$config['objectValue'] = $config['objectValue']->format($format);
}
return 'value="'.htmlspecialchars($config['objectValue']).'"';
}
return '';
} | php | public function getPopulation($config)
{
if ($config['populated'] && ($config['name'] !== $config['objectValue'])) {
if ($config['type'] == 'date' && method_exists($config['objectValue'], 'format')) {
$format = (isset($config['format'])) ? $config['format'] : 'Y-m-d';
$config['objectValue'] = $config['objectValue']->format($format);
}
return 'value="'.htmlspecialchars($config['objectValue']).'"';
}
return '';
} | [
"public",
"function",
"getPopulation",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"config",
"[",
"'populated'",
"]",
"&&",
"(",
"$",
"config",
"[",
"'name'",
"]",
"!==",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"config",
"[",
"'type'",
"]",
"==",
"'date'",
"&&",
"method_exists",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
",",
"'format'",
")",
")",
"{",
"$",
"format",
"=",
"(",
"isset",
"(",
"$",
"config",
"[",
"'format'",
"]",
")",
")",
"?",
"$",
"config",
"[",
"'format'",
"]",
":",
"'Y-m-d'",
";",
"$",
"config",
"[",
"'objectValue'",
"]",
"=",
"$",
"config",
"[",
"'objectValue'",
"]",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}",
"return",
"'value=\"'",
".",
"htmlspecialchars",
"(",
"$",
"config",
"[",
"'objectValue'",
"]",
")",
".",
"'\"'",
";",
"}",
"return",
"''",
";",
"}"
] | Get the population.
@param array $config
@return string | [
"Get",
"the",
"population",
"."
] | 9c92d5592e852183c30b20193970bfc1afef2596 | https://github.com/GrafiteInc/FormMaker/blob/9c92d5592e852183c30b20193970bfc1afef2596/src/Generators/HtmlGenerator.php#L259-L272 |
31,397 | chameleon-system/chameleon-shop | src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php | MTExtranetRegistrationGuestCore.RegisterGuestUser | protected function RegisterGuestUser($sSuccessURL = null, $sFailureURL = null)
{
if (null === $sSuccessURL) {
if ($this->global->UserDataExists('sSuccessURL')) {
$sSuccessURL = $this->global->GetUserData('sSuccessURL', array(), TCMSUserInput::FILTER_URL);
}
if (empty($sSuccessURL)) {
$sSuccessURL = null;
}
}
if (null === $sFailureURL) {
if ($this->global->UserDataExists('sFailureURL')) {
$sFailureURL = $this->global->GetUserData('sFailureURL', array(), TCMSUserInput::FILTER_URL);
}
if (empty($sFailureURL)) {
$sFailureURL = null;
}
}
$oStep = TdbShopOrderStep::GetStep('thankyou');
if (null !== $oStep) {
$oTmpUser = $oStep->GetLastUserBoughtFromSession();
$aData = $this->GetFilteredUserData('aUser');
if (is_array($aData) && 2 == count($aData) && array_key_exists('password', $aData) && array_key_exists('password2', $aData)) {
foreach ($aData as $key => $val) {
$oTmpUser->sqlData[$key] = trim($val);
}
$aData = $oTmpUser->sqlData;
$extranetUserProvider = $this->getExtranetUserProvider();
$extranetUserProvider->reset();
$oUser = $extranetUserProvider->getActiveUser();
$oUser->LoadFromRow($aData);
$bDataValid = $this->ValidateUserLoginData();
$bDataValid = $this->ValidateUserData() && $bDataValid;
if ($bDataValid) {
$oUserOrder = &TShopBasket::GetLastCreatedOrder();
$sNewUserId = $oUser->Register();
$this->UpdateUserAddress(null, null, true);
$oUserOrder->AllowEditByAll(true);
$oUserOrder->SaveFieldsFast(array('data_extranet_user_id' => $sNewUserId));
$oUserOrder->AllowEditByAll(false);
if (!is_null($sSuccessURL)) {
$this->controller->HeaderURLRedirect($sSuccessURL, true);
} else {
$oExtranetConf = &TdbDataExtranet::GetInstance();
$this->controller->HeaderURLRedirect($oExtranetConf->GetLinkRegisterSuccessPage(), true);
}
$oStep->RemoveLastUserBoughtFromSession();
}
}
}
if (null !== $sFailureURL) {
$this->controller->HeaderURLRedirect($sFailureURL, true);
} else {
$oUser = TdbDataExtranetUser::GetInstance();
$this->controller->HeaderURLRedirect($oUser->GetLinkForRegistrationGuest(), true);
}
} | php | protected function RegisterGuestUser($sSuccessURL = null, $sFailureURL = null)
{
if (null === $sSuccessURL) {
if ($this->global->UserDataExists('sSuccessURL')) {
$sSuccessURL = $this->global->GetUserData('sSuccessURL', array(), TCMSUserInput::FILTER_URL);
}
if (empty($sSuccessURL)) {
$sSuccessURL = null;
}
}
if (null === $sFailureURL) {
if ($this->global->UserDataExists('sFailureURL')) {
$sFailureURL = $this->global->GetUserData('sFailureURL', array(), TCMSUserInput::FILTER_URL);
}
if (empty($sFailureURL)) {
$sFailureURL = null;
}
}
$oStep = TdbShopOrderStep::GetStep('thankyou');
if (null !== $oStep) {
$oTmpUser = $oStep->GetLastUserBoughtFromSession();
$aData = $this->GetFilteredUserData('aUser');
if (is_array($aData) && 2 == count($aData) && array_key_exists('password', $aData) && array_key_exists('password2', $aData)) {
foreach ($aData as $key => $val) {
$oTmpUser->sqlData[$key] = trim($val);
}
$aData = $oTmpUser->sqlData;
$extranetUserProvider = $this->getExtranetUserProvider();
$extranetUserProvider->reset();
$oUser = $extranetUserProvider->getActiveUser();
$oUser->LoadFromRow($aData);
$bDataValid = $this->ValidateUserLoginData();
$bDataValid = $this->ValidateUserData() && $bDataValid;
if ($bDataValid) {
$oUserOrder = &TShopBasket::GetLastCreatedOrder();
$sNewUserId = $oUser->Register();
$this->UpdateUserAddress(null, null, true);
$oUserOrder->AllowEditByAll(true);
$oUserOrder->SaveFieldsFast(array('data_extranet_user_id' => $sNewUserId));
$oUserOrder->AllowEditByAll(false);
if (!is_null($sSuccessURL)) {
$this->controller->HeaderURLRedirect($sSuccessURL, true);
} else {
$oExtranetConf = &TdbDataExtranet::GetInstance();
$this->controller->HeaderURLRedirect($oExtranetConf->GetLinkRegisterSuccessPage(), true);
}
$oStep->RemoveLastUserBoughtFromSession();
}
}
}
if (null !== $sFailureURL) {
$this->controller->HeaderURLRedirect($sFailureURL, true);
} else {
$oUser = TdbDataExtranetUser::GetInstance();
$this->controller->HeaderURLRedirect($oUser->GetLinkForRegistrationGuest(), true);
}
} | [
"protected",
"function",
"RegisterGuestUser",
"(",
"$",
"sSuccessURL",
"=",
"null",
",",
"$",
"sFailureURL",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"sSuccessURL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"global",
"->",
"UserDataExists",
"(",
"'sSuccessURL'",
")",
")",
"{",
"$",
"sSuccessURL",
"=",
"$",
"this",
"->",
"global",
"->",
"GetUserData",
"(",
"'sSuccessURL'",
",",
"array",
"(",
")",
",",
"TCMSUserInput",
"::",
"FILTER_URL",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sSuccessURL",
")",
")",
"{",
"$",
"sSuccessURL",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"sFailureURL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"global",
"->",
"UserDataExists",
"(",
"'sFailureURL'",
")",
")",
"{",
"$",
"sFailureURL",
"=",
"$",
"this",
"->",
"global",
"->",
"GetUserData",
"(",
"'sFailureURL'",
",",
"array",
"(",
")",
",",
"TCMSUserInput",
"::",
"FILTER_URL",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFailureURL",
")",
")",
"{",
"$",
"sFailureURL",
"=",
"null",
";",
"}",
"}",
"$",
"oStep",
"=",
"TdbShopOrderStep",
"::",
"GetStep",
"(",
"'thankyou'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"oStep",
")",
"{",
"$",
"oTmpUser",
"=",
"$",
"oStep",
"->",
"GetLastUserBoughtFromSession",
"(",
")",
";",
"$",
"aData",
"=",
"$",
"this",
"->",
"GetFilteredUserData",
"(",
"'aUser'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"aData",
")",
"&&",
"2",
"==",
"count",
"(",
"$",
"aData",
")",
"&&",
"array_key_exists",
"(",
"'password'",
",",
"$",
"aData",
")",
"&&",
"array_key_exists",
"(",
"'password2'",
",",
"$",
"aData",
")",
")",
"{",
"foreach",
"(",
"$",
"aData",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"oTmpUser",
"->",
"sqlData",
"[",
"$",
"key",
"]",
"=",
"trim",
"(",
"$",
"val",
")",
";",
"}",
"$",
"aData",
"=",
"$",
"oTmpUser",
"->",
"sqlData",
";",
"$",
"extranetUserProvider",
"=",
"$",
"this",
"->",
"getExtranetUserProvider",
"(",
")",
";",
"$",
"extranetUserProvider",
"->",
"reset",
"(",
")",
";",
"$",
"oUser",
"=",
"$",
"extranetUserProvider",
"->",
"getActiveUser",
"(",
")",
";",
"$",
"oUser",
"->",
"LoadFromRow",
"(",
"$",
"aData",
")",
";",
"$",
"bDataValid",
"=",
"$",
"this",
"->",
"ValidateUserLoginData",
"(",
")",
";",
"$",
"bDataValid",
"=",
"$",
"this",
"->",
"ValidateUserData",
"(",
")",
"&&",
"$",
"bDataValid",
";",
"if",
"(",
"$",
"bDataValid",
")",
"{",
"$",
"oUserOrder",
"=",
"&",
"TShopBasket",
"::",
"GetLastCreatedOrder",
"(",
")",
";",
"$",
"sNewUserId",
"=",
"$",
"oUser",
"->",
"Register",
"(",
")",
";",
"$",
"this",
"->",
"UpdateUserAddress",
"(",
"null",
",",
"null",
",",
"true",
")",
";",
"$",
"oUserOrder",
"->",
"AllowEditByAll",
"(",
"true",
")",
";",
"$",
"oUserOrder",
"->",
"SaveFieldsFast",
"(",
"array",
"(",
"'data_extranet_user_id'",
"=>",
"$",
"sNewUserId",
")",
")",
";",
"$",
"oUserOrder",
"->",
"AllowEditByAll",
"(",
"false",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"sSuccessURL",
")",
")",
"{",
"$",
"this",
"->",
"controller",
"->",
"HeaderURLRedirect",
"(",
"$",
"sSuccessURL",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"oExtranetConf",
"=",
"&",
"TdbDataExtranet",
"::",
"GetInstance",
"(",
")",
";",
"$",
"this",
"->",
"controller",
"->",
"HeaderURLRedirect",
"(",
"$",
"oExtranetConf",
"->",
"GetLinkRegisterSuccessPage",
"(",
")",
",",
"true",
")",
";",
"}",
"$",
"oStep",
"->",
"RemoveLastUserBoughtFromSession",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"sFailureURL",
")",
"{",
"$",
"this",
"->",
"controller",
"->",
"HeaderURLRedirect",
"(",
"$",
"sFailureURL",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"oUser",
"=",
"TdbDataExtranetUser",
"::",
"GetInstance",
"(",
")",
";",
"$",
"this",
"->",
"controller",
"->",
"HeaderURLRedirect",
"(",
"$",
"oUser",
"->",
"GetLinkForRegistrationGuest",
"(",
")",
",",
"true",
")",
";",
"}",
"}"
] | Register guest user. Requires last basket step to be thankyou.
@param null $sSuccessURL
@param null $sFailureURL | [
"Register",
"guest",
"user",
".",
"Requires",
"last",
"basket",
"step",
"to",
"be",
"thankyou",
"."
] | 2e47f4eeab604449605ee1867180c9a37a8c208e | https://github.com/chameleon-system/chameleon-shop/blob/2e47f4eeab604449605ee1867180c9a37a8c208e/src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php#L39-L96 |
31,398 | chameleon-system/chameleon-shop | src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php | MTExtranetRegistrationGuestCore.HandleRegisterAfterShopping | protected function HandleRegisterAfterShopping()
{
if ($this->ActivePageIsRegisterAfterShopping()) {
if (!$this->IsAllowedToShowRegisterAfterShoppingPage()) {
$oExtranetConfig = TdbDataExtranet::GetInstance();
$this->controller->HeaderURLRedirect($oExtranetConfig->GetLinkAccessDeniedPage(), true);
}
}
} | php | protected function HandleRegisterAfterShopping()
{
if ($this->ActivePageIsRegisterAfterShopping()) {
if (!$this->IsAllowedToShowRegisterAfterShoppingPage()) {
$oExtranetConfig = TdbDataExtranet::GetInstance();
$this->controller->HeaderURLRedirect($oExtranetConfig->GetLinkAccessDeniedPage(), true);
}
}
} | [
"protected",
"function",
"HandleRegisterAfterShopping",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ActivePageIsRegisterAfterShopping",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"IsAllowedToShowRegisterAfterShoppingPage",
"(",
")",
")",
"{",
"$",
"oExtranetConfig",
"=",
"TdbDataExtranet",
"::",
"GetInstance",
"(",
")",
";",
"$",
"this",
"->",
"controller",
"->",
"HeaderURLRedirect",
"(",
"$",
"oExtranetConfig",
"->",
"GetLinkAccessDeniedPage",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"}"
] | if user is not allowed to be register redirect to access denied page. | [
"if",
"user",
"is",
"not",
"allowed",
"to",
"be",
"register",
"redirect",
"to",
"access",
"denied",
"page",
"."
] | 2e47f4eeab604449605ee1867180c9a37a8c208e | https://github.com/chameleon-system/chameleon-shop/blob/2e47f4eeab604449605ee1867180c9a37a8c208e/src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php#L101-L109 |
31,399 | chameleon-system/chameleon-shop | src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php | MTExtranetRegistrationGuestCore.IsAllowedToShowRegisterAfterShoppingPage | protected function IsAllowedToShowRegisterAfterShoppingPage()
{
$oStep = TdbShopOrderStep::GetStep('thankyou');
$bUserIsValid = false;
if (!is_null($oStep)) {
$oUser = $oStep->GetLastUserBoughtFromSession();
if (!is_null($oUser)) {
$bUserIsValid = $this->ValidateGivenUserData($oUser);
if ($bUserIsValid) {
$oUserOrder = &TShopBasket::GetLastCreatedOrder();
if ($oUser->LoginExists()) {
$bUserIsValid = false;
}
if (is_null($oUserOrder)) {
$bUserIsValid = false;
}
}
}
}
return $bUserIsValid;
} | php | protected function IsAllowedToShowRegisterAfterShoppingPage()
{
$oStep = TdbShopOrderStep::GetStep('thankyou');
$bUserIsValid = false;
if (!is_null($oStep)) {
$oUser = $oStep->GetLastUserBoughtFromSession();
if (!is_null($oUser)) {
$bUserIsValid = $this->ValidateGivenUserData($oUser);
if ($bUserIsValid) {
$oUserOrder = &TShopBasket::GetLastCreatedOrder();
if ($oUser->LoginExists()) {
$bUserIsValid = false;
}
if (is_null($oUserOrder)) {
$bUserIsValid = false;
}
}
}
}
return $bUserIsValid;
} | [
"protected",
"function",
"IsAllowedToShowRegisterAfterShoppingPage",
"(",
")",
"{",
"$",
"oStep",
"=",
"TdbShopOrderStep",
"::",
"GetStep",
"(",
"'thankyou'",
")",
";",
"$",
"bUserIsValid",
"=",
"false",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"oStep",
")",
")",
"{",
"$",
"oUser",
"=",
"$",
"oStep",
"->",
"GetLastUserBoughtFromSession",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"oUser",
")",
")",
"{",
"$",
"bUserIsValid",
"=",
"$",
"this",
"->",
"ValidateGivenUserData",
"(",
"$",
"oUser",
")",
";",
"if",
"(",
"$",
"bUserIsValid",
")",
"{",
"$",
"oUserOrder",
"=",
"&",
"TShopBasket",
"::",
"GetLastCreatedOrder",
"(",
")",
";",
"if",
"(",
"$",
"oUser",
"->",
"LoginExists",
"(",
")",
")",
"{",
"$",
"bUserIsValid",
"=",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"oUserOrder",
")",
")",
"{",
"$",
"bUserIsValid",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"bUserIsValid",
";",
"}"
] | Checks if user is allowed to register after shopping.
@return bool | [
"Checks",
"if",
"user",
"is",
"allowed",
"to",
"register",
"after",
"shopping",
"."
] | 2e47f4eeab604449605ee1867180c9a37a8c208e | https://github.com/chameleon-system/chameleon-shop/blob/2e47f4eeab604449605ee1867180c9a37a8c208e/src/ExtranetRegistrationGuestBundle/pkgExtranet/objects/WebModules/MTExtranetRegistrationGuestCore/MTExtranetRegistrationGuestCore.class.php#L116-L137 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.