From ac246f9ffe72960be9a40ca19a0f9b5ec969acd2 Mon Sep 17 00:00:00 2001 From: Vadim Justus <v.justus@techdivision.com> Date: Sat, 9 Feb 2019 15:36:52 +0100 Subject: [PATCH] Implement xsd and configuration reader --- Api/ContentInstallerInterface.php | 14 ++++++++ Model/Config/Converter.php | 15 ++++++++ Model/Config/Data.php | 9 +++++ Model/Config/SchemaLocator.php | 54 ++++++++++++++++++++++++++++ Setup/Recurring.php | 37 ++++++++++++++++++++ etc/content_provisioning.xml | 28 +++++++++++++++ etc/content_provisioning.xsd | 58 +++++++++++++++++++++++++++++++ etc/di.xml | 20 +++++++++++ 8 files changed, 235 insertions(+) create mode 100644 Api/ContentInstallerInterface.php create mode 100644 Model/Config/Converter.php create mode 100644 Model/Config/Data.php create mode 100644 Model/Config/SchemaLocator.php create mode 100644 Setup/Recurring.php create mode 100644 etc/content_provisioning.xml create mode 100644 etc/content_provisioning.xsd create mode 100644 etc/di.xml diff --git a/Api/ContentInstallerInterface.php b/Api/ContentInstallerInterface.php new file mode 100644 index 0000000..4b846f6 --- /dev/null +++ b/Api/ContentInstallerInterface.php @@ -0,0 +1,14 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Api; + +interface ContentInstallerInterface +{ + /** + * Apply all configured CMS content changes + * + * @return void + */ + public function install(): void; +} diff --git a/Model/Config/Converter.php b/Model/Config/Converter.php new file mode 100644 index 0000000..4e96bbd --- /dev/null +++ b/Model/Config/Converter.php @@ -0,0 +1,15 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Config; + +class Converter implements \Magento\Framework\Config\ConverterInterface +{ + /** + * {@inheritdoc} + */ + public function convert($source) + { + + } +} diff --git a/Model/Config/Data.php b/Model/Config/Data.php new file mode 100644 index 0000000..57d371f --- /dev/null +++ b/Model/Config/Data.php @@ -0,0 +1,9 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Config; + +class Data extends \Magento\Framework\Config\Data +{ + +} \ No newline at end of file diff --git a/Model/Config/SchemaLocator.php b/Model/Config/SchemaLocator.php new file mode 100644 index 0000000..afc553b --- /dev/null +++ b/Model/Config/SchemaLocator.php @@ -0,0 +1,54 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Config; + +class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface +{ + /** + * Path to corresponding XSD file with validation rules for merged config + * + * @var string + */ + protected $_schema = null; + + /** + * Path to corresponding XSD file with validation rules for separate config files + * + * @var string + */ + protected $_perFileSchema = null; + + /** + * @param \Magento\Framework\Module\Dir\Reader $moduleReader + */ + public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) + { + $etcDir = $moduleReader->getModuleDir( + \Magento\Framework\Module\Dir::MODULE_ETC_DIR, + 'Firegento_ContentProvisioning' + ); + $this->_schema = $etcDir . '/content_provisioning.xsd'; + $this->_perFileSchema = $etcDir . '/content_provisioning.xsd'; + } + + /** + * Get path to merged config schema + * + * @return string|null + */ + public function getSchema() + { + return $this->_schema; + } + + /** + * Get path to per file validation schema + * + * @return string|null + */ + public function getPerFileSchema() + { + return $this->_perFileSchema; + } +} diff --git a/Setup/Recurring.php b/Setup/Recurring.php new file mode 100644 index 0000000..588f685 --- /dev/null +++ b/Setup/Recurring.php @@ -0,0 +1,37 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Setup; + +use Firegento\ContentProvisioning\Api\ContentInstallerInterface; +use Magento\Framework\Setup\InstallSchemaInterface; +use Magento\Framework\Setup\ModuleContextInterface; +use Magento\Framework\Setup\SchemaSetupInterface; + +/** + * Class Recurring + */ +class Recurring implements InstallSchemaInterface +{ + /** + * @var ContentInstallerInterface + */ + private $contentInstaller; + + /** + * @param ContentInstallerInterface $contentInstaller + */ + public function __construct( + ContentInstallerInterface $contentInstaller + ) { + $this->contentInstaller = $contentInstaller; + } + + /** + * {@inheritdoc} + */ + public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) + { + $this->contentInstaller->install(); + } +} diff --git a/etc/content_provisioning.xml b/etc/content_provisioning.xml new file mode 100644 index 0000000..66d111b --- /dev/null +++ b/etc/content_provisioning.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Firegento/ContentProvisioning/etc/content_provisioning.xsd"> + <page identifier="foobar" maintained="true"> + <stores> + <store code="default" /> + </stores> + <content type="file">path/to/file.html</content> + </page> + <page identifier="test" maintained="false"> + <stores> + <store code="*" /> + </stores> + <content><![CDATA[this is some sample content...]]></content> + </page> + <block identifier="test" maintained="false"> + <stores> + <store code="*" /> + </stores> + <content><![CDATA[this is some sample content...]]></content> + </block> + <block identifier="test2" maintained="false"> + <content><![CDATA[this is some sample content...]]></content> + <stores> + <store code="default" /> + <store code="admin" /> + </stores> + </block> +</config> diff --git a/etc/content_provisioning.xsd b/etc/content_provisioning.xsd new file mode 100644 index 0000000..419ecc0 --- /dev/null +++ b/etc/content_provisioning.xsd @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <xs:element name="config"> + <xs:complexType> + <xs:sequence> + <xs:choice minOccurs="1" maxOccurs="unbounded"> + <xs:element type="cms_entity" name="page" /> + <xs:element type="cms_entity" name="block" /> + </xs:choice> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:complexType name="cms_entity"> + <xs:choice maxOccurs="unbounded"> + <xs:element minOccurs="0" maxOccurs="1" type="stores" name="stores" /> + <xs:element minOccurs="1" maxOccurs="1" type="content" name="content" /> + </xs:choice> + <xs:attribute name="identifier" type="identifier" use="required" /> + <xs:attribute name="maintained" type="xs:boolean" use="optional" /> + </xs:complexType> + + <xs:simpleType name="identifier"> + <xs:annotation> + <xs:documentation> + Unique identifier for cms entities + </xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:pattern value="[a-zA-Z0-9_\\]{1,}" /> + <xs:minLength value="2" /> + </xs:restriction> + </xs:simpleType> + + <xs:complexType name="stores"> + <xs:sequence> + <xs:element minOccurs="1" maxOccurs="unbounded" type="store" name="store" /> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="store"> + <xs:attribute name="code" type="xs:string" use="required" /> + </xs:complexType> + + <xs:complexType name="content"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="type" type="content_type" use="optional" /> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:simpleType name="content_type"> + <xs:restriction base="xs:string"> + <xs:enumeration value="file"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..7caef29 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <virtualType name="Firegento\ContentProvisioning\Model\Config\Reader" type="Magento\Framework\Config\Reader\Filesystem"> + <arguments> + <argument name="fileName" xsi:type="string">content_provisioning.xml</argument> + <argument name="converter" xsi:type="object">Firegento\ContentProvisioning\Model\Config\Converter</argument> + <argument name="schemaLocator" xsi:type="object">Firegento\ContentProvisioning\Model\Config\SchemaLocator</argument> + <argument name="idAttributes" xsi:type="array"> + <item name="/config/page" xsi:type="string">identifier</item> + <item name="/config/block" xsi:type="string">identifier</item> + </argument> + </arguments> + </virtualType> + <type name="Firegento\ContentProvisioning\Model\Config\Data"> + <arguments> + <argument name="reader" xsi:type="object">Firegento\ContentProvisioning\Model\Config\Reader</argument> + <argument name="cacheId" xsi:type="string">content_provisioning_config</argument> + </arguments> + </type> +</config> -- GitLab