public static function analyze($path_to_folder, $map_calsses = true)
 {
     //Log::writeInfo( "ClassManager start analyze classes", "file" );
     if ($path_to_folder == false) {
         throw new CodeRunnerException("Wrong path to code source");
     }
     $all_files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path_to_folder));
     $php_files = new RegexIterator($all_files, '/\\.php$/');
     $classes = [];
     $namespaces_path = [];
     foreach ($php_files as $php_file) {
         $class_info = [];
         $class_info['class_name'] = basename($php_file->getRealPath(), ".php");
         $class_info['namespace'] = self::getNamespace(file_get_contents($php_file->getRealPath()));
         if ($class_info['namespace'] != '') {
             $class_info['full_name'] = $class_info['namespace'] . '\\' . $class_info['class_name'];
         } else {
             $class_info['full_name'] = $class_info['class_name'];
         }
         $class_info['path'] = $php_file->getRealPath();
         self::putToHolder($class_info, 'class_name');
         $namespaces_path[$class_info['namespace']] = pathinfo($class_info['path'])['dirname'];
         //key = namespace key = path to folder;
         $classes[] = ['name' => $class_info['class_name'], 'namespace' => $class_info['namespace'] . "\\" . $class_info['class_name']];
     }
     foreach ($namespaces_path as $namespace => $path) {
         Autoload::addNamespace($namespace, $path);
         // add autoloading for user classes
     }
     if ($map_calsses == true) {
         Backendless::ignoreMapException();
         foreach ($classes as $class) {
             Backendless::mapTableToClass($class['name'], $class['namespace']);
             // set mapping for SDK.
         }
     }
 }
 public static function analyze()
 {
     Log::writeInfo("ClassManager start analyze classes", "file");
     $all_files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PathBuilder::getClasses()));
     $php_files = new RegexIterator($all_files, '/\\.php$/');
     $classes_namespaces = [];
     foreach ($php_files as $php_file) {
         $class_info = [];
         //$class_info["parent_class"] = self::getParentClass( file_get_contents( $php_file->getRealPath() ) );
         $class_info['namespace'] = str_replace("/", "\\", trim(dirname(substr($php_file->getRealPath(), strlen(PathBuilder::getClasses()))), "/"));
         $class_info['class_name'] = basename($php_file->getRealPath(), ".php");
         $class_info['path'] = $php_file->getRealPath();
         self::putToHolder($class_info);
         $classes_namespaces[$class_info['namespace']] = pathinfo($class_info["path"])["dirname"];
         //key = namespace key = path to folder;
         Backendless::mapTableToClass($class_info['class_name'], $class_info['namespace'] . "\\" . $class_info['class_name']);
         // set mapping for SDK.
     }
     foreach ($classes_namespaces as $namespace => $path) {
         Autoload::addNamespace($namespace, $path);
         // add autoloading for user classes
     }
     Log::writeInfo("ClassManager finished analyze classes", "file");
 }
Beispiel #3
0
<?php

//enable the display of errors
error_reporting(E_ALL);
ini_set('display_errors', true);
declare (ticks=1);
use backendless\core\lib\Autoload;
use backendless\core\CodeRunnerLoader;
// define short constants
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));
ini_set('default_socket_timeout', -1);
//include file with CodeRunner autoloader
include 'lib' . DS . 'Autoload.php';
//include file with predis autoloader
include 'lib' . DS . 'predis' . DS . 'autoload.php';
//include file with backendless SDK autoloader
include '..' . DS . 'lib' . DS . 'backendless' . DS . 'autoload.php';
// initialize app autoloading
Autoload::register();
Autoload::addNamespace('backendless\\core', BP . DS . 'core');
// initialize and run application
CodeRunnerLoader::load($argc, $argv);