Strukt Framework
, (*1)
The is the package that unifies all strukt-strukt
components under the framework., (*2)
Rarely should anyone use this on its own., (*3)
Getting started
echo {"minimum-stability":"dev"} > composer.json
composer require "strukt/framework:1.1.8-alpha" --prefer-dist
Setup, Cache, Configuration & Environment
Cache
Always remember to clear and reload the cache when necessary, (*4)
./xcli cache:clear
./xcli cache:make
Shell
Drop into shell, (*5)
./xcli shell:exec
Setting Application Type
config("app.type", "App:Idx")// for index.php, alternative App:Cli for console
Configuration
config("facet.middlewares")
config("facet.providers")
Environment Setup
This class is defaultly found in strukt-commons, (*6)
Strukt\Env::withFile();//default .env file in your root folder
Strukt\Env::withFile(".env-dev");
env("root_dir", getcwd());//setter custom environment variable
env("root_dir");//getter
Setup Packages Registry
Packages reference file location ./cfg/repo.ini
, (*7)
repos(); //list all repositories
repos("published");//list all published strukt packages
repos("installed");//list all installed strukt packages
Packages
Default Package
package("core", "App:Idx")->get("settings"); //returns array of middlewares, commands and providers
//below mode:App:Cli is default
package("core")->get("name");//core
package("core")->get("cmd:name");//null
package("core")->get("files");//null
package("core")->get("modules");//null
package("core")->get("is:published");//true by default
package("core")->get("requirements");//null or array
The above methods are interfaced in class Strukt\Framework\Contract\Package
you must use them in your package., (*8)
Building Packages
The first step in developing your package will require you to install strukt-framework
and execute composer exec strukt
command that will create your folder structure. You'll need to create src
and package
folders., (*9)
See structure of package below:, (*10)
โโโ bootstrap.php
โโโ cfg/
โโโ console
โโโ index.php
โโโ lib/
โโโ tpl/
โโโ vendor/
โโโ composer.json
โโโ LICENSE
โโโ package/ #Place all your packages files here
โโโ README.md
โโโ src
โโโ Strukt
โโโ Package
โโโ Pkg{{Package Name}}.php #Identify your package resources here
Again, your package class in src/Strukt/Package/Pkg<Package Name>.php
will have methods
listed in Strukt\Fraamework\Contract\Package
, (*11)
Package Autoloading
You may require to autoload libraries both from your root directory and package resources., (*12)
$loader = require "vendor/autoload.php";
...
...
$loader->addPsr4("App\\", [
__DIR__."/lib/App",
__DIR__."/package/lib/App"
]);
return $loader;
Note
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
., (*13)
This will require you to enter into your cfg/repo.php
and indicate you are currently in-development with the key/keyword package
which will allow the publisher to install files in the your app source folder app/src
., (*14)
The publish:package
command installs from vendor
but in development-mode you can use --dev
switch
to install your package that will be located in your project root., (*15)
Validator
Example
namespace Payroll\AuthModule\Form;
use Strukt\Framework\Contract\Form as AbstractForm;
class User extends AbstractForm{
/**
* @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.php
There you can find an example App\Validator::isLenGt
, (*16)
/**
* @IsLenGt(10)
*/