Rules Reference

Keywords

Keywords are methods/functions that allow you to control what happens with your data before storing or after reading. This is the full reference:

Keywords Description
also `also` filler word like all other filler words does not come with any side effects but is used sorely for readability purposes. eg: `->beforeCreating()->assign("hello")->to($text)->convertToUpperCase()->reverseString()->storeAs($text)->succeedWith($text)` this can be rewritten as `beforeCreating()->assign("hello")->to($text)->convertToUpperCase()->also->reverseString()->storeAs($text)->succeedWith($text)` notice the introduction of the `also` keyword, this does not change the end results but just makes it more readable. @return $this
then `then` filler word like all other filler words does not come with any side effects but is used solely for readability purposes. eg: `->beforeCreating()->assign("hello")->to($text)->convertToUpperCase()->reverseString()->storeAs($text)->succeedWith($text)` this can be rewritten as `beforeCreating()->assign("hello")->to($text)->convertToUpperCase()->then->reverseString()->storeAs($text)->succeedWith($text)` notice the introduction of the `then` keyword, this does not change the end results but just makes it more readable. @return $this
firstly `firstly` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->then->storeAs($text)->lastly->succeedWith($text)`. @return $this
Secondly `secondly` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->then->storeAs($text)->lastly->succeedWith($text)`. @return $this
thirdly `thirdly` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->then->storeAs($text)->lastly->succeedWith($text)`. @return $this
lastly `lastly` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->then->storeAs($text)->lastly->succeedWith($text)`. @return $this
beSureTo `beSureTo` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->then->beSureTo->storeAs($text)->lastly->succeedWith($text)`. @return $this
next `next` filler word like all other filler words does not come with any side effects but is used solely for readability purposes eg: `->beforeCreating()->firstly->assign("hello")->to($text)->secondly->convertToUpperCase()->next->storeAs($text)->lastly->succeedWith($text)`. @return $this
authenticateUser Appending the authenticateUser method to any query action will force users to login to gain access to the system eg: ->beforeQuerying()->onTable('subscriptions')->autheticateUser() @return $this
denyExternalAccess In the event you do not want to grant external access to a table to any users you should use `denyExternalAccess` method . `->beforeQuerying()->onTable('subscriptions')->denyExternalAccess()` In this case no user will be able to access the `subscriptions` table @return $this
allowExternalAccess You may decide to set all your table access to either `authenticated` or `private` from within the `privacy tab` but then decide to make one or more tables public in this case use the `allowExternalAccess` method `->beforeQuerying()->onTable('news', 'tariffs')->allowExternalAccess()` @return $this
grantOnlyAdminAccess You may decide to provide access of some tables to just the admin instead locking them up totally . To do this use the `grantOnlyAdminAccess` method.`->beforeQuerying()->onTable('news', 'tariffs')->grantOnlyAdminAccess()` @return $this
onQuery Checks if a table is being queried for data then the code attached to it will run. This will run twice before and after the data is being queried. @return $this
onUpdate Checks if data is being updated on a table then the code attached to it will run.This will run twice before and after the data is being updated. @return $this
onCreate Checks if data is being added to table then the code attached to it will run. This will run twice before and after the data is being added @return $this
onDelete Check if data is being deleted from a table. This will run code attached to it before and after its being run @return $this
beforeQuerying Checks if a table is about to be queried for data .The code attached to it will run before the data is queried @return $this
beforeCreating Checks if data is about to be added to a table and runs the code attached to it before this happens @return $this
beforeUpdating Checks if table data is about to be updated, and will run the code attached to it before the action is performed @return $this
beforeDeleting Check if data is about to be deleted from table. Then run the code attached to the action before its being performed. This allows you to perform actions such as `afterQuering()->mutateResponseMessage("the response message has been altered") @return $this
afterQuerying Runs code attached to this method just before the response is being returned to the client. This allows you to perform actions such as `afterQuering()->whenever($rules->status_code == 625)->mutateResponseMessage("the response message has been altered") @return $this
afterCreating Runs code attached to this method after the data has been added to the DB. This allows you to perform actions such as `afterCreating()->whenever($rules->status_code == 625)->mutateResponseMessage("the response message has been altered") @return $this
afterUpdating Run code attached to this method after the data has been updated . This allows you to perform actions such as `afterUpdating()->whenever($rules->status_code == 619)->mutateResponseMessage("the response message has been altered") @return $this
afterDeleting Runs code attached to the `afterDeleting()` method. This allows you to perform actions such as `afterDeleting()->whenever($rules->status_code == 636)->mutateResponseMessage("the response message has been altered") @return $this
onAnyReequest Code attached to the `onAnyRequest()` will run regardless of whether its a query, create delete or update action @return $this
whenever This is the equivalence of if and is mostly used together with assertions to alter execution flows. eg beforeQuerying()->whenever(assertIts::equal($input_name, "edmond"))->then->succeedWith("yes the names are same") @param $assertion @return $this
elseWhenever This is the equivalence of elseif and is mostly used together with assertions to alter execution flows eg.beforeQuerying()->whenever(assertIts::equal($input_name, "edmond"))->then->succeedWith("yes the names are same")->elseWhenever(assertIts::equal($input_name, "charles")))->then->succeedWith("yes the name is charles") @param $assertion @return $this
otherwise This is the equivalence of else eg.beforeQuerying()->whenever(assertIts::equal($input_name, "edmond"))->then->succeedWith("yes the names are same")->elseWhenever(assertIts::equal($input_name, "charles")))->then->succeedWith("yes the names are charles")->otherwise()->succeedWith("Its some other name") @return $this
onTable Checks if the db action to be conducted around one of the tables. Eg beforeQuerying()->onTable('register', 'subscription')->succeedWith("yes"). In the example above yes will be outputted in case data is being queried from either register or subscription table. @param string $expectedTableName @return mixed\
succeedWith Stop execution with an exception and output the message provided. Eg. afterQuering()->succeedWith("I will show up after quering") @param null $msg @return mixed\
failWith Stop execution with an exception and output the message provided. Eg. afterQuering()->failWith("I will show up after quering"). Difference between this and succeedWith is the status code @param string $msg @return mixed\
run DevLess provides developers with ready to use code and one of the ways to access this is via the run statement. After installing an external service you may call it within the rules portion of your app using run eg: beforeCreating()->run('businessMath','discount',[10, $input_price])->getResults($input_price) @param $service @param $method @param array $params @return mixed\
makeExternalRequest In the event where you need to make say an api call, the `makeExternalRequest` method becomes handy. eg beforeUpdating()->makeExternalRequest('GET', 'https://www.calcatraz.com/calculator/api?c=3%2A3')->storeAs($ans) ->succeedWith($ans) @param STRING $method @param STRING $url @param JSON $data (opt) @param JSON $headers (optional) @return $this @param STRING $method @param STRING $url @param JSON $data (opt) @param JSON $headers (optional) @return $this
getResults one of the ways to store results from a method with output is by using the `getResults` method. This will allow you to the output of a method @param $input_var @return $this
storeAs Get results from the last executed method and assign to a variable. eg: beforeQuerying()->sumUp(1.2,3,4,5)->storeAs($ans)->stopAndOutput(1001, 'summed up numbers successfully' $ans) @param $input_var @return $this
assign Assigns one variable to another just like `$sum2 = $sum` . This method works together with `to` method to achive this. eg: afterQuering()->sumUp(1,2,3,4,5)->storeAs($sum)->assign($sum)->to($sum2)->succeedWith($sum2) @param $input_var @return $this
usingService Set the name of service from which you want to use method from. eg: usingService('devless')->callMethod('hello')-> withParams()->getResults($output)->succeedWith($output) @param $serviceName @return $this
callMethod Set the name of the method after setting the service from which you will like to run. eg:usingService('devless')->callMethod('hello')-> withParams()->getResults($output)->succeedWith($output) @param $methodName @return $this
withParams Set parameters for method from which you will like to run eg: usingService('devless')->callMethod('getUserProfile')-> withParams(1)->getResults($output)->succeedWith($output) @param can have n number of parameters @return $this
withoutParams Use this in place of `params()` in case the service method you want to run has no parameters eg: usingService('devless')->callMethod('hello')->withoutParams()->getResults($output)->succeedWith($output) @return $this
to `to` keyword should be used together with `assign` to assign either variables or values to a new variable @param $output @return $this
assignValues Behaves just like the `assign` method but has a much shorter construct. where you will assign say the string "edmond" to variable $name using `assign` `assign("edmond")->to($name)` , `assignValue("edmond", $name)` provides a much shorter construct but loses its redability. @param $input @param $output @return $this
stopAndOutput Should you perform some rules and based on that will like to exit earlier with a response before the actual db command completes, you will want to use `stopAndOutput` eg: beforeQuerying()->usingService('devless')->callMethod('getUserProfile')->withParams(1)->storeAs($profile)->stopAndOutput(1000, 'got profile successfully', $profile). @param $status_code @param $message @param $payload @return $this
help List out all methods as well as get docs on specific method eg: ->help('stopAndOutput') @param $methodToGetDocsFor @return $this
calculate Perform mathematical operations eg: `->beforeQuerying()->calculate(3*5)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @param mathematical expression @return $this
evaluate Evaluate PHP expressions eg:beforeQuering()->evaluate("\DB::table('users')->get()")->storeAs($output)->stopAndOutput(1001, 'got users successfully', $output) @param $expression @return $this
sumUp find the sum of numbers. eg: `->beforeQuerying()->sumUp(3,4,5,6,7)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @param integer $num @return $this
subtract subtract a bunch of numbers. eg: `->beforeQuerying()->subtract(3,4,5,6,7)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` also `->beforeQuerying()->from(5)->subtract(3)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @return $this
multiply find the product of numbers .eg: `->beforeQuerying()->multiply(3,4,5,6,7)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @return $this
divide divide a range of numbers.eg: `->beforeQuerying()->divide(6,2)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @return $this
divideBy This picks results from your earlier computation and divides it by a given number. eg: `->beforeQuerying()->sumUp(3,4,5,6,7)->divdeBy(6)->storeAs($ans)->stopAndOutput(1001,'got answer successfully', $ans)` @param $number @return $this
findSquareRootOf Find the square root of a number. eg:`->beforeQuerying()->findSquareRoot($number)->storeAs($input_root)` @param integer $num @return $this
getSquareRoot Get the squareRoot of the result of the preceeding computation eg: `->beforeQuerying()->divide(20, 40)->getSquareRoot()->storeAs($output)->succeedWith($output)` return $this
roundUp round up a number. eg: `->beforeCreating()->roundUp($input_milage, 1)->storeAs($input_milage)` @param integer $number @param integer $precision @return $this
percentOf Find the percent of a number eg: `->beforeQuerying()->find(10)->percentOf(200)->storeAs($input_discount)` @param $number @return $this
concatenate Concatenate strings together eg: `->beforeCreating()->concatenate("user_",$input_name)` @param n number of params @return $this
getFirstCharacter Get first character eg: `->beforeCreating()->getFirstCharacter("Hello")->storeAs($first_char)->succeedWith($first_char)` @param $string @return $this
getSecondCharacter Get second character eg: `->beforeCreating()->getSecondCharacter("Hello")->storeAs($second_char)->succeedWith($second_char)` @param $string @return $this
getThirdCharacter Get third character eg: `->beforeCreating()->getThirdCharacter("Hello")->storeAs($third_char)->succeedWith($third_char)` @param $string @return $this
getLastCharacter Get last character eg: `->beforeCreating()->getLastCharacter("Hello")->storeAs($last_char)->succeedWith($last_char)` @param $string @return $this
getCharacter Get nth character eg: `->beforeCreating()->getCharacter(5, "Hello")->storeAs($nth_char)->succeedWith($nth_char)` @param $nth @param $string @return $this
getLastButOneCharacter Get last but one character eg: `->beforeCreating()->getLastButOneCharacter("Hello")->storeAs($last_but_one_char)->succeedWith($last_but_one_char)` @param $string @return $this
reverseString Reverse a string eg: ->beforeQuerying()->assign("nan")->to($string)->reverseString()->storeAs($reverseString) ->whenever(assertIts::equal($string, $reverseString))->succeedWith("Its a palindrome :)") ->otherwise()->failWith("Its not a palindrome :(") @param $string @return $this
findNReplace replace a string with another eg `->beforeCreating()->findNReplace("", $input_name, $input_message)->storeAs($input_message)` @param $string @param $replacement @param $subject @return $this
convertToUpperCase change string to uppercase eg: `->beforeCreating()->convertToUpperCase($input_name)->storeAs($input_name)` @param $string @return $this
convertToLowerCase change string to lowercase eg: `->beforeCreating()->convertToLowerCase($input_name)->storeAs($input_name)` @param $string @return $this
truncateString Truncate a string to some length eg `->beforeCreating()->truncateString(4, $input_desc)->getResults($trucatedString)->storeAs($stub)` @param $len @param $string @param $trimMaker @return $this
countWords Count the number of words in a sentence eg: `->beforeCreating()->onTable('users')->countWords($input_description)->storeAs($desc_length)->whenever($desc_length <= 5)->failWith("Your product description is very short")` @param $sentence @return $this
countCharacters Find the number of characters in a word or sentence eg: `->beforeCreating()->onTable('users')->countCharacters($input_name)->storeAs($name_length)->whenever($name_length <= 0)->failWith("name seems to be empty")` @param word @return $this
getTimestamp The `getTimestamp` method returns the current timestamp. eg: beforeQuerying()->getTimestamp()->storeAs($timestamp)->succeedWith($timestamp) @return $this
getCurrentYear Get the current year using the `getCurrentYear` method eg:beforeQuering()->getCurrentYear()->storeAs($currentYear)succeedWith($currentYear) @return $this
getCurrentMonth Get the current month using the `getCurrentMonth` method eg:beforeQuering()->getCurrentMonth()->storeAs($currentMonth)->succeedWith($currentMonth) @return $this
getCurrentDay Get the current day using the `getCurrentDay` method eg:beforeQuering()->getCurrentDay()->storeAs($currentDay)->succeedWith($currentDay) @return $this
getCurrentHour Get the current hour using the `getCurrentHour` method eg:beforeQuering()->getCurrentHour()->storeAs($currentHour)->succeedWith($currentHour) @return $this
getFormattedDate Get the human readable date using the `getFormattedDate` method eg: beforeQuering()->getFormattedDate()->storeAs($formattedDate)->succeedWith($formattedDate) @return $this
generateRandomInteger generates random integers. This may be used for invitation or promotional code generation. eg `->beforeCreating()->generateRandomInteger(10)->storeAs($promo_code)->assign($promo_code)->to($input_promo)` @param $length @return $this
generateRandomAlphanums generates random alphanumeric values. This may be used for generating order Ids. eg `->beforeCreating()->generateRandomAlphanums()->storeAs($order_id)->assign($order_id)->to($input_order_id)` @return $this
generateRandomString generates random string.This generates random string codes. eg `->beforeCreating()->generateRandomInteger(10)->storeAs($promo_code)->assign($promo_code)->to($input_promo)` @param $length @return $this
generateUniqueId generates unique Id.This generates unique Id . eg `->beforeCreating()->generateUniqueId()->storeAs($user_id)->assign($user_id)->to($input_id)` @param $length @return $this ",
mutateStatusCode mutate response status code. This will change the status code that is being outputed eg: `->afterQuering()->mutateStatusCode(1111)`. NB: you should only change the status code if you know what you doing. Changing it might cause some of the official SDKs to malfunction. @param $newCode @return $this
mutateResponseMessage mutate response message. This will change the Message within the response body sent back to the client. eg ->afterQuering()->mutateResponseMessage("new response message") @param $newMessage @return $this
mutateResponsePayload mutate response payload. This will Replace the Response payload being sent back to the client eg: ->afterQuering()->mutateResponsePayload(["name"=>"Edmond"]) @param $newPayload @return $this
getResponse get the output response message. This will fetch the Message about to be sent back to the client . eg ->afterQuering()->getResponse($status_code, $message, $payload) now the variable $status_code, $message, $payload will be available to use within Rules. @param $status_code @param $message @param $payload @return $this
getStatusCode get the output status code. This will fetch the status code about to be sent back to the client . eg ->afterQuering()->getStatusCode()->storeAs($status_code) now the variable $status_code will be available to use within Rules. @param $status_code @return $this
getResponseMessage get the output message. This will fetch the message about to be sent back to the client . eg ->afterQuering()->getResponseMessage()->storeAs($message) now the variable $message will be available to use within Rules. @param $message @return $this
getResponsePayload get the output payload. This will fetch the payload about to be sent back to the client . eg ->afterQuering()->getResponsePayload()->storeAs($payload) now the variable $paylaod will be available to use within Rules.@param $payload @return $this

Assertions

Assertions are a special kind of rule, which asserts that some condition holds. In a programming language, these would be functions returning booleans. Assertions are best used together with the conditional functions, such as whenever.

Assertion Description
anInteger check if $value is an integer. eg: ` - >beforeCreating() - >whenever(assertIts: :anInteger(3)) - >then - >stopAndOutput(1001,'message','its an integer')` @param $value
aString check if $value is a string. eg: ` - >beforeCreating() - >whenever( assertIts: :aString( "Hello")) - >then - >stopAndOutput(1001,'message', 'its a string')` @param $value
aBoolean check if $value is a boolean. eg: ` - >beforeCreating() - > whenever( assertIts : : aBoolean(true)) - > stopAndOutput(1001,'message', 'its a boolean')` @param $value
aFloat check if $value is a float. eg: ` - >beforeCreating() - >whenever(assertIts : :aFloat(3.034)) - >then - >stopAndOutput(1001, 'message', 'its a float')` @param $value
withinRange check if $value is within the range $min $max. eg: `beforeCreating() - >whenever( assertIts : :withinRange($input_value, 1,4)) - >then - >stopAndOutput(1001, 'message', 'its within range')` @param $value @param $min @ param $max
upperCase check if $value is uppercase eg: ` - >beforeCreating() - >whenever( assertIts: :upperCase("HELLO")) - >then- >stopAndOutput(1001, 'message', 'its upper case')`` @param $value
lowerCase check is $value is lowercase. eg: ` - >beforeCreating() - >whenever(assertIts: :lowerCase("hello")) - >then- >stopAndOutput(1001, 'message', 'its lower case')` @param $value
alphanumeric check if $value is alphanumeric. eg: ` - >beforeCreating() - >whenever(assertIts: :("E23D"))- >stopAndOutput(1001, 'message', 'its alphanumeric')` @param $value
alphabets check if $value are alphabets eg: ` - >beforeCreating() - >whenever(assertIts: :alphabet("abcd")) - >then- >stopAndOutput(1001, 'message', its alphabets')` @param $value
startsWith check if $value starts with $prefix eg: ` - >beforeCreating() - >whenever(assertIts: :startsWith("E23D", "E"))- >then- >stopAndOutput(1001, 'message', 'it starts with an E')` @param $value @param $prefix
endsWith check if $value ends with $suffix eg: ` - >beforeCreating()- >whenever(assertIts : :endsWith ("E23D","D"))- >then - >stopAndOutput(1001,'message', 'it ends with D')` @param $value @param $suffix
matchesRegex check if $value is matched regex eg: ` - >beforeCreating() - >whenever(assertIt: :matchesRegex("edmond@devless.io", "email-regex-goes-here"))- >then - >stopAndOutput(1001,'message', 'it matches the email regex')` @param $value @param $pattern
anEmail check if $value is an email eg: `beforeCreating()- >whenever(assertIts: :email("edmond@devless.io"))- >then- >stopAndOutput(1001, 'message', 'its an email')` @param $value
notEmpty check if $value is not an empty array or empty string eg: ` - >beforeCreating()- >whenever(assertIts: :notEmpty("some text"))- >then ->stopAndOutput(1001, 'message', 'its not empty')` @param $value
contains check if $value contains $subString eg: `beforeCreating() - >whenever(assertIts: :contains( "edmond@devless.io", "edmond")) - >then- >stopAndOutput( 1001, 'message', 'email contains edmond') @param $value @param $substring
equal check if $value equals $value1 eg: ` - >beforeCreating()- >whenever(assertIts : :equal("a", "a"))- >then->stopAndOutput( 1001,'message', 'a is equal to a : )')` @param $value @param $value1
notEqual check if $value is not equal to $value1 eg: `beforeCreating()- >wheneverassertIts: :notEqual("a", "b"))- >then->stopAndOutput(1001, 'message', 'a is not equal to b') @param $value @param $value1
greaterThan check if $value is greater than $value1 eg: ` - >beforeCreating() - >whenever(assertIts: :greaterThan(45, 12))- >then- >stopAndOutput(1001,'message', '45 is greater than 12')` @param $value @param $value1
lessThan check if $value is less than $value1 eg:`- > beforeCreating() - >whenever(assertIts: :lessThan(12, 45))- >stopAndOutput(1001, 'message', '12 is less than 45')` @param $value @param $value1
greaterThanOrEqualTo check if $value is greater than or equal to $value1 eg: `- >beforeCreating whenever(assertIts: :greaterThanOrEqualTo(45, 45))- >then stopAndOutput(1001, 'message', '45 is greater than or equal to 45')` @param $value @param $value1
lessThanOrEqualTo check if $value is less than or equal $value1 `- >beforeCreating() - >whenever(assertIts: :lessThanOrEqualTo (45, 45))- >then- >stopAndOutput(1001, 'message', '45 is less than or equal to 45'0` @param $value @param $value1
getAllUsers Get the list of all registed DevLess users `- >beforeCreating() - >run('devless', 'getAllUsers', [])- >storeAs($users)- >then- >stopAndOutput(1000, 'All DevLess Users',$users)` @param $value @param $value1
queryData Query Data from a service table ->run('devless', 'queryData', ['service_name', 'table_name'])->storeAs($users)->stopAndOutput(3, '', $users)
addData add Data to a service table ->run('devless', 'addData', ['service_name', 'table_name', ['field_name'=>'field_value'] ])->storeAs($output)->stopAndOutput(1, 'message', $output)
updateData update Data from a service table ->run('devless', 'updateData', ['service_name', 'table_name', 'id', 2 , ['field_name'=>'field_value'] ])->storeAs($output)->stopAndOutput(1, 'message', $output)
deleteData Delete Data from a service table ->run('devless', 'addData', ['service_name', 'table_name', 2])->storeAs($output)->stopAndOutput(1, 'message', $output)
getUserProfile Get the profile of a specific user ->run('devless', 'getUserProfile', [1])->storeAs($output)->stopAndOutput(1, 'message', $output)
getUserProfile Get the profile of a specific user ->run('devless', 'getUserProfile', [1])->storeAs($output)->stopAndOutput(1, 'message', $output)
deleteUserProfile Delete user profile ->run('devless', 'deleteUserProfile', [1])->storeAs($output)->stopAndOutput(1, 'message', $output)
updateUserProfile Update user profile ->run('devless', 'updateUserProfile', ['id', 'email', 'password', 'username', 'phonenumber', 'firstname', 'lastname'], '', '', '', '', '', ''])->storeAs($output)->stopAndOutput(1, 'message', $output)

results matching ""

    No results matching ""