Skip to content
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

[NFR] Abstraction layer for ODM #507

Closed
tugrul opened this issue Mar 28, 2013 · 2 comments
Closed

[NFR] Abstraction layer for ODM #507

tugrul opened this issue Mar 28, 2013 · 2 comments
Labels
discussion Request for comments and discussion

Comments

@tugrul
Copy link
Contributor

tugrul commented Mar 28, 2013

I know it's very hard to implement following features to actual code base. Because there is a actual architecture.

I just wanted to share my idea.

Phalcon has got excellent model base for ORM and ODM.

ORM and ODM use same interfaces and same active record structure. This is excellent feature because data logic can transform without to change business logic.

Okay i'm starting to share my idea.

I needed to provider to bind Array collection to model. I don't want to use mongo because records are very few and will not change like following.

Part of the data which I use. I stored this data to /app/config/iban.json

[
    {
        "code": 10,
        "title": "Ziraat Bankası",
        "iban": {
            "format": "%05d0%04d%08d%04d",
            "fields": ["bank-code", "branch-code", "customer-number", "customer-suffix"]
        },
        "fields": [
            {"title": "Şube", "name": "branch-code"},
            {"title": "Müşteri No", "name": "customer-number"},
            {"title": "Ek No", "name": "customer-suffix"}
        ]
    },
    {
        "code": 12,
        "title": "Halkbank",
        "iban": {
            "format": "%05d00%94d0%011d",
            "fields": ["bank-code", "branch-code", "account-number"]
        },
        "fields": [
            {"title": "Şube", "name":"branch-code"},
            {"title": "Hesap No", "name": "account-number"}
        ]
    }
]

Following lines are use case which in my mind.

index.php
Maybe can be mark key field, multiple sources and relation among sources. Source can be populate to DBMS after-development easily if required.

$di->set('odb', function() use ($config) {
    $adapter = new \Phalcon\Db\Adapter\Memory();

    $adapter->setSource('iban_records', json_decode(file_get_contents(APP_DIR . '/config/iban.json')));

    return $adapter;
}, true);

/app/models/Iban.php

class Iban extends \Phalcon\Mvc\Collection
{
    public function getSource()
    {
        return 'iban_records';
    }

    public function calculate($params)
    {
        $params['bank-code'] = $this->code;
        $sortedParams = array_merge(array_flip($this->iban->fields), $params);
        return sprintf($this->iban->format, $sortedParams);
    }
}

/app/controllers/IbanController.php

class IbanController extends ControllerBase
{
    public function calculateAction($bankId)
    {
        $iban = Iban::findFirst(array(
            'code' => $bankId
        ));

        $this->view->setVar('fields', $iban->fields);

        if ($this->request->isPost()) {
            $result = $iban->calculate($this->request->getPosts());
            $this->view->setVar('result', $result);
        }   
    }
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@tugrul
Copy link
Contributor Author

tugrul commented Mar 28, 2013

This feature also be able to abstract model of API result like Facebook Graph API. Data source can be change depended to application environment, can be helpful writing test to models which have got API calls.

@sergeyklay sergeyklay added Mongo discussion Request for comments and discussion labels Jul 17, 2017
@sergeyklay sergeyklay added this to the 4.0.0 milestone Jul 17, 2017
@stale stale bot added the stale Stale issue - automatically closed label Apr 16, 2018
@sergeyklay sergeyklay reopened this May 2, 2018
@stale stale bot removed the stale Stale issue - automatically closed label May 2, 2018
@phalcon phalcon deleted a comment from stale bot Feb 23, 2019
@niden
Copy link
Member

niden commented Feb 23, 2019

Closing in favor of #13855. Will revisit if the community votes for it, or in later versions.

@niden niden closed this as completed Feb 23, 2019
@niden niden removed this from the 4.0.0 milestone Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Request for comments and discussion
Projects
None yet
Development

No branches or pull requests

3 participants