contao / managed-edition

Contao Managed Edition
17 stars 14 forks source link

Definition of class in Service.yml #38

Closed hoss-ps closed 6 years ago

hoss-ps commented 6 years ago

Since Contao version 4.6 working with Symfony >4, ill get bellow issue: I define "loadDataContainer" hooks in my config file and in service.yml (all classes are defined correctly under "EventListener" and "DependencyInjection" same as the previous version) and I get an error during installation like : Attempted to load class "<class defined in yml file>" from the global namespace. Did you forget a "use" statement?" after research about this error in Symfony , i understand we need to add key "public: true" in yaml file for DCA service. and after i make it public, i could install the bundle but receive a new error which says" undefined TL_MODE" and since we use word "TRUE" in .yml file, we cant bypass error.

leofeyer commented 6 years ago

Can you please post the stack strace or at least tell us which class "class defined in yml file" is?

hoss-ps commented 6 years ago

Step 1 : My config file contains $GLOBALS['TL_HOOKS']['loadDataContainer'][] = array('BackJin_isotopePlaceOrder.listener.setPlOrder', 'onSetPlOrder');

service.yml contains :

`services: BackJin_isotopePlaceOrder.listener.setPlOrder: class: BackJin\IsotopePlaceOrder\EventListener\SetPlOrder arguments:

and error i have got during register (update) my bundle is (can't complete install):

[Symfony\Component\Debug\Exception\ClassNotFoundException] Attempted to load class "BackJin_isotopePlaceOrder.listener.setPlOrder" from the global namespace. Did you forget a "use" statement?

Step2. My config file contains :

$GLOBALS['TL_HOOKS']['loadDataContainer'][] = array('BackJin_isotopePlaceOrder.listener.setPlOrder', 'onSetPlOrder');

service.yml contains :

`services: BackJin_isotopePlaceOrder.listener.setPlOrder: class: BackJin\IsotopePlaceOrder\EventListener\SetPlOrder public: true arguments:

I can complete update or install but i have got these notice :

Notice: Use of undefined constant TL_MODE - assumed 'TL_MODE' in C:\project\contao\vendor\symfony\symfony\src\Symfony\Component\Config\Resource\ReflectionClassResource.php on line 142 Notice: Use of undefined constant TL_MODE - assumed 'TL_MODE' in C:\project\contao\vendor\symfony\symfony\src\Symfony\Component\Config\Resource\ReflectionClassResource.php on line 146

since i dont remove word 'true' from yml file in frontend and backend also get bellow error :

(1/1) FatalErrorExceptionError: Method ReflectionMethod::__toString() must not throw an exception, caught ErrorException: Notice: Use of undefined constant TL_MODE - assumed 'TL_MODE' in ReflectionClassResource.php line 142

notice: currently I only get the error in "loadDataContainer" hooks,

aschempp commented 6 years ago

I've provided an improvement in https://github.com/contao/core-bundle/pull/1652, can you test it locally?

hoss-ps commented 6 years ago

i did test locally and for Step 1 : the issue is solved, but whenever make it public in service (public = true ), I receive Step 2 issue.

aschempp commented 6 years ago

Are you using TL_MODE in your class somewhere? What does the class look like?

hoss-ps commented 6 years ago

No, I use Isotope bundle and backends. by the way, only word true, in service cause this issue. when I make any of my services public, it will get the same error.

aschempp commented 6 years ago

well if you set it to false then the service is not found/loaded at all …

hoss-ps commented 6 years ago

if im not mistaken, "loadDataContainer" or DCA services need to be public before your changes. by the way, my other services which is work with the last version of Symfony, will get the same error after set it as public in services. could you please confirm, its service issue or Contao bug? notice: the bellow error appear to all my other services too, FatalErrorExceptionError: Method ReflectionMethod::__toString() must not throw an exception, caught ErrorException: Notice: Use of undefined constant TL_MODE - assumed 'TL_MODE' in ReflectionClassResource.php line 142

aschempp commented 6 years ago

I can't tell you where the issue is from. Somewhere someone is using the TL_MODE constant without the Contao framework being initialized. You have to debug your code to find that …

fritzmg commented 6 years ago

Also please use three backticks for your code and error messages, not just one.