本文整理汇总了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');
}
示例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');
示例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;
}
示例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');