1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Metaways Infosystems GmbH, 2011 |
||
6 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||
7 | */ |
||
8 | |||
9 | |||
10 | class TestHelperMw |
||
11 | { |
||
12 | private static $config; |
||
13 | private static $dbm; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
14 | |||
15 | |||
16 | /** |
||
17 | * Autoloader for classes |
||
18 | * |
||
19 | * @param string $className Class name |
||
20 | * @return boolean True if class was found, false if not |
||
21 | */ |
||
22 | public static function autoload( $className ) |
||
23 | { |
||
24 | $fileName = strtr( ltrim( $className, '\\' ), '\\_', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) . '.php'; |
||
25 | |||
26 | if( strncmp( $fileName, 'Aimeos' . DIRECTORY_SEPARATOR, 7 ) === 0 ) { |
||
27 | $fileName = substr( $fileName, 7 ); |
||
28 | } |
||
29 | |||
30 | foreach( explode( PATH_SEPARATOR, get_include_path() ) as $path ) |
||
31 | { |
||
32 | $file = $path . DIRECTORY_SEPARATOR . $fileName; |
||
33 | |||
34 | if( file_exists( $file ) === true && ( include_once $file ) !== false ) { |
||
35 | return true; |
||
36 | } |
||
37 | } |
||
38 | |||
39 | return false; |
||
40 | } |
||
41 | |||
42 | |||
43 | /** |
||
44 | * Returns the configuration object |
||
45 | * |
||
46 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
47 | */ |
||
48 | public static function getConfig() |
||
49 | { |
||
50 | if( !isset( self::$config ) ) { |
||
51 | self::$config = self::createConfig(); |
||
52 | } |
||
53 | |||
54 | return self::$config; |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Returns the database manager object |
||
60 | * |
||
61 | * @return \Aimeos\MW\DB\Manager\Iface Database manager object |
||
62 | */ |
||
63 | public static function getDBManager() |
||
64 | { |
||
65 | return \Aimeos\MW\DB\Factory::create( self::getConfig(), 'DBAL' ); |
||
66 | } |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Creates a new configuration object |
||
71 | * |
||
72 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
73 | */ |
||
74 | private static function createConfig() |
||
75 | { |
||
76 | $path = dirname( dirname( dirname( __DIR__ ) ) ) . DIRECTORY_SEPARATOR . 'config'; |
||
77 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
||
78 | |||
79 | $object = new \Aimeos\MW\Config\PHPArray( [], $path ); |
||
80 | $object = new \Aimeos\MW\Config\Decorator\Documentor( $object, $file ); |
||
81 | |||
82 | return $object; |
||
83 | } |
||
84 | } |
||
85 |