PHP code example of ipaas / gapp-laravel

1. Go to this page and download the library: Download ipaas/gapp-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ipaas / gapp-laravel example snippets


ipaas/gapp-laravel: ~1.1.0
 artisan vendor:publish --tag=gapp
 artisan migrate
 artisan create-partner-app {provider}

/* ------ Class A ------- */
function validateUser(Request $request){
	// validate request
	$request->validate(['user_id'=>'integer|                 // add user details to context
		->setClientId($user->id)        // client id to context
		->setClientKey($user->key);     // client key to context
		
		// add request details context
		iLog()->setType('Validate user name');

		// Calling other class to resolve request
		return ClassB::validateUserName($user);
	}
}

/* ------ Class B ------- */
// all set context still exist
function validateUserName(User $user){
	// log event info
	// will be logged with context
	Log::info('Validating user name')

	// validate user name
	$name = $user->name;
	if(empty($name) || is_null($name))
	{
		// log warning that name is not valid
		// will be logged all context
		Log::warning('Name is null or empty');
		return false;
	}
}

$request->header('Authorization')       // Authorization value from header
$request->header('X-Api-Key')           // Client ID from header
$request->header('Gapp-Request-ID')    // Gapp Request ID from header
$request->uuid                          // request uuid
$request->dateFrom                      // date from
$request->dateTo                        // date to

use Ipaas\Gapp\Request;
use Ipass\Response;
class Accounts extends Response;  
{
	public function index(Request $request)  
	{  
	  $rules = ['name' => '

        $request
            ->boolify('EnablePaymentsToAccount')
            ->arrify('Type')
            ->validate($rules);

// $rules is laravel validation rule set
Func: validate(array $rules)

Return: REQUEST if all sucessfull
Throw: Unprocessable Entity (422) if validation fails

// $item is request csv param
Func: arrify(string $item)

Return: modified REQUEST

// $item is request string 'true/false'
Func: boolify(string $item)

Return: modified REQUEST

// $item is request parameter name
// $value is new value
Func: requestify(string $item, mixed $value)

Return: modified REQUEST

return $this->meta(['client_id' => 'unknown'])->sendResponse($data);

return $this->header(['content-type' => 'application/json'])->sendResponse($data);

// $name is unicode string
Func: normalizedName(string $name)

Return: normalized string

// $list is haystack array
// $item is needle name
Func: boolifyList(array $list, string $item)

Return: modified list
['true', 'false', 'TRUE', 'FALSE', true, false, TRUE, FALSE, 0, 1, '0', '1', '', ' test']