Package Data | |
---|---|
Maintainer Username: | bradcornford |
Maintainer Contact: | me@bradleycornford.co.uk (Bradley Cornford) |
Package Create Date: | 2014-10-16 |
Package Last Update: | 2020-01-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:02:58 |
Package Statistics | |
---|---|
Total Downloads: | 586 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Think of Logical as an easy way to execute logical statements over a none persisted results set with Laravel, providing a way to reduce a results set against a logical sentence. These include:
Logical::setLogicalStatementInstance
Logical::getLogicalStatementInstance
Logical::setInput
Logical::getInput
Logical::setLogic
Logical::getLogic
Logical::execute
Logical::getResults
Logical::reset
Begin by installing this package through Composer. Edit your project's composer.json
file to require cornford/logical
.
"require": {
"cornford/logical": "2.*"
}
Next, update Composer from the Terminal:
composer update
Once this operation completes, the next step is to add the service provider. Open app/config/app.php
, and add a new item to the providers array.
'Cornford\Logical\Providers\LogicalServiceProvider',
The final step is to introduce the facade. Open app/config/app.php
, and add a new item to the aliases array.
'Logical' => 'Cornford\Logical\Facades\Logical',
That's it! You're all set to go.
It's really as simple as using the Logical class in any Controller / Model / File you see fit with:
Logical::
This will give you access to
The setLogicalStatementInstance
method allows a custom Logical Statement Instance to be passed to after construction.
Logical::setLogicalStatementInstance(new LogicalStatement);
Logical::setLogicalStatementInstance(new MyLogicalStatement);
The getLogicalStatementInstance
method returns the set Logical Statement Instance.
Logical::getLogicalStatementInstance();
Logical::getLogicalStatementInstance()->defineCustomStatement('test', function ($input, $expected) { return true; });
The setInput
method sets a input array set.
Logical::setInput([['name' => 'tom'], ['name' => 'jerry']]);
The getInput
method returns the set input array set.
Logical::getInput();
The setLogic
method allows a logic statement string to be set. The available logical methods are within the Logical Statement class.
Logical::setLogic('where("name").equals("tom")');
The getLogic
method returns the set logic statement string.
Logical::getLogic();
The execute
method decodes the logic string into callable methods and then executes those methods against the input array.
Logical::execute();
The getResults
method returns the items matching the logic statement sting from the input array set.
Logical::getResults();
The reset
method resets input, logic and results.
Logical::reset();
Logic statement strings are built by defining as follows:
where("field")
.where("field").equals("tom")
..
.AND
or OR
such as where("field").equals("tom").OR.where("field").equals("jerry")
.Below is a list of available logic statement string methods:
The equals
method returns true if the input value equals the expected value.
equals(1)
The notEquals
method returns true if the input value doesn't equals the expected value.
notEquals(1)
The isLength
method returns true if the input value equals the expected length value.
isLength(1)
The isNotLength
method returns true if the input value doesn't equals the expected length value.
isNotLength(1)
The is
method returns true if the input value is the same type the expected value.
is("boolean")
The isNot
method returns true if the input value isn't the same type the expected value.
isNot("boolean")
The contains
method returns true if the input value contains the expected value.
contains("o")
The notContains
method returns true if the input value doesn't contain the expected value.
notContains("o")
The containedIn
method returns true if the input value contains an item of the expected values.
containedIn(["a", "b", "c"])
The notContainedIn
method returns true if the input value doesn't contain an item of the expected values.
notContainedIn(["a", "b", "c"])
The in
method returns true if the input value is an item of the expected values.
in(["a", "b", "c"])
The notIn
method returns true if the input value is not an item of the expected values.
notIn(["a", "b", "c"])
The between
method returns true if the input value is between the expected values.
between(1, 10)
The notBetween
method returns true if the input value is not between the expected values.
notBetween(1, 10)
The null
method returns true if the input value is null.
null()
The notNull
method returns true if the input value is not null.
notNull()
The lessThan
method returns true if the input value is less than the expected value.
lessThan(10)
The notLessThan
method returns true if the input value is not less than the expected value.
notLessThan(10)
The greaterThan
method returns true if the input value is greater than the expected value.
greaterThan(10)
The notGreaterThan
method returns true if the input value is not greater than the expected value.
notGreaterThan(10)
The lessThanOrEqual
method returns true if the input value is less than or equal to the expected value.
lessThanOrEqual(10)
The notLessThanOrEqual
method returns true if the input value is not less than or not equal to the expected value.
notLessThanOrEqual(10)
The greaterThanOrEqual
method returns true if the input value is greater than or equal to the expected value.
greaterThanOrEqual(10)
The notGreaterThanOrEqual
method returns true if the input value is not greater than or not equal to the expected value.
notGreaterThanOrEqual(10)
The startsWith
method returns true if the input value starts with the expected value.
startsWith('hello')
The notStartsWith
method returns true if the input value doesn't start with the expected value.
notStartsWith('hello')
The endsWith
method returns true if the input value ends with the expected value.
endsWith('goodbye')
The notEndsWith
method returns true if the input value doesn't end with the expected value.
notEndsWith('goodbye')
Logical is open-sourced software licensed under the MIT license