Skip to content

Commit

Permalink
Merge pull request #15 from tattersoftware/ignores
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
MGatner authored Nov 11, 2020
2 parents 9fc5b0f + c429728 commit 36e71bc
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/Drafter/Handlers/ModelHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Tatter\Schemas\Drafter\Handlers;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Model;
use Config\Services;
use Tatter\Schemas\Drafter\BaseDrafter;
use Tatter\Schemas\Drafter\DrafterInterface;
Expand Down Expand Up @@ -162,12 +163,27 @@ protected function getModels(): array
// Try to load each class
foreach ($classes as $class)
{
// Try to instantiate
try { $instance = new $class(); }
catch (\Exception $e) { continue; }

// Check for ignored namespaces
foreach ($this->config->ignoredNamespaces as $namespace)
{
if (strpos($class, $namespace) === 0)
{
continue 2;
}
}

// Make sure it's really a model
if (! ($instance instanceof \CodeIgniter\Model))
if (! is_a($class, Model::class, true))
{
continue;
}

// Try to instantiate
try
{
$instance = new $class();
}
catch (\Exception $e)
{
continue;
}
Expand Down

0 comments on commit 36e71bc

Please sign in to comment.