-
Notifications
You must be signed in to change notification settings - Fork 60
Mongodb support #46
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
vlefr
wants to merge
6
commits into
rvanlaak:3.x
Choose a base branch
from
vlefr:mongodb-support
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mongodb support #46
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e06d6a
add document to work with mongodb
06e2f53
update service to work with db driver
4809429
add configuration check for db driver
591c969
load db services
92b9469
refactor settings manager with mongodb
29be6e6
fix setting retrieve with mongodb
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * This file is part of the DmishhSettingsBundle package. | ||
| * | ||
| * (c) 2013 Dmitriy Scherbina <http://dmishh.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Dmishh\Bundle\SettingsBundle\Document; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
| use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
|
|
||
| /** | ||
| * @MongoDB\Document | ||
| */ | ||
| class Setting | ||
| { | ||
| /** | ||
| * @MongoDB\Id | ||
| */ | ||
| private $id; | ||
|
|
||
| /** | ||
| * @MongoDB\String | ||
| */ | ||
| private $name; | ||
|
|
||
| /** | ||
| * @MongoDB\String | ||
| */ | ||
| private $value; | ||
|
|
||
| /** | ||
| * @MongoDB\ReferenceOne | ||
| */ | ||
| private $owner; | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getId() | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $id | ||
| */ | ||
| public function setId($id) | ||
| { | ||
| $this->id = $id; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getName() | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $name | ||
| */ | ||
| public function setName($name) | ||
| { | ||
| $this->name = $name; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getValue() | ||
| { | ||
| return $this->value; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function setValue($value) | ||
| { | ||
| $this->value = $value; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getOwner() | ||
| { | ||
| return $this->owner; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $owner | ||
| */ | ||
| public function setOwner($owner) | ||
| { | ||
| $this->owner = $owner; | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
src/Dmishh/Bundle/SettingsBundle/Manager/MongoDB/SettingsManager.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
| /** | ||
| * Created by PhpStorm. | ||
| * User: Victor | ||
| * Date: 22/10/15 | ||
| * Time: 12:58 | ||
| */ | ||
| namespace Dmishh\Bundle\SettingsBundle\Manager\MongoDB; | ||
| use Dmishh\Bundle\SettingsBundle\Document\Setting; | ||
| use Dmishh\Bundle\SettingsBundle\Entity\SettingsOwnerInterface; | ||
| use Dmishh\Bundle\SettingsBundle\Exception\WrongScopeException; | ||
| use Dmishh\Bundle\SettingsBundle\Serializer\SerializerInterface; | ||
| use Doctrine\ODM\MongoDB\DocumentManager; | ||
|
|
||
| class SettingsManager extends \Dmishh\Bundle\SettingsBundle\Manager\SettingsManager { | ||
|
|
||
| /** | ||
| * @param DocumentManager $em | ||
| * @param SerializerInterface $serializer | ||
| * @param array $settingsConfiguration | ||
| */ | ||
| public function __construct( | ||
| DocumentManager $em, | ||
| SerializerInterface $serializer, | ||
| array $settingsConfiguration = array() | ||
| ) { | ||
| $this->em = $em; | ||
| $this->repository = $em->getRepository('Dmishh\Bundle\SettingsBundle\Document\Setting'); | ||
| $this->serializer = $serializer; | ||
| $this->settingsConfiguration = $settingsConfiguration; | ||
| } | ||
|
|
||
| /** | ||
| * Retreives settings from repository. | ||
| * | ||
| * @param SettingsOwnerInterface|null $owner | ||
| * | ||
| * @throws \Dmishh\Bundle\SettingsBundle\Exception\UnknownSerializerException | ||
| * @return array | ||
| */ | ||
| protected function getSettingsFromRepository(SettingsOwnerInterface $owner = null) | ||
| { | ||
| $settings = array(); | ||
|
|
||
| foreach (array_keys($this->settingsConfiguration) as $name) { | ||
| try { | ||
| $this->validateSetting($name, $owner); | ||
| $settings[$name] = null; | ||
| } catch (WrongScopeException $e) { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| /** @var Setting $setting */ | ||
| foreach ($this->repository->findBy( | ||
| array('owner.id' => $owner === null ? null : $owner->getSettingIdentifier()) | ||
| ) as $setting) { | ||
| if (array_key_exists($setting->getName(), $settings)) { | ||
| $settings[$setting->getName()] = $this->serializer->unserialize($setting->getValue()); | ||
| } | ||
| } | ||
|
|
||
| return $settings; | ||
| } | ||
|
|
||
| protected function getNewSetting(SettingsOwnerInterface $owner = null){ | ||
| $setting = new Setting(); | ||
| if ($owner !== null) { | ||
| $setting->setOwner($owner); | ||
| } | ||
| return $setting; | ||
|
|
||
| } | ||
|
|
||
| protected function getSettingsFromRepositoryByNames($names,SettingsOwnerInterface $owner = null){ | ||
| $settings = $this->repository->findBy(array( | ||
| 'name' => array('$in' => $names), | ||
| 'owner.$id' => $owner === null ? null : new \MongoId($owner->getSettingIdentifier()) | ||
| ) | ||
| ); | ||
| return $settings; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Dmishh/Bundle/SettingsBundle/Resources/config/services_mongodb.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| services: | ||
| dmishh.settings.settings_manager: | ||
| class: Dmishh\Bundle\SettingsBundle\Manager\MongoDB\SettingsManager | ||
| arguments: | ||
| - @doctrine.odm.mongodb.document_manager | ||
| - @dmishh.settings.serializer | ||
| - %settings_manager.settings% |
7 changes: 7 additions & 0 deletions
7
src/Dmishh/Bundle/SettingsBundle/Resources/config/services_orm.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| services: | ||
| dmishh.settings.settings_manager: | ||
| class: Dmishh\Bundle\SettingsBundle\Manager\SettingsManager | ||
| arguments: | ||
| - @doctrine.orm.entity_manager | ||
| - @dmishh.settings.serializer | ||
| - %settings_manager.settings% |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be
implodeinstead ofjson_encodeI think? Rest of the code looks quite okay, but I've got no MongoDB experience to validate this.