xdrm-framework/exporter/Builder.php

65 lines
1.6 KiB
PHP
Raw Normal View History

<?php if( !defined('__ROOT__') ) define('__ROOT__', dirname(dirname(__FILE__)) );
class Builder{
private static function src(){ return __ROOT__.'/src'; }
private $packages = null;
private $root = null;
/* BUILDS A BUILDER WITH SPECIFIC LOCATION AND CONFIG
*
* @pRoot<String> Path to project root
* @pPackages<Array> Packages to load
*
*/
public function __construct($pRoot, $pPackages){
/* [1] Stores the path
=========================================================*/
$this->root = $pRoot;
/* [2] Stores the packages
=========================================================*/
$this->packages = $pPackages;
}
public function build(){
/* [1] Builds project's base file structure
=========================================================*/
/* (1) Copy from src/files */
shell_exec("cp -r ".__ROOT__."/src/files/* ".$this->root);
/* [2] Browse each package to load
=========================================================*/
foreach($this->packages as $package=>$version){
$path = "/$package/$version";
/* (1) Copy package folder if it exists */
if( file_exists(__ROOT__."/src/packages$path/") && is_dir(__ROOT__."/src/packages$path/") && count(scandir(__ROOT__."/src/packages$path/")) > 2 )
shell_exec("cp -r ".__ROOT__."/src/packages$path ".$this->root."/build/$package");
/* (2) Copy package config if it exists */
if( file_exists(__ROOT__."/src/config$path/") && is_dir(__ROOT__."/src/config$path/") && count(scandir(__ROOT__."/src/config$path/")) > 2 )
shell_exec("cp -r ".__ROOT__."/src/config$path/* ".$this->root."/config/");
}
}
}