- #6584: generates a new application from templates with script bin\tn.php
[tine20] / bin / tn.php
1 <?php
2 /**
3  * Script for code generation
4  *
5  * @package     Tine_Tool
6  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
7  * @author      Fl├ívio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
8  * @copyright   Copyright (c) 2013 Metaways Infosystems GmbH (http://www.metaways.de)
9  * @version     $Id$ 
10  */
11
12 define('APPLICATION','Application');
13
14 main();
15
16 function main()
17 {
18         prepareEnvironment();
19         
20         try {
21                 $opts = new Zend_Console_Getopt(array(
22                                 'create application|a=s'=>'create application option with required string parameter',
23                                 'help'=>'help option with no required parameter'
24                 )
25                 );
26                 $opts->parse();
27         } catch (Zend_Console_Getopt_Exception $e) {
28                 echo $e->getUsageMessage();
29                 exit;
30         }
31
32         if ($applicationName = $opts->getOption('a'))
33         {
34                 create(APPLICATION, array($applicationName));
35                 echo "Application $applicationName was created successfully into tine20 folder! \n";
36                 exit;
37         }
38         echo $e->getUsageMessage();
39         exit;
40 }
41
42 /**
43  * Sets the include path and loads autoloader classes
44  */
45 function prepareEnvironment()
46 {
47         $paths = array(
48                         realpath(dirname(__FILE__) . '/../tine20'),
49                         realpath(dirname(__FILE__) . '/../tine20/library'),
50                         get_include_path()
51         );
52         set_include_path(implode(PATH_SEPARATOR, $paths));
53
54         require_once 'Zend/Loader/Autoloader.php';
55         $autoloader = Zend_Loader_Autoloader::getInstance();
56         $autoloader->setFallbackAutoloader(true);
57         Tinebase_Autoloader::initialize($autoloader);
58 }
59
60 /**
61  * Creates an instance of a class that knows how to build the requested structure
62  * @param string $builder
63  */
64 function create($builder, array $args)
65 {       
66         // last argument is path of Tine 2.0
67         $args[] = realpath(dirname(__FILE__) . '/../tine20');
68
69         $className = 'Tool_CodeGenerator_' . $builder;
70         $tcg = new $className();
71         $tcg->build($args);
72 }