当前位置: 首页>>代码示例>>PHP>>正文


PHP Type::getInstance方法代码示例

本文整理汇总了PHP中Type::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getInstance方法的具体用法?PHP Type::getInstance怎么用?PHP Type::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type::getInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // Using factory
     // Getting an instance of a model User example
     $user = ModelFactory::getInstance('User');
     // Getting an instance of a Library String
     $stringLib = LibraryFactory::getInstance('String');
     // Getting an instance of a Filter DateRange
     $dateRange = FilterFactory::getInstance('DateRange');
     // Getting an instance of a Type User
     $userType = TypeFactory::getInstance('User');
     // Perform an access check
     AccessCheckFactory::getInstance('User')->canAccess(auth()->user()->id, 'view');
     // Using facade
     // Getting an instance of a model User example
     $user = \Model::getInstance('User');
     // Getting an instance of a Library String
     $stringLib = \Library::getInstance('String');
     // Getting an instance of a Filter DateRange
     $dateRange = \Filter::getInstance('DateRange');
     // Getting an instance of a Type User
     $userType = \Type::getInstance('User');
     // Passing data to view example
     $this->view->fullname = auth()->user()->fullname;
     // Perform an access check
     \AccessCheck::getInstance('User')->canAccess(1, 'view');
     return $this->view('dashboard');
 }
开发者ID:atudz,项目名称:gorabelframework,代码行数:33,代码来源:MainPresenter.php

示例2: normalizeAttribute

     * 格式化并补全属性定义数组
     *
     * @param array $attribute
     * @return array
     */
    public static function normalizeAttribute(array $attribute)
    {
        $defaults = ['allow_null' => false, 'allow_tags' => false, 'auto_generate' => false, 'default' => null, 'deprecated' => false, 'pattern' => null, 'primary_key' => false, 'protected' => false, 'refuse_update' => false, 'strict' => null, 'type' => null];
        $type = isset($attribute['type']) ? $attribute['type'] : null;
        $attribute = array_merge($defaults, self::factory($type)->normalizeAttribute($attribute));
        if ($attribute['allow_null']) {
            $attribute['default'] = null;
        }
        if ($attribute['primary_key']) {
            $attribute['allow_null'] = false;
            $attribute['refuse_update'] = true;
            $attribute['strict'] = true;
        }
        if ($attribute['protected'] && $attribute['strict'] === null) {
            $attribute['strict'] = true;
        }
        return $attribute;
    }
    private static $instance;
    public static function getInstance()
    {
        return self::$instance ?: (self::$instance = new self());
    }
}
Type::getInstance()->register('common', '\\Owl\\DataMapper\\Type\\Common')->register('datetime', '\\Owl\\DataMapper\\Type\\Datetime')->register('integer', '\\Owl\\DataMapper\\Type\\Integer')->register('json', '\\Owl\\DataMapper\\Type\\Json')->register('number', '\\Owl\\DataMapper\\Type\\Number')->register('pg_array', '\\Owl\\DataMapper\\Type\\PgsqlArray')->register('pg_hstore', '\\Owl\\DataMapper\\Type\\PgsqlHstore')->register('string', '\\Owl\\DataMapper\\Type\\Text')->register('uuid', '\\Owl\\DataMapper\\Type\\UUID')->register('complex', '\\Owl\\DataMapper\\Type\\Complex');
开发者ID:tempbottle,项目名称:owl,代码行数:30,代码来源:Type.php

示例3: pack

 /**
  * 把存储服务内获取的数据,打包成Data实例.
  *
  * @param array $record
  * @param Data [$data]
  *
  * @return Data
  */
 public function pack(array $record, Data $data = null)
 {
     $types = Type::getInstance();
     $values = [];
     $attributes = $this->getAttributes();
     foreach ($record as $key => $value) {
         if (!isset($attributes[$key])) {
             continue;
         }
         $attribute = $attributes[$key];
         $values[$key] = $types->get($attribute['type'])->restore($value, $attribute);
     }
     if ($data) {
         $data->__pack($values, false);
     } else {
         $class = $this->class;
         $data = new $class(null, ['fresh' => false]);
         $data->__pack($values, true);
     }
     return $data;
 }
开发者ID:yeaha,项目名称:owl-orm,代码行数:29,代码来源:Mapper.php

示例4: normalizeAttribute

     * 格式化并补全属性定义数组
     *
     * @param array $attribute
     * @return array
     */
    public static function normalizeAttribute(array $attribute)
    {
        $defaults = ['allow_null' => false, 'auto_generate' => false, 'default' => null, 'deprecated' => false, 'pattern' => null, 'primary_key' => false, 'protected' => false, 'refuse_update' => false, 'strict' => null, 'type' => null];
        $type = isset($attribute['type']) ? $attribute['type'] : null;
        $attribute = array_merge($defaults, self::factory($type)->normalizeAttribute($attribute));
        if ($attribute['allow_null']) {
            $attribute['default'] = null;
        }
        if ($attribute['primary_key']) {
            $attribute['allow_null'] = false;
            $attribute['refuse_update'] = true;
            $attribute['strict'] = true;
        }
        if ($attribute['protected'] && $attribute['strict'] === null) {
            $attribute['strict'] = true;
        }
        return $attribute;
    }
    private static $instance;
    public static function getInstance()
    {
        return self::$instance ?: (self::$instance = new self());
    }
}
Type::getInstance()->register('mixed', '\\Owl\\DataMapper\\Type\\Mixed')->register('datetime', '\\Owl\\DataMapper\\Type\\Datetime')->register('integer', '\\Owl\\DataMapper\\Type\\Integer')->register('json', '\\Owl\\DataMapper\\Type\\Json')->register('numeric', '\\Owl\\DataMapper\\Type\\Numeric')->register('pg_array', '\\Owl\\DataMapper\\Type\\PgsqlArray')->register('pg_hstore', '\\Owl\\DataMapper\\Type\\PgsqlHstore')->register('string', '\\Owl\\DataMapper\\Type\\String')->register('uuid', '\\Owl\\DataMapper\\Type\\UUID');
开发者ID:niceDreamer,项目名称:owl,代码行数:30,代码来源:Type.php


注:本文中的Type::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。