Triad PHP Framework is PHP framework handling (HTTP or other) requests to your application that results in response - json, php serialized, raw, template engine - smarty or custom.
This framework was done with simplicity in mind - basically it handles requests and handling exceptions. Custom classes (database or template engine) can be easily implemented in application and this framework is not trying to implement custom database or template engine class - instead, use the one you like the most!
Router can handle simple requests or MVP application at full - and you can easily create inline requests in your application (this Framework is HMVP - check HMVC as reference) - even to remote server.
- PHP 5.3 or better (for namespace support)
Request \Triad\Request consists of
method-create,read,update,deletepath(string with full path /site-path)params(dictionary array with params)
Request can be defined
$request = new \Triad\Request("/users/get");
$request->setParams(array("params" => 1));
$request->setMethod(\Triad\RequestMethod::READ);$request = \Triad\Request::factory("/users/get", array("params" => 1));or created from http request
$request = \Triad\Requests\HttpRequest::fromServerRequest();Response is dictionary with values that contain own serializing method outputBody and return method get.
Build in responses are
\Triad\Responses\HtmlResponse\Triad\Responses\JsonResponse\Triad\Responses\PhpSerializeResponse\Triad\Responses\RawResponse\Triad\Responses\RedirectResponse
To obtain final response after application execution
$response = $request->execute($application)->response;Response can be outputed with output buffer (php print) or returned
$response->send(); // output
var_dump($response->get()); // returnInternal calls in same application are called as easy as
$created = \Triad\Request::factory("/users/create", array("email" => "john@doe.com"))
->execute($this->application)
->response
->get();Calls to remote application running on remote http server are done using \Triad\RemoteApplication as
$remoteServer = \Triad\RemoteApplication::factory(array(
"url" => "http://server02",
"base_path" => "/",
"client_secret" => "" // if remote application client_secret set in config
));
$userData = \Triad\Request::factory("/users/get", array("id" => 1))
->execute($remoteServer)
->response
->get();To create a new application, implement own Application class that extends \Triad\Application
index.php
<?php
require("Triad/Load.php");
class Application extends \Triad\Application
{
public function init() {
// simple route that matches /increment-[number]
$this->router->add("#^/increment-(?P<number_to_increment>\d+)#",
array($this, "myCustomHandler"),
true // regex matching enabled
);
}
public function myCustomHandler(Application $application,
\Triad\Request $request,
$params = array()) {
$request->response["number"] = $params["number_to_increment"] + 1;
}
}
$config = \Triad\Config::factory(array("environment" => "development"));
$application = new Application($config);
// default response type
$response = new \Triad\Responses\JsonResponse();
$request = \Triad\Requests\HttpRequest::fromServerRequest($response);
$request->execute($application)->response->send();.htaccess mod rewrite settings
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
</IfModule>
Check examples of full applications that follow MVP, PHP namespaces and dependency injection design patterns. Examples
