1. Go to this page and download the library: Download phastasf/framework 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/ */
phastasf / framework example snippets
e('BASE_PATH', __DIR__.'/..');
$framework = new Phast\Framework;
$framework->getWebEntrypoint()->handle();
#!/usr/bin/env php
IR__);
$framework = new Phast\Framework;
exit($framework->getConsoleEntrypoint()->run());
// config/middleware.php
return [
// Core framework middleware (dleware\SessionMiddleware::class,
// CORS middleware (should be early in pipeline to handle preflight requests)
\Phast\Middleware\CorsMiddleware::class,
// Client IP detection middleware (must be before routing if behind proxy)
// \Phast\Middleware\ClientIpMiddleware::class,
// Add AuthMiddleware here if you want authentication
// \Phast\Middleware\AuthMiddleware::class,
// Add your custom middleware here (before routing)
\App\Middleware\CustomMiddleware::class,
\Phast\Middleware\RoutingMiddleware::class,
\Phast\Middleware\DispatcherMiddleware::class,
];
// config/cors.php
return [
// Allowed origins ('*' for all, or array of specific origins)
// Note: Cannot use '*' when allow_credentials is true
'allowed_origins' => env('CORS_ALLOWED_ORIGINS', '*'),
// Allowed HTTP methods
'allowed_methods' => [
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'OPTIONS',
],
// Allowed request headers ('*' for all, or array of specific headers)
'allowed_headers' => env('CORS_ALLOWED_HEADERS', '*'),
// Headers that can be exposed to the client
'exposed_headers' => [],
// Maximum age (in seconds) for preflight request cache
'max_age' => (int) env('CORS_MAX_AGE', 86400),
// Allow credentials (cookies, authorization headers, etc.)
// Note: When true, allowed_origins cannot be '*'
'allow_credentials' => (bool) env('CORS_ALLOW_CREDENTIALS', false),
// Paths/prefixes to
// config/providers.php
return [
// ConfigProvider must be first (other providers depend on it)
\Phast\Providers\ConfigProvider::class,
\Phast\Providers\CacheProvider::class,
\Phast\Providers\DatabaseProvider::class,
// ... other framework providers
// Add your custom providers here
\App\Providers\CustomProvider::class,
];
namespace App\Providers;
use Katora\Container;
use Phast\Providers\ProviderInterface;
class CustomProvider implements ProviderInterface
{
public function provide(Container $container): void
{
// Register services here
$container->set('custom.service', fn() => new CustomService);
}
public function init(Container $container): void
{
// Initialize services here (called after all providers are registered)
$service = $container->get('custom.service');
$service->initialize();
}
}
namespace App\Controllers;
use Phast\Controller;
class HomeController extends Controller
{
public function index(ServerRequestInterface $request): ResponseInterface
{
return $this->render('welcome', ['message' => 'Hello, Phast!']);
}
}
namespace App\Models;
use Datum\Model;
class User extends Model
{
protected static ?string $table = 'users';
}
// Usage
$user = User::find(1);
$user = new User;
$user->name = 'John';
$user->save();
// Generated migration
class CreateUsersTable implements MigrationInterface
{
public function up(ConnectionInterface $connection): void
{
$connection->execute("CREATE TABLE users (...)");
}
public function down(ConnectionInterface $connection): void
{
$connection->execute("DROP TABLE users");
}
}
// Generated seeder (implements Phast\Database\SeederInterface)
// Dependencies are injected via constructor and resolved by the container.
use Databoss\ConnectionInterface;
use Phast\Database\SeederInterface;
class UserSeeder implements SeederInterface
{
public function __construct(
private readonly ConnectionInterface $connection
) {}
public function run(): void
{
// Raw connection
$this->connection->insert('users', ['name' => 'John', 'email' => '[email protected]']);
// Or via model
$user = new \App\Models\User;
$user->name = 'Jane';
$user->email = '[email protected]';
$user->save();
}
}
'seed' => [
'DatabaseSeeder',
'UserSeeder',
],
namespace App\Jobs;
use Qatar\Job;
class SendEmailJob extends Job
{
public function handle(array $payload): void
{
// Job logic
}
public function retries(): int
{
return 3;
}
}