Skip to content

Commit

Permalink
WIP: boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
agungsugiarto committed Mar 24, 2020
1 parent a59aca4 commit 7adf799
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 64 deletions.
Binary file added .github/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 145 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,145 @@
# CodeIgniter 4 Application Starter

CodeIgniter 4 Application Boilerplate
=====================================
![Package](https://img.shields.io/badge/Package-agungsugiarto%2Fboilerplate-light.svg)
[![StyleCI](https://github.styleci.io/repos/243432201/shield?branch=master)](https://github.styleci.io/repos/243432201)
![PHP Composer](https://github.com/agungsugiarto/boilerplate/workflows/PHP%20Composer/badge.svg)
![GitHub All Releases](https://img.shields.io/github/downloads/agungsugiarto/boilerplate/total)
[![GitHub stars](https://img.shields.io/github/stars/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/stargazers)
[![GitHub license](https://img.shields.io/github/license/agungsugiarto/boilerplate)](https://github.com/agungsugiarto/boilerplate/blob/master/LICENSE.md)

Feature
-------
* Configurable backend theme [AdminLTE 3](https://adminlte.io/docs/3.0/)
* Css framework [Bootstrap 4](https://getbootstrap.com/)
* Icons by [Font Awesome 5](https://fontawesome.com/)
* Role-based permissions provided by [Myth/Auth](https://github.com/lonnieezell/myth-auth)
* Menu dynamically
* Localized English / Indonesian

This project is early on development feel free to contribute
------------------------------------------------------------
Screenshoot | Demo On [Heroku](https://boilerplate-codeigniter4.herokuapp.com/)
-------------------------------------------------------------------------------
![Dashboard](.github/dashboard.png?raw=true)

Installation
------------

**1.** Get The Module

require via composer

```bash
composer require agungsugiarto/boilerplate
```

**2.** Set CI_ENVIRONMENT, base url, index page, and database config in your `.env` file based on your existing database (If you don't have a `.env` file, you can copy first from `env` file: `cp env .env` first). If the database not exists, create database first.

```bash
# .env file
CI_ENVIRONMENT = development

app.baseURL = 'http://localhost:8080'
app.indexPage = ''

database.default.hostname = localhost
database.default.database = boilerplate
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
```
**3.** Run publish auth
```bash
php spark auth:publsih

Publish Migration? [y, n]: n
Publish Models? [y, n]: n
Publish Entities? [y, n]: n
Publish Controller? [y, n]: n
Publish Views? [y, n]: n
Publish Config file? [y, n]: y
created: Config/Auth.php
Publish Language file? [y, n]:
```

> NOTE: Everything about how to configure auth you find add [Myth/Auth](https://github.com/lonnieezell/myth-auth).

Its done ? not to fast. After the publish `Config/Auth.php` you need to change
`public $views` with below like this.
```php
public $views = [
'login' => 'agungsugiarto\boilerplate\Views\Authentication\login',
'register' => 'agungsugiarto\boilerplate\Views\Authentication\register',
'forgot' => 'agungsugiarto\boilerplate\Views\Authentication\forgot',
'reset' => 'agungsugiarto\boilerplate\Views\Authentication\reset',
'emailForgot' => 'agungsugiarto\boilerplate\Views\Authentication\emails\fogot',
'emailActivation' => 'agungsugiarto\boilerplate\Views\Authentication\emails\acivation',
];
```

Open `app\Config\Filters.php` see at `$aliases` add with below like this.
```php
public $aliases = [
'login' => \Myth\Auth\Filters\LoginFilter::class,
'role' => \agungsugiarto\boilerplate\Filters\RoleFilter::class,
'permission' => \agungsugiarto\boilerplate\Filters\PermissionFilter::class,
];
```

**4.** Run publish, migrate and seed boilerplate

```bash
php spark boilerplate:install
```

**5.** Run development server:

```bash
php spark serve
```

**6.** Open in browser http://localhost:8080/admin
```bash
Default user and password
+----+--------+-------------+
| No | User | Password |
+----+--------+-------------+
| 1 | admin | super-admin |
| 2 | user | super-user |
+----+--------+-------------+
```

Settings
--------

Config Boilerplate

You can configure default dashboard controller and backend theme in `app\Config\Boilerplate.php`,

```php
class Boilerplate extends BaseConfig
{
public $appName = 'Boilerplate';

public $dashboard = [
'namespace' => 'agungsugiarto\boilerplate\Controllers',
'controller' => 'DashboardController::index',
'filter' => 'permission:back-office',
];
// App/Config/Boilerplate.php
```

Usage
-----
You can find how its work with the read code routes, controller and views etc. Finnaly happy coding!

Contributing
------------
Contributions are very welcome.

License
-------

This package is free software distributed under the terms of the [MIT license](LICENSE.md).
1 change: 1 addition & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class InstallCommand extends BaseCommand
public function run(array $params)
{
try {
$this->call('boilerplate:publish');
// migrate all first
$this->call('migrate', ['-all']);
// then seed data
Expand Down
67 changes: 4 additions & 63 deletions src/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,76 +71,17 @@ class PublishCommand extends BaseCommand
public function run(array $params)
{
$this->determineSourcePath();

// Controller
if (CLI::prompt('Publish Controller?', ['y', 'n']) == 'y') {
$this->publishController();
}

// Views
if (CLI::prompt('Publish Views?', ['y', 'n']) == 'y') {
$this->publishViews();
}

// Config
if (CLI::prompt('Publish Config file?', ['y', 'n']) == 'y') {
$this->publishConfig();
}
}

protected function publishController()
{
$path = "{$this->sourcePath}/Controllers/AuthController.php";

$content = file_get_contents($path);
$content = $this->replaceNamespace($content, 'Myth\Auth\Controllers', 'Controllers');

$this->writeFile('Controllers/AuthController.php', $content);
}

protected function publishViews()
{
$map = directory_map($this->sourcePath.'/Views');
$prefix = '';

foreach ($map as $key => $view) {
if (is_array($view)) {
$oldPrefix = $prefix;
$prefix .= $key;

foreach ($view as $file) {
$this->publishView($file, $prefix);
}

$prefix = $oldPrefix;

continue;
}

$this->publishView($view, $prefix);
}
}

protected function publishView($view, string $prefix = '')
{
$path = "{$this->sourcePath}/Views/{$prefix}{$view}";
$namespace = defined('APP_NAMESPACE') ? APP_NAMESPACE : 'App';

$content = file_get_contents($path);
$content = str_replace('agungsugiarto\boilertplate\Views', $namespace.'\Authentication', $content);

$this->writeFile("Views/{$prefix}{$view}", $content);
$this->publishConfig();
}

protected function publishConfig()
{
$path = "{$this->sourcePath}/Config/Auth.php";
$path = "{$this->sourcePath}/Config/Boilerplate.php";

$content = file_get_contents($path);
$content = str_replace('namespace Myth\Auth\Config', 'namespace Config', $content);
$content = str_replace('extends BaseConfig', "extends \Myth\Auth\Config\Auth", $content);
$content = str_replace('namespace agungsugiarto\boilerplate\Config', 'namespace Config', $content);

$this->writeFile('Config/Auth.php', $content);
$this->writeFile('Config/Boilerplate.php', $content);
}

//--------------------------------------------------------------------
Expand Down

0 comments on commit 7adf799

Please sign in to comment.