PHP code example of fivesqrd / atlas-foundation

1. Go to this page and download the library: Download fivesqrd/atlas-foundation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fivesqrd / atlas-foundation example snippets


$user = new Model\User\Entity();
$user->set('_email', '[email protected]');
$user->set('_enabled', true);

/* Save to db */
$id = $this->model(Model\User::class)->save($user);

$user = $this->model(Model\User::class)->fetch($id);

/* Fetch from db */
$user = $this->model(Model\User::class)->fetch($id);

/* Update entity */
$user->set('_lastLogin', time());

/* Save to db */
$this->model(Model\User::class)->save($user);

$users = $this->model(Model\User::class)->query()
    ->isEnabled(true)
    ->hasLoggedSince(strtotime('5 days ago'))
    ->fetch()->all();
    
foreach ($users as $user) {
    echo $user->get('_email');
}

$count = $this->model(Model\User::class)->named()
    ->withRecentLogIn()
    -fetch()->count();

/* Fetch from db */
$user = $this->model(Model\User::class)->fetch($id);

/* Update entity */
$user->setEmailAddress('[email protected]');
$user->setEnabled(true);

/* Save to db */
$this->model(Model\User::class)->save($user);

$users = $this->model(Model\User::class)->named()
    ->withRecentLogIn()
    -fetch()->all();
    
$emails = $users->getAllEmailAddresses();

|- Model
   |-- User.php
   |-- User
       |-- Entity.php
       |-- Mapper.php
       |-- Collection.php
       |-- Query.php
       |-- Named.php
       |-- Relation.php
   |-- Customer.php
   |-- Customer
       ...
   |-- Content.php
   |-- Contact
       ...


namespace Application\Model\User;

class Mapper extends \Atlas\Model\Mapper
{
    protected $_alias = 'u';

    protected $_table = 'users';

    protected $_key = 'id';

    protected $_map = array(
        '_id'        => 'id',
        '_email'     => 'email',
        '_password   => 'password',
        '_lastLogin' => 'last_login'
    );

    protected $_readOnly = array('id');
}


namespace Application\Model\User;

class Entity extends \Atlas\Model\Entity
{
    protected $_id;
    
    protected $_email;
    
    protected $_password;
    
    protected $_lastLogin;
}
 
cd /myproject
php composer.phar 

$config = array(
    'read' => array(
        'dsn'      => 'mysql:dbname=testdb;host=127.0.0.1',
        'username' => 'username',
        'password' => 'password',
    ),
    'write' => array(
        'dsn'      => 'mysql:dbname=testdb;host=127.0.0.1',
        'username' => 'username',
        'password' => 'password',
    ),
);