Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cindreta committed Mar 5, 2022
1 parent 7c660af commit 4240482
Show file tree
Hide file tree
Showing 9 changed files with 576 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto

/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.gitignore export-ignore
.php-cs-fixer.dist export-ignore
phpunit.xml.dist export-ignore
94 changes: 94 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()->in([
__DIR__.'/src',
__DIR__.'/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new Config())->setRules([
'@PSR2' => true,
'@PSR12' => true,
'@PHP71Migration' => true,
'array_syntax' => [
'syntax' => 'short',
],
'blank_line_after_namespace' => true,
'blank_line_before_statement' => true,
'cast_spaces' => true,
'class_definition' => false,
'concat_space' => [
'spacing' => 'none',
],
'ereg_to_preg' => true,
'general_phpdoc_tag_rename' => true,
'is_null' => true,
'line_ending' => true,
'modernize_types_casting' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'php_unit_method_casing' => [
'case' => 'camel_case',
],
'php_unit_test_annotation' => [
'style' => 'prefix',
],
'php_unit_test_case_static_method_calls' => [
'call_type' => 'this',
],
'phpdoc_align' => [
'align' => 'vertical',
'tags' => [
'param',
'return',
'throws',
'type',
'var',
],
],
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_tag_type' => [
'tags' => [
'inheritdoc' => 'inline',
],
],
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => false,
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
])
->setFinder($finder)
->setRiskyAllowed(true);
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.1] - 2022-03-05
### Changed
- initial release
114 changes: 112 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,112 @@
# treblle-lumen
The offical Treblle package for Lumen

<img src="https://d224n10qh3hhwu.cloudfront.net/github/hero-lumen.jpg" alt="Treblle for Lumen" align="center">

# Treblle for Lumen

[![Latest Version](https://img.shields.io/packagist/v/treblle/treblle-lumen)](https://packagist.org/packages/treblle/treblle-lumen)
[![Total Downloads](https://img.shields.io/packagist/dt/treblle/treblle-lumen)](https://packagist.org/packages/treblle/treblle-lumen)
[![MIT Licence](https://img.shields.io/packagist/l/treblle/treblle-lumen)](LICENSE.md)

Treblle makes it super easy to understand what’s going on with your APIs and the apps that use them. Just by adding
Treblle to your API out of the box you get:

* Real-time API monitoring and logging
* Auto-generated API docs with OAS support
* API analytics
* Quality scoring
* One-click testing
* API management on the go
* and more...

## Requirements

* PHP 7.2+
* Lumen 7+

## Dependencies

* [`laravel/lumen`](https://packagist.org/packages/laravel/lumen)
* [`guzzlehttp/guzzle`](https://packagist.org/packages/guzzlehttp/guzzle)
* [`nesbot/carbon`](https://packagist.org/packages/nesbot/carbon)

## Installation

Install Treblle for Lumen via [Composer](http://getcomposer.org/) by running the following command in your console:

```bash
composer require treblle/treblle-lumen
```

## Getting started
Installing Lumen packages is a lot more complicated than Laravel packages and requires a few manual steps. If you want a completely automated process please use Laravel.

### Step 1: Publish config files
The first thing we need to do is publish the Treblle config file and make sure Lumen loads it. To do that we need to copy/paste the package config file like so:

```bash
mkdir -p config
cp vendor/treblle/treblle-lumen/config/treblle.php config/treblle.php
```
Now we can have Lumen load the config file. We do that by adding a new line in `bootstrap/app.php`, under the *Register Config Files* section, like so:

```php
$app->configure('treblle');
```

### Step 2: Register middleware
We need to register the Treblle middleware in Lumen. To do add a new line of code to `bootstrap/app.php`, under the Register Middleware section, like so:
```php
$app->routeMiddleware([
'treblle' => Treblle\Middlewares\TreblleMiddleware::class
]);
```
### Step 3: Configure Treblle
You need an API KEY and PROJECT ID for Treblle to work. You can get those by creating a FREE account on <https://treblle.com> and your first project. You'll get the two keys which you need to add to your .ENV file like so:

```bash
TREBLLE_API_KEY=YOUR_API_KEY
TREBLLE_PROJECT_ID=YOUR_PROJECT_ID
```

## Enable Treblle on your API

Now that we've installed the package we simply need to enable it. Open **routes/web.php** and assign the **treblle** middleware to your API routes like so:

```php
$router->group(['prefix' => 'api', 'middleware' => 'treblle'], function () use ($router) {
$router->get('users', ['uses' => 'UserController@index']);
$router->post('users', ['uses' => 'TestController@store']);
});
```
**You're all set**. Next time someone makes a request to your API you will see it in real-time on your Treblle dashboard
alongside other features like: auto-generated documentation, error tracking, analytics and API quality scoring.

## Configuration options

You can configure Treblle using just .ENV variables:

```shell
TREBLLE_IGNORED_ENV=local,dev,test
```

Define which environments Treblle should NOT LOG at all. By default, Treblle will log all environments except local, dev
and test. If you want to change that you can define your own ignored environments by using a comma separated list, or
allow all environments by leaving the value empty.

### Masked fields

Treblle **masks sensitive information** from both the request and response data as well as the request headers data
**before it even leaves your server**. The following parameters are automatically masked: password, pwd, secret,
password_confirmation, cc, card_number, ccv, ssn, credit_score.

You can customize this list by editing the array configuration file.

## Support

If you have problems of any kind feel free to reach out via <https://treblle.com> or email vedran@treblle.com, and we'll
do our best to help you out.

## License

Copyright 2021, Treblle Limited. Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "treblle/treblle-lumen",
"description": "Stay in tune with your APIs",
"license": "MIT",
"type": "library",
"keywords": [
"api",
"debuging",
"documentation",
"lumen",
"monitoring",
"treblle"
],
"authors": [
{
"name": "Vedran Cindrić",
"email": "vedran@treblle.com",
"homepage": "https://treblle.com/",
"role": "Developer"
}
],
"homepage": "https://treblle.com/",
"require": {
"php": "^7.2.5 || ^8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5.0 || ^7.0",
"illuminate/contracts": "^7.0 || ^8.0 || ^9.0",
"illuminate/http": "^7.0 || ^8.0 || ^9.0",
"illuminate/support": "^7.0 || ^8.0 || ^9.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"orchestra/testbench": "^5.0 || ^6.0 || ^7.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Treblle\\": "src/"
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
34 changes: 34 additions & 0 deletions config/treblle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

return [
/*
* A valid Treblle API key. You can get started for FREE by visiting https://treblle.com/
*/
'api_key' => env('TREBLLE_API_KEY'),

/*
* A valid Treblle project ID. Create your first project on https://treblle.com/
*/
'project_id' => env('TREBLLE_PROJECT_ID'),

/*
* Define which environments should Treblle ignore and not monitor
*/
'ignored_environments' => env('TREBLLE_IGNORED_ENV', 'dev,test'),

/*
* Define which fields should be masked before leaving the server
*/
'masked_fields' => [
'password',
'pwd',
'secret',
'password_confirmation',
'cc',
'card_number',
'ccv',
'ssn',
'credit_score',
'api_key',
],
];
11 changes: 11 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit 4240482

Please sign in to comment.