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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
38,200 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.addSoftDeletionToQuery | protected function addSoftDeletionToQuery(EntityDefinition $definition, QueryBuilder $queryBuilder, $fieldPrefix = '', $method = 'andWhere')
{
if (!$definition->isHardDeletion()) {
$queryBuilder->$method($fieldPrefix.'deleted_at IS NULL');
}
} | php | protected function addSoftDeletionToQuery(EntityDefinition $definition, QueryBuilder $queryBuilder, $fieldPrefix = '', $method = 'andWhere')
{
if (!$definition->isHardDeletion()) {
$queryBuilder->$method($fieldPrefix.'deleted_at IS NULL');
}
} | [
"protected",
"function",
"addSoftDeletionToQuery",
"(",
"EntityDefinition",
"$",
"definition",
",",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"fieldPrefix",
"=",
"''",
",",
"$",
"method",
"=",
"'andWhere'",
")",
"{",
"if",
"(",
"!",
"$",
"definition",
"->",
"isHardDeletion",
"(",
")",
")",
"{",
"$",
"queryBuilder",
"->",
"$",
"method",
"(",
"$",
"fieldPrefix",
".",
"'deleted_at IS NULL'",
")",
";",
"}",
"}"
] | Adds the soft deletion parameters if activated.
@param EntityDefinition $definition
the entity definition which might have soft deletion activated
@param QueryBuilder $queryBuilder
the query builder to add the deletion condition to
@param string $fieldPrefix
the prefix to add before the deleted_at field like an table alias
@param string $method
the method to use of the query builder, "where" or "andWhere" | [
"Adds",
"the",
"soft",
"deletion",
"parameters",
"if",
"activated",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L48-L53 |
38,201 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.setValuesAndParameters | protected function setValuesAndParameters(Entity $entity, QueryBuilder $queryBuilder, $setMethod)
{
$formFields = $this->getFormFields();
$count = count($formFields);
for ($i = 0; $i < $count; ++$i) {
$type = $this->definition->getType($formFields[$i]);
$value = $entity->get($formFields[$i]);
if ($type == 'boolean') {
$value = $value ? 1 : 0;
}
if ($type == 'reference' && is_array($value)) {
$value = $value['id'];
}
$queryBuilder->$setMethod('`'.$formFields[$i].'`', '?');
$queryBuilder->setParameter($i, $value);
}
} | php | protected function setValuesAndParameters(Entity $entity, QueryBuilder $queryBuilder, $setMethod)
{
$formFields = $this->getFormFields();
$count = count($formFields);
for ($i = 0; $i < $count; ++$i) {
$type = $this->definition->getType($formFields[$i]);
$value = $entity->get($formFields[$i]);
if ($type == 'boolean') {
$value = $value ? 1 : 0;
}
if ($type == 'reference' && is_array($value)) {
$value = $value['id'];
}
$queryBuilder->$setMethod('`'.$formFields[$i].'`', '?');
$queryBuilder->setParameter($i, $value);
}
} | [
"protected",
"function",
"setValuesAndParameters",
"(",
"Entity",
"$",
"entity",
",",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"setMethod",
")",
"{",
"$",
"formFields",
"=",
"$",
"this",
"->",
"getFormFields",
"(",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"formFields",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"formFields",
"[",
"$",
"i",
"]",
")",
";",
"$",
"value",
"=",
"$",
"entity",
"->",
"get",
"(",
"$",
"formFields",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'boolean'",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
"1",
":",
"0",
";",
"}",
"if",
"(",
"$",
"type",
"==",
"'reference'",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"'id'",
"]",
";",
"}",
"$",
"queryBuilder",
"->",
"$",
"setMethod",
"(",
"'`'",
".",
"$",
"formFields",
"[",
"$",
"i",
"]",
".",
"'`'",
",",
"'?'",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"$",
"i",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Sets the values and parameters of the upcoming given query according
to the entity.
@param Entity $entity
the entity with its fields and values
@param QueryBuilder $queryBuilder
the upcoming query
@param string $setMethod
what method to use on the QueryBuilder: 'setValue' or 'set' | [
"Sets",
"the",
"values",
"and",
"parameters",
"of",
"the",
"upcoming",
"given",
"query",
"according",
"to",
"the",
"entity",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L66-L82 |
38,202 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.hasChildren | protected function hasChildren($id)
{
foreach ($this->definition->getChildren() as $child) {
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->select('COUNT(id)')
->from('`'.$child[0].'`', '`'.$child[0].'`')
->where('`'.$child[1].'` = ?')
->setParameter(0, $id)
;
$this->addSoftDeletionToQuery($this->getDefinition()->getService()->getData($child[2])->getDefinition(), $queryBuilder);
$queryResult = $queryBuilder->execute();
$result = $queryResult->fetch(\PDO::FETCH_NUM);
if ($result[0] > 0) {
return true;
}
}
return false;
} | php | protected function hasChildren($id)
{
foreach ($this->definition->getChildren() as $child) {
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->select('COUNT(id)')
->from('`'.$child[0].'`', '`'.$child[0].'`')
->where('`'.$child[1].'` = ?')
->setParameter(0, $id)
;
$this->addSoftDeletionToQuery($this->getDefinition()->getService()->getData($child[2])->getDefinition(), $queryBuilder);
$queryResult = $queryBuilder->execute();
$result = $queryResult->fetch(\PDO::FETCH_NUM);
if ($result[0] > 0) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hasChildren",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"select",
"(",
"'COUNT(id)'",
")",
"->",
"from",
"(",
"'`'",
".",
"$",
"child",
"[",
"0",
"]",
".",
"'`'",
",",
"'`'",
".",
"$",
"child",
"[",
"0",
"]",
".",
"'`'",
")",
"->",
"where",
"(",
"'`'",
".",
"$",
"child",
"[",
"1",
"]",
".",
"'` = ?'",
")",
"->",
"setParameter",
"(",
"0",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"addSoftDeletionToQuery",
"(",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"child",
"[",
"2",
"]",
")",
"->",
"getDefinition",
"(",
")",
",",
"$",
"queryBuilder",
")",
";",
"$",
"queryResult",
"=",
"$",
"queryBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"result",
"=",
"$",
"queryResult",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_NUM",
")",
";",
"if",
"(",
"$",
"result",
"[",
"0",
"]",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether the by id given entity still has children referencing it.
@param integer $id
the current entities id
@return boolean
true if the entity still has children | [
"Checks",
"whether",
"the",
"by",
"id",
"given",
"entity",
"still",
"has",
"children",
"referencing",
"it",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L93-L111 |
38,203 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.deleteManyToManyReferences | protected function deleteManyToManyReferences(Entity $entity)
{
foreach ($this->definition->getService()->getEntities() as $entityName) {
$data = $this->definition->getService()->getData($entityName);
foreach ($data->getDefinition()->getFieldNames(true) as $field) {
if ($data->getDefinition()->getType($field) == 'many') {
$otherEntity = $data->getDefinition()->getSubTypeField($field, 'many', 'entity');
$otherData = $this->definition->getService()->getData($otherEntity);
if ($entity->getDefinition()->getTable() == $otherData->getDefinition()->getTable()) {
$thatField = $data->getDefinition()->getSubTypeField($field, 'many', 'thatField');
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->delete('`'.$field.'`')
->where('`'.$thatField.'` = ?')
->setParameter(0, $entity->get('id'))
->execute()
;
}
}
}
}
} | php | protected function deleteManyToManyReferences(Entity $entity)
{
foreach ($this->definition->getService()->getEntities() as $entityName) {
$data = $this->definition->getService()->getData($entityName);
foreach ($data->getDefinition()->getFieldNames(true) as $field) {
if ($data->getDefinition()->getType($field) == 'many') {
$otherEntity = $data->getDefinition()->getSubTypeField($field, 'many', 'entity');
$otherData = $this->definition->getService()->getData($otherEntity);
if ($entity->getDefinition()->getTable() == $otherData->getDefinition()->getTable()) {
$thatField = $data->getDefinition()->getSubTypeField($field, 'many', 'thatField');
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->delete('`'.$field.'`')
->where('`'.$thatField.'` = ?')
->setParameter(0, $entity->get('id'))
->execute()
;
}
}
}
}
} | [
"protected",
"function",
"deleteManyToManyReferences",
"(",
"Entity",
"$",
"entity",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getEntities",
"(",
")",
"as",
"$",
"entityName",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"entityName",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"getDefinition",
"(",
")",
"->",
"getFieldNames",
"(",
"true",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"getDefinition",
"(",
")",
"->",
"getType",
"(",
"$",
"field",
")",
"==",
"'many'",
")",
"{",
"$",
"otherEntity",
"=",
"$",
"data",
"->",
"getDefinition",
"(",
")",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'many'",
",",
"'entity'",
")",
";",
"$",
"otherData",
"=",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"otherEntity",
")",
";",
"if",
"(",
"$",
"entity",
"->",
"getDefinition",
"(",
")",
"->",
"getTable",
"(",
")",
"==",
"$",
"otherData",
"->",
"getDefinition",
"(",
")",
"->",
"getTable",
"(",
")",
")",
"{",
"$",
"thatField",
"=",
"$",
"data",
"->",
"getDefinition",
"(",
")",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'many'",
",",
"'thatField'",
")",
";",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"delete",
"(",
"'`'",
".",
"$",
"field",
".",
"'`'",
")",
"->",
"where",
"(",
"'`'",
".",
"$",
"thatField",
".",
"'` = ?'",
")",
"->",
"setParameter",
"(",
"0",
",",
"$",
"entity",
"->",
"get",
"(",
"'id'",
")",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Deletes any many to many references pointing to the given entity.
@param Entity $entity
the referenced entity | [
"Deletes",
"any",
"many",
"to",
"many",
"references",
"pointing",
"to",
"the",
"given",
"entity",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L119-L140 |
38,204 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.getManyIds | protected function getManyIds(array $fields, array $params)
{
$manyIds = [];
foreach ($fields as $field) {
$thisField = $this->definition->getSubTypeField($field, 'many', 'thisField');
$thatField = $this->definition->getSubTypeField($field, 'many', 'thatField');
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->select('`'.$thisField.'`')
->from($field)
->where('`'.$thatField.'` IN (?)')
->setParameter(0, array_column($params[$field], 'id'), Connection::PARAM_STR_ARRAY)
->groupBy('`'.$thisField.'`')
;
$queryResult = $queryBuilder->execute();
$manyResults = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
$manyIds = array_merge($manyIds, array_column($manyResults, $thisField));
}
return $manyIds;
} | php | protected function getManyIds(array $fields, array $params)
{
$manyIds = [];
foreach ($fields as $field) {
$thisField = $this->definition->getSubTypeField($field, 'many', 'thisField');
$thatField = $this->definition->getSubTypeField($field, 'many', 'thatField');
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder
->select('`'.$thisField.'`')
->from($field)
->where('`'.$thatField.'` IN (?)')
->setParameter(0, array_column($params[$field], 'id'), Connection::PARAM_STR_ARRAY)
->groupBy('`'.$thisField.'`')
;
$queryResult = $queryBuilder->execute();
$manyResults = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
$manyIds = array_merge($manyIds, array_column($manyResults, $thisField));
}
return $manyIds;
} | [
"protected",
"function",
"getManyIds",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"params",
")",
"{",
"$",
"manyIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"thisField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'many'",
",",
"'thisField'",
")",
";",
"$",
"thatField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'many'",
",",
"'thatField'",
")",
";",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"select",
"(",
"'`'",
".",
"$",
"thisField",
".",
"'`'",
")",
"->",
"from",
"(",
"$",
"field",
")",
"->",
"where",
"(",
"'`'",
".",
"$",
"thatField",
".",
"'` IN (?)'",
")",
"->",
"setParameter",
"(",
"0",
",",
"array_column",
"(",
"$",
"params",
"[",
"$",
"field",
"]",
",",
"'id'",
")",
",",
"Connection",
"::",
"PARAM_STR_ARRAY",
")",
"->",
"groupBy",
"(",
"'`'",
".",
"$",
"thisField",
".",
"'`'",
")",
";",
"$",
"queryResult",
"=",
"$",
"queryBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"manyResults",
"=",
"$",
"queryResult",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"manyIds",
"=",
"array_merge",
"(",
"$",
"manyIds",
",",
"array_column",
"(",
"$",
"manyResults",
",",
"$",
"thisField",
")",
")",
";",
"}",
"return",
"$",
"manyIds",
";",
"}"
] | Gets all possible many-to-many ids existing for this definition.
@param array $fields
the many field names to fetch for
@param $params
the parameters the possible many field values to fetch for
@return array
an array of this many-to-many ids | [
"Gets",
"all",
"possible",
"many",
"-",
"to",
"-",
"many",
"ids",
"existing",
"for",
"this",
"definition",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L186-L206 |
38,205 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.addPagination | protected function addPagination(QueryBuilder $queryBuilder, $skip, $amount)
{
$queryBuilder->setMaxResults(9999999999);
if ($amount !== null) {
$queryBuilder->setMaxResults(abs(intval($amount)));
}
if ($skip !== null) {
$queryBuilder->setFirstResult(abs(intval($skip)));
}
} | php | protected function addPagination(QueryBuilder $queryBuilder, $skip, $amount)
{
$queryBuilder->setMaxResults(9999999999);
if ($amount !== null) {
$queryBuilder->setMaxResults(abs(intval($amount)));
}
if ($skip !== null) {
$queryBuilder->setFirstResult(abs(intval($skip)));
}
} | [
"protected",
"function",
"addPagination",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"$",
"skip",
",",
"$",
"amount",
")",
"{",
"$",
"queryBuilder",
"->",
"setMaxResults",
"(",
"9999999999",
")",
";",
"if",
"(",
"$",
"amount",
"!==",
"null",
")",
"{",
"$",
"queryBuilder",
"->",
"setMaxResults",
"(",
"abs",
"(",
"intval",
"(",
"$",
"amount",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"skip",
"!==",
"null",
")",
"{",
"$",
"queryBuilder",
"->",
"setFirstResult",
"(",
"abs",
"(",
"intval",
"(",
"$",
"skip",
")",
")",
")",
";",
"}",
"}"
] | Adds pagination parameters to the query.
@param QueryBuilder $queryBuilder
the query
@param integer|null $skip
the rows to skip
@param integer|null $amount
the maximum amount of rows | [
"Adds",
"pagination",
"parameters",
"to",
"the",
"query",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L256-L265 |
38,206 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.fetchReferencesForField | protected function fetchReferencesForField(array &$entities, $field)
{
$nameField = $this->definition->getSubTypeField($field, 'reference', 'nameField');
$queryBuilder = $this->database->createQueryBuilder();
$ids = $this->getReferenceIds($entities, $field);
$referenceEntity = $this->definition->getSubTypeField($field, 'reference', 'entity');
$table = $this->definition->getService()->getData($referenceEntity)->getDefinition()->getTable();
$queryBuilder
->from('`'.$table.'`', '`'.$table.'`')
->where('id IN (?)')
;
$this->addSoftDeletionToQuery($this->definition, $queryBuilder);
if ($nameField) {
$queryBuilder->select('id', $nameField);
} else {
$queryBuilder->select('id');
}
$queryBuilder->setParameter(0, $ids, Connection::PARAM_STR_ARRAY);
$queryResult = $queryBuilder->execute();
$rows = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
$amount = count($entities);
foreach ($rows as $row) {
for ($i = 0; $i < $amount; ++$i) {
if ($entities[$i]->get($field) == $row['id']) {
$value = ['id' => $entities[$i]->get($field)];
if ($nameField) {
$value['name'] = $row[$nameField];
}
$entities[$i]->set($field, $value);
}
}
}
} | php | protected function fetchReferencesForField(array &$entities, $field)
{
$nameField = $this->definition->getSubTypeField($field, 'reference', 'nameField');
$queryBuilder = $this->database->createQueryBuilder();
$ids = $this->getReferenceIds($entities, $field);
$referenceEntity = $this->definition->getSubTypeField($field, 'reference', 'entity');
$table = $this->definition->getService()->getData($referenceEntity)->getDefinition()->getTable();
$queryBuilder
->from('`'.$table.'`', '`'.$table.'`')
->where('id IN (?)')
;
$this->addSoftDeletionToQuery($this->definition, $queryBuilder);
if ($nameField) {
$queryBuilder->select('id', $nameField);
} else {
$queryBuilder->select('id');
}
$queryBuilder->setParameter(0, $ids, Connection::PARAM_STR_ARRAY);
$queryResult = $queryBuilder->execute();
$rows = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
$amount = count($entities);
foreach ($rows as $row) {
for ($i = 0; $i < $amount; ++$i) {
if ($entities[$i]->get($field) == $row['id']) {
$value = ['id' => $entities[$i]->get($field)];
if ($nameField) {
$value['name'] = $row[$nameField];
}
$entities[$i]->set($field, $value);
}
}
}
} | [
"protected",
"function",
"fetchReferencesForField",
"(",
"array",
"&",
"$",
"entities",
",",
"$",
"field",
")",
"{",
"$",
"nameField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'reference'",
",",
"'nameField'",
")",
";",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"ids",
"=",
"$",
"this",
"->",
"getReferenceIds",
"(",
"$",
"entities",
",",
"$",
"field",
")",
";",
"$",
"referenceEntity",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"field",
",",
"'reference'",
",",
"'entity'",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"referenceEntity",
")",
"->",
"getDefinition",
"(",
")",
"->",
"getTable",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"from",
"(",
"'`'",
".",
"$",
"table",
".",
"'`'",
",",
"'`'",
".",
"$",
"table",
".",
"'`'",
")",
"->",
"where",
"(",
"'id IN (?)'",
")",
";",
"$",
"this",
"->",
"addSoftDeletionToQuery",
"(",
"$",
"this",
"->",
"definition",
",",
"$",
"queryBuilder",
")",
";",
"if",
"(",
"$",
"nameField",
")",
"{",
"$",
"queryBuilder",
"->",
"select",
"(",
"'id'",
",",
"$",
"nameField",
")",
";",
"}",
"else",
"{",
"$",
"queryBuilder",
"->",
"select",
"(",
"'id'",
")",
";",
"}",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"0",
",",
"$",
"ids",
",",
"Connection",
"::",
"PARAM_STR_ARRAY",
")",
";",
"$",
"queryResult",
"=",
"$",
"queryBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"queryResult",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"amount",
"=",
"count",
"(",
"$",
"entities",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"amount",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"entities",
"[",
"$",
"i",
"]",
"->",
"get",
"(",
"$",
"field",
")",
"==",
"$",
"row",
"[",
"'id'",
"]",
")",
"{",
"$",
"value",
"=",
"[",
"'id'",
"=>",
"$",
"entities",
"[",
"$",
"i",
"]",
"->",
"get",
"(",
"$",
"field",
")",
"]",
";",
"if",
"(",
"$",
"nameField",
")",
"{",
"$",
"value",
"[",
"'name'",
"]",
"=",
"$",
"row",
"[",
"$",
"nameField",
"]",
";",
"}",
"$",
"entities",
"[",
"$",
"i",
"]",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
] | Adds the id and name of referenced entities to the given entities. The
reference field is before the raw id of the referenced entity and after
the fetch, it's an array with the keys id and name.
@param Entity[] &$entities
the entities to fetch the references for
@param string $field
the reference field | [
"Adds",
"the",
"id",
"and",
"name",
"of",
"referenced",
"entities",
"to",
"the",
"given",
"entities",
".",
"The",
"reference",
"field",
"is",
"before",
"the",
"raw",
"id",
"of",
"the",
"referenced",
"entity",
"and",
"after",
"the",
"fetch",
"it",
"s",
"an",
"array",
"with",
"the",
"keys",
"id",
"and",
"name",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L301-L337 |
38,207 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.generateUUID | protected function generateUUID()
{
$uuid = null;
if ($this->useUUIDs) {
$sql = 'SELECT UUID() as id';
$result = $this->database->fetchAssoc($sql);
$uuid = $result['id'];
}
return $uuid;
} | php | protected function generateUUID()
{
$uuid = null;
if ($this->useUUIDs) {
$sql = 'SELECT UUID() as id';
$result = $this->database->fetchAssoc($sql);
$uuid = $result['id'];
}
return $uuid;
} | [
"protected",
"function",
"generateUUID",
"(",
")",
"{",
"$",
"uuid",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"useUUIDs",
")",
"{",
"$",
"sql",
"=",
"'SELECT UUID() as id'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"database",
"->",
"fetchAssoc",
"(",
"$",
"sql",
")",
";",
"$",
"uuid",
"=",
"$",
"result",
"[",
"'id'",
"]",
";",
"}",
"return",
"$",
"uuid",
";",
"}"
] | Generates a new UUID.
@return string|null
the new UUID or null if this instance isn't configured to do so | [
"Generates",
"a",
"new",
"UUID",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L345-L354 |
38,208 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.enrichWithManyField | protected function enrichWithManyField(&$idToData, $manyField)
{
$queryBuilder = $this->database->createQueryBuilder();
$nameField = $this->definition->getSubTypeField($manyField, 'many', 'nameField');
$thisField = $this->definition->getSubTypeField($manyField, 'many', 'thisField');
$thatField = $this->definition->getSubTypeField($manyField, 'many', 'thatField');
$entity = $this->definition->getSubTypeField($manyField, 'many', 'entity');
$entityDefinition = $this->definition->getService()->getData($entity)->getDefinition();
$entityTable = $entityDefinition->getTable();
$nameSelect = $nameField !== null ? ', t2.`'.$nameField.'` AS name' : '';
$queryBuilder
->select('t1.`'.$thisField.'` AS this, t1.`'.$thatField.'` AS id'.$nameSelect)
->from('`'.$manyField.'`', 't1')
->leftJoin('t1', '`'.$entityTable.'`', 't2', 't2.id = t1.`'.$thatField.'`')
->where('t1.`'.$thisField.'` IN (?)')
;
$this->addSoftDeletionToQuery($entityDefinition, $queryBuilder);
$queryBuilder->setParameter(0, array_keys($idToData), Connection::PARAM_STR_ARRAY);
$queryResult = $queryBuilder->execute();
$manyReferences = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
foreach ($manyReferences as $manyReference) {
$entityId = $manyReference['this'];
unset($manyReference['this']);
$idToData[$entityId][$manyField][] = $manyReference;
}
} | php | protected function enrichWithManyField(&$idToData, $manyField)
{
$queryBuilder = $this->database->createQueryBuilder();
$nameField = $this->definition->getSubTypeField($manyField, 'many', 'nameField');
$thisField = $this->definition->getSubTypeField($manyField, 'many', 'thisField');
$thatField = $this->definition->getSubTypeField($manyField, 'many', 'thatField');
$entity = $this->definition->getSubTypeField($manyField, 'many', 'entity');
$entityDefinition = $this->definition->getService()->getData($entity)->getDefinition();
$entityTable = $entityDefinition->getTable();
$nameSelect = $nameField !== null ? ', t2.`'.$nameField.'` AS name' : '';
$queryBuilder
->select('t1.`'.$thisField.'` AS this, t1.`'.$thatField.'` AS id'.$nameSelect)
->from('`'.$manyField.'`', 't1')
->leftJoin('t1', '`'.$entityTable.'`', 't2', 't2.id = t1.`'.$thatField.'`')
->where('t1.`'.$thisField.'` IN (?)')
;
$this->addSoftDeletionToQuery($entityDefinition, $queryBuilder);
$queryBuilder->setParameter(0, array_keys($idToData), Connection::PARAM_STR_ARRAY);
$queryResult = $queryBuilder->execute();
$manyReferences = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
foreach ($manyReferences as $manyReference) {
$entityId = $manyReference['this'];
unset($manyReference['this']);
$idToData[$entityId][$manyField][] = $manyReference;
}
} | [
"protected",
"function",
"enrichWithManyField",
"(",
"&",
"$",
"idToData",
",",
"$",
"manyField",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"nameField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'nameField'",
")",
";",
"$",
"thisField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'thisField'",
")",
";",
"$",
"thatField",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'thatField'",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'entity'",
")",
";",
"$",
"entityDefinition",
"=",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"entity",
")",
"->",
"getDefinition",
"(",
")",
";",
"$",
"entityTable",
"=",
"$",
"entityDefinition",
"->",
"getTable",
"(",
")",
";",
"$",
"nameSelect",
"=",
"$",
"nameField",
"!==",
"null",
"?",
"', t2.`'",
".",
"$",
"nameField",
".",
"'` AS name'",
":",
"''",
";",
"$",
"queryBuilder",
"->",
"select",
"(",
"'t1.`'",
".",
"$",
"thisField",
".",
"'` AS this, t1.`'",
".",
"$",
"thatField",
".",
"'` AS id'",
".",
"$",
"nameSelect",
")",
"->",
"from",
"(",
"'`'",
".",
"$",
"manyField",
".",
"'`'",
",",
"'t1'",
")",
"->",
"leftJoin",
"(",
"'t1'",
",",
"'`'",
".",
"$",
"entityTable",
".",
"'`'",
",",
"'t2'",
",",
"'t2.id = t1.`'",
".",
"$",
"thatField",
".",
"'`'",
")",
"->",
"where",
"(",
"'t1.`'",
".",
"$",
"thisField",
".",
"'` IN (?)'",
")",
";",
"$",
"this",
"->",
"addSoftDeletionToQuery",
"(",
"$",
"entityDefinition",
",",
"$",
"queryBuilder",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"0",
",",
"array_keys",
"(",
"$",
"idToData",
")",
",",
"Connection",
"::",
"PARAM_STR_ARRAY",
")",
";",
"$",
"queryResult",
"=",
"$",
"queryBuilder",
"->",
"execute",
"(",
")",
";",
"$",
"manyReferences",
"=",
"$",
"queryResult",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"foreach",
"(",
"$",
"manyReferences",
"as",
"$",
"manyReference",
")",
"{",
"$",
"entityId",
"=",
"$",
"manyReference",
"[",
"'this'",
"]",
";",
"unset",
"(",
"$",
"manyReference",
"[",
"'this'",
"]",
")",
";",
"$",
"idToData",
"[",
"$",
"entityId",
"]",
"[",
"$",
"manyField",
"]",
"[",
"]",
"=",
"$",
"manyReference",
";",
"}",
"}"
] | Enriches the given mapping of entity id to raw entity data with some many-to-many data.
@param array $idToData
a reference to the map entity id to raw entity data
@param $manyField
the many field to enrich data with | [
"Enriches",
"the",
"given",
"mapping",
"of",
"entity",
"id",
"to",
"raw",
"entity",
"data",
"with",
"some",
"many",
"-",
"to",
"-",
"many",
"data",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L364-L389 |
38,209 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.enrichWithMany | protected function enrichWithMany(array $rows)
{
$manyFields = $this->getManyFields();
$idToData = [];
foreach ($rows as $row) {
foreach ($manyFields as $manyField) {
$row[$manyField] = [];
}
$idToData[$row['id']] = $row;
}
foreach ($manyFields as $manyField) {
$this->enrichWithManyField($idToData, $manyField);
}
return array_values($idToData);
} | php | protected function enrichWithMany(array $rows)
{
$manyFields = $this->getManyFields();
$idToData = [];
foreach ($rows as $row) {
foreach ($manyFields as $manyField) {
$row[$manyField] = [];
}
$idToData[$row['id']] = $row;
}
foreach ($manyFields as $manyField) {
$this->enrichWithManyField($idToData, $manyField);
}
return array_values($idToData);
} | [
"protected",
"function",
"enrichWithMany",
"(",
"array",
"$",
"rows",
")",
"{",
"$",
"manyFields",
"=",
"$",
"this",
"->",
"getManyFields",
"(",
")",
";",
"$",
"idToData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"manyFields",
"as",
"$",
"manyField",
")",
"{",
"$",
"row",
"[",
"$",
"manyField",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"idToData",
"[",
"$",
"row",
"[",
"'id'",
"]",
"]",
"=",
"$",
"row",
";",
"}",
"foreach",
"(",
"$",
"manyFields",
"as",
"$",
"manyField",
")",
"{",
"$",
"this",
"->",
"enrichWithManyField",
"(",
"$",
"idToData",
",",
"$",
"manyField",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"idToData",
")",
";",
"}"
] | Fetches to the rows belonging many-to-many entries and adds them to the rows.
@param array $rows
the rows to enrich
@return array
the enriched rows | [
"Fetches",
"to",
"the",
"rows",
"belonging",
"many",
"-",
"to",
"-",
"many",
"entries",
"and",
"adds",
"them",
"to",
"the",
"rows",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L399-L413 |
38,210 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.saveMany | protected function saveMany(Entity $entity)
{
$manyFields = $this->getManyFields();
$id = $entity->get('id');
foreach ($manyFields as $manyField) {
$thisField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thisField').'`';
$thatField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thatField').'`';
$this->database->delete($manyField, [$thisField => $id]);
$manyValues = $entity->get($manyField) ?: [];
foreach ($manyValues as $thatId) {
$this->database->insert($manyField, [
$thisField => $id,
$thatField => $thatId['id']
]);
}
}
} | php | protected function saveMany(Entity $entity)
{
$manyFields = $this->getManyFields();
$id = $entity->get('id');
foreach ($manyFields as $manyField) {
$thisField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thisField').'`';
$thatField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thatField').'`';
$this->database->delete($manyField, [$thisField => $id]);
$manyValues = $entity->get($manyField) ?: [];
foreach ($manyValues as $thatId) {
$this->database->insert($manyField, [
$thisField => $id,
$thatField => $thatId['id']
]);
}
}
} | [
"protected",
"function",
"saveMany",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"manyFields",
"=",
"$",
"this",
"->",
"getManyFields",
"(",
")",
";",
"$",
"id",
"=",
"$",
"entity",
"->",
"get",
"(",
"'id'",
")",
";",
"foreach",
"(",
"$",
"manyFields",
"as",
"$",
"manyField",
")",
"{",
"$",
"thisField",
"=",
"'`'",
".",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'thisField'",
")",
".",
"'`'",
";",
"$",
"thatField",
"=",
"'`'",
".",
"$",
"this",
"->",
"definition",
"->",
"getSubTypeField",
"(",
"$",
"manyField",
",",
"'many'",
",",
"'thatField'",
")",
".",
"'`'",
";",
"$",
"this",
"->",
"database",
"->",
"delete",
"(",
"$",
"manyField",
",",
"[",
"$",
"thisField",
"=>",
"$",
"id",
"]",
")",
";",
"$",
"manyValues",
"=",
"$",
"entity",
"->",
"get",
"(",
"$",
"manyField",
")",
"?",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"manyValues",
"as",
"$",
"thatId",
")",
"{",
"$",
"this",
"->",
"database",
"->",
"insert",
"(",
"$",
"manyField",
",",
"[",
"$",
"thisField",
"=>",
"$",
"id",
",",
"$",
"thatField",
"=>",
"$",
"thatId",
"[",
"'id'",
"]",
"]",
")",
";",
"}",
"}",
"}"
] | First, deletes all to the given entity related many-to-many entries from the DB
and then writes them again.
@param Entity $entity
the entity to save the many-to-many entries of | [
"First",
"deletes",
"all",
"to",
"the",
"given",
"entity",
"related",
"many",
"-",
"to",
"-",
"many",
"entries",
"from",
"the",
"DB",
"and",
"then",
"writes",
"them",
"again",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L422-L438 |
38,211 | philiplb/CRUDlex | src/CRUDlex/MySQLData.php | MySQLData.enrichWithReference | protected function enrichWithReference(array &$entities)
{
if (empty($entities)) {
return;
}
foreach ($this->definition->getFieldNames() as $field) {
if ($this->definition->getType($field) !== 'reference') {
continue;
}
$this->fetchReferencesForField($entities, $field);
}
} | php | protected function enrichWithReference(array &$entities)
{
if (empty($entities)) {
return;
}
foreach ($this->definition->getFieldNames() as $field) {
if ($this->definition->getType($field) !== 'reference') {
continue;
}
$this->fetchReferencesForField($entities, $field);
}
} | [
"protected",
"function",
"enrichWithReference",
"(",
"array",
"&",
"$",
"entities",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"entities",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"getFieldNames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"field",
")",
"!==",
"'reference'",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"fetchReferencesForField",
"(",
"$",
"entities",
",",
"$",
"field",
")",
";",
"}",
"}"
] | Adds the id and name of referenced entities to the given entities. Each
reference field is before the raw id of the referenced entity and after
the fetch, it's an array with the keys id and name.
@param Entity[] &$entities
the entities to fetch the references for
@return void | [
"Adds",
"the",
"id",
"and",
"name",
"of",
"referenced",
"entities",
"to",
"the",
"given",
"entities",
".",
"Each",
"reference",
"field",
"is",
"before",
"the",
"raw",
"id",
"of",
"the",
"referenced",
"entity",
"and",
"after",
"the",
"fetch",
"it",
"s",
"an",
"array",
"with",
"the",
"keys",
"id",
"and",
"name",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/MySQLData.php#L450-L461 |
38,212 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.hydrate | protected function hydrate(array $row)
{
$fieldNames = $this->definition->getFieldNames(true);
$entity = new Entity($this->definition);
foreach ($fieldNames as $fieldName) {
$entity->set($fieldName, $row[$fieldName]);
}
return $entity;
} | php | protected function hydrate(array $row)
{
$fieldNames = $this->definition->getFieldNames(true);
$entity = new Entity($this->definition);
foreach ($fieldNames as $fieldName) {
$entity->set($fieldName, $row[$fieldName]);
}
return $entity;
} | [
"protected",
"function",
"hydrate",
"(",
"array",
"$",
"row",
")",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"definition",
"->",
"getFieldNames",
"(",
"true",
")",
";",
"$",
"entity",
"=",
"new",
"Entity",
"(",
"$",
"this",
"->",
"definition",
")",
";",
"foreach",
"(",
"$",
"fieldNames",
"as",
"$",
"fieldName",
")",
"{",
"$",
"entity",
"->",
"set",
"(",
"$",
"fieldName",
",",
"$",
"row",
"[",
"$",
"fieldName",
"]",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Creates an Entity from the raw data array with the field name
as keys and field values as values.
@param array $row
the array with the raw data
@return Entity
the entity containing the array data then | [
"Creates",
"an",
"Entity",
"from",
"the",
"raw",
"data",
"array",
"with",
"the",
"field",
"name",
"as",
"keys",
"and",
"field",
"values",
"as",
"values",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L78-L86 |
38,213 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.getManyFields | protected function getManyFields()
{
$fields = $this->definition->getFieldNames(true);
return array_filter($fields, function($field) {
return $this->definition->getType($field) === 'many';
});
} | php | protected function getManyFields()
{
$fields = $this->definition->getFieldNames(true);
return array_filter($fields, function($field) {
return $this->definition->getType($field) === 'many';
});
} | [
"protected",
"function",
"getManyFields",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"definition",
"->",
"getFieldNames",
"(",
"true",
")",
";",
"return",
"array_filter",
"(",
"$",
"fields",
",",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"field",
")",
"===",
"'many'",
";",
"}",
")",
";",
"}"
] | Gets the many-to-many fields.
@return array|\string[]
the many-to-many fields | [
"Gets",
"the",
"many",
"-",
"to",
"-",
"many",
"fields",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L112-L118 |
38,214 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.getFormFields | protected function getFormFields()
{
$manyFields = $this->getManyFields();
$formFields = [];
foreach ($this->definition->getEditableFieldNames() as $field) {
if (!in_array($field, $manyFields)) {
$formFields[] = $field;
}
}
return $formFields;
} | php | protected function getFormFields()
{
$manyFields = $this->getManyFields();
$formFields = [];
foreach ($this->definition->getEditableFieldNames() as $field) {
if (!in_array($field, $manyFields)) {
$formFields[] = $field;
}
}
return $formFields;
} | [
"protected",
"function",
"getFormFields",
"(",
")",
"{",
"$",
"manyFields",
"=",
"$",
"this",
"->",
"getManyFields",
"(",
")",
";",
"$",
"formFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"getEditableFieldNames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"field",
",",
"$",
"manyFields",
")",
")",
"{",
"$",
"formFields",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"formFields",
";",
"}"
] | Gets all form fields including the many-to-many-ones.
@return array
all form fields | [
"Gets",
"all",
"form",
"fields",
"including",
"the",
"many",
"-",
"to",
"-",
"many",
"-",
"ones",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L126-L136 |
38,215 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.deleteChildren | protected function deleteChildren($id, $deleteCascade)
{
foreach ($this->definition->getChildren() as $childArray) {
$childData = $this->definition->getService()->getData($childArray[2]);
$children = $childData->listEntries([$childArray[1] => $id]);
foreach ($children as $child) {
$result = $childData->events->shouldExecute($child, 'before', 'delete');
if (!$result) {
return static::DELETION_FAILED_EVENT;
}
$childData->doDelete($child, $deleteCascade);
$childData->events->shouldExecute($child, 'after', 'delete');
}
}
return static::DELETION_SUCCESS;
} | php | protected function deleteChildren($id, $deleteCascade)
{
foreach ($this->definition->getChildren() as $childArray) {
$childData = $this->definition->getService()->getData($childArray[2]);
$children = $childData->listEntries([$childArray[1] => $id]);
foreach ($children as $child) {
$result = $childData->events->shouldExecute($child, 'before', 'delete');
if (!$result) {
return static::DELETION_FAILED_EVENT;
}
$childData->doDelete($child, $deleteCascade);
$childData->events->shouldExecute($child, 'after', 'delete');
}
}
return static::DELETION_SUCCESS;
} | [
"protected",
"function",
"deleteChildren",
"(",
"$",
"id",
",",
"$",
"deleteCascade",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"getChildren",
"(",
")",
"as",
"$",
"childArray",
")",
"{",
"$",
"childData",
"=",
"$",
"this",
"->",
"definition",
"->",
"getService",
"(",
")",
"->",
"getData",
"(",
"$",
"childArray",
"[",
"2",
"]",
")",
";",
"$",
"children",
"=",
"$",
"childData",
"->",
"listEntries",
"(",
"[",
"$",
"childArray",
"[",
"1",
"]",
"=>",
"$",
"id",
"]",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"result",
"=",
"$",
"childData",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"child",
",",
"'before'",
",",
"'delete'",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"static",
"::",
"DELETION_FAILED_EVENT",
";",
"}",
"$",
"childData",
"->",
"doDelete",
"(",
"$",
"child",
",",
"$",
"deleteCascade",
")",
";",
"$",
"childData",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"child",
",",
"'after'",
",",
"'delete'",
")",
";",
"}",
"}",
"return",
"static",
"::",
"DELETION_SUCCESS",
";",
"}"
] | Performs the cascading children deletion.
@param integer $id
the current entities id
@param boolean $deleteCascade
whether to delete children and sub children
@return integer
returns one of:
- AbstractData::DELETION_SUCCESS -> successful deletion
- AbstractData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references
- AbstractData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event | [
"Performs",
"the",
"cascading",
"children",
"deletion",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L152-L167 |
38,216 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.getReferenceIds | protected function getReferenceIds(array $entities, $field)
{
$ids = array_map(function(Entity $entity) use ($field) {
$id = $entity->get($field);
return is_array($id) ? $id['id'] : $id;
}, $entities);
return $ids;
} | php | protected function getReferenceIds(array $entities, $field)
{
$ids = array_map(function(Entity $entity) use ($field) {
$id = $entity->get($field);
return is_array($id) ? $id['id'] : $id;
}, $entities);
return $ids;
} | [
"protected",
"function",
"getReferenceIds",
"(",
"array",
"$",
"entities",
",",
"$",
"field",
")",
"{",
"$",
"ids",
"=",
"array_map",
"(",
"function",
"(",
"Entity",
"$",
"entity",
")",
"use",
"(",
"$",
"field",
")",
"{",
"$",
"id",
"=",
"$",
"entity",
"->",
"get",
"(",
"$",
"field",
")",
";",
"return",
"is_array",
"(",
"$",
"id",
")",
"?",
"$",
"id",
"[",
"'id'",
"]",
":",
"$",
"id",
";",
"}",
",",
"$",
"entities",
")",
";",
"return",
"$",
"ids",
";",
"}"
] | Gets an array of reference ids for the given entities.
@param array $entities
the entities to extract the ids
@param string $field
the reference field
@return array
the extracted ids | [
"Gets",
"an",
"array",
"of",
"reference",
"ids",
"for",
"the",
"given",
"entities",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L180-L187 |
38,217 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.create | public function create(Entity $entity)
{
$result = $this->events->shouldExecute($entity, 'before', 'create');
if (!$result) {
return false;
}
$result = $this->doCreate($entity);
$this->events->shouldExecute($entity, 'after', 'create');
return $result;
} | php | public function create(Entity $entity)
{
$result = $this->events->shouldExecute($entity, 'before', 'create');
if (!$result) {
return false;
}
$result = $this->doCreate($entity);
$this->events->shouldExecute($entity, 'after', 'create');
return $result;
} | [
"public",
"function",
"create",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'before'",
",",
"'create'",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"doCreate",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'after'",
",",
"'create'",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Persists the given entity as new entry in the datasource.
@param Entity $entity
the entity to persist
@return boolean
true on successful creation | [
"Persists",
"the",
"given",
"entity",
"as",
"new",
"entry",
"in",
"the",
"datasource",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L267-L276 |
38,218 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.update | public function update(Entity $entity)
{
if (!$this->events->shouldExecute($entity, 'before', 'update')) {
return false;
}
$result = $this->doUpdate($entity);
$this->events->shouldExecute($entity, 'after', 'update');
return $result;
} | php | public function update(Entity $entity)
{
if (!$this->events->shouldExecute($entity, 'before', 'update')) {
return false;
}
$result = $this->doUpdate($entity);
$this->events->shouldExecute($entity, 'after', 'update');
return $result;
} | [
"public",
"function",
"update",
"(",
"Entity",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'before'",
",",
"'update'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"doUpdate",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'after'",
",",
"'update'",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Updates an existing entry in the datasource having the same id.
@param Entity $entity
the entity with the new data
@return boolean
true on successful update | [
"Updates",
"an",
"existing",
"entry",
"in",
"the",
"datasource",
"having",
"the",
"same",
"id",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L287-L295 |
38,219 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.delete | public function delete($entity)
{
$result = $this->events->shouldExecute($entity, 'before', 'delete');
if (!$result) {
return static::DELETION_FAILED_EVENT;
}
$result = $this->doDelete($entity, $this->definition->isDeleteCascade());
$this->events->shouldExecute($entity, 'after', 'delete');
return $result;
} | php | public function delete($entity)
{
$result = $this->events->shouldExecute($entity, 'before', 'delete');
if (!$result) {
return static::DELETION_FAILED_EVENT;
}
$result = $this->doDelete($entity, $this->definition->isDeleteCascade());
$this->events->shouldExecute($entity, 'after', 'delete');
return $result;
} | [
"public",
"function",
"delete",
"(",
"$",
"entity",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'before'",
",",
"'delete'",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"static",
"::",
"DELETION_FAILED_EVENT",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"doDelete",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"definition",
"->",
"isDeleteCascade",
"(",
")",
")",
";",
"$",
"this",
"->",
"events",
"->",
"shouldExecute",
"(",
"$",
"entity",
",",
"'after'",
",",
"'delete'",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Deletes an entry from the datasource.
@param Entity $entity
the entity to delete
@return integer
returns one of:
- AbstractData::DELETION_SUCCESS -> successful deletion
- AbstractData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references
- AbstractData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event | [
"Deletes",
"an",
"entry",
"from",
"the",
"datasource",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L309-L318 |
38,220 | philiplb/CRUDlex | src/CRUDlex/AbstractData.php | AbstractData.createEmpty | public function createEmpty()
{
$entity = new Entity($this->definition);
$fields = $this->definition->getEditableFieldNames();
foreach ($fields as $field) {
$value = null;
if ($this->definition->getType($field) == 'fixed') {
$value = $this->definition->getField($field, 'value');
}
$entity->set($field, $value);
}
$entity->set('id', null);
return $entity;
} | php | public function createEmpty()
{
$entity = new Entity($this->definition);
$fields = $this->definition->getEditableFieldNames();
foreach ($fields as $field) {
$value = null;
if ($this->definition->getType($field) == 'fixed') {
$value = $this->definition->getField($field, 'value');
}
$entity->set($field, $value);
}
$entity->set('id', null);
return $entity;
} | [
"public",
"function",
"createEmpty",
"(",
")",
"{",
"$",
"entity",
"=",
"new",
"Entity",
"(",
"$",
"this",
"->",
"definition",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"definition",
"->",
"getEditableFieldNames",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"field",
")",
"==",
"'fixed'",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"definition",
"->",
"getField",
"(",
"$",
"field",
",",
"'value'",
")",
";",
"}",
"$",
"entity",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"$",
"entity",
"->",
"set",
"(",
"'id'",
",",
"null",
")",
";",
"return",
"$",
"entity",
";",
"}"
] | Creates a new, empty entity instance having all fields prefilled with
null or the defined value in case of fixed fields.
@return Entity
the newly created entity | [
"Creates",
"a",
"new",
"empty",
"entity",
"instance",
"having",
"all",
"fields",
"prefilled",
"with",
"null",
"or",
"the",
"defined",
"value",
"in",
"case",
"of",
"fixed",
"fields",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/AbstractData.php#L386-L399 |
38,221 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getFilteredFieldNames | protected function getFilteredFieldNames(array $exclude)
{
$fieldNames = $this->getFieldNames(true);
$result = [];
foreach ($fieldNames as $fieldName) {
if (!in_array($fieldName, $exclude)) {
$result[] = $fieldName;
}
}
return $result;
} | php | protected function getFilteredFieldNames(array $exclude)
{
$fieldNames = $this->getFieldNames(true);
$result = [];
foreach ($fieldNames as $fieldName) {
if (!in_array($fieldName, $exclude)) {
$result[] = $fieldName;
}
}
return $result;
} | [
"protected",
"function",
"getFilteredFieldNames",
"(",
"array",
"$",
"exclude",
")",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"getFieldNames",
"(",
"true",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fieldNames",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fieldName",
",",
"$",
"exclude",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"fieldName",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Gets the field names exluding the given ones.
@param string[] $exclude
the field names to exclude
@return array
all field names excluding the given ones | [
"Gets",
"the",
"field",
"names",
"exluding",
"the",
"given",
"ones",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L141-L151 |
38,222 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.checkFieldNames | protected function checkFieldNames($reference, $fieldNames)
{
$validFieldNames = $this->getPublicFieldNames();
$invalidFieldNames = [];
foreach ($fieldNames as $fieldName) {
if (!in_array($fieldName, $validFieldNames)) {
$invalidFieldNames[] = $fieldName;
}
}
if (!empty($invalidFieldNames)) {
throw new \InvalidArgumentException('Invalid fields ('.join(', ', $invalidFieldNames).') in '.$reference.', valid ones are: '.join(', ', $validFieldNames));
}
} | php | protected function checkFieldNames($reference, $fieldNames)
{
$validFieldNames = $this->getPublicFieldNames();
$invalidFieldNames = [];
foreach ($fieldNames as $fieldName) {
if (!in_array($fieldName, $validFieldNames)) {
$invalidFieldNames[] = $fieldName;
}
}
if (!empty($invalidFieldNames)) {
throw new \InvalidArgumentException('Invalid fields ('.join(', ', $invalidFieldNames).') in '.$reference.', valid ones are: '.join(', ', $validFieldNames));
}
} | [
"protected",
"function",
"checkFieldNames",
"(",
"$",
"reference",
",",
"$",
"fieldNames",
")",
"{",
"$",
"validFieldNames",
"=",
"$",
"this",
"->",
"getPublicFieldNames",
"(",
")",
";",
"$",
"invalidFieldNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fieldNames",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fieldName",
",",
"$",
"validFieldNames",
")",
")",
"{",
"$",
"invalidFieldNames",
"[",
"]",
"=",
"$",
"fieldName",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"invalidFieldNames",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid fields ('",
".",
"join",
"(",
"', '",
",",
"$",
"invalidFieldNames",
")",
".",
"') in '",
".",
"$",
"reference",
".",
"', valid ones are: '",
".",
"join",
"(",
"', '",
",",
"$",
"validFieldNames",
")",
")",
";",
"}",
"}"
] | Checks whether the given field names are declared and existing.
@param string $reference
a hint towards the source of an invalid field name
@param array $fieldNames
the field names to check
@throws \InvalidArgumentException
thrown with all invalid field names | [
"Checks",
"whether",
"the",
"given",
"field",
"names",
"are",
"declared",
"and",
"existing",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L163-L175 |
38,223 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getFieldNames | public function getFieldNames($includeMany = false)
{
$fieldNames = $this->getReadOnlyFields();
foreach ($this->fields as $field => $value) {
if ($includeMany || $this->getType($field) !== 'many') {
$fieldNames[] = $field;
}
}
return $fieldNames;
} | php | public function getFieldNames($includeMany = false)
{
$fieldNames = $this->getReadOnlyFields();
foreach ($this->fields as $field => $value) {
if ($includeMany || $this->getType($field) !== 'many') {
$fieldNames[] = $field;
}
}
return $fieldNames;
} | [
"public",
"function",
"getFieldNames",
"(",
"$",
"includeMany",
"=",
"false",
")",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"getReadOnlyFields",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"includeMany",
"||",
"$",
"this",
"->",
"getType",
"(",
"$",
"field",
")",
"!==",
"'many'",
")",
"{",
"$",
"fieldNames",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"return",
"$",
"fieldNames",
";",
"}"
] | Gets all field names, including the implicit ones like "id" or
"created_at".
@param boolean $includeMany
whether to include the many fields as well
@return string[]
the field names | [
"Gets",
"all",
"field",
"names",
"including",
"the",
"implicit",
"ones",
"like",
"id",
"or",
"created_at",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L225-L234 |
38,224 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getFieldLabel | public function getFieldLabel($fieldName)
{
$result = $this->getField($fieldName, 'label_'.$this->locale, $this->getField($fieldName, 'label'));
if ($result === null && array_key_exists($fieldName, $this->standardFieldLabels)) {
$result = $this->standardFieldLabels[$fieldName];
}
if ($result === null) {
$result = $fieldName;
}
return $result;
} | php | public function getFieldLabel($fieldName)
{
$result = $this->getField($fieldName, 'label_'.$this->locale, $this->getField($fieldName, 'label'));
if ($result === null && array_key_exists($fieldName, $this->standardFieldLabels)) {
$result = $this->standardFieldLabels[$fieldName];
}
if ($result === null) {
$result = $fieldName;
}
return $result;
} | [
"public",
"function",
"getFieldLabel",
"(",
"$",
"fieldName",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"fieldName",
",",
"'label_'",
".",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"getField",
"(",
"$",
"fieldName",
",",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"null",
"&&",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"this",
"->",
"standardFieldLabels",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"standardFieldLabels",
"[",
"$",
"fieldName",
"]",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"fieldName",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Gets the label of a field.
@param string $fieldName
the field name
@return string
the label of the field or the field name if no label is set in the CRUD
YAML | [
"Gets",
"the",
"label",
"of",
"a",
"field",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L469-L482 |
38,225 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getLabel | public function getLabel()
{
if ($this->locale && array_key_exists($this->locale, $this->localeLabels)) {
return $this->localeLabels[$this->locale];
}
return $this->label;
} | php | public function getLabel()
{
if ($this->locale && array_key_exists($this->locale, $this->localeLabels)) {
return $this->localeLabels[$this->locale];
}
return $this->label;
} | [
"public",
"function",
"getLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"locale",
"&&",
"array_key_exists",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"localeLabels",
")",
")",
"{",
"return",
"$",
"this",
"->",
"localeLabels",
"[",
"$",
"this",
"->",
"locale",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"label",
";",
"}"
] | Gets the label for the entity.
@return string
the label for the entity | [
"Gets",
"the",
"label",
"for",
"the",
"entity",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L525-L531 |
38,226 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getSubTypeField | public function getSubTypeField($fieldName, $subType, $key)
{
if (!isset($this->fields[$fieldName][$subType][$key])) {
return null;
}
return $this->fields[$fieldName][$subType][$key];
} | php | public function getSubTypeField($fieldName, $subType, $key)
{
if (!isset($this->fields[$fieldName][$subType][$key])) {
return null;
}
return $this->fields[$fieldName][$subType][$key];
} | [
"public",
"function",
"getSubTypeField",
"(",
"$",
"fieldName",
",",
"$",
"subType",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"fieldName",
"]",
"[",
"$",
"subType",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"fieldName",
"]",
"[",
"$",
"subType",
"]",
"[",
"$",
"key",
"]",
";",
"}"
] | Gets a sub field of an field.
@param string $fieldName
the field name of the sub type
@param string $subType
the sub type like "reference" or "many"
@param string $key
the key of the value
@return string
the value of the sub field | [
"Gets",
"a",
"sub",
"field",
"of",
"an",
"field",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L726-L734 |
38,227 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.getField | public function getField($name, $key, $default = null)
{
if (array_key_exists($name, $this->fields) && array_key_exists($key, $this->fields[$name])) {
return $this->fields[$name][$key];
}
return $default;
} | php | public function getField($name, $key, $default = null)
{
if (array_key_exists($name, $this->fields) && array_key_exists($key, $this->fields[$name])) {
return $this->fields[$name][$key];
}
return $default;
} | [
"public",
"function",
"getField",
"(",
"$",
"name",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fields",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Gets the value of a field key.
@param string $name
the name of the field
@param string $key
the value of the key
@param mixed $default
the default value to return if nothing is found
@return mixed
the value of the field key or null if not existing | [
"Gets",
"the",
"value",
"of",
"a",
"field",
"key",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L749-L755 |
38,228 | philiplb/CRUDlex | src/CRUDlex/EntityDefinition.php | EntityDefinition.setField | public function setField($name, $key, $value)
{
if (!array_key_exists($name, $this->fields)) {
$this->fields[$name] = [];
}
$this->fields[$name][$key] = $value;
} | php | public function setField($name, $key, $value)
{
if (!array_key_exists($name, $this->fields)) {
$this->fields[$name] = [];
}
$this->fields[$name][$key] = $value;
} | [
"public",
"function",
"setField",
"(",
"$",
"name",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the value of a field key. If the field or the key in the field
don't exist, they get created.
@param string $name
the name of the field
@param string $key
the value of the key
@param mixed $value
the new value | [
"Sets",
"the",
"value",
"of",
"a",
"field",
"key",
".",
"If",
"the",
"field",
"or",
"the",
"key",
"in",
"the",
"field",
"don",
"t",
"exist",
"they",
"get",
"created",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityDefinition.php#L768-L774 |
38,229 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.modifyFilesAndSetFlashBag | protected function modifyFilesAndSetFlashBag(Request $request, AbstractData $crudData, Entity $instance, $entity, $mode)
{
$id = $instance->get('id');
$fileHandler = new FileHandler($this->filesystem, $crudData->getDefinition());
$result = $mode == 'edit' ? $fileHandler->updateFiles($crudData, $request, $instance, $entity) : $fileHandler->createFiles($crudData, $request, $instance, $entity);
if (!$result) {
return null;
}
$this->session->getFlashBag()->add('success', $this->translator->trans('crudlex.'.$mode.'.success', [
'%label%' => $crudData->getDefinition()->getLabel(),
'%id%' => $id
]));
return new RedirectResponse($this->service->generateURL('crudShow', ['entity' => $entity, 'id' => $id]));
} | php | protected function modifyFilesAndSetFlashBag(Request $request, AbstractData $crudData, Entity $instance, $entity, $mode)
{
$id = $instance->get('id');
$fileHandler = new FileHandler($this->filesystem, $crudData->getDefinition());
$result = $mode == 'edit' ? $fileHandler->updateFiles($crudData, $request, $instance, $entity) : $fileHandler->createFiles($crudData, $request, $instance, $entity);
if (!$result) {
return null;
}
$this->session->getFlashBag()->add('success', $this->translator->trans('crudlex.'.$mode.'.success', [
'%label%' => $crudData->getDefinition()->getLabel(),
'%id%' => $id
]));
return new RedirectResponse($this->service->generateURL('crudShow', ['entity' => $entity, 'id' => $id]));
} | [
"protected",
"function",
"modifyFilesAndSetFlashBag",
"(",
"Request",
"$",
"request",
",",
"AbstractData",
"$",
"crudData",
",",
"Entity",
"$",
"instance",
",",
"$",
"entity",
",",
"$",
"mode",
")",
"{",
"$",
"id",
"=",
"$",
"instance",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"fileHandler",
"=",
"new",
"FileHandler",
"(",
"$",
"this",
"->",
"filesystem",
",",
"$",
"crudData",
"->",
"getDefinition",
"(",
")",
")",
";",
"$",
"result",
"=",
"$",
"mode",
"==",
"'edit'",
"?",
"$",
"fileHandler",
"->",
"updateFiles",
"(",
"$",
"crudData",
",",
"$",
"request",
",",
"$",
"instance",
",",
"$",
"entity",
")",
":",
"$",
"fileHandler",
"->",
"createFiles",
"(",
"$",
"crudData",
",",
"$",
"request",
",",
"$",
"instance",
",",
"$",
"entity",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'crudlex.'",
".",
"$",
"mode",
".",
"'.success'",
",",
"[",
"'%label%'",
"=>",
"$",
"crudData",
"->",
"getDefinition",
"(",
")",
"->",
"getLabel",
"(",
")",
",",
"'%id%'",
"=>",
"$",
"id",
"]",
")",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"service",
"->",
"generateURL",
"(",
"'crudShow'",
",",
"[",
"'entity'",
"=>",
"$",
"entity",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
")",
";",
"}"
] | Postprocesses the entity after modification by handling the uploaded
files and setting the flash.
@param Request $request
the current request
@param AbstractData $crudData
the data instance of the entity
@param Entity $instance
the entity
@param string $entity
the name of the entity
@param string $mode
whether to 'edit' or to 'create' the entity
@return null|\Symfony\Component\HttpFoundation\RedirectResponse
the HTTP response of this modification | [
"Postprocesses",
"the",
"entity",
"after",
"modification",
"by",
"handling",
"the",
"uploaded",
"files",
"and",
"setting",
"the",
"flash",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L78-L91 |
38,230 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.setValidationFailedFlashes | protected function setValidationFailedFlashes($optimisticLocking, $mode)
{
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.'.$mode.'.error'));
if ($optimisticLocking) {
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.edit.locked'));
}
} | php | protected function setValidationFailedFlashes($optimisticLocking, $mode)
{
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.'.$mode.'.error'));
if ($optimisticLocking) {
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.edit.locked'));
}
} | [
"protected",
"function",
"setValidationFailedFlashes",
"(",
"$",
"optimisticLocking",
",",
"$",
"mode",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'danger'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'crudlex.'",
".",
"$",
"mode",
".",
"'.error'",
")",
")",
";",
"if",
"(",
"$",
"optimisticLocking",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'danger'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'crudlex.edit.locked'",
")",
")",
";",
"}",
"}"
] | Sets the flashes of a failed entity modification.
@param boolean $optimisticLocking
whether the optimistic locking failed
@param string $mode
the modification mode, either 'create' or 'edit' | [
"Sets",
"the",
"flashes",
"of",
"a",
"failed",
"entity",
"modification",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L101-L107 |
38,231 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.modifyEntity | protected function modifyEntity(Request $request, AbstractData $crudData, Entity $instance, $entity, $edit)
{
$fieldErrors = [];
$mode = $edit ? 'edit' : 'create';
if ($request->getMethod() == 'POST') {
$instance->populateViaRequest($request);
$validator = new EntityValidator($instance);
$validation = $validator->validate($crudData, intval($request->get('version')));
$fieldErrors = $validation['errors'];
if (!$validation['valid']) {
$optimisticLocking = isset($fieldErrors['version']);
$this->setValidationFailedFlashes($optimisticLocking, $mode);
} else {
$modified = $edit ? $crudData->update($instance) : $crudData->create($instance);
$response = $modified ? $this->modifyFilesAndSetFlashBag($request, $crudData, $instance, $entity, $mode) : false;
if ($response) {
return $response;
}
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.'.$mode.'.failed'));
}
}
return new Response($this->twig->render($this->service->getTemplate('template', 'form', $entity), [
'crud' => $this->service,
'crudEntity' => $entity,
'crudData' => $crudData,
'entity' => $instance,
'mode' => $mode,
'fieldErrors' => $fieldErrors,
'layout' => $this->service->getTemplate('layout', $mode, $entity)
]));
} | php | protected function modifyEntity(Request $request, AbstractData $crudData, Entity $instance, $entity, $edit)
{
$fieldErrors = [];
$mode = $edit ? 'edit' : 'create';
if ($request->getMethod() == 'POST') {
$instance->populateViaRequest($request);
$validator = new EntityValidator($instance);
$validation = $validator->validate($crudData, intval($request->get('version')));
$fieldErrors = $validation['errors'];
if (!$validation['valid']) {
$optimisticLocking = isset($fieldErrors['version']);
$this->setValidationFailedFlashes($optimisticLocking, $mode);
} else {
$modified = $edit ? $crudData->update($instance) : $crudData->create($instance);
$response = $modified ? $this->modifyFilesAndSetFlashBag($request, $crudData, $instance, $entity, $mode) : false;
if ($response) {
return $response;
}
$this->session->getFlashBag()->add('danger', $this->translator->trans('crudlex.'.$mode.'.failed'));
}
}
return new Response($this->twig->render($this->service->getTemplate('template', 'form', $entity), [
'crud' => $this->service,
'crudEntity' => $entity,
'crudData' => $crudData,
'entity' => $instance,
'mode' => $mode,
'fieldErrors' => $fieldErrors,
'layout' => $this->service->getTemplate('layout', $mode, $entity)
]));
} | [
"protected",
"function",
"modifyEntity",
"(",
"Request",
"$",
"request",
",",
"AbstractData",
"$",
"crudData",
",",
"Entity",
"$",
"instance",
",",
"$",
"entity",
",",
"$",
"edit",
")",
"{",
"$",
"fieldErrors",
"=",
"[",
"]",
";",
"$",
"mode",
"=",
"$",
"edit",
"?",
"'edit'",
":",
"'create'",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"instance",
"->",
"populateViaRequest",
"(",
"$",
"request",
")",
";",
"$",
"validator",
"=",
"new",
"EntityValidator",
"(",
"$",
"instance",
")",
";",
"$",
"validation",
"=",
"$",
"validator",
"->",
"validate",
"(",
"$",
"crudData",
",",
"intval",
"(",
"$",
"request",
"->",
"get",
"(",
"'version'",
")",
")",
")",
";",
"$",
"fieldErrors",
"=",
"$",
"validation",
"[",
"'errors'",
"]",
";",
"if",
"(",
"!",
"$",
"validation",
"[",
"'valid'",
"]",
")",
"{",
"$",
"optimisticLocking",
"=",
"isset",
"(",
"$",
"fieldErrors",
"[",
"'version'",
"]",
")",
";",
"$",
"this",
"->",
"setValidationFailedFlashes",
"(",
"$",
"optimisticLocking",
",",
"$",
"mode",
")",
";",
"}",
"else",
"{",
"$",
"modified",
"=",
"$",
"edit",
"?",
"$",
"crudData",
"->",
"update",
"(",
"$",
"instance",
")",
":",
"$",
"crudData",
"->",
"create",
"(",
"$",
"instance",
")",
";",
"$",
"response",
"=",
"$",
"modified",
"?",
"$",
"this",
"->",
"modifyFilesAndSetFlashBag",
"(",
"$",
"request",
",",
"$",
"crudData",
",",
"$",
"instance",
",",
"$",
"entity",
",",
"$",
"mode",
")",
":",
"false",
";",
"if",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'danger'",
",",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'crudlex.'",
".",
"$",
"mode",
".",
"'.failed'",
")",
")",
";",
"}",
"}",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"$",
"this",
"->",
"service",
"->",
"getTemplate",
"(",
"'template'",
",",
"'form'",
",",
"$",
"entity",
")",
",",
"[",
"'crud'",
"=>",
"$",
"this",
"->",
"service",
",",
"'crudEntity'",
"=>",
"$",
"entity",
",",
"'crudData'",
"=>",
"$",
"crudData",
",",
"'entity'",
"=>",
"$",
"instance",
",",
"'mode'",
"=>",
"$",
"mode",
",",
"'fieldErrors'",
"=>",
"$",
"fieldErrors",
",",
"'layout'",
"=>",
"$",
"this",
"->",
"service",
"->",
"getTemplate",
"(",
"'layout'",
",",
"$",
"mode",
",",
"$",
"entity",
")",
"]",
")",
")",
";",
"}"
] | Validates and saves the new or updated entity and returns the appropriate HTTP
response.
@param Request $request
the current request
@param AbstractData $crudData
the data instance of the entity
@param Entity $instance
the entity
@param string $entity
the name of the entity
@param boolean $edit
whether to edit (true) or to create (false) the entity
@return Response
the HTTP response of this modification | [
"Validates",
"and",
"saves",
"the",
"new",
"or",
"updated",
"entity",
"and",
"returns",
"the",
"appropriate",
"HTTP",
"response",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L127-L159 |
38,232 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.getAfterDeleteRedirectParameters | protected function getAfterDeleteRedirectParameters(Request $request, $entity, &$redirectPage)
{
$redirectPage = 'crudList';
$redirectParameters = ['entity' => $entity];
$redirectEntity = $request->get('redirectEntity');
$redirectId = $request->get('redirectId');
if ($redirectEntity && $redirectId) {
$redirectPage = 'crudShow';
$redirectParameters = [
'entity' => $redirectEntity,
'id' => $redirectId
];
}
return $redirectParameters;
} | php | protected function getAfterDeleteRedirectParameters(Request $request, $entity, &$redirectPage)
{
$redirectPage = 'crudList';
$redirectParameters = ['entity' => $entity];
$redirectEntity = $request->get('redirectEntity');
$redirectId = $request->get('redirectId');
if ($redirectEntity && $redirectId) {
$redirectPage = 'crudShow';
$redirectParameters = [
'entity' => $redirectEntity,
'id' => $redirectId
];
}
return $redirectParameters;
} | [
"protected",
"function",
"getAfterDeleteRedirectParameters",
"(",
"Request",
"$",
"request",
",",
"$",
"entity",
",",
"&",
"$",
"redirectPage",
")",
"{",
"$",
"redirectPage",
"=",
"'crudList'",
";",
"$",
"redirectParameters",
"=",
"[",
"'entity'",
"=>",
"$",
"entity",
"]",
";",
"$",
"redirectEntity",
"=",
"$",
"request",
"->",
"get",
"(",
"'redirectEntity'",
")",
";",
"$",
"redirectId",
"=",
"$",
"request",
"->",
"get",
"(",
"'redirectId'",
")",
";",
"if",
"(",
"$",
"redirectEntity",
"&&",
"$",
"redirectId",
")",
"{",
"$",
"redirectPage",
"=",
"'crudShow'",
";",
"$",
"redirectParameters",
"=",
"[",
"'entity'",
"=>",
"$",
"redirectEntity",
",",
"'id'",
"=>",
"$",
"redirectId",
"]",
";",
"}",
"return",
"$",
"redirectParameters",
";",
"}"
] | Gets the parameters for the redirection after deleting an entity.
@param Request $request
the current request
@param string $entity
the entity name
@param string $redirectPage
reference, where the page to redirect to will be stored
@return array<string,string>
the parameters of the redirection, entity and id | [
"Gets",
"the",
"parameters",
"for",
"the",
"redirection",
"after",
"deleting",
"an",
"entity",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L174-L188 |
38,233 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.buildUpListFilter | protected function buildUpListFilter(Request $request, EntityDefinition $definition, &$filter, &$filterActive, &$filterToUse, &$filterOperators)
{
$rawFilter = [];
foreach ($definition->getFilter() as $filterField) {
$type = $definition->getType($filterField);
$filter[$filterField] = $request->get('crudFilter'.$filterField);
$rawFilter[$filterField] = $filter[$filterField];
if ($filter[$filterField]) {
$filterActive = true;
$filterToUse[$filterField] = $filter[$filterField];
$filterOperators[$filterField] = '=';
if ($type === 'boolean') {
$filterToUse[$filterField] = $filter[$filterField] == 'true' ? 1 : 0;
} else if ($type === 'reference') {
$filter[$filterField] = ['id' => $filter[$filterField]];
} else if ($type === 'many') {
$filter[$filterField] = array_map(function($value) {
return ['id' => $value];
}, $filter[$filterField]);
$filterToUse[$filterField] = $filter[$filterField];
} else if (in_array($type, ['text', 'multiline', 'fixed'])) {
$filterToUse[$filterField] = '%'.$filter[$filterField].'%';
$filterOperators[$filterField] = 'LIKE';
}
}
}
return $rawFilter;
} | php | protected function buildUpListFilter(Request $request, EntityDefinition $definition, &$filter, &$filterActive, &$filterToUse, &$filterOperators)
{
$rawFilter = [];
foreach ($definition->getFilter() as $filterField) {
$type = $definition->getType($filterField);
$filter[$filterField] = $request->get('crudFilter'.$filterField);
$rawFilter[$filterField] = $filter[$filterField];
if ($filter[$filterField]) {
$filterActive = true;
$filterToUse[$filterField] = $filter[$filterField];
$filterOperators[$filterField] = '=';
if ($type === 'boolean') {
$filterToUse[$filterField] = $filter[$filterField] == 'true' ? 1 : 0;
} else if ($type === 'reference') {
$filter[$filterField] = ['id' => $filter[$filterField]];
} else if ($type === 'many') {
$filter[$filterField] = array_map(function($value) {
return ['id' => $value];
}, $filter[$filterField]);
$filterToUse[$filterField] = $filter[$filterField];
} else if (in_array($type, ['text', 'multiline', 'fixed'])) {
$filterToUse[$filterField] = '%'.$filter[$filterField].'%';
$filterOperators[$filterField] = 'LIKE';
}
}
}
return $rawFilter;
} | [
"protected",
"function",
"buildUpListFilter",
"(",
"Request",
"$",
"request",
",",
"EntityDefinition",
"$",
"definition",
",",
"&",
"$",
"filter",
",",
"&",
"$",
"filterActive",
",",
"&",
"$",
"filterToUse",
",",
"&",
"$",
"filterOperators",
")",
"{",
"$",
"rawFilter",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"definition",
"->",
"getFilter",
"(",
")",
"as",
"$",
"filterField",
")",
"{",
"$",
"type",
"=",
"$",
"definition",
"->",
"getType",
"(",
"$",
"filterField",
")",
";",
"$",
"filter",
"[",
"$",
"filterField",
"]",
"=",
"$",
"request",
"->",
"get",
"(",
"'crudFilter'",
".",
"$",
"filterField",
")",
";",
"$",
"rawFilter",
"[",
"$",
"filterField",
"]",
"=",
"$",
"filter",
"[",
"$",
"filterField",
"]",
";",
"if",
"(",
"$",
"filter",
"[",
"$",
"filterField",
"]",
")",
"{",
"$",
"filterActive",
"=",
"true",
";",
"$",
"filterToUse",
"[",
"$",
"filterField",
"]",
"=",
"$",
"filter",
"[",
"$",
"filterField",
"]",
";",
"$",
"filterOperators",
"[",
"$",
"filterField",
"]",
"=",
"'='",
";",
"if",
"(",
"$",
"type",
"===",
"'boolean'",
")",
"{",
"$",
"filterToUse",
"[",
"$",
"filterField",
"]",
"=",
"$",
"filter",
"[",
"$",
"filterField",
"]",
"==",
"'true'",
"?",
"1",
":",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"'reference'",
")",
"{",
"$",
"filter",
"[",
"$",
"filterField",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"filter",
"[",
"$",
"filterField",
"]",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"'many'",
")",
"{",
"$",
"filter",
"[",
"$",
"filterField",
"]",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"value",
"]",
";",
"}",
",",
"$",
"filter",
"[",
"$",
"filterField",
"]",
")",
";",
"$",
"filterToUse",
"[",
"$",
"filterField",
"]",
"=",
"$",
"filter",
"[",
"$",
"filterField",
"]",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"[",
"'text'",
",",
"'multiline'",
",",
"'fixed'",
"]",
")",
")",
"{",
"$",
"filterToUse",
"[",
"$",
"filterField",
"]",
"=",
"'%'",
".",
"$",
"filter",
"[",
"$",
"filterField",
"]",
".",
"'%'",
";",
"$",
"filterOperators",
"[",
"$",
"filterField",
"]",
"=",
"'LIKE'",
";",
"}",
"}",
"}",
"return",
"$",
"rawFilter",
";",
"}"
] | Builds up the parameters of the list page filters.
@param Request $request
the current request
@param EntityDefinition $definition
the current entity definition
@param array &$filter
will hold a map of fields to request parameters for the filters
@param boolean $filterActive
reference, will be true if at least one filter is active
@param array $filterToUse
reference, will hold a map of fields to integers (0 or 1) which boolean filters are active
@param array $filterOperators
reference, will hold a map of fields to operators for AbstractData::listEntries()
@return array
the raw filter query parameters | [
"Builds",
"up",
"the",
"parameters",
"of",
"the",
"list",
"page",
"filters",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L209-L236 |
38,234 | philiplb/CRUDlex | src/CRUDlex/Controller.php | Controller.getNotFoundPage | protected function getNotFoundPage($error)
{
return new Response($this->twig->render('@crud/notFound.twig', [
'crud' => $this->service,
'error' => $error,
'crudEntity' => '',
'layout' => $this->service->getTemplate('layout', '', '')
]), 404);
} | php | protected function getNotFoundPage($error)
{
return new Response($this->twig->render('@crud/notFound.twig', [
'crud' => $this->service,
'error' => $error,
'crudEntity' => '',
'layout' => $this->service->getTemplate('layout', '', '')
]), 404);
} | [
"protected",
"function",
"getNotFoundPage",
"(",
"$",
"error",
")",
"{",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"'@crud/notFound.twig'",
",",
"[",
"'crud'",
"=>",
"$",
"this",
"->",
"service",
",",
"'error'",
"=>",
"$",
"error",
",",
"'crudEntity'",
"=>",
"''",
",",
"'layout'",
"=>",
"$",
"this",
"->",
"service",
"->",
"getTemplate",
"(",
"'layout'",
",",
"''",
",",
"''",
")",
"]",
")",
",",
"404",
")",
";",
"}"
] | Generates the not found page.
@param string $error
the cause of the not found error
@return Response
the rendered not found page with the status code 404 | [
"Generates",
"the",
"not",
"found",
"page",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Controller.php#L247-L255 |
38,235 | philiplb/CRUDlex | src/CRUDlex/StreamedFileResponse.php | StreamedFileResponse.getStreamedFileFunction | public function getStreamedFileFunction($file)
{
return function() use ($file) {
set_time_limit(0);
$handle = fopen($file, 'rb');
if ($handle !== false) {
$chunkSize = 1024 * 1024;
while (!feof($handle)) {
$buffer = fread($handle, $chunkSize);
echo $buffer;
flush();
}
fclose($handle);
}
};
} | php | public function getStreamedFileFunction($file)
{
return function() use ($file) {
set_time_limit(0);
$handle = fopen($file, 'rb');
if ($handle !== false) {
$chunkSize = 1024 * 1024;
while (!feof($handle)) {
$buffer = fread($handle, $chunkSize);
echo $buffer;
flush();
}
fclose($handle);
}
};
} | [
"public",
"function",
"getStreamedFileFunction",
"(",
"$",
"file",
")",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"file",
")",
"{",
"set_time_limit",
"(",
"0",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"handle",
"!==",
"false",
")",
"{",
"$",
"chunkSize",
"=",
"1024",
"*",
"1024",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"handle",
")",
")",
"{",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"handle",
",",
"$",
"chunkSize",
")",
";",
"echo",
"$",
"buffer",
";",
"flush",
"(",
")",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"}",
"}",
";",
"}"
] | Generates a lambda which is streaming the given file to standard output.
@param string $file
the filename to stream
@return \Closure
the generated lambda | [
"Generates",
"a",
"lambda",
"which",
"is",
"streaming",
"the",
"given",
"file",
"to",
"standard",
"output",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/StreamedFileResponse.php#L30-L45 |
38,236 | philiplb/CRUDlex | src/CRUDlex/EntityEvents.php | EntityEvents.shouldExecute | public function shouldExecute(Entity $entity, $moment, $action)
{
if (!isset($this->events[$moment.'.'.$action])) {
return true;
}
foreach ($this->events[$moment.'.'.$action] as $event) {
$result = $event($entity);
if (!$result) {
return false;
}
}
return true;
} | php | public function shouldExecute(Entity $entity, $moment, $action)
{
if (!isset($this->events[$moment.'.'.$action])) {
return true;
}
foreach ($this->events[$moment.'.'.$action] as $event) {
$result = $event($entity);
if (!$result) {
return false;
}
}
return true;
} | [
"public",
"function",
"shouldExecute",
"(",
"Entity",
"$",
"entity",
",",
"$",
"moment",
",",
"$",
"action",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"moment",
".",
"'.'",
".",
"$",
"action",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"moment",
".",
"'.'",
".",
"$",
"action",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"result",
"=",
"$",
"event",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Executes the event chain of an entity.
@param Entity $entity
the entity having the event chain to execute
@param string $moment
the "moment" of the event, can be either "before" or "after"
@param string $action
the "action" of the event, can be either "create", "update" or "delete"
@return boolean
true on successful execution of the full chain or false if it broke at
any point (and stopped the execution) | [
"Executes",
"the",
"event",
"chain",
"of",
"an",
"entity",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityEvents.php#L40-L52 |
38,237 | philiplb/CRUDlex | src/CRUDlex/EntityEvents.php | EntityEvents.pop | public function pop($moment, $action)
{
if (array_key_exists($moment.'.'.$action, $this->events)) {
return array_pop($this->events[$moment.'.'.$action]);
}
return null;
} | php | public function pop($moment, $action)
{
if (array_key_exists($moment.'.'.$action, $this->events)) {
return array_pop($this->events[$moment.'.'.$action]);
}
return null;
} | [
"public",
"function",
"pop",
"(",
"$",
"moment",
",",
"$",
"action",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"moment",
".",
"'.'",
".",
"$",
"action",
",",
"$",
"this",
"->",
"events",
")",
")",
"{",
"return",
"array_pop",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"moment",
".",
"'.'",
".",
"$",
"action",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Removes and returns the latest event for the given parameters.
@param string $moment
the "moment" of the event, can be either "before" or "after"
@param string $action
the "action" of the event, can be either "create", "update" or "delete"
@return \Closure|null
the popped event or null if no event was available. | [
"Removes",
"and",
"returns",
"the",
"latest",
"event",
"for",
"the",
"given",
"parameters",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/EntityEvents.php#L88-L94 |
38,238 | philiplb/CRUDlex | src/CRUDlex/UniqueValidator.php | UniqueValidator.isValidUniqueMany | protected function isValidUniqueMany(array $value, AbstractData $data, Entity $entity, $field)
{
return !$data->hasManySet($field, array_column($value, 'id'), $entity->get('id'));
} | php | protected function isValidUniqueMany(array $value, AbstractData $data, Entity $entity, $field)
{
return !$data->hasManySet($field, array_column($value, 'id'), $entity->get('id'));
} | [
"protected",
"function",
"isValidUniqueMany",
"(",
"array",
"$",
"value",
",",
"AbstractData",
"$",
"data",
",",
"Entity",
"$",
"entity",
",",
"$",
"field",
")",
"{",
"return",
"!",
"$",
"data",
"->",
"hasManySet",
"(",
"$",
"field",
",",
"array_column",
"(",
"$",
"value",
",",
"'id'",
")",
",",
"$",
"entity",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}"
] | Checks whether the unique constraint is valid for a many-to-many field.
@param array $value
the value to check
@param AbstractData $data
the data to perform the check with
@param Entity $entity
the entity to perform the check on
@param $field
the many field to perform the check on
@return boolean
true if it is a valid unique many-to-many constraint | [
"Checks",
"whether",
"the",
"unique",
"constraint",
"is",
"valid",
"for",
"a",
"many",
"-",
"to",
"-",
"many",
"field",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/UniqueValidator.php#L37-L40 |
38,239 | philiplb/CRUDlex | src/CRUDlex/UniqueValidator.php | UniqueValidator.isValidUnique | protected function isValidUnique($value, AbstractData $data, Entity $entity, $field, $type)
{
$params = [$field => $type === 'reference' ? $value['id'] : $value];
$paramsOperators = [$field => '='];
if ($entity->get('id') !== null) {
$params['id'] = $entity->get('id');
$paramsOperators['id'] = '!=';
}
$amount = intval($data->countBy($data->getDefinition()->getTable(), $params, $paramsOperators, true));
return $amount == 0;
} | php | protected function isValidUnique($value, AbstractData $data, Entity $entity, $field, $type)
{
$params = [$field => $type === 'reference' ? $value['id'] : $value];
$paramsOperators = [$field => '='];
if ($entity->get('id') !== null) {
$params['id'] = $entity->get('id');
$paramsOperators['id'] = '!=';
}
$amount = intval($data->countBy($data->getDefinition()->getTable(), $params, $paramsOperators, true));
return $amount == 0;
} | [
"protected",
"function",
"isValidUnique",
"(",
"$",
"value",
",",
"AbstractData",
"$",
"data",
",",
"Entity",
"$",
"entity",
",",
"$",
"field",
",",
"$",
"type",
")",
"{",
"$",
"params",
"=",
"[",
"$",
"field",
"=>",
"$",
"type",
"===",
"'reference'",
"?",
"$",
"value",
"[",
"'id'",
"]",
":",
"$",
"value",
"]",
";",
"$",
"paramsOperators",
"=",
"[",
"$",
"field",
"=>",
"'='",
"]",
";",
"if",
"(",
"$",
"entity",
"->",
"get",
"(",
"'id'",
")",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"'id'",
"]",
"=",
"$",
"entity",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"paramsOperators",
"[",
"'id'",
"]",
"=",
"'!='",
";",
"}",
"$",
"amount",
"=",
"intval",
"(",
"$",
"data",
"->",
"countBy",
"(",
"$",
"data",
"->",
"getDefinition",
"(",
")",
"->",
"getTable",
"(",
")",
",",
"$",
"params",
",",
"$",
"paramsOperators",
",",
"true",
")",
")",
";",
"return",
"$",
"amount",
"==",
"0",
";",
"}"
] | Performs the regular unique validation.
@param $value
the value to validate
@param $data
the data instance to validate with
@param $entity
the entity of the field
@param $field
the field to validate
@param $type
the type of the field to validate
@return boolean
true if everything is valid | [
"Performs",
"the",
"regular",
"unique",
"validation",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/UniqueValidator.php#L59-L69 |
38,240 | philiplb/CRUDlex | src/CRUDlex/YamlReader.php | YamlReader.readFromCache | protected function readFromCache($fileName)
{
$cacheFile = $this->getCacheFile($fileName);
if (file_exists($cacheFile) && is_readable($cacheFile)) {
include($cacheFile);
if (isset($crudlexCacheContent)) {
return $crudlexCacheContent;
}
}
return null;
} | php | protected function readFromCache($fileName)
{
$cacheFile = $this->getCacheFile($fileName);
if (file_exists($cacheFile) && is_readable($cacheFile)) {
include($cacheFile);
if (isset($crudlexCacheContent)) {
return $crudlexCacheContent;
}
}
return null;
} | [
"protected",
"function",
"readFromCache",
"(",
"$",
"fileName",
")",
"{",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"cacheFile",
")",
"&&",
"is_readable",
"(",
"$",
"cacheFile",
")",
")",
"{",
"include",
"(",
"$",
"cacheFile",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"crudlexCacheContent",
")",
")",
"{",
"return",
"$",
"crudlexCacheContent",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Reads the content of the cached file if it exists.
@param string $fileName
the cache file to read from
@return null|array
the cached data structure or null if the cache file was not available | [
"Reads",
"the",
"content",
"of",
"the",
"cached",
"file",
"if",
"it",
"exists",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/YamlReader.php#L50-L60 |
38,241 | philiplb/CRUDlex | src/CRUDlex/YamlReader.php | YamlReader.writeToCache | protected function writeToCache($fileName, $content)
{
if ($this->cachePath === null || !is_dir($this->cachePath) || !is_writable($this->cachePath)) {
return;
}
$encoder = new \Riimu\Kit\PHPEncoder\PHPEncoder();
$contentPHP = $encoder->encode($content, [
'whitespace' => false,
'recursion.detect' => false
]);
$cache = '<?php $crudlexCacheContent = '.$contentPHP.';';
file_put_contents($this->getCacheFile($fileName), $cache);
} | php | protected function writeToCache($fileName, $content)
{
if ($this->cachePath === null || !is_dir($this->cachePath) || !is_writable($this->cachePath)) {
return;
}
$encoder = new \Riimu\Kit\PHPEncoder\PHPEncoder();
$contentPHP = $encoder->encode($content, [
'whitespace' => false,
'recursion.detect' => false
]);
$cache = '<?php $crudlexCacheContent = '.$contentPHP.';';
file_put_contents($this->getCacheFile($fileName), $cache);
} | [
"protected",
"function",
"writeToCache",
"(",
"$",
"fileName",
",",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cachePath",
"===",
"null",
"||",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"cachePath",
")",
"||",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"cachePath",
")",
")",
"{",
"return",
";",
"}",
"$",
"encoder",
"=",
"new",
"\\",
"Riimu",
"\\",
"Kit",
"\\",
"PHPEncoder",
"\\",
"PHPEncoder",
"(",
")",
";",
"$",
"contentPHP",
"=",
"$",
"encoder",
"->",
"encode",
"(",
"$",
"content",
",",
"[",
"'whitespace'",
"=>",
"false",
",",
"'recursion.detect'",
"=>",
"false",
"]",
")",
";",
"$",
"cache",
"=",
"'<?php $crudlexCacheContent = '",
".",
"$",
"contentPHP",
".",
"';'",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getCacheFile",
"(",
"$",
"fileName",
")",
",",
"$",
"cache",
")",
";",
"}"
] | Writes the given content to a cached PHP file.
@param string $fileName
the original filename
@param array $content
the content to cache | [
"Writes",
"the",
"given",
"content",
"to",
"a",
"cached",
"PHP",
"file",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/YamlReader.php#L70-L82 |
38,242 | philiplb/CRUDlex | src/CRUDlex/YamlReader.php | YamlReader.read | public function read($fileName)
{
$parsedYaml = $this->readFromCache($fileName);
if ($parsedYaml !== null) {
return $parsedYaml;
}
try {
$fileContent = file_get_contents($fileName);
$parsedYaml = Yaml::parse($fileContent);
if (!is_array($parsedYaml)) {
$parsedYaml = [];
}
$this->writeToCache($fileName, $parsedYaml);
return $parsedYaml;
} catch (\Exception $e) {
throw new \RuntimeException('Could not read Yaml file '.$fileName, $e->getCode(), $e);
}
} | php | public function read($fileName)
{
$parsedYaml = $this->readFromCache($fileName);
if ($parsedYaml !== null) {
return $parsedYaml;
}
try {
$fileContent = file_get_contents($fileName);
$parsedYaml = Yaml::parse($fileContent);
if (!is_array($parsedYaml)) {
$parsedYaml = [];
}
$this->writeToCache($fileName, $parsedYaml);
return $parsedYaml;
} catch (\Exception $e) {
throw new \RuntimeException('Could not read Yaml file '.$fileName, $e->getCode(), $e);
}
} | [
"public",
"function",
"read",
"(",
"$",
"fileName",
")",
"{",
"$",
"parsedYaml",
"=",
"$",
"this",
"->",
"readFromCache",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"$",
"parsedYaml",
"!==",
"null",
")",
"{",
"return",
"$",
"parsedYaml",
";",
"}",
"try",
"{",
"$",
"fileContent",
"=",
"file_get_contents",
"(",
"$",
"fileName",
")",
";",
"$",
"parsedYaml",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"fileContent",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parsedYaml",
")",
")",
"{",
"$",
"parsedYaml",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"writeToCache",
"(",
"$",
"fileName",
",",
"$",
"parsedYaml",
")",
";",
"return",
"$",
"parsedYaml",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not read Yaml file '",
".",
"$",
"fileName",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Reads and returns the contents of the given Yaml file. If
it goes wrong, it throws an exception.
@param string $fileName
the file to read
@return array
the file contents
@throws \RuntimeException
thrown if the file could not be read or parsed | [
"Reads",
"and",
"returns",
"the",
"contents",
"of",
"the",
"given",
"Yaml",
"file",
".",
"If",
"it",
"goes",
"wrong",
"it",
"throws",
"an",
"exception",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/YamlReader.php#L107-L125 |
38,243 | philiplb/CRUDlex | src/CRUDlex/Entity.php | Entity.toType | protected function toType($value, $type)
{
if (in_array($type, ['integer', 'float']) && !in_array($value, ['', null], true)) {
settype($value, $type);
} else if ($type == 'boolean') {
$value = (bool)$value;
} else if ($type == 'many') {
$value = $value ?: [];
}
return $value === '' ? null : $value;
} | php | protected function toType($value, $type)
{
if (in_array($type, ['integer', 'float']) && !in_array($value, ['', null], true)) {
settype($value, $type);
} else if ($type == 'boolean') {
$value = (bool)$value;
} else if ($type == 'many') {
$value = $value ?: [];
}
return $value === '' ? null : $value;
} | [
"protected",
"function",
"toType",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"[",
"'integer'",
",",
"'float'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"value",
",",
"[",
"''",
",",
"null",
"]",
",",
"true",
")",
")",
"{",
"settype",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'boolean'",
")",
"{",
"$",
"value",
"=",
"(",
"bool",
")",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'many'",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
":",
"[",
"]",
";",
"}",
"return",
"$",
"value",
"===",
"''",
"?",
"null",
":",
"$",
"value",
";",
"}"
] | Converts a given value to the given type.
@param mixed $value
the value to convert
@param string $type
the type to convert to like 'integer' or 'float'
@return mixed
the converted value | [
"Converts",
"a",
"given",
"value",
"to",
"the",
"given",
"type",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Entity.php#L48-L58 |
38,244 | philiplb/CRUDlex | src/CRUDlex/Entity.php | Entity.getRaw | public function getRaw($field)
{
if (!array_key_exists($field, $this->entity)) {
return null;
}
return $this->entity[$field];
} | php | public function getRaw($field)
{
if (!array_key_exists($field, $this->entity)) {
return null;
}
return $this->entity[$field];
} | [
"public",
"function",
"getRaw",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"entity",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"entity",
"[",
"$",
"field",
"]",
";",
"}"
] | Gets the raw value of a field no matter what type it is.
This is usefull for input validation for example.
@param string $field
the field
@return mixed
null on invalid field or else the raw value | [
"Gets",
"the",
"raw",
"value",
"of",
"a",
"field",
"no",
"matter",
"what",
"type",
"it",
"is",
".",
"This",
"is",
"usefull",
"for",
"input",
"validation",
"for",
"example",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Entity.php#L96-L102 |
38,245 | philiplb/CRUDlex | src/CRUDlex/Entity.php | Entity.get | public function get($field)
{
if ($this->definition->getField($field, 'value') !== null) {
return $this->definition->getField($field, 'value');
}
if (!array_key_exists($field, $this->entity)) {
return null;
}
$type = $this->definition->getType($field);
$value = $this->toType($this->entity[$field], $type);
return $value;
} | php | public function get($field)
{
if ($this->definition->getField($field, 'value') !== null) {
return $this->definition->getField($field, 'value');
}
if (!array_key_exists($field, $this->entity)) {
return null;
}
$type = $this->definition->getType($field);
$value = $this->toType($this->entity[$field], $type);
return $value;
} | [
"public",
"function",
"get",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"definition",
"->",
"getField",
"(",
"$",
"field",
",",
"'value'",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"definition",
"->",
"getField",
"(",
"$",
"field",
",",
"'value'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"entity",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"type",
"=",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"field",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"toType",
"(",
"$",
"this",
"->",
"entity",
"[",
"$",
"field",
"]",
",",
"$",
"type",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Gets the value of a field in its specific type.
@param string $field
the field
@return mixed
null on invalid field, an integer if the definition says that the
type of the field is an integer, a boolean if the field is a boolean or
else the raw value | [
"Gets",
"the",
"value",
"of",
"a",
"field",
"in",
"its",
"specific",
"type",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Entity.php#L115-L128 |
38,246 | philiplb/CRUDlex | src/CRUDlex/Entity.php | Entity.populateViaRequest | public function populateViaRequest(Request $request)
{
$fields = $this->definition->getEditableFieldNames();
foreach ($fields as $field) {
$type = $this->definition->getType($field);
if ($type === 'file') {
$file = $request->files->get($field);
if ($file) {
$this->set($field, $file->getClientOriginalName());
}
} else if ($type === 'reference') {
$value = $request->get($field);
if ($value === '') {
$value = null;
}
$this->set($field, ['id' => $value]);
} else if ($type === 'many') {
$array = $request->get($field, []);
if (is_array($array)) {
$many = array_map(function($id) {
return ['id' => $id];
}, $array);
$this->set($field, $many);
}
} else {
$this->set($field, $request->get($field));
}
}
} | php | public function populateViaRequest(Request $request)
{
$fields = $this->definition->getEditableFieldNames();
foreach ($fields as $field) {
$type = $this->definition->getType($field);
if ($type === 'file') {
$file = $request->files->get($field);
if ($file) {
$this->set($field, $file->getClientOriginalName());
}
} else if ($type === 'reference') {
$value = $request->get($field);
if ($value === '') {
$value = null;
}
$this->set($field, ['id' => $value]);
} else if ($type === 'many') {
$array = $request->get($field, []);
if (is_array($array)) {
$many = array_map(function($id) {
return ['id' => $id];
}, $array);
$this->set($field, $many);
}
} else {
$this->set($field, $request->get($field));
}
}
} | [
"public",
"function",
"populateViaRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"definition",
"->",
"getEditableFieldNames",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"definition",
"->",
"getType",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'file'",
")",
"{",
"$",
"file",
"=",
"$",
"request",
"->",
"files",
"->",
"get",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"file",
"->",
"getClientOriginalName",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"'reference'",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"[",
"'id'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"'many'",
")",
"{",
"$",
"array",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"field",
",",
"[",
"]",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"$",
"many",
"=",
"array_map",
"(",
"function",
"(",
"$",
"id",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"id",
"]",
";",
"}",
",",
"$",
"array",
")",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"many",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"request",
"->",
"get",
"(",
"$",
"field",
")",
")",
";",
"}",
"}",
"}"
] | Populates the entities fields from the requests parameters.
@param Request $request
the request to take the field data from | [
"Populates",
"the",
"entities",
"fields",
"from",
"the",
"requests",
"parameters",
"."
] | 6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc | https://github.com/philiplb/CRUDlex/blob/6c6c9fe554134e6b300d576a1cf4447f3c7aa1dc/src/CRUDlex/Entity.php#L147-L175 |
38,247 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.get | public function get($property, $default = null)
{
$this->storage->openReader();
$object = $this->getObjectSafely('openReader');
$this->storage->close();
$data = $object->getData();
if (!property_exists($data, $property))
{
return $default;
}
return $data->{$property};
} | php | public function get($property, $default = null)
{
$this->storage->openReader();
$object = $this->getObjectSafely('openReader');
$this->storage->close();
$data = $object->getData();
if (!property_exists($data, $property))
{
return $default;
}
return $data->{$property};
} | [
"public",
"function",
"get",
"(",
"$",
"property",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openReader",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openReader'",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"$",
"data",
"=",
"$",
"object",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"data",
",",
"$",
"property",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"data",
"->",
"{",
"$",
"property",
"}",
";",
"}"
] | Returns a value from the shared object
@access public
@param mixed $property
@param mixed $default
@return mixed
@throws \Exception | [
"Returns",
"a",
"value",
"from",
"the",
"shared",
"object"
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L131-L144 |
38,248 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.set | public function set($property, $value)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$data = $object->getData();
$data->{$property} = $value;
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $value;
} | php | public function set($property, $value)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$data = $object->getData();
$data->{$property} = $value;
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $value;
} | [
"public",
"function",
"set",
"(",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openWriter",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openWriter'",
")",
";",
"$",
"data",
"=",
"$",
"object",
"->",
"getData",
"(",
")",
";",
"$",
"data",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"value",
";",
"$",
"object",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"setObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Add a new property to the shared object.
@access public
@param mixed $property
@param mixed $value
@return self
@throws \Exception | [
"Add",
"a",
"new",
"property",
"to",
"the",
"shared",
"object",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L189-L199 |
38,249 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.remove | public function remove($property)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$data = $object->getData();
if (property_exists($data, $property))
{
unset($data->{$property});
}
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | php | public function remove($property)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$data = $object->getData();
if (property_exists($data, $property))
{
unset($data->{$property});
}
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openWriter",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openWriter'",
")",
";",
"$",
"data",
"=",
"$",
"object",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"data",
",",
"$",
"property",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"->",
"{",
"$",
"property",
"}",
")",
";",
"}",
"$",
"object",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"setObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Removes a value from the shared object.
@access public
@param mixed $property
@return self
@throws \Exception | [
"Removes",
"a",
"value",
"from",
"the",
"shared",
"object",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L238-L251 |
38,250 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.lock | public function lock($timeout = 0, $interval = 50000)
{
if ((!is_numeric($timeout)) || ($timeout < 0))
{
throw new \Exception("Lock timeout should be an integer greater or equals to 0.");
}
if ((!is_numeric($interval)) || ($interval < 5000))
{
throw new \Exception("Lock check interval should be an integer greater or equals to 5000.");
}
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setLocked(true);
$object->setTimeout($timeout);
$object->setInterval($interval);
$this->lock = true;
$this->storage->setObject($object);
$this->storage->close();
} | php | public function lock($timeout = 0, $interval = 50000)
{
if ((!is_numeric($timeout)) || ($timeout < 0))
{
throw new \Exception("Lock timeout should be an integer greater or equals to 0.");
}
if ((!is_numeric($interval)) || ($interval < 5000))
{
throw new \Exception("Lock check interval should be an integer greater or equals to 5000.");
}
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setLocked(true);
$object->setTimeout($timeout);
$object->setInterval($interval);
$this->lock = true;
$this->storage->setObject($object);
$this->storage->close();
} | [
"public",
"function",
"lock",
"(",
"$",
"timeout",
"=",
"0",
",",
"$",
"interval",
"=",
"50000",
")",
"{",
"if",
"(",
"(",
"!",
"is_numeric",
"(",
"$",
"timeout",
")",
")",
"||",
"(",
"$",
"timeout",
"<",
"0",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Lock timeout should be an integer greater or equals to 0.\"",
")",
";",
"}",
"if",
"(",
"(",
"!",
"is_numeric",
"(",
"$",
"interval",
")",
")",
"||",
"(",
"$",
"interval",
"<",
"5000",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Lock check interval should be an integer greater or equals to 5000.\"",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"->",
"openWriter",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openWriter'",
")",
";",
"$",
"object",
"->",
"setLocked",
"(",
"true",
")",
";",
"$",
"object",
"->",
"setTimeout",
"(",
"$",
"timeout",
")",
";",
"$",
"object",
"->",
"setInterval",
"(",
"$",
"interval",
")",
";",
"$",
"this",
"->",
"lock",
"=",
"true",
";",
"$",
"this",
"->",
"storage",
"->",
"setObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"}"
] | Locks synchronized variable to the current process.
This is useful to avoid concurrent accesses, such as :
if (is_null($shared->check)) {
$shared->data = "something";
}
In the example above, the condition can be true for several processes
if $shared->check is accessed simultaneously.
@access public
@param int $timeout Define how many seconds the shared variable should be locked (0 = unlimited)
@param int $interval Microseconds between each lock check when a process awaits unlock
@return self
@throws \Exception | [
"Locks",
"synchronized",
"variable",
"to",
"the",
"current",
"process",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L271-L293 |
38,251 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.unlock | public function unlock()
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setLocked(false);
$this->lock = false;
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | php | public function unlock()
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setLocked(false);
$this->lock = false;
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | [
"public",
"function",
"unlock",
"(",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openWriter",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openWriter'",
")",
";",
"$",
"object",
"->",
"setLocked",
"(",
"false",
")",
";",
"$",
"this",
"->",
"lock",
"=",
"false",
";",
"$",
"this",
"->",
"storage",
"->",
"setObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Unlocks synchronized variable, making it available for
all processes that uses it. Note that any app using a
shared object can unlock it.
@access public
@return self | [
"Unlocks",
"synchronized",
"variable",
"making",
"it",
"available",
"for",
"all",
"processes",
"that",
"uses",
"it",
".",
"Note",
"that",
"any",
"app",
"using",
"a",
"shared",
"object",
"can",
"unlock",
"it",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L303-L312 |
38,252 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.getData | public function getData()
{
$this->storage->openReader();
$object = $this->getObjectSafely('openReader');
$this->storage->close();
return $object->getData();
} | php | public function getData()
{
$this->storage->openReader();
$object = $this->getObjectSafely('openReader');
$this->storage->close();
return $object->getData();
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openReader",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openReader'",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"return",
"$",
"object",
"->",
"getData",
"(",
")",
";",
"}"
] | Get the whole object, raw, for quicker access to its properties.
This class delivers objects designed to be always safely synchronized
with a file, to allow safe concurrent accesses. To avoid getting in
trouble, you should use lock() method before using getData and
unlock() method after using setData.
@access public
@return \stdClass
@throws \Exception | [
"Get",
"the",
"whole",
"object",
"raw",
"for",
"quicker",
"access",
"to",
"its",
"properties",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L362-L368 |
38,253 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.setData | public function setData(\stdClass $data)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | php | public function setData(\stdClass $data)
{
$this->storage->openWriter();
$object = $this->getObjectSafely('openWriter');
$object->setData($data);
$this->storage->setObject($object);
$this->storage->close();
return $this;
} | [
"public",
"function",
"setData",
"(",
"\\",
"stdClass",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"openWriter",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObjectSafely",
"(",
"'openWriter'",
")",
";",
"$",
"object",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"setObject",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the whole object, replacing all its properties and values by the new ones.
This class delivers objects designed to be always safely synchronized
with a file, to allow safe concurrent accesses. To avoid getting in
trouble, you should use lock() method before using getData and
unlock() method after using setData.
@access public
@param \stdClass $data
@return self
@throws \Exception | [
"Set",
"the",
"whole",
"object",
"replacing",
"all",
"its",
"properties",
"and",
"values",
"by",
"the",
"new",
"ones",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L383-L391 |
38,254 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.getObject | protected function getObject()
{
$object = $this->storage->getObject();
if (!($object instanceof StoredEntity))
{
$object = new StoredEntity();
}
return $object;
} | php | protected function getObject()
{
$object = $this->storage->getObject();
if (!($object instanceof StoredEntity))
{
$object = new StoredEntity();
}
return $object;
} | [
"protected",
"function",
"getObject",
"(",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"storage",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"object",
"instanceof",
"StoredEntity",
")",
")",
"{",
"$",
"object",
"=",
"new",
"StoredEntity",
"(",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Creates or validates an object coming from storage.
@access protected
@return StoredEntity | [
"Creates",
"or",
"validates",
"an",
"object",
"coming",
"from",
"storage",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L399-L407 |
38,255 | ninsuo/php-shared-memory | src/Fuz/Component/SharedMemory/SharedMemory.php | SharedMemory.getObjectSafely | protected function getObjectSafely($openCallback)
{
$elapsed = 0;
$object = $this->getObject();
if ($this->lock === false)
{
while ($object->isLocked())
{
$this->storage->close();
usleep($object->getInterval());
$this->storage->{$openCallback}();
$object = $this->getObject();
if ($object->getTimeout() > 0)
{
$elapsed += $object->getInterval();
if (floor($elapsed / 1000000) >= $object->getTimeout())
{
throw new \Exception(sprintf("Can't access shared object, it is still locked after %d second(s).",
$object->getTimeout()));
}
}
}
}
return $object;
} | php | protected function getObjectSafely($openCallback)
{
$elapsed = 0;
$object = $this->getObject();
if ($this->lock === false)
{
while ($object->isLocked())
{
$this->storage->close();
usleep($object->getInterval());
$this->storage->{$openCallback}();
$object = $this->getObject();
if ($object->getTimeout() > 0)
{
$elapsed += $object->getInterval();
if (floor($elapsed / 1000000) >= $object->getTimeout())
{
throw new \Exception(sprintf("Can't access shared object, it is still locked after %d second(s).",
$object->getTimeout()));
}
}
}
}
return $object;
} | [
"protected",
"function",
"getObjectSafely",
"(",
"$",
"openCallback",
")",
"{",
"$",
"elapsed",
"=",
"0",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"lock",
"===",
"false",
")",
"{",
"while",
"(",
"$",
"object",
"->",
"isLocked",
"(",
")",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"close",
"(",
")",
";",
"usleep",
"(",
"$",
"object",
"->",
"getInterval",
"(",
")",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"{",
"$",
"openCallback",
"}",
"(",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"$",
"object",
"->",
"getTimeout",
"(",
")",
">",
"0",
")",
"{",
"$",
"elapsed",
"+=",
"$",
"object",
"->",
"getInterval",
"(",
")",
";",
"if",
"(",
"floor",
"(",
"$",
"elapsed",
"/",
"1000000",
")",
">=",
"$",
"object",
"->",
"getTimeout",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"\"Can't access shared object, it is still locked after %d second(s).\"",
",",
"$",
"object",
"->",
"getTimeout",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"object",
";",
"}"
] | Recovers the object if the mutex-style lock is released.
@access protected
@param callable $openCallback
@return StoredEntity
@throws \Exception | [
"Recovers",
"the",
"object",
"if",
"the",
"mutex",
"-",
"style",
"lock",
"is",
"released",
"."
] | ff08f15fe010ad07063f287363e692f9e7816b0d | https://github.com/ninsuo/php-shared-memory/blob/ff08f15fe010ad07063f287363e692f9e7816b0d/src/Fuz/Component/SharedMemory/SharedMemory.php#L417-L441 |
38,256 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerAmiAction | protected function registerAmiAction()
{
$this->app->singleton(AmiAction::class, function ($app) {
return new AmiAction($app['events'], $app['ami.eventloop'], $app['ami.factory'], $app['config']['ami']);
});
$this->app->alias(AmiAction::class, 'command.ami.action');
} | php | protected function registerAmiAction()
{
$this->app->singleton(AmiAction::class, function ($app) {
return new AmiAction($app['events'], $app['ami.eventloop'], $app['ami.factory'], $app['config']['ami']);
});
$this->app->alias(AmiAction::class, 'command.ami.action');
} | [
"protected",
"function",
"registerAmiAction",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"AmiAction",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"AmiAction",
"(",
"$",
"app",
"[",
"'events'",
"]",
",",
"$",
"app",
"[",
"'ami.eventloop'",
"]",
",",
"$",
"app",
"[",
"'ami.factory'",
"]",
",",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'ami'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"AmiAction",
"::",
"class",
",",
"'command.ami.action'",
")",
";",
"}"
] | Register the ami action sender. | [
"Register",
"the",
"ami",
"action",
"sender",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L86-L92 |
38,257 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerDongleSms | protected function registerDongleSms()
{
$this->app->singleton(AmiSms::class, function ($app) {
return new AmiSms($app['events'], $app['ami.eventloop'], $app['ami.factory'], $app['config']['ami']);
});
$this->app->alias(AmiSms::class, 'command.ami.dongle.sms');
} | php | protected function registerDongleSms()
{
$this->app->singleton(AmiSms::class, function ($app) {
return new AmiSms($app['events'], $app['ami.eventloop'], $app['ami.factory'], $app['config']['ami']);
});
$this->app->alias(AmiSms::class, 'command.ami.dongle.sms');
} | [
"protected",
"function",
"registerDongleSms",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"AmiSms",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"AmiSms",
"(",
"$",
"app",
"[",
"'events'",
"]",
",",
"$",
"app",
"[",
"'ami.eventloop'",
"]",
",",
"$",
"app",
"[",
"'ami.factory'",
"]",
",",
"$",
"app",
"[",
"'config'",
"]",
"[",
"'ami'",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"AmiSms",
"::",
"class",
",",
"'command.ami.dongle.sms'",
")",
";",
"}"
] | Register the dongle sms. | [
"Register",
"the",
"dongle",
"sms",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L97-L103 |
38,258 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerDongleUssd | protected function registerDongleUssd()
{
$this->app->singleton(AmiUssd::class, function ($app) {
return new AmiUssd();
});
$this->app->alias(AmiUssd::class, 'command.ami.dongle.ussd');
} | php | protected function registerDongleUssd()
{
$this->app->singleton(AmiUssd::class, function ($app) {
return new AmiUssd();
});
$this->app->alias(AmiUssd::class, 'command.ami.dongle.ussd');
} | [
"protected",
"function",
"registerDongleUssd",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"AmiUssd",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"AmiUssd",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"AmiUssd",
"::",
"class",
",",
"'command.ami.dongle.ussd'",
")",
";",
"}"
] | Register the dongle ussd. | [
"Register",
"the",
"dongle",
"ussd",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L108-L114 |
38,259 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerEventLoop | protected function registerEventLoop()
{
$this->app->singleton(LoopInterface::class, function () {
return new StreamSelectLoop();
});
$this->app->alias(LoopInterface::class, 'ami.eventloop');
} | php | protected function registerEventLoop()
{
$this->app->singleton(LoopInterface::class, function () {
return new StreamSelectLoop();
});
$this->app->alias(LoopInterface::class, 'ami.eventloop');
} | [
"protected",
"function",
"registerEventLoop",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"LoopInterface",
"::",
"class",
",",
"function",
"(",
")",
"{",
"return",
"new",
"StreamSelectLoop",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"LoopInterface",
"::",
"class",
",",
"'ami.eventloop'",
")",
";",
"}"
] | Register event loop. | [
"Register",
"event",
"loop",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L119-L125 |
38,260 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerConnector | protected function registerConnector()
{
$this->app->singleton(ConnectorInterface::class, function ($app) {
$loop = $app[LoopInterface::class];
return new Connector($loop, (new DnsResolver())->create('8.8.8.8', $loop));
});
$this->app->alias(ConnectorInterface::class, 'ami.connector');
} | php | protected function registerConnector()
{
$this->app->singleton(ConnectorInterface::class, function ($app) {
$loop = $app[LoopInterface::class];
return new Connector($loop, (new DnsResolver())->create('8.8.8.8', $loop));
});
$this->app->alias(ConnectorInterface::class, 'ami.connector');
} | [
"protected",
"function",
"registerConnector",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"ConnectorInterface",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"loop",
"=",
"$",
"app",
"[",
"LoopInterface",
"::",
"class",
"]",
";",
"return",
"new",
"Connector",
"(",
"$",
"loop",
",",
"(",
"new",
"DnsResolver",
"(",
")",
")",
"->",
"create",
"(",
"'8.8.8.8'",
",",
"$",
"loop",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"ConnectorInterface",
"::",
"class",
",",
"'ami.connector'",
")",
";",
"}"
] | Register connector. | [
"Register",
"connector",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L130-L138 |
38,261 | enniel/ami | src/Providers/AmiServiceProvider.php | AmiServiceProvider.registerFactory | protected function registerFactory()
{
$this->app->singleton(Factory::class, function ($app) {
return new Factory($app[LoopInterface::class], $app[ConnectorInterface::class]);
});
$this->app->alias(Factory::class, 'ami.factory');
} | php | protected function registerFactory()
{
$this->app->singleton(Factory::class, function ($app) {
return new Factory($app[LoopInterface::class], $app[ConnectorInterface::class]);
});
$this->app->alias(Factory::class, 'ami.factory');
} | [
"protected",
"function",
"registerFactory",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"Factory",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Factory",
"(",
"$",
"app",
"[",
"LoopInterface",
"::",
"class",
"]",
",",
"$",
"app",
"[",
"ConnectorInterface",
"::",
"class",
"]",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"Factory",
"::",
"class",
",",
"'ami.factory'",
")",
";",
"}"
] | Register factory. | [
"Register",
"factory",
"."
] | 090442334a28a6b3f4236823c22fd8142199edbf | https://github.com/enniel/ami/blob/090442334a28a6b3f4236823c22fd8142199edbf/src/Providers/AmiServiceProvider.php#L143-L149 |
38,262 | LasseRafn/php-initials | src/Initials.php | Initials.length | public function length($length = 2)
{
$this->length = (int) $length;
$this->initials = $this->generateInitials();
return $this;
} | php | public function length($length = 2)
{
$this->length = (int) $length;
$this->initials = $this->generateInitials();
return $this;
} | [
"public",
"function",
"length",
"(",
"$",
"length",
"=",
"2",
")",
"{",
"$",
"this",
"->",
"length",
"=",
"(",
"int",
")",
"$",
"length",
";",
"$",
"this",
"->",
"initials",
"=",
"$",
"this",
"->",
"generateInitials",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the length of the generated initials.
@param int $length
@return Initials | [
"Set",
"the",
"length",
"of",
"the",
"generated",
"initials",
"."
] | ba4669e77552986998a9d1b34515a4e0c0f7acd2 | https://github.com/LasseRafn/php-initials/blob/ba4669e77552986998a9d1b34515a4e0c0f7acd2/src/Initials.php#L48-L54 |
38,263 | LasseRafn/php-initials | src/Initials.php | Initials.generate | public function generate($name = null)
{
if ($name !== null) {
$this->name = $name;
$this->initials = $this->generateInitials();
}
return (string) $this;
} | php | public function generate($name = null)
{
if ($name !== null) {
$this->name = $name;
$this->initials = $this->generateInitials();
}
return (string) $this;
} | [
"public",
"function",
"generate",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"initials",
"=",
"$",
"this",
"->",
"generateInitials",
"(",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"this",
";",
"}"
] | Generate the initials.
@param null|string $name
@return string | [
"Generate",
"the",
"initials",
"."
] | ba4669e77552986998a9d1b34515a4e0c0f7acd2 | https://github.com/LasseRafn/php-initials/blob/ba4669e77552986998a9d1b34515a4e0c0f7acd2/src/Initials.php#L63-L71 |
38,264 | LasseRafn/php-initials | src/Initials.php | Initials.getUrlfriendlyInitials | public function getUrlfriendlyInitials()
{
$urlFriendlyInitials = $this->convertToUrlFriendlyString($this->getInitials());
$urlFriendlyInitials = mb_substr($urlFriendlyInitials, 0, $this->length);
return $urlFriendlyInitials;
} | php | public function getUrlfriendlyInitials()
{
$urlFriendlyInitials = $this->convertToUrlFriendlyString($this->getInitials());
$urlFriendlyInitials = mb_substr($urlFriendlyInitials, 0, $this->length);
return $urlFriendlyInitials;
} | [
"public",
"function",
"getUrlfriendlyInitials",
"(",
")",
"{",
"$",
"urlFriendlyInitials",
"=",
"$",
"this",
"->",
"convertToUrlFriendlyString",
"(",
"$",
"this",
"->",
"getInitials",
"(",
")",
")",
";",
"$",
"urlFriendlyInitials",
"=",
"mb_substr",
"(",
"$",
"urlFriendlyInitials",
",",
"0",
",",
"$",
"this",
"->",
"length",
")",
";",
"return",
"$",
"urlFriendlyInitials",
";",
"}"
] | Will return the generated initials,
without special characters.
@return string | [
"Will",
"return",
"the",
"generated",
"initials",
"without",
"special",
"characters",
"."
] | ba4669e77552986998a9d1b34515a4e0c0f7acd2 | https://github.com/LasseRafn/php-initials/blob/ba4669e77552986998a9d1b34515a4e0c0f7acd2/src/Initials.php#L89-L96 |
38,265 | LasseRafn/php-initials | src/Initials.php | Initials.generateInitials | private function generateInitials()
{
$nameOrInitials = trim($this->name);
if( !$this->keepCase ) {
$nameOrInitials = mb_strtoupper($nameOrInitials);
}
$names = explode(' ', $nameOrInitials);
$initials = $nameOrInitials;
$assignedNames = 0;
if (count($names) > 1) {
$initials = '';
$start = 0;
for ($i = 0; $i < $this->length; $i++) {
$index = $i;
if (($index === ($this->length - 1) && $index > 0) || ($index > (count($names) - 1))) {
$index = count($names) - 1;
}
if ($assignedNames >= count($names)) {
$start++;
}
$initials .= mb_substr($names[$index], $start, 1);
$assignedNames++;
}
}
$initials = mb_substr($initials, 0, $this->length);
return $initials;
} | php | private function generateInitials()
{
$nameOrInitials = trim($this->name);
if( !$this->keepCase ) {
$nameOrInitials = mb_strtoupper($nameOrInitials);
}
$names = explode(' ', $nameOrInitials);
$initials = $nameOrInitials;
$assignedNames = 0;
if (count($names) > 1) {
$initials = '';
$start = 0;
for ($i = 0; $i < $this->length; $i++) {
$index = $i;
if (($index === ($this->length - 1) && $index > 0) || ($index > (count($names) - 1))) {
$index = count($names) - 1;
}
if ($assignedNames >= count($names)) {
$start++;
}
$initials .= mb_substr($names[$index], $start, 1);
$assignedNames++;
}
}
$initials = mb_substr($initials, 0, $this->length);
return $initials;
} | [
"private",
"function",
"generateInitials",
"(",
")",
"{",
"$",
"nameOrInitials",
"=",
"trim",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"keepCase",
")",
"{",
"$",
"nameOrInitials",
"=",
"mb_strtoupper",
"(",
"$",
"nameOrInitials",
")",
";",
"}",
"$",
"names",
"=",
"explode",
"(",
"' '",
",",
"$",
"nameOrInitials",
")",
";",
"$",
"initials",
"=",
"$",
"nameOrInitials",
";",
"$",
"assignedNames",
"=",
"0",
";",
"if",
"(",
"count",
"(",
"$",
"names",
")",
">",
"1",
")",
"{",
"$",
"initials",
"=",
"''",
";",
"$",
"start",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"index",
"=",
"$",
"i",
";",
"if",
"(",
"(",
"$",
"index",
"===",
"(",
"$",
"this",
"->",
"length",
"-",
"1",
")",
"&&",
"$",
"index",
">",
"0",
")",
"||",
"(",
"$",
"index",
">",
"(",
"count",
"(",
"$",
"names",
")",
"-",
"1",
")",
")",
")",
"{",
"$",
"index",
"=",
"count",
"(",
"$",
"names",
")",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"assignedNames",
">=",
"count",
"(",
"$",
"names",
")",
")",
"{",
"$",
"start",
"++",
";",
"}",
"$",
"initials",
".=",
"mb_substr",
"(",
"$",
"names",
"[",
"$",
"index",
"]",
",",
"$",
"start",
",",
"1",
")",
";",
"$",
"assignedNames",
"++",
";",
"}",
"}",
"$",
"initials",
"=",
"mb_substr",
"(",
"$",
"initials",
",",
"0",
",",
"$",
"this",
"->",
"length",
")",
";",
"return",
"$",
"initials",
";",
"}"
] | Generate a two-letter initial from a name,
and if no name, assume its already initials.
For safety, we limit it to two characters,
in case its a single, but long, name.
@return string | [
"Generate",
"a",
"two",
"-",
"letter",
"initial",
"from",
"a",
"name",
"and",
"if",
"no",
"name",
"assume",
"its",
"already",
"initials",
".",
"For",
"safety",
"we",
"limit",
"it",
"to",
"two",
"characters",
"in",
"case",
"its",
"a",
"single",
"but",
"long",
"name",
"."
] | ba4669e77552986998a9d1b34515a4e0c0f7acd2 | https://github.com/LasseRafn/php-initials/blob/ba4669e77552986998a9d1b34515a4e0c0f7acd2/src/Initials.php#L116-L151 |
38,266 | LasseRafn/php-initials | src/Initials.php | Initials.convertToUrlFriendlyString | private function convertToUrlFriendlyString($string)
{
foreach (static::charsArray() as $key => $val) {
$string = str_replace($val, mb_substr($key, 0, 1), $string);
}
return preg_replace('/[^\x20-\x7E]/u', '', $string);
} | php | private function convertToUrlFriendlyString($string)
{
foreach (static::charsArray() as $key => $val) {
$string = str_replace($val, mb_substr($key, 0, 1), $string);
}
return preg_replace('/[^\x20-\x7E]/u', '', $string);
} | [
"private",
"function",
"convertToUrlFriendlyString",
"(",
"$",
"string",
")",
"{",
"foreach",
"(",
"static",
"::",
"charsArray",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"val",
",",
"mb_substr",
"(",
"$",
"key",
",",
"0",
",",
"1",
")",
",",
"$",
"string",
")",
";",
"}",
"return",
"preg_replace",
"(",
"'/[^\\x20-\\x7E]/u'",
",",
"''",
",",
"$",
"string",
")",
";",
"}"
] | Converts specialcharacters to url-friendly characters.
Copied from: https://github.com/laravel/framework/blob/5.4/src/Illuminate/Support/Str.php#L56
@param $string
@return string | [
"Converts",
"specialcharacters",
"to",
"url",
"-",
"friendly",
"characters",
"."
] | ba4669e77552986998a9d1b34515a4e0c0f7acd2 | https://github.com/LasseRafn/php-initials/blob/ba4669e77552986998a9d1b34515a4e0c0f7acd2/src/Initials.php#L162-L169 |
38,267 | merorafael/yii2-monolog | src/Mero/Monolog/Handler/Strategy.php | Strategy.hasFactory | protected function hasFactory($type)
{
if (!array_key_exists($type, $this->factories)) {
throw new HandlerNotFoundException(
sprintf("Type '%s' not found in handler factory", $type)
);
}
$factoryClass = &$this->factories[$type];
if (!class_exists($factoryClass)) {
throw new \BadMethodCallException(
sprintf("Type '%s' not implemented", $type)
);
}
return true;
} | php | protected function hasFactory($type)
{
if (!array_key_exists($type, $this->factories)) {
throw new HandlerNotFoundException(
sprintf("Type '%s' not found in handler factory", $type)
);
}
$factoryClass = &$this->factories[$type];
if (!class_exists($factoryClass)) {
throw new \BadMethodCallException(
sprintf("Type '%s' not implemented", $type)
);
}
return true;
} | [
"protected",
"function",
"hasFactory",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"factories",
")",
")",
"{",
"throw",
"new",
"HandlerNotFoundException",
"(",
"sprintf",
"(",
"\"Type '%s' not found in handler factory\"",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"factoryClass",
"=",
"&",
"$",
"this",
"->",
"factories",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"factoryClass",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"sprintf",
"(",
"\"Type '%s' not implemented\"",
",",
"$",
"type",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Verifies that the factory class exists.
@param string $type Name of type
@return bool
@throws HandlerNotFoundException When handler factory not found
@throws \BadMethodCallException When handler not implemented | [
"Verifies",
"that",
"the",
"factory",
"class",
"exists",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/Handler/Strategy.php#L80-L95 |
38,268 | merorafael/yii2-monolog | src/Mero/Monolog/Handler/Strategy.php | Strategy.createFactory | public function createFactory(array $config)
{
if (!array_key_exists('type', $config)) {
throw new ParameterNotFoundException(
sprintf("Parameter '%s' not found in handler configuration", 'type')
);
}
$this->hasFactory($config['type']);
if (isset($config['level'])) {
$config['level'] = Logger::toMonologLevel($config['level']);
}
$factoryClass = &$this->factories[$config['type']];
return new $factoryClass($config);
} | php | public function createFactory(array $config)
{
if (!array_key_exists('type', $config)) {
throw new ParameterNotFoundException(
sprintf("Parameter '%s' not found in handler configuration", 'type')
);
}
$this->hasFactory($config['type']);
if (isset($config['level'])) {
$config['level'] = Logger::toMonologLevel($config['level']);
}
$factoryClass = &$this->factories[$config['type']];
return new $factoryClass($config);
} | [
"public",
"function",
"createFactory",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'type'",
",",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"ParameterNotFoundException",
"(",
"sprintf",
"(",
"\"Parameter '%s' not found in handler configuration\"",
",",
"'type'",
")",
")",
";",
"}",
"$",
"this",
"->",
"hasFactory",
"(",
"$",
"config",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'level'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'level'",
"]",
"=",
"Logger",
"::",
"toMonologLevel",
"(",
"$",
"config",
"[",
"'level'",
"]",
")",
";",
"}",
"$",
"factoryClass",
"=",
"&",
"$",
"this",
"->",
"factories",
"[",
"$",
"config",
"[",
"'type'",
"]",
"]",
";",
"return",
"new",
"$",
"factoryClass",
"(",
"$",
"config",
")",
";",
"}"
] | Create a factory object.
@param array $config Configuration parameters
@return AbstractFactory Factory object
@throws ParameterNotFoundException When required parameter not found | [
"Create",
"a",
"factory",
"object",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/Handler/Strategy.php#L106-L121 |
38,269 | merorafael/yii2-monolog | src/Mero/Monolog/MonologComponent.php | MonologComponent.createChannel | public function createChannel($name, array $config)
{
$handlers = [];
$processors = [];
if (!empty($config['handler']) && is_array($config['handler'])) {
foreach ($config['handler'] as $handler) {
if (!is_array($handler) && !$handler instanceof AbstractHandler) {
throw new HandlerNotFoundException();
}
if (is_array($handler)) {
$handlerObject = $this->createHandlerInstance($handler);
if (array_key_exists('formatter', $handler) &&
$handler['formatter'] instanceof FormatterInterface
) {
$handlerObject->setFormatter($handler['formatter']);
}
} else {
$handlerObject = $handler;
}
$handlers[] = $handlerObject;
}
}
if (!empty($config['processor']) && is_array($config['processor'])) {
$processors = $config['processor'];
}
$this->openChannel($name, $handlers, $processors);
return;
} | php | public function createChannel($name, array $config)
{
$handlers = [];
$processors = [];
if (!empty($config['handler']) && is_array($config['handler'])) {
foreach ($config['handler'] as $handler) {
if (!is_array($handler) && !$handler instanceof AbstractHandler) {
throw new HandlerNotFoundException();
}
if (is_array($handler)) {
$handlerObject = $this->createHandlerInstance($handler);
if (array_key_exists('formatter', $handler) &&
$handler['formatter'] instanceof FormatterInterface
) {
$handlerObject->setFormatter($handler['formatter']);
}
} else {
$handlerObject = $handler;
}
$handlers[] = $handlerObject;
}
}
if (!empty($config['processor']) && is_array($config['processor'])) {
$processors = $config['processor'];
}
$this->openChannel($name, $handlers, $processors);
return;
} | [
"public",
"function",
"createChannel",
"(",
"$",
"name",
",",
"array",
"$",
"config",
")",
"{",
"$",
"handlers",
"=",
"[",
"]",
";",
"$",
"processors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'handler'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'handler'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'handler'",
"]",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"handler",
")",
"&&",
"!",
"$",
"handler",
"instanceof",
"AbstractHandler",
")",
"{",
"throw",
"new",
"HandlerNotFoundException",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"handler",
")",
")",
"{",
"$",
"handlerObject",
"=",
"$",
"this",
"->",
"createHandlerInstance",
"(",
"$",
"handler",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'formatter'",
",",
"$",
"handler",
")",
"&&",
"$",
"handler",
"[",
"'formatter'",
"]",
"instanceof",
"FormatterInterface",
")",
"{",
"$",
"handlerObject",
"->",
"setFormatter",
"(",
"$",
"handler",
"[",
"'formatter'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"handlerObject",
"=",
"$",
"handler",
";",
"}",
"$",
"handlers",
"[",
"]",
"=",
"$",
"handlerObject",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'processor'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'processor'",
"]",
")",
")",
"{",
"$",
"processors",
"=",
"$",
"config",
"[",
"'processor'",
"]",
";",
"}",
"$",
"this",
"->",
"openChannel",
"(",
"$",
"name",
",",
"$",
"handlers",
",",
"$",
"processors",
")",
";",
"return",
";",
"}"
] | Create a logger channel.
@param string $name Logger channel name
@param array $config Logger channel configuration
@throws \InvalidArgumentException When the channel already exists
@throws HandlerNotFoundException When a handler configuration is invalid | [
"Create",
"a",
"logger",
"channel",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/MonologComponent.php#L67-L95 |
38,270 | merorafael/yii2-monolog | src/Mero/Monolog/MonologComponent.php | MonologComponent.openChannel | protected function openChannel($name, array $handlers, array $processors)
{
if (isset($this->channels[$name]) && $this->channels[$name] instanceof Logger) {
throw new \InvalidArgumentException("Channel '{$name}' already exists");
}
$this->channels[$name] = new Logger($name, $handlers, $processors);
return;
} | php | protected function openChannel($name, array $handlers, array $processors)
{
if (isset($this->channels[$name]) && $this->channels[$name] instanceof Logger) {
throw new \InvalidArgumentException("Channel '{$name}' already exists");
}
$this->channels[$name] = new Logger($name, $handlers, $processors);
return;
} | [
"protected",
"function",
"openChannel",
"(",
"$",
"name",
",",
"array",
"$",
"handlers",
",",
"array",
"$",
"processors",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
")",
"&&",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
"instanceof",
"Logger",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Channel '{$name}' already exists\"",
")",
";",
"}",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
"=",
"new",
"Logger",
"(",
"$",
"name",
",",
"$",
"handlers",
",",
"$",
"processors",
")",
";",
"return",
";",
"}"
] | Open a new logger channel.
@param string $name Logger channel name
@param array $handlers Handlers collection
@param array $processors Processors collection | [
"Open",
"a",
"new",
"logger",
"channel",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/MonologComponent.php#L104-L113 |
38,271 | merorafael/yii2-monolog | src/Mero/Monolog/MonologComponent.php | MonologComponent.hasLogger | public function hasLogger($name)
{
return isset($this->channels[$name]) && ($this->channels[$name] instanceof Logger);
} | php | public function hasLogger($name)
{
return isset($this->channels[$name]) && ($this->channels[$name] instanceof Logger);
} | [
"public",
"function",
"hasLogger",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
")",
"&&",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
"instanceof",
"Logger",
")",
";",
"}"
] | Checks if the given logger exists.
@param string $name Logger name
@return bool | [
"Checks",
"if",
"the",
"given",
"logger",
"exists",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/MonologComponent.php#L150-L153 |
38,272 | merorafael/yii2-monolog | src/Mero/Monolog/MonologComponent.php | MonologComponent.getLogger | public function getLogger($name = 'main')
{
if (!$this->hasLogger($name)) {
throw new LoggerNotFoundException(sprintf("Logger instance '%s' not found", $name));
}
return $this->channels[$name];
} | php | public function getLogger($name = 'main')
{
if (!$this->hasLogger($name)) {
throw new LoggerNotFoundException(sprintf("Logger instance '%s' not found", $name));
}
return $this->channels[$name];
} | [
"public",
"function",
"getLogger",
"(",
"$",
"name",
"=",
"'main'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLogger",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"LoggerNotFoundException",
"(",
"sprintf",
"(",
"\"Logger instance '%s' not found\"",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"channels",
"[",
"$",
"name",
"]",
";",
"}"
] | Return logger object.
@param string $name Logger name
@return Logger Logger object
@throws LoggerNotFoundException | [
"Return",
"logger",
"object",
"."
] | c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7 | https://github.com/merorafael/yii2-monolog/blob/c3aaa8bb3bfa51c50e44672a134221dde2fcb2a7/src/Mero/Monolog/MonologComponent.php#L164-L171 |
38,273 | raulfraile/distill | src/Method/AbstractMethod.php | AbstractMethod.guessType | protected function guessType()
{
$os = strtolower(PHP_OS);
if (false !== strpos($os, 'cygwin')) {
return self::OS_TYPE_CYGWIN;
}
if (false !== strpos($os, 'darwin')) {
return self::OS_TYPE_DARWIN;
}
if (false !== strpos($os, 'bsd')) {
return self::OS_TYPE_BSD;
}
if (0 === strpos($os, 'win')) {
return self::OS_TYPE_WINDOWS;
}
return self::OS_TYPE_UNIX;
} | php | protected function guessType()
{
$os = strtolower(PHP_OS);
if (false !== strpos($os, 'cygwin')) {
return self::OS_TYPE_CYGWIN;
}
if (false !== strpos($os, 'darwin')) {
return self::OS_TYPE_DARWIN;
}
if (false !== strpos($os, 'bsd')) {
return self::OS_TYPE_BSD;
}
if (0 === strpos($os, 'win')) {
return self::OS_TYPE_WINDOWS;
}
return self::OS_TYPE_UNIX;
} | [
"protected",
"function",
"guessType",
"(",
")",
"{",
"$",
"os",
"=",
"strtolower",
"(",
"PHP_OS",
")",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"os",
",",
"'cygwin'",
")",
")",
"{",
"return",
"self",
"::",
"OS_TYPE_CYGWIN",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"os",
",",
"'darwin'",
")",
")",
"{",
"return",
"self",
"::",
"OS_TYPE_DARWIN",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"os",
",",
"'bsd'",
")",
")",
"{",
"return",
"self",
"::",
"OS_TYPE_BSD",
";",
"}",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"os",
",",
"'win'",
")",
")",
"{",
"return",
"self",
"::",
"OS_TYPE_WINDOWS",
";",
"}",
"return",
"self",
"::",
"OS_TYPE_UNIX",
";",
"}"
] | Guesses OS type.
@return int | [
"Guesses",
"OS",
"type",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Method/AbstractMethod.php#L92-L109 |
38,274 | raulfraile/distill | src/Method/Native/TarExtractor.php | TarExtractor.calculateChecksum | protected function calculateChecksum($headerBlock)
{
$checksum = 0;
for ($i = 0; $i<self::SIZE_HEADER_BLOCK; $i++) {
if ($i < 148 || $i >= 156) {
$checksum += ord($headerBlock[$i]);
} else {
$checksum += 32;
}
}
return $checksum;
} | php | protected function calculateChecksum($headerBlock)
{
$checksum = 0;
for ($i = 0; $i<self::SIZE_HEADER_BLOCK; $i++) {
if ($i < 148 || $i >= 156) {
$checksum += ord($headerBlock[$i]);
} else {
$checksum += 32;
}
}
return $checksum;
} | [
"protected",
"function",
"calculateChecksum",
"(",
"$",
"headerBlock",
")",
"{",
"$",
"checksum",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"self",
"::",
"SIZE_HEADER_BLOCK",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"148",
"||",
"$",
"i",
">=",
"156",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"$",
"headerBlock",
"[",
"$",
"i",
"]",
")",
";",
"}",
"else",
"{",
"$",
"checksum",
"+=",
"32",
";",
"}",
"}",
"return",
"$",
"checksum",
";",
"}"
] | Calculates the checksum of the header block.
The checksum is calculated by taking the sum of the unsigned byte values of the header
record with the eight checksum bytes taken to be ascii spaces (decimal value 32).
@param string $headerBlock
@return int | [
"Calculates",
"the",
"checksum",
"of",
"the",
"header",
"block",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Method/Native/TarExtractor.php#L131-L143 |
38,275 | raulfraile/distill | src/Method/Native/GzipExtractor.php | GzipExtractor.getFixedHuffmanTrees | protected function getFixedHuffmanTrees()
{
return [
HuffmanTree::createFromLengths(array_merge(
array_fill_keys(range(0, 143), 8),
array_fill_keys(range(144, 255), 9),
array_fill_keys(range(256, 279), 7),
array_fill_keys(range(280, 287), 8)
)),
HuffmanTree::createFromLengths(array_fill_keys(range(0, 31), 5))
];
} | php | protected function getFixedHuffmanTrees()
{
return [
HuffmanTree::createFromLengths(array_merge(
array_fill_keys(range(0, 143), 8),
array_fill_keys(range(144, 255), 9),
array_fill_keys(range(256, 279), 7),
array_fill_keys(range(280, 287), 8)
)),
HuffmanTree::createFromLengths(array_fill_keys(range(0, 31), 5))
];
} | [
"protected",
"function",
"getFixedHuffmanTrees",
"(",
")",
"{",
"return",
"[",
"HuffmanTree",
"::",
"createFromLengths",
"(",
"array_merge",
"(",
"array_fill_keys",
"(",
"range",
"(",
"0",
",",
"143",
")",
",",
"8",
")",
",",
"array_fill_keys",
"(",
"range",
"(",
"144",
",",
"255",
")",
",",
"9",
")",
",",
"array_fill_keys",
"(",
"range",
"(",
"256",
",",
"279",
")",
",",
"7",
")",
",",
"array_fill_keys",
"(",
"range",
"(",
"280",
",",
"287",
")",
",",
"8",
")",
")",
")",
",",
"HuffmanTree",
"::",
"createFromLengths",
"(",
"array_fill_keys",
"(",
"range",
"(",
"0",
",",
"31",
")",
",",
"5",
")",
")",
"]",
";",
"}"
] | Creates the Huffman codes for literals and distances for fixed Huffman compression.
@return HuffmanTree[] Literals tree and distances tree. | [
"Creates",
"the",
"Huffman",
"codes",
"for",
"literals",
"and",
"distances",
"for",
"fixed",
"Huffman",
"compression",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Method/Native/GzipExtractor.php#L238-L249 |
38,276 | raulfraile/distill | src/Extractor/Util/Filesystem.php | Filesystem.unlink | private function unlink($path)
{
if (!@$this->unlinkImplementation($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@$this->unlinkImplementation($path))) {
$error = error_get_last();
$message = 'Could not delete '.$path.': '.@$error['message'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
}
throw new \RuntimeException($message);
}
}
return true;
} | php | private function unlink($path)
{
if (!@$this->unlinkImplementation($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@$this->unlinkImplementation($path))) {
$error = error_get_last();
$message = 'Could not delete '.$path.': '.@$error['message'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
}
throw new \RuntimeException($message);
}
}
return true;
} | [
"private",
"function",
"unlink",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"@",
"$",
"this",
"->",
"unlinkImplementation",
"(",
"$",
"path",
")",
")",
"{",
"// retry after a bit on windows since it tends to be touchy with mass removals",
"if",
"(",
"!",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
"||",
"(",
"usleep",
"(",
"350000",
")",
"&&",
"!",
"@",
"$",
"this",
"->",
"unlinkImplementation",
"(",
"$",
"path",
")",
")",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"$",
"message",
"=",
"'Could not delete '",
".",
"$",
"path",
".",
"': '",
".",
"@",
"$",
"error",
"[",
"'message'",
"]",
";",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"$",
"message",
".=",
"\"\\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed\"",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Attempts to unlink a file and in case of failure retries after 350ms on windows
@param string $path
@return bool
@throws \RuntimeException | [
"Attempts",
"to",
"unlink",
"a",
"file",
"and",
"in",
"case",
"of",
"failure",
"retries",
"after",
"350ms",
"on",
"windows"
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Extractor/Util/Filesystem.php#L140-L156 |
38,277 | raulfraile/distill | src/Extractor/Util/Filesystem.php | Filesystem.rmdir | private function rmdir($path)
{
if (!@rmdir($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@rmdir($path))) {
$error = error_get_last();
$message = 'Could not delete '.$path.': '.@$error['message'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
}
throw new \RuntimeException($message);
}
}
return true;
} | php | private function rmdir($path)
{
if (!@rmdir($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@rmdir($path))) {
$error = error_get_last();
$message = 'Could not delete '.$path.': '.@$error['message'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
}
throw new \RuntimeException($message);
}
}
return true;
} | [
"private",
"function",
"rmdir",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"@",
"rmdir",
"(",
"$",
"path",
")",
")",
"{",
"// retry after a bit on windows since it tends to be touchy with mass removals",
"if",
"(",
"!",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
"||",
"(",
"usleep",
"(",
"350000",
")",
"&&",
"!",
"@",
"rmdir",
"(",
"$",
"path",
")",
")",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"$",
"message",
"=",
"'Could not delete '",
".",
"$",
"path",
".",
"': '",
".",
"@",
"$",
"error",
"[",
"'message'",
"]",
";",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"$",
"message",
".=",
"\"\\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed\"",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Attempts to rmdir a file and in case of failure retries after 350ms on windows
@param string $path
@return bool
@throws \RuntimeException | [
"Attempts",
"to",
"rmdir",
"a",
"file",
"and",
"in",
"case",
"of",
"failure",
"retries",
"after",
"350ms",
"on",
"windows"
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Extractor/Util/Filesystem.php#L166-L182 |
38,278 | raulfraile/distill | src/Extractor/Util/ProcessExecutor.php | ProcessExecutor.execute | public function execute($command, &$output = null, $cwd = null)
{
// make sure that null translate to the proper directory in case the dir is a symlink
// and we call a git command, because msysgit does not handle symlinks properly
if (null === $cwd && defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($command, 'git') && getcwd()) {
$cwd = realpath(getcwd());
}
$this->captureOutput = count(func_get_args()) > 1;
$this->errorOutput = null;
$process = new Process($command, $cwd, null, null, static::getTimeout());
$callback = is_callable($output) ? $output : array($this, 'outputHandler');
$process->run($callback);
if ($this->captureOutput && !is_callable($output)) {
$output = $process->getOutput();
}
$this->errorOutput = $process->getErrorOutput();
return $process->getExitCode();
} | php | public function execute($command, &$output = null, $cwd = null)
{
// make sure that null translate to the proper directory in case the dir is a symlink
// and we call a git command, because msysgit does not handle symlinks properly
if (null === $cwd && defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($command, 'git') && getcwd()) {
$cwd = realpath(getcwd());
}
$this->captureOutput = count(func_get_args()) > 1;
$this->errorOutput = null;
$process = new Process($command, $cwd, null, null, static::getTimeout());
$callback = is_callable($output) ? $output : array($this, 'outputHandler');
$process->run($callback);
if ($this->captureOutput && !is_callable($output)) {
$output = $process->getOutput();
}
$this->errorOutput = $process->getErrorOutput();
return $process->getExitCode();
} | [
"public",
"function",
"execute",
"(",
"$",
"command",
",",
"&",
"$",
"output",
"=",
"null",
",",
"$",
"cwd",
"=",
"null",
")",
"{",
"// make sure that null translate to the proper directory in case the dir is a symlink",
"// and we call a git command, because msysgit does not handle symlinks properly",
"if",
"(",
"null",
"===",
"$",
"cwd",
"&&",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
"&&",
"false",
"!==",
"strpos",
"(",
"$",
"command",
",",
"'git'",
")",
"&&",
"getcwd",
"(",
")",
")",
"{",
"$",
"cwd",
"=",
"realpath",
"(",
"getcwd",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"captureOutput",
"=",
"count",
"(",
"func_get_args",
"(",
")",
")",
">",
"1",
";",
"$",
"this",
"->",
"errorOutput",
"=",
"null",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"command",
",",
"$",
"cwd",
",",
"null",
",",
"null",
",",
"static",
"::",
"getTimeout",
"(",
")",
")",
";",
"$",
"callback",
"=",
"is_callable",
"(",
"$",
"output",
")",
"?",
"$",
"output",
":",
"array",
"(",
"$",
"this",
",",
"'outputHandler'",
")",
";",
"$",
"process",
"->",
"run",
"(",
"$",
"callback",
")",
";",
"if",
"(",
"$",
"this",
"->",
"captureOutput",
"&&",
"!",
"is_callable",
"(",
"$",
"output",
")",
")",
"{",
"$",
"output",
"=",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}",
"$",
"this",
"->",
"errorOutput",
"=",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
";",
"return",
"$",
"process",
"->",
"getExitCode",
"(",
")",
";",
"}"
] | runs a process on the commandline
@param string $command the command to execute
@param mixed $output the output will be written into this var if passed by ref
if a callable is passed it will be used as output handler
@param string $cwd the working directory
@return int statuscode | [
"runs",
"a",
"process",
"on",
"the",
"commandline"
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Extractor/Util/ProcessExecutor.php#L37-L59 |
38,279 | raulfraile/distill | src/ContainerProvider.php | ContainerProvider.registerFormats | protected function registerFormats(Container $container)
{
foreach ($this->formats as $formatClass) {
$container['format.'.$formatClass::getName()] = $container->factory(function() use ($formatClass) {
return new $formatClass();
});
}
} | php | protected function registerFormats(Container $container)
{
foreach ($this->formats as $formatClass) {
$container['format.'.$formatClass::getName()] = $container->factory(function() use ($formatClass) {
return new $formatClass();
});
}
} | [
"protected",
"function",
"registerFormats",
"(",
"Container",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"formats",
"as",
"$",
"formatClass",
")",
"{",
"$",
"container",
"[",
"'format.'",
".",
"$",
"formatClass",
"::",
"getName",
"(",
")",
"]",
"=",
"$",
"container",
"->",
"factory",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"formatClass",
")",
"{",
"return",
"new",
"$",
"formatClass",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | Registers the formats.
@param Container $container Container | [
"Registers",
"the",
"formats",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/ContainerProvider.php#L152-L159 |
38,280 | raulfraile/distill | src/ContainerProvider.php | ContainerProvider.registerMethods | protected function registerMethods(Container $container)
{
$orderedMethods = [];
foreach ($this->methods as $methodClass) {
/** @var MethodInterface $method */
$method = new $methodClass();
if ($method->isSupported()) {
$container['method.'.$method->getName()] = function() use ($methodClass) {
return new $methodClass();
};
$orderedMethods[] = 'method.'.$method->getName();
}
}
// order methods
usort($orderedMethods, function ($methodName1, $methodName2) use ($container) {
$value1 = ((int) $container[$methodName1]->isSupported()) + ($container[$methodName1]->getUncompressionSpeedLevel() / 10);
$value2 = ((int) $container[$methodName2]->isSupported()) + ($container[$methodName2]->getUncompressionSpeedLevel() / 10);
if ($value1 == $value2) {
return 0;
}
return ($value1 > $value2) ? -1 : 1;
});
$container['method.__ordered'] = $orderedMethods;
} | php | protected function registerMethods(Container $container)
{
$orderedMethods = [];
foreach ($this->methods as $methodClass) {
/** @var MethodInterface $method */
$method = new $methodClass();
if ($method->isSupported()) {
$container['method.'.$method->getName()] = function() use ($methodClass) {
return new $methodClass();
};
$orderedMethods[] = 'method.'.$method->getName();
}
}
// order methods
usort($orderedMethods, function ($methodName1, $methodName2) use ($container) {
$value1 = ((int) $container[$methodName1]->isSupported()) + ($container[$methodName1]->getUncompressionSpeedLevel() / 10);
$value2 = ((int) $container[$methodName2]->isSupported()) + ($container[$methodName2]->getUncompressionSpeedLevel() / 10);
if ($value1 == $value2) {
return 0;
}
return ($value1 > $value2) ? -1 : 1;
});
$container['method.__ordered'] = $orderedMethods;
} | [
"protected",
"function",
"registerMethods",
"(",
"Container",
"$",
"container",
")",
"{",
"$",
"orderedMethods",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"methods",
"as",
"$",
"methodClass",
")",
"{",
"/** @var MethodInterface $method */",
"$",
"method",
"=",
"new",
"$",
"methodClass",
"(",
")",
";",
"if",
"(",
"$",
"method",
"->",
"isSupported",
"(",
")",
")",
"{",
"$",
"container",
"[",
"'method.'",
".",
"$",
"method",
"->",
"getName",
"(",
")",
"]",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"methodClass",
")",
"{",
"return",
"new",
"$",
"methodClass",
"(",
")",
";",
"}",
";",
"$",
"orderedMethods",
"[",
"]",
"=",
"'method.'",
".",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"// order methods",
"usort",
"(",
"$",
"orderedMethods",
",",
"function",
"(",
"$",
"methodName1",
",",
"$",
"methodName2",
")",
"use",
"(",
"$",
"container",
")",
"{",
"$",
"value1",
"=",
"(",
"(",
"int",
")",
"$",
"container",
"[",
"$",
"methodName1",
"]",
"->",
"isSupported",
"(",
")",
")",
"+",
"(",
"$",
"container",
"[",
"$",
"methodName1",
"]",
"->",
"getUncompressionSpeedLevel",
"(",
")",
"/",
"10",
")",
";",
"$",
"value2",
"=",
"(",
"(",
"int",
")",
"$",
"container",
"[",
"$",
"methodName2",
"]",
"->",
"isSupported",
"(",
")",
")",
"+",
"(",
"$",
"container",
"[",
"$",
"methodName2",
"]",
"->",
"getUncompressionSpeedLevel",
"(",
")",
"/",
"10",
")",
";",
"if",
"(",
"$",
"value1",
"==",
"$",
"value2",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"value1",
">",
"$",
"value2",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"container",
"[",
"'method.__ordered'",
"]",
"=",
"$",
"orderedMethods",
";",
"}"
] | Register the uncompression methods.
@param Container $container | [
"Register",
"the",
"uncompression",
"methods",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/ContainerProvider.php#L165-L195 |
38,281 | raulfraile/distill | src/Distill.php | Distill.initialize | protected function initialize()
{
$this->container = new Container();
$containerProvider = new ContainerProvider($this->disabledMethods, $this->disabledFormats);
$this->container->register($containerProvider);
$this->initialized = false;
} | php | protected function initialize()
{
$this->container = new Container();
$containerProvider = new ContainerProvider($this->disabledMethods, $this->disabledFormats);
$this->container->register($containerProvider);
$this->initialized = false;
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"$",
"this",
"->",
"container",
"=",
"new",
"Container",
"(",
")",
";",
"$",
"containerProvider",
"=",
"new",
"ContainerProvider",
"(",
"$",
"this",
"->",
"disabledMethods",
",",
"$",
"this",
"->",
"disabledFormats",
")",
";",
"$",
"this",
"->",
"container",
"->",
"register",
"(",
"$",
"containerProvider",
")",
";",
"$",
"this",
"->",
"initialized",
"=",
"false",
";",
"}"
] | Initialize the DIC. | [
"Initialize",
"the",
"DIC",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Distill.php#L97-L105 |
38,282 | raulfraile/distill | src/Method/Native/GzipExtractor/BitReader.php | BitReader.readByte | protected function readByte()
{
if (feof($this->fileHandler)) {
return false;
}
$data = unpack('C1byte', fread($this->fileHandler, 1));
$this->currentByte = $data['byte'];
$this->currentBitPosition = 0;
return true;
} | php | protected function readByte()
{
if (feof($this->fileHandler)) {
return false;
}
$data = unpack('C1byte', fread($this->fileHandler, 1));
$this->currentByte = $data['byte'];
$this->currentBitPosition = 0;
return true;
} | [
"protected",
"function",
"readByte",
"(",
")",
"{",
"if",
"(",
"feof",
"(",
"$",
"this",
"->",
"fileHandler",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"unpack",
"(",
"'C1byte'",
",",
"fread",
"(",
"$",
"this",
"->",
"fileHandler",
",",
"1",
")",
")",
";",
"$",
"this",
"->",
"currentByte",
"=",
"$",
"data",
"[",
"'byte'",
"]",
";",
"$",
"this",
"->",
"currentBitPosition",
"=",
"0",
";",
"return",
"true",
";",
"}"
] | Reads a byte from the file.
@return bool | [
"Reads",
"a",
"byte",
"from",
"the",
"file",
"."
] | 9ab33b98651bd15c2d6d70bf8c78eda0068fe52b | https://github.com/raulfraile/distill/blob/9ab33b98651bd15c2d6d70bf8c78eda0068fe52b/src/Method/Native/GzipExtractor/BitReader.php#L105-L116 |
38,283 | AydinHassan/magento-core-composer-installer | src/Exclude.php | Exclude.exclude | public function exclude($filePath)
{
foreach ($this->excludes as $exclude) {
if ($this->isExcludeDir($exclude)) {
if (substr($filePath, 0, strlen($exclude)) === $exclude) {
return true;
}
} elseif ($exclude === $filePath) {
return true;
}
}
return false;
} | php | public function exclude($filePath)
{
foreach ($this->excludes as $exclude) {
if ($this->isExcludeDir($exclude)) {
if (substr($filePath, 0, strlen($exclude)) === $exclude) {
return true;
}
} elseif ($exclude === $filePath) {
return true;
}
}
return false;
} | [
"public",
"function",
"exclude",
"(",
"$",
"filePath",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"excludes",
"as",
"$",
"exclude",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isExcludeDir",
"(",
"$",
"exclude",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"filePath",
",",
"0",
",",
"strlen",
"(",
"$",
"exclude",
")",
")",
"===",
"$",
"exclude",
")",
"{",
"return",
"true",
";",
"}",
"}",
"elseif",
"(",
"$",
"exclude",
"===",
"$",
"filePath",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Should we exclude this file from the install?
@param string $filePath
@return bool | [
"Should",
"we",
"exclude",
"this",
"file",
"from",
"the",
"install?"
] | 3e986ad18ff57847f543a850bc48b62ece411a23 | https://github.com/AydinHassan/magento-core-composer-installer/blob/3e986ad18ff57847f543a850bc48b62ece411a23/src/Exclude.php#L40-L54 |
38,284 | AydinHassan/magento-core-composer-installer | src/GitIgnore.php | GitIgnore.addEntriesForDirectoriesToIgnoreEntirely | protected function addEntriesForDirectoriesToIgnoreEntirely()
{
foreach ($this->directoriesToIgnoreEntirely as $directory) {
if (!in_array($directory, $this->lines)) {
$this->lines[] = $directory;
$this->hasChanges = true;
}
}
} | php | protected function addEntriesForDirectoriesToIgnoreEntirely()
{
foreach ($this->directoriesToIgnoreEntirely as $directory) {
if (!in_array($directory, $this->lines)) {
$this->lines[] = $directory;
$this->hasChanges = true;
}
}
} | [
"protected",
"function",
"addEntriesForDirectoriesToIgnoreEntirely",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"directoriesToIgnoreEntirely",
"as",
"$",
"directory",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"directory",
",",
"$",
"this",
"->",
"lines",
")",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"]",
"=",
"$",
"directory",
";",
"$",
"this",
"->",
"hasChanges",
"=",
"true",
";",
"}",
"}",
"}"
] | Add entries to for all directories ignored entirely. | [
"Add",
"entries",
"to",
"for",
"all",
"directories",
"ignored",
"entirely",
"."
] | 3e986ad18ff57847f543a850bc48b62ece411a23 | https://github.com/AydinHassan/magento-core-composer-installer/blob/3e986ad18ff57847f543a850bc48b62ece411a23/src/GitIgnore.php#L135-L143 |
38,285 | AydinHassan/magento-core-composer-installer | src/CoreManager.php | CoreManager.getSubscribedEvents | public static function getSubscribedEvents()
{
return array(
InstallerEvents::POST_DEPENDENCIES_SOLVING => array(
array('checkCoreDependencies', 0)
),
PackageEvents::POST_PACKAGE_INSTALL => array(
array('installCore', 0)
),
PackageEvents::PRE_PACKAGE_UPDATE => array(
array('uninstallCore', 0)
),
PackageEvents::POST_PACKAGE_UPDATE => array(
array('installCore', 0)
),
PackageEvents::PRE_PACKAGE_UNINSTALL => array(
array('uninstallCore', 0)
),
);
} | php | public static function getSubscribedEvents()
{
return array(
InstallerEvents::POST_DEPENDENCIES_SOLVING => array(
array('checkCoreDependencies', 0)
),
PackageEvents::POST_PACKAGE_INSTALL => array(
array('installCore', 0)
),
PackageEvents::PRE_PACKAGE_UPDATE => array(
array('uninstallCore', 0)
),
PackageEvents::POST_PACKAGE_UPDATE => array(
array('installCore', 0)
),
PackageEvents::PRE_PACKAGE_UNINSTALL => array(
array('uninstallCore', 0)
),
);
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"return",
"array",
"(",
"InstallerEvents",
"::",
"POST_DEPENDENCIES_SOLVING",
"=>",
"array",
"(",
"array",
"(",
"'checkCoreDependencies'",
",",
"0",
")",
")",
",",
"PackageEvents",
"::",
"POST_PACKAGE_INSTALL",
"=>",
"array",
"(",
"array",
"(",
"'installCore'",
",",
"0",
")",
")",
",",
"PackageEvents",
"::",
"PRE_PACKAGE_UPDATE",
"=>",
"array",
"(",
"array",
"(",
"'uninstallCore'",
",",
"0",
")",
")",
",",
"PackageEvents",
"::",
"POST_PACKAGE_UPDATE",
"=>",
"array",
"(",
"array",
"(",
"'installCore'",
",",
"0",
")",
")",
",",
"PackageEvents",
"::",
"PRE_PACKAGE_UNINSTALL",
"=>",
"array",
"(",
"array",
"(",
"'uninstallCore'",
",",
"0",
")",
")",
",",
")",
";",
"}"
] | Tell event dispatcher what events we want to subscribe to
@return array | [
"Tell",
"event",
"dispatcher",
"what",
"events",
"we",
"want",
"to",
"subscribe",
"to"
] | 3e986ad18ff57847f543a850bc48b62ece411a23 | https://github.com/AydinHassan/magento-core-composer-installer/blob/3e986ad18ff57847f543a850bc48b62ece411a23/src/CoreManager.php#L97-L116 |
38,286 | AydinHassan/magento-core-composer-installer | src/CoreManager.php | CoreManager.checkCoreDependencies | public function checkCoreDependencies(InstallerEvent $event)
{
$options = new Options($this->composer->getPackage()->getExtra());
$installedCorePackages = array();
foreach ($event->getInstalledRepo()->getPackages() as $package) {
if ($package->getType() === $options->getMagentoCorePackageType()) {
$installedCorePackages[$package->getName()] = $package;
}
}
$operations = array_filter($event->getOperations(), function (OperationInterface $o) {
return in_array($o->getJobType(), array('install', 'uninstall'));
});
foreach ($operations as $operation) {
$p = $operation->getPackage();
if ($package->getType() === $options->getMagentoCorePackageType()) {
switch ($operation->getJobType()) {
case "uninstall":
unset($installedCorePackages[$p->getName()]);
break;
case "install":
$installedCorePackages[$p->getName()] = $p;
break;
}
}
}
if (count($installedCorePackages) > 1) {
throw new \RuntimeException("Cannot use more than 1 core package");
}
} | php | public function checkCoreDependencies(InstallerEvent $event)
{
$options = new Options($this->composer->getPackage()->getExtra());
$installedCorePackages = array();
foreach ($event->getInstalledRepo()->getPackages() as $package) {
if ($package->getType() === $options->getMagentoCorePackageType()) {
$installedCorePackages[$package->getName()] = $package;
}
}
$operations = array_filter($event->getOperations(), function (OperationInterface $o) {
return in_array($o->getJobType(), array('install', 'uninstall'));
});
foreach ($operations as $operation) {
$p = $operation->getPackage();
if ($package->getType() === $options->getMagentoCorePackageType()) {
switch ($operation->getJobType()) {
case "uninstall":
unset($installedCorePackages[$p->getName()]);
break;
case "install":
$installedCorePackages[$p->getName()] = $p;
break;
}
}
}
if (count($installedCorePackages) > 1) {
throw new \RuntimeException("Cannot use more than 1 core package");
}
} | [
"public",
"function",
"checkCoreDependencies",
"(",
"InstallerEvent",
"$",
"event",
")",
"{",
"$",
"options",
"=",
"new",
"Options",
"(",
"$",
"this",
"->",
"composer",
"->",
"getPackage",
"(",
")",
"->",
"getExtra",
"(",
")",
")",
";",
"$",
"installedCorePackages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"event",
"->",
"getInstalledRepo",
"(",
")",
"->",
"getPackages",
"(",
")",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"$",
"package",
"->",
"getType",
"(",
")",
"===",
"$",
"options",
"->",
"getMagentoCorePackageType",
"(",
")",
")",
"{",
"$",
"installedCorePackages",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"package",
";",
"}",
"}",
"$",
"operations",
"=",
"array_filter",
"(",
"$",
"event",
"->",
"getOperations",
"(",
")",
",",
"function",
"(",
"OperationInterface",
"$",
"o",
")",
"{",
"return",
"in_array",
"(",
"$",
"o",
"->",
"getJobType",
"(",
")",
",",
"array",
"(",
"'install'",
",",
"'uninstall'",
")",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"operations",
"as",
"$",
"operation",
")",
"{",
"$",
"p",
"=",
"$",
"operation",
"->",
"getPackage",
"(",
")",
";",
"if",
"(",
"$",
"package",
"->",
"getType",
"(",
")",
"===",
"$",
"options",
"->",
"getMagentoCorePackageType",
"(",
")",
")",
"{",
"switch",
"(",
"$",
"operation",
"->",
"getJobType",
"(",
")",
")",
"{",
"case",
"\"uninstall\"",
":",
"unset",
"(",
"$",
"installedCorePackages",
"[",
"$",
"p",
"->",
"getName",
"(",
")",
"]",
")",
";",
"break",
";",
"case",
"\"install\"",
":",
"$",
"installedCorePackages",
"[",
"$",
"p",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"p",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"installedCorePackages",
")",
">",
"1",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Cannot use more than 1 core package\"",
")",
";",
"}",
"}"
] | Check that there is only 1 core package required | [
"Check",
"that",
"there",
"is",
"only",
"1",
"core",
"package",
"required"
] | 3e986ad18ff57847f543a850bc48b62ece411a23 | https://github.com/AydinHassan/magento-core-composer-installer/blob/3e986ad18ff57847f543a850bc48b62ece411a23/src/CoreManager.php#L121-L152 |
38,287 | AydinHassan/magento-core-composer-installer | src/CoreManager.php | CoreManager.ensureRootDirExists | private function ensureRootDirExists(Options $options)
{
if (!file_exists($options->getMagentoRootDir())) {
mkdir($options->getMagentoRootDir(), 0755, true);
}
} | php | private function ensureRootDirExists(Options $options)
{
if (!file_exists($options->getMagentoRootDir())) {
mkdir($options->getMagentoRootDir(), 0755, true);
}
} | [
"private",
"function",
"ensureRootDirExists",
"(",
"Options",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"options",
"->",
"getMagentoRootDir",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"options",
"->",
"getMagentoRootDir",
"(",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"}"
] | Create root directory if it doesn't exist already
@param Options $options | [
"Create",
"root",
"directory",
"if",
"it",
"doesn",
"t",
"exist",
"already"
] | 3e986ad18ff57847f543a850bc48b62ece411a23 | https://github.com/AydinHassan/magento-core-composer-installer/blob/3e986ad18ff57847f543a850bc48b62ece411a23/src/CoreManager.php#L224-L229 |
38,288 | thecodingmachine/mouf | src/Mouf/Reflection/MoufReflectionProperty.php | MoufReflectionProperty.getDeclaringClassWithoutTraits | public function getDeclaringClassWithoutTraits()
{
$refClass = parent::getDeclaringClass();
if ($refClass->getName() === $this->className) {
if (null === $this->refClass) {
$this->refClass = new MoufReflectionClass($this->className);
}
return $this->refClass;
}
$moufRefClass = new MoufReflectionClass($refClass->getName());
return $moufRefClass;
} | php | public function getDeclaringClassWithoutTraits()
{
$refClass = parent::getDeclaringClass();
if ($refClass->getName() === $this->className) {
if (null === $this->refClass) {
$this->refClass = new MoufReflectionClass($this->className);
}
return $this->refClass;
}
$moufRefClass = new MoufReflectionClass($refClass->getName());
return $moufRefClass;
} | [
"public",
"function",
"getDeclaringClassWithoutTraits",
"(",
")",
"{",
"$",
"refClass",
"=",
"parent",
"::",
"getDeclaringClass",
"(",
")",
";",
"if",
"(",
"$",
"refClass",
"->",
"getName",
"(",
")",
"===",
"$",
"this",
"->",
"className",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"refClass",
")",
"{",
"$",
"this",
"->",
"refClass",
"=",
"new",
"MoufReflectionClass",
"(",
"$",
"this",
"->",
"className",
")",
";",
"}",
"return",
"$",
"this",
"->",
"refClass",
";",
"}",
"$",
"moufRefClass",
"=",
"new",
"MoufReflectionClass",
"(",
"$",
"refClass",
"->",
"getName",
"(",
")",
")",
";",
"return",
"$",
"moufRefClass",
";",
"}"
] | Returns the class that declares this parameter
@return MoufReflectionClass | [
"Returns",
"the",
"class",
"that",
"declares",
"this",
"parameter"
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Reflection/MoufReflectionProperty.php#L215-L228 |
38,289 | thecodingmachine/mouf | src/Mouf/Reflection/MoufReflectionProperty.php | MoufReflectionProperty.getDefault | public function getDefault() {
if ($this->isPublic() && !$this->isStatic() && $this->refClass->isAbstract() == false) {
$className = $this->refClass->getName();
// TODO: find a way to get default value for abstract properties.
// TODO: optimize this: we should not have to create one new instance for every property....
/*$instance = new $className();
$property = $this->getName();
return $instance->$property;*/
// In some cases, the call to getDefaultProperties can log NOTICES
// in particular if an undefined constant is used as default value.
ob_start();
$defaultProperties = $this->refClass->getDefaultProperties();
$possibleError = ob_get_clean();
if ($possibleError) {
throw new \Exception($possibleError);
}
return $defaultProperties[$this->getName()];
} else {
return null;
}
} | php | public function getDefault() {
if ($this->isPublic() && !$this->isStatic() && $this->refClass->isAbstract() == false) {
$className = $this->refClass->getName();
// TODO: find a way to get default value for abstract properties.
// TODO: optimize this: we should not have to create one new instance for every property....
/*$instance = new $className();
$property = $this->getName();
return $instance->$property;*/
// In some cases, the call to getDefaultProperties can log NOTICES
// in particular if an undefined constant is used as default value.
ob_start();
$defaultProperties = $this->refClass->getDefaultProperties();
$possibleError = ob_get_clean();
if ($possibleError) {
throw new \Exception($possibleError);
}
return $defaultProperties[$this->getName()];
} else {
return null;
}
} | [
"public",
"function",
"getDefault",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPublic",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isStatic",
"(",
")",
"&&",
"$",
"this",
"->",
"refClass",
"->",
"isAbstract",
"(",
")",
"==",
"false",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"refClass",
"->",
"getName",
"(",
")",
";",
"// TODO: find a way to get default value for abstract properties.\r",
"// TODO: optimize this: we should not have to create one new instance for every property....\r",
"/*$instance = new $className();\r\n\t\t\t$property = $this->getName();\r\n\t \treturn $instance->$property;*/",
"// In some cases, the call to getDefaultProperties can log NOTICES\r",
"// in particular if an undefined constant is used as default value.\r",
"ob_start",
"(",
")",
";",
"$",
"defaultProperties",
"=",
"$",
"this",
"->",
"refClass",
"->",
"getDefaultProperties",
"(",
")",
";",
"$",
"possibleError",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"$",
"possibleError",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"possibleError",
")",
";",
"}",
"return",
"$",
"defaultProperties",
"[",
"$",
"this",
"->",
"getName",
"(",
")",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Returns the default value
@return mixed | [
"Returns",
"the",
"default",
"value"
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Reflection/MoufReflectionProperty.php#L235-L256 |
38,290 | thecodingmachine/mouf | src/Mouf/Reflection/MoufReflectionProperty.php | MoufReflectionProperty.toJson | public function toJson() {
$result = array();
$result['name'] = $this->getName();
$result['comment'] = $this->getMoufPhpDocComment()->getJsonArray();
/*$properties = $this->getAnnotations("Property");
if (!empty($properties)) {
$result['moufProperty'] = true;*/
try {
$result['default'] = $this->getDefault();
// TODO: is there a need to instanciate a MoufPropertyDescriptor?
$moufPropertyDescriptor = new MoufPropertyDescriptor($this);
$types = $moufPropertyDescriptor->getTypes();
$result['types'] = $types->toJson();
if ($types->getWarningMessage()) {
$result['classinerror'] = $types->getWarningMessage();
}
} catch (\Exception $e) {
$result['classinerror'] = $e->getMessage();
}
/*if ($moufPropertyDescriptor->isAssociativeArray()) {
$result['keytype'] = $moufPropertyDescriptor->getKeyType();
}
if ($moufPropertyDescriptor->isArray()) {
$result['subtype'] = $moufPropertyDescriptor->getSubType();
}*/
//}
return $result;
} | php | public function toJson() {
$result = array();
$result['name'] = $this->getName();
$result['comment'] = $this->getMoufPhpDocComment()->getJsonArray();
/*$properties = $this->getAnnotations("Property");
if (!empty($properties)) {
$result['moufProperty'] = true;*/
try {
$result['default'] = $this->getDefault();
// TODO: is there a need to instanciate a MoufPropertyDescriptor?
$moufPropertyDescriptor = new MoufPropertyDescriptor($this);
$types = $moufPropertyDescriptor->getTypes();
$result['types'] = $types->toJson();
if ($types->getWarningMessage()) {
$result['classinerror'] = $types->getWarningMessage();
}
} catch (\Exception $e) {
$result['classinerror'] = $e->getMessage();
}
/*if ($moufPropertyDescriptor->isAssociativeArray()) {
$result['keytype'] = $moufPropertyDescriptor->getKeyType();
}
if ($moufPropertyDescriptor->isArray()) {
$result['subtype'] = $moufPropertyDescriptor->getSubType();
}*/
//}
return $result;
} | [
"public",
"function",
"toJson",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"result",
"[",
"'comment'",
"]",
"=",
"$",
"this",
"->",
"getMoufPhpDocComment",
"(",
")",
"->",
"getJsonArray",
"(",
")",
";",
"/*$properties = $this->getAnnotations(\"Property\");\n \t\tif (!empty($properties)) {\n \t$result['moufProperty'] = true;*/",
"try",
"{",
"$",
"result",
"[",
"'default'",
"]",
"=",
"$",
"this",
"->",
"getDefault",
"(",
")",
";",
"// TODO: is there a need to instanciate a MoufPropertyDescriptor?",
"$",
"moufPropertyDescriptor",
"=",
"new",
"MoufPropertyDescriptor",
"(",
"$",
"this",
")",
";",
"$",
"types",
"=",
"$",
"moufPropertyDescriptor",
"->",
"getTypes",
"(",
")",
";",
"$",
"result",
"[",
"'types'",
"]",
"=",
"$",
"types",
"->",
"toJson",
"(",
")",
";",
"if",
"(",
"$",
"types",
"->",
"getWarningMessage",
"(",
")",
")",
"{",
"$",
"result",
"[",
"'classinerror'",
"]",
"=",
"$",
"types",
"->",
"getWarningMessage",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"result",
"[",
"'classinerror'",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"/*if ($moufPropertyDescriptor->isAssociativeArray()) {\n \t\t$result['keytype'] = $moufPropertyDescriptor->getKeyType();\n \t}\n \tif ($moufPropertyDescriptor->isArray()) {\n \t\t$result['subtype'] = $moufPropertyDescriptor->getSubType();\n \t}*/",
"//}",
"return",
"$",
"result",
";",
"}"
] | Returns a PHP array representing the property.
@return array | [
"Returns",
"a",
"PHP",
"array",
"representing",
"the",
"property",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Reflection/MoufReflectionProperty.php#L295-L328 |
38,291 | thecodingmachine/mouf | src/Mouf/Composer/ComposerService.php | ComposerService.registerAutoloader | public static function registerAutoloader()
{
if (null !== static::$loader) {
return static::$loader;
}
static::$loader = $loader = new \Composer\Autoload\ClassLoader();
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
$map = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register();
return $loader;
} | php | public static function registerAutoloader()
{
if (null !== static::$loader) {
return static::$loader;
}
static::$loader = $loader = new \Composer\Autoload\ClassLoader();
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
$map = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require 'phar://'.__DIR__.'/../../../composer.phar/vendor/composer/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register();
return $loader;
} | [
"public",
"static",
"function",
"registerAutoloader",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"static",
"::",
"$",
"loader",
")",
"{",
"return",
"static",
"::",
"$",
"loader",
";",
"}",
"static",
"::",
"$",
"loader",
"=",
"$",
"loader",
"=",
"new",
"\\",
"Composer",
"\\",
"Autoload",
"\\",
"ClassLoader",
"(",
")",
";",
"$",
"vendorDir",
"=",
"dirname",
"(",
"__DIR__",
")",
";",
"$",
"baseDir",
"=",
"dirname",
"(",
"$",
"vendorDir",
")",
";",
"$",
"map",
"=",
"require",
"'phar://'",
".",
"__DIR__",
".",
"'/../../../composer.phar/vendor/composer/autoload_namespaces.php'",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"namespace",
"=>",
"$",
"path",
")",
"{",
"$",
"loader",
"->",
"set",
"(",
"$",
"namespace",
",",
"$",
"path",
")",
";",
"}",
"$",
"map",
"=",
"require",
"'phar://'",
".",
"__DIR__",
".",
"'/../../../composer.phar/vendor/composer/autoload_psr4.php'",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"namespace",
"=>",
"$",
"path",
")",
"{",
"$",
"loader",
"->",
"setPsr4",
"(",
"$",
"namespace",
",",
"$",
"path",
")",
";",
"}",
"$",
"classMap",
"=",
"require",
"'phar://'",
".",
"__DIR__",
".",
"'/../../../composer.phar/vendor/composer/autoload_classmap.php'",
";",
"if",
"(",
"$",
"classMap",
")",
"{",
"$",
"loader",
"->",
"addClassMap",
"(",
"$",
"classMap",
")",
";",
"}",
"$",
"loader",
"->",
"register",
"(",
")",
";",
"return",
"$",
"loader",
";",
"}"
] | Register the autoloader for composer. | [
"Register",
"the",
"autoloader",
"for",
"composer",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Composer/ComposerService.php#L209-L237 |
38,292 | thecodingmachine/mouf | src/Mouf/Composer/ComposerService.php | ComposerService.getComposer | public function getComposer() {
if (null === $this->composer) {
$this->configureEnv();
if ($this->outputBufferedJs) {
$this->io = new MoufJsComposerIO();
} else {
$this->io = new BufferIO();
}
$this->composer = Factory::create($this->io, null, true);
}
return $this->composer;
} | php | public function getComposer() {
if (null === $this->composer) {
$this->configureEnv();
if ($this->outputBufferedJs) {
$this->io = new MoufJsComposerIO();
} else {
$this->io = new BufferIO();
}
$this->composer = Factory::create($this->io, null, true);
}
return $this->composer;
} | [
"public",
"function",
"getComposer",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"composer",
")",
"{",
"$",
"this",
"->",
"configureEnv",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"outputBufferedJs",
")",
"{",
"$",
"this",
"->",
"io",
"=",
"new",
"MoufJsComposerIO",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"io",
"=",
"new",
"BufferIO",
"(",
")",
";",
"}",
"$",
"this",
"->",
"composer",
"=",
"Factory",
"::",
"create",
"(",
"$",
"this",
"->",
"io",
",",
"null",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"composer",
";",
"}"
] | Exposes the Composer object
@return Composer | [
"Exposes",
"the",
"Composer",
"object"
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Composer/ComposerService.php#L244-L257 |
38,293 | thecodingmachine/mouf | src/Mouf/Composer/ComposerService.php | ComposerService.configureEnv | private function configureEnv() {
if ($this->selfEdit) {
chdir(__DIR__."/../../..");
\putenv('COMPOSER=composer-mouf.json');
} else {
chdir(__DIR__."/../../../../../..");
}
$composerHome = getenv('COMPOSER_HOME');
if (!$composerHome) {
$composerTmpDir = sys_get_temp_dir().'/.mouf_composer/';
if (function_exists('posix_getpwuid')) {
$processUser = posix_getpwuid(posix_geteuid());
$composerTmpDir .= $processUser['name'].'/';
}
\putenv('COMPOSER_HOME='.$composerTmpDir);
}
} | php | private function configureEnv() {
if ($this->selfEdit) {
chdir(__DIR__."/../../..");
\putenv('COMPOSER=composer-mouf.json');
} else {
chdir(__DIR__."/../../../../../..");
}
$composerHome = getenv('COMPOSER_HOME');
if (!$composerHome) {
$composerTmpDir = sys_get_temp_dir().'/.mouf_composer/';
if (function_exists('posix_getpwuid')) {
$processUser = posix_getpwuid(posix_geteuid());
$composerTmpDir .= $processUser['name'].'/';
}
\putenv('COMPOSER_HOME='.$composerTmpDir);
}
} | [
"private",
"function",
"configureEnv",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"selfEdit",
")",
"{",
"chdir",
"(",
"__DIR__",
".",
"\"/../../..\"",
")",
";",
"\\",
"putenv",
"(",
"'COMPOSER=composer-mouf.json'",
")",
";",
"}",
"else",
"{",
"chdir",
"(",
"__DIR__",
".",
"\"/../../../../../..\"",
")",
";",
"}",
"$",
"composerHome",
"=",
"getenv",
"(",
"'COMPOSER_HOME'",
")",
";",
"if",
"(",
"!",
"$",
"composerHome",
")",
"{",
"$",
"composerTmpDir",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/.mouf_composer/'",
";",
"if",
"(",
"function_exists",
"(",
"'posix_getpwuid'",
")",
")",
"{",
"$",
"processUser",
"=",
"posix_getpwuid",
"(",
"posix_geteuid",
"(",
")",
")",
";",
"$",
"composerTmpDir",
".=",
"$",
"processUser",
"[",
"'name'",
"]",
".",
"'/'",
";",
"}",
"\\",
"putenv",
"(",
"'COMPOSER_HOME='",
".",
"$",
"composerTmpDir",
")",
";",
"}",
"}"
] | Changes the current working directory and set environment variables to be able to work with Composer. | [
"Changes",
"the",
"current",
"working",
"directory",
"and",
"set",
"environment",
"variables",
"to",
"be",
"able",
"to",
"work",
"with",
"Composer",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Composer/ComposerService.php#L262-L280 |
38,294 | thecodingmachine/mouf | src/Mouf/Composer/ComposerService.php | ComposerService.getLocalPackages | public function getLocalPackages() {
$composer = $this->getComposer();
$dispatcher = new EventDispatcher($composer, $this->io);
$autoloadGenerator = new \Composer\Autoload\AutoloadGenerator($dispatcher);
if ($this->selfEdit) {
chdir(__DIR__."/../../..");
\putenv('COMPOSER=composer-mouf.json');
} else {
chdir(__DIR__."/../../../../../..");
}
//TODO: this call is strange because it will return the same isntance as above.
$composer = $this->getComposer();
$localRepos = new CompositeRepository(array($composer->getRepositoryManager()->getLocalRepository()));
$package = $composer->getPackage();
$packagesList = $localRepos->getPackages();
$packagesList[] = $package;
return $packagesList;
} | php | public function getLocalPackages() {
$composer = $this->getComposer();
$dispatcher = new EventDispatcher($composer, $this->io);
$autoloadGenerator = new \Composer\Autoload\AutoloadGenerator($dispatcher);
if ($this->selfEdit) {
chdir(__DIR__."/../../..");
\putenv('COMPOSER=composer-mouf.json');
} else {
chdir(__DIR__."/../../../../../..");
}
//TODO: this call is strange because it will return the same isntance as above.
$composer = $this->getComposer();
$localRepos = new CompositeRepository(array($composer->getRepositoryManager()->getLocalRepository()));
$package = $composer->getPackage();
$packagesList = $localRepos->getPackages();
$packagesList[] = $package;
return $packagesList;
} | [
"public",
"function",
"getLocalPackages",
"(",
")",
"{",
"$",
"composer",
"=",
"$",
"this",
"->",
"getComposer",
"(",
")",
";",
"$",
"dispatcher",
"=",
"new",
"EventDispatcher",
"(",
"$",
"composer",
",",
"$",
"this",
"->",
"io",
")",
";",
"$",
"autoloadGenerator",
"=",
"new",
"\\",
"Composer",
"\\",
"Autoload",
"\\",
"AutoloadGenerator",
"(",
"$",
"dispatcher",
")",
";",
"if",
"(",
"$",
"this",
"->",
"selfEdit",
")",
"{",
"chdir",
"(",
"__DIR__",
".",
"\"/../../..\"",
")",
";",
"\\",
"putenv",
"(",
"'COMPOSER=composer-mouf.json'",
")",
";",
"}",
"else",
"{",
"chdir",
"(",
"__DIR__",
".",
"\"/../../../../../..\"",
")",
";",
"}",
"//TODO: this call is strange because it will return the same isntance as above.",
"$",
"composer",
"=",
"$",
"this",
"->",
"getComposer",
"(",
")",
";",
"$",
"localRepos",
"=",
"new",
"CompositeRepository",
"(",
"array",
"(",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
")",
")",
";",
"$",
"package",
"=",
"$",
"composer",
"->",
"getPackage",
"(",
")",
";",
"$",
"packagesList",
"=",
"$",
"localRepos",
"->",
"getPackages",
"(",
")",
";",
"$",
"packagesList",
"[",
"]",
"=",
"$",
"package",
";",
"return",
"$",
"packagesList",
";",
"}"
] | Returns an array of Composer packages currently installed.
@return PackageInterface[] | [
"Returns",
"an",
"array",
"of",
"Composer",
"packages",
"currently",
"installed",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Composer/ComposerService.php#L311-L331 |
38,295 | thecodingmachine/mouf | src/Mouf/Composer/ComposerService.php | ComposerService.searchPackages | public function searchPackages($text, OnPackageFoundInterface $callback, $onlyName = false, $includeLocal = true) {
$this->onPackageFoundCallback = $callback;
$composer = $this->getComposer();
$platformRepo = new PlatformRepository;
$searched = array();
if ($includeLocal) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$searched[] = $localRepo;
}
$searched[] = $platformRepo;
$installedRepo = new CompositeRepository($searched);
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
//$this->onlyName = $input->getOption('only-name');
$this->onlyName = $onlyName;
//$this->tokens = $input->getArgument('tokens');
$this->tokens = explode(" ", $text);
//$this->output = $output;
$repos->filterPackages(array($this, 'processPackage'), 'Composer\Package\CompletePackage');
/*foreach ($this->lowMatches as $details) {
$output->writeln($details['name'] . '<comment>:</comment> '. $details['description']);
}*/
} | php | public function searchPackages($text, OnPackageFoundInterface $callback, $onlyName = false, $includeLocal = true) {
$this->onPackageFoundCallback = $callback;
$composer = $this->getComposer();
$platformRepo = new PlatformRepository;
$searched = array();
if ($includeLocal) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$searched[] = $localRepo;
}
$searched[] = $platformRepo;
$installedRepo = new CompositeRepository($searched);
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
//$this->onlyName = $input->getOption('only-name');
$this->onlyName = $onlyName;
//$this->tokens = $input->getArgument('tokens');
$this->tokens = explode(" ", $text);
//$this->output = $output;
$repos->filterPackages(array($this, 'processPackage'), 'Composer\Package\CompletePackage');
/*foreach ($this->lowMatches as $details) {
$output->writeln($details['name'] . '<comment>:</comment> '. $details['description']);
}*/
} | [
"public",
"function",
"searchPackages",
"(",
"$",
"text",
",",
"OnPackageFoundInterface",
"$",
"callback",
",",
"$",
"onlyName",
"=",
"false",
",",
"$",
"includeLocal",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"onPackageFoundCallback",
"=",
"$",
"callback",
";",
"$",
"composer",
"=",
"$",
"this",
"->",
"getComposer",
"(",
")",
";",
"$",
"platformRepo",
"=",
"new",
"PlatformRepository",
";",
"$",
"searched",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"includeLocal",
")",
"{",
"$",
"localRepo",
"=",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
";",
"$",
"searched",
"[",
"]",
"=",
"$",
"localRepo",
";",
"}",
"$",
"searched",
"[",
"]",
"=",
"$",
"platformRepo",
";",
"$",
"installedRepo",
"=",
"new",
"CompositeRepository",
"(",
"$",
"searched",
")",
";",
"$",
"repos",
"=",
"new",
"CompositeRepository",
"(",
"array_merge",
"(",
"array",
"(",
"$",
"installedRepo",
")",
",",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getRepositories",
"(",
")",
")",
")",
";",
"//$this->onlyName = $input->getOption('only-name');",
"$",
"this",
"->",
"onlyName",
"=",
"$",
"onlyName",
";",
"//$this->tokens = $input->getArgument('tokens');",
"$",
"this",
"->",
"tokens",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"text",
")",
";",
"//$this->output = $output;",
"$",
"repos",
"->",
"filterPackages",
"(",
"array",
"(",
"$",
"this",
",",
"'processPackage'",
")",
",",
"'Composer\\Package\\CompletePackage'",
")",
";",
"/*foreach ($this->lowMatches as $details) {\n\t\t\t$output->writeln($details['name'] . '<comment>:</comment> '. $details['description']);\n\t\t}*/",
"}"
] | Returns a list of packages matching the search query.
@param string $text
@param OnPackageFoundInterface $callback
@param bool $onlyName | [
"Returns",
"a",
"list",
"of",
"packages",
"matching",
"the",
"search",
"query",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/Composer/ComposerService.php#L356-L382 |
38,296 | Lecturize/Laravel-Taxonomies | src/TaxonomiesServiceProvider.php | TaxonomiesServiceProvider.handleConfig | private function handleConfig()
{
$configPath = __DIR__ . '/../config/config.php';
$this->publishes([$configPath => config_path('lecturize.php')]);
$this->mergeConfigFrom($configPath, 'lecturize');
} | php | private function handleConfig()
{
$configPath = __DIR__ . '/../config/config.php';
$this->publishes([$configPath => config_path('lecturize.php')]);
$this->mergeConfigFrom($configPath, 'lecturize');
} | [
"private",
"function",
"handleConfig",
"(",
")",
"{",
"$",
"configPath",
"=",
"__DIR__",
".",
"'/../config/config.php'",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"configPath",
"=>",
"config_path",
"(",
"'lecturize.php'",
")",
"]",
")",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"$",
"configPath",
",",
"'lecturize'",
")",
";",
"}"
] | Publish and merge the config file.
@return void | [
"Publish",
"and",
"merge",
"the",
"config",
"file",
"."
] | 46774dbfef61131cf8f3fd9a2ab5c2ef4fccd6be | https://github.com/Lecturize/Laravel-Taxonomies/blob/46774dbfef61131cf8f3fd9a2ab5c2ef4fccd6be/src/TaxonomiesServiceProvider.php#L41-L48 |
38,297 | thecodingmachine/mouf | src-dev/Mouf/Menu/DocumentationMenuItem.php | DocumentationMenuItem.getMenuTree | private function getMenuTree() {
if ($this->computed) {
return parent::getChildren();
}
$this->computed = true;
$children = $this->cache->get('documentationMenuItem');
if ($children) {
return $children;
}
if (isset($_REQUEST['selfedit']) && $_REQUEST['selfedit'] == 'true') {
$selfedit = true;
} else {
$selfedit = false;
}
$composerService = new ComposerService($selfedit);
$packages = $composerService->getLocalPackages();
$tree = array();
// Let's fill the menu with the packages.
foreach ($packages as $package) {
$name = $package->getName();
if (strpos($name, '/') === false) {
continue;
}
list($vendorName, $packageName) = explode('/', $name);
$items = explode('.', $packageName);
array_unshift($items, $vendorName);
$node =& $tree;
foreach ($items as $str) {
if (!isset($node["children"][$str])) {
$node["children"][$str] = array();
}
$node =& $node["children"][$str];
}
$node['package'] = $package;
}
$this->walkMenuTree($tree, '', $this);
// Short lived cache (3 minutes).
$this->cache->set('documentationMenuItem', parent::getChildren(), 180);
return parent::getChildren();
} | php | private function getMenuTree() {
if ($this->computed) {
return parent::getChildren();
}
$this->computed = true;
$children = $this->cache->get('documentationMenuItem');
if ($children) {
return $children;
}
if (isset($_REQUEST['selfedit']) && $_REQUEST['selfedit'] == 'true') {
$selfedit = true;
} else {
$selfedit = false;
}
$composerService = new ComposerService($selfedit);
$packages = $composerService->getLocalPackages();
$tree = array();
// Let's fill the menu with the packages.
foreach ($packages as $package) {
$name = $package->getName();
if (strpos($name, '/') === false) {
continue;
}
list($vendorName, $packageName) = explode('/', $name);
$items = explode('.', $packageName);
array_unshift($items, $vendorName);
$node =& $tree;
foreach ($items as $str) {
if (!isset($node["children"][$str])) {
$node["children"][$str] = array();
}
$node =& $node["children"][$str];
}
$node['package'] = $package;
}
$this->walkMenuTree($tree, '', $this);
// Short lived cache (3 minutes).
$this->cache->set('documentationMenuItem', parent::getChildren(), 180);
return parent::getChildren();
} | [
"private",
"function",
"getMenuTree",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"computed",
")",
"{",
"return",
"parent",
"::",
"getChildren",
"(",
")",
";",
"}",
"$",
"this",
"->",
"computed",
"=",
"true",
";",
"$",
"children",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"'documentationMenuItem'",
")",
";",
"if",
"(",
"$",
"children",
")",
"{",
"return",
"$",
"children",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'selfedit'",
"]",
")",
"&&",
"$",
"_REQUEST",
"[",
"'selfedit'",
"]",
"==",
"'true'",
")",
"{",
"$",
"selfedit",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"selfedit",
"=",
"false",
";",
"}",
"$",
"composerService",
"=",
"new",
"ComposerService",
"(",
"$",
"selfedit",
")",
";",
"$",
"packages",
"=",
"$",
"composerService",
"->",
"getLocalPackages",
"(",
")",
";",
"$",
"tree",
"=",
"array",
"(",
")",
";",
"// Let's fill the menu with the packages.",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"$",
"name",
"=",
"$",
"package",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'/'",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"vendorName",
",",
"$",
"packageName",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"items",
"=",
"explode",
"(",
"'.'",
",",
"$",
"packageName",
")",
";",
"array_unshift",
"(",
"$",
"items",
",",
"$",
"vendorName",
")",
";",
"$",
"node",
"=",
"&",
"$",
"tree",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"node",
"[",
"\"children\"",
"]",
"[",
"$",
"str",
"]",
")",
")",
"{",
"$",
"node",
"[",
"\"children\"",
"]",
"[",
"$",
"str",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"node",
"=",
"&",
"$",
"node",
"[",
"\"children\"",
"]",
"[",
"$",
"str",
"]",
";",
"}",
"$",
"node",
"[",
"'package'",
"]",
"=",
"$",
"package",
";",
"}",
"$",
"this",
"->",
"walkMenuTree",
"(",
"$",
"tree",
",",
"''",
",",
"$",
"this",
")",
";",
"// Short lived cache (3 minutes).",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"'documentationMenuItem'",
",",
"parent",
"::",
"getChildren",
"(",
")",
",",
"180",
")",
";",
"return",
"parent",
"::",
"getChildren",
"(",
")",
";",
"}"
] | Adds the packages menu to the menu. | [
"Adds",
"the",
"packages",
"menu",
"to",
"the",
"menu",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src-dev/Mouf/Menu/DocumentationMenuItem.php#L51-L103 |
38,298 | thecodingmachine/mouf | src/Mouf/MoufManager.php | MoufManager.initMoufManager | public static function initMoufManager() {
if (self::$defaultInstance == null) {
self::$defaultInstance = new MoufManager();
self::$defaultInstance->configManager = new MoufConfigManager("../../../../../config.php");
self::$defaultInstance->componentsFileName = "../../../../../mouf/MoufComponents.php";
//self::$defaultInstance->requireFileName = "../MoufRequire.php";
self::$defaultInstance->adminUiFileName = "../../../../../mouf/MoufUI.php";
self::$defaultInstance->mainClassName = "Mouf";
// FIXME: not appscope for sure
self::$defaultInstance->scope = MoufManager::SCOPE_APP;
}
} | php | public static function initMoufManager() {
if (self::$defaultInstance == null) {
self::$defaultInstance = new MoufManager();
self::$defaultInstance->configManager = new MoufConfigManager("../../../../../config.php");
self::$defaultInstance->componentsFileName = "../../../../../mouf/MoufComponents.php";
//self::$defaultInstance->requireFileName = "../MoufRequire.php";
self::$defaultInstance->adminUiFileName = "../../../../../mouf/MoufUI.php";
self::$defaultInstance->mainClassName = "Mouf";
// FIXME: not appscope for sure
self::$defaultInstance->scope = MoufManager::SCOPE_APP;
}
} | [
"public",
"static",
"function",
"initMoufManager",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"defaultInstance",
"==",
"null",
")",
"{",
"self",
"::",
"$",
"defaultInstance",
"=",
"new",
"MoufManager",
"(",
")",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"configManager",
"=",
"new",
"MoufConfigManager",
"(",
"\"../../../../../config.php\"",
")",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"componentsFileName",
"=",
"\"../../../../../mouf/MoufComponents.php\"",
";",
"//self::$defaultInstance->requireFileName = \"../MoufRequire.php\";\r",
"self",
"::",
"$",
"defaultInstance",
"->",
"adminUiFileName",
"=",
"\"../../../../../mouf/MoufUI.php\"",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"mainClassName",
"=",
"\"Mouf\"",
";",
"// FIXME: not appscope for sure\r",
"self",
"::",
"$",
"defaultInstance",
"->",
"scope",
"=",
"MoufManager",
"::",
"SCOPE_APP",
";",
"}",
"}"
] | Instantiates the default instance of the MoufManager.
Does nothing if the default instance is already instanciated. | [
"Instantiates",
"the",
"default",
"instance",
"of",
"the",
"MoufManager",
".",
"Does",
"nothing",
"if",
"the",
"default",
"instance",
"is",
"already",
"instanciated",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/MoufManager.php#L84-L96 |
38,299 | thecodingmachine/mouf | src/Mouf/MoufManager.php | MoufManager.switchToHidden | public static function switchToHidden() {
self::$hiddenInstance = self::$defaultInstance;
self::$defaultInstance = new MoufManager();
self::$defaultInstance->configManager = new MoufConfigManager("../../config.php");
self::$defaultInstance->componentsFileName = "../../mouf/MoufComponents.php";
//self::$defaultInstance->requireFileName = "MoufAdminRequire.php";
self::$defaultInstance->adminUiFileName = "../../mouf/MoufUI.php";
self::$defaultInstance->mainClassName = "MoufAdmin";
self::$defaultInstance->scope = MoufManager::SCOPE_ADMIN;
} | php | public static function switchToHidden() {
self::$hiddenInstance = self::$defaultInstance;
self::$defaultInstance = new MoufManager();
self::$defaultInstance->configManager = new MoufConfigManager("../../config.php");
self::$defaultInstance->componentsFileName = "../../mouf/MoufComponents.php";
//self::$defaultInstance->requireFileName = "MoufAdminRequire.php";
self::$defaultInstance->adminUiFileName = "../../mouf/MoufUI.php";
self::$defaultInstance->mainClassName = "MoufAdmin";
self::$defaultInstance->scope = MoufManager::SCOPE_ADMIN;
} | [
"public",
"static",
"function",
"switchToHidden",
"(",
")",
"{",
"self",
"::",
"$",
"hiddenInstance",
"=",
"self",
"::",
"$",
"defaultInstance",
";",
"self",
"::",
"$",
"defaultInstance",
"=",
"new",
"MoufManager",
"(",
")",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"configManager",
"=",
"new",
"MoufConfigManager",
"(",
"\"../../config.php\"",
")",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"componentsFileName",
"=",
"\"../../mouf/MoufComponents.php\"",
";",
"//self::$defaultInstance->requireFileName = \"MoufAdminRequire.php\";\r",
"self",
"::",
"$",
"defaultInstance",
"->",
"adminUiFileName",
"=",
"\"../../mouf/MoufUI.php\"",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"mainClassName",
"=",
"\"MoufAdmin\"",
";",
"self",
"::",
"$",
"defaultInstance",
"->",
"scope",
"=",
"MoufManager",
"::",
"SCOPE_ADMIN",
";",
"}"
] | This function takes the whole configuration stored in the default instance of the Mouf framework
and switches it in the hidden instance.
The default instance is cleaned afterwards. | [
"This",
"function",
"takes",
"the",
"whole",
"configuration",
"stored",
"in",
"the",
"default",
"instance",
"of",
"the",
"Mouf",
"framework",
"and",
"switches",
"it",
"in",
"the",
"hidden",
"instance",
".",
"The",
"default",
"instance",
"is",
"cleaned",
"afterwards",
"."
] | b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b | https://github.com/thecodingmachine/mouf/blob/b6a11bfd4a93859c1014d5b3d54ee99314f5fc7b/src/Mouf/MoufManager.php#L104-L113 |
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.