Overview

Namespaces

  • Inteve
    • FeedGenerator
      • Feeds
        • GoogleMerchant
        • PostFeed
      • Outputs
      • Responses
      • Utils

Classes

  • Inteve\FeedGenerator\Feed
  • Inteve\FeedGenerator\Feeds\GoogleMerchant\GoogleMerchantFeed
  • Inteve\FeedGenerator\Feeds\GoogleMerchant\GoogleMerchantItem
  • Inteve\FeedGenerator\Feeds\PostFeed\PostFeed
  • Inteve\FeedGenerator\Feeds\PostFeed\PostFeedItem
  • Inteve\FeedGenerator\Outputs\DirectOutput
  • Inteve\FeedGenerator\Outputs\FileOutput
  • Inteve\FeedGenerator\Outputs\MemoryOutput
  • Inteve\FeedGenerator\Responses\NetteDownloadResponse
  • Inteve\FeedGenerator\Utils\Helpers

Interfaces

  • Inteve\FeedGenerator\IFeed
  • Inteve\FeedGenerator\IFeedItem
  • Inteve\FeedGenerator\IOutput

Exceptions

  • Inteve\FeedGenerator\AssertException
  • Inteve\FeedGenerator\FeedGeneratorException
  • Inteve\FeedGenerator\FileSystemException
  • Inteve\FeedGenerator\InvalidArgumentException
  • Inteve\FeedGenerator\InvalidItemException
  • Inteve\FeedGenerator\OutputException
  • Inteve\FeedGenerator\StaticClassException
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 
<?php

    namespace Inteve\FeedGenerator\Utils;

    use Inteve\FeedGenerator\AssertException;
    use Inteve\FeedGenerator\IOutput;
    use Inteve\FeedGenerator\StaticClassException;


    class Helpers
    {
        public function __construct()
        {
            throw new StaticClassException('This is static class.');
        }


        /**
         * @param  bool
         * @param  string|NULL
         * @return void
         * @throws AssertException
         */
        public static function assert($value, $msg = NULL)
        {
            if ($value !== TRUE) {
                throw new AssertException($msg !== NULL ? $msg : "Assertion failed.");
            }
        }


        /**
         * @param  string
         * @return string
         */
        public static function escapeXml($s)
        {
            return htmlspecialchars(preg_replace('#[\x00-\x08\x0B\x0C\x0E-\x1F]+#', '', $s), ENT_QUOTES);
        }


        /**
         * Escapes URL parameter.
         * @param  string
         * @return string
         */
        public static function escapeUrl($s)
        {
            return rawurlencode($s);
        }


        /**
         * Formats XML tag
         * @param  string
         * @param  string|NULL
         * @param  array
         * @return string
         */
        public static function writeXml(IOutput $output, array $xml)
        {
            foreach ($xml as $tagName => $content) {
                if ($content === NULL || (is_array($content) && array_key_exists('content', $content) && $content['content'] === NULL)) {
                    continue;
                }

                $tag = $tagName;

                if (is_array($content) && isset($content['tag'])) {
                    $tag = $content['tag'];
                }

                // open tag
                $output->output('<' . $tag);

                if (is_array($content) && isset($content['attrs'])) {
                    foreach ($content['attrs'] as $attrName => $attrValue) {
                        if ($attrValue === NULL) {
                            continue;
                        }

                        $output->output(' ' . $attrName . '="' . self::escapeXml($attrValue) . '"');
                    }
                }

                $isEmpty = is_array($content) && !isset($content['content']);

                if ($isEmpty) {
                    $output->output(' /');
                }

                $output->output('>');

                if (!$isEmpty) {
                    // content
                    if (is_array($content) && isset($content['content'])) {
                        if (is_array($content['content'])) {
                            $output->output("\n");
                            self::writeXml($output, $content['content']);

                        } else {
                            $output->output(self::escapeXml($content['content']));
                        }

                    } else {
                        $output->output(self::escapeXml($content));
                    }

                    // close tag
                    $output->output('</' . $tag . ">");
                }

                $output->output("\n");
            }
        }
    }
inteve/feed-generator v1.0.0 API documentation API documentation generated by ApiGen