buymeua / parser
Help with parse tests/files with products
Requires
- php: ^8
- ext-simplexml: *
- ext-xmlreader: *
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^9|^10
Requires (Dev)
- laravel/sail: ^1.21
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7|^8
- phpstan/phpstan: ^1.10.22
- phpunit/phpunit: ^9.0
README
This package can parse files with any format with custom adapters for example we have two adapters for xml and yml files!
Installation
- Package requires php-xmlrpc and php-mbstring (but need check before install maybe you have this packages on the your server)
sudo apt-get install php-xmlrpc php-mbstring
- You can install this package via composer using this command:
composer require buymeua/parser
-
The package will automatically register itself.
-
You can publish the configs file using the following command:
php artisan vendor:publish --provider="Buyme\Parser\BuymeParserServiceProvider" --tag=buyme-parser-config
This will create the package's config file called buyme_parser.php
in the config
directory. These are the contents of the published config file:
return [ /* |------------------------------------------------------------------------------------------------------------ | The package will use this mapping_parser for detect what adapter need connect to parse file by extension. |------------------------------------------------------------------------------------------------------------ */ "adapters" => [ 'xml' => \Buyme\Parser\Adapter\SimpleXML::class, 'yml' => \Buyme\Parser\Adapter\XMLReader::class, ], ];
- You can publish the lang file using the following command:
php artisan vendor:publish --provider="Buyme\Parser\BuymeParserServiceProvider" --tag=buyme-parser-lang
How to use
-
After setting up the config file values you are all set to use the following methods:
-
First you need to initialize an instance of the BuymeParser.php class using Facade or direct connection of the BuymeParser class:
Facade
use Buyme\Parser\Facades\BuymeParser;
Direct
use Buyme\Parser\BuymeParser;
Use Container
$byml = app(BuymeParser::class);
OR Use ID
public function __construct(private BuymeParser $buymeParser) { }
By URL
$this->buymeParser->open('https://example.com/file.yml');
By Local Path
$this->buymeParser->open('storage/xml/file.yml');
$categories = $this->buymeParser->getCategories(); $currencies = $this->buymeParser->getCurrencies(); $products = $this->buymeParser->getProducts();
Testing
You can run the tests with:
vendor/bin/phpunit
License
The MIT License (MIT). Please see the License File for more information.