Skip to content

Commit bef5af7

Browse files
innocenzibrendt
andauthored
feat: add inline documentation on all namespaced functions (#616)
Co-authored-by: Brent Roose <[email protected]>
1 parent 80d3464 commit bef5af7

File tree

10 files changed

+101
-2
lines changed

10 files changed

+101
-2
lines changed

src/Tempest/CommandBus/src/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Tempest\CommandBus\CommandBus;
88

9+
/**
10+
* Dispatches the given `$command` to the {@see CommandBus}, triggering all associated command handlers.
11+
*/
912
function command(object $command): void
1013
{
1114
$commandBus = get(CommandBus::class);

src/Tempest/Container/src/functions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Tempest\Reflection\MethodReflector;
1010

1111
/**
12+
* Retrieves an instance of the specified `$className` from the container.
13+
*
1214
* @template TClassName of object
1315
* @param class-string<TClassName> $className
1416
* @return TClassName
@@ -20,6 +22,19 @@ function get(string $className, ?string $tag = null, mixed ...$params): object
2022
return $container->get($className, $tag, ...$params);
2123
}
2224

25+
/**
26+
* Invokes the given method, function, callable or invokable class from the container. If no named parameters are specified, they will be resolved from the container.
27+
*
28+
* #### Examples
29+
* ```php
30+
* \Tempest\invoke(function (MyService $service) {
31+
* $service->execute();
32+
* });
33+
* ```
34+
* ```php
35+
* \Tempest\invoke(MyService::class, key: $apiKey);
36+
* ```
37+
*/
2338
function invoke(MethodReflector|FunctionReflector|callable|string $callable, mixed ...$params): mixed
2439
{
2540
$container = GenericContainer::instance();

src/Tempest/Core/src/functions.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Tempest\Core\Kernel;
1111
use function Tempest\Support\str;
1212

13+
/**
14+
* Creates and sanitizes a file system path from the given `$parts`. The resulting path is not checked against the file system.
15+
*/
1316
function path(string ...$parts): string
1417
{
1518
$path = implode('/', $parts);
@@ -21,18 +24,27 @@ function path(string ...$parts): string
2124
);
2225
}
2326

27+
/**
28+
* Creates a path scoped within the root of the project
29+
*/
2430
function root_path(string ...$parts): string
2531
{
2632
return path(realpath(get(Kernel::class)->root), ...$parts);
2733
}
2834

35+
/**
36+
* Creates a path scoped within the src folder of the project
37+
*/
2938
function src_path(string ...$parts): string
3039
{
3140
$composer = get(Composer::class);
3241

3342
return path($composer->mainNamespace->path, ...$parts);
3443
}
3544

45+
/**
46+
* Creates a namespace scoped within the main namespace of the project
47+
*/
3648
function src_namespace(?string $append = null): string
3749
{
3850
$composer = get(Composer::class);
@@ -44,6 +56,9 @@ function src_namespace(?string $append = null): string
4456
->toString();
4557
}
4658

59+
/**
60+
* Retrieves the given `$key` from the environment variables. If `$key` is not defined, `$default` is returned instead.
61+
*/
4762
function env(string $key, mixed $default = null): mixed
4863
{
4964
$value = getenv($key);
@@ -60,6 +75,9 @@ function env(string $key, mixed $default = null): mixed
6075
};
6176
}
6277

78+
/**
79+
* Defer a task, will be run after a request has been sent or a command has executed
80+
*/
6381
function defer(Closure $closure): void
6482
{
6583
get(DeferredTasks::class)->add($closure);

src/Tempest/Debug/src/functions.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
use Tempest\Debug\Debug;
88

99
if (! function_exists('lw')) {
10+
/**
11+
* Writes the given `$input` to the logs, and dumps it.
12+
* @see \Tempest\Debug\Debug::log()
13+
*/
1014
function lw(mixed ...$input): void
1115
{
1216
Debug::resolve()->log($input);
1317
}
1418
}
1519

1620
if (! function_exists('ld')) {
21+
/**
22+
* Writes the given `$input` to the logs, dumps it, and stops the execution of the script.
23+
* @see \Tempest\Debug\Debug::log()
24+
*/
1725
function ld(mixed ...$input): void
1826
{
1927
Debug::resolve()->log($input);
@@ -22,22 +30,34 @@ function ld(mixed ...$input): void
2230
}
2331

2432
if (! function_exists('ll')) {
33+
/**
34+
* Writes the given `$input` to the logs.
35+
* @see \Tempest\Debug\Debug::log()
36+
*/
2537
function ll(mixed ...$input): void
2638
{
2739
Debug::resolve()->log($input, writeToOut: false);
2840
}
2941
}
3042

31-
// Alias dd to ld
3243
if (! function_exists('dd')) {
44+
/**
45+
* Writes the given `$input` to the logs, dumps it, and stops the execution of the script.
46+
* @see ld()
47+
* @see \Tempest\Debug\Debug::log()
48+
*/
3349
function dd(mixed ...$input): void
3450
{
3551
ld(...$input);
3652
}
3753
}
3854

39-
// Alias dump to lw
4055
if (! function_exists('dump')) {
56+
/**
57+
* Writes the given `$input` to the logs, and dumps it.
58+
* @see lw()
59+
* @see \Tempest\Debug\Debug::log()
60+
*/
4161
function dump(mixed ...$input): void
4262
{
4363
lw(...$input);

src/Tempest/EventBus/src/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
use Tempest\EventBus\EventBus;
99
use Tempest\EventBus\EventBusConfig;
1010

11+
/**
12+
* Dispatches the given `$event`, triggering all associated event listeners.
13+
*/
1114
function event(string|object $event): void
1215
{
1316
$eventBus = get(EventBus::class);
1417

1518
$eventBus->dispatch($event);
1619
}
1720

21+
/**
22+
* Registers a closure-based event listener for the given `$event`.
23+
*/
1824
function listen(string|object $event, Closure $handler): void
1925
{
2026
$config = get(EventBusConfig::class);

src/Tempest/Http/src/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Tempest\Http\Router;
88
use Tempest\Reflection\MethodReflector;
99

10+
/**
11+
* Creates a valid URI to the given controller `$action`.
12+
*/
1013
function uri(array|string|MethodReflector $action, ...$params): string
1114
{
1215
if ($action instanceof MethodReflector) {

src/Tempest/Mapper/src/functions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
declare(strict_types=1);
44

55
namespace Tempest {
6+
67
use Tempest\Mapper\ObjectFactory;
78

89
/**
10+
* Creates a factory which allows instanciating `$objectOrClass` with the data specified by the {@see \Tempest\Mapper\ObjectFactory::from()} method.
11+
*
12+
* ### Example
13+
* ```php
14+
* make(Author::class)->from([
15+
* 'first_name' => 'Jon',
16+
* 'last_name' => 'Doe',
17+
* ])
18+
* ```
19+
*
920
* @template T of object
1021
* @param T|class-string<T> $objectOrClass
1122
* @return ObjectFactory<T>
@@ -17,6 +28,17 @@ function make(object|string $objectOrClass): ObjectFactory
1728
return $factory->forClass($objectOrClass);
1829
}
1930

31+
/**
32+
* Creates a factory which allows instanciating the object or class specified by {@see \Tempest\Mapper\ObjectFactory::to()} the given `$data`.
33+
*
34+
* ### Example
35+
* ```php
36+
* map([
37+
* 'first_name' => 'Jon',
38+
* 'last_name' => 'Doe',
39+
* ])->to($author);
40+
* ```
41+
*/
2042
function map(mixed $data): ObjectFactory
2143
{
2244
$factory = get(ObjectFactory::class);

src/Tempest/Reflection/src/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Tempest\Reflection\ClassReflector;
1010
use Tempest\Reflection\PropertyReflector;
1111

12+
/**
13+
* Creates a new {@see Reflector} instance based on the given `$classOrProperty`.
14+
*/
1215
function reflect(mixed $classOrProperty, ?string $propertyName = null): ClassReflector|PropertyReflector
1316
{
1417
if ($classOrProperty instanceof PHPReflectionClass) {

src/Tempest/Support/src/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
declare(strict_types=1);
44

55
namespace Tempest\Support {
6+
/**
7+
* Creates an instance of {@see StringHelper} using the given `$string`.
8+
*/
69
function str(string $string = ''): StringHelper
710
{
811
return new StringHelper($string);
912
}
1013

14+
/**
15+
* Creates an instance of {@see ArrayHelper} using the given `$input`. If `$input` is not an array, it will be wrapped in one.
16+
*/
1117
function arr(mixed $input = []): ArrayHelper
1218
{
1319
return new ArrayHelper($input);

src/Tempest/View/src/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Tempest\View\GenericView;
99
use Tempest\View\View;
1010

11+
/**
12+
* Returns a {@see View} instance for the specified `$path`.
13+
*/
1114
function view(string $path, mixed ...$params): View
1215
{
1316
return (new GenericView($path))->data(...$params);

0 commit comments

Comments
 (0)