GithubHelp home page GithubHelp logo

bjeavons / acquia-sdk-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acquia/acquia-sdk-php

0.0 2.0 1.0 490 KB

The Acquia SDK for PHP allows developers to build applications on top of Acquia services.

License: MIT License

PHP 100.00%

acquia-sdk-php's Introduction

Acquia SDK for PHP

Build Status Coverage Status Latest Stable Version

The Acquia SDK for PHP allows developers to build applications on top of Acquia services.

Acquia provides open cloud hosting, developer tools and world-class support for Drupal, the open source content management platform that unifies content, community and commerce.

Installation

The SDK can be installed with Composer by adding this library as a dependency to your composer.json file.

{
    "repositories": [
        {
            "type": "pear",
            "url": "pear.php.net"
        }
    ],
    "require": {
        "acquia/acquia-sdk-php": "*"
    }
}

After running php composer.phar update on the command line, include the autoloader in your PHP scripts so that the SDK classes are made available.

require_once 'vendor/autoload.php';

Take Only What You Need

Instead of downloading the entire SDK, it is recommended to take only what you need by requiring the individual components you intend to use. For example, the following code requires the Acquia Search component and it's dependencies.

{
    "require": {
        "acquia/acquia-sdk-php-search": "*"
    }
}

The following components are available:

Usage

Basic usage examples for the SDK.

Cloud API

The Cloud API is a web service that that developers can use to extend, enhance, and customize Acquia Cloud.

use Acquia\Cloud\Api\CloudApiClient;

$cloudapi = CloudApiClient::factory(array(
    'username' => 'xxx...',  // Email address used to log into the Acquia Network
    'password' => 'xxx...',  // Acquia Network password
));

$sites = $cloudapi->sites();

Acquia Network

The Acquia Network is a comprehensive suite of tools to help you create and manage killer web sites, backed by the best Drupal support team in the world.

use Acquia\Network\AcquiaNetworkClient;
use Acquia\Common\Services;

$network = AcquiaNetworkClient::factory(array(
    'network_id' => 'XXXX-XXXXX',  // Acquia Network identifier
    'network_key' => 'xxxxxx...',  // Acquia Network key
));

// Enable Acquia Search and return index information.
$acquiaServices = Services::ACQUIA_SEARCH;

$subscription = $network->checkSubscription($acquiaServices);
print $subscription->getDashboardUrl();

Acquia Search

Acquia Search is a fully managed enterprise site search solution built on Apache Solr and other open source technologies.

use Acquia\Search\AcquiaSearchService;

// A subscription can have multiple indexes. The Acquia Search service builder
// generates credentials and clients for all of the subscription's indexes.
$search = AcquiaSearchService::factory($subscription);

$index = $search->get('XXXX-XXXXX');
$results = $index->select('my keywords');

Refer to the PSolr project's documentation for more advanced usage examples.

Recommended: Use the Service Manager to store credentials so that you don't have to query the Acquia Network on every search request.

Acquia Cloud Database

The Database component allows developers to connect to the active master database when running applications on Acquia Cloud.

use Acquia\Cloud\Database\DatabaseService;

$service = new DatabaseService();

$creds = $service->credentials('mydatabase');
$dbh = new PDO($creds, $creds->username(), $creds->password());

Local Development

The SDK facilitates code portability for developers who like to test their application locally. The following snippet shows how to connect to a local database.

use Acquia\Cloud\Database\DatabaseService;
use Acquia\Cloud\Environment\LocalEnvironment;

// "mydatabase" is the name of the database on Acquia Cloud.
$environment = new LocalEnvironment('mysite');
$environment->addDatabaseCredentials('mydatabase', 'local_db_name', 'db_user', 'db_password');

$service = new DatabaseService($environment);

$creds = $service->credentials('mydatabase');
$dbh = new PDO($creds, $creds->username(), $creds->password());

Acquia Cloud Memcache

The Memcache component allows developers to connect to the Memcached caching system when running applications on Acquia Cloud.

use Acquia\Cloud\Memcache\MemcacheService;

$service  = new MemcacheService();
$memcache = new \Memcache();

$creds = $service->credentials();
foreach ($creds as $server) {
    $memcache->addServer($server->host(), $server->port());
}

Local Development

The SDK facilitates code portability for developers who like to test their application locally. The following snippet shows how to connect to a local memcache server.

use Acquia\Cloud\Memcache\MemcacheService;
use Acquia\Cloud\Environment\LocalEnvironment;

$environment = new LocalEnvironment('mysite');
$environment->addMemcacheCredentials('localhost', 11211);

$service  = new MemcacheService(environment);
$memcache = new \Memcache();

$creds = $service->credentials();
foreach ($creds as $server) {
    $memcache->addServer($server->host(), $server->port());
}

Refer to the Memcache PECL project's documentation for more details.

The Acquia Service Manager

The Acquia Service Manager simplifies credential management and client instantiation. The credential management system is built using Guzzle's service builder subsystem, so the documentation and techniques can also apply here.

Saving Credentials

The following example saves the configurations for the client to JSON files in the specified directory. Note that the Acquia Search client is a service builder which is why we use the setBuilder method for it.

use Acquia\Rest\ServiceManager;

$services = new ServiceManager(array(
    'conf_dir' => '/path/to/conf/dir',
));

$services
    ->setClient('cloudapi', 'mysite', $cloudapi)
    ->setClient('network', 'XXXX-XXXXX', $network)
    ->setBuilder('search', $search)
;

$services->save();

Instantiating Service Clients

Clients can now be instantiated from the service manager by passing the service group (e.g. "network", "search", etc.) and service name defined in the setClient() method. For Acquia Search, the service builder automatically names the clients after their index identifiers.

use Acquia\Rest\ServiceManager;

$services = new ServiceManager(array(
    'conf_dir' => '/path/to/conf/dir',
));

$cloudapi = $services->getClient('cloudapi', 'mysite');
$network = $services->getClient('network', 'XXXX-XXXXX');
$index = $services->getClient('search', 'XXXX-XXXXX');

Contributing and Development

Submit changes using GitHub's standard pull request workflow.

All code should adhere to the following standards:

It is recommend to use the PHP Coding Standards Fixer tool to ensure that code adheres to the coding standards mentioned above.

Refer to PHP Project Starter's documentation for the Apache Ant targets supported by this project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.