", * "after_id": "" * */ class JsonAutoload { private $json_file; private $json_data_dec; private $replace_namespace; private $namespace_to_change; private $amount_replace; function __construct( ) { $this->amount_replace = 0; $this->replace_namespace = array( ); $this->namespace_to_change = array( ); $this->ExistFileJSON( ); $this->ReadJson( ); $this->get_JsonLibrary(); } public function get_NamespaceToPathname( $classname ){ $result = str_replace( $this->namespace_to_change, $this->replace_namespace, $classname ); return $result; } private function obtain_replace_namespace( $lib, $json_replace ){ $amount_replace = count( $json_replace["replace"] ); $odd = ($amount_replace % 2); if( $odd == 1 ){ $this->ERROR_OBJ("Campo Replace em autoload.json tem quantidade ímpar. Deve ser par em $lib"); } foreach ($json_replace["replace"] as $key => $value) { if( str_contains( $key, "before") ){ $this->namespace_to_change[$this->amount_replace] = $value; } if( str_contains( $key, "after") ){ $this->replace_namespace[$this->amount_replace] = $value; } if(count($this->replace_namespace) == count($this->namespace_to_change)){ ++$this->amount_replace; } } } private function get_JsonLibrary( ){ foreach ( $this->json_data_dec as $lib => $value ) { if(!is_array($value["replace"])){ $this->ERROR_OBJ("Está faltando campo replace em $lib no arquivo {$this->json_file}"); } $this->obtain_replace_namespace( $lib, $value ); } } private function ExistFileJSON( ){ if( !file_exists( $this->FileName() )){ $this->ERROR_OBJ("Não foi possível encontrar o json para autoload"); } return true; } private function ReadJson( ){ $json_file = file_get_contents( $this->FileName() ); $this->json_data_dec = json_decode( $json_file, true ); if(!$this->json_data_dec){ $this->ERROR_OBJ("não foi possivel carregar {$this->json_file}"); } } private function FileName( ){ $this->json_file = dirname(__FILE__)."/autoload.json"; return $this->json_file; } private function ERROR_OBJ( $str ){ echo $str; die; } }