Source of file AbleObject.php

Size: 0,893 Bytes - Last Modified: 2018-05-11T23:35:49+00:00

/Users/hperrin/repos/nymph/tilmeld.org/../tilmeld-server/src/Entities/AbleObject.php

123456789101112131415161718192021222324252627282930313233343536373839
<?php namespace Tilmeld\Entities;

/**
 * AbleObject class.
 *
 * Entities which support abilities, such as users and groups.
 *
 * @license https://www.apache.org/licenses/LICENSE-2.0
 * @author Hunter Perrin <hperrin@gmail.com>
 * @copyright SciActive.com
 * @link http://tilmeld.org/
 */
class AbleObject extends \Nymph\Entity {
  /**
   * Grant an ability.
   *
   * @param string $ability The ability.
   */
  public function grant($ability) {
    if (!in_array($ability, $this->abilities)) {
      return $this->abilities = array_merge([$ability], $this->abilities);
    }
    return true;
  }

  /**
   * Revoke an ability.
   *
   * @param string $ability The ability.
   */
  public function revoke($ability) {
    if (in_array($ability, $this->abilities)) {
      return $this->abilities =
        array_values(array_diff($this->abilities, [$ability]));
    }
    return true;
  }
}