Helpers.php ➔ cdn_elixir()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Created by PhpStorm.
5
 * User: xuan
6
 * Date: 9/22/15
7
 * Time: 2:47 PM.
8
 */
9
10
/**
11
 * 获取每页数量.
12
 *
13
 * @param null $default
14
 *
15
 * @return string
16
 */
17
function per_page($default = null)
18
{
19
    $max_per_page = config('api.max_per_page');
20
    $per_page = (Input::get('per_page') ?: $default) ?: config('api.default_per_page');
21
22
    return (int) ($per_page < $max_per_page ? $per_page : $max_per_page);
23
};
24
25
/**
26
 * 使用 cdn 镜像获取本地资源的加速连接.
27
 *
28
 * @param $file_path
29
 *
30
 * @return string
31
 */
32
function cdn($file_path)
33
{
34
    $base_url = config('app.static_mirror_url') ?: config('app.url');
35
36
    return trim($base_url, '/').'/'.$file_path;
37
}
38
39
/**
40
 * 获取 elixir 的 CDN 连接.
41
 *
42
 * @param $file
43
 *
44
 * @return string
45
 */
46
function cdn_elixir($file)
47
{
48
    $cdn_url = config('app.static_mirror_url');
49
50
    return $cdn_url ? trim($cdn_url, '/').elixir($file) : elixir($file);
51
}
52
53
/**
54
 * 生成用户客户端 URL Schema 技术的链接.
55
 *
56
 * @param $path
57
 * @param $parameters
58
 *
59
 * @return string
60
 */
61
function schema_url($path, $parameters = [])
62
{
63
    $query = empty($parameters) ? '' : '?'.http_build_query($parameters);
64
65
    return strtolower(config('app.name')).'://'.trim($path, '/').$query;
66
}
67
68
/**
69
 * 拼装 Eloquent 事件名.
70
 *
71
 * @param $name
72
 * @param $event
73
 *
74
 * @return string
75
 */
76
function eloquent_event($name, $event)
77
{
78
    return "eloquent.{$event}: {$name}";
79
}
80
81
/**
82
 * 拼装类方法回调.
83
 *
84
 * @param $class_name
85
 * @param $method
86
 *
87
 * @return string
88
 */
89
function class_callback($class_name, $method)
90
{
91
    return "{$class_name}@{$method}";
92
}
93