Initial commit
This commit is contained in:
commit
efa5624dab
687 changed files with 162710 additions and 0 deletions
54
kirby/src/Cms/SiteRules.php
Normal file
54
kirby/src/Cms/SiteRules.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\PermissionException;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* Validators for all site actions
|
||||
*
|
||||
* @package Kirby Cms
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
class SiteRules
|
||||
{
|
||||
/**
|
||||
* Validates if the site title can be changed
|
||||
*
|
||||
* @throws \Kirby\Exception\InvalidArgumentException If the title is empty
|
||||
* @throws \Kirby\Exception\PermissionException If the user is not allowed to change the title
|
||||
*/
|
||||
public static function changeTitle(Site $site, string $title): void
|
||||
{
|
||||
if ($site->permissions()->can('changeTitle') !== true) {
|
||||
throw new PermissionException(
|
||||
key: 'site.changeTitle.permission'
|
||||
);
|
||||
}
|
||||
|
||||
if (Str::length($title) === 0) {
|
||||
throw new InvalidArgumentException(
|
||||
key: 'site.changeTitle.empty'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if the site can be updated
|
||||
*
|
||||
* @throws \Kirby\Exception\PermissionException If the user is not allowed to update the site
|
||||
*/
|
||||
public static function update(Site $site, array $content = []): void
|
||||
{
|
||||
if ($site->permissions()->can('update') !== true) {
|
||||
throw new PermissionException(
|
||||
key: 'site.update.permission'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue