Skip to content

Commit 1246650

Browse files
committed
first commit
0 parents  commit 1246650

34 files changed

+2234
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
.DS_Store

app/Http/Controllers/Controller.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
class Controller {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Database\Capsule\Manager as Capsule;
6+
7+
class HomeController extends Controller {
8+
9+
/**
10+
* This is the index page.
11+
*
12+
* @return string
13+
*/
14+
public function index()
15+
{
16+
return view('welcome', [
17+
'sitename' => config('app.name')
18+
]);
19+
}
20+
}

app/Http/Middleware/Authenticate.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
7+
class Authenticate {
8+
9+
/**
10+
* Handle an incoming request.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
14+
* @param string|null $guard
15+
* @return mixed
16+
*/
17+
public function handle($request, Closure $next, $guard = null)
18+
{
19+
// Do authentication check...and return something if failed...
20+
21+
return $next($request);
22+
}
23+
}

app/Model/User.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Model;
4+
5+
use Illuminate\Database\Eloquent\Model as Eloquent;
6+
7+
class User extends Eloquent {
8+
9+
/**
10+
* Name of the table.
11+
*
12+
* @var string
13+
*/
14+
protected $table = 'users';
15+
}

app/components.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
5+
// ------------------------------------------------------------
6+
// Illuminate components that are pluged into your application
7+
// ------------------------------------------------------------
8+
9+
// Core components
10+
Nimble\Component\Events\EventsComponent::class,
11+
Nimble\Component\Routing\RoutingComponent::class,
12+
13+
// Optional components
14+
Nimble\Component\Filesystem\FilesystemComponent::class,
15+
Nimble\Component\View\ViewComponent::class,
16+
Nimble\Component\Config\ConfigComponent::class,
17+
Nimble\Component\Database\DatabaseComponent::class,
18+
19+
// Custom components
20+
21+
];

app/helpers.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
if ( ! function_exists('app'))
4+
{
5+
/**
6+
* Get the illuminate container instance.
7+
*
8+
* @param string $instance
9+
* @return \Illuminate\Container\Container|mixed
10+
*/
11+
function app($instance)
12+
{
13+
global $app;
14+
15+
return $instance ? $app->make($instance) : $app;
16+
}
17+
}
18+
19+
if ( ! function_exists('config'))
20+
{
21+
/**
22+
* Get a configuration value.
23+
*
24+
* @param string $key
25+
* @param mixed $default
26+
* @return mixed
27+
*/
28+
function config($key, $default = false)
29+
{
30+
return app('config')->get($key, $default);
31+
}
32+
}
33+
34+
if ( ! function_exists('view'))
35+
{
36+
/**
37+
* Load views from the filesystem.
38+
*
39+
* @param string $view
40+
* @param array $parameters
41+
* @param array $mergeData
42+
* @return \Illuminate\Contracts\View\View
43+
*/
44+
function view($view, array $parameters = [], array $mergeData = [])
45+
{
46+
return app('view')->make($view, $parameters, $mergeData);
47+
}
48+
}

bootstrap.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
// ------------------------------------------------------------
4+
// Load composer
5+
// ------------------------------------------------------------
6+
7+
require "vendor/autoload.php";
8+
9+
// ------------------------------------------------------------
10+
// Define constant(s)
11+
// ------------------------------------------------------------
12+
13+
defined('NIMBLE_ROOT') OR define('NIMBLE_ROOT', __DIR__);
14+
defined('NIMBLE_APP') OR define('NIMBLE_APP', NIMBLE_ROOT."/app");
15+
defined('NIMBLE_STORAGE') OR define('NIMBLE_STORAGE', __DIR__."/storage");
16+
defined('NIMBLE_PUBLIC') OR define('NIMBLE_PUBLIC', NIMBLE_ROOT."/public");
17+
defined('NIMBLE_RESOURCES') OR define('NIMBLE_RESOURCES', NIMBLE_ROOT."/resources");
18+
19+
// ------------------------------------------------------------
20+
// Load the container and plug all things
21+
// ------------------------------------------------------------
22+
23+
$app = new Illuminate\Container\Container;
24+
25+
// ------------------------------------------------------------
26+
// Load the helpers
27+
// ------------------------------------------------------------
28+
29+
require NIMBLE_APP.'/helpers.php';
30+
31+
// ------------------------------------------------------------
32+
// Load the components
33+
// ------------------------------------------------------------
34+
35+
$components = require NIMBLE_APP.'/components.php';
36+
37+
foreach ($components as $component) {
38+
(new $component($app))->setUp();
39+
}

component/Cache/CacheComponent.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Nimble\Component\Cache;
4+
5+
use Nimble\Component\Component;
6+
use Illuminate\Cache\CacheManager;
7+
8+
class CacheComponent extends Component {
9+
10+
/**
11+
* Set up the component.
12+
*/
13+
public function setUp()
14+
{
15+
$this->app->singleton($this->name(), function () {
16+
return (new CacheManager($this->app));
17+
});
18+
19+
$this->app->singleton("{$this->name()}.file", function () {
20+
return app($this->name())->store('file');
21+
});
22+
}
23+
24+
/**
25+
* Returns the name of the component
26+
*
27+
* @return string
28+
*/
29+
public function name()
30+
{
31+
return 'cache';
32+
}
33+
}

component/Component.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Nimble\Component;
4+
5+
use Illuminate\Container\Container;
6+
7+
abstract class Component {
8+
9+
/**
10+
* Container instance.
11+
*
12+
* @var Container
13+
*/
14+
protected $app;
15+
16+
/**
17+
* Component constructor.
18+
*
19+
* @param Container $app
20+
*/
21+
public function __construct(Container $app)
22+
{
23+
$this->app = $app;
24+
}
25+
26+
/**
27+
* Get the name of the plug in
28+
*
29+
* @return string
30+
*/
31+
abstract public function name();
32+
}

component/Config/ConfigComponent.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Nimble\Component\Config;
4+
5+
use Nimble\Component\Component;
6+
use Illuminate\Config\Repository as Config;
7+
8+
class ConfigComponent extends Component {
9+
10+
/**
11+
* Set up the component.
12+
*/
13+
public function setUp()
14+
{
15+
$this->app->singleton($this->name(), function () {
16+
$configDir = NIMBLE_ROOT."/config";
17+
18+
if (is_dir($configDir)) {
19+
$config_items = [];
20+
21+
foreach (glob($configDir."/*.php") as $file) {
22+
$namespace = str_replace('.php', '', basename($file));
23+
24+
$config_items[strtolower($namespace)] = require $file;
25+
}
26+
27+
return new Config($config_items);
28+
}
29+
});
30+
}
31+
32+
/**
33+
* Returns the name of the component
34+
*
35+
* @return string
36+
*/
37+
public function name()
38+
{
39+
return 'config';
40+
}
41+
}

component/Config/readme.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Config Component
2+
This is the config component. It uses the Illuminate Config component.
3+
4+
## Installation
5+
Add the component to the list of the Components in your `app/components.php` file.
6+
7+
```php
8+
return [
9+
Nimble\Component\Config\ConfigComponent::class,
10+
11+
//...
12+
];
13+
```
14+
15+
Create your first configuration file `app/config/app.php`.
16+
17+
```php
18+
<?php
19+
20+
return [
21+
'foo' => 'bar'
22+
];
23+
```
24+
25+
You can now access the configuration in your application.
26+
27+
```
28+
config('app.foo'); // returns "bar"
29+
```
30+
31+
You can add more configuration files. For example `app/config/services.php`
32+
33+
```php
34+
<?php
35+
36+
return [
37+
'name' => 'Facebook'
38+
];
39+
```
40+
41+
Then access it as thus
42+
43+
```
44+
config('services.name'); // returns "Facebook"
45+
```
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Nimble\Component\Database;
4+
5+
use Nimble\Component\Component;
6+
use Illuminate\Database\Capsule\Manager as Capsule;
7+
8+
class DatabaseComponent extends Component {
9+
10+
/**
11+
* Set up the component.
12+
*/
13+
public function setUp()
14+
{
15+
$capsule = new Capsule;
16+
17+
$driver = config('database.driver', 'mysql');
18+
19+
$capsule->addConnection([
20+
'driver' => $driver,
21+
'host' => config("database.{$driver}.host"),
22+
'database' => config("database.{$driver}.database"),
23+
'username' => config("database.{$driver}.username"),
24+
'password' => config("database.{$driver}.password"),
25+
'charset' => config("database.{$driver}.charset", 'utf8'),
26+
'collation' => config("database.{$driver}.collation", 'utf8_unicode_ci'),
27+
'prefix' => config("database.{$driver}.prefix"),
28+
]);
29+
30+
$capsule->setAsGlobal();
31+
32+
if (config('database.eloquent', true) === true) {
33+
$capsule->setEventDispatcher(app('events'));
34+
$capsule->bootEloquent();
35+
}
36+
37+
$this->app->singleton($this->name(), function () use ($capsule) {
38+
return $capsule;
39+
});
40+
}
41+
42+
/**
43+
* Returns the name of the component
44+
*
45+
* @return string
46+
*/
47+
public function name()
48+
{
49+
return 'database';
50+
}
51+
}

0 commit comments

Comments
 (0)