Skip to content

Commit dd0b2df

Browse files
committed
several improvements
- Removed unused several vars and arguments - Fixed Dom\Selector cache - Fixed Form::setup method - Fixed Http\Negotiation class - Fixed Routing\Redirector - Packages::version() work without composer instalation for detect inphinit/framework package version
1 parent faca206 commit dd0b2df

File tree

9 files changed

+25
-20
lines changed

9 files changed

+25
-20
lines changed

src/Experimental/Dom/Document.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function toArray($type = Document::SIMPLE)
155155
throw new DomException('Invalid type', 2);
156156
}
157157

158-
return $this->getNodes($this->childNodes, true);
158+
return $this->getNodes($this->childNodes);
159159
}
160160

161161
/**
@@ -429,7 +429,7 @@ private function attrs(\DOMNode $node, array $attributes)
429429
}
430430
}
431431

432-
private function getNodes($nodes, $toplevel = false)
432+
private function getNodes($nodes)
433433
{
434434
$items = array();
435435

src/Experimental/Dom/Selector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function toXPath($query)
185185

186186
$restore = array_combine(array_values($this->prevent), array_keys($this->prevent));
187187

188-
return $cache[$query] = '//' . strtr($query, $restore);
188+
return self::$cache[$query] = '//' . strtr($query, $restore);
189189
}
190190

191191
private function putQuotes($arg)

src/Experimental/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function xhtml($xhtml)
3636
*/
3737
public static function setup($byType, array $attributes)
3838
{
39-
if (0 !== preg_match('#^(' . self::$alloweds . '|select|form)$#', $type)) {
39+
if (0 !== preg_match('#^(' . self::$alloweds . '|select|form)$#', $byType)) {
4040
self::$preAttrs[$byType] = $attributes;
4141
}
4242
}

src/Experimental/Http/Negotiation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function accept($level = self::HIGH)
100100
* @throws \Inphinit\Experimental\Exception
101101
* @return mixed
102102
*/
103-
public function getLanguage($$alternative = null)
103+
public function getLanguage($alternative = null)
104104
{
105105
$headers = $this->acceptLanguage();
106106
return $headers ? key($headers) : $alternative;
@@ -115,7 +115,7 @@ public function getLanguage($$alternative = null)
115115
* @throws \Inphinit\Experimental\Exception
116116
* @return mixed
117117
*/
118-
public function getCharset($$alternative = null)
118+
public function getCharset($alternative = null)
119119
{
120120
$headers = $this->acceptCharset();
121121
return $headers ? key($headers) : $alternative;
@@ -130,7 +130,7 @@ public function getCharset($$alternative = null)
130130
* @throws \Inphinit\Experimental\Exception
131131
* @return mixed
132132
*/
133-
public function getEncoding($$alternative = null)
133+
public function getEncoding($alternative = null)
134134
{
135135
$headers = $this->acceptEncoding();
136136
return $headers ? key($headers) : $alternative;
@@ -145,7 +145,7 @@ public function getEncoding($$alternative = null)
145145
* @throws \Inphinit\Experimental\Exception
146146
* @return mixed
147147
*/
148-
public function getAccept($$alternative = null)
148+
public function getAccept($alternative = null)
149149
{
150150
$headers = $this->accept();
151151
return $headers ? key($headers) : $alternative;

src/Experimental/Routing/Group.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class Group extends Router
2929
private $levelSecure;
3030
private $ready = false;
3131
private $currentPrefixPath;
32-
private $callback;
3332
private $domain;
3433
private $path;
3534
private $ns;

src/Experimental/Routing/Quick.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,5 @@ public function prepare()
170170
Route::set($value[0], $route, $controller . ':' . $value[2]);
171171
}
172172
}
173-
174-
$controller = $classMethods = null;
175173
}
176174
}

src/Experimental/Routing/Redirector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ class Redirector extends \Inphinit\Routing\Router
2828
public static function route($route, array $args = array(), $code = 302)
2929
{
3030
$verbs = array_keys(parent::$httpRoutes);
31+
$route = '/' . ltrim($route, '/');
3132
$to = false;
3233

3334
foreach ($verbs as $verb) {
34-
if (preg_match('#^(GET|ANY) /(|[\s\S]+)$#', $verb, $out) && $out[2] === $verb) {
35+
if (preg_match('#^(GET|ANY) (/|/[\s\S]+)$#', $verb, $out) && $out[2] === $route) {
3536
$to = $verb;
3637
break;
3738
}
@@ -64,7 +65,7 @@ public static function action($name, array $args = array(), $code = 302)
6465

6566
private static function redirect($verb, $args, $code)
6667
{
67-
if (!$verb) {
68+
if ($verb === false) {
6869
throw new Exception('Route or Action not defined in route', 3);
6970
}
7071

src/Inphinit/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class App
1717
{
1818
/** Inphinit framework version */
19-
const VERSION = '0.4.2';
19+
const VERSION = '0.4.3';
2020

2121
private static $events = array();
2222
private static $configs = array();

src/Inphinit/Packages.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
class Packages implements \IteratorAggregate
1313
{
14+
private static $composerLock;
1415
private $composerPath;
1516
private $classmapName = 'autoload_classmap.php';
1617
private $psrZeroName = 'autoload_namespaces.php';
1718
private $psrFourName = 'autoload_psr4.php';
18-
private $logs = array();
19+
private $log = array();
1920
private $libs;
2021

2122
/**
@@ -63,7 +64,6 @@ public function auto()
6364
public function inAutoload()
6465
{
6566
$path = INPHINIT_PATH . 'boot/namespaces.php';
66-
$i = 0;
6767

6868
if (is_file($path)) {
6969
$data = include $path;
@@ -171,7 +171,7 @@ public function save($path)
171171
foreach ($this->libs as $key => $value) {
172172
$value = self::relativePath($value);
173173

174-
fwrite($handle, ($first ? '' : ',') . $eol . " '" . $key . "' => '" . $value . "'");
174+
fwrite($handle, ($first ? '' : ',') . "$eol '$key' => '$value'");
175175

176176
$first = false;
177177
}
@@ -224,11 +224,18 @@ private static function relativePath($path)
224224
*/
225225
public static function version($name)
226226
{
227-
$file = INPHINIT_ROOT . 'composer.lock';
228-
$data = is_file($file) ? json_decode(file_get_contents($file)) : false;
227+
if (self::$composerLock === null) {
228+
$file = INPHINIT_ROOT . 'composer.lock';
229+
230+
if (is_file($file)) {
231+
self::$composerLock = json_decode(file_get_contents($file));
232+
}
233+
}
234+
235+
$data = self::$composerLock;
229236

230237
if (empty($data->packages)) {
231-
return null;
238+
return $name === 'inphinit/framework' ? App::VERSION : null;
232239
}
233240

234241
$version = null;

0 commit comments

Comments
 (0)