Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
eminetto committed May 15, 2012
1 parent dd048fd commit be12c98
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 369 deletions.
54 changes: 40 additions & 14 deletions bootstrap.php
Expand Up @@ -13,6 +13,9 @@
Doctrine\ORM\Configuration,
Doctrine\Common\Cache\ArrayCache as Cache,
Doctrine\Common\Annotations\AnnotationRegistry,
Doctrine\Common\Annotations\AnnotationReader,
DMS\Filter\Mapping,
DMS\Filter\Filter,
Doctrine\Common\ClassLoader;

require_once __DIR__.'/vendor/silex.phar';
Expand Down Expand Up @@ -43,31 +46,48 @@
$classLoaderMetadata = new \Doctrine\Common\ClassLoader('Metadata', __DIR__.'/vendor/Metadata/src' );
$classLoaderMetadata->register();

$classLoaderModel = new \Doctrine\Common\ClassLoader('model', __DIR__ );
$classLoaderLibrary = new \Doctrine\Common\ClassLoader('library', __DIR__ );
$classLoaderLibrary->register();

$classLoaderCoderockr = new \Doctrine\Common\ClassLoader('Coderockr', __DIR__.'/vendor' );
$classLoaderCoderockr->register();

$classLoaderModel = new \Doctrine\Common\ClassLoader('model', getenv('APPLICATION_PATH') . '/library' );
$classLoaderModel->register();

$classLoaderService = new \Doctrine\Common\ClassLoader('service', __DIR__ );
$classLoaderService = new \Doctrine\Common\ClassLoader('service', getenv('APPLICATION_PATH') . '/library' );
$classLoaderService->register();

$classLoaderTest = new \Doctrine\Common\ClassLoader('test', __DIR__ );
$classLoaderTest = new \Doctrine\Common\ClassLoader('test', getenv('APPLICATION_PATH') . '/library' );
$classLoaderTest->register();

$classLoaderCoderockr = new \Doctrine\Common\ClassLoader('Coderockr', __DIR__.'/vendor' );
$classLoaderCoderockr->register();


if(!getenv('APPLICATION_ENV'))
$env = 'testing';
else
$env = getenv('APPLICATION_ENV');

if ($env == 'testing')
include __DIR__.'/configs/configs.testing.php';
include getenv('APPLICATION_PATH').'/configs/configs.testing.php';
elseif ($env == 'development')
include __DIR__.'/configs/configs.development.php';
include getenv('APPLICATION_PATH').'/configs/configs.development.php';
else
include __DIR__.'/configs/configs.php';
include getenv('APPLICATION_PATH').'/configs/configs.php';

//filter
//Get Doctrine Reader
$reader = new AnnotationReader();
//$reader->setEnableParsePhpImports(true);

//Load AnnotationLoader
$loader = new Mapping\Loader\AnnotationLoader($reader);

include __DIR__.'/library/filter.php';
//Get a MetadataFactory
$metadataFactory = new Mapping\ClassMetadataFactory($loader);

//Get a Filter
$filter = new Filter($metadataFactory);

//doctrine
$config = new Configuration();
Expand All @@ -80,6 +100,7 @@
//mapping (example uses annotations, could be any of XML/YAML or plain PHP)
AnnotationRegistry::registerFile(__DIR__.'/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
AnnotationRegistry::registerAutoloadNamespace('JMS', __DIR__.'/vendor');
AnnotationRegistry::registerAutoloadNamespace('DMS', __DIR__.'/vendor');

$driver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
new Doctrine\Common\Annotations\AnnotationReader(),
Expand All @@ -97,10 +118,15 @@

//load subscribers
$evm = $em->getEventManager();
$directoryIterator = new \DirectoryIterator(__DIR__ . '/model/subscriber');
foreach ($directoryIterator as $f) {
if ($f->getFileName() != '.' && $f->getFilename() !='..') {
$subscriber = 'model\\subscriber\\' . $f->getBasename('.php');
$evm->addEventSubscriber(new $subscriber);
try {
$directoryIterator = new \DirectoryIterator(__DIR__ . '/model/subscriber');
foreach ($directoryIterator as $f) {
if ($f->getFileName() != '.' && $f->getFilename() !='..') {
$subscriber = 'model\\subscriber\\' . $f->getBasename('.php');
$evm->addEventSubscriber(new $subscriber);
}
}
}catch (UnexpectedValueException $e) {
//directory doesn't exists
}

6 changes: 0 additions & 6 deletions configs/clients.php

This file was deleted.

11 changes: 0 additions & 11 deletions configs/configs.development.php

This file was deleted.

10 changes: 0 additions & 10 deletions configs/configs.php

This file was deleted.

11 changes: 0 additions & 11 deletions configs/configs.testing.php

This file was deleted.

7 changes: 3 additions & 4 deletions index.php
Expand Up @@ -63,7 +63,6 @@
$serializer = new service\Serializer();
$serializer->setGroups(array('entity', $entity));
$entityName = 'model\\' .ucfirst($entity);
//$query = "SELECT e FROM $entityName e";

$qb = $em->createQueryBuilder();

Expand Down Expand Up @@ -209,14 +208,14 @@
});

//rpc
$app->post('/rpc/{service}', function ($service, Request $request) use ($app)
$app->post('/rpc/{service}', function ($service, Request $request) use ($app, $em)
{
$service = "service\\". ucfirst($service);

if (!class_exists($service)) {
return new Response('Invalid service.', 400, array('Content-Type' => 'text/json'));
}
$class = new $service;
$class = new $service($em);
if (!$parameters = $request->get('parameters'))
$parameters = array();

Expand Down Expand Up @@ -252,7 +251,7 @@
return new Response('Unauthorized', 401);
}

require_once __DIR__.'/configs/clients.php';
require_once getenv('APPLICATION_PATH').'/configs/clients.php';
if (!in_array($request->headers->get('authorization'), array_keys($clients))) {
return new Response('Unauthorized', 401);
}
Expand Down
2 changes: 1 addition & 1 deletion service/Serializer.php → library/Serializer.php
@@ -1,5 +1,5 @@
<?php
namespace service;
namespace library;


use JMS\SerializerBundle\Serializer\Serializer as JMSSerializer;
Expand Down
36 changes: 0 additions & 36 deletions library/doctrine.php

This file was deleted.

17 changes: 0 additions & 17 deletions library/filter.php

This file was deleted.

87 changes: 0 additions & 87 deletions model/Entity.php

This file was deleted.

64 changes: 0 additions & 64 deletions public/scripts/RestClient.js

This file was deleted.

0 comments on commit be12c98

Please sign in to comment.