Skip to content
Snippets Groups Projects
Commit ac246f9f authored by Vadim Justus's avatar Vadim Justus
Browse files

Implement xsd and configuration reader

parent 2bc19b1b
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Api;
interface ContentInstallerInterface
{
/**
* Apply all configured CMS content changes
*
* @return void
*/
public function install(): void;
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Config;
class Converter implements \Magento\Framework\Config\ConverterInterface
{
/**
* {@inheritdoc}
*/
public function convert($source)
{
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Config;
class Data extends \Magento\Framework\Config\Data
{
}
\ No newline at end of file
<?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;
}
}
<?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();
}
}
<?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>
<?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
<?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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment