How to handle the Xml Parser Orchestra through the Laravel IoC Container

I am using laravel 5.1. I want to use an XML parser, and I searched and found Orchestra as it is mostly used. Therefore, I examined in detail all the steps indicated in the documentation for installation and configuration. I added the Orchestra\Parser\XmlServiceProvider::class section to the providers in the config/app.php and the 'XmlParser' => Orchestra\Parser\Xml\Facade::class in aliases .

Now in my controller I added my namespace, for example use Orchestra\Parser\Xml\Facade; at the top of my controller. But when I try to use its function in my action, for example

 $xml = XmlParser::load($xml_document); 

It generates an error message,

 Class 'App\Http\Controllers\XmlParser' not found 

So, I want to know if there is another way in Laravel 5.1 use packages, and I am doing something wrong with Orchestra if someone used it.

+4
source share
3 answers

Since the documentation already describes how to register a facade alias:

 'XmlParser' => Orchestra\Parser\Xml\Facade::class, 

You can use \XmlParser::load() or import an alias.

 use XmlParser; 

or import the full namespace.

 use Orchestra\Parser\Xml\Facade as XmlParser; 
+16
source

It looks like he is looking inside the controllers for him.

Class 'App \ Http \ Controllers \ XmlParser' not found

Thus:

$xml = XmlParser::load($xml_document);

Must be:

$xml = \XmlParser::load($xml_document);

Need to solve this problem

+1
source

In Laravel 5.1, the controller is in the namespace. XmlParser is in a different namespace. You must include this namespace in your controller.

 <?php namespace Orchestra\Parser\Xml; // Maybe this one is different class Controller... 

You can also add the \ file to make it work.

 $xml = XmlParser::load($xml_document); 
-one
source

All Articles