%PDF- %PDF-
Direktori : /var/www/html/bbw/farmaci/kritik-portale/vendor/zf-commons/zfc-rbac/data/ |
Current File : //var/www/html/bbw/farmaci/kritik-portale/vendor/zf-commons/zfc-rbac/data/HierarchicalRole.php.dist |
<?php /* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Rbac\Role\HierarchicalRoleInterface; use ZfcRbac\Permission\PermissionInterface; /** * @ORM\Entity * @ORM\Table(name="roles") */ class HierarchicalRole implements HierarchicalRoleInterface { /** * @var int|null * * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var string|null * * @ORM\Column(type="string", length=48, unique=true) */ protected $name; /** * @var HierarchicalRoleInterface[]|\Doctrine\Common\Collections\Collection * * @ORM\ManyToMany(targetEntity="HierarchicalRole") */ protected $children = []; /** * @var PermissionInterface[]|\Doctrine\Common\Collections\Collection * * @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER") */ protected $permissions; /** * Init the Doctrine collection */ public function __construct() { $this->children = new ArrayCollection(); $this->permissions = new ArrayCollection(); } /** * Get the role identifier * * @return int */ public function getId() { return $this->id; } /** * Set the role name * * @param string $name * @return void */ public function setName($name) { $this->name = (string) $name; } /** * Get the role name * * @return string */ public function getName() { return $this->name; } /** * {@inheritDoc} */ public function addChild(HierarchicalRoleInterface $child) { $this->children[] = $child; } /** * {@inheritDoc} */ public function addPermission($permission) { if (is_string($permission)) { $permission = new Permission($permission); } $this->permissions[(string) $permission] = $permission; } /** * {@inheritDoc} */ public function hasPermission($permission) { // This can be a performance problem if your role has a lot of permissions. Please refer // to the cookbook to an elegant way to solve this issue return isset($this->permissions[(string) $permission]); } /** * {@inheritDoc} */ public function getChildren() { return $this->children; } /** * {@inheritDoc} */ public function hasChildren() { return !$this->children->isEmpty(); } }