PHP code example of utopia-php / platform
1. Go to this page and download the library: Download utopia-php/platform 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/ */
utopia-php / platform example snippets
// Action
use Utopia\Platform\Action;
class HelloWorldAction extends Action
{
public function __construct()
{
$this->httpPath = '/hello';
$this->httpMethod = 'GET';
$this->inject('response');
$this->callback(fn ($response) => $this->action($response));
}
public function action($response)
{
$response->send('Hello World!');
}
}
// service
use Utopia\Platform\Service;
class HelloWorldService extends Service
{
public function __construct()
{
$this->type = Service::TYPE_HTTP;
$this->addAction('hello', new HelloWorldAction());
}
}
// Platform
use Utopia\Platform\Platform;
class HelloWorldPlatform extends Platform
{
public function __construct()
{
$this->addService('helloService', new HelloWorldService());
}
}
// Using platform to initialize http service
$platform = new HelloWorldPlatform();
$platform->init('http');
composer