System : Construire automatiquement la config d'un service en détectant les class

This commit is contained in:
Michael RICOIS 2015-04-15 13:20:30 +00:00
parent ee763e8c49
commit 13dc262ba0

View File

@ -0,0 +1,90 @@
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
//Use classmap autoloader - useful with opcode and realpath cache
require_once 'Zend/Loader/AutoloaderFactory.php';
require_once 'Zend/Loader/ClassMapAutoloader.php';
Zend_Loader_AutoloaderFactory::factory(array(
'Zend_Loader_ClassMapAutoloader' => array(
__DIR__ . '/../../library/Zend/autoload_classmap.php',
__DIR__ . '/../../library/Application/autoload_classmap.php',
__DIR__ . '/../../application/autoload_classmap.php',
__DIR__ . '/../../library/Scores/autoload_classmap.php',
__DIR__ . '/../../library/SdMetier/autoload_classmap.php',
),
'Zend_Loader_StandardAutoloader' => array(
'prefixes' => array(
'Zend' => __DIR__ . '/../../library/Zend',
'Application' => __DIR__ . '/../../library/Application',
'Scores' => __DIR__ . '/../../library/Scores',
'SdMetier' => __DIR__ . '/../../library/SdMetier',
'Metier' => __DIR__ . '/../../library/Metier',
),
'fallback_autoloader' => true
)
));
// Zend_Application - Use it if you don't have autoloaders
//require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Aide.",
'path=s' => "{Service Name}/{version}",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if( count($opts->getOptions())==0 || isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
$wsPath = APPLICATION_PATH . '/../library/WsScore/';
require_once $wsPath . $opts->path . '/Types.php';
$detect = new Zend_Reflection_File($wsPath . $opts->path . '/Types.php');
$result = $detect->getClasses();
$outPath = dirname($wsPath . $opts->path . '/Types.php');
$outFile = $outPath . '/Config.php';
if (count($result) > 0) {
file_put_contents($outFile, "<?php\n");
file_put_contents($outFile, "return array(\n", FILE_APPEND);
foreach ($result as $c) {
file_put_contents($outFile, "\t'". $c->name . "' => '" . $c->name ."',\n", FILE_APPEND);
}
file_put_contents($outFile, ");\n", FILE_APPEND);
}