Skip to content

Commit c82dfcc

Browse files
committed
initial commit
0 parents  commit c82dfcc

File tree

6 files changed

+327
-0
lines changed

6 files changed

+327
-0
lines changed

.gitignore

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#-------------------------
2+
# Operating Specific Junk Files
3+
#-------------------------
4+
5+
# OS X
6+
.DS_Store
7+
.AppleDouble
8+
.LSOverride
9+
10+
# OS X Thumbnails
11+
._*
12+
13+
# Windows image file caches
14+
Thumbs.db
15+
ehthumbs.db
16+
Desktop.ini
17+
18+
# Recycle Bin used on file shares
19+
$RECYCLE.BIN/
20+
21+
# Windows Installer files
22+
*.cab
23+
*.msi
24+
*.msm
25+
*.msp
26+
27+
# Windows shortcuts
28+
*.lnk
29+
30+
# Linux
31+
*~
32+
33+
# KDE directory preferences
34+
.directory
35+
36+
# Linux trash folder which might appear on any partition or disk
37+
.Trash-*
38+
39+
#-------------------------
40+
# Environment Files
41+
#-------------------------
42+
# These should never be under version control,
43+
# as it poses a security risk.
44+
.env
45+
.vagrant
46+
Vagrantfile
47+
48+
#-------------------------
49+
# Temporary Files
50+
#-------------------------
51+
writable/cache/*
52+
!writable/cache/index.html
53+
54+
writable/logs/*
55+
!writable/logs/index.html
56+
57+
writable/session/*
58+
!writable/session/index.html
59+
60+
writable/uploads/*
61+
!writable/uploads/index.html
62+
63+
writable/debugbar/*
64+
65+
php_errors.log
66+
67+
#-------------------------
68+
# User Guide Temp Files
69+
#-------------------------
70+
user_guide_src/build/*
71+
user_guide_src/cilexer/build/*
72+
user_guide_src/cilexer/dist/*
73+
user_guide_src/cilexer/pycilexer.egg-info/*
74+
75+
#-------------------------
76+
# Test Files
77+
#-------------------------
78+
tests/coverage*
79+
80+
# Don't save phpunit under version control.
81+
phpunit
82+
83+
#-------------------------
84+
# Composer
85+
#-------------------------
86+
vendor/
87+
composer.lock
88+
89+
#-------------------------
90+
# IDE / Development Files
91+
#-------------------------
92+
93+
# Modules Testing
94+
_modules/*
95+
96+
# phpenv local config
97+
.php-version
98+
99+
# Jetbrains editors (PHPStorm, etc)
100+
.idea/
101+
*.iml
102+
103+
# Netbeans
104+
nbproject/
105+
build/
106+
nbbuild/
107+
dist/
108+
nbdist/
109+
nbactions.xml
110+
nb-configuration.xml
111+
.nb-gradle/
112+
113+
# Sublime Text
114+
*.tmlanguage.cache
115+
*.tmPreferences.cache
116+
*.stTheme.cache
117+
*.sublime-workspace
118+
*.sublime-project
119+
.phpintel
120+
/api/
121+
122+
# Visual Studio Code
123+
.vscode/
124+
125+
/results/
126+
/phpunit*.xml
127+
/.phpunit.*.cache

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019-2020 Agung Sugiarto
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# The Illuminate Database package for CodeIgniter 4
2+
3+
[![Latest Version](https://img.shields.io/github/release/agungsugiarto/codeigniter4-inspiring.svg)](https://github.com/agungsugiarto/codeigniter4-inspiring/releases)
4+
[![Total Downloads](https://poser.pugx.org/agungsugiarto/codeigniter4-inspiring/downloads)](https://packagist.org/packages/agungsugiarto/codeigniter4-inspiring)
5+
[![License](https://poser.pugx.org/agungsugiarto/codeigniter4-inspiring/license)](https://packagist.org/packages/agungsugiarto/codeigniter4-inspiring)
6+
[![test](https://github.com/agungsugiarto/codeigniter4-inspiring/workflows/inspiring%20build/badge.svg)](https://github.com/agungsugiarto/codeigniter4-inspiring/actions)
7+
8+
[Notepad++ easter egg quotes](http://en.wikipedia.org/wiki/Notepad%2B%2B#Easter_egg) and have a lot more inspiration.
9+
10+
![](.github/carbon.png?raw=true)
11+
## Instalation
12+
13+
Include this package via Composer:
14+
15+
```console
16+
composer require agungsugiarto/codeigniter4-eloquent
17+
```
18+
19+
## Setup services eloquent
20+
Open App\Controllers\BaseController.php
21+
22+
add `service(eloquent);` on function initController
23+
```php
24+
//--------------------------------------------------------------------
25+
// Preload any models, libraries, etc, here.
26+
//--------------------------------------------------------------------
27+
// E.g.:
28+
// $this->session = \Config\Services::session();
29+
30+
service(eloquent);
31+
```
32+
## Usage
33+
34+
Example model
35+
```php
36+
<?php
37+
38+
namespace App\Models;
39+
40+
use Illuminate\Database\Eloquent\Model;
41+
42+
class Authors extends Model
43+
{
44+
protected $table = 'authors';
45+
protected $primaryKey = 'id';
46+
}
47+
48+
```
49+
50+
### How to use in controller
51+
```php
52+
<?php
53+
54+
namespace App\Controllers;
55+
56+
use App\Models\Authors;
57+
use Fluent\Models\DB;
58+
59+
class Home extends BaseController
60+
{
61+
public function index()
62+
{
63+
return $this->response->setJSON([
64+
'data' => Authors::all(),
65+
'sample' => DB::table('authors')->skip(1)->take(100)->get(),
66+
]);
67+
}
68+
}
69+
70+
```
71+
72+
## More info usefull link docs laravel
73+
- [Database: Getting Started](https://laravel.com/docs/7.x/database)
74+
75+
- [Eloquent: Getting Started](https://laravel.com/docs/7.x/eloquent)
76+
77+
## License
78+
79+
This package is free software distributed under the terms of the [MIT license](LICENSE.md).

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "agungsugiarto/codeigniter4-eloquent",
3+
"description": "The Illuminate Database package for CodeIgniter 4",
4+
"keywords": ["codegniter4", "codeigniter4-eloquent", "database", "orm", "sql"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "agungsugiarto",
9+
"email": "me.agungsugiarto@tgmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": "^7.2",
14+
"codeigniter4/framework": "^4.0",
15+
"illuminate/database": "^7.22"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"Fluent\\": "src/"
20+
}
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^8.5"
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Tests\\": "tests/"
28+
}
29+
},
30+
"scripts": {
31+
"test": "phpunit --colors=always -vvv"
32+
}
33+
}

src/Config/Services.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Fluent\Config;
4+
5+
use CodeIgniter\Config\BaseService as CoreServices;
6+
use CodeIgniter\Config\Config;
7+
use Fluent\Models\DB;
8+
use Illuminate\Database\Capsule\Manager;
9+
10+
class Services extends CoreServices
11+
{
12+
public static function eloquent($getShared = true)
13+
{
14+
if ($getShared) {
15+
return static::getSharedInstance('eloquent');
16+
}
17+
18+
return new DB(new Manager, new Config);
19+
}
20+
}

src/Models/DB.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Fluent\Models;
4+
5+
use CodeIgniter\Config\Config;
6+
use Illuminate\Database\Capsule\Manager;
7+
8+
class DB extends Manager
9+
{
10+
protected $driver;
11+
12+
public function __construct(Manager $capsule, Config $config)
13+
{
14+
parent::__construct();
15+
16+
switch ($config::get('Database')->default['DBDriver']) {
17+
case 'MySQLi':
18+
$this->driver = 'mysql';
19+
break;
20+
case 'Postgre':
21+
$this->driver = 'pgsql';
22+
case 'SQLite3':
23+
$this->driver = 'sqlite';
24+
default:
25+
$this->driver = 'mysql';
26+
break;
27+
}
28+
29+
$capsule->addConnection([
30+
'driver' => $this->driver,
31+
'host' => $config::get('Database')->default['hostname'],
32+
'port' => $config::get('Database')->default['port'],
33+
'database' => $config::get('Database')->default['database'],
34+
'username' => $config::get('Database')->default['username'],
35+
'password' => $config::get('Database')->default['password'],
36+
'charset' => $config::get('Database')->default['charset'],
37+
'collation' => $config::get('Database')->default['DBCollat'],
38+
'prefix' => $config::get('Database')->default['DBPrefix'],
39+
'strict' => $config::get('Database')->default['strictOn'],
40+
'schema' => 'public',
41+
]);
42+
43+
$capsule->setAsGlobal();
44+
45+
$capsule->bootEloquent();
46+
}
47+
}

0 commit comments

Comments
 (0)