Repository navigation
Expand file tree
/
Copy pathsignature_help.php
More file actions
75 lines (62 loc) · 2.94 KB
/
Copy pathsignature_help.php
File metadata and controls
75 lines (62 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* PHP Showcase — Signature Help
*
* The parameter hints shown while typing a call's arguments, for functions,
* methods, and attribute constructors.
*
* One of the demo files listed in README.md. Supporting fixtures live in
* scaffolding/scaffolding.php (namespace Demo\Scaffolding), and the runtime
* assertions that verify the type claims in the comments below live in
* scaffolding/assertions.php.
*/
namespace Demo;
use Attribute;
use Demo\Scaffolding;
// ── Signature Help ──────────────────────────────────────────────────────────
class SignatureHelpDemo
{
public function demo(): void
{
// Place cursor inside parentheses to see parameter hints.
// The active parameter updates as you type commas.
$user = new Scaffolding\User('Alice', 'alice@example.com');
Scaffolding\createUser('Alice', 'alice@example.com'); // standalone function
$user->setStatus(Scaffolding\Status::Active); // instance method
Scaffolding\User::findByEmail('alice@example.com'); // static method
new Scaffolding\User('Bob', 'bob@example.com'); // constructor
// Chains resolve through return types and properties:
$user->getProfile()->setBio('Hello'); // method return chain
(new Scaffolding\User('X', 'x@x.com'))->setStatus(Scaffolding\Status::Active); // (new ...)->method
new Scaffolding\User('X', 'x@x.com')->setStatus(Scaffolding\Status::Active); // PHP 8.4 style
// Default values appear in parameter labels (e.g. "int $page = 1"):
$svc = new Scaffolding\ScaffoldingSignatureHelp();
$svc->paginate(2, 50);
// Per-parameter @param descriptions appear next to each parameter.
// When the effective docblock type differs from the native PHP type
// the description is prefixed with the effective type:
$svc->search('php', 1, 25);
}
public function invokable(Scaffolding\ScaffoldingGreetAction $greet): void
{
// Invoking an object shows the parameters of its __invoke() method:
$greet('Alice', true); // injected instance
(new Scaffolding\ScaffoldingGreetAction())('Bob'); // (new ...)()
}
}
// ── Attribute Signature Help ────────────────────────────────────────────────
#[Attribute]
class DemoRoute
{
public function __construct(
public string $path,
public string $method = 'GET',
) {}
}
class AttributeSigHelpDemo
{
// Try: place cursor inside the attribute parens and trigger signature help.
// Named parameter completion also works: type "method:" after the first arg.
#[DemoRoute('/users', method: 'POST')]
public function store(): void {}
}