Skip to content

Commit

Permalink
Оформил под composer
Browse files Browse the repository at this point in the history
  • Loading branch information
notdest committed Aug 10, 2019
1 parent 20899cb commit 2e89034
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 32 deletions.
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "notdest/yandex-yml-generator",
"description": "Simple Yandex Yml file generator.",
"type": "library",
"keywords": [
"Yandex",
"Yml"
],
"license": "MIT",
"authors": [
{
"name": "Aleksandr Solodov",
"email": "[email protected]",
"homepage": "https://github.com/notdest",
"role": "Developer"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0"
},
"autoload": {
"psr-4": {
"notdest\\yandexYmlGenerator\\": "src"
}
}
}
6 changes: 4 additions & 2 deletions examples/arbitrary.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './arbitrary.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/artist.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './artist.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/audiobook.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './audiobook.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/book.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './book.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/event.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './event.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/medicine.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './medicine.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/simple.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './simple.xml' ;

Expand Down
6 changes: 4 additions & 2 deletions examples/stress-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$start = time();

Expand Down
6 changes: 4 additions & 2 deletions examples/tour.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include('../ymlOffer.php');
include("../ymlDocument.php");
include('../src/ymlOffer.php');
include("../src/ymlDocument.php");

use notdest\yandexYmlGenerator\ymlDocument ;

$fileName = './tour.xml' ;

Expand Down
12 changes: 7 additions & 5 deletions ymlDocument.php → src/ymlDocument.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace notdest\yandexYmlGenerator;

class ymlDocument extends DomDocument

class ymlDocument extends \DomDocument
{

protected $currencies ;
Expand All @@ -17,7 +19,7 @@ public function __construct($name, $company ,$enc = "UTF-8") // или windows-
{
parent::__construct('1.0',$enc);

$imp = new DOMImplementation;
$imp = new \DOMImplementation;

$root = $this->createElement('yml_catalog'); // делаем основные элементы
$shop = $this->createElement('shop');
Expand All @@ -26,7 +28,7 @@ public function __construct($name, $company ,$enc = "UTF-8") // или windows-
$root->appendChild($shop);
$this->appendChild($root);
// TODO: mb_strlen не включены по умолчанию, лучше чем-то заменить
if(mb_strlen($name,$this->encoding) >20 ) throw new RuntimeException("name='$name' длиннее 20 символов");
if(mb_strlen($name,$this->encoding) >20 ) throw new \RuntimeException("name='$name' длиннее 20 символов");

$this ->add('name' ,$name)
->add('company' ,$company)
Expand Down Expand Up @@ -280,7 +282,7 @@ protected function newOffer( $id, $price, $currency, $category, $type, $from )
$this->offer ->add('currencyId',$currency)
->add('categoryId',$category);

$pr = new DomElement('price',$price);
$pr = new \DomElement('price',$price);
$this->offer->appendChild($pr);
if( !is_null($from)) $pr->setAttribute('from',($from) ? 'true' :'false' );

Expand All @@ -291,7 +293,7 @@ protected function newOffer( $id, $price, $currency, $category, $type, $from )

protected function exc($text)
{
throw new RuntimeException($text);
throw new \RuntimeException($text);
}


Expand Down
21 changes: 12 additions & 9 deletions ymlOffer.php → src/ymlOffer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

class ymlOffer extends DomElement
namespace notdest\yandexYmlGenerator;


class ymlOffer extends \DomElement
{
protected $enc ;
protected $type ;
Expand Down Expand Up @@ -91,7 +94,7 @@ public function dlvOption($cost,$days,$before = -1)
$dlvs = $this->getElementsByTagName('delivery-options');

if( !$dlvs->length ){
$dlv = new DomElement('delivery-options');
$dlv = new \DomElement('delivery-options');
$this->appendChild($dlv);
}else{
$dlv = $dlvs->item(0);
Expand All @@ -103,7 +106,7 @@ public function dlvOption($cost,$days,$before = -1)
$this->check( preg_match("/[^0-9\-]/",$days) , "days должно состоять из цифр и тирэ" );
$this->check( !is_int($before) || $before>24 , "order-before должно быть целым и меньше 25");

$opt = new DomElement( 'option');
$opt = new \DomElement( 'option');
$dlv->appendChild($opt);

$opt->setAttribute('cost', $cost);
Expand All @@ -120,8 +123,8 @@ public function description($txt,$tags = false)
$this->check( mb_strlen($txt,$this->enc)>3000 , "description должен быть короче 3000 символов" );

if( $tags ){
$cdata = new DOMCdataSection($txt);
$desc = new DomElement( 'description');
$cdata = new \DOMCdataSection($txt);
$desc = new \DomElement( 'description');
$this->appendChild($desc);
$desc->appendChild($cdata);
return $this;
Expand Down Expand Up @@ -187,7 +190,7 @@ protected function _age($args)
{
$this->check( !is_int($args[0]) , "age должен иметь тип int" );

$ageEl = new DomElement( 'age',$args[0] );
$ageEl = new \DomElement( 'age',$args[0] );
$this->appendChild($ageEl);
$ageEl->setAttribute('unit',$args[1] );

Expand All @@ -210,7 +213,7 @@ protected function _age($args)

protected function _param($args)
{
$newEl = new DomElement('param',$args[1]);
$newEl = new \DomElement('param',$args[1]);
$this->appendChild($newEl);
$newEl->setAttribute('name', $args[0]);
if( isset($args[2]) ) $newEl->setAttribute('unit', $args[2]);
Expand Down Expand Up @@ -273,7 +276,7 @@ protected function _cpa($args)

protected function check($expr , $msg)
{
if( $expr ) throw new RuntimeException($msg);
if( $expr ) throw new \RuntimeException($msg);
}

public function addStr( $name,$val,$limit )
Expand All @@ -284,7 +287,7 @@ public function addStr( $name,$val,$limit )

public function add( $name,$val=false )
{
$newEl = ($val===false) ? new DomElement($name) : new DomElement($name,$val);
$newEl = ($val===false) ? new \DomElement($name) : new \DomElement($name,$val);
$this->appendChild($newEl);
return $this;
}
Expand Down

0 comments on commit 2e89034

Please sign in to comment.