Upload
gene-kobilansky
View
452
Download
1
Embed Size (px)
Citation preview
Symfony with MongoDB AND MySQLYes, but why?!
wealth management, set free
Symfony● Stable● Plenty of Resources● Interoperability● Open Source● + Doctrine!
Doctrine● Decoupled from Symfony and
optional● DB connections setup in
parameters.yml● Doctrine MongoDB Bundle ● Doctrine Fixtures Bundle
integrated in Symfony standard edition
From http://symfony.com/doc/current/book/doctrine.html
A tale of two layers
wealthbot/app/config/config.yml
A tale of two layersMySQL = presentation
● Relational● Table● Vertical Scaling● Normalization: make tables as small as
possible (ex: user table)● PAS normalizes to MySQL
Mongo = communication
● Non-relational / NoSQL● Key - value pairs (JSON/BSON)● Horizontal scaling● Denormalization: to quickly get all the data● Standardize into mongo ● Do pre-calcs in mongo (bc it’s faster)
“Makes coding life easier, but must know the structure ahead of time”
“We don't know what the data file will look like from custodians”
MongoDBBundle
● Deal only with plain PHP objects
● Persist transparently to and from MongoDB
● Mapping via DocBlock annotations{
"require": { "doctrine/mongodb-odm": "~1.0", "doctrine/mongodb-odm-bundle": "~3.0" },}
Fixtures Bundle
● Fixtures are PHP classes● Load a controlled set of data● Used for testing or could be the
initial data● Shares Objects between
Fixtures● (enable in app/AppKernal.php)
$ composer require --dev doctrine/doctrine-fixtures-bundle
Exampleswealthbot/src/Wealthbot/FixturesBundle/DataFixtures/ORM/LoadClientData.php
class LoadClientData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface {
private $accounts = array( array( 'consolidator_key' => null, 'group_key' => AccountGroup::GROUP_DEPOSIT_MONEY, 'type_key' => 10, 'financial_institution' => null, 'value' => 20000, 'monthly_contributions' => null, 'monthly_distributions' => null, 'sas_cash' => 1500, ), ...
Examples cont.wealthbot/src/Wealthbot/FixturesBundle/DataFixtures/ORM/LoadClientData.php
private function createClientAccounts(ObjectManager $manager, User $clientUser) { foreach ($this->accounts as $index => $item) {
$account = new ClientAccount(); $account->setGroupType($groupType); $account->setClient($clientUser); $account->setMonthlyDistributions($item['monthly_distributions']); $account->setSasCash($item['sas_cash']); $accountOwner = new ClientAccountOwner(); $accountOwner->setAccount($account); $accountOwner->setClient($clientUser); $accountOwner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF);
}}
Why not just mongo?
● Cleaner code● More predictable = better unit
testing● Faster dashboards● And yet, flexible enough when
working with custodians
wealthbot.io
@wealthbot
https://github.com/wealthbot-io/wealthbot