Skip to content

Commit

Permalink
Improved naming for method with memory output and updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklan committed Jul 6, 2018
1 parent 22ee3f8 commit bca56e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Current dev changes

## 8.x-1.0-alpha4

- By [Batkor](https://github.com/Niklan/yandex_yml/issues/1). Added method to return generated XML as string using meory. So you can now create custom controllers and other suff.
- Updated documentation.

## 8.x-1.0-alpha3

- **Breaking change.** Default filename was changed from products.yml to products.xml, because it's allowed by Yandex, and this is better for XML file.
Expand Down
1 change: 1 addition & 0 deletions docs/generate-yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $generator = \Drupal::service('yandex_yml.generator');
- `addDeliveryOption(YandexYmlDelivery $delivery_option)`: Add delivery option. Each delivery option added separately and every delivery option is instance of `yandex_yml.delivery` service.
- `addOffer(YandexYmlOfferBase $offer)`: Add offer information. Each offer added separately and every offer is instance one of it service `yandex_yml.offer.{TYPE}`.
- `generateFile($filename = 'products.yml', $destination_path = 'public://')`: Generate result file according to all provided data.
- `generateMarkup()`: Generate result in meory and returns string with valid XML markup. Use it as you wish, e.g. inside custom controller as response.

### Example

Expand Down
24 changes: 12 additions & 12 deletions src/YandexYmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,19 @@ public function generateFile($filename = 'products.xml', $destination_path = 'pu
}

/**
* Write elements to writer object
* Generate XML in memory and returns result markup.
*/
protected function buildData(){
public function generateMarkup() {
$this->writer->openMemory();
$this->writeHeader();
$this->buildData();
return $this->writer->outputMemory();
}

/**
* Write elements to writer object.
*/
protected function buildData() {
$this->writeShopInfo();
$this->writeCurrencies();
$this->writeCategories();
Expand All @@ -97,16 +107,6 @@ protected function buildData(){
$this->writeFooter();
}

/**
* Return xml data from memory
*/
public function getResponceData(){
$this->writer->openMemory();
$this->writeHeader();
$this->buildData();
return $this->writer->outputMemory();
}

/**
* Write document headers.
*/
Expand Down

0 comments on commit bca56e1

Please sign in to comment.