PHP code example of spoova / ghost
1. Go to this page and download the library: Download spoova/ghost 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/ */
spoova / ghost example snippets
Ghost\GhostFunction;
$ghost = new GhostFunction(['greet', ['name' => 'Ghost']]);
$ghost->greet(fn(string $who = 'world') => 'Hello ' . $who);
echo $ghost->greet('Ada'); // Hello Ada
echo PHP_EOL;
echo $ghost->name; // Ghost
$ghost->ghosts(GhostFunction::methods); // list registered methods
$ghost->ghosts(GhostFunction::properties); // list registered properties
Ghost\GhostDraft;
use Ghost\GhostFunction;
use Ghost\GhostProxy;
$ghost = new GhostFunction(['greet']);
$ghost->greet(fn(string $who = 'world') => 'Hello ' . $who);
GhostProxy::new($ghost, function (GhostDraft $draft) {
return new class($draft) {
public function __construct(protected GhostDraft $get) {}
public function hello(string $name = 'world'): string {
return $this->get->ghost()->greet($name);
}
};
});
$object = GhostProxy::object();
echo $object->hello('Ada');
abstract class GhostDraft {
abstract public function id(): int;
abstract public function ghost(): GhostFunction;
}
Ghost\GhostClass;
use Ghost\GhostDraft;
use Ghost\GhostFunction;
use Ghost\GhostProxy;
class GreetingService extends GhostClass
{
protected function ghostInit(): void
{
echo $this->proxy->greet('Bob');
}
}
$ghost = new GhostFunction(['greet']);
$ghost->greet(fn(string $who = 'world') => 'Hello ' . $who);
GhostProxy::new($ghost, fn(GhostDraft $draft) => new GreetingService($draft));
$service = GhostProxy::object();