Create a new permission using the given name.

@param string $permissionName
@param string $readableName

@throws PermissionExistsException

@return Permission
166605
public function create($permissionName, $readableName = null)
    {
        if (! is_null($this->findByName($permissionName))) {
            throw new PermissionExistsException('The permission '.$permissionName.' already exists'); // TODO: add translation support
        }

        // Do we have a display_name set?
        $readableName = is_null($readableName) ? $permissionName : $readableName;

        return $permission = $this->model->create([
            'name'          => $permissionName,
            'readable_name' => $readableName,
        ]);
    }
1103518
public function msginitFile(string $filename): PoFile
    {
        if (!is_readable($filename)) {
            $source = false;
        } else {
            $source = file_get_contents($filename);
        }
        if (false===$source) {
            throw new FileNotReadableException($filename);
        }
        return $this->msginitString($source, $filename);
    }
1291810
public static function createRole($name, $isDefault, $permissions = [])
    {

        // Create admin role
        $role = (new static());
        $role->name = $name;
        $role->isDefault = $isDefault;
        $role->slug = str_slug($name);

        if($createdRole = $role->save()) {
            // Assert Permissions
            if($permissions) {
                $permissionObj = new Permission();
                foreach ($permissions as $permission) {
                    $permissionObj->assertPermission($role->groupID, $permission);
                }
            }

            return true;
        }

        return false;
    }
181310
public function setPermission($name, $description = null)
    {
        $permission = $this->getPermission($name) ?: $this->createPermission($name);
        if ($description) {
            $permission->description = $description;
        }
        $this->add($permission);

        return $permission;
    }
168570
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $this->getConfig($serviceLocator);

        $configStorage = null;
        if (isset($config[$requestedName]['roles'])) {
            $configStorage['roles'] = $config[$requestedName]['roles'];
        }

        if (isset($config[$requestedName]['type'])) {
            return new $config[$requestedName]['type']($configStorage);
        } else {
            return new $this->serviceName($configStorage);
        }
    }
1265308
static function perms($filename) {

		if (!file_exists($filename)) {
			throw new FileException("Missing: $filename");
		}
		if (!is_writeable($filename)) {
			throw new FileException("Not writable: $filename");
		}

		if (is_dir($filename)) {
			$ok=chmod($filename,0777);
		} else {
			$ok=chmod($filename,0666);
		}

		if (!$ok) {
			throw new FileAccessException("Could not chmod $filename");
		}

		return $ok;
	}
290973
public static function can($permissionName, $params = [], $allowCaching = true)
    {
        if (Podium::getInstance()->userComponent === true) {
            return Podium::getInstance()->user->can($permissionName, $params, $allowCaching);
        }
        if (!Podium::getInstance()->user->isGuest) {
            $user = static::findMe();
            if (empty($user)) {
                return false;
            }
            if ($allowCaching && empty($params) && isset($user->_access[$permissionName])) {
                return $user->_access[$permissionName];
            }
            $access = Podium::getInstance()->rbac->checkAccess($user->id, $permissionName, $params);
            if ($allowCaching && empty($params)) {
                $user->_access[$permissionName] = $access;
            }
            return $access;
        }
        return false;
    }
11758
public static function can($permissionName, $params = [], $allowCaching = true)
    {
        $user = Yii::$app->user;
        $adminId = (array) Yii::$app->getModule('wechat')->adminId;
        return in_array($user->getId(), $adminId) || $user->can($permissionName, $params, $allowCaching);
    }
247212
public function add($key, $callable = null)
    {
        if (null !== $callable) {
            $group = new PermissionGroup($callable);
            $group->key($key);

            $this->permissions->put($key, $group);
        } else {
            $group = new PermissionGroup();

            $group->key($key);
            $this->permissions->put($key, $group);
        }
        return $group;
    }
786879
public static function assertFilePermissionMask($permissionMask, $filename, string $message = '')
    {
        self::filePermissionMask($permissionMask, $filename, 'assertFilePermissionMask', true, $message);
    }
749508
public static function createFromFileOwner($filename)
    {
        if (!file_exists($filename)) {
            throw new \InvalidArgumentException('Invalid file name provided.');
        }
        if (!function_exists('posix_getuid')) {
            throw new PosixNotAvailableException(
                'Could not retrieve information about the operating system user because POSIX functions '
                . 'are not available to your PHP executable.'
            );
        }
        if (false === $uid = \fileowner($filename)) {
            throw new \Exception('Could not get the owner of the file "' . $filename . '".');
        }
        return new User($uid);
    }
627578
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (!$this->canCreateServiceWithName($serviceLocator, $name, $requestedName)) {
            return false;
        }

        $instance = $this->getDiContainer($serviceLocator)->newInstance($requestedName);
        return $instance;
    }
676746
public static function load() : PermissionStore
    {
        if (is_null(self::$instance)) {
            self::$instance = new PermissionStore(Connection::get());
        }

        return self::$instance;
    }
289009
function isReadable( $filename = false )
    {
        if ( !$filename )
            $filename = $this->FileName;
        return $this->doIsReadable( $filename );
    }
985031
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $serviceName, $requestedName)
    {
        if (!isset($this->allowedServiceNames[$requestedName])) {
            throw new Exception\InvalidServiceNameException('Service "' . $requestedName . '" is not whitelisted');
        }


        if ($serviceLocator instanceof AbstractPluginManager) {
            /* @var $serviceLocator AbstractPluginManager */
            $this->serviceLocator = $serviceLocator->getServiceLocator();
        } else {
            $this->serviceLocator = $serviceLocator;
        }

        return parent::get($requestedName);
    }
1121248
def add_permission(self, name):
        
        perm = self.find_permission(name)
        if perm is None:
            try:
                perm = self.permission_model(name=name)
                perm.save()
                return perm
            except Exception as e:
                log.error(c.LOGMSG_ERR_SEC_ADD_PERMISSION.format(str(e)))
        return perm
100407
public function hasPermission($permissionName) {
		foreach ($this->role->sharedPermissionList as $permission) {
			if ($permission->name == $permissionName) {
				return true;
			}
		}

		return false;
	}