Вход Регистрация
Файл: gapps/vendor/laravel/framework/src/Illuminate/Foundation/Console/IlluminateCaster.php
Строк: 83
<?php

namespace IlluminateFoundationConsole;

use 
Exception;
use 
IlluminateSupportCollection;
use 
IlluminateFoundationApplication;
use 
IlluminateDatabaseEloquentModel;
use 
SymfonyComponentVarDumperCasterCaster;

class 
IlluminateCaster
{
    
/**
     * Illuminate application methods to include in the presenter.
     *
     * @var array
     */
    
private static $appProperties = [
        
'configurationIsCached',
        
'environment',
        
'environmentFile',
        
'isLocal',
        
'routesAreCached',
        
'runningUnitTests',
        
'version',
        
'path',
        
'basePath',
        
'configPath',
        
'databasePath',
        
'langPath',
        
'publicPath',
        
'storagePath',
        
'bootstrapPath',
    ];

    
/**
     * Get an array representing the properties of an application.
     *
     * @param  IlluminateFoundationApplication  $app
     * @return array
     */
    
public static function castApplication(Application $app)
    {
        
$results = [];

        foreach (
self::$appProperties as $property) {
            try {
                
$val $app->$property();

                if (! 
is_null($val)) {
                    
$results[Caster::PREFIX_VIRTUAL.$property] = $val;
                }
            } catch (
Exception $e) {
                
//
            
}
        }

        return 
$results;
    }

    
/**
     * Get an array representing the properties of a collection.
     *
     * @param  IlluminateSupportCollection  $collection
     * @return array
     */
    
public static function castCollection(Collection $collection)
    {
        return [
            
Caster::PREFIX_VIRTUAL.'all' => $collection->all(),
        ];
    }

    
/**
     * Get an array representing the properties of a model.
     *
     * @param  IlluminateDatabaseEloquentModel  $model
     * @return array
     */
    
public static function castModel(Model $model)
    {
        
$attributes array_merge(
            
$model->getAttributes(), $model->getRelations()
        );

        
$visible array_flip(
            
$model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden())
        );

        
$results = [];

        foreach (
array_intersect_key($attributes$visible) as $key => $value) {
            
$results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL Caster::PREFIX_PROTECTED).$key] = $value;
        }

        return 
$results;
    }
}
Онлайн: 1
Реклама