Skip to content

Commit 74f70b1

Browse files
committed
Initial commit 🎉
0 parents  commit 74f70b1

18 files changed

+784
-0
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
laravel: [8, 9, 10]
12+
php: ["8.0", 8.1, 8.2]
13+
exclude:
14+
- php: "8.0"
15+
laravel: 10
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: test against Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }}
21+
run: docker build . --build-arg PHP_VERSION=${{ matrix.php }} --build-arg LARAVEL=${{ matrix.laravel }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
vendor/
3+
composer.lock
4+
.phpunit.result.cache

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ARG PHP_VERSION=8.0
2+
FROM php:$PHP_VERSION-cli-alpine
3+
4+
RUN apk add git zip unzip autoconf make g++
5+
6+
# apparently newer xdebug needs these now?
7+
RUN apk add --update linux-headers
8+
9+
RUN pecl install xdebug && docker-php-ext-enable xdebug
10+
11+
RUN curl -sS https://getcomposer.org/installer | php \
12+
&& mv composer.phar /usr/local/bin/composer
13+
14+
WORKDIR /package
15+
16+
COPY composer.json ./
17+
18+
ARG LARAVEL=8
19+
RUN composer require illuminate/support ^$LARAVEL.0
20+
21+
COPY src src
22+
COPY tests tests
23+
COPY phpunit.xml ./
24+
25+
RUN COMPOSER_ALLOW_SUPERUSER=1 composer test

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Synergi Tech Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Laravel Salesforce
2+
3+
[![Tests](https://github.com/SynergiTech/laravel-salesforce/actions/workflows/test.yml/badge.svg)](https://github.com/SynergiTech/laravel-salesforce/actions/workflows/test.yml)
4+
5+
This package uses [omniphx/forrest](https://github.com/omniphx/forrest) to provide an Eloquent-style way of querying sObjects from Salesforce.
6+
7+
:warning: This is an initial version that only allows for the selecting of data. Newer versions will aim to provide a more complete experience.
8+
9+
## Getting Started
10+
11+
Follow the instructions provided at [omniphx/forrest](https://github.com/omniphx/forrest) to connect to your Salesforce environment.
12+
Once done, you can then use the `SynergiTech\Salesforce\Facades\Salesforce` facade to perform queries against a particular table like so:
13+
14+
```php
15+
use SynergiTech\Salesforce\Facades\Salesforce;
16+
17+
// Get an individual record by Id
18+
Salesforce::table('MyTable')->find('YourIdHere');
19+
```
20+
21+
## Available Methods
22+
23+
### find
24+
25+
Allows you to directly pull an individual record as an array by Id.
26+
You can also specify another field name as the second parameter.
27+
If you specify a non-unique column and multiple records are returned then the first record is always returned.
28+
29+
```php
30+
Salesforce::table('MyTable')->find('YourIdHere');
31+
```
32+
33+
### findMany
34+
35+
Allows you to directly pull multiple records as a Laravel Collection by provide an array of their respective Id fields.
36+
You can also specify another field name as the second parameter.
37+
38+
```php
39+
Salesforce::table('MyTable')->findMany(['YourId1Here', 'YourId2Here']);
40+
```
41+
42+
### where
43+
44+
You can also scope your queries with where clauses.
45+
46+
```php
47+
// Basic where clause
48+
Salesforce::table('MyTable')->where('Name', 'John Doe')->get();
49+
50+
// You can also use any of the following operators
51+
52+
// Equals and Not Equals
53+
Salesforce::table('MyTable')->where('Name', '=', 'John Doe')->get();
54+
Salesforce::table('MyTable')->where('Name', '!=', 'John Doe')->get();
55+
56+
// Comparisons
57+
Salesforce::table('MyTable')->where('Age', '<', 30)->get();
58+
Salesforce::table('MyTable')->where('Age', '<=', 30)->get();
59+
Salesforce::table('MyTable')->where('Age', '>', 30)->get();
60+
Salesforce::table('MyTable')->where('Age', '>=', 30)->get();
61+
62+
// Like
63+
Salesforce::table('MyTable')->where('Name', 'LIKE', 'John %')->get();
64+
Salesforce::table('MyTable')->where('Name', 'LIKE', '% Middlename %')->get();
65+
Salesforce::table('MyTable')->where('Name', 'LIKE', '% Doe')->get();
66+
```
67+
68+
### whereIn
69+
70+
You can provide an array of possible values to the `whereIn` method to select any records that match any of the values.
71+
72+
```php
73+
Salesforce::table('MyTable')->whereIn('Country', ['United Kingdom', 'United States'])->get();
74+
```
75+
76+
### orderBy
77+
78+
You can order by a particular field in either ascending or descending order.
79+
80+
```php
81+
// Ascending (default)
82+
Salesforce::table('MyTable')->orderBy('Age')->get();
83+
84+
// Descending
85+
Salesforce::table('MyTable')->orderBy('Age', 'DESC')->get();
86+
```
87+
88+
### nullsLast
89+
90+
By default when chaining an orderBy null values are returned first.
91+
You can chain on `->nullsLast()` to return null values last.
92+
93+
```php
94+
Salesforce::table('MyTable')->orderBy('LastLoginDate')->nullsLast()->get();
95+
```
96+
97+
### limit
98+
99+
You can limit the amount of records returned.
100+
101+
```php
102+
Salesforce::table('MyTable')->where('Name', 'LIKE', 'John%')->limit(20)->get();
103+
```
104+
105+
## Exceptions
106+
107+
By default [omniphx/forrest](https://github.com/omniphx/forrest) typically throws a single exception with more detail contained within a JSON encoded string.
108+
We've wrapped a couple with our own exceptions to help with debugging.

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "synergitech/laravel-salesforce",
3+
"description": "This package uses omniphx/forrest to provide an Eloquent-style way of querying sObjects from Salesforce.",
4+
"license": "MIT",
5+
"keywords": [
6+
"laravel",
7+
"salesforce"
8+
],
9+
"require": {
10+
"php": "^8.0",
11+
"illuminate/collections": "^8.0 || ^9.0 || ^10.0",
12+
"illuminate/support": "^8.0 || ^9.0 || ^10.0",
13+
"omniphx/forrest": "^2.0"
14+
},
15+
"require-dev": {
16+
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
17+
"php-parallel-lint/php-parallel-lint": "^1.3",
18+
"phpstan/phpstan": "^1",
19+
"phpunit/phpunit": "^9.0",
20+
"squizlabs/php_codesniffer": "^3.6"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"SynergiTech\\Salesforce\\": "src/"
25+
}
26+
},
27+
"extra": {
28+
"laravel": {
29+
"aliases": {
30+
"Salesforce": "SynergiTech\\Salesforce\\Facades\\Salesforce"
31+
}
32+
}
33+
},
34+
"scripts": {
35+
"test": [
36+
"Composer\\Config::disableProcessTimeout",
37+
"XDEBUG_MODE=coverage phpunit tests",
38+
"parallel-lint --exclude vendor .",
39+
"phpcs --standard=PSR12 src/ tests/",
40+
"phpstan analyse --level 9 src"
41+
]
42+
}
43+
}

phpunit.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
12+
stopOnFailure="false">
13+
<testsuites>
14+
<testsuite name="alert-package-tests">
15+
<directory suffix="Test.php">./tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<coverage processUncoveredFiles="true">
19+
<report>
20+
<html outputDirectory="build/coverage"/>
21+
<text outputFile="php://stdout"/>
22+
</report>
23+
<include>
24+
<directory suffix=".php">./src</directory>
25+
</include>
26+
</coverage>
27+
</phpunit>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Exceptions;
4+
5+
use Exception;
6+
7+
class AuthenticationFailedException extends Exception
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Exceptions;
4+
5+
use Exception;
6+
7+
class InvalidFieldException extends Exception
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Exceptions;
4+
5+
use Exception;
6+
7+
class InvalidResponseException extends Exception
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Exceptions;
4+
5+
use Exception;
6+
7+
class MalformedQueryException extends Exception
8+
{
9+
}

src/Exceptions/NotFoundException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Exceptions;
4+
5+
use Exception;
6+
7+
class NotFoundException extends Exception
8+
{
9+
}

src/Facades/Salesforce.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace SynergiTech\Salesforce\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
use SynergiTech\Salesforce\Services\SalesforceService;
7+
8+
class Salesforce extends Facade
9+
{
10+
/**
11+
* Get the registered class for the component.
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor(): string
16+
{
17+
return SalesforceService::class;
18+
}
19+
}

0 commit comments

Comments
 (0)