Important
This repository is a read-only mirror of the utopia-php monorepo. Development happens in packages/platform — please open issues and pull requests there.
An object oriented way of writing Applications using Utopia libraries
This library contains abstract classes that assist in implementing services and actions for Utopia http framework and CLI. You must implement Platform, Service and Action classes to build your application.
Install using Composer
composer require utopia-php/platform
Implementing a HTTP services using platform.
// Action<?phpuseUtopia\Platform\Action;
class HelloWorldAction extends Action
{
publicfunction__construct()
{
$this->httpPath = '/hello';
$this->httpMethod = 'GET';
$this->inject('response');
$this->callback(fn ($response) => $this->action($response));
}
publicfunctionaction($response)
{
$response->send('Hello World!');
}
}
// serviceuseUtopia\Platform\Service;
class HelloWorldService extends Service
{
publicfunction__construct()
{
$this->type = Service::TYPE_HTTP;
$this->addAction('hello', newHelloWorldAction());
}
}
// PlatformuseUtopia\Platform\Platform;
class HelloWorldPlatform extends Platform
{
publicfunction__construct()
{
$this->addService('helloService', newHelloWorldService());
}
}
// Using platform to initialize http service$platform = newHelloWorldPlatform();
$platform->init('http');Utopia Framework requires PHP 8.3 or later. We recommend using the latest PHP version whenever possible.
All code contributions - including those of people having commit access - must go through a pull request and be approved by a core developer before being merged. This is to ensure a proper review of all the code.
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php