-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a24a6a
commit 29d4fcb
Showing
2 changed files
with
178 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,228 @@ | ||
.. index:: | ||
single: Introduction | ||
single: AppKernel | ||
single: Installation | ||
|
||
Installation | ||
============ | ||
|
||
Prerequisites | ||
------------- | ||
|
||
PHP 7.1 and Symfony >=3.4 or >= 4.2 are needed to make this bundle work, there are | ||
also some Sonata dependencies that need to be installed and configured beforehand: | ||
PHP 7.2 and Symfony 4.4 are needed to make this bundle work. | ||
|
||
* `SonataEasyExtendsBundle <https://sonata-project.org/bundles/easy-extends>`_ | ||
|
||
Add ``SonataClassificationBundle`` via composer: | ||
|
||
.. code-block:: bash | ||
Add ``SonataClassificationBundle`` via composer:: | ||
|
||
composer require sonata-project/classification-bundle | ||
|
||
Now, add the new ``SonataClassificationBundle`` to ``bundles.php`` file:: | ||
|
||
|
||
// config/bundles.php | ||
|
||
return [ | ||
// ... | ||
Sonata\ClassificationBundle\SonataClassificationBundle::class => ['all' => true], | ||
]; | ||
|
||
.. note:: | ||
|
||
If you are not using Symfony Flex, you should enable bundles in your | ||
``AppKernel.php``. | ||
|
||
.. code-block:: php | ||
// app/AppKernel.php | ||
public function registerBundles() | ||
{ | ||
return [ | ||
new Sonata\ClassificationBundle\SonataClassificationBundle(), | ||
// ... | ||
]; | ||
} | ||
Configuration | ||
------------- | ||
|
||
Doctrine Configuration | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
Add these bundles in the config mapping definition (or enable `auto_mapping`_): | ||
SonataClassificationBundle Configuration | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: yaml | ||
# config/packages/sonata_classification.yaml | ||
sonata_classification: | ||
class: | ||
tag: App\Entity\SonataClassificationTag | ||
category: App\Entity\SonataClassificationCategory | ||
collection: App\Entity\SonataClassificationCollection | ||
context: App\Entity\SonataClassificationContext | ||
Doctrine ORM Configuration | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Add these bundles in the config mapping definition (or enable `auto_mapping`_):: | ||
|
||
# config/packages/doctrine.yaml | ||
|
||
doctrine: | ||
orm: | ||
entity_managers: | ||
default: | ||
mappings: | ||
ApplicationSonataClassificationBundle: ~ | ||
SonataClassificationBundle: ~ | ||
|
||
.. note:: | ||
And then create the corresponding entities, ``src/Entity/SonataClassificationTag``:: | ||
|
||
If you are not using Symfony Flex, this configuration should be added | ||
to ``app/config/config.yml``. | ||
// src/Entity/SonataClassificationTag.php | ||
|
||
Extending the Bundle | ||
-------------------- | ||
At this point, the bundle is functional, but not quite ready yet. You need to | ||
generate the correct entities for the media: | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sonata\ClassificationBundle\Entity\BaseTag; | ||
|
||
.. code-block:: bash | ||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="classification__tag") | ||
*/ | ||
class SonataClassificationTag extends BaseTag | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
protected $id; | ||
} | ||
|
||
bin/console sonata:easy-extends:generate SonataClassificationBundle --dest=src --namespace_prefix=App | ||
``src/Entity/SonataClassificationCategory``:: | ||
|
||
.. note:: | ||
// src/Entity/SonataClassificationCategory.php | ||
|
||
If you are not using Symfony Flex, use command without ``--namespace_prefix=App``. | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sonata\ClassificationBundle\Entity\BaseCategory; | ||
|
||
With provided parameters, the files are generated in ``src/Application/Sonata/ClassificationBundle``. | ||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="classification__category") | ||
*/ | ||
class SonataClassificationCategory extends BaseCategory | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
protected $id; | ||
} | ||
|
||
.. note:: | ||
``src/Entity/SonataClassificationCollection``:: | ||
|
||
The command will generate domain objects in ``App\Application`` namespace. | ||
So you can point entities' associations to a global and common namespace. | ||
This will make Entities sharing easier as your models will allow to | ||
point to a global namespace. For instance the tag will be | ||
``App\Application\Sonata\ClassificationBundle\Entity\Tag``. | ||
// src/Entity/SonataClassificationCollection.php | ||
|
||
.. note:: | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sonata\ClassificationBundle\Entity\BaseCollection; | ||
|
||
If you are not using Symfony Flex, the namespace will be ``Application\Sonata\ClassificationBundle\Entity``. | ||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="classification__collection") | ||
*/ | ||
class SonataClassificationCollection extends BaseCollection | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
protected $id; | ||
} | ||
|
||
Now, add the new ``Application`` Bundle into the ``bundles.php``:: | ||
and ``src/Entity/SonataClassificationContext``:: | ||
|
||
// config/bundles.php | ||
// src/Entity/SonataClassificationContext.php | ||
|
||
return [ | ||
// ... | ||
App\Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle::class => ['all' => true], | ||
]; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sonata\ClassificationBundle\Entity\BaseContext; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="classification__context") | ||
*/ | ||
class SonataClassificationContext extends BaseContext | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
protected $id; | ||
} | ||
|
||
The only thing left is to update your schema:: | ||
|
||
.. note:: | ||
bin/console doctrine:schema:update --force | ||
|
||
If you are not using Symfony Flex, add the new ``Application`` Bundle into your | ||
``AppKernel.php``. | ||
Doctrine MongoDB Configuration | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: php | ||
You have to create the corresponding documents, ``src/Document/SonataClassificationTag``:: | ||
|
||
// app/AppKernel.php | ||
// src/Document/SonataClassificationTag.php | ||
|
||
class AppKernel { | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Sonata\ClassificationBundle\Document\BaseTag; | ||
|
||
public function registerBundles() | ||
{ | ||
return [ | ||
// Application Bundles | ||
// ... | ||
new Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle(), | ||
// ... | ||
]; | ||
} | ||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class SonataClassificationTag extends BaseTag | ||
{ | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
} | ||
|
||
And configure ``ClassificationBundle`` to use the newly generated classes: | ||
``src/Document/SonataClassificationCategory``:: | ||
|
||
.. code-block:: yaml | ||
// src/Document/SonataClassificationCategory.php | ||
|
||
# config/packages/sonata.yaml | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Sonata\ClassificationBundle\Document\BaseCategory; | ||
|
||
sonata_classification: | ||
class: | ||
tag: App\Application\Sonata\ClassificationBundle\Entity\Tag | ||
category: App\Application\Sonata\ClassificationBundle\Entity\Category | ||
collection: App\Application\Sonata\ClassificationBundle\Entity\Collection | ||
context: App\Application\Sonata\ClassificationBundle\Entity\Context | ||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class SonataClassificationCategory extends BaseCategory | ||
{ | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
} | ||
|
||
``src/Document/SonataClassificationCollection``:: | ||
|
||
.. note:: | ||
// src/Document/SonataClassificationCollection.php | ||
|
||
If you are not using Symfony Flex, add classes without the ``App\`` | ||
part and this configuration should be added to ``app/config/config.yml`` | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Sonata\ClassificationBundle\Document\BaseCollection; | ||
|
||
The only thing left is to update your schema: | ||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class SonataClassificationCollection extends BaseCollection | ||
{ | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
} | ||
|
||
.. code-block:: bash | ||
and ``src/Document/SonataClassificationContext``:: | ||
|
||
bin/console doctrine:schema:update --force | ||
// src/Document/SonataClassificationContext.php | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
use Sonata\ClassificationBundle\Document\BaseContext; | ||
|
||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class SonataClassificationContext extends BaseContext | ||
{ | ||
/** | ||
* @MongoDB\Id | ||
*/ | ||
protected $id; | ||
} | ||
|
||
And then configure ``ClassificationBundle`` to use the newly generated classes:: | ||
|
||
# config/packages/sonata_classification.yaml | ||
|
||
sonata_classification: | ||
class: | ||
tag: App\Document\SonataClassificationTag | ||
category: App\Document\SonataClassificationCategory | ||
collection: App\Document\SonataClassificationCollection | ||
context: App\Document\SonataClassificationContext | ||
|
||
.. _`auto_mapping`: http://symfony.com/doc/2.0/reference/configuration/doctrine.html#configuration-overview | ||
.. _`auto_mapping`: http://symfony.com/doc/4.4/reference/configuration/doctrine.html#configuration-overviews |