/** * Create a new instance of the AlexaCRM\CRMToolkit\AlexaSDK * * @param Settings $settings * @param CacheInterface $cache * @param LoggerInterface $logger * * @throws Exception */ function __construct(Settings $settings, CacheInterface $cache = null, LoggerInterface $logger = null) { try { // Create settings object $this->settings = $settings; // Inject CacheInterface implementation $this->cache = $cache; // Inject LoggerInterface implementation $this->logger = $logger; if (!$this->logger instanceof LoggerInterface) { // Provide a dummy logger if no logger supplied. $this->logger = new NullLogger(); } /* If either mandatory parameter is NULL, throw an Exception */ if (!$this->checkConnectionSettings()) { switch ($this->settings->authMode) { case "OnlineFederation": throw new BadMethodCallException(get_class($this) . ' constructor requires Username and Password'); case "Federation": throw new BadMethodCallException(get_class($this) . ' constructor requires the Discovery URI, Username and Password'); } } /* Create authentication class to connect to CRM Online or Internet facing deployment via ADFS */ switch ($this->settings->authMode) { case "OnlineFederation": $this->authentication = new OnlineFederation($this->settings, $this); break; case "Federation": $this->settings->loginUrl = $this->getFederationSecurityURI('organization'); $this->authentication = new Federation($this->settings, $this); break; } $this->soapActions = new SoapActions($this); if (!$this->settings->hasOrganizationData()) { $organizationDetails = $this->retrieveOrganization($this->settings->serverUrl); $this->settings->organizationId = $organizationDetails['OrganizationId']; $this->settings->organizationName = $organizationDetails['FriendlyName']; $this->settings->organizationUniqueName = $organizationDetails['UniqueName']; $this->settings->organizationVersion = $organizationDetails['OrganizationVersion']; } /* Initialize the entity metadata instance */ MetadataCollection::instance($this); } catch (Exception $e) { $this->logger->critical('Exception during instantiation of the CRM Toolkit.', ['exception' => $e]); throw $e; } }
use AlexaCRM\CRMToolkit\Settings; /* * Enable autoloading for the toolkit. * * CRM Toolkit for PHP is a PSR-4 compliant package. * If you installed the package via Composer, please use * its own autoloader which is generally placed in vendor/autoload.php * * See: https://getcomposer.org/doc/01-basic-usage.md#autoloading */ require_once '../init.php'; $clientOptions = (include 'config.php'); $clientSettings = new Settings($clientOptions); $client = new Client($clientSettings); $metadata = MetadataCollection::instance($client); /* * When Client is instantiated, it connects to the CRM and retrieves * additional organization data. It is then stored in $clientSettings. */ if ($clientSettings->hasOrganizationData()) { echo "You have connected to the organization '{$clientSettings->organizationName}' [{$clientSettings->organizationUniqueName}]" . PHP_EOL; } else { die('There was an error retrieving organization data for the CRM. Please check connection settings.'); } // retrieve "WhoAmI" information $whoAmIResponse = $client->executeAction('WhoAmI'); echo PHP_EOL . 'WhoAmI request response' . PHP_EOL; echo '--------------------------' . PHP_EOL; echo 'UserId: ' . $whoAmIResponse->UserId . PHP_EOL; echo 'BusinessUnitId: ' . $whoAmIResponse->BusinessUnitId . PHP_EOL; echo 'OrganizationId: ' . $whoAmIResponse->OrganizationId . PHP_EOL;