PHP code example of rougin / basilisk
1. Go to this page and download the library: Download rougin/basilisk 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' );
rougin / basilisk example snippets bash
$ cd hogwarts
$ php setup.php
php
return array (
'name' => getenv('APP_NAME' ),
'version' => getenv('APP_VERSION' ),
);
php
return array (
'paths' => array (
'migrations' => array (
$root . '/src/Phinx/Scripts' ,
),
'seeds' => array (
$root . '/src/Phinx/Seeders' ,
),
),
);
php
namespace App \Depots ;
use App \Models \User ;
class UserDepot
{
protected $user;
public function __construct (User $user)
{
$this ->user = $user;
}
public function all ()
{
$result = $this ->user->all();
$items = array ();
return $items;
}
}
php
use Phinx \Migration \AbstractMigration ;
class CreateUsersTable extends AbstractMigration
{
public function change () : void
{
$properties = ['id' => false , 'primary_key' => ['id' ]];
$table = $this ->table('users' , $properties);
$table->addColumn('id' , 'integer' , ['limit' => 10 , 'identity' => true ]);
$table->addColumn('name' , 'string' , ['limit' => 200 ]);
$table->addColumn('email' , 'string' , ['limit' => 200 ]);
$table->addColumn('password' , 'string' , ['limit' => 500 ]);
$table->addColumn('created_at' , 'datetime' );
$table->addColumn('updated_at' , 'datetime' , ['null' => true ]);
$table->create();
}
}
php
use Phinx \Seed \AbstractSeed ;
class UserSeeder extends AbstractSeed
{
protected $items =
[
['name' => 'Harry Jonathans Potter' , 'email' => 'hjpotter@hogwarts.co.uk' ],
['name' => 'Hermione Jane Granger' , 'email' => 'hjgranger@hogwarts.co.uk' ],
['name' => 'Ronald Bilius Weasley' , 'email' => 'rbweasley@hogwarts.co.uk' ],
];
public function run () : void
{
$data = array ();
foreach ($this ->items as $item)
{
$item['created_at' ] = date('Y-m-d H:i:s' );
$data[] = $item;
}
$this ->table('users' )->insert($data)->save();
}
}
php
namespace App \Routes ;
use Rougin \Slytherin \Template \RendererInterface ;
class Hello
{
public function index (RendererInterface $renderer)
{
return $renderer->render('index' );
}
}
php
namespace App ;
use Rougin \Slytherin \Routing \Router as Slytherin ;
class Router extends Slytherin
{
protected $namespace = 'App\Routes' ;
protected $prefix = '/' ;
public function routes ()
{
$this ->get('/' , 'Hello@index' );
return $this ->routes;
}
}
php
echo 'Hello world!' ;
bash
$ php src/Scripts/HelloWorld.php
Hello world!
bash
$ composer global
bash
$ php-cs-fixer fix --config=phpstyle.php