Closed 7ochem closed 5 years ago
If you want to contribute this, you can start by making a PR on the stable branch with this:
@trigger_error(sprintf(
'Calling "%s" with an invalid admin code is deprecated since sonata-project/admin-bundle 3.x and will throw an exception in 4.0',
__METHOD__
), E_USER_DEPRECATED);
Also, a new hasAdminByAdminCode()
method should be introduced.
If you want to contribute this [...]
I'd really like to. Just wanted to check if this is a good idea to you too.
Also, a new
hasAdminByAdminCode()
method should be introduced.
Good point. I'll add that too.
B.t.w. there's no 4.0 branch to contribute the actual code to, right?
This should go into 3.x branch šš»
B.t.w. there's no 4.0 branch to contribute the actual code to, right?
It's called master :wink: , but you would have to do what I said on 3.x first, then wait for 3.x to be merged on master (happens nightly), and then make the PR on master.
I will be waiting on #5543 before issuing a PR for the 3.x branch
@7ochem, #5543 is now merged :+1:
Throw exception vs. return false
Environment
Subject
I ran into this when I got the infamous PHP Warning:
On the line above I was trying to retrieve a Sonata admin from the Admin Pool:
So calling
\Sonata\AdminBundle\Admin\Pool::getAdminByAdminCode()
could return\Sonata\AdminBundle\Admin\AdminInterface
or booleanfalse
. You would say that in my code I should add a check for afalse
value returned bygetAdminByAdminCode()
, but I think the method should be improved and not returnfalse
but throw exceptions, because:false
checks in my code when I use this method.false
I have to write my own messages (to be written to a log) on all places where I use the method.public function getAdminByAdminCode(string $adminCode) : AdminInterface
https://github.com/sonata-project/SonataAdminBundle/blob/b6bc0297d524fdcf361d77a5181508ba58bcf6a5/src/Admin/Pool.php#L236-L255
I'm not issuing this as a bug, but a feature request, because implementing throwing errors will break things.