Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/laravel-appkit/lockable int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
darrencoutts118 committed Jan 7, 2021
2 parents 94e0125 + fde6e2e commit f4bf09c
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
blank_issues_enabled: false
contact_links:
- name: Documentation
url: https://appkit.coutts.io/packages/lockable/docs
url: https://appkit.coutts.io/packages/:package_name/docs
about: View the documentation

- name: Community
url: https://appkit.coutts.io/packages/lockable/community
url: https://appkit.coutts.io/packages/:package_name/community
about: Ask the community for help
4 changes: 2 additions & 2 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check & Fix Styling
name: Check & fix styling

on: [push]

Expand All @@ -20,4 +20,4 @@ jobs:
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
commit_message: Fix styling
1 change: 1 addition & 0 deletions .php_cs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"7.4.13","version":"2.17.3","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["const","method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true},"hashes":{"tests\/database\/migrations\/2021_01_01_000000_create_articles_table.php":1906224168}}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

All notable changes to `lockable` will be documented in this file
All notable changes to `:package_name` will be documented in this file

## 1.0.0 - 201X-XX-XX

Expand Down
54 changes: 9 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,27 @@
# Eloquent Lockable
# Very short description of the package

[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable)
[![Build Status](https://img.shields.io/github/workflow/status/laravel-appkit/lockable/Automated%20Tests?style=flat-square)](https://github.com/laravel-appkit/lockable/actions?query=workflow%3A%22Automated+Tests%22)
[![Quality Score](https://img.shields.io/github/workflow/status/laravel-appkit/lockable/Check%20&%20fix%20styling?label=code%20quality&style=flat-square)](https://github.com/laravel-appkit/lockable/actions?query=workflow%3A%22Check+%26+fix+styling%22)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable)
[![Licence](https://img.shields.io/packagist/l/laravel-appkit/lockable.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/lockable)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name)
[![Build Status](https://img.shields.io/github/workflow/status/laravel-appkit/:package_name/Automated%20Tests?style=flat-square)](https://github.com/laravel-appkit/:package_name/actions?query=workflow%3A%22Automated+Tests%22)
[![Quality Score](https://img.shields.io/github/workflow/status/laravel-appkit/:package_name/Check%20&%20fix%20styling?label=code%20quality&style=flat-square)](https://github.com/laravel-appkit/:package_name/actions?query=workflow%3A%22Check+%26+fix+styling%22)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name)
[![Licence](https://img.shields.io/packagist/l/laravel-appkit/:package_name.svg?style=flat-square)](https://packagist.org/packages/laravel-appkit/:package_name)

Allows a user to acquire a lock on a model, which prevents anyone else from being able to edit it.
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

## Installation

You can install the package via composer:

```bash
composer require laravel-appkit/lockable
composer require laravel-appkit/:package_name
```

## Usage

Add the `AppKit\Lockable\Traits\Lockable` trait to the model you want to set locks on

Add a `locked_by` integer column to the corresponding table. This can also be done using the `lockable` method on the migration.

``` php
<?php

namespace App\Models;

use AppKit\Lockable\Traits\Lockable;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
use Lockable;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'body'
];
}
```

### Acquiring Locks
To acquire a lock on a model, call the `acquireLock` method on it.

```php
$article->acquireLock();
// Usage description here
```
### Releasing Locks
To release the existing lock on a model, call the `releaseLock` method on it.

```php
$article->releaseLock();
```
### Testing

``` bash
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "laravel-appkit/lockable",
"name": "laravel-appkit/:package_name",
"description": "",
"keywords": [
"laravel",
"appkit",
"lockable"
":package_name"
],
"homepage": "https://github.com/laravel-appkit/lockable",
"homepage": "https://github.com/laravel-appkit/:package_name",
"license": "MIT",
"type": "library",
"authors": [
Expand All @@ -27,12 +27,12 @@
},
"autoload": {
"psr-4": {
"AppKit\\Lockable\\": "src"
"AppKit\\:package_name_php\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"AppKit\\Lockable\\Tests\\": "tests"
"AppKit\\:package_name_php\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -42,10 +42,10 @@
"extra": {
"laravel": {
"providers": [
"AppKit\\Lockable\\LockableServiceProvider"
"AppKit\\:package_name_php\\:package_name_phpServiceProvider"
],
"aliases": {
"Lockable": "AppKit\\Lockable\\Facades\\Lockable"
":package_name_php": "AppKit\\:package_name_php\\Facades\\:package_name_php"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* lockable configuration
* :package_name configuration
*/
return [

Expand Down
1 change: 1 addition & 0 deletions routes/package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
82 changes: 82 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

git_name=`git config user.name`;
git_email=`git config user.email`;

read -p "Author name ($git_name): " author_name
author_name=${author_name:-$git_name}

read -p "Author email ($git_email): " author_email
author_email=${author_email:-$git_email}

username_guess=${author_name//[[:blank:]]/}
read -p "Author username ($username_guess): " author_username
author_username=${author_username:-$username_guess}

current_directory=`pwd`
current_directory=`basename $current_directory`
read -p "Package name ($current_directory): " package_name
package_name=${package_name:-$current_directory}
package_name_php=$(echo $package_name | sed -E 's/[^a-z]+([a-z])/\U\1/gi;s/^([A-Z])/\l\1/')

read -p "Package description: " package_description

echo
echo -e "Author: $author_name ($author_username, $author_email)"
echo -e "Package: $package_name <${package_name_php^}>"

echo
echo "This script will replace the above values in all files in the project directory and reset the git repository."
read -p "Are you sure you wish to continue? (n/y) " -n 1 -r

echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi

echo

echo "Scaffolding package"

find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:author_name/$author_name/g" {} \;
find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:author_username/$author_username/g" {} \;
find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:author_email/$author_email/g" {} \;
find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:package_name_php/${package_name_php^}/g" {} \;
find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:package_name/$package_name/g" {} \;
find . -type f -not -path "./.git/*" -not -path "./vendor/*" -not -path "./setup.sh" -exec sed -i -e "s/:package_description/$package_description/g" {} \;

sed -i -e "/^\*\*Note:\*\* Replace/d" README.md

echo "Renaming files"

mv "./routes/package.php" "./routes/$package_name_php.php"
mv "./src/Package.php" "./src/${package_name_php^}.php"
mv "./src/PackageFacade.php" "./src/${package_name_php^}Facade.php"
mv "./src/PackageServiceProvider.php" "./src/${package_name_php^}ServiceProvider.php"

if [[ -d "vendor" ]]
then
echo "Composer dependencies already installed. Dumping autoload"
composer dump-autoload
else
echo "Composer dependencies not installed. Installing them"
composer install
fi

if [ "$current_directory" != "package-starter" ]
then
rm -- "$0"

git add .
git commit -m ":sparkles: Configure Package";
git pull
git push

echo "Replaced all values and commited, self destructing in 3... 2... 1..."
else
echo "Replaced all values"
fi

echo
printf "\033[0;32mBuild something awesome!"
21 changes: 21 additions & 0 deletions src/Facades/Blameable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace AppKit\:package_name_php\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @see \AppKit\:package_name_php\:package_name_php
*/
class :package_name_php extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return ':package_name';
}
}
15 changes: 15 additions & 0 deletions src/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace AppKit\:package_name_php;

class :package_name_php
{
private $app;

public function __construct()
{
$this->app = app();
}

// Build your next great package.
}
60 changes: 60 additions & 0 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace AppKit\:package_name_php;

use Illuminate\Support\ServiceProvider;

class :package_name_phpServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
/*
* Optional methods to load your package assets
*/
// $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', ':package_name');
// $this->loadViewsFrom(__DIR__ . '/../resources/views', ':package_name');
// $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
// $this->loadRoutesFrom(__DIR__ . '/../routes/:package_name.php');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../config/config.php' => config_path(':package_name.php'),
], 'config');

// Publishing the views.
/*$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/:package_name'),
], 'views');*/

// Publishing assets.
/*$this->publishes([
__DIR__ . '/../resources/assets' => public_path('vendor/:package_name'),
], 'assets');*/

// Publishing the translation files.
/*$this->publishes([
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/:package_name'),
], 'lang');*/

// Registering package commands.
// $this->commands([]);
}
}

/**
* Register the application services.
*/
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', ':package_name');

// Register the main class to use with the facade
$this->app->singleton(':package_name', function () {
return new :package_name_php();
});
}
}
23 changes: 23 additions & 0 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace AppKit\:package_name_php\Tests;

use AppKit\:package_name_php\Tests\Models\Article;
class ExampleTest extends TestCase
{
/** @test */
public function trueIsTrue()
{
$this->assertTrue(true);
}

/** @test */
public function artcilesCanBeLoaded()
{
// create 5 articles
factory(Article::class, 5)->create();

// check the database for 5 articles
$this->assertEquals(5, Article::count());
}
}
5 changes: 1 addition & 4 deletions tests/Models/Article.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

namespace AppKit\Lockable\Tests\Models;
namespace AppKit\:package_name_php\Tests\Models;

use AppKit\Lockable\Traits\Lockable;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
use Lockable;

/**
* The attributes that are mass assignable.
*
Expand Down
Loading

0 comments on commit f4bf09c

Please sign in to comment.