本文整理汇总了PHP中trait_uses_recursive函数的典型用法代码示例。如果您正苦于以下问题:PHP trait_uses_recursive函数的具体用法?PHP trait_uses_recursive怎么用?PHP trait_uses_recursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trait_uses_recursive函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootUpload
protected static function bootUpload()
{
static::updating(function (Model $model) {
foreach ($model->getUploadFields() as $key) {
$originalValue = array_get($model->original, $key);
if (!empty($originalValue) and $originalValue != $model->attributes[$key] and file_exists($filePath = public_path($originalValue))) {
unlink($filePath);
}
}
});
static::saving(function (Model $model) {
foreach ($model->getUploadFields() as $key) {
if ($model->{$key} instanceof UploadedFile) {
$model->attachFile($key, $model->{$key});
}
}
});
static::deleting(function (Model $model) {
if (in_array(\Illuminate\Database\Eloquent\SoftDeletes::class, trait_uses_recursive($model)) && !$model->forceDeleting) {
return;
}
foreach ($model->getUploadFields() as $key) {
$filePath = $model->{$key . '_path'};
if (!empty($filePath) and file_exists($filePath)) {
unlink($model->{$key . '_path'});
}
}
});
}
示例2: trait_uses_recursive
/**
* Returns all traits used by a trait and its traits.
*
* @param string $trait
* @return array
*/
function trait_uses_recursive($trait)
{
$traits = class_uses($trait);
foreach ($traits as $trait) {
$traits += trait_uses_recursive($trait);
}
return $traits;
}
示例3: class_uses_recursive
/**
* Returns all traits used by a class, it's subclasses and trait of their traits
*
* @param string $class
* @return array
*/
function class_uses_recursive($class)
{
$results = [];
foreach (array_merge([$class => $class], class_parents($class)) as $class) {
$results += trait_uses_recursive($class);
}
return array_unique($results);
}