forked from phalcon/incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.php
67 lines (61 loc) · 2.2 KB
/
Loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Anton Kornilov <kachit@yandex.ru> |
+------------------------------------------------------------------------+
*/
namespace Phalcon\Config;
use Phalcon\Config\Adapter\Ini;
use Phalcon\Config\Adapter\Json;
use Phalcon\Config\Adapter\Php;
use Phalcon\Config\Adapter\Yaml;
use Phalcon\Config;
/**
* Phalcon config loader
*
* @package Phalcon\Config
*/
class Loader
{
/**
* Load config from file extension dynamical
*
* @param string $filePath
*
* @return Config
* @throws Exception
*/
public static function load($filePath)
{
if (!is_file($filePath)) {
throw new Exception('Config file not found');
}
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
switch ($extension) {
case 'ini':
return new Ini($filePath);
case 'json':
return new Json($filePath);
case 'php':
case 'php5':
case 'inc':
return new Php($filePath);
case 'yml':
case 'yaml':
return new Yaml($filePath);
default:
throw new Exception('Config adapter for .' . $extension . ' files is not support');
}
}
}