tobento / app-backend
App backend.
Requires
- php: >=8.0
- tobento/app: ^1.0.7
- tobento/app-cache: ^1.0
- tobento/app-card: ^1.0
- tobento/app-crud: ^1.0
- tobento/app-media: ^1.0
- tobento/app-search: ^1.0
- tobento/app-user-web: ^1.0
- tobento/apps: ^1.0
- tobento/css-modal: ^1.0
- tobento/js-editor: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- tobento/app-profiler: ^1.0
- tobento/app-testing: ^1.0
- vimeo/psalm: ^4.0
README
The App Backend is a minimal admin panel using the following main app bundles:
- Apps to run the backend in its own application
- App User Web for authentication
- App Crud for users and roles CRUD operations
- App Media to support media
- App Search to search apps content
- App Card to display cards on dashboard
Table of Contents
Getting Started
Add the latest version of the app backend project running this command.
composer require tobento/app-backend
Requirements
- PHP 8.0 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
Backend Boot
The backend boot is extended :
use Tobento\App\AppFactory; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots $app->boot(\Tobento\App\Backend\Boot\Backend::class); // Run the app $app->run();
Once booted, you can access the backend by the following URL http://localhost/{project}/public/admin/
.
You may change the backend
slug admin
or even route to another domain in the app/config/apps.php
file.
Adding Boots
There are two ways to add backend boots:
Via App Config
In the apps/backend/config/app.php
file you can add more boots.
'boots' => [ // ... SomeBoot::class, ],
Via Backend Boot
use Tobento\App\Boot; use Tobento\App\Backend\Boot\Backend; class BackendBoots extends Boot { public const BOOT = [ Backend::class, ]; public function boot(Backend $backend): void { $backend->addBoot(SomeBoot::class); } }
Register your boot:
use Tobento\App\AppFactory; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots $app->boot(\Tobento\App\Backend\Boot\Backend::class); $app->boot(BackendBoots::class); // Run the app $app->run();
Adding Dashboard Cards
Use the DashboardCards::class
and app on
method to add dashboard cards only on demand:
use Tobento\App\Backend\Card\DashboardCards; use Tobento\App\Card\Factory; $app->on( DashboardCards::class, static function(DashboardCards $cards): void { // Adding cards: $cards->add(name: 'foo', card: new Factory\Table( rows: ['foo', 'bar'], )); } );
Check out the App Card bundle to learn more.
Adding Searchables
To add searchables, check out the App Search - Adding Searchables section.
Customization
Customize Via App
In your app/src
directory you may create a boot customizing specific controllers for instance.
namespace App; use use Tobento\App\Backend\Controller\RoleCrudController; class Customization extends Boot { public function boot(): void { // Custom controller: $this->app->set(RoleCrudController::class, \App\CustomRoleCrudController::class); } }
In the apps/backend/config/app.php
file add your boot.
'boots' => [ // ... \App\Customization::class, ],
Customize Via App Config
In the apps/backend/config/app.php
file you can replace existing boots with your customized boots.
'boots' => [ // ... // Resources: //\Tobento\App\Backend\Boot\Roles::class, \Tobento\App\Backend\Boot\CustomRoles::class, //\Tobento\App\Backend\Boot\Users::class, \Tobento\App\Backend\Boot\CustomUsers::class, // ... ],
Testing
You may boot the \Tobento\App\Backend\Testing\UserAndRolesBoot::class
which will migrate the following users for testing:
Smartphone | Role | Active | |
---|---|---|---|
admin@example.com | - | administrator | 1 |
inactive@example.com | - | administrator | 0 |
editor@example.com | 12345678 | editor | 1 |
registered@example.com | - | registered | 1 |
use Tobento\App\AppInterface; final class SomeBackendAppTest extends \Tobento\App\Testing\TestCase { use \Tobento\App\Testing\Database\MigrateDatabases; public function createApp(): AppInterface { $app = $this->createTmpApp(rootDir: __DIR__.'/../..'); $app->boot(\Tobento\App\Backend\Boot\Backend::class); $app->booting(); $app = $app->get(AppsInterface::class)->get('backend')->app(); $app->boot(\Tobento\App\Seeding\Boot\Seeding::class); $app->boot(\Tobento\App\Backend\Testing\UserAndRolesBoot::class); return $app; } }
You may check out the following links to learn more about testing.