From 29bc4f526caf450129cae631fa9291d7978c1565 Mon Sep 17 00:00:00 2001 From: Daniel Janiga Date: Sat, 6 Feb 2021 13:42:58 +0100 Subject: [PATCH] initial commit for snowflake, added snowflake singleton and HasSnowflake primary trait --- .github/FUNDING.yml | 2 +- .github/ISSUE_TEMPLATE/config.yml | 6 +- .github/SECURITY.md | 2 +- CHANGELOG.md | 2 +- LICENSE.md | 2 +- README.md | 35 ++----- composer.json | 29 +++--- config/skeleton.php | 5 - config/snowflake.php | 33 +++++++ configure-skeleton.sh | 93 ------------------- database/factories/ModelFactory.php | 19 ---- .../migrations/create_skeleton_table.php.stub | 19 ---- phpunit.xml.dist | 2 +- resources/views/.gitkeep | 0 src/Commands/SkeletonCommand.php | 17 ---- src/LaravelSnowflakeFacade.php | 16 ++++ src/LaravelSnowflakeServiceProvider.php | 40 ++++++++ src/Skeleton.php | 7 -- src/SkeletonFacade.php | 16 ---- src/SkeletonServiceProvider.php | 25 ----- src/Traits/HasSnowflakePrimary.php | 19 ++++ tests/ExampleTest.php | 2 +- tests/TestCase.php | 10 +- 23 files changed, 147 insertions(+), 254 deletions(-) delete mode 100644 config/skeleton.php create mode 100644 config/snowflake.php delete mode 100755 configure-skeleton.sh delete mode 100644 database/factories/ModelFactory.php delete mode 100644 database/migrations/create_skeleton_table.php.stub delete mode 100644 resources/views/.gitkeep delete mode 100644 src/Commands/SkeletonCommand.php create mode 100644 src/LaravelSnowflakeFacade.php create mode 100644 src/LaravelSnowflakeServiceProvider.php delete mode 100755 src/Skeleton.php delete mode 100644 src/SkeletonFacade.php delete mode 100644 src/SkeletonServiceProvider.php create mode 100644 src/Traits/HasSnowflakePrimary.php diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index c68765b..a426078 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -github: :vendor_name +github: pixwell-dev diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index aeef948..0bd759e 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,11 +1,11 @@ blank_issues_enabled: false contact_links: - name: Ask a question - url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a + url: https://github.com/pixwell-dev/laravel-snowflake/discussions/new?category=q-a about: Ask the community for help - name: Request a feature - url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas + url: https://github.com/pixwell-dev/laravel-snowflake/discussions/new?category=ideas about: Share ideas for new features - name: Report a bug - url: https://github.com/:vendor_name/:package_name/issues/new + url: https://github.com/pixwell-dev/laravel-snowflake/issues/new about: Report a reproducable bug diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 3d41ffb..235285f 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -1,3 +1,3 @@ # Security Policy -If you discover any security related issues, please email :author_email instead of using the issue tracker. +If you discover any security related issues, please email daniel.janiga@pixwell.sk instead of using the issue tracker. diff --git a/CHANGELOG.md b/CHANGELOG.md index 767365d..7aa680a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -All notable changes to `:package_name` will be documented in this file. +All notable changes to `laravel-snowflake` will be documented in this file. ## 1.0.0 - 202X-XX-XX diff --git a/LICENSE.md b/LICENSE.md index d76fbb6..9e7d9aa 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) :vendor_name <:author_email> +Copyright (c) pixwell-dev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f1f6429..c4a3424 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -# :package_description +# laravel-snowflake -[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_name/:package_name.svg?style=flat-square)](https://packagist.org/packages/:vendor_name/:package_name) -[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/:vendor_name/:package_name/run-tests?label=tests)](https://github.com/:vendor_name/:package_name/actions?query=workflow%3ATests+branch%3Amaster) -[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_name/:package_name.svg?style=flat-square)](https://packagist.org/packages/:vendor_name/:package_name) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/pixwell-dev/laravel-snowflake.svg?style=flat-square)](https://packagist.org/packages/pixwell-dev/laravel-snowflake) +[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/pixwell-dev/laravel-snowflake/run-tests?label=tests)](https://github.com/pixwell-dev/laravel-snowflake/actions?query=workflow%3ATests+branch%3Amaster) +[![Total Downloads](https://img.shields.io/packagist/dt/pixwell-dev/laravel-snowflake.svg?style=flat-square)](https://packagist.org/packages/pixwell-dev/laravel-snowflake) -**Note:** Run `./configure-skeleton` to get started, or manually replace ```:author_name``` ```:author_username``` ```:author_email``` ```:vendor_name``` ```:package_name``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](.github/CONTRIBUTING.md), [LICENSE.md](LICENSE.md) and [composer.json](composer.json) files, then delete this line. You can also run `configure-skeleton.sh` to do this automatically. This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. ## Support us -[](https://spatie.be/github-ad-click/package-skeleton-laravel) +[](https://spatie.be/github-ad-click/package-laravel-snowflake-laravel) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). @@ -21,33 +20,19 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh You can install the package via composer: ```bash -composer require :vendor_name/:package_name -``` - -You can publish and run the migrations with: - -```bash -php artisan vendor:publish --provider="Spatie\Skeleton\SkeletonServiceProvider" --tag=":package_name-migrations" -php artisan migrate +composer require pixwell-dev/laravel-snowflake ``` You can publish the config file with: ```bash -php artisan vendor:publish --provider="Spatie\Skeleton\SkeletonServiceProvider" --tag=":package_name-config" -``` - -This is the contents of the published config file: - -```php -return [ -]; +php artisan vendor:publish --provider="PixwellDev\LaravelSnowflake\LaravelSnowflakeServiceProvider" --tag="laravel-snowflake-config" ``` ## Usage ```php -$skeleton = new Spatie\Skeleton(); -echo $skeleton->echoPhrase('Hello, Spatie!'); +$laravel-snowflake = new PixwellDev\LaravelSnowflake(); +echo $laravel-snowflake->echoPhrase('Hello, Pixwell-dev!'); ``` ## Testing @@ -70,7 +55,7 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits -- [:author_name](https://github.com/:author_username) +- [Daniel Janiga](https://github.com/danieljaniga) - [All Contributors](../../contributors) ## License diff --git a/composer.json b/composer.json index 3917d41..b50b418 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,24 @@ { - "name": ":vendor_name/:package_name", - "description": ":package_description", + "name": "pixwell-dev/laravel-snowflake", + "description": "laravel-snowflake", "keywords": [ - ":vendor_name", - ":package_name" + "pixwell-dev", + "laravel-snowflake" ], - "homepage": "https://github.com/:vendor_name/:package_name", + "homepage": "https://github.com/pixwell-dev/laravel-snowflake", "license": "MIT", "authors": [ { - "name": ":author_name", - "email": ":author_email", + "name": "Daniel Janiga", + "email": "daniel.janiga@pixwell.sk", "role": "Developer" } ], "require": { "php": "^7.4|^8.0", - "spatie/laravel-package-tools": "^1.1", - "illuminate/contracts": "^8.0" + "godruoyi/php-snowflake": "^1.0", + "illuminate/contracts": "^8.0", + "spatie/laravel-package-tools": "^1.1" }, "require-dev": { "orchestra/testbench": "^6.0", @@ -27,13 +28,13 @@ }, "autoload": { "psr-4": { - "Spatie\\Skeleton\\": "src", - "Spatie\\Skeleton\\Database\\Factories\\": "database/factories" + "PixwellDev\\LaravelSnowflake\\": "src", + "PixwellDev\\LaravelSnowflake\\Database\\Factories\\": "database/factories" } }, "autoload-dev": { "psr-4": { - "Spatie\\Skeleton\\Tests\\": "tests" + "PixwellDev\\LaravelSnowflake\\Tests\\": "tests" } }, "scripts": { @@ -47,10 +48,10 @@ "extra": { "laravel": { "providers": [ - "Spatie\\Skeleton\\SkeletonServiceProvider" + "PixwellDev\\LaravelSnowflake\\LaravelSnowflakeServiceProvider" ], "aliases": { - "Skeleton": "Spatie\\Skeleton\\SkeletonFacade" + "LaravelSnowflake": "PixwellDev\\LaravelSnowflake\\LaravelSnowflakeFacade" } } }, diff --git a/config/skeleton.php b/config/skeleton.php deleted file mode 100644 index ca5d8ed..0000000 --- a/config/skeleton.php +++ /dev/null @@ -1,5 +0,0 @@ - env('SNOWFLAKE_EPOCH', '2021-02-01 00:00:00'), + + /* + |-------------------------------------------------------------------------- + | Snowflake Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure the log settings for snowflake. + | If you are using multiple servers, please assign unique + | ID(1-31) for Snowflake. + | + | Available Settings: 1-31 + | + */ + 'worker_id' => env('SNOWFLAKE_WORKER_ID', 1), + + 'datacenter_id' => env('SNOWFLAKE_DATACENTER_ID', 1), +]; \ No newline at end of file diff --git a/configure-skeleton.sh b/configure-skeleton.sh deleted file mode 100755 index 0426c0a..0000000 --- a/configure-skeleton.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash -# 'return' when run as "source