/**
  *
  * @param string $deploymentDescriptorPath absolute path of descriptor file
  * $return array module deployment descriptor
  */
 public function deploy()
 {
     $compontens = [];
     $models = [];
     $modules = [];
     $moduleInfo = [];
     $moduleInfoFile = new File("{$this->modulePath}/" . ModuleInfo::MODULE_INFO_FILENAME);
     if ($moduleInfoFile->exists()) {
         $moduleInfo = $moduleInfoFile->includeFile();
     } else {
         $this->log->console("Missing module info file in {$this->modulePath}", null, Log::WARNING);
     }
     $componentsDir = new Directory("{$this->modulePath}/" . self::COMPONENTS_FOLDER);
     if ($componentsDir->exists()) {
         $compontens = $componentsDir->getFiles(true, self::PHP_FILE_FILTER);
     }
     $modelsDir = new Directory("{$this->modulePath}/" . self::MODELS_FOLDER);
     if ($modelsDir->exists()) {
         $modelsTmp = $modelsDir->getFiles(true, self::PHP_FILE_FILTER);
         foreach ($modelsTmp as $modelPath) {
             $class = substr($modelPath, strrpos($this->modulePath, DS) + 1);
             // remove path
             $class = substr($class, 0, -4);
             // remove .php extendsion
             $class = str_replace(DS, '\\', $class);
             // direectory separator to namespace separator
             $models[$class] = $modelPath;
         }
     }
     $modulesDir = new Directory("{$this->modulePath}/" . self::MODULES_FOLDER);
     if ($modulesDir->exists()) {
         foreach ($modulesDir->getDirectories() as $subModulePath) {
             $moduleName = substr(str_replace($modulesDir->getPath(), '', $subModulePath), 1);
             $subModuleDeployer = new ModuleDeployer($subModulePath);
             $modules[$moduleName] = $subModuleDeployer->deploy();
         }
     }
     return ['path' => $this->modulePath, 'compontents' => $compontens, 'modules' => $modules, 'models' => $models, 'info' => $moduleInfo];
 }
 /**
  * @param string path of directory
  */
 public function __construct($path)
 {
     $this->path = Directory::normalize($path);
 }
require_once BASE_PATH . '/zool/annotation/annotations.php';
require_once BASE_PATH . '/zool/annotation/annotations.php';
require_once BASE_PATH . '/zool/deploy/Deployment.php';
require_once BASE_PATH . '/zool/util/log/LogProvider.php';
function displayException($exception)
{
    echo "\n\n" . get_class($exception);
    echo $exception->getMessage() . ' (' . $exception->getFile() . ':' . $exception->getLine() . ")";
    echo $exception->getTraceAsString();
    if ($exception->getPrevious() !== null) {
        displayException($exception->getPrevious());
    }
}
$appdeployer = new \zool\deploy\ApplicationDeployer(['zool' => ZOOL_PATH, 'app' => APP_PATH]);
$prevmtimehash = $argv[1];
$app = new Directory(BASE_PATH);
$files = $app->getFiles(true, ModuleDeployer::PHP_FILE_FILTER);
$mtime = '';
foreach ($files as $file) {
    if (!Strings::endsWidth($file, Deployment::DEPLOYMENT_DESCRIPTOR) && (Strings::contains($file, 'component') || Strings::contains($file, 'zool') || true)) {
        $mtime .= filemtime($file);
    }
}
$mtimehash = md5($mtime);
if ($prevmtimehash != $mtimehash) {
    try {
        $appdeployer->deploy(BASE_PATH);
    } catch (Exception $e) {
        echo "\n///////////////////  INCOMPLETE DEPLOYMENT  ///////////////////\n\n";
        displayException($e);
        //echo $mtimehash."\n";
 /**
  * Writes the collected data to file.
  * @return void
  */
 private function exportDeploymentDescriptor()
 {
     // sort events by priority
     uasort($this->events, function ($a, $b) {
         if ($a['priority'] == $b['priority']) {
             return 0;
         }
         return $a['priority'] > $b['priority'] ? -1 : 1;
     });
     $deployment = ['modules' => $this->modules, 'models' => $this->models, 'components' => $this->components, 'factories' => $this->factories, 'events' => $this->events];
     $deploymentScript = '<?php return ' . var_export($deployment, true) . ";\n";
     $runtimeDir = new Directory(RUNTIME_PATH);
     $runtimeDir->create();
     $deploymentDescriptor = new File(self::getDeploymentDescriptorPath());
     $deploymentDescriptor->touch($deploymentScript);
 }