PHP code example of omniphx / forrest
1. Go to this page and download the library: Download omniphx/forrest 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/ */
omniphx / forrest example snippets
"omniphx/forrest": "2.*"
Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider::class
'Forrest' => Omniphx\Forrest\Providers\Laravel\Facades\Forrest::class
class_alias('Omniphx\Forrest\Providers\Laravel\Facades\Forrest', 'Forrest');
$app->register(Omniphx\Forrest\Providers\Lumen\ForrestServiceProvider::class);
$app->configure('forrest');
$app->withFacades();
Route::get('/authenticate', function()
{
return Forrest::authenticate();
});
Route::get('/callback', function()
{
Forrest::callback();
return Redirect::to('/');
});
Route::get('/authenticate', function()
{
Forrest::authenticate();
return Redirect::to('/');
});
Route::get('/authenticate', function()
{
Forrest::authenticate();
return Redirect::to('/');
});
Route::get('/authenticate', function()
{
Forrest::authenticate();
return Redirect::to('/');
});
Route::Post('/authenticate', function(Request $request)
{
Forrest::authenticateUser('https://login.salesforce.com',$request->username, $request->password);
return Redirect::to('/');
});
Route::get('/authenticate', function()
{
Forrest::authenticate();
return Redirect::to('/');
});
Route::get('/authenticate', function()
{
$loginURL = 'https://test.salesforce.com';
return Forrest::authenticate($loginURL);
});
Forrest::query('SELECT Id FROM Account');
(
[totalSize] => 2
[done] => 1
[records] => Array
(
[0] => Array
(
[attributes] => Array
(
[type] => Account
[url] => /services/data/v48.0/sobjects/Account/0013I000004zuIXQAY
)
[Id] => 0013I000004zuIXQAY
)
[1] => Array
(
[attributes] => Array
(
[type] => Account
[url] => /services/data/v48.0/sobjects/Account/0013I000004zuIcQAI
)
[Id] => 0013I000004zuIcQAI
)
)
)
(
[nextRecordsUrl] => /services/data/v20.0/query/01gD0000002HU6KIAW-2000
)
Forrest::sobjects('Account',[
'method' => 'post',
'body' => ['Name' => 'Dunder Mifflin']
]);
Forrest::sobjects('Account/001i000000xxx',[
'method' => 'put',
'body' => [
'Name' => 'Dunder Mifflin',
'Phone' => '555-555-5555'
]
]);
$externalId = 'XYZ1234';
Forrest::sobjects('Account/External_Id__c/' . $externalId, [
'method' => 'patch',
'body' => [
'Name' => 'Dunder Mifflin',
'Phone' => '555-555-5555'
]
]);
Forrest::sobjects('Account/001i000000xxx', ['method' => 'delete']);
Forrest::sobjects('Lead',[
'method' => 'post',
'body' => [
'Company' => 'Dunder Mifflin',
'LastName' => 'Scott'
],
'headers' => [
'Sforce-Auto-Assign' => '01Q1N000000yMQZUA2'
]
]);
Forrest::sobjects('Account',['format'=>'xml']);
Forrest::resources();
Array
(
[sobjects] => /services/data/v30.0/sobjects
[connect] => /services/data/v30.0/connect
[query] => /services/data/v30.0/query
[theme] => /services/data/v30.0/theme
[queryAll] => /services/data/v30.0/queryAll
[tooling] => /services/data/v30.0/tooling
[chatter] => /services/data/v30.0/chatter
[analytics] => /services/data/v30.0/analytics
[recent] => /services/data/v30.0/recent
[process] => /services/data/v30.0/process
[identity] => https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000aaaaAAA
[flexiPage] => /services/data/v30.0/flexiPage
[search] => /services/data/v30.0/search
[quickActions] => /services/data/v30.0/quickActions
[appMenu] => /services/data/v30.0/appMenu
)
Forrest::theme();
Forrest::appMenu();
Forrest::sobjects('Account/describe/approvalLayouts/');
Forrest::theme(['format'=>'xml']);
$bulkJob = Forrest::jobs('ingest', [
'method' => 'post',
'body' => [
"object" => "Contact",
"externalIdFieldName" => "externalId",
"contentType" => "CSV",
"operation" => "upsert"
]
]);
Forrest::jobs('ingest/' . $bulkJob['id'] . '/batches', [
'method' => 'put',
'headers' => [
'Content-Type' => 'text/csv'
],
'body' => $csv
]);
$response = Forrest::jobs('ingest/' . $bulkJob['id'] . '/', [
'method' => 'patch',
'body' => [
"state" => "UploadComplete"
]
]);
Forrest::refresh();
Forrest::revoke();
Forrest::versions();
Forrest::resources();
Forrest::identity();
Forrest::getBaseUrl(); // https://my-instance.my.salesforce.com/services/data/v50.0
Forrest::getInstanceURL(); // https://my-instance.my.salesforce.com
Forrest::custom('/myEndpoint');
Forrest::custom('/myEndpoint', [
'method' => 'post',
'body' => ['foo' => 'bar'],
'parameters' => ['flim' => 'flam']]);
Forrest::get('/services/data/v20.0/endpoint');
Forrest::head('/services/data/v20.0/endpoint');
Forrest::post('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::put('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::patch('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::delete('/services/data/v20.0/endpoint');
# example
$data = Forrest::getContentVersionBody($version->Id);
$content = $data->getBody()->getContents();
$response = Forrest::sobjects($resource, ['format'=> 'none']);
echo $response; // Unformatted string
Event::listen('forrest.response', function($request, $response) {
dd((string) $response);
});
'storage'=> [
'type' => 'object'
],
$forrest1 = app()->make('forrest');
$forrest1->setCredentials(['username' => '[email protected] ', 'password'=> '1234']);
$forrest1->authenticate();
$forrest2 = app()->make('forrest');
$forrest2->setCredentials(['username' => '[email protected] ', 'password'=> '1234']);
$forrest2->authenticate();
'storage' => [
'type' => App\Storage\CustomStorage::class,
],
namespace App\Storage;
use Session;
use Omniphx\Forrest\Exceptions\MissingKeyException;
use Omniphx\Forrest\Interfaces\StorageInterface;
class CustomStorage implements StorageInterface
{
public $path;
public function __construct()
{
$this->path = 'app.custom.path';
}
/**
* Store into session.
*
* @param $key
* @param $value
*
* @return void
*/
public function put($key, $value)
{
return Session::put($this->path.$key, $value);
}
/**
* Get from session.
*
* @param $key
*
* @return mixed
*/
public function get($key)
{
if(!$this->has($key)) {
throw new MissingKeyException(sprintf('No value for requested key: %s', $key));
}
return Session::get($this->path.$key);
}
/**
* Check if storage has a key.
*
* @param $key
*
* @return bool
*/
public function has($key)
{
return Session::has($this->path.$key);
}
}
bash
php artisan vendor:publish