本文整理汇总了PHP中DreamFactory\Library\Utility\ArrayUtils::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::set方法的具体用法?PHP ArrayUtils::set怎么用?PHP ArrayUtils::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DreamFactory\Library\Utility\ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refreshToken
/**
* @return string
* @throws \DreamFactory\Core\Exceptions\UnauthorizedException
*/
public static function refreshToken()
{
$token = Session::getSessionToken();
try {
$newToken = \JWTAuth::refresh($token);
$payload = \JWTAuth::getPayload($newToken);
$userId = $payload->get('user_id');
$user = User::find($userId);
$userInfo = $user->toArray();
ArrayUtils::set($userInfo, 'is_sys_admin', $user->is_sys_admin);
Session::setSessionToken($newToken);
Session::setUserInfo($userInfo);
static::setTokenMap($payload, $newToken);
} catch (TokenExpiredException $e) {
$payloadArray = \JWTAuth::manager()->getJWTProvider()->decode($token);
$forever = boolval(ArrayUtils::get($payloadArray, 'forever'));
if ($forever) {
$userId = ArrayUtils::get($payloadArray, 'user_id');
$user = User::find($userId);
Session::setUserInfoWithJWT($user, $forever);
} else {
throw new UnauthorizedException($e->getMessage());
}
}
return Session::getSessionToken();
}
示例2: __construct
public function __construct($settings = [])
{
$verbAliases = [Verbs::PUT => Verbs::POST, Verbs::MERGE => Verbs::POST, Verbs::PATCH => Verbs::POST];
ArrayUtils::set($settings, "verbAliases", $verbAliases);
parent::__construct($settings);
$this->model = \DreamFactory\Core\Models\Config::class;
}
示例3: __construct
/**
* @param array $settings
*/
public function __construct($settings = [])
{
$verbAliases = [Verbs::PUT => Verbs::PATCH, Verbs::MERGE => Verbs::PATCH];
ArrayUtils::set($settings, "verbAliases", $verbAliases);
parent::__construct($settings);
$this->model = ArrayUtils::get($settings, "model_name", $this->model);
// could be statically set
}
示例4: __construct
/**
* @param array $settings
*/
public function __construct($settings = [])
{
$verbAliases = [Verbs::PUT => Verbs::POST, Verbs::MERGE => Verbs::PATCH];
ArrayUtils::set($settings, "verbAliases", $verbAliases);
parent::__construct($settings);
$config = ArrayUtils::get($settings, 'config');
$this->defaultRole = ArrayUtils::get($config, 'default_role');
$this->setDriver($config);
}
示例5: __construct
/**
* @param array $settings
*/
public function __construct($settings = [])
{
$verbAliases = [Verbs::PUT => Verbs::POST, Verbs::MERGE => Verbs::PATCH];
ArrayUtils::set($settings, "verbAliases", $verbAliases);
parent::__construct($settings);
$config = ArrayUtils::get($settings, 'config');
$this->publicPaths = ArrayUtils::get($config, 'public_path', []);
$this->setDriver($config);
}
示例6: getRoleServiceAccess
/**
* @return array
*/
public function getRoleServiceAccess()
{
$this->load('role_service_access_by_role_id', 'service_by_role_service_access');
$rsa = $this->getRelation('role_service_access_by_role_id')->toArray();
$services = $this->getRelation('service_by_role_service_access')->toArray();
foreach ($rsa as $key => $s) {
$serviceName = ArrayUtils::findByKeyValue($services, 'id', ArrayUtils::get($s, 'service_id'), 'name');
ArrayUtils::set($rsa[$key], 'service', $serviceName);
}
return $rsa;
}
示例7: getSelectionCriteria
/**
* {@inheritdoc}
*/
protected function getSelectionCriteria()
{
$criteria = parent::getSelectionCriteria();
$condition = ArrayUtils::get($criteria, 'condition');
if (!empty($condition)) {
$condition .= " AND is_sys_admin = '0'";
} else {
$condition = " is_sys_admin = '0'";
}
ArrayUtils::set($criteria, 'condition', $condition);
return $criteria;
}
示例8: setUserInfoWithJWT
/**
* Sets basic info of the user in session with JWT when authenticated.
*
* @param array|User $user
* @param bool $forever
* @param integer $appId
*
* @return bool
*/
public static function setUserInfoWithJWT($user, $forever = false, $appId = null)
{
$userInfo = null;
if ($user instanceof User) {
$userInfo = $user->toArray();
ArrayUtils::set($userInfo, 'is_sys_admin', $user->is_sys_admin);
}
if (!empty($userInfo)) {
$id = ArrayUtils::get($userInfo, 'id');
$email = ArrayUtils::get($userInfo, 'email');
$token = JWTUtilities::makeJWTByUser($id, $email, $forever);
static::setSessionToken($token);
if (!empty($appId) && !$user->is_sys_admin) {
static::setSessionData($appId, $id);
return true;
} else {
return static::setUserInfo($userInfo);
}
}
return false;
}
示例9: 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());
}
}
示例10: getCachedInfo
/**
* Returns user info cached, or reads from db if not present.
* Pass in a key to return a portion/index of the cached data.
*
* @param int $id
* @param null|string $key
* @param null $default
*
* @return mixed|null
*/
public static function getCachedInfo($id, $key = null, $default = null)
{
$cacheKey = 'user:' . $id;
$result = \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () use($id) {
$user = static::with('user_lookup_by_user_id')->whereId($id)->first();
if (empty($user)) {
throw new NotFoundException("User not found.");
}
if (!$user->is_active) {
throw new ForbiddenException("User is not active.");
}
$userInfo = $user->toArray();
ArrayUtils::set($userInfo, 'is_sys_admin', $user->is_sys_admin);
return $userInfo;
});
if (is_null($result)) {
return $default;
}
if (is_null($key)) {
return $result;
}
return isset($result[$key]) ? $result[$key] : $default;
}
示例11: __construct
/**
* @param array $settings
*/
public function __construct($settings = [])
{
$verbAliases = [Verbs::PUT => Verbs::POST, Verbs::MERGE => Verbs::POST, Verbs::PATCH => Verbs::POST];
ArrayUtils::set($settings, "verbAliases", $verbAliases);
parent::__construct($settings);
}
示例12: loadScript
/**
* Look through the known paths for a particular script. Returns full path to script file.
*
* @param string $name The name/id of the script
* @param string $path The name of the script
* @param bool $returnContents If true, the contents of the file, if found, are returned. Otherwise, the only the
* path is returned
*
* @return string
*/
public static function loadScript($name, $path = null, $returnContents = true)
{
if ($path) {
// no longer support file paths for scripts?
}
// Already read, return script
if (null !== ($script = ArrayUtils::get(static::$libraries, $name))) {
return $returnContents ? file_get_contents($script) : $script;
}
$script = ltrim($script, ' /');
// Spin through paths and look for the script
foreach (static::$libraryPaths as $path) {
$check = $path . '/' . $script;
if (is_file($check) && is_readable($check)) {
ArrayUtils::set(static::$libraries, $name, $check);
return $returnContents ? file_get_contents($check) : $check;
}
}
return false;
}
示例13: setDriver
protected function setDriver($config)
{
$diskName = null;
if (empty($config) || !isset($config['container'])) {
$diskName = Config::get('filesystems.default');
} else {
$diskName = $config['container'];
}
if (empty($diskName)) {
throw new InternalServerErrorException('Local file service driver/disk not configured. Please check configuration for file service - ' . $this->name . '.');
}
$disks = Config::get('filesystems.disks');
if (!array_key_exists($diskName, $disks)) {
throw new InternalServerErrorException('Local file service disk - ' . $diskName . ' not found.Please check configuration for file service - ' . $this->name . '.');
}
$disk = ArrayUtils::get($disks, $diskName);
// Replace any private lookups
Session::replaceLookups($disk, true);
if (!isset($disk['driver'])) {
throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Driver not specified.');
}
switch ($disk['driver']) {
case 'local':
if (config('df.standalone')) {
$root = $disk['root'];
} else {
$root = Managed::getStoragePath(config('df.local_file_service_container'));
}
if (!is_dir($root)) {
mkdir($root, 0775);
}
if (empty($root)) {
throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not specified.');
}
if (!is_dir($root)) {
throw new InternalServerErrorException('Mis-configured disk - ' . $diskName . '. Root path not found.');
}
$this->driver = new LocalFileSystem($root);
break;
case 's3':
$this->container = ArrayUtils::get($disk, 'bucket', ArrayUtils::get($disk, 'container'));
ArrayUtils::set($disk, 'container', $this->container);
if (empty($this->container)) {
throw new InternalServerErrorException('S3 file service bucket/container not specified. Please check configuration for file service - ' . $this->name);
}
$this->driver = new S3FileSystem($disk);
break;
case 'rackspace':
$this->container = ArrayUtils::get($disk, 'container');
if (empty($this->container)) {
throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
}
$this->driver = new OpenStackObjectStorageSystem($disk);
break;
case 'azure':
$this->container = ArrayUtils::get($disk, 'container');
if (empty($this->container)) {
throw new InternalServerErrorException('Azure blob container not specified. Please check configuration for file service - ' . $this->name);
}
$this->driver = new AzureBlobFileSystem($disk);
break;
default:
break;
}
}
示例14: cleanCriteria
/**
* Removes 'config' from select criteria if supplied as it chokes the model.
*
* @param array $criteria
*
* @return array
*/
protected static function cleanCriteria(array $criteria)
{
$fields = ArrayUtils::get($criteria, 'select');
ArrayUtils::set($criteria, 'select', static::cleanFields($fields));
return $criteria;
}
示例15: fixRecords
/**
* Fixes supplied records to always set is_set_admin flag to true.
* Encrypts passwords if it is supplied.
*
* @param array $records
*
* @return array
*/
protected static function fixRecords(array $records)
{
if (ArrayUtils::isArrayNumeric($records)) {
foreach ($records as $key => $record) {
ArrayUtils::set($record, 'is_sys_admin', 1);
$records[$key] = $record;
}
} else {
ArrayUtils::set($records, 'is_sys_admin', 1);
}
return $records;
}