buymeua/parser

Help with parse tests/files with products

v1.0.11 2023-07-09 19:08 UTC

This package is auto-updated.

Last update: 2024-04-08 01:30:28 UTC


README

Latest Stable Version Total Downloads Tests Laravel CD License PHP Version Require Fruitcake

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.