本文整理汇总了PHP中DreamFactory\Library\Utility\ArrayUtils::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::remove方法的具体用法?PHP ArrayUtils::remove怎么用?PHP ArrayUtils::remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DreamFactory\Library\Utility\ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateInternal
/**
* {@inheritdoc}
*/
public static function updateInternal($id, $record, $params = [])
{
if (empty($record)) {
throw new BadRequestException('There are no fields in the record to create . ');
}
if (empty($id)) {
//Todo:perform logging below
//Log::error( 'Update request with no id supplied: ' . print_r( $record, true ) );
throw new BadRequestException('Identifying field "id" can not be empty for update request . ');
}
/** @type User $model */
$model = static::find($id);
if (!$model instanceof Model) {
throw new NotFoundException('No resource found for ' . $id);
}
$pk = $model->primaryKey;
// Remove the PK from the record since this is an update
ArrayUtils::remove($record, $pk);
try {
if ($model->is_sys_admin && !ArrayUtils::getBool($params, 'admin')) {
throw new ForbiddenException('Not allowed to change an admin user.');
} elseif (ArrayUtils::getBool($params, 'admin') && !$model->is_sys_admin) {
throw new BadRequestException('Cannot update a non-admin user.');
}
$password = ArrayUtils::get($record, 'password');
if (!empty($password)) {
$model->password = $password;
}
$model->update($record);
return static::buildResult($model, $params);
} catch (\Exception $ex) {
if (!$ex instanceof ForbiddenException && !$ex instanceof BadRequestException) {
throw new InternalServerErrorException('Failed to update resource: ' . $ex->getMessage());
} else {
throw $ex;
}
}
}
示例2: updateInternal
/**
* @param $id
* @param $record
* @param array $params
*
* @return array
* @throws \DreamFactory\Core\Exceptions\BadRequestException
* @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
* @throws \DreamFactory\Core\Exceptions\NotFoundException
*/
public static function updateInternal($id, $record, $params = [])
{
if (empty($record)) {
throw new BadRequestException('There are no fields in the record to create . ');
}
if (empty($id)) {
//Todo:perform logging below
//Log::error( 'Update request with no id supplied: ' . print_r( $record, true ) );
throw new BadRequestException('Identifying field "id" can not be empty for update request . ');
}
$userId = SessionUtility::getCurrentUserId();
ArrayUtils::set($record, 'user_id', $userId);
//Making sure name is not changed during update as it not be unique.
ArrayUtils::set($record, 'name', $id);
$model = static::whereUserId($userId)->whereName($id)->first();
if (!$model instanceof Model) {
throw new NotFoundException('No resource found for ' . $id);
}
$pk = $model->primaryKey;
// Remove the PK from the record since this is an update
ArrayUtils::remove($record, $pk);
try {
$model->update($record);
return static::buildResult($model, $params);
} catch (\Exception $ex) {
throw new InternalServerErrorException('Failed to update resource: ' . $ex->getMessage());
}
}
示例3: updateInternal
/**
* @param $id
* @param $record
* @param array $params
*
* @return array
* @throws \DreamFactory\Core\Exceptions\BadRequestException
* @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
* @throws \DreamFactory\Core\Exceptions\NotFoundException
*/
public static function updateInternal($id, $record, $params = [])
{
if (empty($record)) {
throw new BadRequestException('There are no fields in the record to create . ');
}
if (empty($id)) {
//Todo:perform logging below
//Log::error( 'Update request with no id supplied: ' . print_r( $record, true ) );
throw new BadRequestException('Identifying field "id" can not be empty for update request . ');
}
$model = static::find($id);
if (!$model instanceof Model) {
throw new NotFoundException('No resource found for ' . $id);
}
$pk = $model->primaryKey;
// Remove the PK from the record since this is an update
ArrayUtils::remove($record, $pk);
try {
$model->update($record);
return static::buildResult($model, $params);
} catch (\Exception $ex) {
throw new InternalServerErrorException('Failed to update resource: ' . $ex->getMessage());
}
}