Skip to content

Commit a10f76d

Browse files
authored
feat: algos (#1)
1 parent 11fc7e5 commit a10f76d

40 files changed

+675
-574
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github: :vendor_name
1+
github: Foxws

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=q-a
4+
url: https://github.com/foxws/laravel-algos/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=ideas
7+
url: https://github.com/foxws/laravel-algos/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a security issue
10-
url: https://github.com/:vendor_slug/:package_name/security/policy
10+
url: https://github.com/foxws/laravel-algos/security/policy
1111
about: Learn how to notify us for sensitive bugs

.github/workflows/phpstan.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: PHPStan
33
on:
44
push:
55
paths:
6-
- '**.php'
7-
- 'phpstan.neon.dist'
8-
- '.github/workflows/phpstan.yml'
6+
- "**.php"
7+
- "phpstan.neon.dist"
8+
- ".github/workflows/phpstan.yml"
99

1010
jobs:
1111
phpstan:
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: '8.2'
21+
php-version: "8.2"
2222
coverage: none
2323

2424
- name: Install composer dependencies

.github/workflows/run-tests.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: run-tests
33
on:
44
push:
55
paths:
6-
- '**.php'
7-
- '.github/workflows/run-tests.yml'
8-
- 'phpunit.xml.dist'
9-
- 'composer.json'
10-
- 'composer.lock'
6+
- "**.php"
7+
- ".github/workflows/run-tests.yml"
8+
- "phpunit.xml.dist"
9+
- "composer.json"
10+
- "composer.lock"
1111

1212
jobs:
1313
test:
@@ -16,17 +16,13 @@ jobs:
1616
strategy:
1717
fail-fast: true
1818
matrix:
19-
os: [ubuntu-latest, windows-latest]
19+
os: [ubuntu-latest]
2020
php: [8.3, 8.2]
21-
laravel: [11.*, 10.*]
2221
stability: [prefer-lowest, prefer-stable]
2322
include:
2423
- laravel: 11.*
2524
testbench: 9.*
26-
carbon: ^2.63
27-
- laravel: 10.*
28-
testbench: 8.*
29-
carbon: ^2.63
25+
carbon: ^3.1.1
3026

3127
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
3228

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Changelog
22

3-
All notable changes to `:package_name` will be documented in this file.
3+
All notable changes to `laravel-algos` will be documented in this file.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <author@domain.com>
3+
Copyright (c) Foxws <francoism90@users.noreply.github.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,89 @@
1-
# :package_description
1+
# Laravel Algos
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
7-
<!--delete-->
8-
---
9-
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/foxws/laravel-algos.svg?style=flat-square)](https://packagist.org/packages/foxws/laravel-algos)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/foxws/laravel-algos/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/foxws/laravel-algos/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/foxws/laravel-algos/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/foxws/laravel-algos/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/foxws/laravel-algos.svg?style=flat-square)](https://packagist.org/packages/foxws/laravel-algos)
107

11-
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
12-
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
13-
3. Have fun creating your package.
14-
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
15-
---
16-
<!--/delete-->
17-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
18-
19-
## Support us
20-
21-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
22-
23-
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).
24-
25-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
8+
This package can be used to create algorithms (algos) for your Laravel application.
269

2710
## Installation
2811

2912
You can install the package via composer:
3013

3114
```bash
32-
composer require :vendor_slug/:package_slug
33-
```
34-
35-
You can publish and run the migrations with:
36-
37-
```bash
38-
php artisan vendor:publish --tag=":package_slug-migrations"
39-
php artisan migrate
15+
composer require foxws/laravel-algos
4016
```
4117

4218
You can publish the config file with:
4319

4420
```bash
45-
php artisan vendor:publish --tag=":package_slug-config"
21+
php artisan vendor:publish --tag="algos-config"
4622
```
4723

48-
This is the contents of the published config file:
49-
50-
```php
51-
return [
52-
];
53-
```
24+
## Usage
5425

55-
Optionally, you can publish the views using
26+
Generate an `Algo` class:
5627

57-
```bash
58-
php artisan vendor:publish --tag=":package_slug-views"
28+
```php
29+
<?php
30+
31+
use Foxws\Algos\Algos\Algo;
32+
use Foxws\Algos\Algos\Result;
33+
use Foxws\Algos\Tests\Models\Post;
34+
use Foxws\Algos\Tests\Models\User;
35+
use Illuminate\Support\Collection;
36+
use Illuminate\Support\Str;
37+
38+
class GenerateUserFeed extends Algo
39+
{
40+
protected ?User $user = null;
41+
42+
public function handle(): Result
43+
{
44+
$hash = cache()->set(
45+
$this->generateUniqueId(),
46+
['ids' => (array) $this->getCollection()],
47+
now()->addMinutes(10),
48+
);
49+
50+
return $this
51+
->success('Feed generated successfully')
52+
->with('hash', $hash);
53+
}
54+
55+
public function model(User $user): self
56+
{
57+
$this->user = $user;
58+
59+
return $this;
60+
}
61+
62+
protected function getCollection(): Collection
63+
{
64+
return Post::query()
65+
->select('id')
66+
->where('user_id', $this->user->getKey())
67+
->inRandomOrder()
68+
->take(5)
69+
->get();
70+
}
71+
72+
protected function generateUniqueId(): string
73+
{
74+
return Str::ulid();
75+
}
76+
}
5977
```
6078

61-
## Usage
79+
To run the algorithm:
6280

6381
```php
64-
$variable = new VendorName\Skeleton();
65-
echo $variable->echoPhrase('Hello, VendorName!');
82+
$algo = GenerateUserFeed::make()->model($this->user)->run();
83+
84+
// $algo->status; // success, failed, skipped
85+
// $algo->message; // reason
86+
// $algo->meta['foo'] // array of metadata
6687
```
6788

6889
## Testing
@@ -85,7 +106,7 @@ Please review [our security policy](../../security/policy) on how to report secu
85106

86107
## Credits
87108

88-
- [:author_name](https://github.com/:author_username)
109+
- [francoism90](https://github.com/foxws)
89110
- [All Contributors](../../contributors)
90111

91112
## License

composer.json

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
{
2-
"name": ":vendor_slug/:package_slug",
3-
"description": ":package_description",
2+
"name": "foxws/laravel-algos",
3+
"description": "This is my package laravel-algos",
44
"keywords": [
5-
":vendor_name",
5+
"foxws",
66
"laravel",
7-
":package_slug"
7+
"laravel-algos",
8+
"algos",
9+
"algorithms"
810
],
9-
"homepage": "https://github.com/:vendor_slug/:package_slug",
11+
"homepage": "https://github.com/foxws/laravel-algos",
1012
"license": "MIT",
1113
"authors": [
1214
{
13-
"name": ":author_name",
14-
"email": "author@domain.com",
15+
"name": "francoism90",
16+
"email": "francoism90@users.noreply.github.com",
1517
"role": "Developer"
1618
}
1719
],
1820
"require": {
1921
"php": "^8.2",
20-
"spatie/laravel-package-tools": "^1.16",
21-
"illuminate/contracts": "^10.0||^11.0"
22+
"illuminate/cache": "^10.0|^11.0",
23+
"illuminate/console": "^10.0|^11.0",
24+
"illuminate/container": "^10.0|^11.0",
25+
"illuminate/contracts": "^10.0||^11.0",
26+
"illuminate/support": "^10.0|^11.0",
27+
"nesbot/carbon": "^2.63|^3.0",
28+
"spatie/laravel-package-tools": "^1.16"
2229
},
2330
"require-dev": {
2431
"laravel/pint": "^1.14",
25-
"nunomaduro/collision": "^8.1.1||^7.10.0",
2632
"larastan/larastan": "^2.9",
33+
"nunomaduro/collision": "^8.1.1||^7.10.0",
2734
"orchestra/testbench": "^9.0.0||^8.22.0",
2835
"pestphp/pest": "^2.34",
2936
"pestphp/pest-plugin-arch": "^2.7",
@@ -35,19 +42,19 @@
3542
},
3643
"autoload": {
3744
"psr-4": {
38-
"VendorName\\Skeleton\\": "src/",
39-
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
45+
"Foxws\\Algos\\": "src/"
4046
}
4147
},
4248
"autoload-dev": {
4349
"psr-4": {
44-
"VendorName\\Skeleton\\Tests\\": "tests/",
50+
"Foxws\\Algos\\Tests\\": "tests/src/",
51+
"Foxws\\Algos\\Tests\\Database\\Factories\\": "tests/database/factories/",
4552
"Workbench\\App\\": "workbench/app/"
4653
}
4754
},
4855
"scripts": {
4956
"post-autoload-dump": "@composer run prepare",
50-
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
57+
"clear": "@php vendor/bin/testbench package:purge-laravel-algos --ansi",
5158
"prepare": "@php vendor/bin/testbench package:discover --ansi",
5259
"build": [
5360
"@composer run prepare",
@@ -73,10 +80,10 @@
7380
"extra": {
7481
"laravel": {
7582
"providers": [
76-
"VendorName\\Skeleton\\SkeletonServiceProvider"
83+
"Foxws\\Algos\\AlgosServiceProvider"
7784
],
7885
"aliases": {
79-
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
86+
"Algos": "Foxws\\Algos\\Facades\\Algos"
8087
}
8188
}
8289
},

config/algos.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
5+
];

config/skeleton.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)