本文整理汇总了PHP中object_get函数的典型用法代码示例。如果您正苦于以下问题:PHP object_get函数的具体用法?PHP object_get怎么用?PHP object_get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了object_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: composer
/**
* Format:
*
* n: name
* v: version
* l: location
* p: parent
*/
private function composer()
{
$path = app_path() . '\\..\\composer.lock';
if (!file_exists($path)) {
return;
}
// Parse composer.lock
$content = @file_get_contents($path);
$list = @json_decode($content);
if (!$list) {
return;
}
$list = object_get($list, 'packages', []);
// Determe the parent of the composer modules, most likely this will
// resolve to laravel/laravel.
$parent = '';
$parent_path = realpath(app_path() . '\\..\\composer.json');
if (file_exists($parent_path)) {
$parent_object = @json_decode(@file_get_contents($parent_path));
if ($parent_object) {
$parent = object_get($parent_object, 'name', '');
}
}
// Store base package, which is laravel/laravel.
$packages = [['n' => $parent, 'l' => $parent_path, 'v' => '']];
// Add each composer module to the packages list,
// but respect the parent relation.
foreach ($list as $package) {
$packages[] = ['n' => $package->name, 'v' => $package->version, 'p' => $parent, 'l' => $parent_path];
}
return $packages;
}
示例2: __invoke
/**
* На самом деле тут у меня фантация играет по полной, поймать мошеника это круто
* можно было реализовать из hidden risk некую битовую маску и по ней уже обсчитывать мошеников
* @param Collection $leaders
* @param []Collection $prevLeaders
* @return []Collection
*/
public function __invoke(Collection $leaders, array $prevLeaders)
{
$leaders->each(function ($value) use($prevLeaders) {
$id = object_get($value, 'id', null);
$score = object_get($value, 'score', null);
// Идем по списку лидеров
foreach ($prevLeaders as $leaders) {
$leaders->each(function ($leader) use($id, $score) {
// Если личдер найден
if ($leader->id === $id) {
// И он есть в hidden risk
if (isset($this->hidRisk[$id])) {
// Удаляем его
unset($this->hidRisk[$id]);
}
// Если сейчас у него очков больше чем в прошлый раз
if ($leader->score < $score / static::RISK_GROWTH_SCOPE) {
$this->result[$id] = $leader;
} else {
$this->hidRisk[$id] = $leader;
}
}
});
}
if (isset($this->hidRisk[$id])) {
$this->result[$id] = $value;
}
});
return $this->result;
}
示例3: responseHandler
/**
* @param ResponseInterface $responseInterface
* @return mixed
* @throws HttpResponseException
* @throws \HttpInvalidParamException
*/
protected function responseHandler(ResponseInterface $responseInterface)
{
// Проверяем код http, если не 200 или 201, то все нормально
if ($this->checkHttpResponse($responseInterface)) {
// Получаем тело запроса
$body = json_decode($responseInterface->getBody());
// Проверяем на json ошибки
if (json_last_error() !== JSON_ERROR_NONE) {
throw new HttpResponseException('Json invalid - ' . json_last_error_msg());
}
// Получем стус в ответе
if ($status = object_get($body, 'status', null)) {
if ($status === 'error') {
throw new HttpResponseException(object_get($body, 'message', null), object_get($body, 'code', 500));
}
}
$parameter = 'leaderboard';
if ($leaders = object_get($body, $parameter, null)) {
return $leaders;
} else {
throw new \HttpInvalidParamException('Parameter - ' . $parameter);
}
}
throw new HttpResponseException($responseInterface->getBody(), $responseInterface->getStatusCode());
}
示例4: get_parent_behavior
public function get_parent_behavior()
{
if (!$this->parent_behavior && $this->parent_obj) {
$this->parent_behavior = object_get($this->parent_obj, 'acts_as_' . self::$name);
}
return $this->parent_behavior;
}
示例5: __get
public function __get($key)
{
if ($this->isEloquent()) {
return $this->data->__get($key);
}
return object_get($this->data, $key);
}
示例6: visitor
/**
* @param null $key
* @param string $guard
*
* @var \Illuminate\Auth\Guard $auth
* @return \PortOneFive\Essentials\Users\User|false
*/
function visitor($key = null, $guard = null)
{
$auth = app('auth');
if (!$auth->guard($guard)->check()) {
return false;
}
return $key == null ? $auth->guard()->user() : object_get($auth->guard()->user(), $key);
}
示例7: getRawValueAttribute
/**
* Resolve value by uses as attribute as raw.
*
* @param \SimpleXMLElement $content
* @param string $use
* @param mixed $default
*
* @return mixed
*/
protected function getRawValueAttribute(SimpleXMLElement $content, $use, $default = null)
{
list($value, $attribute) = explode('::', $use, 2);
if (is_null($parent = object_get($content, $value))) {
return $default;
}
$attributes = $parent->attributes();
return Arr::get($attributes, $attribute, $default);
}
示例8: ping
/**
* Ping our cachet installation.
*
* @return bool True, if we get a response.
* @throws CachetException If the status code returned wasn't what we expected.
*/
public function ping()
{
$res = $this->client->get('ping');
if ($res->getStatusCode() !== 200) {
throw new CachetException('Invalid response code!');
}
$json = $this->json($res);
return object_get($json, 'data', '') == 'Pong!';
}
示例9: get
/**
* @param $key
* @param null $default
*
* @return mixed
*/
public function get($key, $default = null)
{
// Check for a Presenter Method first
if (method_exists($this, $key)) {
return $this->{$key}($default);
}
// Ok, now try to access the entities attribute
return object_get($this->entity, $key, $default);
}
示例10: smarty_function_admin_relations
function smarty_function_admin_relations($params = array(), &$smarty)
{
require_once $smarty->_get_plugin_filepath('function', 'admin_link');
$relations = array('parent' => 'edit ', 'children' => 'add/edit ');
$object = null;
$wrap = false;
$links = array();
$output = '';
foreach ($params as $_key => $_value) {
${$_key} = $_value;
}
if (empty($object)) {
$smarty->trigger_error("admin_relations: missing 'object' parameter", E_USER_NOTICE);
return;
}
// cycle relations
foreach ($relations as $relation_name => $relation_prefix) {
// cycle object's 'get_' variables
$i = 0;
foreach ($object->{'get_' . $relation_name} as $model_name => $model_params) {
AppModel::RelationNameParams($model_name, $model_params);
// get controller
$controller = Globe::Init($model_name, 'controller');
// TODO replace by ::singleton, find others
// action & text
switch ($relation_name) {
case 'parent':
$action = ($model = object_get($object, $model_name)) ? 'edit' . DS . $model->id : null;
$text = ucwords(AppInflector::titleize($model_name));
$image = 'page_white_edit';
break;
case 'children':
$prefix = $i == 0 ? '' : AppInflector::tableize(get_class($object)) . '_id=';
$action = '?filter=' . $prefix . $object->id;
$text = ucwords(AppInflector::pluralize(AppInflector::titleize($model_name)));
$image = 'magnifier';
break;
default:
$action = '';
$text = AppInflector::titleize($model_name);
$image = 'magnifier';
break;
}
// build link
$links[] = smarty_function_admin_link(array('controller' => AppInflector::fileize(get_class($controller), 'controller'), 'action' => $action, 'text' => "<span>{$relation_prefix}{$text}</span>" . ' <img src="/assets/images/admin/silk/' . $image . '.png" width="16" height="16">'), $smarty);
$i++;
}
}
foreach ($links as $link) {
$output .= "<li>{$link}</li>\n";
}
if ($wrap) {
$output = '<ul class="relations">' . $output . '</ul>';
}
return $output;
}
示例11: getTitleFields
/**
* Because a title slug can be created from multiple sources (such as an article title, a category title.etc.),
* this allows us to search out those fields from related objects and return the combined values.
*
* @param array $fields
* @return array
*/
public function getTitleFields(array $fields)
{
$fields = array_map(function ($field) {
if (str_contains($field, '.')) {
return object_get($this, $field);
// this acts as a delimiter, which we can replace with /
} else {
return $this->{$field};
}
}, $fields);
return $fields;
}
示例12: array_extract
function array_extract(&$array, $keys, $unset = false)
{
if (is_string($keys)) {
$keys = array($keys);
}
$output = array();
foreach ($keys as $key) {
$output[$key] = is_array($array) ? array_get($array, $key) : object_get($array, $key);
if ($unset) {
unset($array[$key]);
}
}
return $output;
}
示例13: replacePlaceholders
/**
* Replaces placeholders in title
* Matches all {{rule}} placeholders, escaped @{{ blocks (w/ optional }})
* Technically also matches "{{something"
*
* @param $title string Title with placeholders
* @param $replacedWith object Things to replace with
*
* @return mixed
*/
protected function replacePlaceholders($title, $replacedWith)
{
return preg_replace_callback('/(\\@)?\\{\\{([\\w\\d\\.]+)(?:\\}\\})/', function ($matches) use($replacedWith) {
if ($matches[1] == '@') {
// Escape
return substr($matches[0], 1);
}
// Find the requested thing
$value = object_get($replacedWith, $matches[2]);
if ($value) {
return $value;
}
// No idea
return $matches[0];
}, $title);
}
示例14: pluck
public static function pluck($array, $value, $key = null)
{
$results = [];
foreach ($array as $item) {
$itemValue = is_object($item) ? object_get($item, $value) : array_get($item, $value);
// If the key is "null", we will just append the value to the array and keep
// looping. Otherwise we will key the array using the value of the key we
// received from the developer. Then we'll return the final array form.
if (is_null($key)) {
$results[] = $itemValue;
} else {
$itemKey = is_object($item) ? object_get($item, $key) : array_get($item, $key);
$results[$itemKey] = $itemValue;
}
}
return $results;
}
示例15: __invoke
/**
* @param Collection $leaders
* @param []Collection $prevLeaders Массив ранее собраных списков
* @return array
*/
public function __invoke(Collection $leaders, array $prevLeaders)
{
$leaders->each(function ($value) use($prevLeaders) {
$id = object_get($value, 'id', null);
$place = object_get($value, 'place', null);
$this->result[$id] = 0;
foreach ($prevLeaders as $leaders) {
$leaders->each(function ($value) use($id, $place) {
if ($value->id === $id) {
if ($value->place !== $place) {
$this->result[$id]++;
}
}
});
}
});
return $this->result;
}