loadDeclaredSchemas() public static method

Returns declared schema objects.
public static loadDeclaredSchemas ( ) : array
return array Schema objects
 public function testSchemaFinder()
 {
     $finder = new SchemaFinder();
     $finder->findByPaths(['src', 'tests']);
     $schemas = SchemaLoader::loadDeclaredSchemas();
     $this->assertNotEmpty($schemas);
     foreach ($schemas as $schema) {
         $this->assertInstanceOf('LazyRecord\\Schema\\DeclareSchema', $schema);
     }
 }
Beispiel #2
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, $args, $logger = null)
 {
     if (count($args) && !file_exists($args[0])) {
         $classes = array();
         // it's classnames
         foreach ($args as $class) {
             // call class loader to load
             if (class_exists($class, true)) {
                 $classes[] = $class;
             } else {
                 if ($logger) {
                     $logger->warn("{$class} not found.");
                 } else {
                     echo ">>> {$class} not found.\n";
                 }
             }
         }
         return ClassUtils::schema_classes_to_objects($classes);
     } else {
         $finder = new SchemaFinder();
         if (count($args) && file_exists($args[0])) {
             $finder->paths = $args;
             foreach ($args as $file) {
                 if (is_file($file)) {
                     require_once $file;
                 }
             }
         } elseif ($paths = $loader->getSchemaPaths()) {
             $finder->setPaths($paths);
         }
         $finder->find();
         // load class from class map
         if ($classMap = $loader->getClassMap()) {
             foreach ($classMap as $file => $class) {
                 if (!is_numeric($file) && is_string($file)) {
                     require $file;
                 }
             }
         }
         return SchemaLoader::loadDeclaredSchemas();
     }
 }
Beispiel #3
0
<?php

use LazyRecord\Schema\SchemaLoader;
$finder = new LazyRecord\Schema\SchemaFinder();
if ($app = kernel()->getApp()) {
    $finder->in($app->locate() . DIRECTORY_SEPARATOR . 'Model');
}
if ($bundles = kernel()->bundles) {
    foreach ($bundles as $bundle) {
        $finder->in($bundle->locate() . DIRECTORY_SEPARATOR . 'Model');
    }
}
$finder->find();
if (method_exists($finder, "getSchemas")) {
    return $finder->getSchemas();
}
return $finder;
return SchemaLoader::loadDeclaredSchemas();
Beispiel #4
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, array $args, Logger $logger = null)
 {
     $classes = array_filter($args, function ($class) {
         return class_exists($class, true);
     });
     if (!empty($classes)) {
         return ClassUtils::schema_classes_to_objects(array_unique($classes));
     }
     $paths = array_filter($args, 'file_exists');
     if (empty($paths)) {
         $paths = $loader->getSchemaPaths();
     }
     if (!empty($paths)) {
         $finder = new SchemaFinder($paths);
         $finder->find();
     }
     // load class from class map
     if ($classMap = $loader->getClassMap()) {
         foreach ($classMap as $file => $class) {
             if (is_numeric($file)) {
                 continue;
             }
             require_once $file;
         }
     }
     return SchemaLoader::loadDeclaredSchemas();
 }