Merge branch 'maint/7.0'
[ninja.git] / src / generators / buildlib.php
blob385c030cc4d8797f366efe01b347d57f4b81adf4
1 <?php
3 define('NINJA_SDK_PATH', __DIR__.'/../op5/ninja_sdk');
5 if( php_sapi_name() != 'cli' ) {
6 print("Builders can only be runned as cli\n");
7 exit(1);
10 define('KOHANA_BASE', dirname(dirname(dirname(__FILE__))) ); // FIXME: make nicer
11 define('TARGET_BASE', KOHANA_BASE . DIRECTORY_SEPARATOR . 'modules');
12 define('GENERATOR_BASE', KOHANA_BASE . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'generators');
14 require_once( NINJA_SDK_PATH.'/class_generator.php' );
16 class_generator::$model_suffix = '_Model';
17 class_generator::$library_suffix = '';
18 class_generator::$library_dir = 'libraries';
19 class_generator::$model_dir = 'models';
20 class_generator::$manifest_dir = 'manifest';
22 abstract class generator_module {
23 public $mod_name;
24 public $mod_dir;
25 public $gen_dir;
27 public function __construct( $mod_name ) {
28 $this->mod_name = $mod_name;
29 $this->mod_dir = TARGET_BASE . DIRECTORY_SEPARATOR . $mod_name;
30 $this->gen_dir = GENERATOR_BASE . DIRECTORY_SEPARATOR . $mod_name . DIRECTORY_SEPARATOR;
32 abstract protected function do_run();
34 final public function run() {
35 try {
36 if( !is_dir( $this->mod_dir ) && !mkdir( $this->mod_dir, 0755 ) )
37 gen_error( sprintf("Can not create '%s'", $this->mod_dir) );
38 chdir( $this->mod_dir );
40 $this->do_run();
41 } catch( Exception $e ) {
42 fprintf( STDERR, "Generator exception in module %s: %s\nExiting module...\n", $this->mod_name, $e->getMessage() );
43 fprintf( STDERR, "%s @ %s\n%s\n", $e->getFile(), $e->getLine(), $e->getTraceAsString());
44 exit( 1 );
46 exit( 0 );