create method for validating module file descriptor
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Class InvalidXmlDocumentException
|
||||
* @package Thelia\Module\Exception
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class InvalidXmlDocumentException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
@@ -21,51 +21,40 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module\Loader;
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
namespace Thelia\Module;
|
||||
use Thelia\Module\Exception\InvalidXmlDocumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Class XmlFileLoader
|
||||
* @package Thelia\Module\Loader
|
||||
* Class ModuleDescriptorValidator
|
||||
* @package Thelia\Module
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class XmlFileLoader extends FileLoader
|
||||
class ModuleDescriptorValidator
|
||||
{
|
||||
private $xsd_file;
|
||||
|
||||
/**
|
||||
* Loads a resource.
|
||||
*
|
||||
* @param mixed $resource The resource
|
||||
* @param string $type The resource type
|
||||
*/
|
||||
public function load($resource, $type = null)
|
||||
public function __construct()
|
||||
{
|
||||
$path = $this->locator->locate($resource);
|
||||
|
||||
$xml = $this->parseFile($path);
|
||||
$this->xsd_file = __DIR__ . '/schema/module/module.xsd';
|
||||
}
|
||||
|
||||
protected function parseFile($file)
|
||||
public function validate($xml_file)
|
||||
{
|
||||
$schema = str_replace('\\', '/',__DIR__.'/schema/module-1.0.xsd');
|
||||
$dom = new \DOMDocument();
|
||||
|
||||
$dom = XmlUtils::loadFile($file, $schema);
|
||||
if ($dom->load($xml_file)) {
|
||||
if($dom->schemaValidate($this->xsd_file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return simplexml_import_dom($dom);
|
||||
throw new InvalidXmlDocumentException(sprintf("%s file is not a valid file", $xml_file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this class supports the given resource.
|
||||
*
|
||||
* @param mixed $resource A resource
|
||||
* @param string $type The resource type
|
||||
*
|
||||
* @return Boolean true if this class supports the given resource, false otherwise
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
// TODO: Implement supports() method.
|
||||
public function getDescriptor($xml_file) {
|
||||
$this->validate($xml_file);
|
||||
|
||||
return @simplexml_load_file($xml_file);
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,16 @@
|
||||
<module xmlns="http://thelia.net/schema/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/module http://thelia.net/schema/module/module-1.0.xsd">
|
||||
<descriptif lang="fr">
|
||||
<titre>Produits factices</titre>
|
||||
<chapo></chapo>
|
||||
<description>Insertion des produits dans votre site Thelia permettant d'avoir un Thelia de test vite opérationnel.</description>
|
||||
<postscriptum></postscriptum>
|
||||
</descriptif>
|
||||
<descriptive locale="en_US">
|
||||
<title>Cheque</title>
|
||||
</descriptive>
|
||||
<full-namespace>Cheque\\Cheque</full-namespace>
|
||||
<version>1.1</version>
|
||||
<auteur>
|
||||
<nom>Manuel Raynaud - mraynaud@openstudio.fr</nom>
|
||||
<societe></societe>
|
||||
<email></email>
|
||||
<web></web>
|
||||
</auteur>
|
||||
<type>classique</type>
|
||||
<prerequis/>
|
||||
<thelia>1.5.0</thelia>
|
||||
<etat>production</etat>
|
||||
<documentation>README.TXT</documentation>
|
||||
<urlmiseajour></urlmiseajour>
|
||||
<author>
|
||||
<name>Manuel Raynaud</name>
|
||||
<email>mraynaud@openstudio.fr</email>
|
||||
</author>
|
||||
<type>payment</type>
|
||||
<thelia>2.0.0</thelia>
|
||||
<stability>alpha</stability>
|
||||
</module>
|
||||
|
||||
Reference in New Issue
Block a user