@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | class Cache { |
14 | - use Module; |
|
14 | + use Module; |
|
15 | 15 | |
16 | - protected static $driver = null; |
|
17 | - protected static $enabled = true; |
|
16 | + protected static $driver = null; |
|
17 | + protected static $enabled = true; |
|
18 | 18 | |
19 | 19 | public static function get($key,$default='',$expire=0){ |
20 | 20 | if (static::$enabled){ |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | } |
72 | - return false; |
|
72 | + return false; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | protected static $driver = null; |
17 | 17 | protected static $enabled = true; |
18 | 18 | |
19 | - public static function get($key,$default='',$expire=0){ |
|
20 | - if (static::$enabled){ |
|
19 | + public static function get($key, $default = '', $expire = 0) { |
|
20 | + if (static::$enabled) { |
|
21 | 21 | $hash = static::hash($key); |
22 | - if(static::$driver->exists($hash) && $results = static::$driver->get($hash)){ |
|
22 | + if (static::$driver->exists($hash) && $results = static::$driver->get($hash)) { |
|
23 | 23 | return $results; |
24 | 24 | } else { |
25 | - if($data = is_callable($default)?call_user_func($default):$default){ |
|
26 | - static::$driver->set($hash,$data,$expire); |
|
25 | + if ($data = is_callable($default) ? call_user_func($default) : $default) { |
|
26 | + static::$driver->set($hash, $data, $expire); |
|
27 | 27 | } |
28 | 28 | return $data; |
29 | 29 | } |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | * ]); |
55 | 55 | * |
56 | 56 | */ |
57 | - public static function using($driver){ |
|
58 | - foreach((array)$driver as $key => $value){ |
|
59 | - if(is_numeric($key)){ |
|
57 | + public static function using($driver) { |
|
58 | + foreach ((array) $driver as $key => $value) { |
|
59 | + if (is_numeric($key)) { |
|
60 | 60 | $drv = $value; |
61 | 61 | $conf = []; |
62 | 62 | } else { |
63 | 63 | $drv = $key; |
64 | 64 | $conf = $value; |
65 | 65 | } |
66 | - $class = 'Cache\\' . ucfirst(strtolower($drv)); |
|
67 | - if(class_exists($class) && $class::valid()) { |
|
66 | + $class = 'Cache\\'.ucfirst(strtolower($drv)); |
|
67 | + if (class_exists($class) && $class::valid()) { |
|
68 | 68 | static::$driver = new $class($conf); |
69 | 69 | return true; |
70 | 70 | } |
@@ -81,45 +81,45 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return boolean Cache on/off status |
83 | 83 | */ |
84 | - public static function enabled($enabled=null){ |
|
84 | + public static function enabled($enabled = null) { |
|
85 | 85 | return $enabled ? static::$enabled : static::$enabled = $enabled; |
86 | 86 | } |
87 | 87 | |
88 | 88 | |
89 | - public static function set($key,$value,$expire=0){ |
|
90 | - return static::$driver->set(static::hash($key),$value,$expire); |
|
89 | + public static function set($key, $value, $expire = 0) { |
|
90 | + return static::$driver->set(static::hash($key), $value, $expire); |
|
91 | 91 | } |
92 | 92 | |
93 | - public static function delete($key){ |
|
93 | + public static function delete($key) { |
|
94 | 94 | return static::$driver->delete(static::hash($key)); |
95 | 95 | } |
96 | 96 | |
97 | - public static function exists($key){ |
|
97 | + public static function exists($key) { |
|
98 | 98 | return static::$enabled && static::$driver->exists(static::hash($key)); |
99 | 99 | } |
100 | 100 | |
101 | - public static function flush(){ |
|
101 | + public static function flush() { |
|
102 | 102 | return static::$driver->flush(); |
103 | 103 | } |
104 | 104 | |
105 | - public static function inc($key,$value=1){ |
|
106 | - return static::$driver->inc(static::hash($key),$value); |
|
105 | + public static function inc($key, $value = 1) { |
|
106 | + return static::$driver->inc(static::hash($key), $value); |
|
107 | 107 | } |
108 | 108 | |
109 | - public static function dec($key,$value=1){ |
|
110 | - return static::$driver->dec(static::hash($key),$value); |
|
109 | + public static function dec($key, $value = 1) { |
|
110 | + return static::$driver->dec(static::hash($key), $value); |
|
111 | 111 | } |
112 | 112 | |
113 | - public static function hash($key,$group=null){ |
|
113 | + public static function hash($key, $group = null) { |
|
114 | 114 | static $hashes = []; |
115 | - if (false === isset($hashes[$group][$key])){ |
|
115 | + if (false === isset($hashes[$group][$key])) { |
|
116 | 116 | $k = $key; |
117 | - if(is_array($key) && count($key)>1) list($group,$key) = $k; |
|
118 | - $hashes[$group][$key] = ($group?$group.'-':'') . md5($key); |
|
117 | + if (is_array($key) && count($key) > 1) list($group, $key) = $k; |
|
118 | + $hashes[$group][$key] = ($group ? $group.'-' : '').md5($key); |
|
119 | 119 | } |
120 | 120 | return $hashes[$group][$key]; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | |
125 | -Cache::using(['files','memory']); |
|
125 | +Cache::using(['files', 'memory']); |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | protected static $driver = null; |
17 | 17 | protected static $enabled = true; |
18 | 18 | |
19 | - public static function get($key,$default='',$expire=0){ |
|
20 | - if (static::$enabled){ |
|
19 | + public static function get($key,$default='',$expire=0) { |
|
20 | + if (static::$enabled) { |
|
21 | 21 | $hash = static::hash($key); |
22 | - if(static::$driver->exists($hash) && $results = static::$driver->get($hash)){ |
|
22 | + if(static::$driver->exists($hash) && $results = static::$driver->get($hash)) { |
|
23 | 23 | return $results; |
24 | 24 | } else { |
25 | - if($data = is_callable($default)?call_user_func($default):$default){ |
|
25 | + if($data = is_callable($default)?call_user_func($default):$default) { |
|
26 | 26 | static::$driver->set($hash,$data,$expire); |
27 | 27 | } |
28 | 28 | return $data; |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * ]); |
55 | 55 | * |
56 | 56 | */ |
57 | - public static function using($driver){ |
|
58 | - foreach((array)$driver as $key => $value){ |
|
59 | - if(is_numeric($key)){ |
|
57 | + public static function using($driver) { |
|
58 | + foreach((array)$driver as $key => $value) { |
|
59 | + if(is_numeric($key)) { |
|
60 | 60 | $drv = $value; |
61 | 61 | $conf = []; |
62 | 62 | } else { |
@@ -81,40 +81,42 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return boolean Cache on/off status |
83 | 83 | */ |
84 | - public static function enabled($enabled=null){ |
|
84 | + public static function enabled($enabled=null) { |
|
85 | 85 | return $enabled ? static::$enabled : static::$enabled = $enabled; |
86 | 86 | } |
87 | 87 | |
88 | 88 | |
89 | - public static function set($key,$value,$expire=0){ |
|
89 | + public static function set($key,$value,$expire=0) { |
|
90 | 90 | return static::$driver->set(static::hash($key),$value,$expire); |
91 | 91 | } |
92 | 92 | |
93 | - public static function delete($key){ |
|
93 | + public static function delete($key) { |
|
94 | 94 | return static::$driver->delete(static::hash($key)); |
95 | 95 | } |
96 | 96 | |
97 | - public static function exists($key){ |
|
97 | + public static function exists($key) { |
|
98 | 98 | return static::$enabled && static::$driver->exists(static::hash($key)); |
99 | 99 | } |
100 | 100 | |
101 | - public static function flush(){ |
|
101 | + public static function flush() { |
|
102 | 102 | return static::$driver->flush(); |
103 | 103 | } |
104 | 104 | |
105 | - public static function inc($key,$value=1){ |
|
105 | + public static function inc($key,$value=1) { |
|
106 | 106 | return static::$driver->inc(static::hash($key),$value); |
107 | 107 | } |
108 | 108 | |
109 | - public static function dec($key,$value=1){ |
|
109 | + public static function dec($key,$value=1) { |
|
110 | 110 | return static::$driver->dec(static::hash($key),$value); |
111 | 111 | } |
112 | 112 | |
113 | - public static function hash($key,$group=null){ |
|
113 | + public static function hash($key,$group=null) { |
|
114 | 114 | static $hashes = []; |
115 | - if (false === isset($hashes[$group][$key])){ |
|
115 | + if (false === isset($hashes[$group][$key])) { |
|
116 | 116 | $k = $key; |
117 | - if(is_array($key) && count($key)>1) list($group,$key) = $k; |
|
117 | + if(is_array($key) && count($key)>1) { |
|
118 | + list($group,$key) = $k; |
|
119 | + } |
|
118 | 120 | $hashes[$group][$key] = ($group?$group.'-':'') . md5($key); |
119 | 121 | } |
120 | 122 | return $hashes[$group][$key]; |
@@ -13,20 +13,20 @@ |
||
13 | 13 | class Loader { |
14 | 14 | protected static $paths = []; |
15 | 15 | |
16 | - public static function addPath($path,$name=null){ |
|
16 | + public static function addPath($path, $name = null) { |
|
17 | 17 | static::$paths[$path] = $name; |
18 | 18 | } |
19 | 19 | |
20 | - public static function register(){ |
|
20 | + public static function register() { |
|
21 | 21 | ini_set('unserialize_callback_func', 'spl_autoload_call'); |
22 | - spl_autoload_register(function($class){ |
|
23 | - $cfile = strtr($class,'_\\','//') . '.php'; |
|
22 | + spl_autoload_register(function($class) { |
|
23 | + $cfile = strtr($class, '_\\', '//').'.php'; |
|
24 | 24 | foreach (static::$paths as $path => $v) { |
25 | - $file = rtrim($path,'/').'/'.$cfile; |
|
26 | - if(is_file($file)) return include($file); |
|
25 | + $file = rtrim($path, '/').'/'.$cfile; |
|
26 | + if (is_file($file)) return include($file); |
|
27 | 27 | } |
28 | 28 | return false; |
29 | - },false,true); |
|
29 | + },false, true); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -13,17 +13,19 @@ |
||
13 | 13 | class Loader { |
14 | 14 | protected static $paths = []; |
15 | 15 | |
16 | - public static function addPath($path,$name=null){ |
|
16 | + public static function addPath($path,$name=null) { |
|
17 | 17 | static::$paths[$path] = $name; |
18 | 18 | } |
19 | 19 | |
20 | - public static function register(){ |
|
20 | + public static function register() { |
|
21 | 21 | ini_set('unserialize_callback_func', 'spl_autoload_call'); |
22 | - spl_autoload_register(function($class){ |
|
22 | + spl_autoload_register(function($class) { |
|
23 | 23 | $cfile = strtr($class,'_\\','//') . '.php'; |
24 | 24 | foreach (static::$paths as $path => $v) { |
25 | 25 | $file = rtrim($path,'/').'/'.$cfile; |
26 | - if(is_file($file)) return include($file); |
|
26 | + if(is_file($file)) { |
|
27 | + return include($file); |
|
28 | + } |
|
27 | 29 | } |
28 | 30 | return false; |
29 | 31 | },false,true); |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | public static function all($page=1,$limit=-1){ |
32 | - $offset = max(1,$page)-1; |
|
32 | + $offset = max(1,$page)-1; |
|
33 | 33 | return static::where($limit < 1 ? "" : "1 limit $limit offset $offset"); |
34 | 34 | } |
35 | 35 | |
36 | 36 | public function primaryKey(){ |
37 | - $self = get_called_class(); |
|
37 | + $self = get_called_class(); |
|
38 | 38 | $key = $self::persistenceOptions('key'); |
39 | 39 | return $this->$key; |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public static function create(array $data){ |
43 | 43 | $tmp = new static; |
44 | 44 | foreach ($data as $key => $value) { |
45 | - $tmp->$key = $value; |
|
45 | + $tmp->$key = $value; |
|
46 | 46 | } |
47 | 47 | $tmp->save(); |
48 | 48 | return $tmp; |
@@ -13,33 +13,33 @@ |
||
13 | 13 | abstract class Model { |
14 | 14 | use Module, Persistence; |
15 | 15 | |
16 | - public static function where($where_sql = false){ |
|
16 | + public static function where($where_sql = false) { |
|
17 | 17 | // Forward persistence calls to caller class, not Model |
18 | 18 | $self = get_called_class(); |
19 | 19 | $table = $self::persistenceOptions('table'); |
20 | 20 | $key = $self::persistenceOptions('key'); |
21 | 21 | |
22 | - $sql = "select $key from $table" . ($where_sql ? " where $where_sql" : ''); |
|
22 | + $sql = "select $key from $table".($where_sql ? " where $where_sql" : ''); |
|
23 | 23 | |
24 | 24 | $results = []; |
25 | - SQL::each($sql, function($row) use ($self,&$results,$key){ |
|
25 | + SQL::each($sql, function($row) use ($self, &$results, $key){ |
|
26 | 26 | $results[] = $self::load($row->$key); |
27 | 27 | }); |
28 | 28 | return $results; |
29 | 29 | } |
30 | 30 | |
31 | - public static function all($page=1,$limit=-1){ |
|
32 | - $offset = max(1,$page)-1; |
|
31 | + public static function all($page = 1, $limit = -1) { |
|
32 | + $offset = max(1, $page) - 1; |
|
33 | 33 | return static::where($limit < 1 ? "" : "1 limit $limit offset $offset"); |
34 | 34 | } |
35 | 35 | |
36 | - public function primaryKey(){ |
|
37 | - $self = get_called_class(); |
|
38 | - $key = $self::persistenceOptions('key'); |
|
36 | + public function primaryKey() { |
|
37 | + $self = get_called_class(); |
|
38 | + $key = $self::persistenceOptions('key'); |
|
39 | 39 | return $this->$key; |
40 | 40 | } |
41 | 41 | |
42 | - public static function create(array $data){ |
|
42 | + public static function create(array $data) { |
|
43 | 43 | $tmp = new static; |
44 | 44 | foreach ($data as $key => $value) { |
45 | 45 | $tmp->$key = $value; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | abstract class Model { |
14 | 14 | use Module, Persistence; |
15 | 15 | |
16 | - public static function where($where_sql = false){ |
|
16 | + public static function where($where_sql = false) { |
|
17 | 17 | // Forward persistence calls to caller class, not Model |
18 | 18 | $self = get_called_class(); |
19 | 19 | $table = $self::persistenceOptions('table'); |
@@ -22,24 +22,24 @@ discard block |
||
22 | 22 | $sql = "select $key from $table" . ($where_sql ? " where $where_sql" : ''); |
23 | 23 | |
24 | 24 | $results = []; |
25 | - SQL::each($sql, function($row) use ($self,&$results,$key){ |
|
25 | + SQL::each($sql, function($row) use ($self,&$results,$key) { |
|
26 | 26 | $results[] = $self::load($row->$key); |
27 | 27 | }); |
28 | 28 | return $results; |
29 | 29 | } |
30 | 30 | |
31 | - public static function all($page=1,$limit=-1){ |
|
31 | + public static function all($page=1,$limit=-1) { |
|
32 | 32 | $offset = max(1,$page)-1; |
33 | 33 | return static::where($limit < 1 ? "" : "1 limit $limit offset $offset"); |
34 | 34 | } |
35 | 35 | |
36 | - public function primaryKey(){ |
|
36 | + public function primaryKey() { |
|
37 | 37 | $self = get_called_class(); |
38 | 38 | $key = $self::persistenceOptions('key'); |
39 | 39 | return $this->$key; |
40 | 40 | } |
41 | 41 | |
42 | - public static function create(array $data){ |
|
42 | + public static function create(array $data) { |
|
43 | 43 | $tmp = new static; |
44 | 44 | foreach ($data as $key => $value) { |
45 | 45 | $tmp->$key = $value; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $options = (object)$options; |
19 | 19 | $region = isset($options->region) ? $options->region : 'eu-west-1'; |
20 | 20 | if (empty($options->username) || empty($options->password)) |
21 | - throw new \Exception("[core.email.ses] You must provide an Amazon SES SMTP username and password", 1); |
|
21 | + throw new \Exception("[core.email.ses] You must provide an Amazon SES SMTP username and password", 1); |
|
22 | 22 | |
23 | 23 | Smtp::onInit([ |
24 | 24 | 'host' => "email-smtp.{$region}.amazonaws.com", |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public function onSend(Envelope $envelope){ |
34 | 34 | if (!$envelope->from()) |
35 | - throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1); |
|
35 | + throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1); |
|
36 | 36 | return Smtp::onSend($envelope); |
37 | 37 | } |
38 | 38 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | class Ses extends Smtp { |
16 | 16 | |
17 | 17 | public function onInit($options) { |
18 | - $options = (object)$options; |
|
18 | + $options = (object) $options; |
|
19 | 19 | $region = isset($options->region) ? $options->region : 'eu-west-1'; |
20 | 20 | if (empty($options->username) || empty($options->password)) |
21 | 21 | throw new \Exception("[core.email.ses] You must provide an Amazon SES SMTP username and password", 1); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | } |
32 | 32 | |
33 | - public function onSend(Envelope $envelope){ |
|
33 | + public function onSend(Envelope $envelope) { |
|
34 | 34 | if (!$envelope->from()) |
35 | 35 | throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1); |
36 | 36 | return Smtp::onSend($envelope); |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | public function onInit($options) { |
18 | 18 | $options = (object)$options; |
19 | 19 | $region = isset($options->region) ? $options->region : 'eu-west-1'; |
20 | - if (empty($options->username) || empty($options->password)) |
|
21 | - throw new \Exception("[core.email.ses] You must provide an Amazon SES SMTP username and password", 1); |
|
20 | + if (empty($options->username) || empty($options->password)) { |
|
21 | + throw new \Exception("[core.email.ses] You must provide an Amazon SES SMTP username and password", 1); |
|
22 | + } |
|
22 | 23 | |
23 | 24 | Smtp::onInit([ |
24 | 25 | 'host' => "email-smtp.{$region}.amazonaws.com", |
@@ -30,9 +31,10 @@ discard block |
||
30 | 31 | |
31 | 32 | } |
32 | 33 | |
33 | - public function onSend(Envelope $envelope){ |
|
34 | - if (!$envelope->from()) |
|
35 | - throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1); |
|
34 | + public function onSend(Envelope $envelope) { |
|
35 | + if (!$envelope->from()) { |
|
36 | + throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1); |
|
37 | + } |
|
36 | 38 | return Smtp::onSend($envelope); |
37 | 39 | } |
38 | 40 |
@@ -16,12 +16,12 @@ |
||
16 | 16 | |
17 | 17 | protected $listener = 'core.email.proxy.send'; |
18 | 18 | |
19 | - public function onInit($options){ |
|
19 | + public function onInit($options) { |
|
20 | 20 | if (!empty($options['hook'])) $this->listener = $options['hook']; |
21 | 21 | } |
22 | 22 | |
23 | - public function onSend(Envelope $envelope){ |
|
24 | - \Event::trigger('core.email.send',$envelope->to(),$envelope,'proxy'); |
|
23 | + public function onSend(Envelope $envelope) { |
|
24 | + \Event::trigger('core.email.send', $envelope->to(), $envelope, 'proxy'); |
|
25 | 25 | \Event::trigger($this->listener, $envelope); |
26 | 26 | return true; |
27 | 27 | } |
@@ -16,11 +16,13 @@ |
||
16 | 16 | |
17 | 17 | protected $listener = 'core.email.proxy.send'; |
18 | 18 | |
19 | - public function onInit($options){ |
|
20 | - if (!empty($options['hook'])) $this->listener = $options['hook']; |
|
19 | + public function onInit($options) { |
|
20 | + if (!empty($options['hook'])) { |
|
21 | + $this->listener = $options['hook']; |
|
22 | + } |
|
21 | 23 | } |
22 | 24 | |
23 | - public function onSend(Envelope $envelope){ |
|
25 | + public function onSend(Envelope $envelope) { |
|
24 | 26 | \Event::trigger('core.email.send',$envelope->to(),$envelope,'proxy'); |
25 | 27 | \Event::trigger($this->listener, $envelope); |
26 | 28 | return true; |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | |
15 | 15 | class Native implements Driver { |
16 | 16 | |
17 | - public function onInit($options){} |
|
17 | + public function onInit($options) {} |
|
18 | 18 | |
19 | - public function onSend(Envelope $envelope){ |
|
19 | + public function onSend(Envelope $envelope) { |
|
20 | 20 | // PHP requires direct handling of To and Subject Headers. |
21 | 21 | $success = true; |
22 | 22 | $recipients = $envelope->to(); |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | $envelope->to(false); |
25 | 25 | $envelope->subject(false); |
26 | 26 | foreach ($recipients as $to) { |
27 | - $current_success = mail($to,$subject,$envelope->body(),$envelope->head()); |
|
28 | - \Event::trigger('core.email.send',$to,$envelope,'native'); |
|
27 | + $current_success = mail($to, $subject, $envelope->body(), $envelope->head()); |
|
28 | + \Event::trigger('core.email.send', $to, $envelope, 'native'); |
|
29 | 29 | $success = $success && $current_success; |
30 | 30 | } |
31 | 31 | return $success; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | public function onInit($options){} |
18 | 18 | |
19 | - public function onSend(Envelope $envelope){ |
|
19 | + public function onSend(Envelope $envelope) { |
|
20 | 20 | // PHP requires direct handling of To and Subject Headers. |
21 | 21 | $success = true; |
22 | 22 | $recipients = $envelope->to(); |
@@ -25,36 +25,36 @@ discard block |
||
25 | 25 | $password; |
26 | 26 | |
27 | 27 | public function onInit($options) { |
28 | - $options = (object)$options; |
|
29 | - $this->host = isset($options->host) ? $options->host : 'localhost'; |
|
28 | + $options = (object) $options; |
|
29 | + $this->host = isset($options->host) ? $options->host : 'localhost'; |
|
30 | 30 | $this->username = isset($options->username) ? $options->username : false; |
31 | - $this->secure = isset($options->secure) ? $options->secure : ($this->username ? true : false); |
|
32 | - $this->port = isset($options->port) ? $options->port : ($this->secure ? 465 : 25); |
|
31 | + $this->secure = isset($options->secure) ? $options->secure : ($this->username ? true : false); |
|
32 | + $this->port = isset($options->port) ? $options->port : ($this->secure ? 465 : 25); |
|
33 | 33 | $this->password = isset($options->password) ? $options->password : false; |
34 | 34 | } |
35 | 35 | |
36 | - protected function connect(){ |
|
36 | + protected function connect() { |
|
37 | 37 | if ($this->socket) $this->close(); |
38 | - $url = ($this->secure ? 'tls' : 'tcp') ."://{$this->host}"; |
|
39 | - $this->socket = fsockopen( $url, $this->port, $errno, $errstr, 30 ); |
|
40 | - if ( ! $this->socket ) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
38 | + $url = ($this->secure ? 'tls' : 'tcp')."://{$this->host}"; |
|
39 | + $this->socket = fsockopen($url, $this->port, $errno, $errstr, 30); |
|
40 | + if (!$this->socket) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
41 | 41 | $this->lastMessage = ''; |
42 | 42 | $this->lastCode = 0; |
43 | 43 | } |
44 | 44 | |
45 | - public function close(){ |
|
45 | + public function close() { |
|
46 | 46 | $this->socket && @fclose($this->socket); |
47 | 47 | } |
48 | 48 | |
49 | - protected function write($data, $nl = 1){ |
|
50 | - $payload = $data . str_repeat("\r\n",$nl); |
|
49 | + protected function write($data, $nl = 1) { |
|
50 | + $payload = $data.str_repeat("\r\n", $nl); |
|
51 | 51 | fwrite($this->socket, $payload); |
52 | 52 | } |
53 | 53 | |
54 | - protected function expectCode($code){ |
|
54 | + protected function expectCode($code) { |
|
55 | 55 | |
56 | 56 | $this->lastMessage = ''; |
57 | - while (substr($this->lastMessage, 3, 1) != ' '){ |
|
57 | + while (substr($this->lastMessage, 3, 1) != ' ') { |
|
58 | 58 | $this->lastMessage = fgets($this->socket, 256); |
59 | 59 | } |
60 | 60 | |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | return $code == $this->lastCode; |
63 | 63 | } |
64 | 64 | |
65 | - protected function SMTPmail($from,$to,$body){ |
|
65 | + protected function SMTPmail($from, $to, $body) { |
|
66 | 66 | $this->connect(); |
67 | 67 | $this->expectCode(220); |
68 | 68 | |
69 | 69 | $this->write("EHLO {$this->host}"); |
70 | 70 | $this->expectCode(250); |
71 | 71 | |
72 | - if ($this->username){ |
|
72 | + if ($this->username) { |
|
73 | 73 | $this->write("AUTH LOGIN"); |
74 | 74 | $this->expectCode(334); |
75 | 75 | $this->write(base64_encode($this->username)); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | return $success; |
99 | 99 | } |
100 | 100 | |
101 | - public function onSend(Envelope $envelope){ |
|
101 | + public function onSend(Envelope $envelope) { |
|
102 | 102 | // PHP requires direct handling of To and Subject Headers. |
103 | 103 | $success = true; |
104 | 104 | $recipients = $envelope->to(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $envelope->from(false); |
108 | 108 | foreach ($recipients as $to) { |
109 | 109 | $current_success = $this->SMTPmail($from, $to, $envelope->build()); |
110 | - \Event::trigger('core.email.send',$to,$envelope,'smtp'); |
|
110 | + \Event::trigger('core.email.send', $to, $envelope, 'smtp'); |
|
111 | 111 | $success = $success && $current_success; |
112 | 112 | } |
113 | 113 | return $success; |
@@ -33,28 +33,32 @@ discard block |
||
33 | 33 | $this->password = isset($options->password) ? $options->password : false; |
34 | 34 | } |
35 | 35 | |
36 | - protected function connect(){ |
|
37 | - if ($this->socket) $this->close(); |
|
36 | + protected function connect() { |
|
37 | + if ($this->socket) { |
|
38 | + $this->close(); |
|
39 | + } |
|
38 | 40 | $url = ($this->secure ? 'tls' : 'tcp') ."://{$this->host}"; |
39 | 41 | $this->socket = fsockopen( $url, $this->port, $errno, $errstr, 30 ); |
40 | - if ( ! $this->socket ) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
42 | + if ( ! $this->socket ) { |
|
43 | + throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
44 | + } |
|
41 | 45 | $this->lastMessage = ''; |
42 | 46 | $this->lastCode = 0; |
43 | 47 | } |
44 | 48 | |
45 | - public function close(){ |
|
49 | + public function close() { |
|
46 | 50 | $this->socket && @fclose($this->socket); |
47 | 51 | } |
48 | 52 | |
49 | - protected function write($data, $nl = 1){ |
|
53 | + protected function write($data, $nl = 1) { |
|
50 | 54 | $payload = $data . str_repeat("\r\n",$nl); |
51 | 55 | fwrite($this->socket, $payload); |
52 | 56 | } |
53 | 57 | |
54 | - protected function expectCode($code){ |
|
58 | + protected function expectCode($code) { |
|
55 | 59 | |
56 | 60 | $this->lastMessage = ''; |
57 | - while (substr($this->lastMessage, 3, 1) != ' '){ |
|
61 | + while (substr($this->lastMessage, 3, 1) != ' ') { |
|
58 | 62 | $this->lastMessage = fgets($this->socket, 256); |
59 | 63 | } |
60 | 64 | |
@@ -62,14 +66,14 @@ discard block |
||
62 | 66 | return $code == $this->lastCode; |
63 | 67 | } |
64 | 68 | |
65 | - protected function SMTPmail($from,$to,$body){ |
|
69 | + protected function SMTPmail($from,$to,$body) { |
|
66 | 70 | $this->connect(); |
67 | 71 | $this->expectCode(220); |
68 | 72 | |
69 | 73 | $this->write("EHLO {$this->host}"); |
70 | 74 | $this->expectCode(250); |
71 | 75 | |
72 | - if ($this->username){ |
|
76 | + if ($this->username) { |
|
73 | 77 | $this->write("AUTH LOGIN"); |
74 | 78 | $this->expectCode(334); |
75 | 79 | $this->write(base64_encode($this->username)); |
@@ -98,7 +102,7 @@ discard block |
||
98 | 102 | return $success; |
99 | 103 | } |
100 | 104 | |
101 | - public function onSend(Envelope $envelope){ |
|
105 | + public function onSend(Envelope $envelope) { |
|
102 | 106 | // PHP requires direct handling of To and Subject Headers. |
103 | 107 | $success = true; |
104 | 108 | $recipients = $envelope->to(); |
@@ -66,7 +66,7 @@ |
||
66 | 66 | $this->connect(); |
67 | 67 | $this->expectCode(220); |
68 | 68 | |
69 | - $this->write("EHLO {$this->host}"); |
|
69 | + $this->write("ehlo {$this->host}"); |
|
70 | 70 | $this->expectCode(250); |
71 | 71 | |
72 | 72 | if ($this->username){ |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | class Redirect { |
14 | 14 | use Module; |
15 | 15 | |
16 | - public static function to($url){ |
|
17 | - if ($link = Filter::with('core.redirect',$url)) { |
|
16 | + public static function to($url) { |
|
17 | + if ($link = Filter::with('core.redirect', $url)) { |
|
18 | 18 | Response::clean(); |
19 | 19 | Response::header('Location', $link); |
20 | 20 | Response::send(); |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | - public static function back(){ |
|
26 | - if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )){ |
|
25 | + public static function back() { |
|
26 | + if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri', false) : $_SERVER['HTTP_REFERER']))) { |
|
27 | 27 | Response::clean(); |
28 | 28 | Response::header('Location', $link); |
29 | 29 | Response::send(); |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - public static function viaJavaScript($url, $parent=false){ |
|
35 | - if ($link = Filter::with('core.redirect', $url)){ |
|
34 | + public static function viaJavaScript($url, $parent = false) { |
|
35 | + if ($link = Filter::with('core.redirect', $url)) { |
|
36 | 36 | Response::type('text/html'); |
37 | - Response::add('<script>'.($parent?'parent.':'').'location.href="',addslashes($link),'"</script>'); |
|
37 | + Response::add('<script>'.($parent ? 'parent.' : '').'location.href="', addslashes($link), '"</script>'); |
|
38 | 38 | Response::send(); |
39 | 39 | exit; |
40 | 40 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | class Redirect { |
14 | 14 | use Module; |
15 | 15 | |
16 | - public static function to($url){ |
|
16 | + public static function to($url) { |
|
17 | 17 | if ($link = Filter::with('core.redirect',$url)) { |
18 | 18 | Response::clean(); |
19 | 19 | Response::header('Location', $link); |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | - public static function back(){ |
|
26 | - if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )){ |
|
25 | + public static function back() { |
|
26 | + if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )) { |
|
27 | 27 | Response::clean(); |
28 | 28 | Response::header('Location', $link); |
29 | 29 | Response::send(); |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - public static function viaJavaScript($url, $parent=false){ |
|
35 | - if ($link = Filter::with('core.redirect', $url)){ |
|
34 | + public static function viaJavaScript($url, $parent=false) { |
|
35 | + if ($link = Filter::with('core.redirect', $url)) { |
|
36 | 36 | Response::type('text/html'); |
37 | 37 | Response::add('<script>'.($parent?'parent.':'').'location.href="',addslashes($link),'"</script>'); |
38 | 38 | Response::send(); |
@@ -20,6 +20,6 @@ |
||
20 | 20 | public function append($path, $data); |
21 | 21 | public function delete($path); |
22 | 22 | public function move($old_path, $new_path); |
23 | - public function search($pattern, $recursive=true); |
|
23 | + public function search($pattern, $recursive = true); |
|
24 | 24 | |
25 | 25 | } |