Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
0df18862
Commit
0df18862
authored
May 14, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/doctrine-dbal-cli'
Close #598
parents
5d12e3f9
0a108b48
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
70 deletions
+167
-70
doctrine-dbal
bin/doctrine-dbal
+1
-1
doctrine-dbal.php
bin/doctrine-dbal.php
+58
-27
doctrine.php
bin/doctrine.php
+0
-42
composer.json
composer.json
+1
-0
ConsoleRunner.php
lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php
+107
-0
No files found.
bin/doctrine-dbal
100644 → 100755
View file @
0df18862
#!/usr/bin/env php
<?php
include
(
'doctrine-dbal.php'
);
\ No newline at end of file
require
__DIR__
.
'/doctrine-dbal.php'
;
bin/doctrine-dbal.php
View file @
0df18862
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
require_once
'Doctrine/Common/ClassLoader.php'
;
use
Symfony\Component\Console\Helper\HelperSet
;
use
Doctrine\DBAL\Tools\Console\ConsoleRunner
;
$classLoader
=
new
\Doctrine\Common\ClassLoader
(
'Doctrine'
);
$classLoader
->
register
();
$files
=
array
(
__DIR__
.
'/../vendor/autoload.php'
,
__DIR__
.
'/../../../autoload.php'
);
$loader
=
null
;
$cwd
=
getcwd
();
$directories
=
array
(
$cwd
,
$cwd
.
DIRECTORY_SEPARATOR
.
'config'
);
$configFile
=
null
;
$classLoader
=
new
\Doctrine\Common\ClassLoader
(
'Symfony'
);
$classLoader
->
register
();
foreach
(
$files
as
$file
)
{
if
(
file_exists
(
$file
))
{
$loader
=
require
$file
;
$configFile
=
getcwd
()
.
DIRECTORY_SEPARATOR
.
'cli-config.php'
;
break
;
}
}
if
(
!
$loader
)
{
throw
new
RuntimeException
(
'vendor/autoload.php could not be found. Did you run `php composer.phar install`?'
);
}
$helperSet
=
null
;
if
(
file_exists
(
$configFile
))
{
if
(
!
is_readable
(
$configFile
))
{
trigger_error
(
'Configuration file ['
.
$configFile
.
'] does not have read permission.'
,
E_ERROR
);
foreach
(
$directories
as
$directory
)
{
$configFile
=
$directory
.
DIRECTORY_SEPARATOR
.
'cli-config.php'
;
if
(
file_exists
(
$configFile
))
{
break
;
}
}
require
$configFile
;
if
(
!
file_exists
(
$configFile
))
{
ConsoleRunner
::
printCliConfigTemplate
();
exit
(
1
);
}
if
(
!
is_readable
(
$configFile
))
{
echo
'Configuration file ['
.
$configFile
.
'] does not have read permission.'
.
PHP_EOL
;
exit
(
1
);
}
$commands
=
array
();
$helperSet
=
require
$configFile
;
if
(
!
$helperSet
instanceof
HelperSet
)
{
foreach
(
$GLOBALS
as
$helperSetCandidate
)
{
if
(
$helperSetCandidate
instanceof
\Symfony\Component\Console\Helper\
HelperSet
)
{
if
(
$helperSetCandidate
instanceof
HelperSet
)
{
$helperSet
=
$helperSetCandidate
;
break
;
}
}
}
$helperSet
=
(
$helperSet
)
?:
new
\Symfony\Component\Console\Helper\HelperSet
();
$cli
=
new
\Symfony\Component\Console\Application
(
'Doctrine Command Line Interface'
,
Doctrine\DBAL\Version
::
VERSION
);
$cli
->
setCatchExceptions
(
true
);
$cli
->
setHelperSet
(
$helperSet
);
$cli
->
addCommands
(
array
(
// DBAL Commands
new
\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
(),
new
\Doctrine\DBAL\Tools\Console\Command\ImportCommand
(),
new
\Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand
(),
));
$cli
->
run
();
ConsoleRunner
::
run
(
$helperSet
,
$commands
);
bin/doctrine.php
deleted
100644 → 0
View file @
5d12e3f9
<?php
require_once
'Doctrine/Common/ClassLoader.php'
;
$classLoader
=
new
\Doctrine\Common\ClassLoader
(
'Doctrine'
);
$classLoader
->
register
();
$classLoader
=
new
\Doctrine\Common\ClassLoader
(
'Symfony'
);
$classLoader
->
register
();
$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_ERROR
);
}
require
$configFile
;
foreach
(
$GLOBALS
as
$helperSetCandidate
)
{
if
(
$helperSetCandidate
instanceof
\Symfony\Component\Console\Helper\HelperSet
)
{
$helperSet
=
$helperSetCandidate
;
break
;
}
}
}
$helperSet
=
(
$helperSet
)
?:
new
\Symfony\Component\Console\Helper\HelperSet
();
$cli
=
new
\Symfony\Component\Console\Application
(
'Doctrine Command Line Interface'
,
Doctrine\DBAL\Version
::
VERSION
);
$cli
->
setCatchExceptions
(
true
);
$cli
->
setHelperSet
(
$helperSet
);
$cli
->
addCommands
(
array
(
// DBAL Commands
new
\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
(),
new
\Doctrine\DBAL\Tools\Console\Command\ImportCommand
(),
));
$cli
->
run
();
composer.json
View file @
0df18862
...
...
@@ -22,6 +22,7 @@
"suggest"
:
{
"symfony/console"
:
"For helpful console commands such as SQL execution and import of files."
},
"bin"
:
[
"bin/doctrine-dbal"
],
"autoload"
:
{
"psr-0"
:
{
"Doctrine
\\
DBAL
\\
"
:
"lib/"
}
},
...
...
lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php
0 → 100644
View file @
0df18862
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Tools\Console
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Tools\Console\Command\ImportCommand
;
use
Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Symfony\Component\Console\Helper\HelperSet
;
use
Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper
;
use
Symfony\Component\Console\Application
;
use
Doctrine\DBAL\Version
;
/**
* Handles running the Console Tools inside Symfony Console context.
*/
class
ConsoleRunner
{
/**
* Create a Symfony Console HelperSet
*
* @param Connection $connection
*
* @return HelperSet
*/
static
public
function
createHelperSet
(
Connection
$connection
)
{
return
new
HelperSet
(
array
(
'db'
=>
new
ConnectionHelper
(
$connection
)
));
}
/**
* Runs console with the given helperset.
*
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet
* @param \Symfony\Component\Console\Command\Command[] $commands
*
* @return void
*/
static
public
function
run
(
HelperSet
$helperSet
,
$commands
=
array
())
{
$cli
=
new
Application
(
'Doctrine Command Line Interface'
,
Version
::
VERSION
);
$cli
->
setCatchExceptions
(
true
);
$cli
->
setHelperSet
(
$helperSet
);
self
::
addCommands
(
$cli
);
$cli
->
addCommands
(
$commands
);
$cli
->
run
();
}
/**
* @param Application $cli
*
* @return void
*/
static
public
function
addCommands
(
Application
$cli
)
{
$cli
->
addCommands
(
array
(
new
RunSqlCommand
(),
new
ImportCommand
(),
new
ReservedWordsCommand
(),
));
}
/**
* Prints the instructions to create a configuration file
*/
static
public
function
printCliConfigTemplate
()
{
echo
<<<'HELP'
You are missing a "cli-config.php" or "config/cli-config.php" file in your
project, which is required to get the Doctrine-DBAL Console working. You can use the
following sample as a template:
<?php
use Doctrine\DBAL\Tools\Console\ConsoleRunner;
// replace with the mechanism to retrieve DBAL connection in your app
$connection = getDBALConnection();
// You can append new commands to $commands array, if needed
return ConsoleRunner::createHelperSet($connection);
HELP;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment