本文整理汇总了PHP中Entity::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::toArray方法的具体用法?PHP Entity::toArray怎么用?PHP Entity::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::toArray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: adaptCustomFields
/**
* Watches config for this entity's custom fields, if any key value pair matches
* a custom field name, it is extracted from the values and added to a new value with key
* 'custom_fields'
*
* @param \EntityPopulator\Entities\Entity $entity The Redmine entity being created
* treated.
*
* @return void
*/
public static function adaptCustomFields(Entity $entity)
{
$customFields = $entity->getCustomFieldsConfig();
$fields = $entity->toArray();
$usedCustomFields = array_intersect_key($fields, $customFields);
if (0 < count($usedCustomFields)) {
$apiReadyCustomFields = self::createCustomFields($entity, $usedCustomFields);
$nativeFields = array_diff_key($fields, $customFields);
$nativeFields += $apiReadyCustomFields;
$entity->fromArray($nativeFields);
}
}
示例2: makeSetterGetterDoc
/**
* Generate the setter and getter method PHPDoc declaration to paste into your entity class.
*
* @param Entity $entity
*/
public static function makeSetterGetterDoc(Entity $entity)
{
$properties = $entity->toArray(false);
$entityName = $entity->calledClassName();
echo "<pre>\n";
foreach ($properties as $name => $value) {
$methodName = ucfirst($name);
$type = $entity->typeof($name);
echo " * @method {$entityName} set{$methodName}({$type} \$value)\n";
echo " * @method {$type} get{$methodName}()\n";
}
echo "</pre>\n";
}
示例3: update
/**
* @param Entity $entity
* @return int Returns the number of rows affected by the query
*/
public function update(Entity $entity)
{
$vars = $entity->toArray();
unset($vars['id'], $vars['created_at']);
if (array_key_exists('updated_at', $vars)) {
$vars['updated_at'] = date('Y-m-d H:i:s');
$entity->addUpdated('updated_at');
}
$updatedColumns = $entity->getUpdated();
if (count($updatedColumns) <= 0) {
return false;
}
$entity->resetUpdated();
$columns = '';
$values = array();
foreach ($updatedColumns as $column) {
$columns .= '`' . $column . '` = ?,';
$values[] = $vars[$column];
}
$sql = 'UPDATE ' . $this->table . ' SET ' . rtrim($columns, ',') . ' WHERE id = ' . $entity->id;
$stmt = $this->execute($sql, $values);
return $stmt instanceof PDOStatement ? $stmt->rowCount() : false;
}
示例4: toArray
public function toArray()
{
$result = parent::toArray();
$result['content'] = Utility::DecodeAsSafeString($result['content']);
return $result;
}
示例5: decodeAnswer
/**
* Returns [$sector, $rank] (both strings) of the sector that an
* answer is about and the rank the respondent gave to it.
*
* @param array $answer Answer array
* @param Entity $survey The result of a call to SurveysTable::get()
* @return array [$sector, $rank]
*/
public function decodeAnswer($answer, $survey)
{
$answerIds = $survey->toArray();
$sectorId = $answer['row'];
$sector = str_replace('_aid', '', array_search($sectorId, $answerIds));
$rankId = $answer['col'];
$rank = str_replace('_aid', '', array_search($rankId, $answerIds));
return [$sector, $rank];
}
示例6: update
/**
* Update an existing user.
*
* @param \Stidges\LaravelDbNormalizer\Entity $user
* @return bool
*/
public function update(Entity $user)
{
$model = $this->model->newInstance($user->toArray(), true);
$model->id = $user->id;
return $user->getDirtyAttributes() ? $model->save() : $model->touch();
}
示例7: update
/**
* Update an existing user.
*
* @param \Stidges\LaravelDbNormalizer\Entity $user
* @return bool
*/
public function update(Entity $user)
{
$data = array_only($user->toArray(), $this->fillable);
return (bool) $this->db->table($this->table)->where('id', $user->id)->update($data);
}
示例8: toArray
public function toArray()
{
$attribute_values = parent::toArray();
$attribute_values[self::OBJECT_TYPE] = $this->getType()->getVariantPrefix();
return $attribute_values;
}