Quantcast

Object Oriented Programming in ACL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Object Oriented Programming in ACL

nettrinity
Dear friends,
The below code "extends" and "implements" at the same time from two different classes.
How could this be possible? I am confused! Where can I find materials to explain this OO concept?

Thank you!
Nicolas Xu




class Storefront_Model_Acl_Storefront extends Zend_Acl implements
SF_Acl_Interface
{
public function __construct()
{
$this->addRole(new Storefront_Model_Acl_Role_Guest)
->addRole(new Storefront_Model_Acl_Role_Customer, 'Guest')
->addRole(new Storefront_Model_Acl_Role_Admin, 'Customer');
$this->deny();
}
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Object Oriented Programming in ACL

nettrinity
Please help me take a look at this crazy class! It implements and extends 3 classes! What's really going on here? Does it just combine them all?


class Storefront_Resource_User_Item extends SF_Model_Resource_Db_Table_Row_Abstract implements
Storefront_Resource_User_Item_Interface, Zend_Acl_Role_Interface
{
   /*... */
   public function getRoleId()
   {
       if (null === $this->getRow()->role) {
       return 'Guest';
       }
       return $this->getRow()->role;
   }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Object Oriented Programming in ACL

weierophinney
Administrator
-- nettrinity <[hidden email]> wrote
(on Saturday, 12 March 2011, 02:07 PM -0800):
> Please help me take a look at this crazy class! It implements and extends 3
> classes! What's really going on here? Does it just combine them all?

You need to read up on interfaces and extension in PHP:

    http://php.net/oop

Basically, you can extend a single class, which allows you to inherit
any defined methods, variables, or constants from that class. However,
you can _implement_ as many interfaces as you want. An interface
declares one or more public methods that _must_ be defined in a concrete
implementation. If you class implements several interfaces, it must then
implement the methods defined in each of those interfaces.

In the example below, getRoleId() is declared within
Zend_Acl_Role_Interface, and thus implemented in this particular class.

> class Storefront_Resource_User_Item extends
> SF_Model_Resource_Db_Table_Row_Abstract implements
> Storefront_Resource_User_Item_Interface, Zend_Acl_Role_Interface
> {
>    /*... */
>    public function getRoleId()
>    {
>        if (null === $this->getRow()->role) {
>        return 'Guest';
>        }
>        return $this->getRow()->role;
>    }
> }

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Loading...