Skip to content

Clean integration of CouchDB #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CouchDocument/AccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move MongoDB to make way for CouchDB? This way, one of them seems "more important".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Apache CouchDB can have real advantage. For my project, I use it for scalability, and master-master replication capability. But, like you said, library are not up-to-date, I try to make some PR to keep these libraries usable with Symfony 3.X but they are not ready for 4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, should we move the MongoDB models to say FOS\Document\MongoDB to make room for other ODM implementations?


use FOS\OAuthServerBundle\Model\AccessToken as BaseAccessToken;

class AccessToken extends BaseAccessToken
{
}
20 changes: 20 additions & 0 deletions CouchDocument/AccessTokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\AccessTokenManagerInterface;

class AccessTokenManager extends TokenManager implements AccessTokenManagerInterface
{
}
23 changes: 23 additions & 0 deletions CouchDocument/AuthCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\AuthCode as BaseAuthCode;

/**
* @author Richard Fullmer <[email protected]>
*/
class AuthCode extends BaseAuthCode
{
}
86 changes: 86 additions & 0 deletions CouchDocument/AuthCodeManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager;

class AuthCodeManager extends BaseAuthCodeManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findAuthCodeBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}

/**
* {@inheritdoc}
*/
public function updateAuthCode(AuthCodeInterface $authCode)
{
$this->dm->persist($authCode);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteAuthCode(AuthCodeInterface $authCode)
{
$this->dm->remove($authCode);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteExpired()
{
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the existing code work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CouchDB work with JS view to make request, I don't have function to request and check date, I have to find a way to make this view and import this view in CouchDB.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but ODM abstracts all of it away. My questions was: why can't existing code (or something very similar to it) do the same task.

}
}
20 changes: 20 additions & 0 deletions CouchDocument/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\Client as BaseClient;

class Client extends BaseClient
{
}
86 changes: 86 additions & 0 deletions CouchDocument/ClientManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;

class ClientManager extends BaseClientManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findClientBy(array $criteria)
{
$client = $this->repository->findOneBy(['randomId' => $criteria['randomId']]);

if ($client !== null) {
if ($client->getId() === $criteria['id']) {
return $client;
}
}

return null;
}

/**
* {@inheritdoc}
*/
public function updateClient(ClientInterface $client)
{
$this->dm->persist($client);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteClient(ClientInterface $client)
{
$this->dm->remove($client);
$this->dm->flush();
}
}
20 changes: 20 additions & 0 deletions CouchDocument/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\RefreshToken as BaseRefreshToken;

class RefreshToken extends BaseRefreshToken
{
}
20 changes: 20 additions & 0 deletions CouchDocument/RefreshTokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface;

class RefreshTokenManager extends TokenManager implements RefreshTokenManagerInterface
{
}
86 changes: 86 additions & 0 deletions CouchDocument/TokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\TokenInterface;
use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;

class TokenManager extends BaseTokenManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findTokenBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}

/**
* {@inheritdoc}
*/
public function updateToken(TokenInterface $token)
{
$this->dm->persist($token);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteToken(TokenInterface $token)
{
$this->dm->remove($token);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteExpired()
{
return null;
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getConfigTreeBuilder()
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('fos_oauth_server');

$supportedDrivers = ['orm', 'mongodb', 'propel'];
$supportedDrivers = ['orm', 'mongodb', 'propel', 'couchdb'];

$rootNode
->children()
Expand Down
Loading