Skip to content

Commit

Permalink
Merge pull request #8 from cslant/feature/First-generate-api-package-#1
Browse files Browse the repository at this point in the history
Feature/first generate api package #1
  • Loading branch information
mytruong-z authored Jul 7, 2024
2 parents 36da68f + b949e43 commit d92aba3
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 20 deletions.
File renamed without changes.
47 changes: 27 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
/vendor/
node_modules/
npm-debug.log
yarn-error.log

# Laravel 4 specific
bootstrap/compiled.php
app/storage/

# Laravel 5 & Lumen specific
public/storage
public/hot
/vendor
composer.lock
composer.phar
.DS_Store
/node_modules
/public/storage
/storage/*.key
Thumbs.db
/bower_components

# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot

storage/*.key
.env
.idea/
Homestead.yaml
.env.backup
.idea
.vscode

.vagrant
Homestead.json
/.vagrant
Homestead.yaml
npm-debug.log

.phpunit.cache
.phpunit.result.cache
/storage/.license
/storage/fonts
/storage/installing
/storage/installed
/log
build
package-lock.json
yarn.lock
/.sass-cache
42 changes: 42 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
build:
nodes:
analysis:
project_setup:
override: true
tests:
override: [ php-scrutinizer-run ]
environment:
php:
version: 8.0

checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

tools:
php_analyzer: true
php_code_coverage: true
php_code_sniffer:
config:
standard: PSR4
filter:
paths: [ 'src' ]
php_loc:
enabled: true
excluded_dirs: [ vendor ]
php_cpd:
enabled: true
excluded_dirs: [ vendor ]
4 changes: 4 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preset: laravel

disabled:
- not_operator_with_successor_space
Empty file added common/helpers.php
Empty file.
70 changes: 70 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "cslant/blog-api-package",
"description": "Send notification from Gitlab and Github events to Telegram",
"keywords": [
"cslant",
"laravel",
"cslant-blog-api-package",
"cslant-blog-api",
"cslant-blog",
"cslant-api",
"cslant-package",
"blog-api-package"
],
"homepage": "https://github.com/cslant/blog-api-package",
"license": "MIT",
"authors": [
{
"name": "Tan Nguyen",
"email": "tannp27@gmail.com",
"homepage": "https://tanhongit.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"CSlant\\BlogApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CSlant\\BlogApi\\Tests\\": "tests/"
}
},
"require": {
"php": "^8.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.0",
"nunomaduro/collision": "^7.10",
"nunomaduro/larastan": "^2.9",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3"
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"support": {
"issues": "https://github.com/cslant/blog-api-package/issues"
},
"extra": {
"laravel": {
"providers": [
"CSlant\\BlogApi\\Providers\\BlogApiServiceProvider"
]
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
10 changes: 10 additions & 0 deletions config/blog-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$routePrefix = env('BLOG_API_ROUTE_PREFIX', 'api');

return [
'defaults' => [
/* Set route prefix for the blog API */
'route_prefix' => $routePrefix,
],
];
5 changes: 5 additions & 0 deletions lang/en/blog-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'message' => 'Hello from the blog API!',
];
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
- message: '#Parameter \#1 \$prefix of static method Illuminate\\Support\\Facades\\Route::prefix\(\) expects string, mixed given\.#'
path: routes/blog-api.php

- message: '#Part \$routePrefix \(mixed\) of encapsed string cannot be cast to string\.#'
path: routes/blog-api.php
11 changes: 11 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- phpstan-baseline.neon

parameters:
level: 9
paths:
- src
- routes
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
20 changes: 20 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="CSlant Blog API Package">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
24 changes: 24 additions & 0 deletions routes/blog-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Blog API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register bot routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Enjoy building your API!
|
*/

$routePrefix = config('blog-api.defaults.route_prefix');

Route::prefix($routePrefix)->name("$routePrefix.")->group(function () {
Route::get('/hello', function () {
return response()->json([
'message' => 'Hello from the blog API!',
]);
});
});
8 changes: 8 additions & 0 deletions src/Models/Traits/IsIncrementing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CSlant\BlogApi\Models\Traits;

trait IsIncrementing
{
public $incrementing = true;
}
73 changes: 73 additions & 0 deletions src/Providers/BlogApiServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace CSlant\BlogApi\Providers;

use Illuminate\Support\ServiceProvider;

class BlogApiServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot(): void
{
$routePath = __DIR__.'/../../routes/blog-api.php';
if (file_exists($routePath)) {
$this->loadRoutesFrom($routePath);
}

$this->loadTranslationsFrom(__DIR__.'/../../lang', 'blog-api');

$this->registerCommands();

$this->registerAssetPublishing();
}

/**
* Register services.
*
* @return void
*/
public function register(): void
{
$configPath = __DIR__.'/../../config/blog-api.php';
$this->mergeConfigFrom($configPath, 'blog-api');
}

/**
* Get the services provided by the provider.
*
* @return array<string>|null
*/
public function provides(): ?array
{
return ['blog-api'];
}

/**
* @return void
*/
protected function registerCommands(): void
{
$this->commands([
//
]);
}

/**
* @return void
*/
protected function registerAssetPublishing(): void
{
$configPath = __DIR__.'/../../config/blog-api.php';
$this->publishes([
$configPath => config_path('blog-api.php'),
], 'config');

$this->publishes([
__DIR__.'/../../lang' => resource_path('lang/packages/blog-api'),
], 'lang');
}
}
7 changes: 7 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

/*
|--------------------------------------------------------------------------
| Integration
|--------------------------------------------------------------------------
*/

0 comments on commit d92aba3

Please sign in to comment.