Skip to content
Browse files

Getting phpcr bin usable when installed via Composer

The phpcr bin is now installed when phpcr-odm is installed
via Composer.

The entire process is a little less DRY as the root folder
bootstrap.php has been removed in favor of having that
code live both in bin/phpcr and in tests/bootstrap.php.
This was done to remove the requirement that the
cli-config.php scripts require bootstrap.php individually.
  • Loading branch information...
1 parent fa22ffd commit 13875c38a65451afb5271bf2ac86a32ad7ef7b3d @simensen simensen committed Sep 12, 2012
View
44 bin/phpcr
@@ -1,46 +1,4 @@
#!/usr/bin/env php
<?php
-$configFile = __DIR__ . DIRECTORY_SEPARATOR . '/../cli-config.php';
-
-$helperSet = null;
-if (file_exists($configFile)) {
- if (!is_readable($configFile)) {
- trigger_error(
- 'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR
- );
- }
-
- require $configFile;
-
- foreach ($GLOBALS as $helperSetCandidate) {
- if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
- $helperSet = $helperSetCandidate;
- break;
- }
- }
-} else {
- trigger_error(
- 'Configuration file [' . $configFile . '] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration', E_USER_ERROR
- );
-}
-
-$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
-
-$cli = new \Symfony\Component\Console\Application('Doctrine ODM PHPCR Command Line Interface', Doctrine\ODM\PHPCR\Version::VERSION);
-$cli->setCatchExceptions(true);
-$cli->setHelperSet($helperSet);
-$cli->addCommands(array(
- new \PHPCR\Util\Console\Command\CreateWorkspaceCommand(),
- new \PHPCR\Util\Console\Command\ImportXmlCommand(),
- new \PHPCR\Util\Console\Command\DumpCommand(),
- new \PHPCR\Util\Console\Command\PurgeCommand(),
- new \PHPCR\Util\Console\Command\RegisterNodeTypesCommand(),
- new \PHPCR\Util\Console\Command\QueryCommand(),
- new \Doctrine\ODM\PHPCR\Tools\Console\Command\RegisterSystemNodeTypesCommand(),
-));
-if (isset($extraCommands) && ! empty($extraCommands)) {
- $cli->addCommands($extraCommands);
-}
-$cli->run();
-
+include('phpcr.php');
View
54 bin/phpcr.php
@@ -0,0 +1,54 @@
+<?php
+
+($autoload = @include_once __DIR__ . '/../vendor/autoload.php') || $autoload = @include_once __DIR__ . '/../../../autoload.php';
+if (!$autoload) {
+ throw new RuntimeException('Install dependencies to run phpcr.');
+}
+
+use Doctrine\Common\Annotations\AnnotationRegistry;
+AnnotationRegistry::registerLoader(array($autoload, 'loadClass'));
+AnnotationRegistry::registerFile(__DIR__.'/../lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');
+
+$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
+
+$helperSet = null;
+if (file_exists($configFile)) {
+ if (!is_readable($configFile)) {
+ trigger_error(
+ 'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR
+ );
+ }
+
+ require $configFile;
+
+ foreach ($GLOBALS as $helperSetCandidate) {
+ if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
+ $helperSet = $helperSetCandidate;
+ break;
+ }
+ }
+} else {
+ trigger_error(
+ 'Configuration file [' . $configFile . '] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration', E_USER_ERROR
+ );
+}
+
+$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
+
+$cli = new \Symfony\Component\Console\Application('Doctrine ODM PHPCR Command Line Interface', Doctrine\ODM\PHPCR\Version::VERSION);
+$cli->setCatchExceptions(true);
+$cli->setHelperSet($helperSet);
+$cli->addCommands(array(
+ new \PHPCR\Util\Console\Command\CreateWorkspaceCommand(),
+ new \PHPCR\Util\Console\Command\ImportXmlCommand(),
+ new \PHPCR\Util\Console\Command\DumpCommand(),
+ new \PHPCR\Util\Console\Command\PurgeCommand(),
+ new \PHPCR\Util\Console\Command\RegisterNodeTypesCommand(),
+ new \PHPCR\Util\Console\Command\QueryCommand(),
+ new \Doctrine\ODM\PHPCR\Tools\Console\Command\RegisterSystemNodeTypesCommand(),
+));
+if (isset($extraCommands) && ! empty($extraCommands)) {
+ $cli->addCommands($extraCommands);
+}
+$cli->run();
+
View
18 bootstrap.php
@@ -1,18 +0,0 @@
-<?php
-
-$file = './vendor/autoload.php';
-if (file_exists($file)) {
- $autoload = require_once $file;
-} else {
- throw new RuntimeException('Install dependencies to run test suite.');
-}
-
-use Doctrine\Common\Annotations\AnnotationRegistry;
-
-AnnotationRegistry::registerLoader(function($class) use ($autoload) {
- $autoload->loadClass($class);
- return class_exists($class, false);
-});
-AnnotationRegistry::registerFile(__DIR__.'/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');
-
-return $autoload;
View
2 cli-config.doctrine_dbal.php.dist
@@ -7,8 +7,6 @@
* Add instances of commands for eventual implementation specific commands to this array.
*/
-require_once __DIR__.'/bootstrap.php';
-
$extraCommands = array();
$extraCommands[] = new \Jackalope\Tools\Console\Command\InitDoctrineDbalCommand();
View
2 cli-config.jackrabbit.php.dist
@@ -7,8 +7,6 @@
* Add instances of commands for eventual implementation specific commands to this array.
*/
-require_once __DIR__.'/bootstrap.php';
-
$extraCommands = array();
$extraCommands[] = new \Jackalope\Tools\Console\Command\JackrabbitCommand();
View
2 cli-config.midgard_mysql.php.dist
@@ -7,8 +7,6 @@
* Add instances of commands for eventual implementation specific commands to this array.
*/
-require_once __DIR__.'/bootstrap.php';
-
$extraCommands = array();
$params = array(
View
2 cli-config.midgard_sqlite.php.dist
@@ -7,8 +7,6 @@
* Add instances of commands for eventual implementation specific commands to this array.
*/
-require_once __DIR__.'/bootstrap.php';
-
$extraCommands = array();
$params = array(
View
1 composer.json
@@ -29,6 +29,7 @@
"autoload": {
"psr-0": { "Doctrine\\ODM\\PHPCR": "lib/" }
},
+ "bin": ["bin/phpcr", "bin/phpcr.php"],
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
View
11 tests/bootstrap.php
@@ -1,6 +1,15 @@
<?php
-$autoload = require_once __DIR__.'/../bootstrap.php';
+$file = __DIR__.'/../vendor/autoload.php';
+if (file_exists($file)) {
+ $autoload = require_once $file;
+} else {
+ throw new RuntimeException('Install dependencies to run test suite.');
+}
+
+use Doctrine\Common\Annotations\AnnotationRegistry;
+AnnotationRegistry::registerLoader(array($autoload, 'loadClass'));
+AnnotationRegistry::registerFile(__DIR__.'/../lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');
// tests are not autoloaded the composer.json
$autoload->add('Doctrine\Tests', __DIR__);

0 comments on commit 13875c3

Please sign in to comment.
Something went wrong with that request. Please try again.