2017 © Pedro Peláez
 

library phalcon-toolbox

Phalcon Extras

image

rootwork/phalcon-toolbox

Phalcon Extras

  • Wednesday, November 1, 2017
  • by rootwork
  • Repository
  • 3 Watchers
  • 2 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

phalcon-extras

A growing collection of useful Phalcon classes, (*1)

Installation

composer require rootwork/phalcon-extras:dev-master

Authorization Component

Uses Phalcon\Acl, see acl.example.php.

<?php
cp acl.example.php app/config/acl.php

The AuthComponent uses events for your custom logic after allowing or denying a session role.

<?php
/**
 * Setup the auth component
 */
$di->setShared('auth', function () {
    /** @var \Phalcon\Config $aclConfig */
    $aclConfig  = include APP_PATH . '/config/acl.php';
    $auth       = new AuthComponent($aclConfig->toArray());

    $eventsManager = new EventsManager();

    $eventsManager->attach('auth:afterAllowed', function (Event $event, AuthComponent $auth) {
        if ($auth->persistent->role == 'Guest') {
            return true; // If the ACL allows a Guest at this route, no additional steps
        }

        // Load authorized user from the DB
        if ($user = User::findFirstById($auth->persistent->userId)) {
            $auth->di->setShared('user', $user);
            return true;
        }

        return false;
    });

    $eventsManager->attach('auth:afterDenied', function (Event $event, AuthComponent $auth) {
        // Redirect unathorized users
        $auth->response->redirect('/login');
        $auth->response->send();
        return false;
    });

    $auth->setEventsManager($eventsManager);

    return $auth;
});

/**
 * Register a dispatcher
 */
$di->setShared('dispatcher', function () use ($config, $di) {
    $eventsManager = new EventsManager();
    $eventsManager->attach('dispatch:beforeExecuteRoute', $di->get('auth'));

    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace('App\Controller');
    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
});

/**
 * Make the current user available to the app
 */
$di->setShared('user', function () {
    return null;
});

Create an authorized session

In your login code, you must set the user role. You can optionally persist other auth data., (*2)

<?php
// In a login action... 
$auth = $this->getDI()->get('auth');
$auth->setRole($user->role);

// Optional persisted auth data
$auth->persistent->userId   = $user->id;
$auth->persistent->name     = $user->name;

TODO

  • Document usage with Micro app

The Versions

01/11 2017

dev-master

9999999-dev https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.4

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

01/11 2017

dev-develop

dev-develop https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.4

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

31/10 2017

0.2.3

0.2.3.0 https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.4

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

17/06 2017

0.2.2

0.2.2.0 https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5.4

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

08/11 2016

0.2.1

0.2.1.0 https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

29/06 2016

0.2.0

0.2.0.0 https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

20/06 2016

0.1.3

0.1.3.0 https://github.com/rootworkit/phalcon-extras

Phalcon Extras

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.4

 

The Development Requires

by Mike Soule

library phalcon extras rootwork

15/06 2016

0.1.2

0.1.2.0 https://github.com/rootworkit/phalcon-toolbox

Phalcon Toolbox

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.4

 

The Development Requires

by Mike Soule

library toolbox phalcon rootwork

09/06 2016

0.1.1

0.1.1.0 https://github.com/rootworkit/phalcon-toolbox

Phalcon Toolbox

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.4

 

The Development Requires

by Mike Soule

library toolbox phalcon rootwork

27/05 2016

0.1.0

0.1.0.0 https://github.com/rootworkit/phalcon-toolbox

Phalcon Toolbox

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.4

 

The Development Requires

by Mike Soule

library toolbox phalcon rootwork