-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make a db_driver configuration parameter optional with no_driver default value #1420
Conversation
src/Generator/NoDriverGenerator.php
Outdated
|
||
use Sonata\MediaBundle\Model\MediaInterface; | ||
use Sonata\MediaBundle\SonataMediaBundle; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@author
is missing
src/Model/NoDriverManager.php
Outdated
/** | ||
* @internal | ||
*/ | ||
class NoDriverManager implements ManagerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@author
src/Model/NoDriverManager.php
Outdated
SonataMediaBundle::noDriverRuntimeException(); | ||
} | ||
|
||
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comments about types
of vars
src/Model/NoDriverManager.php
Outdated
SonataMediaBundle::noDriverRuntimeException(); | ||
} | ||
|
||
public function find($id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment about type
src/Model/NoDriverManager.php
Outdated
SonataMediaBundle::noDriverRuntimeException(); | ||
} | ||
|
||
public function save($entity, $andFlush = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment about type
src/Model/NoDriverManager.php
Outdated
SonataMediaBundle::noDriverRuntimeException(); | ||
} | ||
|
||
public function delete($entity, $andFlush = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment about type
@@ -99,7 +99,7 @@ public function load(array $configs, ContainerBuilder $container) | |||
$loader->load('serializer.xml'); | |||
$loader->load('command.xml'); | |||
|
|||
if (!in_array(strtolower($config['db_driver']), ['doctrine_orm', 'doctrine_mongodb', 'doctrine_phpcr'])) { | |||
if (!in_array(strtolower($config['db_driver']), ['doctrine_orm', 'doctrine_mongodb', 'doctrine_phpcr', 'no_driver'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extract this array into a const
maybe, what do @sonata-project/contributors think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is how it is done in FOSUserBundle, we can move this check to Sonata\NotificationBundle\DependencyInjection\Configuration
and add constant there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ye, I would like that more, let's see what others say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better, if we don't produce any BC breaks I would prefer that way too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, forgot about this @covex-nn can you move this without doing a BC break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! i'll do it a little bit later (i must go right now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked merge, thank you for helping!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kunicmarko20 all done, please review )
src/Model/NoDriverManager.php
Outdated
|
||
public function findAll() | ||
{ | ||
SonataMediaBundle::noDriverRuntimeException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we generate a new Exception class for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error will be shown to developer in a browser, if a pack with additional configuration was not installed. Here is a screenshot how it is decorated by symfony/debug
in dev environment:
That message could be updated! We could add instructions how to install a pack =)
But, i agree, that method should be removed. Can i use Sonata\CoreBundle\Exception\InvalidParameterException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought more about new exception class, NoDriverException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new NoDriverException
tests/Model/NoDriverManagerTest.php
Outdated
{ | ||
$this->expectException('Sonata\MediaBundle\Exception\NoDriverException'); | ||
|
||
$manager = new NoDriverManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this var is not needed, can you just move new NoDriverManager()
to method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed =)
tests/Model/NoDriverManagerTest.php
Outdated
*/ | ||
public function testException($method, array $arguments) | ||
{ | ||
$this->expectException('Sonata\MediaBundle\Exception\NoDriverException'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use NoDriverException::class
{ | ||
public function testException() | ||
{ | ||
$this->expectException('Sonata\MediaBundle\Exception\NoDriverException'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, use ::class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocked to avoid merge
->defaultValue('no_driver') | ||
->validate() | ||
->ifNotInArray(self::DB_DRIVERS) | ||
->thenInvalid('SonataMediaBundle - Invalid db driver %s.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it throw the same exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before my changes there was \InvalidArgumentException
, and now it will throw a same exception, see https://github.com/symfony/config/blob/master/Definition/Builder/ExprBuilder.php#L187, but before container compilation started
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
src/Exception/NoDriverException.php
Outdated
/** | ||
* @author Andrey F. Mindubaev <[email protected]> | ||
*/ | ||
class NoDriverException extends \RuntimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/Generator/NoDriverGenerator.php
Outdated
* | ||
* @author Andrey F. Mindubaev <[email protected]> | ||
*/ | ||
class NoDriverGenerator implements GeneratorInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final?
src/Model/NoDriverManager.php
Outdated
* | ||
* @author Andrey F. Mindubaev <[email protected]> | ||
*/ | ||
class NoDriverManager implements ManagerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final?
I pushed a commit with recipe for MediaBundle; after new version will be released i will create a PR
|
I think we need to mention that uploads folder should be writable |
@@ -32,7 +37,13 @@ public function getConfigTreeBuilder() | |||
|
|||
$node | |||
->children() | |||
->scalarNode('db_driver')->isRequired()->end() | |||
->scalarNode('db_driver') | |||
->defaultValue('no_driver') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a call to info()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added ->info('Choose persistence mechanism driver from the following list: "doctrine_orm", "doctrine_mongodb", "doctrine_phpcr"')
src/Exception/NoDriverException.php
Outdated
{ | ||
const DEFAULT_MESSAGE = 'The child node "db_driver" at path "sonata_media" must be configured.'; | ||
|
||
public function __construct($message = self::DEFAULT_MESSAGE, $code = 0, \Throwable $previous = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\Throwable
is not available with php 5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/Exception/NoDriverException.php
Outdated
*/ | ||
final class NoDriverException extends \RuntimeException | ||
{ | ||
const DEFAULT_MESSAGE = 'The child node "db_driver" at path "sonata_media" must be configured.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why put this in a constant? It's public now, and it's only ever used once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a default value for message. I set it once and use it each time when i throw this exception just with new NoDriverException();
without setting first argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but why not do this: https://3v4l.org/WmvS8 or this: https://3v4l.org/ROnrq?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just i did not think, that it is important. Next time i will try not to create new not necessary entities. Fixed
src/Resources/config/no_driver.xml
Outdated
<services> | ||
<service id="sonata.media.manager.media" class="Sonata\MediaBundle\Model\NoDriverManager"/> | ||
<service id="sonata.media.manager.gallery" class="Sonata\MediaBundle\Model\NoDriverManager"/> | ||
<service id="sonata.media.generator.default" class="Sonata\MediaBundle\Generator\NoDriverGenerator"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mark service than can be private as such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greg0ire only sonata.media.generator.default
can be private, two others must be public. I added public="true"
there
@@ -0,0 +1,3 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |||
</container> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is loaded from SonataMediaExtension.php when SonataAdminBundle is enabled. So, i created an empty file for that case. <container />
tag can be empty. See http://symfony.com/schema/dic/services/services-1.0.xsd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an XML comment to explain this, hopefully xmllint will not remove it.
f602634
@@ -1,3 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |||
<!-- | |||
This file will be loaded when SonataAdminBundle is enabled and db_driver has it's default value, not corresponding to real persistence mechanism. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- it's => its
- linebreak that line 4
and we're good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Thanks @covex-nn ! |
I am targeting this branch, because this is BC.
Closes #1419
Changelog
To do
Subject
To create a recipe for Symfony Flex, it should be possible to create a default configuration, that allows to run
cache:clear
without errors (see sonata-project/dev-kit#409) A default value fordb_driver
configuration parameter will allow this.If this PR will be accepted, a default configuration, i.e. a recipe for
sonata-media/media-bundle
could be like this (please fix me, it there something wrong here; may beproviders
orformats
sections should be changed to more commonly used?):Additional configuration, i.e. a recipe for a new package
sonata-project/media-orm-pack
could be like this (i created a gist with entity classes):