Skip to content

Commit

Permalink
Added warning if the class name doesn't match with the file name
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopvilar committed Jul 13, 2014
1 parent 188fb27 commit c49cfaf
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/core/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,32 @@ private function load()

private function loadFile($file){

$name = str_replace('.php', '', $file);
$name_arr = explode('/', $name);
$name = $name_arr[count($name_arr) - 1];;
try{

require $file;
$name = str_replace('.php', '', $file);
$name_arr = explode('/', $name);
$name = $name_arr[count($name_arr) - 1];;

$instance = new $name;
require $file;

// Register the meta-boxes if is a model
if (is_subclass_of($instance, 'AppModel')) {
$this->app->registerModel($instance);
$this->rw->add($instance->getPostType(), $instance->getFields());
}
if(!class_exists($name)){
throw new InvalidArgumentException("The class " . $name ." cannot be found, please check if the file and class name is correct");
}

$instance = new $name;

// Register the meta-boxes if is a model
if (is_subclass_of($instance, 'AppModel')) {
$this->app->registerModel($instance);
$this->rw->add($instance->getPostType(), $instance->getFields());
}

if (is_subclass_of($instance, 'OptionPage')) {
$this->app->registerOption($instance);
}

if (is_subclass_of($instance, 'OptionPage')) {
$this->app->registerOption($instance);
}catch(InvalidArgumentException $e){
trigger_error($e->getMessage(), E_USER_WARNING);
}

}
Expand Down

0 comments on commit c49cfaf

Please sign in to comment.