Skip to content

Commit

Permalink
Merge pull request #1 from laravel-appkit/develop
Browse files Browse the repository at this point in the history
Very Basic Locking Mechanisum
  • Loading branch information
darrencoutts118 authored Jan 7, 2021
2 parents 3f41f9e + 4f169ed commit d0ba677
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 149 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/:package_name/docs
url: https://appkit.coutts.io/packages/lockable/docs
about: View the documentation

- name: Community
url: https://appkit.coutts.io/packages/:package_name/community
url: https://appkit.coutts.io/packages/lockable/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
2 changes: 1 addition & 1 deletion .php_cs.cache
Original file line number Diff line number Diff line change
@@ -1 +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,"src\/Facades\/Lockable.php":1969634961,"src\/Lockable.php":3429273821,"src\/Traits\/Lockable.php":3743096533,"src\/LockableServiceProvider.php":1931141247,"tests\/database\/migrations\/2014_10_12_000000_create_users_table.php":2933585291,"tests\/database\/factories\/UserFactory.php":364335595,"tests\/Models\/User.php":1901976356,"tests\/LockableTest.php":2883837912}}
{"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":3885317590,"src\/Facades\/Lockable.php":1969634961,"src\/Lockable.php":3429273821,"src\/Traits\/Lockable.php":3743096533,"src\/LockableServiceProvider.php":1931141247,"tests\/database\/migrations\/2014_10_12_000000_create_users_table.php":2933585291,"tests\/database\/factories\/UserFactory.php":364335595,"tests\/Models\/User.php":1901976356,"tests\/LockableTest.php":2883837912,"tests\/database\/factories\/ArticlesFactory.php":2293051357,"tests\/Models\/Article.php":376444782,"tests\/TestCase.php":1479180223}}
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 `:package_name` will be documented in this file
All notable changes to `lockable` will be documented in this file

## 1.0.0 - 201X-XX-XX

Expand Down
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
# Very short description of the package
# Eloquent 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)
[![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)

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.
Allows a user to acquire a lock on a model, which prevents anyone else from being able to edit it.

## Installation

You can install the package via composer:

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

## 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
// Usage description here
<?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();
```
### 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/:package_name",
"name": "laravel-appkit/lockable",
"description": "",
"keywords": [
"laravel",
"appkit",
":package_name"
"lockable"
],
"homepage": "https://github.com/laravel-appkit/:package_name",
"homepage": "https://github.com/laravel-appkit/lockable",
"license": "MIT",
"type": "library",
"authors": [
Expand All @@ -27,12 +27,12 @@
},
"autoload": {
"psr-4": {
"AppKit\\:package_name_php\\": "src"
"AppKit\\Lockable\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"AppKit\\:package_name_php\\Tests\\": "tests"
"AppKit\\Lockable\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -42,10 +42,10 @@
"extra": {
"laravel": {
"providers": [
"AppKit\\:package_name_php\\:package_name_phpServiceProvider"
"AppKit\\Lockable\\LockableServiceProvider"
],
"aliases": {
":package_name_php": "AppKit\\:package_name_php\\Facades\\:package_name_php"
"Lockable": "AppKit\\Lockable\\Facades\\Lockable"
}
}
}
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

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

Expand Down
21 changes: 0 additions & 21 deletions src/Facades/Blameable.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Package.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/PackageServiceProvider.php

This file was deleted.

Empty file removed src/Traits/.gitkeep
Empty file.
23 changes: 0 additions & 23 deletions tests/ExampleTest.php

This file was deleted.

5 changes: 4 additions & 1 deletion tests/Models/Article.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

namespace AppKit\:package_name_php\Tests\Models;
namespace AppKit\Lockable\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
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

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

use Orchestra\Testbench\TestCase as OrchestraTestCase;
use AppKit\:package_name_php\:package_name_phpServiceProvider;
use AppKit\:package_name_php\Facades\:package_name_php;
use AppKit\Lockable\LockableServiceProvider;
use AppKit\Lockable\Facades\Lockable;

class TestCase extends OrchestraTestCase
{
Expand Down Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
*/
protected function getPackageProviders($app)
{
return [:package_name_phpServiceProvider::class];
return [LockableServiceProvider::class];
}

/**
Expand All @@ -45,7 +45,7 @@ protected function getPackageProviders($app)
protected function getPackageAliases($app)
{
return [
':package_name_php' => :package_name_php::class
'Lockable' => Lockable::class
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/database/factories/ArticlesFactory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
use AppKit\:package_name_php\Tests\Models\Article;
use AppKit\Lockable\Tests\Models\Article;
use Faker\Generator as Faker;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function up()
$table->string('title');
$table->text('body');
$table->timestamps();
$table->lockable();
});
}

Expand Down

0 comments on commit d0ba677

Please sign in to comment.