Japanese version, (*1)
DEPRECATED
PLEASE USE THE ALTERNATIVE LIBRARIES, (*2)
SAKURA Internet API Client Library for PHP
This library gives you an easy interface to control your resources on
SAKURA Cloud., (*3)
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., (*4)
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()., (*5)
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., (*6)
<?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., (*7)
Copyright and license
Copyright (C) 2014 SAKURA Internet, Inc., (*8)
This library is freely redistributable under MIT license., (*9)