Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 29ecda7

Browse files
committed
restructured leaf API
0 parents  commit 29ecda7

File tree

93 files changed

+12927
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+12927
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.env.example

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
APP_NAME=LEAF_API
2+
APP_ENV=local
3+
APP_KEY=base64:AUAyDriQD1kFdIbwTHlnCm2pYn+qxDBa55SFwB9PUzg=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
DB_CONNECTION=mysql
8+
DB_HOST=127.0.0.1
9+
DB_PORT=3306
10+
DB_DATABASE=LEAF_DB_NAME
11+
DB_USERNAME=LEAF_DB_USERNAME
12+
DB_PASSWORD=
13+
14+
MAIL_DRIVER=smtp
15+
MAIL_HOST=smtp.mailtrap.io
16+
MAIL_PORT=2525
17+
MAIL_USERNAME=null
18+
MAIL_PASSWORD=null
19+
MAIL_ENCRYPTION=null
20+
21+
PROD_SERVER=hello
22+
PROD_PORT=22
23+
PROD_USER=leaf
24+
APPLICATION_DIR=leaf
25+
APPLICATION_PATH=leaf

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
vendor
2+
vendor2
3+
.env
4+
node_modules
5+
build
6+
dist
7+
compiled
8+
.idea

.htaccess

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<IfModule mod_rewrite.c>
2+
<IfModule mod_negotiation.c>
3+
Options -MultiViews -Indexes
4+
</IfModule>
5+
6+
RewriteEngine On
7+
8+
# Handle Authorization Header
9+
RewriteCond %{HTTP:Authorization} .
10+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
11+
12+
# Redirect Trailing Slashes If Not A Folder...
13+
RewriteCond %{REQUEST_FILENAME} !-d
14+
RewriteCond %{REQUEST_URI} (.+)/$
15+
RewriteRule ^ %1 [L,R=301]
16+
17+
# Handle Front Controller...
18+
RewriteCond %{REQUEST_FILENAME} !-d
19+
RewriteCond %{REQUEST_FILENAME} !-f
20+
RewriteRule ^ index.php [L]
21+
</IfModule>

App/Console/ExampleCommand.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace App\Console;
3+
4+
use Symfony\Component\Console\Command\Command;
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Input\InputArgument;
8+
use Symfony\Component\Console\Input\InputOption;
9+
10+
class ExampleCommand extends Command
11+
{
12+
protected static $defaultName = 'example';
13+
14+
protected $description = 'Testing example command';
15+
16+
protected $help = 'Example command\'s help';
17+
18+
public function __construct(){
19+
parent::__construct();
20+
}
21+
22+
23+
protected function configure()
24+
{
25+
$this
26+
->setDescription($this->description)
27+
->setHelp($this->help)
28+
->addOption('example', null, InputOption::VALUE_OPTIONAL, 'description', 'default');
29+
}
30+
31+
32+
public function execute(InputInterface $input, OutputInterface $output)
33+
{
34+
$this->outputSomething($input, $output);
35+
}
36+
37+
38+
protected function outputSomething($input, $output)
39+
{
40+
$option = $input->getOption('example');
41+
isset($option) ? $output->writeln("Example output. Your option was $option") : $output->writeln("Example output");
42+
}
43+
}

App/Controllers/Controller.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace App\Controllers;
3+
4+
use Leaf\Http\Request;
5+
6+
class Controller extends \Leaf\ApiController {
7+
public $request;
8+
9+
public function __construct() {
10+
parent::__construct();
11+
$this->request = new Request;
12+
}
13+
}

App/Database/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.sqlite
2+
*.sqlite-journal
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
use App\Models\User;
3+
use Faker\Generator as Faker;
4+
use Illuminate\Support\Str;
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Model Factories
9+
|--------------------------------------------------------------------------
10+
|
11+
| This directory should contain each of the model factory definitions for
12+
| your application. Factories provide a convenient way to generate new
13+
| model instances for testing / seeding your application's database.
14+
|
15+
*/
16+
17+
$factory->define(User::class, function (Faker $faker) {
18+
return [
19+
'name' => $faker->name,
20+
'email' => $faker->unique()->safeEmail,
21+
'email_verified_at' => now(),
22+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
23+
'remember_token' => Str::random(10)
24+
];
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace App\Database\Migrations;
3+
4+
use Leaf\Core\Database;
5+
6+
class CreateUsers extends Database {
7+
public function __construct() {
8+
parent::__construct();
9+
}
10+
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up() {
17+
if(!$this->capsule::schema()->hasTable("users")):
18+
$this->capsule::schema()->create("users", function ($table) {
19+
$table->increments('id');
20+
$table->string('name');
21+
$table->string('email')->unique();
22+
$table->timestamp('email_verified_at')->nullable();
23+
$table->string('password');
24+
$table->rememberToken();
25+
$table->timestamps();
26+
});
27+
endif;
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*
33+
* @return void
34+
*/
35+
public function down() {
36+
$this->capsule::schema()->dropIfExists("users");
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
namespace App\Database\Migrations;
3+
4+
use Leaf\Core\Database;
5+
6+
class CreatePasswordResets extends Database {
7+
public function __construct() {
8+
parent::__construct();
9+
}
10+
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up() {
17+
if(!$this->capsule::schema()->hasTable("password_resets")):
18+
$this->capsule::schema()->create("password_resets", function ($table) {
19+
$table->string('email')->index();
20+
$table->string('token');
21+
$table->timestamp('created_at')->nullable();
22+
});
23+
endif;
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*
29+
* @return void
30+
*/
31+
public function down() {
32+
$this->capsule::schema()->dropIfExists("password_resets");
33+
}
34+
}

App/Database/Seeds/DatabaseSeeder.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace App\Database\Seeds;
3+
4+
use Illuminate\Database\Seeder;
5+
6+
class DatabaseSeeder extends Seeder
7+
{
8+
/**
9+
* Seed the application's database.
10+
*
11+
* @return void
12+
*/
13+
public function run()
14+
{
15+
// $this->call(UsersTableSeeder::class);
16+
}
17+
}

App/Helpers/.init

Whitespace-only changes.

App/Models/Model.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace App\Models;
3+
4+
new \Leaf\Database;
5+
6+
/**
7+
* Base Model
8+
*/
9+
class Model extends \Leaf\Model {}

App/Models/User.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
class User extends Model
6+
{
7+
/**
8+
* The attributes that are mass assignable.
9+
*
10+
* @var array
11+
*/
12+
protected $fillable = [
13+
'name', 'email', 'password',
14+
];
15+
16+
/**
17+
* The attributes that should be hidden for arrays.
18+
*
19+
* @var array
20+
*/
21+
protected $hidden = [
22+
'password', 'remember_token',
23+
];
24+
25+
/**
26+
* Indicates if the model should be timestamped.
27+
*
28+
* @var bool
29+
*/
30+
public $timestamps = false;
31+
32+
/**
33+
* The attributes that should be cast to native types.
34+
*
35+
* @var array
36+
*/
37+
protected $casts = [
38+
'email_verified_at' => 'datetime',
39+
];
40+
}

App/Routes.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Set up 404 handler
6+
|--------------------------------------------------------------------------
7+
|
8+
| Create a handler for 404 errors
9+
|
10+
*/
11+
$app->set404(function () use ($app) {
12+
$app->response->respondWithCode([
13+
"data" => "Resource not found",
14+
], 404);
15+
});
16+
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Set up Controller namespace
20+
|--------------------------------------------------------------------------
21+
|
22+
| This allows you to directly use controller names instead of typing
23+
| the controller namespace first.
24+
|
25+
*/
26+
$app->setNamespace("\App\Controllers");
27+
28+
$app->get("/", function() use($app) {
29+
$app->response->respondWithCode("Welcome to bitcart API v2", 200);
30+
});
31+
32+
$app->mount('/info', function() use($app) {
33+
$app->get('/', 'InfoController@index');
34+
$app->get('/addresses', 'InfoController@addresses');
35+
$app->get('/qr', 'InfoController@qr');
36+
$app->get('/bank', 'InfoController@bank');
37+
$app->get('/mobile', 'InfoController@mobile');
38+
$app->get('/tax', 'InfoController@tax');
39+
});
40+
41+
$app->mount('/auth', function() use($app) {
42+
$app->post('/login', 'AuthController@login');
43+
$app->post('/register', 'AuthController@register');
44+
});
45+
46+
$app->mount('/account', function() use($app) {
47+
$app->get('/', 'AccountController@user');
48+
$app->get('/verify/{username}', 'AccountController@verifyUsername');
49+
$app->post('/update', 'AccountController@update');
50+
$app->post('/update/password', 'AccountController@password');
51+
});
52+
53+
$app->mount('/transactions', function() use($app) {
54+
$app->get('/', 'TransactionsController@index');
55+
$app->get('/(\d+)', 'TransactionsController@withLimit');
56+
});
57+
58+
$app->mount('/transaction', function() use($app) {
59+
$app->get('/(\d+)', 'TransactionsController@transaction');
60+
});

App/Views/assets/css/leaf.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.leaf-center-center {
2+
display: flex !important;
3+
align-items: center !important;
4+
justify-content: center !important;
5+
flex-direction: column !important;
6+
height: 90vh !important;
7+
}

0 commit comments

Comments
 (0)