Permalink
Browse files

Plugging the configuration system into the ClassMapBuild CLI command.

  • Loading branch information...
1 parent 66b9a5a commit 7db908548f12050d2f5330c3816a9649385d944a @zyxist zyxist committed Jul 9, 2011
Showing with 38 additions and 67 deletions.
  1. +24 −54 src/Opl/Autoloader/Command/ClassMapBuild.php
  2. +0 −12 tests/data/classMap.ini
  3. +1 −1 tests/data/classMap.txt
  4. +13 −0 tests/data/config.xml
@@ -11,12 +11,14 @@
*/
namespace Opl\Autoloader\Command;
use Opl\Autoloader\Toolset\ClassMapBuilder;
+use Opl\Autoloader\Toolset\Configuration;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command;
+use RuntimeException;
/**
* This command line interface command is responsible for building
@@ -29,38 +31,21 @@
class ClassMapBuild extends Command
{
/**
- * The class map builder.
- * @var ClassMapBuilder
- */
- protected $_builder;
-
- /**
* @see Command
*/
protected function configure()
{
$this->ignoreValidationErrors = true;
$this->setDefinition(array(
- new InputArgument('definition', InputArgument::REQUIRED, 'The class map definition INI file'),
+ new InputArgument('configuration', InputArgument::REQUIRED, 'The Open Power Autoloader configuration'),
))
->setName('opl:autoloader:build-class-map')
->setDescription('Generates the class map for the ClassMapLoader')
->setHelp(<<<EOF
The <info>autoloader:class-map:build</info> command is responsible for building
-the class maps for the ClassMapLoader autoloader. The configuration is given as
-an INI file, where each entry represents a single top-level namespace and a path to its code:
-
- [config]
- outputFile = "./data/classMap.txt"
- extension = "./php"
-
- [namespaces]
- Opl = "../libs/"
- Foo = "../libs/"
- Bar = "../other/"
-
-It is recommended for the paths to have the trailing slashes prepended.
+the class maps for the ClassMapLoader autoloader. The configuration file is an
+XML document. Please refer to the OPA user manual to get to know more.
EOF
);
} // end configure();
@@ -70,54 +55,39 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $definition = $input->getArgument('definition');
- if(!$definition)
+ try
{
- $output->writeln('<error>No definition file specified!</error>');
- return;
+ $configuration = new Configuration($input->getArgument('configuration'));
}
-
- if(!file_exists($definition))
+ catch(RuntimeException $exception)
{
- $output->writeln('<error>The specified definition file does not exist!</error>');
+ $output->writeln('<error>An error occured: '.$exception->getMessage().'</error>');
+ return;
}
- $data = parse_ini_file($definition, true);
- if(!is_array($data))
+
+ if(!$configuration->hasFile('serialized-class-map'))
{
- $output->writeln('<error>Invalid INI structure in the definition file!</error>');
+ $output->writeln('<error>Serialized class map file definition is missing in the configuration file!</error>');
+ $output->writeln('Hint: add \'serialized-class-map\' file type to export-files section.');
+ return;
}
- $extension = 'php';
- $outputFile = './class-map.txt';
- if(isset($data['config']))
+ $builder = new ClassMapBuilder();
+
+ foreach($configuration->getSeparators() as $separator)
{
- if(isset($data['config']['extension']))
- {
- $extension = $data['config']['extension'];
- }
- if(isset($data['config']['outputFile']))
+ foreach($configuration->getSeparatorNamespaces($separator) as $name => $namespace)
{
- $outputFile = $data['config']['outputFile'];
+ $builder->addNamespace($name, $namespace['path'], $namespace['extension']);
}
}
-
- if(!isset($data['namespaces']))
- {
- $output->writeln('<error>No namespaces specified!</error>');
- }
-
- $this->_builder = new ClassMapBuilder();
- foreach($data['namespaces'] as $name => $path)
- {
- $this->_builder->addNamespace($name, $path, $extension);
- }
- $errors = $this->_builder->buildMap();
+ $errors = $builder->buildMap();
foreach($errors as $error)
{
- $output->writeln(preg_replace('/^(([^\:]+)\:) (.*)$/', '<error>$1</error> $3', $error));
+ $output->writeln(preg_replace('/^(([^\:]+)\:) (.*)$/', '<error>Warning: $1</error> $3', $error));
}
- file_put_contents($outputFile, serialize($this->_builder->getMap()));
- $output->writeln('<info>Map saved as:</info> '.$outputFile);
+ file_put_contents($configuration->getFile('serialized-class-map'), serialize($builder->getMap()));
+ $output->writeln('<info>Map saved as:</info> '.$configuration->getFile('serialized-class-map'));
} // end execute();
} // end ClassMapBuild;
View
@@ -1,12 +0,0 @@
-; This is a sample class map definition for the
-; class map autoloader.
-
-[config]
-; Where the map should be stored
-outputFile = "./data/classMap.txt"
-
-; The recognized file extension
-extension = ".php"
-
-[namespaces]
-Dummy = "./data/"
View
@@ -1 +1 @@
-a:6:{s:29:"Dummy\DifferentNamespaceStyle";a:2:{i:0;s:5:"Dummy";i:1;s:33:"Dummy/DifferentNamespaceStyle.php";}s:32:"Dummy\Subdirectory\SubdirSupport";a:2:{i:0;s:5:"Dummy";i:1;s:36:"Dummy/Subdirectory/SubdirSupport.php";}s:30:"Dummy_Subdirectory_NoNamespace";a:2:{i:0;s:5:"Dummy";i:1;s:34:"Dummy/Subdirectory/NoNamespace.php";}s:15:"Dummy\ShortFile";a:2:{i:0;s:5:"Dummy";i:1;s:19:"Dummy/ShortFile.php";}s:21:"Dummy\AnotherLongFile";a:2:{i:0;s:5:"Dummy";i:1;s:25:"Dummy/AnotherLongFile.php";}s:14:"Dummy\LongFile";a:2:{i:0;s:5:"Dummy";i:1;s:18:"Dummy/LongFile.php";}}
+a:6:{s:14:"Dummy\LongFile";a:2:{i:0;s:5:"Dummy";i:1;s:18:"Dummy/LongFile.php";}s:32:"Dummy\Subdirectory\SubdirSupport";a:2:{i:0;s:5:"Dummy";i:1;s:36:"Dummy/Subdirectory/SubdirSupport.php";}s:30:"Dummy_Subdirectory_NoNamespace";a:2:{i:0;s:5:"Dummy";i:1;s:34:"Dummy/Subdirectory/NoNamespace.php";}s:15:"Dummy\ShortFile";a:2:{i:0;s:5:"Dummy";i:1;s:19:"Dummy/ShortFile.php";}s:29:"Dummy\DifferentNamespaceStyle";a:2:{i:0;s:5:"Dummy";i:1;s:33:"Dummy/DifferentNamespaceStyle.php";}s:21:"Dummy\AnotherLongFile";a:2:{i:0;s:5:"Dummy";i:1;s:25:"Dummy/AnotherLongFile.php";}}
View
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <export-files>
+ <file type="serialized-class-map">./classMap.txt</file>
+ <file type="chdb-class-map">./classMap.chdb</file>
+ <file type="core-dump">./coreDump.txt</file>
+ <file type="core-export">./core.php</file>
+ </export-files>
+
+ <separator value="\">
+ <namespace name="Dummy">./</namespace>
+ </separator>
+</autoload>

0 comments on commit 7db9085

Please sign in to comment.