Skip to content

Commit

Permalink
Deprecate the doctrine binary (#9661)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Apr 19, 2022
1 parent 5b2bf9d commit d550364
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 87 deletions.
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade to 2.12

## Deprecated the `doctrine` binary.

The documentation explains how the console tools can be bootstrapped for
standalone usage.

The method `ConsoleRunner::printCliConfigTemplate()` is deprecated because it
was only useful in the context of the `doctrine` binary.

## Deprecate omitting `$class` argument to `ORMInvalidArgumentException::invalidIdentifierBindingEntity()`

To make it easier to identify understand the cause for that exception, it is
Expand All @@ -13,6 +21,7 @@ multiple entity managers had been deprecated with 2.9 already. This leaves
The `EntityManagerHelper` class with no purpose which is why it is now
deprecated too. Applications that still rely on the `em` console helper, can
easily recreate that class in their own codebase.

## Deprecate custom repository classes that don't extend `EntityRepository`

Although undocumented, it is currently possible to configure a custom repository
Expand Down
10 changes: 10 additions & 0 deletions bin/doctrine-pear.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

fwrite(
STDERR,
'[Warning] The use of this script is discouraged. See'
. ' https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/tools.html#doctrine-console'
. ' for instructions on bootstrapping the console runner.'
. PHP_EOL
);

echo PHP_EOL . PHP_EOL;

require_once 'Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
Expand Down
10 changes: 10 additions & 0 deletions bin/doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\ORM\Tools\Console\ConsoleRunner;

fwrite(
STDERR,
'[Warning] The use of this script is discouraged. See'
. ' https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/tools.html#doctrine-console'
. ' for instructions on bootstrapping the console runner.'
. PHP_EOL
);

echo PHP_EOL . PHP_EOL;

$autoloadFiles = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php'
Expand Down
16 changes: 2 additions & 14 deletions docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,5 @@ Setting up the Console
----------------------

Doctrine uses the Symfony Console component for generating the command
line interface. You can take a look at the ``vendor/bin/doctrine.php``
script and the ``Doctrine\ORM\Tools\Console\ConsoleRunner`` command
for inspiration how to setup the cli.

In general the required code looks like this:

.. code-block:: php
<?php
$cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($cli);
$cli->run();
line interface. You can take a look at the
:doc:`tools chapter <../reference/tools>` for inspiration how to setup the cli.
26 changes: 3 additions & 23 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,6 @@ Setting up the Commandline Tool
-------------------------------

Doctrine ships with a number of command line tools that are very helpful
during development. You can call this command from the Composer binary
directory:

.. code-block:: sh
$ php vendor/bin/doctrine
You need to register your applications EntityManager to the console tool
to make use of the tasks by creating a ``cli-config.php`` file with the
following content:

.. code-block:: php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
during development. In order to make use of them, create an executable PHP
script in your project as described in the
:doc:`tools chapter <../reference/tools>`.
79 changes: 41 additions & 38 deletions docs/en/reference/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@ Doctrine Console
The Doctrine Console is a Command Line Interface tool for simplifying common
administration tasks during the development of a project that uses ORM.

Take a look at the :doc:`Installation and Configuration <configuration>`
chapter for more information how to setup the console command.
For the following examples, we will set up the CLI as ``bin/doctrine``.

Display Help Information
~~~~~~~~~~~~~~~~~~~~~~~~

Type ``php vendor/bin/doctrine`` on the command line and you should see an
overview of the available commands or use the --help flag to get
information on the available commands. If you want to know more
about the use of generate entities for example, you can call:

.. code-block:: php
$> php vendor/bin/doctrine orm:generate-entities --help
Configuration
~~~~~~~~~~~~~
Setting Up the Console
~~~~~~~~~~~~~~~~~~~~~~

Whenever the ``doctrine`` command line tool is invoked, it can
access all Commands that were registered by a developer. There is no
Expand All @@ -34,32 +20,52 @@ Doctrine DBAL and ORM. If you want to use additional commands you
have to register them yourself.

All the commands of the Doctrine Console require access to the
``EntityManager``. You have to inject it into the console application with
``ConsoleRunner::createHelperSet``. Whenever you invoke the Doctrine
binary, it searches the current directory for the file ``cli-config.php``.
This file contains the project-specific configuration.
``EntityManager``. You have to inject it into the console application.

Here is an example of a the project-specific ``cli-config.php``:
Here is an example of a the project-specific ``bin/doctrine`` binary.

.. code-block:: php
#!/usr/bin/env php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
// replace this with the path to your own project bootstrap file.
// replace with path to your own project bootstrap file
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
$commands = [
// If you want to add your own custom console commands,
// you can do so here.
];
ConsoleRunner::run(
new SingleManagerProvider($entityManager),
$commands
);
.. note::

You have to adjust this snippet for your specific application or framework
and use their facilities to access the Doctrine EntityManager and
Connection Resources.

Display Help Information
~~~~~~~~~~~~~~~~~~~~~~~~

Type ``php bin/doctrine`` on the command line and you should see an
overview of the available commands or use the ``--help`` flag to get
information on the available commands. If you want to know more
about the use of generate entities for example, you can call:

::

$> php bin/doctrine orm:generate-entities --help

Command Overview
~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -189,38 +195,35 @@ To create the schema use the ``create`` command:

.. code-block:: php
$ php doctrine orm:schema-tool:create
$ php bin/doctrine orm:schema-tool:create
To drop the schema use the ``drop`` command:

.. code-block:: php
$ php doctrine orm:schema-tool:drop
$ php bin/doctrine orm:schema-tool:drop
If you want to drop and then recreate the schema then use both
options:

.. code-block:: php
$ php doctrine orm:schema-tool:drop
$ php doctrine orm:schema-tool:create
$ php bin/doctrine orm:schema-tool:drop
$ php bin/doctrine orm:schema-tool:create
As you would think, if you want to update your schema use the
``update`` command:

.. code-block:: php
$ php doctrine orm:schema-tool:update
$ php bin/doctrine orm:schema-tool:update
All of the above commands also accept a ``--dump-sql`` option that
will output the SQL for the ran operation.

.. code-block:: php
$ php doctrine orm:schema-tool:create --dump-sql
Before using the orm:schema-tool commands, remember to configure
your cli-config.php properly.
$ php bin/doctrine orm:schema-tool:create --dump-sql
Entity Generation
-----------------
Expand All @@ -229,9 +232,9 @@ Generate entity classes and method stubs from your mapping information.

.. code-block:: php
$ php doctrine orm:generate-entities
$ php doctrine orm:generate-entities --update-entities
$ php doctrine orm:generate-entities --regenerate-entities
$ php bin/doctrine orm:generate-entities
$ php bin/doctrine orm:generate-entities --update-entities
$ php bin/doctrine orm:generate-entities --regenerate-entities
This command is not suited for constant usage. It is a little helper and does
not support all the mapping edge cases very well. You still have to put work
Expand Down Expand Up @@ -316,7 +319,7 @@ convert to and the path to generate it:

.. code-block:: php
$ php doctrine orm:convert-mapping xml /path/to/mapping-path-converted-to-xml
$ php bin/doctrine orm:convert-mapping xml /path/to/mapping-path-converted-to-xml
Reverse Engineering
-------------------
Expand Down Expand Up @@ -366,7 +369,7 @@ You can also reverse engineer a database using the

.. code-block:: php
$ php doctrine orm:convert-mapping --from-database yml /path/to/mapping-path-converted-to-yml
$ php bin/doctrine orm:convert-mapping --from-database yml /path/to/mapping-path-converted-to-yml
.. note::

Expand Down
37 changes: 25 additions & 12 deletions docs/en/tutorials/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,35 @@ Generating the Database Schema

Doctrine has a command-line interface that allows you to access the SchemaTool,
a component that can generate a relational database schema based entirely on the
defined entity classes and their metadata. For this tool to work, a
``cli-config.php`` file must exist in the project root directory:
defined entity classes and their metadata. For this tool to work, you need to
create an executable console script as described in the
:doc:`tools chapter <../reference/tools>`.

If you created the ``bootstrap.php`` file as described in the previous section,
that script could look like this:

.. code-block:: php
#!/usr/bin/env php
<?php
// cli-config.php
require_once "bootstrap.php";
// bin/doctrine
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
// Adjust this path to your actual bootstrap.php
require __DIR__ . 'path/to/your/bootstrap.php';
ConsoleRunner::run(
new SingleManagerProvider($entityManager)
);
Now call the Doctrine command-line tool:
In the following examples, we will assume that this script has been created as
``bin/doctrine``.

::

$ vendor/bin/doctrine orm:schema-tool:create
$ php bin/doctrine orm:schema-tool:create

Since we haven't added any entity metadata in ``src`` yet, you'll see a message
stating "No Metadata Classes to process." In the next section, we'll create a
Expand All @@ -218,14 +231,14 @@ You can easily recreate the database using the following commands:

::

$ vendor/bin/doctrine orm:schema-tool:drop --force
$ vendor/bin/doctrine orm:schema-tool:create
$ php bin/doctrine orm:schema-tool:drop --force
$ php bin/doctrine orm:schema-tool:create

Or you can use the update functionality:

::

$ vendor/bin/doctrine orm:schema-tool:update --force
$ php bin/doctrine orm:schema-tool:update --force

The updating of databases uses a diff algorithm for a given
database schema. This is a cornerstone of the ``Doctrine\DBAL`` package,
Expand Down Expand Up @@ -571,7 +584,7 @@ let's update the database schema:

::

$ vendor/bin/doctrine orm:schema-tool:update --force --dump-sql
$ php bin/doctrine orm:schema-tool:update --force --dump-sql

Specifying both flags ``--force`` and ``--dump-sql`` will cause the DDL
statements to be executed and then printed to the screen.
Expand Down Expand Up @@ -1268,7 +1281,7 @@ class that holds the owning sides.
Update your database schema by running:
::

$ vendor/bin/doctrine orm:schema-tool:update --force
$ php bin/doctrine orm:schema-tool:update --force


Implementing more Requirements
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public static function addCommands(Application $cli, ?EntityManagerProvider $ent
);
}

/**
* @deprecated This method will be removed in ORM 3.0 without replacement.
*/
public static function printCliConfigTemplate(): void
{
echo <<<'HELP'
Expand Down

0 comments on commit d550364

Please sign in to comment.