Strukt Framework

v1.1.5-alpha 2023-03-02 08:41 UTC

This package is auto-updated.

Last update: 2023-03-02 08:42:08 UTC


Build Status Latest Stable Version Total Downloads Latest Unstable Version License

The is the package that unifies all strukt-strukt components under the framework.

Rarely should anyone use this on its own.

Getting started

echo {"minimum-stability":"dev"} > composer.json
composer require "strukt/framework:1.1.5-alpha" --prefer-dist

Setup, Configuration & Environment

Setting Application Type

use Strukt\Framework\App as FrameworkApp;

FrameworkApp::create($type); //Can only be "App:Idx" for web or "App:Cli" for command line
FrameworkApp::getType(); //get application type
FrameworkApp::getConfig();// Strukt\Framework\Configuration


$cfg = new Strukt\Framework\Configuration();
$cfg->getInjectables();//Get package configurations from App\Injectables
$cfg->getSetup();//Already called in instance above
$cfg->get($type);//Configuration type "providers", "middlewares" or "commands"

Environment Setup

This class is defaultly found in strukt-commons

Strukt\Env::withFile();//default .env file in your root folder
Strukt\Env::set("root_dir", getcwd());//custom environment variable

Setup Packages Registry

File location ./cfg/repo.ini

core = Core # Default in built package for default middlewares and providers
pkg-do = PkgDo #
pkg-roles = PkgRoles #
pkg-audit = PkgAudit #
pkg-books = PkgBooks #
pkg-tests = PkgTests #
pkg-asset = PkgAsset #

Repo packages load and list.

FrameworkApp::mayBeRepo(); //Load repo names
FrameworkApp::getRepo(); //Get loaded repo names

Some Application Methods

// The line below sets up namespace with the application name
//	the ns will translate into Payroll\AuthModule\Command\PermissionAdd
//	if your app's name is payroll
$cls = FrameworkApp::newCls("{{app}}\AuthModule\Command\PermissionAdd");

//Get app_name from cfg/app.ini file
$app_name = FrameworkApp::getName(); //payroll


//Get installed and published packages

Default Package

$core = new Strukt\Package\Core();//implements Strukt\Package\Pkg

//returns array of middlewares, commands and providers
$core->getSettings($type);//type is "App:Idx" or "App:Cli"

$core->isPublished();//true by default
$core->getRequirements();//null or array

The above methods are in abstract class Strukt\Package\Pkg you can use them to create your package.

Building Packages

Your first step in developing your package will require you to install strukt-framework and execute composer exec strukt-cfg command that will create your folder structure. You'll need to create src and package folders.

See structure of package below.

├── bootstrap.php
├── cfg
├── console
├── index.php
├── lib
├── tpl
├── vendor
├── composer.json
├── package #Place all your packages files here
└── src
    └── Strukt
        └── Package
            └── Pkg{{Package Name}}.php #Identify your package resources here

Your package class in src/Strukt/Package/Pkg<Package Name>.php will have methods listed in the Default Package section that is it should implement the interface Strukt\Contract\Package

Package Autoloading

You may require to autoload libraries both from your root directory and package resources.

$loader = require "vendor/autoload.php";
$loader->addPsr4("App\\", [


return $loader;


For packages that require installation into your app/src/{{AppName}} folder, there are a few tricks you could use while building your package. The publish:package command takes argument package for publishing packages that are currently in development, since your source will be in the root folder in a subfolder called package.

This will require you to enter into your cfg/repo.php (See Setup Packages Registry) and indicate your currently in-development package with the key/keyword package which will allow the publisher to install files in the your app source folder app/src.



class User extends \Strukt\Contract\Form{

	* @IsNotEmpty()
	* @IsAlpha()
	public string $username;

	* @IsNotEmpty()
	public string $password;

Validator Annotations

* @IsNotEmpty()
* @IsAlpha()
* @IsAlphaNum()
* @IsNumeric()
* @IsEmail()
* @IsDate(Y-m-d)
* @IsIn(a,b,c)
* @EqualTo(xyz)
* @IsLen(10)

Adding Validators

New validators can be added is in your lib/App/Validator/Extra.php There you can find an example App\Validator\Extra::isLenGt

* @IsLenGt(10)


Somes notable mentions that can be explored via repl ./console shell:exec console.