forked from vitorportela/maintroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
42 lines (33 loc) · 1.15 KB
/
config.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
<?php
set_include_path( '.'
. PATH_SEPARATOR . realpath( $caminhoRootUrl . 'includes' ) . DIRECTORY_SEPARATOR
. PATH_SEPARATOR . get_include_path() );
spl_autoload_register(
function( $classname )
{
require_once fileExistsReturningPath(str_replace( '\\', DIRECTORY_SEPARATOR, $classname) ) ;
}
);
/**
* Verifica se o arquivo existe com ou sem sufixos e retorna o caminho encontrado,
* se não encontrou retorna null
* @param string $fullClassPathWithouExt
* @return null|string
*/
function fileExistsReturningPath($fullClassPathWithouExt)
{
$fullClassPathWithouExt = preg_replace("/\\\\/", "/", $fullClassPathWithouExt);
$fullClassPathWithouExt = 'includes/' . $fullClassPathWithouExt;
if(file_exists($fullClassPathWithouExt.".php"))
return $fullClassPathWithouExt.".php";
$arraySufixos = array(
'class','interface','enum','exception','page',
'dados'
);
foreach($arraySufixos AS $sufixo)
{
if(\file_exists($fullClassPathWithouExt.".".$sufixo.".php"))
return $fullClassPathWithouExt.".".$sufixo.".php";
}
return null;
}