Zend without a database

i googled for an hour, but maybe my google-fu is too weak, I could not find a solution.

I want to create an application that requests a service through JSON requests (all data and backend / business logic are stored in the service). With simple PHP, this is quite simple, since I just make a curl request, json_decode the result and get what I need. This is already working well.

The request may look like this:

Call http://service-host/userlistwith body:

{"logintoken": "123456-1234-5678-901234"}

Get the result:

{
  "status": "Ok",
  "userlist":[
     {"name": "foo", "id": 1},
     {"name": "bar", "id": 2}
  ]
}

Now we want to get this in the Zend Framework, as this is a hobby project, and we want to learn about Zend. The problem is that all the information I could find uses the database.

Zend, ? , ?

+3
2

Zend_Json Zend_Http ( plain cURL).

, , -. , , . - getUserById - , .

class UserGateway
{
    protected $_dataSource;
    public function __construct($dataSource)
    {
        $this->_dataSource = $dataSource;
    }
    public function getUserById($id)
    {
        // interact with datasource instance to retrieve a user by ID
    }
}

$dataSource -

class UserDb extends Zend_Db_Table {}

-

class UserWebService extends Zend_Http_Client {}

, , UserGateway, .

$users = new UserGateway(new UserWebService);
$users->findById(123);

, , / .

Zend_Rest_Client

+5

Zend Framework MVC (Model-View-Controller), . , .

, Doctrine , ZF. Doctrine , . .

+1

Source: https://habr.com/ru/post/1745280/


All Articles