Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Reflectable package for reference docs #2415

Open
wants to merge 28 commits into
base: release/v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5c9cfb4
Reflectable package
distantnative Feb 16, 2025
1a9896e
Reference\Types: fix nullable types for mixed
distantnative Feb 25, 2025
4ee06fd
Types divider in lighter gray
distantnative Feb 25, 2025
6fef46d
Cache reflection objects
distantnative Feb 25, 2025
2a41a2d
Fix KirbyTag attributes in Reference
distantnative Feb 25, 2025
cd14206
Switch to `phpstan/phpdoc-parser`
distantnative Mar 1, 2025
8c95c14
Reference: fix short object names
distantnative Mar 1, 2025
f92af65
Reference: fix multiple menu entries as current
distantnative Mar 1, 2025
daf5dfd
Fix meta snippet for reference article pages
distantnative Mar 1, 2025
21e5b69
Fix option kirbytag for fields and sections
distantnative Mar 1, 2025
6b1ce75
ReflectableOptions
distantnative Mar 1, 2025
cdb201a
Fix getting return node from doc block
distantnative Mar 1, 2025
171e7f5
Initial support for type templates
distantnative Mar 1, 2025
29ef23c
Prefer docblock annotations over native type hints
distantnative Mar 1, 2025
ed946d2
Context types: derive from param types for methods
distantnative Mar 1, 2025
a9fe771
Fixes for Context resolver
distantnative Mar 1, 2025
666cc51
Replace `static`/`$this` with class name
distantnative Mar 1, 2025
4bda41e
Better code style for specific strings
distantnative Mar 1, 2025
06993f3
Clean up
distantnative Mar 1, 2025
fd541a7
Class methods: use custom class name also for call
distantnative Mar 5, 2025
986b3b6
Consider since field from content files
distantnative Mar 5, 2025
09505df
Fix field and section references
distantnative Mar 5, 2025
5444282
Fix reference block pages
distantnative Mar 5, 2025
0c3ae07
Harden reference meta logic
distantnative Mar 5, 2025
c5aa894
Use camel-casing for camel-cased class names
distantnative Mar 5, 2025
8e692ae
Returns: support for description
distantnative Mar 5, 2025
de0da4a
Fix `$request` in reference menu
distantnative Mar 5, 2025
2e78f13
Fix reference overview page
distantnative Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/css/layouts/reference.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ html {
font-size: var(--text-sm);
margin-bottom: var(--spacing-6);
}
.reference-meta:not(:has(:first-child)) {
display: none;
}
.reference-meta li {
margin-bottom: var(--spacing-2);
}
Expand Down
3 changes: 2 additions & 1 deletion assets/css/site/types.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
.type.type-boolean {
background: var(--color-purple-400);
}
.type.type-array {
.type.type-array,
.type.type-callable {
background: var(--color-aqua-400);
}
.type.type-object,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Title: $kirby

----

Name: Kirby

----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Title: $block
Name: Block

----

Class: Kirby\Cms\Block

----
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $blocks
Name: Blocks

----

Expand Down
112 changes: 56 additions & 56 deletions content/docs/2_reference/4_objects/cms/0_file/reference-class.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
Title: $file
----
Class: Kirby\Cms\File
----
Proxies:
- Kirby\Filesystem\File
- Kirby\Image\Image
----
Text:
You can extend this set of methods with (link: docs/reference/plugins/extensions/file-methods text: custom file methods).
## How to get a `$file` object
You can get a `$file` object to use with these methods by fetching it from the `$site`, a `$page` or a `$user` object.
### Site file
```php
<?php if ($file = $site->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```
### Page file
```php
<?php if ($file = $page->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```
### User file
```php
<?php if ($file = $user->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```
<info>
Note how we use an if statement here to check if we have a file object before we call the `url()` method to prevent errors in case the page doesn't have any files. Never forget to do this in your own code.
</info>
## Examples
### Resizing a file
```php
<?php if ($image = $page->image('myimage.jpg')): ?>
<img src="<?= $image->resize(300)->url() ?>" alt="">
<?php endif ?>
```
Name: File

----

Class: Kirby\Cms\File

----

Proxies:
- Kirby\Filesystem\File
- Kirby\Image\Image

----

Text:

You can extend this set of methods with (link: docs/reference/plugins/extensions/file-methods text: custom file methods).

## How to get a `$file` object

You can get a `$file` object to use with these methods by fetching it from the `$site`, a `$page` or a `$user` object.

### Site file
```php
<?php if ($file = $site->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```

### Page file
```php
<?php if ($file = $page->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```

### User file
```php
<?php if ($file = $user->files()->first()): ?>
<img src="<?= $file->url() ?>" alt="">
<?php endif ?>
```

<info>
Note how we use an if statement here to check if we have a file object before we call the `url()` method to prevent errors in case the page doesn't have any files. Never forget to do this in your own code.
</info>

## Examples

### Resizing a file

```php
<?php if ($image = $page->image('myimage.jpg')): ?>
<img src="<?= $image->resize(300)->url() ?>" alt="">
<?php endif ?>
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $files
Name: Files

----

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $language
Name: Language

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $languages
Name: Languages

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $layout
Name: Layout

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $layouts
Name: Layouts

----

Expand Down
168 changes: 84 additions & 84 deletions content/docs/2_reference/4_objects/cms/0_page/reference-class.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
Title: $page
----
Class: Kirby\Cms\Page
----
Text:
You can extend this set of methods with (link: docs/reference/plugins/extensions/page-methods text: custom page methods) or in a (link: docs/reference/plugins/extensions/page-models text: page model).
## How to fetch the `$page` object
The `$page` class is available in Kirby's templates/snippets etc. through the `$page` variable that - unless otherwise defined – always refers to the current page. However, you can also define a `$page` object by calling a specific page using the [`page()` helper](/docs/reference/templates/helpers/page):
```php
$page = page('somepage');
```
Or getting it from a collection of pages
```php
$page = $pages->first();
```
<info>
When getting a specific page via the [`page()` helper](/docs/reference/templates/helpers/page) or when trying to create a page object from field values stored in content, always verify that you have a page object before you call any of the Page methods.
</info>
## Content fields
The `$page` class offers a magic caller for your (link: docs/guide/content/fields text: content fields). Instead of getting them via e.g.
```php
$page->content()->get('your_field')
```
you can use the shorthand
```php
$page->your_field()
```
<info>
You can not use the shorthand for fields with names that conflict with the default methods of the `$page` class (see above) or used by custom page methods.
</info>
## Examples
With the `$page` object defined, you can start using the methods of the class:
### Get a field of the page
```php
<?= $page->title() ?>
```
### Get the children of the page
```php
<?php $children = $page->children() ?>
```
### Get all images of the page
```php
<?php $images = $page->images() ?>
```
### Check if the page is active
```php
<?php e($page->isActive(), 'active') ?>
```
### Check if the page has draft children
```php
if ($page->hasDrafts()) {
echo "This page still has some children that haven't been published yet";
}
```
Name: Page

----

Class: Kirby\Cms\Page

----

Text:

You can extend this set of methods with (link: docs/reference/plugins/extensions/page-methods text: custom page methods) or in a (link: docs/reference/plugins/extensions/page-models text: page model).

## How to fetch the `$page` object

The `$page` class is available in Kirby's templates/snippets etc. through the `$page` variable that - unless otherwise defined – always refers to the current page. However, you can also define a `$page` object by calling a specific page using the [`page()` helper](/docs/reference/templates/helpers/page):

```php
$page = page('somepage');
```

Or getting it from a collection of pages

```php
$page = $pages->first();
```

<info>
When getting a specific page via the [`page()` helper](/docs/reference/templates/helpers/page) or when trying to create a page object from field values stored in content, always verify that you have a page object before you call any of the Page methods.
</info>

## Content fields

The `$page` class offers a magic caller for your (link: docs/guide/content/fields text: content fields). Instead of getting them via e.g.

```php
$page->content()->get('your_field')
```

you can use the shorthand

```php
$page->your_field()
```

<info>
You can not use the shorthand for fields with names that conflict with the default methods of the `$page` class (see above) or used by custom page methods.
</info>


## Examples

With the `$page` object defined, you can start using the methods of the class:

### Get a field of the page

```php
<?= $page->title() ?>
```

### Get the children of the page

```php
<?php $children = $page->children() ?>
```

### Get all images of the page

```php
<?php $images = $page->images() ?>
```

### Check if the page is active

```php
<?php e($page->isActive(), 'active') ?>
```

### Check if the page has draft children

```php
if ($page->hasDrafts()) {
echo "This page still has some children that haven't been published yet";
}
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $pages
Name: Pages

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $pagination
Name: Pagination

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $responder
Name: Responder

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $site
Name: Site

----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: $user
Name: User

----

Expand Down
Loading