public function register(Application $app)
 {
     $configuration = $app['mandango.configuration'];
     if (!isset($configuration['metadata_factory_class'])) {
         throw new \Exception("Missing param 'metadata_factory_class' in 'mandango.configuration'");
     }
     if (!isset($configuration['metadata_factory_output'])) {
         throw new \Exception("Missing param 'metadata_factory_output' in 'mandango.configuration'");
     }
     if (!isset($configuration['default_output'])) {
         throw new \Exception("Missing param 'default_output' in 'mandango.configuration'");
     }
     if (!isset($configuration['schema_file'])) {
         throw new \Exception("Missing param 'schema_file' in 'mandango.configuration'");
     }
     if (!isset($app['mandango.token'])) {
         throw new \Exception("Missing param 'mandango.token'");
     }
     $app['mandango'] = $app->share(function () use($app) {
         $connections = isset($app['mandango.connections']) ? $app['mandango.connections'] : array('local' => array('host' => 'mongodb://localhost:27017', 'database' => 'test'));
         $default = isset($app['mandango.default_connection']) ? $app['mandango.default_connection'] : 'local';
         $logging = isset($app['mandango.logging']) ? (bool) $app['mandango.logging'] : false;
         $cache_dir = isset($app['mandango.cache_dir']) ? $app['mandango.cache_dir'] : sys_get_tempd_dir();
         $metadata = new $app['mandango.configuration']['metadata_factory_class']();
         $mandango = new Mandango($metadata, new FilesystemCache($cache_dir));
         foreach ($connections as $name => $config) {
             $connections[$name] = new Connection($config['host'], $config['database']);
         }
         $mandango->setConnections($connections);
         $mandango->setDefaultConnectionName($default);
         return $mandango;
     });
     $app['mandango.mondator'] = $app->share(function () use($app, $configuration) {
         $mondator = new Mondator();
         $mondator->setConfigClasses(require $configuration['schema_file']);
         $mondator->setExtensions(array(new \Mandango\Extension\Core(array('metadata_factory_class' => $configuration['metadata_factory_class'], 'metadata_factory_output' => $configuration['metadata_factory_output'], 'default_output' => $configuration['default_output']))));
         return $mondator;
     });
     $app->get('/_mandango/generate/{token}', function ($token) use($app) {
         if ($token !== $app['mandango.token']) {
             return 'Access Denied!';
         }
         $app['mandango.mondator']->process();
         return 'Successfull generated models';
     });
     // autoloading Mandango library
     if (isset($app['mandango.class_path'])) {
         $app['autoloader']->registerNamespace('Mandango', $app['mandango.class_path']);
         $app['autoloader']->registerNamespace('Mandango\\Mondator', $app['mandango.class_path'] . '/../vendor/mondator/src');
     }
     if (isset($configuration['default_output'])) {
         $outputDir = rtrim($configuration['default_output'], DIRECTORY_SEPARATOR);
         $outputDir = dirname($outputDir);
         $app['autoloader']->registerNamespace(isset($configuration['model_namespace']) ? $configuration['model_namespace'] : 'Model', $outputDir);
     }
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Get the schema
     $schema = \Config::get('laravel-mandango::mandango.schema');
     $mondator = new Mondator();
     $mondator->setConfigClasses($schema);
     $directory = app_path() . '/mandango';
     $this->info('Writing Mondango classes to ' . $directory);
     $mondator->setExtensions(array(new \Mandango\Extension\Core(array('metadata_factory_class' => 'Model\\Mapping\\Metadata', 'metadata_factory_output' => $directory . '/models/Mapping', 'default_output' => $directory . '/models')), new \Mandango\Extension\DocumentPropertyOverloading(), new \Mandango\Extension\DocumentArrayAccess()));
     $mondator->process();
 }
Example #3
0
 public function testGenerateContainersNewConfigClasses()
 {
     $mondator = new Mondator();
     $mondator->setConfigClasses(array('Article' => array('name' => 'MyArticle', 'extensions' => array(array('class' => 'Mandango\\Mondator\\Tests\\Fixtures\\Extension\\NewConfigClass', 'options' => array('suffix' => 'Translation', 'name' => 'translation', 'multiple' => true, 'multiple_suffix' => 'Multiple', 'multiple_name' => 'multiplex')))), 'Category' => array('name' => 'MyCategory')));
     $mondator->setExtensions(array(new \Mandango\Mondator\Tests\Fixtures\Extension\Name(), new \Mandango\Mondator\Tests\Fixtures\Extension\ProcessOthersFromArray()));
     $containers = $mondator->generateContainers();
     $this->assertSame(5, count($containers));
     $this->assertTrue(isset($containers['_global']));
     $this->assertTrue(isset($containers['Article']));
     $this->assertTrue(isset($containers['ArticleTranslation']));
     $this->assertTrue(isset($containers['ArticleTranslationMultiple']));
     $this->assertTrue(isset($containers['Category']));
 }
 public function register(Container $app)
 {
     $app['mondator'] = function ($app) {
         if (!$app['mongator.models.output']) {
             throw new \LogicException('You must register "mongator.models.output" to this provider');
         }
         if (!$app['mongator.metadata.class']) {
             throw new \LogicException('You must register "mongator.metadata.class" to this provider');
         }
         $extensions = array(new Core(array('metadata_factory_class' => $app['mongator.metadata.class'], 'metadata_factory_output' => $app['mongator.models.output'], 'default_output' => $app['mongator.models.output'])));
         $mondator = new Mondator();
         $mondator->setExtensions(array_merge($extensions, $app['mongator.extensions']));
         return $mondator;
     };
     $app['mongator.extensions'] = array();
     $app['mongator.models.output'] = null;
 }
Example #5
0
 public function mondatorProcessAction()
 {
     // Config
     $config = $this->getServiceLocator()->get('Config');
     $configMandango = $config['skar']['mandango'];
     // Start Mondator
     $mondator = new Mondator();
     // Assign the config classes
     if (is_array($configMandango['config_classes'])) {
         $mondator->setConfigClasses($configMandango['config_classes']);
     } else {
         $mondator->setConfigClasses($config[$configMandango['config_classes']]);
     }
     // Assign extensions
     $mondator->setExtensions(array(new MandangoCore(array('metadata_factory_class' => $configMandango['metadata_factory_class'], 'metadata_factory_output' => $configMandango['metadata_factory_output'], 'default_output' => $configMandango['default_output']))));
     // Process
     $mondator->process();
 }
<?php

$loader = (require __DIR__ . '/../vendor/.composer/autoload.php');
$loader->add('Mandango\\Tests', __DIR__);
$loader->add('Model', __DIR__);
// mondator
$configClasses = (require __DIR__ . '/config_classes.php');
use Mandango\Mondator\Mondator;
$mondator = new Mondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(new Mandango\Extension\Core(array('metadata_factory_class' => 'Model\\Mapping\\MetadataFactory', 'metadata_factory_output' => __DIR__ . '/Model/Mapping', 'default_output' => __DIR__ . '/Model'))));
$mondator->process();
Example #7
0
<?php

$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->add('Mongator\\Tests', __DIR__);
$loader->add('Model', __DIR__);
// mondator
$configClasses = (require __DIR__ . '/config_classes.php');
use Mandango\Mondator\Mondator;
$mondator = new Mondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(new Mongator\Extension\Core(array('metadata_factory_class' => 'Model\\Mapping\\MetadataFactory', 'metadata_factory_output' => __DIR__, 'default_output' => __DIR__))));
$mondator->process();
Example #8
0
 public function testProcessUsesNamespaceSeparatorForNestingClassFilesInDirectories()
 {
     $tmpDir = sys_get_temp_dir();
     $expectedFile = $tmpDir . '/MiClase/Test.php';
     if (file_exists($expectedFile)) {
         unlink($expectedFile);
     }
     $mondator = new Mondator();
     $mondator->setConfigClass('Foo', array());
     $mondator->setExtensions(array(new \Mandango\Mondator\Tests\Fixtures\Extension\InitDefinition(array('definition_name' => 'myclass', 'class_name' => 'MiClase\\Test', 'output_dir' => $tmpDir)), new \Mandango\Mondator\Extension\NamespaceSeparatorOutputFixerExtension()));
     $mondator->process();
     $this->assertFileExists($expectedFile);
 }
Example #9
0
<?php

$vendorDir = __DIR__ . '/../vendor';
require_once $vendorDir . '/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('Mandango' => __DIR__ . '/../src', 'Mandango\\Tests' => __DIR__, 'Mandango\\Mondator' => $vendorDir . '/mondator/src', 'Model' => __DIR__));
$loader->registerPrefixes(array('Twig_' => $vendorDir . '/twig/lib'));
$loader->register();
// mondator
$configClasses = (require __DIR__ . '/config_classes.php');
use Mandango\Mondator\Mondator;
$mondator = new Mondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(new Mandango\Extension\Core(array('metadata_factory_class' => 'Model\\Mapping\\Metadata', 'metadata_factory_output' => __DIR__ . '/Model/Mapping', 'default_output' => __DIR__ . '/Model')), new Mandango\Extension\DocumentArrayAccess(), new Mandango\Extension\DocumentPropertyOverloading()));
$mondator->process();
Example #10
0
<?php

$loader = (require __DIR__ . "/../vendor/autoload.php");
$loader->add('Model', __DIR__);
// mondator
use Mandango\Mondator\Mondator;
$configClasses = array('Model\\Article' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => array('type' => 'string', 'length' => 100), 'slug' => array('name' => 'titleSlug', 'type' => 'string', 'length' => 110, 'unique' => true), 'content' => 'text', 'source' => array('type' => 'string', 'length' => 255, 'nullable' => true), 'isActive' => array('type' => 'boolean', 'default' => true), 'score' => array('type' => 'decimal', 'precision' => 2, 'scale' => 4), 'date' => 'date'), 'many_to_one' => array('category' => array('class' => 'Model\\Category', 'inversedBy' => 'articles')), 'indexes' => array('my_slug_index' => array('columns' => array('titleSlug'), 'unique' => true), 'isActive_date' => array('columns' => array('isActive', 'date')))), 'Model\\Category' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'name' => array('type' => 'string', 'length' => 100)), 'one_to_many' => array('articles' => array('class' => 'Model\\Article', 'mappedBy' => 'category'))), 'Model\\Simple' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'column' => array('type' => 'string', 'length' => 255), 'column2' => array('type' => 'string', 'length' => 255, 'nullable' => true))), 'Model\\Student' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'name' => array('type' => 'string', 'length' => 255)), 'many_to_one' => array('school' => array('class' => 'Model\\School', 'inversedBy' => 'students'))), 'Model\\School' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'name' => array('type' => 'string', 'length' => 255)), 'one_to_many' => array('students' => array('class' => 'Model\\Student', 'mappedBy' => 'school'))), 'Model\\Person' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'name' => array('type' => 'string', 'length' => 255)), 'many_to_many' => array('likings' => array('class' => 'Model\\Liking', 'inversedBy' => 'persons'))), 'Model\\Liking' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'name' => array('type' => 'string', 'length' => 255)), 'many_to_many' => array('persons' => array('class' => 'Model\\Person', 'mappedBy' => 'likings'))), 'Model\\IdentifierStrategyIdentity' => array('columns' => array('id' => array('id' => array('strategy' => 'identity'), 'type' => 'integer'))), 'Model\\IdentifierStrategyNone' => array('columns' => array('id' => array('id' => array('strategy' => 'none'), 'type' => 'integer'))), 'Model\\Hashable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Hashable'))), 'Model\\Ipable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Ipable'))), 'Model\\Sluggable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Sluggable', 'options' => array('from_column' => 'title')))), 'Model\\SluggableUpdate' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string', 'body' => array('type' => 'text', 'nullable' => true)), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Sluggable', 'options' => array('from_column' => 'title', 'update' => true)))), 'Model\\Sortable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Sortable'))), 'Model\\Taggable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Taggable'))), 'Model\\Timestampable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => 'string'), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Timestampable'))), 'Model\\Translatable' => array('columns' => array('id' => array('id' => 'auto', 'type' => 'integer'), 'title' => array('type' => 'string', 'length' => 255), 'body' => array('type' => 'text'), 'date' => array('type' => 'datetime'), 'isActive' => array('type' => 'boolean', 'default' => true)), 'behaviors' => array(array('class' => 'Doctrator\\Behavior\\Translatable', 'options' => array('columns' => array('title', 'body'))))));
$mondator = new Mondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(new Doctrator\Extension\Core(array('default_output' => __DIR__ . '/Model')), new Doctrator\Extension\ActiveRecord(), new Doctrator\Extension\ArrayAccess(), new Doctrator\Extension\PropertyOverloading(), new Doctrator\Extension\Behaviors()));
$mondator->process();
/*
 * Not ActiveRecord
 */
$mondator = new Mondator();
$mondator->setConfigClasses($configClasses);
$mondator->setExtensions(array(new Doctrator\Extension\Core(array('default_output' => __DIR__ . '/ModelNotAR'))));
$mondator->process();
 protected function registerMondator()
 {
     $this->app['mondator'] = $this->app->share(function ($app) {
         if (!$app['config']['mongator::models_output']) {
             throw new \LogicException('You must register "mongator::models_output" to this provider');
         }
         if (!$app['config']['mongator::metadata_class']) {
             throw new \LogicException('You must register "mongator::metadata_class" to this provider');
         }
         $extensions = array(new Core(array('metadata_factory_class' => $app['config']['mongator::metadata_class'], 'metadata_factory_output' => $app['config']['mongator::models_output'], 'default_output' => $app['config']['mongator::models_output'])));
         $mondator = new Mondator();
         $mondator->setExtensions(array_merge($extensions, $app['config']['mongator::extensions']));
         return $mondator;
     });
 }