Wallogit.com
2017 © Pedro Peláez
Simple PHP Oject Framework
This micro-framework was first created to help people learning Object Oriented Programming through a framework., (*1)
It's quite simple to get started and quite alike with a well known micro-framework : Silex (based on Symfony components)., (*2)
The aim is not to provide a production ready framework that you should use in your enterprise project but mostly to try things and to bootstrap a small structured project very quickly., (*3)
The recommended way to install Sophwork is through Composer:, (*4)
$ composer require sophwork/sophwork "0.1.1", (*5)
As you can also download it from : here, (*6)
You first need to configure your server to use Sophwork. You can take exemple on the .htaccess file in the sources folder. (Make sure Apache2 mod_rewrite is enabled: here is a quick tutorial)., (*7)
#Default htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
<?php use Sophwork\app\app\SophworkApp; use Sophwork\modules\handlers\requests\Requests; // If you're not using composer, you must define your sources path $autoloader->sources = __DIR__ . '/../src/'; /* * Create a new applicaion with the Sophwork class * It will create 3 new class : * - appController class * - appModel class * - appView class * * Set up app parameters here or in the config file */ $app = new SophworkApp();
Then you need to define your routes, (*8)
<?php
/**
* Simply declare your routes and the pattern to match
* and link them to the controller
*
* You can match the following http requests
* - get
* - post
* You can also attribute them a name so you can use UrlGenerator to create links
*/
$app->get('/', function(SophworkApp $app, Requests $request) {
return "
Hello World !
";
});
As you can see you can declare controller directly through your router, but I mostly recommend to do it in a proper controller file :, (*9)
<?php
// src/MyApp/Controller/Home.php
namespace MyApp\Controller;
use Sophwork\app\app\SophworkApp;
use Sophwork\modules\handlers\requests\Requests;
class Home
{
public function show(SophworkApp $app, Requests $requests) {
return 'Hello World';
}
}
And then call the right method in the controller you've just define :, (*10)
<?php
// index.php
//...
// Separate controller file (recommended)
$app->get('/', ['MyApp\Controller\Home' => 'show'], 'home');
Now you have configured your app, it's about time to actually run it (It will not run any of your controllers, unless you call this method), (*11)
// Run the actual app $app->run();
Sophwork isn't tested yet. (As I said it's not production ready yet)., (*12)
Sophwork is licensed under the MIT license., (*13)