--- a/.hgignore Fri Oct 21 17:10:54 2011 +0200
+++ b/.hgignore Thu Oct 27 05:47:14 2011 +0200
@@ -6,4 +6,4 @@
syntax: regexp
^web/bundles$
syntax: regexp
-^app/config/parameters\.ini$
\ No newline at end of file
+^src/IRI$
\ No newline at end of file
--- a/.hgsubstate Fri Oct 21 17:10:54 2011 +0200
+++ b/.hgsubstate Thu Oct 27 05:47:14 2011 +0200
@@ -1,1 +1,1 @@
-cc32af72517618a30f426fe5fba0572ad0a50035 vendor/bundles/IRI/Bundle/WikiTagBundle
+7d2fb5d7c9fff6d099ab7d154e7b520bec6773e3 vendor/bundles/IRI/Bundle/WikiTagBundle
--- a/.settings/org.eclipse.core.resources.prefs Fri Oct 21 17:10:54 2011 +0200
+++ b/.settings/org.eclipse.core.resources.prefs Thu Oct 27 05:47:14 2011 +0200
@@ -1,3 +1,4 @@
-#Wed Oct 19 12:37:15 CEST 2011
+#Fri Oct 21 00:16:41 CEST 2011
eclipse.preferences.version=1
+encoding//vendor/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig=UTF-8
encoding/<project>=UTF-8
--- a/app/autoload.php Fri Oct 21 17:10:54 2011 +0200
+++ b/app/autoload.php Thu Oct 27 05:47:14 2011 +0200
@@ -16,6 +16,7 @@
'Metadata' => __DIR__.'/../vendor/metadata/src',
'FOS' => __DIR__.'/../vendor/bundles',
'Pagerfanta' => __DIR__.'/../vendor/bundles',
+ 'Mandango\Mondator' => __DIR__.'/../vendor/mondator/src',
'IRI\Bundle\WikiTagBundle' => __DIR__.'/../vendor/bundles',
));
$loader->registerPrefixes(array(
--- a/app/config/config.yml Fri Oct 21 17:10:54 2011 +0200
+++ b/app/config/config.yml Thu Oct 27 05:47:14 2011 +0200
@@ -62,3 +62,16 @@
db_driver: orm # other valid values are 'mongodb', 'couchdb'
firewall_name: main
user_class: Company\UserBundle\Entity\User
+
+wiki_tag:
+ document_class: Company\BaseBundle\Entity\Document
+ document_id_column: title
+ fields:
+ title:
+ type: string
+ length: 1024
+ accessor: getTitle
+ description:
+ type: text
+ shortTitle: ~
+
--- a/app/config/parameters.ini Fri Oct 21 17:10:54 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-; These parameters can be imported into other config files
-; by enclosing the key with % (like %database_user%)
-; Comments start with ';', as in php.ini
-[parameters]
- database_driver = pdo_mysql
- database_host = localhost
- database_port =
- database_name = hdabo_sf
- database_user = root
- database_password = admin
-
- mailer_transport = smtp
- mailer_host = localhost
- mailer_user =
- mailer_password =
-
- locale = en
-
- secret = ThisTokenIsNotSoSecretChangeIt
\ No newline at end of file
--- a/src/Company/BaseBundle/Entity/Document.php Fri Oct 21 17:10:54 2011 +0200
+++ b/src/Company/BaseBundle/Entity/Document.php Thu Oct 27 05:47:14 2011 +0200
@@ -11,7 +11,7 @@
* @ORM\Table()
* @ORM\Entity(repositoryClass="Company\BaseBundle\Entity\DocumentRepository")
*/
-class Document implements DocumentInterface
+class Document
{
/**
* @var integer $id
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/CHANGELOG Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,10 @@
+1.0.0 BETA2 - 18/5/2011
+-----------------------
+
+ * [e0bad9d] added README
+ * [2037709] changed some getters
+ * [61f979d] added @api phpdoc tag
+ * [ef3b967] changed some properties and methods to private
+ * [d758cda] changed license to MIT and files header
+ * [9c78b69] moved symfony class loader submodule
+ * [ca6812c] importing
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/LICENSE Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,19 @@
+Copyright (c) 2010-2011 Pablo Díez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/README.md Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,7 @@
+# Mondator
+
+Mondator is an easy and flexible class generator for PHP.
+
+## Documentation
+
+See the documentation in [http://mandango.org/doc/](http://mandango.org/doc/)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/phpunit.xml.dist Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ bootstrap="tests/bootstrap.php"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+>
+ <testsuites>
+ <testsuite name="Mandango Test Suite">
+ <directory>./tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./src</directory>
+ </whitelist>
+ </filter>
+</phpunit>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/ClassExtension.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,461 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+use Mandango\Mondator\Definition\Method;
+use Mandango\Mondator\Definition\Property;
+
+/**
+ * ClassExtension is the base class for class extensions.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+abstract class ClassExtension
+{
+ private $options;
+ private $requiredOptions;
+
+ protected $definitions;
+
+ protected $class;
+ protected $configClasses;
+ protected $configClass;
+
+ protected $newClassExtensions;
+ protected $newConfigClasses;
+
+ protected $twig;
+ protected $twigTempDir;
+
+ /**
+ * Constructor.
+ *
+ * @param array $options An array of options.
+ *
+ * @api
+ */
+ public function __construct(array $options = array())
+ {
+ $this->options = array();
+ $this->requiredOptions = array();
+
+ $this->setUp();
+
+ foreach ($options as $name => $value) {
+ $this->setOption($name, $value);
+ }
+
+ // required options
+ if ($diff = array_diff($this->requiredOptions, array_keys($options))) {
+ throw new \RuntimeException(sprintf('%s requires the options: "%s".', get_class($this), implode(', ', $diff)));
+ }
+ }
+
+ /**
+ * Set up the extension.
+ *
+ * @api
+ */
+ protected function setUp()
+ {
+ }
+
+ /**
+ * Add an option.
+ *
+ * @param string $name The option name.
+ * @param mixed $defaultValue The default value (optional, null by default).
+ *
+ * @api
+ */
+ protected function addOption($name, $defaultValue = null)
+ {
+ $this->options[$name] = $defaultValue;
+ }
+
+ /**
+ * Add options.
+ *
+ * @param array $options An array with options (name as key and default value as value).
+ *
+ * @api
+ */
+ protected function addOptions(array $options)
+ {
+ foreach ($options as $name => $defaultValue) {
+ $this->addOption($name, $defaultValue);
+ }
+ }
+
+ /**
+ * Add a required option.
+ *
+ * @param string $name The option name.
+ *
+ * @api
+ */
+ protected function addRequiredOption($name)
+ {
+ $this->addOption($name);
+
+ $this->requiredOptions[] = $name;
+ }
+
+ /**
+ * Add required options.
+ *
+ * @param array $options An array with the name of the required option as value.
+ *
+ * @api
+ */
+ protected function addRequiredOptions(array $options)
+ {
+ foreach ($options as $name) {
+ $this->addRequiredOption($name);
+ }
+ }
+
+ /**
+ * Returns if exists an option.
+ *
+ * @param string $name The name.
+ *
+ * @return bool Returns true if the option exists, false otherwise.
+ *
+ * @api
+ */
+ public function hasOption($name)
+ {
+ return array_key_exists($name, $this->options);
+ }
+
+ /**
+ * Set an option.
+ *
+ * @param string $name The name.
+ * @param mixed $value The value.
+ *
+ * @throws \InvalidArgumentException If the option does not exists.
+ *
+ * @api
+ */
+ public function setOption($name, $value)
+ {
+ if (!$this->hasOption($name)) {
+ throw new \InvalidArgumentException(sprintf('The option "%s" does not exists.', $name));
+ }
+
+ $this->options[$name] = $value;
+ }
+
+ /**
+ * Returns the options.
+ *
+ * @return array The options.
+ *
+ * @api
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * Return an option.
+ *
+ * @param string $name The name.
+ *
+ * @return mixed The value of the option.
+ *
+ * @throws \InvalidArgumentException If the options does not exists.
+ *
+ * @api
+ */
+ public function getOption($name)
+ {
+ if (!$this->hasOption($name)) {
+ throw new \InvalidArgumentException(sprintf('The option "%s" does not exists.', $name));
+ }
+
+ return $this->options[$name];
+ }
+
+ /**
+ * New class extensions process.
+ *
+ * @param string $class The class.
+ * @param \ArrayObject $configClasses The config classes.
+ * @param \ArrayObject $newClassExtensions The new class extensions.
+ *
+ * @api
+ */
+ public function newClassExtensionsProcess($class, \ArrayObject $configClasses, \ArrayObject $newClassExtensions)
+ {
+ $this->class = $class;
+ $this->configClasses = $configClasses;
+ $this->configClass = $configClasses[$class];
+ $this->newClassExtensions = $newClassExtensions;
+
+ $this->doNewClassExtensionsProcess();
+
+ $this->class = null;
+ $this->configClasses = null;
+ $this->configClass = null;
+ $this->newClassExtensions = null;
+ }
+
+ /**
+ * Do the new class extensions process.
+ *
+ * Here you can add new class extensions.
+ *
+ * @api
+ */
+ protected function doNewClassExtensionsProcess()
+ {
+ }
+
+ /**
+ * New config classes process.
+ *
+ * @param string $class The class.
+ * @param \ArrayObject $configClasses The config classes.
+ * @param \ArrayObject $newConfigClasses The new config classes.
+ *
+ * @api
+ */
+ public function newConfigClassesProcess($class, \ArrayObject $configClasses, \ArrayObject $newConfigClasses)
+ {
+ $this->class = $class;
+ $this->configClasses = $configClasses;
+ $this->configClass = $configClasses[$class];
+ $this->newConfigClasses = $newConfigClasses;
+
+ $this->doNewConfigClassesProcess();
+
+ $this->class = null;
+ $this->configClasses = null;
+ $this->configClass = null;
+ $this->newConfigClasses = null;
+ }
+
+ /**
+ * Do the new config classes process.
+ *
+ * Here you can add new config classes, and change the config classes
+ * if it is necessary to build the new config classes.
+ *
+ * @api
+ */
+ protected function doNewConfigClassesProcess()
+ {
+ }
+
+ /**
+ * Process the config class.
+ *
+ * @param string $class The class.
+ * @param \ArrayObject $configClasses The config classes.
+ *
+ * @api
+ */
+ public function configClassProcess($class, \ArrayObject $configClasses)
+ {
+ $this->class = $class;
+ $this->configClasses = $configClasses;
+ $this->configClass = $configClasses[$class];
+
+ $this->doConfigClassProcess();
+
+ $this->class = null;
+ $this->configClasses = null;
+ $this->configClass = null;
+ }
+
+ /**
+ * Do the config class process.
+ *
+ * Here you can modify the config class.
+ *
+ * @api
+ */
+ protected function doConfigClassProcess()
+ {
+ }
+
+
+ /**
+ * Process the class.
+ *
+ * @param string $class The class.
+ * @param \ArrayObject $configClasses The config classes.
+ * @param Mandango\Mondator\Container $container The container.
+ *
+ * @api
+ */
+ public function classProcess($class, \ArrayObject $configClasses, Container $container)
+ {
+ $this->class = $class;
+ $this->configClasses = $configClasses;
+ $this->configClass = $configClasses[$class];
+ $this->definitions = $container;
+
+ $this->doClassProcess();
+
+ $this->class = null;
+ $this->configClasses = null;
+ $this->configClass = null;
+ $this->definitions = null;
+ }
+
+ /**
+ * Do the class process.
+ *
+ * @api
+ */
+ protected function doClassProcess()
+ {
+ }
+
+ /**
+ * Twig.
+ */
+ protected function processTemplate(Definition $definition, $name, array $variables = array())
+ {
+ $twig = $this->getTwig();
+
+ $variables['options'] = $this->options;
+ $variables['class'] = $this->class;
+ $variables['config_class'] = $this->configClass;
+ $variables['config_classes'] = $this->configClasses;
+
+ $result = $twig->loadTemplate($name)->render($variables);
+
+ // properties
+ $expression = '/
+ (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n?
+ \ \ \ \ (?P<static>static\ )?
+ (?P<visibility>public|protected|private)
+ \s
+ \$
+ (?P<name>[a-zA-Z0-9_]+)
+ ;
+ /xU';
+ preg_match_all($expression, $result, $matches);
+
+ for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
+ $property = new Property($matches['visibility'][$i], $matches['name'][$i], null);
+ if ($matches['static'][$i]) {
+ $property->setStatic(true);
+ }
+ if ($matches['docComment'][$i]) {
+ $property->setDocComment($matches['docComment'][$i]);
+ }
+ $definition->addProperty($property);
+ }
+
+ // methods
+ $expression = '/
+ (?P<docComment>\ \ \ \ \/\*\*\n[\s\S]*\ \ \ \ \ \*\/)?\n
+ \ \ \ \ (?P<static>static\ )?
+ (?P<visibility>public|protected|private)
+ \s
+ function
+ \s
+ (?P<name>[a-zA-Z0-9_]+)
+ \((?P<arguments>[$a-zA-Z0-9_\\\=\(\), ]*)\)
+ \n
+ \ \ \ \ \{
+ (?P<code>[\s\S]*)
+ \n\ \ \ \ \}
+ /xU';
+ preg_match_all($expression, $result, $matches);
+
+ for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
+ $code = trim($matches['code'][$i], "\n");
+ $method = new Method($matches['visibility'][$i], $matches['name'][$i], $matches['arguments'][$i], $code);
+ if ($matches['static'][$i]) {
+ $method->setStatic(true);
+ }
+ if ($matches['docComment'][$i]) {
+ $method->setDocComment($matches['docComment'][$i]);
+ }
+ $definition->addMethod($method);
+ }
+ }
+
+ public function getTwig()
+ {
+ if (null === $this->twig) {
+ if (!class_exists('Twig_Environment')) {
+ throw new \RuntimeException('Twig is required to use templates.');
+ }
+
+ $loader = new \Twig_Loader_String();
+ $twig = new \Twig_Environment($loader, array(
+ 'autoescape' => false,
+ 'strict_variables' => true,
+ 'debug' => true,
+ 'cache' => $this->twigTempDir = sys_get_temp_dir().'Mondator/'.mt_rand(111111, 999999),
+ ));
+
+ $this->configureTwig($twig);
+
+ $this->twig = $twig;
+ }
+
+ return $this->twig;
+ }
+
+ protected function configureTwig(\Twig_Environment $twig)
+ {
+ }
+
+ /*
+ * Tools.
+ */
+ protected function createClassExtensionFromArray(array $data)
+ {
+ if (!isset($data['class'])) {
+ throw new \InvalidArgumentException(sprintf('The extension does not have class.'));
+ }
+
+ return new $data['class'](isset($data['options']) ? $data['options'] : array());
+ }
+
+ private function removeDir($target)
+ {
+ $fp = opendir($target);
+ while (false !== $file = readdir($fp)) {
+ if (in_array($file, array('.', '..'))) {
+ continue;
+ }
+
+ if (is_dir($target.'/'.$file)) {
+ self::removeDir($target.'/'.$file);
+ } else {
+ unlink($target.'/'.$file);
+ }
+ }
+ closedir($fp);
+ rmdir($target);
+ }
+
+ public function __destruct()
+ {
+ if ($this->twigTempDir && is_dir($this->twigTempDir)) {
+ $this->removeDir($this->twigTempDir);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Container.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,183 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+/**
+ * Container of definitions.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Container implements \ArrayAccess, \Countable, \IteratorAggregate
+{
+ private $definitions;
+
+ /**
+ * Constructor.
+ *
+ * @api
+ */
+ public function __construct()
+ {
+ $this->definitions = array();
+ }
+
+ /**
+ * Returns if a definition name exists.
+ *
+ * @param string $name The definition name.
+ *
+ * @return bool Returns if the definition name exists.
+ *
+ * @api
+ */
+ public function hasDefinition($name)
+ {
+ return isset($this->definitions[$name]);
+ }
+
+ /**
+ * Set a definition.
+ *
+ * @param string $name The definition name.
+ * @param Mandango\Mondator\Definition $definition The definition.
+ *
+ * @api
+ */
+ public function setDefinition($name, Definition $definition)
+ {
+ $this->definitions[$name] = $definition;
+ }
+
+ /**
+ * Set the definitions.
+ *
+ * @param array $definitions An array of definitions.
+ *
+ * @api
+ */
+ public function setDefinitions(array $definitions)
+ {
+ $this->definitions = array();
+ foreach ($definitions as $name => $definition) {
+ $this->setDefinition($name, $definition);
+ }
+ }
+
+ /**
+ * Returns a definition by name.
+ *
+ * @param string $name The definition name.
+ *
+ * @return Mandango\Mondator\Definition The definition.
+ *
+ * @throws \InvalidArgumentException If the definition does not exists.
+ *
+ * @api
+ */
+ public function getDefinition($name)
+ {
+ if (!$this->hasDefinition($name)) {
+ throw new \InvalidArgumentException(sprintf('The definition "%s" does not exists.', $name));
+ }
+
+ return $this->definitions[$name];
+ }
+
+ /**
+ * Returns the definitions.
+ *
+ * @return arary The definitions.
+ *
+ * @api
+ */
+ public function getDefinitions()
+ {
+ return $this->definitions;
+ }
+
+ /**
+ * Remove a definition
+ *
+ * @param string $name The definition name
+ *
+ * @throws \InvalidArgumentException If the definition does not exists.
+ *
+ * @api
+ */
+ public function removeDefinition($name)
+ {
+ if (!$this->hasDefinition($name)) {
+ throw new \InvalidArgumentException(sprintf('The definition "%s" does not exists.', $name));
+ }
+
+ unset($this->definitions[$name]);
+ }
+
+ /**
+ * Clear the definitions.
+ *
+ * @api
+ */
+ public function clearDefinitions()
+ {
+ $this->definitions = array();
+ }
+
+ /*
+ * \ArrayAccess interface.
+ */
+ public function offsetExists($name)
+ {
+ return $this->hasDefinition($name);
+ }
+
+ public function offsetSet($name, $definition)
+ {
+ $this->setDefinition($name, $definition);
+ }
+
+ public function offsetGet($name)
+ {
+ return $this->getDefinition($name);
+ }
+
+ public function offsetUnset($name)
+ {
+ $this->removeDefinition($name);
+ }
+
+ /**
+ * Returns the number of definitions (implements the \Countable interface).
+ *
+ * @return integer The number of definitions.
+ *
+ * @api
+ */
+ public function count()
+ {
+ return count($this->definitions);
+ }
+
+ /**
+ * Returns an \ArrayIterator with the definitions (implements \IteratorAggregate interface).
+ *
+ * @return \ArrayIterator An \ArrayIterator with the definitions.
+ *
+ * @api
+ */
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->definitions);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Definition.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+use Mandango\Mondator\Definition\Definition as BaseDefinition;
+
+/**
+ * Definitions to save with the extensions. Allows save the output.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Definition extends BaseDefinition
+{
+ private $output;
+
+ /**
+ * Constructor.
+ *
+ * @param string $class The class.
+ * @param Mandango\Mondator\Output $output The output.
+ *
+ * @api
+ */
+ public function __construct($class, Output $output)
+ {
+ parent::__construct($class);
+
+ $this->setOutput($output);
+ }
+
+ /**
+ * Set the output.
+ *
+ * @param Mandango\Mondator\Output $output The output.
+ *
+ * @api
+ */
+ public function setOutput(Output $output)
+ {
+ $this->output = $output;
+ }
+
+ /**
+ * Returns the output.
+ *
+ * @return Mandango\Mondator\Output The output.
+ *
+ * @api
+ */
+ public function getOutput()
+ {
+ return $this->output;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Definition/Definition.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,443 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator\Definition;
+
+/**
+ * Represents a definition of a class.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Definition
+{
+ private $class;
+ private $parentClass;
+ private $interfaces;
+ private $final;
+ private $abstract;
+ private $properties;
+ private $methods;
+ private $docComment;
+
+ /**
+ * Constructor.
+ *
+ * @param string $class The class.
+ *
+ * @api
+ */
+ public function __construct($class)
+ {
+ $this->setClass($class);
+ $this->interfaces = array();
+ $this->final = false;
+ $this->abstract = false;
+ $this->properties = array();
+ $this->methods = array();
+ }
+
+ /**
+ * Set the class.
+ *
+ * @param string $class The class.
+ *
+ * @api
+ */
+ public function setClass($class)
+ {
+ $this->class = $class;
+ }
+
+ /**
+ * Returns the class.
+ *
+ * @return string The class.
+ *
+ * @api
+ */
+ public function getClass()
+ {
+ return $this->class;
+ }
+
+ /**
+ * Returns the namespace.
+ *
+ * @return string|null The namespace.
+ *
+ * @api
+ */
+ public function getNamespace()
+ {
+ if (false !== $pos = strrpos($this->class, '\\')) {
+ return substr($this->class, 0, $pos);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the class name.
+ *
+ * @return string|null The class name.
+ *
+ * @api
+ */
+ public function getClassName()
+ {
+ if (false !== $pos = strrpos($this->class, '\\')) {
+ return substr($this->class, $pos + 1);
+ }
+
+ return $this->class;
+ }
+
+ /**
+ * Set the parent class.
+ *
+ * @param string $parentClass The parent class.
+ *
+ * @api
+ */
+ public function setParentClass($parentClass)
+ {
+ $this->parentClass = $parentClass;
+ }
+
+ /**
+ * Returns the parent class.
+ *
+ * @return string The parent class.
+ *
+ * @api
+ */
+ public function getParentClass()
+ {
+ return $this->parentClass;
+ }
+
+ /**
+ * Add an interface.
+ *
+ * @param string $interface The interface.
+ *
+ * @api
+ */
+ public function addInterface($interface)
+ {
+ $this->interfaces[] = $interface;
+ }
+
+ /**
+ * Set the interfaces.
+ *
+ * @param array $interfaces The interfaces.
+ *
+ * @api
+ */
+ public function setInterfaces(array $interfaces)
+ {
+ $this->interfaces = array();
+ foreach ($interfaces as $interface) {
+ $this->addInterface($interface);
+ }
+ }
+
+ /**
+ * Returns the interfaces.
+ *
+ * @return array The interfaces.
+ *
+ * @api
+ */
+ public function getInterfaces()
+ {
+ return $this->interfaces;
+ }
+
+ /**
+ * Set if the class is final.
+ *
+ * @param bool $final If the class is final.
+ *
+ * @api
+ */
+ public function setFinal($final)
+ {
+ $this->final = (bool) $final;
+ }
+
+ /**
+ * Returns if the class is final.
+ *
+ * @return bool Returns if the class is final.
+ *
+ * @api
+ */
+ public function isFinal()
+ {
+ return $this->final;
+ }
+
+ /**
+ * Set if the class is abstract.
+ *
+ * @param bool $abstract If the class is abstract.
+ *
+ * @api
+ */
+ public function setAbstract($abstract)
+ {
+ $this->abstract = (bool) $abstract;
+ }
+
+ /**
+ * Returns if the class is abstract.
+ *
+ * @return bool If the class is abstract.
+ *
+ * @api
+ */
+ public function isAbstract()
+ {
+ return $this->abstract;
+ }
+
+ /**
+ * Add a property.
+ *
+ * @param Mandango\Mondator\Definition\Property $property The property.
+ *
+ * @api
+ */
+ public function addProperty(Property $property)
+ {
+ $this->properties[] = $property;
+ }
+
+ /**
+ * Set the properties.
+ *
+ * @param array $properties An array of properties.
+ *
+ * @api
+ */
+ public function setProperties(array $properties)
+ {
+ $this->properties = array();
+ foreach ($properties as $name => $property) {
+ $this->addProperty($property);
+ }
+ }
+
+ /**
+ * Returns the properties.
+ *
+ * @return array The properties.
+ *
+ * @api
+ */
+ public function getProperties()
+ {
+ return $this->properties;
+ }
+
+ /**
+ * Returns if a property exists by name.
+ *
+ * @param string $name The property name.
+ *
+ * @return bool If the property exists.
+ *
+ * @api
+ */
+ public function hasPropertyByName($name)
+ {
+ foreach ($this->properties as $property) {
+ if ($property->getName() == $name) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns a property by name.
+ *
+ * @param string $name The property name.
+ *
+ * @return Mandango\Mondator\Definition\Property The property.
+ *
+ * @throws \InvalidArgumentException If the property does not exists.
+ *
+ * @api
+ */
+ public function getPropertyByName($name)
+ {
+ foreach ($this->properties as $property) {
+ if ($property->getName() == $name) {
+ return $property;
+ }
+ }
+
+ throw new \InvalidArgumentException(sprintf('The property "%s" does not exists.', $name));
+ }
+
+ /**
+ * Remove property by name.
+ *
+ * @param string $name The property name.
+ *
+ * @throws \InvalidArgumentException If the property does not exists.
+ *
+ * @api
+ */
+ public function removePropertyByName($name)
+ {
+ foreach ($this->properties as $key => $property) {
+ if ($property->getName() == $name) {
+ unset($this->properties[$key]);
+ return;
+ }
+ }
+
+ throw new \InvalidArgumentException(sprintf('The property "%s" does not exists.', $name));
+ }
+
+ /**
+ * Add a method.
+ *
+ * @param Mandango\Mondator\Definition\Method $method The method.
+ *
+ * @api
+ */
+ public function addMethod(Method $method)
+ {
+ $this->methods[] = $method;
+ }
+
+ /**
+ * Set the methods.
+ *
+ * @param array $methods An array of methods.
+ *
+ * @api
+ */
+ public function setMethods(array $methods)
+ {
+ $this->methods = array();
+ foreach ($methods as $name => $method) {
+ $this->addMethod($method);
+ }
+ }
+
+ /**
+ * Returns the methods.
+ *
+ * @return array The methods.
+ *
+ * @api
+ */
+ public function getMethods()
+ {
+ return $this->methods;
+ }
+
+ /**
+ * Returns if exists a method by name.
+ *
+ * @param string $name The method name.
+ *
+ * @return bool If the method exists.
+ *
+ * @api
+ */
+ public function hasMethodByName($name)
+ {
+ foreach ($this->methods as $method) {
+ if ($method->getName() == $name) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Return a method by name.
+ *
+ * @param string $name The method name.
+ *
+ * @return Mandango\Mondator\Definition\Method The method.
+ *
+ * @throws \InvalidArgumentException If the method does not exists.
+ *
+ * @api
+ */
+ public function getMethodByName($name)
+ {
+ foreach ($this->methods as $method) {
+ if ($method->getName() == $name) {
+ return $method;
+ }
+ }
+
+ throw new \InvalidArgumentException(sprintf('The method "%s" does not exists.', $name));
+ }
+
+ /**
+ * Remove a method by name.
+ *
+ * @param string $name The method name.
+ *
+ * @throws \InvalidArgumentException If the method does not exists.
+ *
+ * @api
+ */
+ public function removeMethodByName($name)
+ {
+ foreach ($this->methods as $key => $method) {
+ if ($method->getName() == $name) {
+ unset($this->methods[$key]);
+ return;
+ }
+ }
+
+ throw new \InvalidArgumentException(sprintf('The method "%s" does not exists.', $name));
+ }
+
+ /**
+ * Set the doc comment.
+ *
+ * @param string|null $docComment The doc comment.
+ *
+ * @api
+ */
+ public function setDocComment($docComment)
+ {
+ $this->docComment = $docComment;
+ }
+
+ /**
+ * Returns the doc comment.
+ *
+ * @return string|null The doc comment.
+ *
+ * @api
+ */
+ public function getDocComment()
+ {
+ return $this->docComment;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Definition/Method.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,244 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator\Definition;
+
+/**
+ * Represents a method of a class.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Method
+{
+ private $visibility;
+ private $name;
+ private $arguments;
+ private $code;
+ private $final;
+ private $static;
+ private $abstract;
+ private $docComment;
+
+ /**
+ * Constructor.
+ *
+ * @param string $visibility The visibility.
+ * @param string $name The name.
+ * @param string $arguments The arguments (as string).
+ * @param string $code The code.
+ *
+ * @api
+ */
+ public function __construct($visibility, $name, $arguments, $code)
+ {
+ $this->setVisibility($visibility);
+ $this->setName($name);
+ $this->setArguments($arguments);
+ $this->setCode($code);
+ $this->final = false;
+ $this->static = false;
+ $this->abstract = false;
+ }
+
+ /**
+ * Set the visibility.
+ *
+ * @param string $visibility The visibility.
+ *
+ * @api
+ */
+ public function setVisibility($visibility)
+ {
+ $this->visibility = $visibility;
+ }
+
+ /**
+ * Returns the visibility.
+ *
+ * @return string The visibility.
+ *
+ * @api
+ */
+ public function getVisibility()
+ {
+ return $this->visibility;
+ }
+
+ /**
+ * Set the name.
+ *
+ * @param string $name The name.
+ *
+ * @api
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Returns the name.
+ *
+ * @return string The name.
+ *
+ * @api
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set the arguments.
+ *
+ * Example: "$argument1, &$argument2"
+ *
+ * @param string $arguments The arguments (as string).
+ *
+ * @api
+ */
+ public function setArguments($arguments)
+ {
+ $this->arguments = $arguments;
+ }
+
+ /**
+ * Returns the arguments.
+ *
+ * @api
+ */
+ public function getArguments()
+ {
+ return $this->arguments;
+ }
+
+ /**
+ * Set the code.
+ *
+ * @param string $code.
+ *
+ * @api
+ */
+ public function setCode($code)
+ {
+ $this->code = $code;
+ }
+
+ /**
+ * Returns the code.
+ *
+ * @return string The code.
+ *
+ * @api
+ */
+ public function getCode()
+ {
+ return $this->code;
+ }
+
+ /**
+ * Set if the method is final.
+ *
+ * @param bool $final If the method is final.
+ *
+ * @api
+ */
+ public function setFinal($final)
+ {
+ $this->final = (bool) $final;
+ }
+
+ /**
+ * Returns if the method is final.
+ *
+ * @return bool If the method is final.
+ *
+ * @api
+ */
+ public function isFinal()
+ {
+ return $this->final;
+ }
+
+ /**
+ * Set if the method is static.
+ *
+ * @param bool $static If the method is static.
+ *
+ * @api
+ */
+ public function setStatic($static)
+ {
+ $this->static = (bool) $static;
+ }
+
+ /**
+ * Return if the method is static.
+ *
+ * @return bool Returns if the method is static.
+ *
+ * @api
+ */
+ public function isStatic()
+ {
+ return $this->static;
+ }
+
+ /**
+ * Set if the method is abstract.
+ *
+ * @param bool $abstract If the method is abstract.
+ *
+ * @api
+ */
+ public function setAbstract($abstract)
+ {
+ $this->abstract = (bool) $abstract;
+ }
+
+ /**
+ * Return if the method is abstract.
+ *
+ * @return bool Returns if the method is abstract.
+ *
+ * @api
+ */
+ public function isAbstract()
+ {
+ return $this->abstract;
+ }
+
+ /**
+ * Set the doc comment.
+ *
+ * @param string|null $docComment The doc comment.
+ *
+ * @api
+ */
+ public function setDocComment($docComment)
+ {
+ $this->docComment = $docComment;
+ }
+
+ /**
+ * Returns the doc comment.
+ *
+ * @return string|null The doc comment.
+ *
+ * @api
+ */
+ public function getDocComment()
+ {
+ return $this->docComment;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Definition/Property.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,165 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator\Definition;
+
+/**
+ * Represents a property of a class.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Property
+{
+ private $visibility;
+ private $name;
+ private $value;
+ private $static;
+ private $docComment;
+
+ /**
+ * Constructor.
+ *
+ * @param string $visibility The visibility.
+ * @param string $name The name.
+ * @param mixed $value The value.
+ *
+ * @api
+ */
+ public function __construct($visibility, $name, $value)
+ {
+ $this->setVisibility($visibility);
+ $this->setName($name);
+ $this->setValue($value);
+ $this->static = false;
+ }
+
+ /**
+ * Set the visibility.
+ *
+ * @param string $visibility The visibility.
+ *
+ * @api
+ */
+ public function setVisibility($visibility)
+ {
+ $this->visibility = $visibility;
+ }
+
+ /**
+ * Returns the visibility.
+ *
+ * @return string The visibility.
+ *
+ * @api
+ */
+ public function getVisibility()
+ {
+ return $this->visibility;
+ }
+
+ /**
+ * Set the name.
+ *
+ * @param string $name The name.
+ *
+ * @api
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Returns the name.
+ *
+ * @return string The name.
+ *
+ * @api
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set the value.
+ *
+ * @param mixed $value The value.
+ *
+ * @api
+ */
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return mixed The value.
+ *
+ * @api
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Set if the property is static.
+ *
+ * @param bool $static If the property is static.
+ *
+ * @api
+ */
+ public function setStatic($static)
+ {
+ $this->static = (bool) $static;
+ }
+
+ /**
+ * Return if the property is static.
+ *
+ * @return bool Returns if the property is static.
+ *
+ * @api
+ */
+ public function isStatic()
+ {
+ return $this->static;
+ }
+
+ /**
+ * Set the doc comment.
+ *
+ * @param string|null $docComment The doc comment.
+ *
+ * @api
+ */
+ public function setDocComment($docComment)
+ {
+ $this->docComment = $docComment;
+ }
+
+ /**
+ * Returns the doc comment.
+ *
+ * @return string|null The doc comment.
+ *
+ * @api
+ */
+ public function getDocComment()
+ {
+ return $this->docComment;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Dumper.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,258 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+use Mandango\Mondator\Definition\Definition as BaseDefinition;
+
+/**
+ * The Mondator Dumper.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Dumper
+{
+ private $definition;
+
+ /**
+ * Constructor.
+ *
+ * @param Mandango\Mondator\Definition\Definition $definition The definition.
+ *
+ * @api
+ */
+ public function __construct(BaseDefinition $definition)
+ {
+ $this->setDefinition($definition);
+ }
+
+ /**
+ * Set the definition.
+ *
+ * @param Mandango\Mondator\Definition\Definition $definition The definition.
+ *
+ * @api
+ */
+ public function setDefinition(BaseDefinition $definition)
+ {
+ $this->definition = $definition;
+ }
+
+ /**
+ * Returns the definition
+ *
+ * @return Mandango\Mondator\Definition\Definition The definition.
+ *
+ * @api
+ */
+ public function getDefinition()
+ {
+ return $this->definition;
+ }
+
+ /**
+ * Dump the definition.
+ *
+ * @return string The PHP code of the definition.
+ *
+ * @api
+ */
+ public function dump()
+ {
+ return
+ $this->startFile().
+ $this->addNamespace().
+ $this->startClass().
+ $this->addProperties().
+ $this->addMethods().
+ $this->endClass()
+ ;
+ }
+
+ /**
+ * Export an array.
+ *
+ * Based on Symfony\Component\DependencyInjection\Dumper\PhpDumper::exportParameters
+ * http://github.com/symfony/symfony
+ *
+ * @param array $array The array.
+ * @param int $indent The indent.
+ *
+ * @return string The array exported.
+ */
+ static public function exportArray(array $array, $indent)
+ {
+ $code = array();
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ $value = self::exportArray($value, $indent + 4);
+ } else {
+ $value = null === $value ? 'null' : var_export($value, true);
+ }
+
+ $code[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), var_export($key, true), $value);
+ }
+
+ return sprintf("array(\n%s\n%s)", implode("\n", $code), str_repeat(' ', $indent - 4));
+ }
+
+ private function startFile()
+ {
+ return <<<EOF
+<?php
+
+EOF;
+ }
+
+ private function addNamespace()
+ {
+ if (!$namespace = $this->definition->getNamespace()) {
+ return '';
+ }
+
+ return <<<EOF
+
+namespace $namespace;
+
+EOF;
+ }
+
+ private function startClass()
+ {
+ $code = "\n";
+
+ // doc comment
+ if ($docComment = $this->definition->getDocComment()) {
+ $code .= $docComment."\n";
+ }
+
+ /*
+ * declaration
+ */
+ $declaration = '';
+
+ // abstract
+ if ($this->definition->isAbstract()) {
+ $declaration .= 'abstract ';
+ }
+
+ // class
+ $declaration .= 'class '.$this->definition->getClassName();
+
+ // parent class
+ if ($parentClass = $this->definition->getParentClass()) {
+ $declaration .= ' extends '.$parentClass;
+ }
+
+ // interfaces
+ if ($interfaces = $this->definition->getInterfaces()) {
+ $declaration .= ' implements '.implode(', ', $interfaces);
+ }
+
+ $code .= <<<EOF
+$declaration
+{
+EOF;
+
+ return $code;
+ }
+
+ private function addProperties()
+ {
+ $code = '';
+
+ $properties = $this->definition->getProperties();
+ foreach ($properties as $property) {
+ $code .= "\n";
+
+ if ($docComment = $property->getDocComment()) {
+ $code .= $docComment."\n";
+ }
+ $isStatic = $property->isStatic() ? 'static ' : '';
+
+ $value = $property->getValue();
+ if (null === $value) {
+ $code .= <<<EOF
+ $isStatic{$property->getVisibility()} \${$property->getName()};
+EOF;
+ } else {
+ $value = is_array($property->getValue()) ? self::exportArray($property->getValue(), 8) : var_export($property->getValue(), true);
+
+ $code .= <<<EOF
+ $isStatic{$property->getVisibility()} \${$property->getName()} = $value;
+EOF;
+ }
+ }
+ if ($properties) {
+ $code .= "\n";
+ }
+
+ return $code;
+ }
+
+ private function addMethods()
+ {
+ $code = '';
+
+ foreach ($this->definition->getMethods() as $method) {
+ $code .= "\n";
+
+ // doc comment
+ if ($docComment = $method->getDocComment()) {
+ $code .= $docComment."\n";
+ }
+
+ // isFinal
+ $isFinal = $method->isFinal() ? 'final ' : '';
+
+ // isStatic
+ $isStatic = $method->isStatic() ? 'static ' : '';
+
+ // abstract
+ if ($method->isAbstract()) {
+ $code .= <<<EOF
+ abstract $isStatic{$method->getVisibility()} function {$method->getName()}({$method->getArguments()});
+EOF;
+ } else {
+ $methodCode = trim($method->getCode());
+ if ($methodCode) {
+ $methodCode = ' '.$methodCode."\n ";
+ }
+ $code .= <<<EOF
+ $isFinal$isStatic{$method->getVisibility()} function {$method->getName()}({$method->getArguments()})
+ {
+ $methodCode}
+EOF;
+ }
+
+ $code .= "\n";
+ }
+
+ return $code;
+ }
+
+ private function endClass()
+ {
+ $code = '';
+
+ if (!$this->definition->getProperties() && !$this->definition->getMethods()) {
+ $code .= "\n";
+ }
+
+ $code .= <<<EOF
+}
+EOF;
+
+ return $code;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Extension.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+/**
+ * Extension is the base class for extensions.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+abstract class Extension extends ClassExtension
+{
+ /**
+ * Pre global process of the extension.
+ *
+ * @param \ArrayObject $configClasses The config classes.
+ * @param Mandango\Mondator\Container $container The global container.
+ *
+ * @api
+ */
+ public function preGlobalProcess(\ArrayObject $configClasses, Container $container)
+ {
+ $this->configClasses = $configClasses;
+ $this->definitions = $container;
+
+ $this->doPreGlobalProcess();
+
+ $this->configClasses = null;
+ $this->definitions = null;
+ }
+
+ /**
+ * Do the pre global process.
+ *
+ * @api
+ */
+ protected function doPreGlobalProcess()
+ {
+ }
+
+ /**
+ * Post global process of the extension.
+ *
+ * @param \ArrayObject $configClasses The config classes.
+ * @param Mandango\Mondator\Container $container The global container.
+ *
+ * @api
+ */
+ public function postGlobalProcess(\ArrayObject $configClasses, Container $container)
+ {
+ $this->configClasses = $configClasses;
+ $this->definitions = $container;
+
+ $this->doPostGlobalProcess();
+
+ $this->configClasses = null;
+ $this->definitions = null;
+ }
+
+ /**
+ * Do the post global process.
+ *
+ * @api
+ */
+ protected function doPostGlobalProcess()
+ {
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Mondator.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,311 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+/**
+ * Mondator.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Mondator
+{
+ private $configClasses;
+ private $extensions;
+ private $outputs;
+
+ /**
+ * Constructor.
+ *
+ * @api
+ */
+ public function __construct()
+ {
+ $this->configClasses = array();
+ $this->extensions = array();
+ $this->options = array();
+ }
+
+ /**
+ * Set a config class.
+ *
+ * @param string $class The class.
+ * @param array $configClass The config class.
+ *
+ * @api
+ */
+ public function setConfigClass($class, array $configClass)
+ {
+ $this->configClasses[$class] = $configClass;
+ }
+
+ /**
+ * Set the config classes.
+ *
+ * @param array $configClasses An array of config classes (class as key and config class as value).
+ *
+ * @api
+ */
+ public function setConfigClasses(array $configClasses)
+ {
+ $this->configClasses = array();
+ foreach ($configClasses as $class => $configClass) {
+ $this->setConfigClass($class, $configClass);
+ }
+ }
+
+ /**
+ * Returns if a config class exists.
+ *
+ * @param string $class The class.
+ *
+ * @return bool Returns if the config class exists.
+ *
+ * @api
+ */
+ public function hasConfigClass($class)
+ {
+ return array_key_exists($class, $this->configClasses);
+ }
+
+ /**
+ * Returns the config classes.
+ *
+ * @return array The config classes.
+ *
+ * @api
+ */
+ public function getConfigClasses()
+ {
+ return $this->configClasses;
+ }
+
+ /**
+ * Returns a config class.
+ *
+ * @param string $class The class.
+ *
+ * @return array The config class.
+ *
+ * @throws \InvalidArgumentException If the config class does not exists.
+ *
+ * @api
+ */
+ public function getConfigClass($class)
+ {
+ if (!$this->hasConfigClass($class)) {
+ throw new \InvalidArgumentException(sprintf('The config class "%s" does not exists.', $class));
+ }
+
+ return $this->configClasses[$class];
+ }
+
+ /**
+ * Add a extension.
+ *
+ * @param Mandango\Mondator\Extension $extension The extension.
+ *
+ * @api
+ */
+ public function addExtension(Extension $extension)
+ {
+ $this->extensions[] = $extension;
+ }
+
+ /**
+ * Set the extensions.
+ *
+ * @param array $extensions An array of extensions.
+ *
+ * @api
+ */
+ public function setExtensions(array $extensions)
+ {
+ $this->extensions = array();
+ foreach ($extensions as $extension) {
+ $this->addExtension($extension);
+ }
+ }
+
+ /**
+ * Returns the extensions.
+ *
+ * @return array The extensions.
+ *
+ * @api
+ */
+ public function getExtensions()
+ {
+ return $this->extensions;
+ }
+
+ /**
+ * Generate the containers.
+ *
+ * @return array The containers.
+ *
+ * @api
+ */
+ public function generateContainers()
+ {
+ $containers = array();
+ $containers['_global'] = new Container();
+
+ // global extensions
+ $globalExtensions = $this->getExtensions();
+
+ // configClasses
+ $configClasses = new \ArrayObject();
+ foreach ($this->getConfigClasses() as $class => $configClass) {
+ $configClasses[$class] = new \ArrayObject($configClass);
+ }
+
+ // classes extensions
+ $classesExtensions = new \ArrayObject();
+ $this->generateContainersClassesExtensions($globalExtensions, $classesExtensions, $configClasses);
+
+ // config class process
+ foreach ($classesExtensions as $class => $classExtensions) {
+ foreach ($classExtensions as $classExtension) {
+ $classExtension->configClassProcess($class, $configClasses);
+ }
+ }
+
+ // pre global process
+ foreach ($globalExtensions as $globalExtension) {
+ $globalExtension->preGlobalProcess($configClasses, $containers['_global']);
+ }
+
+ // class process
+ foreach ($classesExtensions as $class => $classExtensions) {
+ $containers[$class] = $container = new Container();
+ foreach ($classExtensions as $classExtension) {
+ $classExtension->classProcess($class, $configClasses, $container);
+ }
+ }
+
+ // post global process
+ foreach ($globalExtensions as $globalExtension) {
+ $globalExtension->postGlobalProcess($configClasses, $containers['_global']);
+ }
+
+ return $containers;
+ }
+
+ private function generateContainersClassesExtensions($globalExtensions, $classesExtensions, $configClasses)
+ {
+ foreach ($configClasses as $class => $configClass) {
+ if (isset($classesExtensions[$class])) {
+ continue;
+ }
+
+ $classesExtensions[$class] = $classExtensions = new \ArrayObject($globalExtensions);
+ $this->generateContainersNewClassExtensions($class, $classExtensions, $configClasses);
+
+ foreach ($classExtensions as $classExtension) {
+ $newConfigClasses = new \ArrayObject();
+ $classExtension->newConfigClassesProcess($class, $configClasses, $newConfigClasses);
+
+ foreach ($newConfigClasses as $newClass => $newConfigClass) {
+ if (isset($classesExtensions[$newClass])) {
+ throw new \RuntimeException(sprintf('The class "%s" has several config classes.', $class));
+ }
+ $configClasses[$newClass] = new \ArrayObject($newConfigClass);
+ }
+
+ $this->generateContainersClassesExtensions($globalExtensions, $classesExtensions, $configClasses);
+ }
+ }
+ }
+
+ private function generateContainersNewClassExtensions($class, $classExtensions, $configClasses, $extensions = null)
+ {
+ if (null === $extensions) {
+ $extensions = $classExtensions;
+ }
+
+ foreach ($extensions as $extension) {
+ $newClassExtensions = new \ArrayObject();
+ $extension->newClassExtensionsProcess($class, $configClasses, $newClassExtensions);
+
+ foreach ($newClassExtensions as $newClassExtension) {
+ if (!$newClassExtension instanceof ClassExtension) {
+ throw new \RuntimeException(sprintf('Some class extension of the class "%s" in the extension "%s" is not an instance of ClassExtension.', $class, get_class($extension)));
+ }
+ if ($newClassExtension instanceof Extension) {
+ throw new \RuntimeException(sprintf('Some class extension of the class "%s" in the extension "%s" is a instance of Extension, and it can be only a instance of ClassExtension.', $class, get_class($extension)));
+ }
+
+ $classExtensions[] = $newClassExtension;
+ $this->generateContainersNewClassExtensions($class, $classExtensions, $configClasses, $newClassExtension);
+ }
+ }
+ }
+
+ /**
+ * Dump containers.
+ *
+ * @param array $containers An array of containers.
+ *
+ * @api
+ */
+ public function dumpContainers(array $containers)
+ {
+ // directories
+ foreach ($containers as $container) {
+ foreach ($container->getDefinitions() as $name => $definition) {
+ $output = $definition->getOutput();
+ $dir = $output->getDir();
+
+ if (!file_exists($dir) && false === @mkdir($dir, 0777, true)) {
+ throw new \RuntimeException(sprintf('Unable to create the %s directory (%s).', $name, $dir));
+ }
+
+ if (!is_writable($dir)) {
+ throw new \RuntimeException(sprintf('Unable to write in the %s directory (%s).', $name, $dir));
+ }
+ }
+ }
+
+ // output
+ foreach ($containers as $container) {
+ foreach ($container->getDefinitions() as $name => $definition) {
+ $output = $definition->getOutput($name);
+ $dir = $output->getDir();
+
+ $file = $dir.DIRECTORY_SEPARATOR.$definition->getClassName().'.php';
+
+ if (!file_exists($file) || $output->getOverride()) {
+ $dumper = new Dumper($definition);
+ $content = $dumper->dump();
+
+ $tmpFile = tempnam(dirname($file), basename($file));
+ if (false === @file_put_contents($tmpFile, $content) || !@rename($tmpFile, $file)) {
+ throw new \RuntimeException(sprintf('Failed to write the file "%s".', $file));
+ }
+ chmod($file, 0644);
+ }
+ }
+ }
+ }
+
+ /**
+ * Generate and dump the containers.
+ *
+ * @api
+ */
+ public function process()
+ {
+ $this->dumpContainers($this->generateContainers());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/mondator/src/Mandango/Mondator/Output.php Thu Oct 27 05:47:14 2011 +0200
@@ -0,0 +1,87 @@
+<?php
+
+/*
+ * This file is part of Mandango.
+ *
+ * (c) Pablo Díez <pablodip@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Mandango\Mondator;
+
+/**
+ * Represents a output for a definition.
+ *
+ * @author Pablo Díez <pablodip@gmail.com>
+ *
+ * @api
+ */
+class Output
+{
+ private $dir;
+ private $override;
+
+ /**
+ * Constructor.
+ *
+ * @param string $dir The dir.
+ * @param bool $override The override. It indicate if override files (optional, false by default).
+ *
+ * @api
+ */
+ public function __construct($dir, $override = false)
+ {
+ $this->setDir($dir);
+ $this->setOverride($override);
+ }
+
+ /**
+ * Set the dir.
+ *
+ * @param $string $dir The dir.
+ *
+ * @api
+ */
+ public function setDir($dir)
+ {
+ $this->dir = $dir;
+ }
+
+ /**
+ * Returns the dir.
+ *
+ * @return string The dir.
+ *
+ * @api
+ */
+ public function getDir()
+ {
+ return $this->dir;
+ }
+
+ /**
+ * Set the override. It indicate if override files.
+ *
+ * @param bool $override The override.
+ *
+ * @api
+ */
+ public function setOverride($override)
+ {
+ $this->override = (bool) $override;
+ }
+
+ /**
+ * Returns the override.
+ *
+ * @return bool The override.
+ *
+ * @api
+ */
+ public function getOverride()
+ {
+ return $this->override;
+ }
+}