1. Go to this page and download the library: Download milpa/command library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
milpa / command example snippets
use Milpa\Command\CommandProvider;
use Milpa\Command\Operation;
use Milpa\Command\SurfaceProjector;
final class PostsProvider implements CommandProvider
{
public function operations(): array
{
return [
new Operation(
name: 'create_post',
description: 'Create a post',
handler: [PostsHandler::class, 'create'],
inputSchema: ['type' => 'object', 'properties' => ['title' => ['type' => 'string']]],
mutating: true,
use Milpa\Command\Declaration\{Because, Confirms, Mutates, Needs, Operation, Target};
use Milpa\Command\Effect\{Externality, Mutation, Reversibility, Subject};
#[Operation(name: 'posts:publish', description: 'Publish a post.')]
#[Mutates(Mutation::Persistent, Externality::None, Reversibility::Guaranteed, subject: Subject::Data)]
#[Needs(scopes: ['posts:write'])]
#[Confirms]
final readonly class PublishPost
{
public function __construct(
#[Target] #[Because('which post to publish')] public string $id,
public Visibility $visibility = Visibility::Public,
) {
}
public function run(Posts $posts): Receipt
{
return $posts->publish($this->id, $this->visibility);
}
}
use Milpa\Command\Declaration\DeclaredOperation;
$operation = DeclaredOperation::from(PublishPost::class, fn (string $type) => $container->get($type));
new Operation(
name: 'plugins.disable',
// …
namedTarget: 'name', // the argument whose value must appear in the request
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.