xdrm-framework/exporter/Builder.php

82 lines
2.1 KiB
PHP
Raw Permalink 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 */
echo "(1) Building file structure\n";
shell_exec("cp -r ".__ROOT__."/src/files/* ".$this->root);
2016-12-08 18:20:42 +00:00
shell_exec("cp -r ".__ROOT__."/src/files/.htaccess ".$this->root."/.htaccess");
/* [2] Browse each package to load
=========================================================*/
echo "(2) Building packages\n";
$count = 1;
foreach($this->packages as $package=>$version){
$path = "$package/$version";
echo " ($count) $package:$version\n";
/* (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/");
$count++;
}
echo "(*) Build finished\n";
/* [3] Start stats
=========================================================*/
echo "\n\nStatistics:\n";
echo shell_exec("du -hs ".$this->root."/*;");
echo "--\n";
echo shell_exec("du -hs ".$this->root."/;");
}
}