Skip to content

Instantly share code, notes, and snippets.

View dennis-fedco's full-sized avatar

Dennis Matveyev dennis-fedco

  • Fedco
  • Monroe, Michigan
View GitHub Profile
DROP SCHEMA IF EXISTS `dennis_db` ;
CREATE SCHEMA IF NOT EXISTS `dennis_db` DEFAULT CHARACTER SET utf8 ;
USE `dennis_db` ;
-- -----------------------------------------------------
-- Table `dennis_db`.`resource`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `dennis_db`.`resource` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,

I modeled my application using SQL first. I wanted to have users, roles, resources, and access. My privileges table contained {role, resource, access} entries. I then put it together with CsnAuthorization, and modeled it with MySQL Workbench:

Image: user_auth_diagram SQL with data: https://gist.github.com/dennis-fedco/7084960

Referential Integrity ensures that access (such as "cook") can only be added if there is a resource that exists (such as "Kitchen" controller), and that a privilege can only be added if a user/role and resource and access exists.

What I can call from my application is any one of these:

<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/FedcoUser for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
$additionalNamespaces = $additionalModulePaths = $moduleDependencies = null;
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
<?php
namespace FedcoUserTest;
use FedcoUser\Controller\MachinistController;
require_once 'vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php';
/**
* MachinistController test case.
*/
@dennis-fedco
dennis-fedco / MachinistController.php
Created December 12, 2013 22:24
Looking for a way to PHPUnit Test this
<?php
namespace FedcoUser\Controller;
use Zend\View\Model\ViewModel;
use ZfcUser\Controller\UserController as ZfcUserController;
/**
* MachinistController
*
* @author
<?php
namespace FedcoUserTest;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
@dennis-fedco
dennis-fedco / ClassMethodsExample.php
Created March 16, 2017 15:53
ClassMethods example with UnderscoreNamingStrategy not validating a form.
<?php
use Zend\Form\Form;
use Zend\Form\Annotation\AnnotationBuilder;
use Zend\Hydrator\ClassMethods;
use Zend\Form\Annotation;
require 'vendor/autoload.php';
/*
* How to run: php ClassMethodsExample.php
*
@dennis-fedco
dennis-fedco / nestedCollectionSetCount.php
Created March 22, 2017 16:49
How to set count to Collection that is part of another Collection?
<?php
use Zend\Form\Form;
use Zend\Form\Annotation\AnnotationBuilder;
use Zend\Form\Annotation;
use Zend\Form\Element\Collection;
require 'vendor/autoload.php';
class FormTestController
{
<?php
use Zend\Form\Form;
use Zend\Form\Annotation\AnnotationBuilder;
use Zend\Form\Annotation;
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Resolver;
use Zend\View\View;
require 'vendor/autoload.php';