php-arsenal / salesforce-mapper-bundle
Symfony bundle that maps raw Salesforce objects with your models.
Installs: 3 918
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 27
Type:symfony-bundle
Requires
- php: >=8.0
- doctrine/cache: ^1.11
- doctrine/common: ^3.1.0
- doctrine/mongodb-odm-bundle: ^4.3
- friendsofphp/proxy-manager-lts: ^1.0
- php-arsenal/salesforce-bundle: ^4.0
- sensio/framework-extra-bundle: ^6.1.0
- symfony/dependency-injection: ^5.2
- symfony/event-dispatcher: ^5.2
- symfony/http-kernel: ^5.2
Requires (Dev)
- phpunit/php-code-coverage: ^9.0
- phpunit/phpunit: ^9.0
- dev-master
- 4.6.1
- 4.6.0
- 4.5.3
- 4.5.2
- 4.5.1
- 4.5.0
- 4.4.1
- 4.4.0
- 4.3.9
- 4.3.8
- 4.3.7
- 4.3.6
- 4.3.5
- 4.3.4
- 4.3.3
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.8.0
- 3.7.1
- 3.7.0
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1.x-dev
- 3.6.1
- 3.6
- 3.5.1
- 3.5.0
- 3.4.1
- 3.4.0
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 0.2.1
- 0.2.0
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1
- dev-wsdlvalidator
- dev-test-helper
- dev-revert-1-test-helper
- dev-php7
This package is auto-updated.
Last update: 2024-11-16 18:33:35 UTC
README
Introduction
The Symfony bundle helps you fetch & map Salesforce objects effectivelly to your own modals to use later with Doctrine or stand-alone.
Installation
composer require php-arsenal/salesforce-mapper-bundle
Features
- Easily fetch records from Salesforce, and save these same records back to Salesforce: read-only fields are automatically ignored when saving.
- Find by criteria just like in Doctrine.
- Fetch related records in one go, so you save on API calls.
- Adjust the mappings to retrieve and save records exactly like you want to.
- The MappedBulkSaver helps you stay within your Salesforce API limits by using bulk creates, deletes, updates and upserts for mapped objects.
- Completely unit tested (still working on that one).
Usage
Once installed, the bundle offers several services that are autowired for dependancy injection:
- a mapper:
PhpArsenal\SalesforceMapperBundle\Mapper
- a bulk saver:
PhpArsenal\SalesforceMapperBundle\MappedBulkSaver
Fetch filtered records
Use the mapper to fetch records from Salesforce. An example:
<?php use PhpArsenal\SalesforceMapperBundle\Mapper; use PhpArsenal\SalesforceMapperBundle\Model\Opportunity; class MyService { private $mapper; public function __construct(Mapper $mapper) { $fetchedObjects = $mapper->findBy(new Opportunity(), [ 'Name' => 'Just an opportunity', ]); } }
You can even fetch related records just by going through related objects:
... $opportunity = $fetchedObjects[0]; echo 'The opportunity belongs to: ' . $opportunity->getAccount()->getName(); ...
Fetch all records
... $fetchedObjects = $mapper->findAll(Opportunity::class); ...
Saving records
If you create a new record and save it, the ID assigned to it by Salesforce is
accessible with getId()
.
... $opportunity = new Opportunity(); $opportunity->setName('Some name'); echo $opportunity->getId(); // Returns null $mapper->save($account); echo $account->getId(); // Returns the new ID, e.g. `001D000000h0Jod` ...
PhpArsenal\SalesforceMapperBundle\MappedBulkSaver
can be used to save mulitple objects in batches.
Custom objects and properties
In the Model
folder you will find several standard Salesforce objects. As this
is a generic client bundle, this directory does not contain custom objects, nor
do the objects in it have custom properties.
If you would like to add custom objects or properties, please extend from AbstractModel
or the models provided.
The mapper knows how to map fields reading the annotations above the property:
... use PhpArsenal\SalesforceMapperBundle\Annotation as Salesforce; ... /** * @var string * @Salesforce\Field(name="AccountId") */ protected $accountId; ...