Skip to content

Commit 968a53c

Browse files
committed
first commit
0 parents  commit 968a53c

40 files changed

+6022
-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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
APP_NAME=Lumen
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
APP_TIMEZONE=UTC
7+
8+
LOG_CHANNEL=stack
9+
LOG_SLACK_WEBHOOK_URL=
10+
11+
DB_CONNECTION=mysql
12+
DB_HOST=127.0.0.1
13+
DB_PORT=3306
14+
DB_DATABASE=homestead
15+
DB_USERNAME=homestead
16+
DB_PASSWORD=secret
17+
18+
CACHE_DRIVER=file
19+
QUEUE_CONNECTION=sync

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
/.idea
3+
Homestead.json
4+
Homestead.yaml
5+
.env
6+
.phpunit.result.cache

.styleci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
php:
2+
preset: laravel
3+
disabled:
4+
- unused_use
5+
js: true
6+
css: true

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Lumen PHP Framework
2+
3+
[![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework)
4+
[![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework)
5+
[![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework)
6+
[![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework)
7+
8+
Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.
9+
10+
## Official Documentation
11+
12+
Documentation for the framework can be found on the [Lumen website](https://lumen.laravel.com/docs).
13+
14+
## Contributing
15+
16+
Thank you for considering contributing to Lumen! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
17+
18+
## Security Vulnerabilities
19+
20+
If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at [email protected]. All security vulnerabilities will be promptly addressed.
21+
22+
## License
23+
24+
The Lumen framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
25+
# lumen-rest-api

app/Console/Commands/.gitkeep

Whitespace-only changes.

app/Console/Kernel.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
//
28+
}
29+
}

app/Events/Event.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Queue\SerializesModels;
6+
7+
abstract class Event
8+
{
9+
use SerializesModels;
10+
}

app/Events/ExampleEvent.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
class ExampleEvent extends Event
6+
{
7+
/**
8+
* Create a new event instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
}

app/Exceptions/Handler.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use http\Exception;
6+
use Illuminate\Auth\Access\AuthorizationException;
7+
use Illuminate\Database\Eloquent\ModelNotFoundException;
8+
use Illuminate\Validation\ValidationException;
9+
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
10+
use Symfony\Component\HttpKernel\Exception\HttpException;
11+
use Throwable;
12+
13+
class Handler extends ExceptionHandler
14+
{
15+
16+
/**
17+
* A list of the exception types that should not be reported.
18+
*
19+
* @var array
20+
*/
21+
protected $dontReport = [
22+
AuthorizationException::class,
23+
HttpException::class,
24+
ModelNotFoundException::class,
25+
ValidationException::class,
26+
];
27+
28+
/**
29+
* Report or log an exception.
30+
*
31+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
32+
*
33+
* @param \Throwable $exception
34+
*
35+
* @return void
36+
*
37+
* @throws \Exception
38+
*/
39+
public function report(Throwable $exception)
40+
{
41+
42+
parent::report($exception);
43+
}
44+
45+
/**
46+
* Render an exception into an HTTP response.
47+
*
48+
* @param \Illuminate\Http\Request $request
49+
* @param \Throwable $exception
50+
*
51+
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
52+
*
53+
* @throws \Throwable
54+
*/
55+
public function render($request, Exception $e)
56+
{
57+
58+
$rendered = parent::render($request, $e);
59+
60+
return response()->json([
61+
'error' => [
62+
'code' => $rendered->getStatusCode(),
63+
'message' => $e->getMessage(),
64+
]
65+
], $rendered->getStatusCode());
66+
}
67+
}

app/Http/Controllers/Controller.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Laravel\Lumen\Routing\Controller as BaseController;
6+
7+
class Controller extends BaseController
8+
{
9+
//
10+
}
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use http\Env\Request;
6+
7+
ini_set('memory_limit', '1GB');
8+
9+
class ExampleController extends Controller
10+
{
11+
12+
private $apiUrl = "https://coronavirus-monitor.p.rapidapi.com/coronavirus/";
13+
private $headerVars = array(
14+
"x-rapidapi-host: coronavirus-monitor.p.rapidapi.com",
15+
"x-rapidapi-key: 9a182b9ddamshef0fdd8891477ebp175fb9jsna8d94bc01b0c"
16+
);
17+
18+
private $validsEndpoints = array('affected', 'cases_by_country', 'usastates');
19+
20+
/**
21+
* Create a new controller instance.
22+
*
23+
* @return void
24+
*/
25+
public function __construct()
26+
{
27+
28+
header('Content-Type: application/json');
29+
}
30+
31+
/**
32+
* @param $type
33+
*
34+
* @return false|string
35+
*/
36+
public function getData($type = 'affected')
37+
{
38+
39+
if (in_array($type, $this->validsEndpoints)) {
40+
41+
$result = $this->connectApi($type);
42+
43+
if (!empty($result['error'])) {
44+
echo json_encode($result);
45+
}
46+
47+
echo $result;
48+
49+
return;
50+
}
51+
52+
return response(array('error' => true, 'message' => 'not found'), 404);
53+
54+
}
55+
56+
57+
/**
58+
* @param $type
59+
*
60+
* @return array
61+
*/
62+
public function connectApi($type)
63+
{
64+
65+
$curl = curl_init();
66+
67+
curl_setopt_array($curl, array(
68+
CURLOPT_URL => $this->apiUrl . $type . '.php',
69+
CURLOPT_RETURNTRANSFER => true,
70+
CURLOPT_FOLLOWLOCATION => true,
71+
CURLOPT_ENCODING => "",
72+
CURLOPT_MAXREDIRS => 10,
73+
CURLOPT_TIMEOUT => 30,
74+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
75+
CURLOPT_CUSTOMREQUEST => "GET",
76+
CURLOPT_HTTPHEADER => $this->headerVars,
77+
));
78+
79+
$response = curl_exec($curl);
80+
$err = curl_error($curl);
81+
82+
curl_close($curl);
83+
84+
if ($err) {
85+
return array('error' => true, 'message' => "cURL Error #:" . $err);
86+
}
87+
88+
return $response;
89+
90+
}
91+
}

app/Http/Middleware/Authenticate.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Contracts\Auth\Factory as Auth;
7+
8+
class Authenticate
9+
{
10+
/**
11+
* The authentication guard factory instance.
12+
*
13+
* @var \Illuminate\Contracts\Auth\Factory
14+
*/
15+
protected $auth;
16+
17+
/**
18+
* Create a new middleware instance.
19+
*
20+
* @param \Illuminate\Contracts\Auth\Factory $auth
21+
* @return void
22+
*/
23+
public function __construct(Auth $auth)
24+
{
25+
$this->auth = $auth;
26+
}
27+
28+
/**
29+
* Handle an incoming request.
30+
*
31+
* @param \Illuminate\Http\Request $request
32+
* @param \Closure $next
33+
* @param string|null $guard
34+
* @return mixed
35+
*/
36+
public function handle($request, Closure $next, $guard = null)
37+
{
38+
if ($this->auth->guard($guard)->guest()) {
39+
return response('Unauthorized.', 401);
40+
}
41+
42+
return $next($request);
43+
}
44+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
7+
class ExampleMiddleware
8+
{
9+
/**
10+
* Handle an incoming request.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
14+
* @return mixed
15+
*/
16+
public function handle($request, Closure $next)
17+
{
18+
return $next($request);
19+
}
20+
}

app/Jobs/ExampleJob.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
class ExampleJob extends Job
6+
{
7+
/**
8+
* Create a new job instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Execute the job.
19+
*
20+
* @return void
21+
*/
22+
public function handle()
23+
{
24+
//
25+
}
26+
}

0 commit comments

Comments
 (0)