LENKRAD - The modern PHP core
Quick Start
Docs Starter

Simple.

Lightning fast.

A joy to develop with.

1. Install via composer

composer require neoan.io/core

2. Create a source folder and a web folder

mkdir src
mkdir public (or however appropriate with your system)

3. Prepare composer.json to autoload files


                ...
                "autoload": {
                    "psr-4": {
                      "App\\": "./src/",
                    }
                ...
            

4. Make composer understand

composer dumpautoload

5. Set up your app

Your index.php should run in the root of the intended web-entry (usually /public)


                // /public/index.php

                use Neoan\NeoanApp;
                use Neoan\Routing\Route;
                use Neoan\Helper\Setup;

                $projectPath = dirname(__DIR__);
                require_once $projectPath . '/vendor/autoload.php';

                $pathToSourceFiles = $projectPath . '/src';
                $publicPath = __DIR__;

                $setup = new Setup();
                $setup->setLibraryPath($pathToSourceFiles)
                      ->setPublicPath($publicPath);

                $app = new NeoanApp($setup);

                // register a test route
                Route::get('/')->inject([
                        'msg' => 'Neoan LENKRAD is running'
                    ]);

                // run application
                $app->run();
            
NOTE: prior to v0.2, the neoanApp instance does not accept a setup instance. It is not recommended to start a new project with older versions.

6. Test your app

cd public
php -S localhost:8000 index.php

Database Connectivity

LENKRAD uses a database adapter to interact with databases in a standardized way. Own database adapters have to implement Neoan\Database\Adapter and be able to handle the easy-markup. For this quick setup we will assume the use of MySQL.

composer require neoan.io/legacy-db-adapter


                use Neoan\Database\Database;
                use NeoanIo\MarketPlace\DatabaseAdapter;
                use Neoan\Helper\Env;

                $dbClient = [
                    'host' => Env::get('DB_HOST', 'localhost'),
                    'name' => Env::get('DB_NAME', 'neoan_io'),
                    'port' => Env::get('DB_PORT', 3306),
                    'user' => Env::get('DB_USER', 'root'),
                    'password' => Env::get('DB_PASSWORD', ''),
                    'charset' => Env::get('DB_CHARSET', 'utf8mb4'),
                    'casing' => Env::get('DB_CASING', 'camel'),
                    'assumes_uuid' => Env::get('DB_UUID', false)
                ];
                Database::connect(new DatabaseAdapter($dbClient));
            

It's up to you where you place this code. You could decide to place it as a middleware or in a general setup file. However, make sure to execute it prior to any model-interactions. In most cases you want to add this to your application bootstrapping after initialization of the app and before execution ($app->run())

That's it for the app itself. What about the cli helper?

However, let's set up the CLI application as well. The cli tool helps you with common tasks like migrating models or generating files.

1. Create a file cli in your project's root directory

touch cli (or however appropriate with your system)

2. Configure the CLI application

As we didn't use .php as a file extension, make sure to use the shebang line to execute as PHP.

                #!/usr/bin/env php
                ?php


                use Neoan\Cli\Application;
                use Neoan\NeoanApp;
                use Neoan\Helper\Setup;

                $projectPath = __DIR__;
                require_once $projectPath . '/vendor/autoload.php';

                $setup = (new Setup())
                            ->setLibraryPath($projectPath . '/src')
                            ->setPublicPath($projectPath . '/public');

                // Note that we add a second parameter here, the CLI-path
                // In our case, it's the same as the project path
                $app = new NeoanApp($setup, $projectPath);

                // Now let's pass the initialized app into our console application
                $console = new Application($app);
                $console->run();
            

3. Test CLI setup

php cli list

Just let me code!

The actual fastest way to get you to your application is by using one of the starter packages: Starter Projects

Prerequisites

  • PHP - min. 8.1
  • Composer - min. 2.x