This package is abandoned and no longer maintained. No replacement package was suggested.

0.0.2.11 2015-08-12 07:46 UTC

This package is not auto-updated.

Last update: 2022-08-06 04:53:55 UTC


README

Japanese version

DEPRECATED

PLEASE USE THE ALTERNATIVE LIBRARIES

SAKURA Internet API Client Library for PHP

This library gives you an easy interface to control your resources on SAKURA Cloud.

Table of Contents

Requirements

How to use this library in your project

cd YOUR/PROJECT/ROOT

# Install Composer (if not yet)
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

# Create composer.json
# (Edit existing one when using some kind of framework such as FuelPHP)
cat > composer.json << EOT
{
    "require": {
        "sakura-internet/saklient": "dev-master"
    }
}
EOT

# Install packages
composer install

# Edit your code
vi YOUR-CODE.php
<?php

require_once 'vendor/autoload.php';
$api = \Saklient\Cloud\API::authorize(YOUR_API_TOKEN, YOUR_API_SECRET, ZONE);
// ZONE: "is1a" (Ishikari 1st zone), "is1b" (Ishikari 2nd zone), "tk1v" (Sandbox)
// "tk1v" is recommended for tests

// ...

A notice about ArrayObject

Some methods such as $api->server->find() return an array. This array is made of ArrayObject instead of PHP standard array.

Therefore, you have to cast each array (returned by any methods in this library) from ArrayObject to standard array before you use it as an argument for the functions of PHP standard array API such as array_shift().

Also, be aware that an ArrayObject will not be copied in an assignment or as an argument to a function since it is an object but not an array. By the same token, a boolean-casted empty ArrayObject will not be evaluated as false.

<?php

$servers = $api->server->find();

// This doesn't work well
while ($server = array_shift($servers)) {
    //...
    
    // The same goes for accessors
    while ($tag = array_shift($server->tags)) {
        //...
    }
}

// This works well
$servers_array = (array)$servers;
while ($server = array_shift($servers_array)) {
    //...
    
    $tags_array = (array)$server->tags;
    while ($tag = array_shift($tags_array)) {
        //...
    }
}

// This works well because ArrayObject implements IteratorAggregate
foreach ($servers as $server) {
    //...
    
    foreach ($server->tags as $tag) {
        //...
    }
}

// This works well too because ArrayObject implements ArrayAccess and Countable
for ($i=0; $i < count($servers); $i++) {
    $server = $servers[$i];
    //...
    
    for ($j=0; $j < count($server->tags); $j++) {
        $tag = $server->tags[$j];
        //...
    }
}

Examples

Code examples are available here.

Copyright and license

Copyright (C) 2014 SAKURA Internet, Inc.

This library is freely redistributable under MIT license.