Skip to content

Commit cd62bea

Browse files
committed
Version 0.5.13
- Improved performance of `Inphinit\Experimental\Session` and `Inphinit\Packages` - `Inphinit\Helper::parseVersion()` use "Semantic Versioning 2.0.0" now - New param value for Request::is() method, eg: `Request::is('prefetch')` check if exists `Purpose` or `X-Moz` or `X-Purpose` headers, if exist check if value is `prefetch` (case-insenstive) - Improved performance of `Inphinit\Routing\Route` if is not using regex - Removed unnecessary check in `UtilsAutoload` function - Classes that are no longer experimental and are now available in the main namespace (can still be used with the "experimental" namespace to avoid breaking old projects): - `Inphinit\Experimental\Config` moved to `Inphinit\Config` - `Inphinit\Experimental\Debug` moved to `Inphinit\Debug` - `Inphinit\Experimental\Dir` moved to `Inphinit\Dir` - `Inphinit\Experimental\Dom\Document` moved to - `Inphinit\Experimental\Dom\DomException` moved to - `Inphinit\Experimental\Dom\Selector` moved to - `Inphinit\Experimental\Exception` moved to `Inphinit\Exception` - `Inphinit\Experimental\Maintenance` moved to `Inphinit\Maintenance` - Methods from `Inphinit\Experimental\File` class that are no longer experimental and are now available in `Inphinit\File` class (can still be used with the `Inphinit\Experimental\File` class to avoid breaking old projects): - `Inphinit\Experimental\File::lines()` moved to `Inphinit\File::lines()` - `Inphinit\Experimental\File::portion()` moved to `Inphinit\File::portion()`
1 parent 36da409 commit cd62bea

25 files changed

+1768
-1631
lines changed

src/Experimental/Config.php

Lines changed: 1 addition & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -9,203 +9,6 @@
99

1010
namespace Inphinit\Experimental;
1111

12-
use Inphinit\Helper;
13-
use Inphinit\Storage;
14-
15-
class Config implements \IteratorAggregate
12+
class Config extends \Inphinit\Config
1613
{
17-
private static $exceptionlevel = 3;
18-
private $data = array();
19-
private $path;
20-
21-
/**
22-
* Return items from a config file in a object (iterator or with ->)
23-
*
24-
* @param string $path
25-
* @throws \Inphinit\Experimental\Exception
26-
* @return void
27-
*/
28-
public function __construct($path)
29-
{
30-
$this->path = 'application/Config/' . strtr($path, '.', '/') . '.php';
31-
32-
$this->reload();
33-
}
34-
35-
/**
36-
* Create a Negotiation instance
37-
*
38-
* @param string $path
39-
* @throws \Inphinit\Experimental\Exception
40-
* @return \Inphinit\Experimental\Config
41-
*/
42-
public static function load($path)
43-
{
44-
self::$exceptionlevel = 4;
45-
46-
return new static($path);
47-
}
48-
49-
/**
50-
* Reload configuration from file
51-
*
52-
* @param string $path
53-
* @throws \Inphinit\Experimental\Exception
54-
* @return \Inphinit\Experimental\Config
55-
*/
56-
public function reload()
57-
{
58-
$level = self::$exceptionlevel;
59-
60-
self::$exceptionlevel = 2;
61-
62-
if (false === \Inphinit\File::exists(INPHINIT_PATH . $this->path)) {
63-
throw new Exception('File not found ' . $this->path, $level);
64-
}
65-
66-
foreach (\UtilsSandboxLoader($this->path) as $key => $value) {
67-
$this->data[$key] = $value;
68-
}
69-
70-
return $this;
71-
}
72-
73-
/**
74-
* Reload configuration from file
75-
*
76-
* @return bool
77-
*/
78-
public function save()
79-
{
80-
if (Storage::createFolder('tmp/cfg')) {
81-
$wd = preg_replace('#,(\s+|)\)#', '$1)', var_export($this->data, true));
82-
$path = Storage::temp('<?php' . EOL . 'return ' . $wd . ';' . EOL, 'tmp/cfg');
83-
84-
if ($path) {
85-
$response = copy($path, INPHINIT_PATH . $this->path);
86-
87-
unlink($path);
88-
89-
return $response;
90-
}
91-
}
92-
93-
return false;
94-
}
95-
96-
/**
97-
* Get all values like array or get specific item by level (multidimensional) using path
98-
*
99-
* @param string $path (optional) Path with "dots"
100-
* @param string $alternative (optional) alternative value does not find the selected value, default is null
101-
* @return mixed
102-
*/
103-
public function get($path = null, $alternative = null)
104-
{
105-
if ($path === null) {
106-
return $this->data;
107-
}
108-
109-
return Helper::extract($path, $this->data, $alternative);
110-
}
111-
112-
/**
113-
* Set value by path in specific level (multidimensional)
114-
*
115-
* @param string $path Path with "dots"
116-
* @param mixed $value Define value
117-
* @return \Inphinit\Experimental\Config
118-
*/
119-
public function set($path, $value)
120-
{
121-
$paths = explode('.', $path);
122-
123-
$key = array_shift($paths);
124-
125-
$tree = $value;
126-
127-
foreach (array_reverse($paths) as $item) {
128-
$tree = array($item => $tree);
129-
}
130-
131-
$this->data[$key] = $tree;
132-
133-
$tree = null;
134-
135-
return $this;
136-
}
137-
138-
/**
139-
* Magic method for get specific item by ->
140-
*
141-
* @param string $name
142-
* @return mixed
143-
*/
144-
public function __get($name)
145-
{
146-
if (array_key_exists($name, $this->data)) {
147-
return $this->data[$name];
148-
}
149-
}
150-
151-
/**
152-
* Magic method for set value (this method don't save data)
153-
*
154-
* @param string $name
155-
* @param mixed $value
156-
* @return void
157-
*/
158-
public function __set($name, $value)
159-
{
160-
$this->data[$name] = $value;
161-
}
162-
163-
/**
164-
* Magic method for check if value exists in top-level
165-
*
166-
* @param string $name
167-
* @return bool
168-
*/
169-
public function __isset($name)
170-
{
171-
return array_key_exists($name, $this->data);
172-
}
173-
174-
/**
175-
* Magic method for unset variable with `unset()` function
176-
*
177-
* @param string $name
178-
* @return void
179-
*/
180-
public function __unset($name)
181-
{
182-
unset($this->data[$name]);
183-
}
184-
185-
/**
186-
* Allow iteration with `for`, `foreach` and `while`
187-
*
188-
* Example:
189-
* <pre>
190-
* <code>
191-
* $foo = new Config('file'); //or Config::load('file')
192-
*
193-
* foreach ($foo as $key => $value) {
194-
* var_dump($key, $value);
195-
* echo EOL;
196-
* }
197-
* </code>
198-
* </pre>
199-
*
200-
* @return \ArrayIterator
201-
*/
202-
public function getIterator()
203-
{
204-
return new \ArrayIterator($this->data);
205-
}
206-
207-
public function __destruct()
208-
{
209-
$this->data = null;
210-
}
21114
}

0 commit comments

Comments
 (0)