Skip to content

Commit

Permalink
Remove entities CRUDL controller as useless from library level.
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Dec 18, 2014
1 parent 0ac9312 commit 25fc168
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 162 deletions.
7 changes: 7 additions & 0 deletions app/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
117 changes: 0 additions & 117 deletions src/AuthBucket/OAuth2/Controller/ClientController.php

This file was deleted.

27 changes: 0 additions & 27 deletions src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

namespace AuthBucket\OAuth2\Provider;

use AuthBucket\OAuth2\Controller\AuthorizeController;
use AuthBucket\OAuth2\Controller\ClientController;
use AuthBucket\OAuth2\Controller\OAuth2Controller;
use AuthBucket\OAuth2\Controller\ScopeController;
use AuthBucket\OAuth2\EventListener\ExceptionListener;
use AuthBucket\OAuth2\GrantType\GrantTypeHandlerFactory;
use AuthBucket\OAuth2\Model\InMemory\ModelManagerFactory;
Expand Down Expand Up @@ -138,30 +135,6 @@ public function register(Application $app)
);
});

$app['authbucket_oauth2.authorize_controller'] = $app->share(function () use ($app) {
return new AuthorizeController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['authbucket_oauth2.client_controller'] = $app->share(function () use ($app) {
return new ClientController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['authbucket_oauth2.scope_controller'] = $app->share(function () use ($app) {
return new ScopeController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['security.authentication_provider.oauth2_token._proto'] = $app->protect(function ($name, $options) use ($app) {
return $app->share(function () use ($app, $name, $options) {
return new TokenProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace AuthBucket\OAuth2\Controller;
namespace AuthBucket\OAuth2\Tests\TestBundle\Controller;

use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,107 @@

namespace AuthBucket\OAuth2\Tests\TestBundle\Controller;

use Silex\Application;
use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\ValidatorInterface;

/**
* Client endpoint controller implementation.
*
* @author Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
*/
class ClientController
{
public function indexAction(Request $request, Application $app)
protected $validator;
protected $serializer;
protected $modelManagerFactory;

public function __construct(
ValidatorInterface $validator,
SerializerInterface $serializer,
ModelManagerFactoryInterface $modelManagerFactory
) {
$this->validator = $validator;
$this->serializer = $serializer;
$this->modelManagerFactory = $modelManagerFactory;
}

public function createAction(Request $request)
{
$format = $request->getRequestFormat();

$modelManager = $this->modelManagerFactory->getModelManager('client');
$model = $this->serializer->deserialize(
$request->getContent(),
$modelManager->getClassName(),
$format
);
$model = $modelManager->createModel($model);

return new Response($this->serializer->serialize($model, $format), 200, array(
"Content-Type" => $request->getMimeType($format),
));
}

public function readAction(Request $request, $id)
{
$format = $request->getRequestFormat();

$modelManager = $this->modelManagerFactory->getModelManager('client');
$model = $modelManager->readModelOneBy(array('id' => (int) $id));

return new Response($this->serializer->serialize($model, $format), 200, array(
"Content-Type" => $request->getMimeType($format),
));
}

public function updateAction(Request $request, $id)
{
$format = $request->getRequestFormat();

$modelManager = $this->modelManagerFactory->getModelManager('client');
$model = $modelManager->readModelOneBy(array('id' => (int) $id));

$values = $this->serializer->decode($request->getContent(), $format);
foreach ($values as $key => $value) {
$setter = 'set'.ucfirst($key);
if (method_exists($model, $setter)) {
$model->$setter($value);
}
}

$model = $modelManager->updateModel($model);

return new Response($this->serializer->serialize($model, $format), 200, array(
"Content-Type" => $request->getMimeType($format),
));
}

public function deleteAction(Request $request, $id)
{
return $app['twig']->render('client/index.html.twig');
$format = $request->getRequestFormat();

$modelManager = $this->modelManagerFactory->getModelManager('client');
$model = $modelManager->readModelOneBy(array('id' => (int) $id));
$model = $modelManager->deleteModel($model);

return new Response($this->serializer->serialize($model, $format), 200, array(
"Content-Type" => $request->getMimeType($format),
));
}

public function listAction(Request $request)
{
$format = $request->getRequestFormat();

$modelManager = $this->modelManagerFactory->getModelManager('client');
$model = $modelManager->readModelAll();

return new Response($this->serializer->serialize($model, $format), 200, array(
"Content-Type" => $request->getMimeType($format),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace AuthBucket\OAuth2\Controller;
namespace AuthBucket\OAuth2\Tests\TestBundle\Controller;

use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
$app->get('/admin/refresh_database', 'authbucket_oauth2.tests.default_controller:adminRefreshDatabaseAction')
->bind('admin_refresh_database');

$app->get('/client', 'authbucket_oauth2.tests.client_controller:indexAction')
->bind('client');

$app->get('/demo', 'authbucket_oauth2.tests.demo_controller:indexAction')
->bind('demo');

Expand Down Expand Up @@ -71,23 +68,23 @@
->method('GET|POST');

foreach (array('authorize', 'client', 'scope') as $type) {
$app->post('/api/v1.0/'.$type.'.{_format}', 'authbucket_oauth2.'.$type.'_controller:createAction')
$app->post('/api/v1.0/'.$type.'.{_format}', 'authbucket_oauth2.tests.'.$type.'_controller:createAction')
->bind('api_'.$type.'_create')
->assert('_format', 'json|xml');

$app->get('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.'.$type.'_controller:readAction')
$app->get('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.tests.'.$type.'_controller:readAction')
->bind('api_'.$type.'_read')
->assert('_format', 'json|xml');

$app->put('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.'.$type.'_controller:updateAction')
$app->put('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.tests.'.$type.'_controller:updateAction')
->bind('api_'.$type.'_update')
->assert('_format', 'json|xml');

$app->delete('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.'.$type.'_controller:deleteAction')
$app->delete('/api/v1.0/'.$type.'/{id}.{_format}', 'authbucket_oauth2.tests.'.$type.'_controller:deleteAction')
->bind('api_'.$type.'_delete')
->assert('_format', 'json|xml');

$app->get('/api/v1.0/'.$type.'.{_format}', 'authbucket_oauth2.'.$type.'_controller:listAction')
$app->get('/api/v1.0/'.$type.'.{_format}', 'authbucket_oauth2.tests.'.$type.'_controller:listAction')
->bind('api_'.$type.'_list')
->assert('_format', 'json|xml');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{ path('demo') }}">Demo</a></li>
<li><a href="{{ path('client') }}">Client</a></li>
<li><a href="{{ path('oauth2') }}">Authorization Server</a></li>
<li><a href="{{ path('resource') }}">Resource Server</a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace AuthBucket\OAuth2\Tests\TestBundle;

use AuthBucket\OAuth2\Tests\TestBundle\Controller\AuthorizeController;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\ClientController;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\DefaultController;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\DemoController;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\OAuth2Controller;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\ResourceController;
use AuthBucket\OAuth2\Tests\TestBundle\Controller\ScopeController;
use Silex\Application;
use Silex\ServiceProviderInterface;

Expand All @@ -28,6 +30,30 @@ class TestBundleServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['authbucket_oauth2.tests.authorize_controller'] = $app->share(function () use ($app) {
return new AuthorizeController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['authbucket_oauth2.tests.client_controller'] = $app->share(function () use ($app) {
return new ClientController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['authbucket_oauth2.tests.scope_controller'] = $app->share(function () use ($app) {
return new ScopeController(
$app['validator'],
$app['serializer'],
$app['authbucket_oauth2.model_manager.factory']
);
});

$app['authbucket_oauth2.tests.default_controller'] = $app->share(function () {
return new DefaultController();
});
Expand All @@ -36,10 +62,6 @@ public function register(Application $app)
return new DemoController();
});

$app['authbucket_oauth2.tests.client_controller'] = $app->share(function () {
return new ClientController();
});

$app['authbucket_oauth2.tests.oauth2_controller'] = $app->share(function () {
return new OAuth2Controller();
});
Expand Down

0 comments on commit 25fc168

Please sign in to comment.