Initial commit

This commit is contained in:
isUnknown 2024-07-10 16:10:33 +02:00
commit 08a8a71c55
631 changed files with 139902 additions and 0 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class App extends Interceptor
{
public const CLASS_ALIAS = 'kirby';
protected $toArray = [
'site',
'url'
];
public function allowedMethods(): array
{
return [
'collection',
'defaultLanguage',
'detectedLanguage',
'draft',
'file',
'language',
'languageCode',
'languages',
'multilang',
'page',
'roles',
'site',
'translation',
'translations',
'url',
'user',
'users',
'version'
];
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Block extends Model
{
public const CLASS_ALIAS = 'block';
protected $toArray = [
'content',
'id',
'isEmpty',
'isHidden',
'type'
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForSiblings(),
[
'content',
'id',
'isEmpty',
'isHidden',
'isNotEmpty',
'toField',
'toHtml',
'parent',
'type'
]
);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Blocks extends Collection
{
public const CLASS_ALIAS = 'blocks';
public function allowedMethods(): array
{
return array_merge(
parent::allowedMethods(),
[
'excerpt',
'toHtml'
]
);
}
public function toArray(): array
{
return $this->object->toArray();
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class Blueprint extends Interceptor
{
public const CLASS_ALIAS = 'blueprint';
protected $toArray = [
'description',
'fields',
'isDefault',
'name',
'sections',
'options',
'tabs',
'title',
];
public function allowedMethods(): array
{
return [
'description',
'field',
'fields',
'isDefault',
'name',
'options',
'section',
'sections',
'tab',
'tabs',
'title',
];
}
public function fields(): array
{
return $this->object->fields();
}
public function sections(): array
{
return array_keys($this->object->sections());
}
public function tab(string $name): ?array
{
if ($tab = $this->object->tab($name)) {
foreach ($tab['columns'] as $columnIndex => $column) {
$tab['columns'][$columnIndex]['sections'] = array_keys($column['sections']);
}
return $tab;
}
return null;
}
public function tabs(): array
{
$tabs = [];
foreach ($this->object->tabs() as $tab) {
$tabs[$tab['name']] = $this->tab($tab['name']);
}
return $tabs;
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class Collection extends Interceptor
{
public const CLASS_ALIAS = 'collection';
public function allowedMethods(): array
{
return [
'chunk',
'count',
'filterBy',
'find',
'findBy',
'findByKey',
'first',
'flip',
'groupBy',
'has',
'isEmpty',
'isEven',
'isNotEmpty',
'isOdd',
'keys',
'last',
'limit',
'next',
'not',
'nth',
'offset',
'pagination',
'pluck',
'prev',
'shuffle',
'slice',
'sortBy',
'without',
];
}
public function toArray(): array
{
return $this->object->keys();
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class File extends Model
{
public const CLASS_ALIAS = 'file';
protected $toArray = [
'extension',
'filename',
'height',
'id',
'mime',
'niceSize',
'template',
'type',
'url',
'width'
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForModels(),
$this->allowedMethodsForParents(),
$this->allowedMethodsForSiblings(),
[
'blur',
'bw',
'crop',
'dataUri',
'dimensions',
'exif',
'extension',
'filename',
'files',
'grayscale',
'greyscale',
'height',
'html',
'isPortrait',
'isLandscape',
'isSquare',
'mime',
'name',
'niceSize',
'orientation',
'ratio',
'resize',
'size',
'srcset',
'template',
'templateSiblings',
'thumb',
'type',
'width'
]
);
}
public function dimensions(): array
{
return $this->object->dimensions()->toArray();
}
public function exif(): array
{
return $this->object->exif()->toArray();
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class FileVersion extends File
{
public const CLASS_ALIAS = 'file';
}

View file

@ -0,0 +1,18 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Files extends Collection
{
public const CLASS_ALIAS = 'files';
public function allowedMethods(): array
{
return array_merge(
parent::allowedMethods(),
[
'template'
]
);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Layout extends Model
{
public const CLASS_ALIAS = 'layout';
protected $toArray = [
'attrs',
'columns',
'id',
'isEmpty',
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForSiblings(),
[
'attrs',
'columns',
'id',
'isEmpty',
'isNotEmpty',
'parent'
]
);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class LayoutColumn extends Model
{
public const CLASS_ALIAS = 'layoutColumn';
protected $toArray = [
'blocks',
'id',
'isEmpty',
'width',
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForSiblings(),
[
'blocks',
'id',
'isEmpty',
'isNotEmpty',
'span',
'width'
]
);
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class LayoutColumns extends Collection
{
public const CLASS_ALIAS = 'layoutColumns';
public function toArray(): array
{
return $this->object->toArray();
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Layouts extends Collection
{
public const CLASS_ALIAS = 'layouts';
public function toArray(): array
{
return $this->object->toArray();
}
}

View file

@ -0,0 +1,113 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class Model extends Interceptor
{
public const CLASS_ALIAS = 'model';
public function __call($method, array $args = [])
{
if ($this->isAllowedMethod($method) === true) {
return $this->object->$method(...$args);
}
if (method_exists($this->object, $method) === false) {
return $this->object->content()->get($method);
}
$this->forbiddenMethod($method);
}
protected function allowedMethodsForChildren()
{
return [
'children',
'childrenAndDrafts',
'draft',
'drafts',
'find',
'findPageOrDraft',
'grandChildren',
'hasChildren',
'hasDrafts',
'hasListedChildren',
'hasUnlistedChildren',
'index',
'search',
];
}
protected function allowedMethodsForFiles()
{
return [
'audio',
'code',
'documents',
'file',
'files',
'hasAudio',
'hasCode',
'hasDocuments',
'hasFiles',
'hasImages',
'hasVideos',
'image',
'images',
'videos'
];
}
protected function allowedMethodsForModels()
{
return [
'apiUrl',
'blueprint',
'content',
'dragText',
'exists',
'id',
'mediaUrl',
'modified',
'permissions',
'panel',
'permalink',
'previewUrl',
'url',
];
}
protected function allowedMethodsForSiblings()
{
return [
'indexOf',
'next',
'nextAll',
'prev',
'prevAll',
'siblings',
'hasNext',
'hasPrev',
'isFirst',
'isLast',
'isNth'
];
}
protected function allowedMethodsForParents()
{
return [
'parent',
'parentId',
'parentModel',
'site',
];
}
public function uuid(): string
{
return $this->object->uuid()->toString();
}
}

View file

@ -0,0 +1,68 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Page extends Model
{
public const CLASS_ALIAS = 'page';
protected $toArray = [
'children',
'content',
'drafts',
'files',
'id',
'intendedTemplate',
'isHomePage',
'isErrorPage',
'num',
'template',
'title',
'slug',
'status',
'uid',
'url'
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForChildren(),
$this->allowedMethodsForFiles(),
$this->allowedMethodsForModels(),
$this->allowedMethodsForParents(),
$this->allowedMethodsForSiblings(),
[
'blueprints',
'depth',
'hasTemplate',
'intendedTemplate',
'isDraft',
'isErrorPage',
'isHomePage',
'isHomeOrErrorPage',
'isListed',
'isReadable',
'isSortable',
'isUnlisted',
'num',
'slug',
'status',
'template',
'title',
'uid',
'uri',
]
);
}
public function intendedTemplate(): string
{
return $this->object->intendedTemplate()->name();
}
public function template(): string
{
return $this->object->template()->name();
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Pages extends Collection
{
public const CLASS_ALIAS = 'pages';
public function allowedMethods(): array
{
return array_merge(
parent::allowedMethods(),
[
'audio',
'children',
'code',
'documents',
'drafts',
'files',
'findByUri',
'images',
'index',
'listed',
'notTemplate',
'nums',
'published',
'search',
'template',
'unlisted',
'videos',
]
);
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class Role extends Interceptor
{
public const CLASS_ALIAS = 'role';
protected $toArray = [
'description',
'id',
'name',
'title',
];
public function allowedMethods(): array
{
return [
'description',
'id',
'name',
'permissions',
'title'
];
}
public function permissions(): array
{
return $this->object->permissions()->toArray();
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Site extends Model
{
public const CLASS_ALIAS = 'site';
protected $toArray = [
'children',
'drafts',
'files',
'title',
'url',
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForChildren(),
$this->allowedMethodsForFiles(),
$this->allowedMethodsForModels(),
[
'blueprints',
'breadcrumb',
'errorPage',
'errorPageId',
'homePage',
'homePageId',
'page',
'pages',
'title',
]
);
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Structure extends Collection
{
public const CLASS_ALIAS = 'structure';
public function toArray(): array
{
return $this->object->toArray();
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class StructureObject extends Model
{
public const CLASS_ALIAS = 'structureItem';
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForSiblings(),
[
'content',
'id',
'parent',
]
);
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
use Kirby\Kql\Interceptor;
class Translation extends Interceptor
{
public const CLASS_ALIAS = 'translation';
protected $toArray = [
'code',
'data',
'direction',
'id',
'name',
'locale',
'author'
];
public function allowedMethods(): array
{
return [
'code',
'data',
'dataWithFallback',
'direction',
'get',
'id',
'name',
'locale',
'author'
];
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class User extends Model
{
public const CLASS_ALIAS = 'user';
protected $toArray = [
'id',
'name',
'role',
'username'
];
public function allowedMethods(): array
{
return array_merge(
$this->allowedMethodsForFiles(),
$this->allowedMethodsForModels(),
$this->allowedMethodsForSiblings(),
[
'avatar',
'email',
'id',
'isAdmin',
'language',
'modified',
'name',
'role',
'username',
]
);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Kirby\Kql\Interceptors\Cms;
class Users extends Collection
{
public const CLASS_ALIAS = 'users';
public function allowedMethods(): array
{
return array_merge(
parent::allowedMethods(),
[
'role'
]
);
}
}