Adds IPermissionObject
authorMatthias Schmidt <gravatronics@live.com>
Tue, 1 Jan 2013 08:15:56 +0000 (09:15 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 1 Jan 2013 08:15:56 +0000 (09:15 +0100)
wcfsetup/install/files/lib/data/IPermissionObject.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/category/ViewableCategory.class.php

diff --git a/wcfsetup/install/files/lib/data/IPermissionObject.class.php b/wcfsetup/install/files/lib/data/IPermissionObject.class.php
new file mode 100644 (file)
index 0000000..934cb06
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+namespace wcf\data;
+
+/**
+ * Every object with permissions has to implement this interface.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.acl
+ * @subpackage data
+ * @category   Community Framework
+ */
+interface IPermissionObject {
+       /**
+        * Checks if the active user has the given permissions for this object and
+        * throws a PermissionDeniedException if they don't have one of the permissions.
+        * 
+        * @param       array<string>           $permissions
+        */
+       public function checkPermissions(array $permissions);
+       
+       /**
+        * Returns the permission value of the given permission for this object
+        * and the active user.
+        * 
+        * @param       string                  $permission
+        * @return      mixed
+        */
+       public function getPermission($permission);
+}
\ No newline at end of file
index 691faa9e4cc8a110c6e22a262391266f9924a0ee..27a1feaa56e0310fdb37af8abdfc57af35466371 100644 (file)
@@ -1,12 +1,13 @@
 <?php
 namespace wcf\data\category;
 use wcf\data\DatabaseObjectDecorator;
+use wcf\data\IPermissionObject;
 use wcf\system\category\CategoryPermissionHandler;
 use wcf\system\exception\PermissionDeniedException;
 
 /**
  * Represents a viewable category.
- *
+ * 
  * @author     Matthias Schmidt
  * @copyright  2001-2012 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
@@ -14,7 +15,7 @@ use wcf\system\exception\PermissionDeniedException;
  * @subpackage data.category
  * @category   Community Framework
  */
-class ViewableCategory extends DatabaseObjectDecorator {
+class ViewableCategory extends DatabaseObjectDecorator implements IPermissionObject {
        /**
         * list of all parent category generations of this category
         * @var array<wcf\data\category\ViewableCategory>
@@ -39,10 +40,7 @@ class ViewableCategory extends DatabaseObjectDecorator {
        protected $permissions = null;
        
        /**
-        * Checks if the active user has all given permissions and throws a 
-        * PermissionDeniedException if that isn't the case.
-        * 
-        * @param       array<string>           $permissions
+        * @see wcf\data\IPermissionObject::checkPermissions()
         */
        public function checkPermissions(array $permissions) {
                foreach ($permissions as $permission) {
@@ -82,11 +80,7 @@ class ViewableCategory extends DatabaseObjectDecorator {
        }
        
        /**
-        * Returns the acl permission value of the given permission for the active
-        * user and of this category.
-        * 
-        * @param       string          $permission
-        * @return      boolean
+        * @see wcf\data\IPermissionObject::getPermission()
         */
        public function getPermission($permission) {
                if ($this->permissions === null) {