Merge branch 'master' into update-parent-storage-mtime

Conflicts:
	lib/private/files/cache/updater.php
This commit is contained in:
Robin Appelman 2013-10-30 13:41:10 +01:00
commit c9f3f2874f
327 changed files with 12938 additions and 4927 deletions

View File

@ -334,8 +334,13 @@ $(document).ready(function() {
var result=$.parseJSON(response);
delete data.jqXHR;
if (typeof result[0] === 'undefined') {
if (result.status === 'error' && result.data && result.data.message){
data.textStatus = 'servererror';
data.errorThrown = result.data.message;
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
fu._trigger('fail', e, data);
} else if (typeof result[0] === 'undefined') {
data.textStatus = 'servererror';
data.errorThrown = t('files', 'Could not get result from server.');
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');

View File

@ -57,7 +57,7 @@ class App {
// rename to "/Shared" is denied
if( $dir === '/' and $newname === 'Shared' ) {
$result['data'] = array(
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved.")
);
// rename to existing file is denied
} else if ($this->view->file_exists($dir . '/' . $newname)) {

View File

@ -88,7 +88,7 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$result = $this->files->rename($dir, $oldname, $newname);
$expected = array(
'success' => false,
'data' => array('message' => "Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
'data' => array('message' => "Invalid folder name. Usage of 'Shared' is reserved.")
);
$this->assertEquals($expected, $result);

View File

@ -12,7 +12,8 @@ if (!isset($_)) { //also provide standalone error page
$errorMsg = $l->t('Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app.');
break;
case \OCA\Encryption\Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR:
$errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.');
$theme = new OC_Defaults();
$errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside of %s (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.', array($theme->getName()));
break;
case \OCA\Encryption\Crypt::ENCRYPTION_NO_SHARE_KEY_FOUND:
$errorMsg = $l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');

View File

@ -35,6 +35,12 @@ class Hooks {
* @note This method should never be called for users using client side encryption
*/
public static function login($params) {
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
$l = new \OC_L10N('files_encryption');
$view = new \OC_FilesystemView('/');
@ -117,11 +123,12 @@ class Hooks {
* @note This method should never be called for users using client side encryption
*/
public static function postCreateUser($params) {
$view = new \OC_FilesystemView('/');
$util = new Util($view, $params['uid']);
Helper::setupUser($util, $params['password']);
if (\OCP\App::isEnabled('files_encryption')) {
$view = new \OC_FilesystemView('/');
$util = new Util($view, $params['uid']);
Helper::setupUser($util, $params['password']);
}
}
/**
@ -129,26 +136,31 @@ class Hooks {
* @note This method should never be called for users using client side encryption
*/
public static function postDeleteUser($params) {
$view = new \OC_FilesystemView('/');
// cleanup public key
$publicKey = '/public-keys/' . $params['uid'] . '.public.key';
if (\OCP\App::isEnabled('files_encryption')) {
$view = new \OC_FilesystemView('/');
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// cleanup public key
$publicKey = '/public-keys/' . $params['uid'] . '.public.key';
$view->unlink($publicKey);
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
\OC_FileProxy::$enabled = $proxyStatus;
$view->unlink($publicKey);
\OC_FileProxy::$enabled = $proxyStatus;
}
}
/**
* @brief If the password can't be changed within ownCloud, than update the key password in advance.
*/
public static function preSetPassphrase($params) {
if ( ! \OC_User::canUserChangePassword($params['uid']) ) {
self::setPassphrase($params);
if (\OCP\App::isEnabled('files_encryption')) {
if ( ! \OC_User::canUserChangePassword($params['uid']) ) {
self::setPassphrase($params);
}
}
}
@ -157,6 +169,11 @@ class Hooks {
* @param array $params keys: uid, password
*/
public static function setPassphrase($params) {
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
// Only attempt to change passphrase if server-side encryption
// is in use (client-side encryption does not have access to
// the necessary keys)
@ -227,6 +244,10 @@ class Hooks {
*/
public static function preShared($params) {
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
$l = new \OC_L10N('files_encryption');
$users = array();
$view = new \OC\Files\View('/public-keys/');
@ -278,6 +299,10 @@ class Hooks {
// [run] => whether emitting script should continue to run
// TODO: Should other kinds of item be encrypted too?
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
$view = new \OC_FilesystemView('/');
@ -372,6 +397,10 @@ class Hooks {
// [shareWith] => test1
// [itemParent] =>
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
$view = new \OC_FilesystemView('/');
@ -453,6 +482,11 @@ class Hooks {
* of the stored versions along the actual file
*/
public static function postRename($params) {
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;

View File

@ -11,9 +11,7 @@
$tmpl = new OCP\Template('files_encryption', 'settings-admin');
// Check if an adminRecovery account is enabled for recovering files after lost pwd
$view = new OC_FilesystemView('');
$recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled');
$recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled', '0');
$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);

View File

@ -0,0 +1,16 @@
Copyright 2012-2013 Rackspace US, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
All contributions to this repository are covered under the same license,
terms, and conditions.

View File

@ -0,0 +1,296 @@
<?php
// Copyright (c) 2004-2013 Fabien Potencier
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
class ClassLoader
{
private $namespaces = array();
private $prefixes = array();
private $namespaceFallbacks = array();
private $prefixFallbacks = array();
private $useIncludePath = false;
/**
* Turns on searching the include for class files. Allows easy loading
* of installed PEAR packages
*
* @param Boolean $useIncludePath
*/
public function useIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Gets the configured namespaces.
*
* @return array A hash with namespaces as keys and directories as values
*/
public function getNamespaces()
{
return $this->namespaces;
}
/**
* Gets the configured class prefixes.
*
* @return array A hash with class prefixes as keys and directories as values
*/
public function getPrefixes()
{
return $this->prefixes;
}
/**
* Gets the directory(ies) to use as a fallback for namespaces.
*
* @return array An array of directories
*/
public function getNamespaceFallbacks()
{
return $this->namespaceFallbacks;
}
/**
* Gets the directory(ies) to use as a fallback for class prefixes.
*
* @return array An array of directories
*/
public function getPrefixFallbacks()
{
return $this->prefixFallbacks;
}
/**
* Registers the directory to use as a fallback for namespaces.
*
* @param array $dirs An array of directories
*
* @api
*/
public function registerNamespaceFallbacks(array $dirs)
{
$this->namespaceFallbacks = $dirs;
}
/**
* Registers a directory to use as a fallback for namespaces.
*
* @param string $dir A directory
*/
public function registerNamespaceFallback($dir)
{
$this->namespaceFallbacks[] = $dir;
}
/**
* Registers directories to use as a fallback for class prefixes.
*
* @param array $dirs An array of directories
*
* @api
*/
public function registerPrefixFallbacks(array $dirs)
{
$this->prefixFallbacks = $dirs;
}
/**
* Registers a directory to use as a fallback for class prefixes.
*
* @param string $dir A directory
*/
public function registerPrefixFallback($dir)
{
$this->prefixFallbacks[] = $dir;
}
/**
* Registers an array of namespaces
*
* @param array $namespaces An array of namespaces (namespaces as keys and locations as values)
*
* @api
*/
public function registerNamespaces(array $namespaces)
{
foreach ($namespaces as $namespace => $locations) {
$this->namespaces[$namespace] = (array) $locations;
}
}
/**
* Registers a namespace.
*
* @param string $namespace The namespace
* @param array|string $paths The location(s) of the namespace
*
* @api
*/
public function registerNamespace($namespace, $paths)
{
$this->namespaces[$namespace] = (array) $paths;
}
/**
* Registers an array of classes using the PEAR naming convention.
*
* @param array $classes An array of classes (prefixes as keys and locations as values)
*
* @api
*/
public function registerPrefixes(array $classes)
{
foreach ($classes as $prefix => $locations) {
$this->prefixes[$prefix] = (array) $locations;
}
}
/**
* Registers a set of classes using the PEAR naming convention.
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
*
* @api
*/
public function registerPrefix($prefix, $paths)
{
$this->prefixes[$prefix] = (array) $paths;
}
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
*
* @api
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Fix for certain versions of PHP that have trouble with
* namespaces with leading separators.
*
* @access private
* @param mixed $className
* @return void
*/
private function makeBackwardsCompatible($className)
{
return (phpversion() < '5.3.3') ? ltrim($className, '\\') : $className;
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return Boolean|null True, if loaded
*/
public function loadClass($class)
{
$class = $this->makeBackwardsCompatible($class);
if ($file = $this->findFile($class)) {
require $file;
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|null The path, if found
*/
public function findFile($class)
{
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$namespace = substr($class, 0, $pos);
$className = substr($class, $pos + 1);
$normalizedClass = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
foreach ($this->namespaces as $ns => $dirs) {
if (0 !== strpos($namespace, $ns)) {
continue;
}
foreach ($dirs as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
if (is_file($file)) {
return $file;
}
}
}
foreach ($this->namespaceFallbacks as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
if (is_file($file)) {
return $file;
}
}
} else {
// PEAR-like class name
$normalizedClass = str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
foreach ($this->prefixes as $prefix => $dirs) {
if (0 !== strpos($class, $prefix)) {
continue;
}
foreach ($dirs as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
if (is_file($file)) {
return $file;
}
}
}
foreach ($this->prefixFallbacks as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
if (is_file($file)) {
return $file;
}
}
}
if ($this->useIncludePath && $file = stream_resolve_include_path($normalizedClass)) {
return $file;
}
}
}

View File

@ -0,0 +1,301 @@
<?php
/**
* @copyright 2012-2013 Rackspace Hosting, Inc.
* See COPYING for licensing information
* @package phpOpenCloud
* @version 1.0
* @author Glen Campbell <glen.campbell@rackspace.com>
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Common;
use OpenCloud\Common\Lang;
use OpenCloud\Common\Exceptions\AttributeError;
use OpenCloud\Common\Exceptions\JsonError;
use OpenCloud\Common\Exceptions\UrlError;
/**
* The root class for all other objects used or defined by this SDK.
*
* It contains common code for error handling as well as service functions that
* are useful. Because it is an abstract class, it cannot be called directly,
* and it has no publicly-visible properties.
*/
abstract class Base
{
private $http_headers = array();
private $_errors = array();
/**
* Debug status.
*
* @var LoggerInterface
* @access private
*/
private $logger;
/**
* Sets the Logger object.
*
* @param \OpenCloud\Common\Log\LoggerInterface $logger
*/
public function setLogger(Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* Returns the Logger object.
*
* @return \OpenCloud\Common\Log\AbstractLogger
*/
public function getLogger()
{
if (null === $this->logger) {
$this->setLogger(new Log\Logger);
}
return $this->logger;
}
/**
* Returns the URL of the service/object
*
* The assumption is that nearly all objects will have a URL; at this
* base level, it simply throws an exception to enforce the idea that
* subclasses need to define this method.
*
* @throws UrlError
*/
public function url($subresource = '')
{
throw new UrlError(Lang::translate(
'URL method must be overridden in class definition'
));
}
/**
* Populates the current object based on an unknown data type.
*
* @param array|object|string|integer $info
* @throws Exceptions\InvalidArgumentError
*/
public function populate($info, $setObjects = true)
{
if (is_string($info) || is_integer($info)) {
// If the data type represents an ID, the primary key is set
// and we retrieve the full resource from the API
$this->{$this->primaryKeyField()} = (string) $info;
$this->refresh($info);
} elseif (is_object($info) || is_array($info)) {
foreach($info as $key => $value) {
if ($key == 'metadata' || $key == 'meta') {
if (empty($this->metadata) || !$this->metadata instanceof Metadata) {
$this->metadata = new Metadata;
}
// Metadata
$this->$key->setArray($value);
} elseif (!empty($this->associatedResources[$key]) && $setObjects === true) {
// Associated resource
try {
$resource = $this->service()->resource($this->associatedResources[$key], $value);
$resource->setParent($this);
$this->$key = $resource;
} catch (Exception\ServiceException $e) {}
} elseif (!empty($this->associatedCollections[$key]) && $setObjects === true) {
// Associated collection
try {
$this->$key = $this->service()->resourceList($this->associatedCollections[$key], null, $this);
} catch (Exception\ServiceException $e) {}
} else {
// Normal key/value pair
$this->$key = $value;
}
}
} elseif (null !== $info) {
throw new Exceptions\InvalidArgumentError(sprintf(
Lang::translate('Argument for [%s] must be string or object'),
get_class()
));
}
}
/**
* Sets extended attributes on an object and validates them
*
* This function is provided to ensure that attributes cannot
* arbitrarily added to an object. If this function is called, it
* means that the attribute is not defined on the object, and thus
* an exception is thrown.
*
* @codeCoverageIgnore
*
* @param string $property the name of the attribute
* @param mixed $value the value of the attribute
* @return void
*/
public function __set($property, $value)
{
$this->setProperty($property, $value);
}
/**
* Sets an extended (unrecognized) property on the current object
*
* If RAXSDK_STRICT_PROPERTY_CHECKS is TRUE, then the prefix of the
* property name must appear in the $prefixes array, or else an
* exception is thrown.
*
* @param string $property the property name
* @param mixed $value the value of the property
* @param array $prefixes optional list of supported prefixes
* @throws \OpenCloud\AttributeError if strict checks are on and
* the property prefix is not in the list of prefixes.
*/
public function setProperty($property, $value, array $prefixes = array())
{
// if strict checks are off, go ahead and set it
if (!RAXSDK_STRICT_PROPERTY_CHECKS
|| $this->checkAttributePrefix($property, $prefixes)
) {
$this->$property = $value;
} else {
// if that fails, then throw the exception
throw new AttributeError(sprintf(
Lang::translate('Unrecognized attribute [%s] for [%s]'),
$property,
get_class($this)
));
}
}
/**
* Converts an array of key/value pairs into a single query string
*
* For example, array('A'=>1,'B'=>2) would become 'A=1&B=2'.
*
* @param array $arr array of key/value pairs
* @return string
*/
public function makeQueryString($array)
{
$queryString = '';
foreach($array as $key => $value) {
if ($queryString) {
$queryString .= '&';
}
$queryString .= urlencode($key) . '=' . urlencode($this->to_string($value));
}
return $queryString;
}
/**
* Checks the most recent JSON operation for errors
*
* This function should be called after any `json_*()` function call.
* This ensures that nasty JSON errors are detected and the proper
* exception thrown.
*
* Example:
* `$obj = json_decode($string);`
* `if (check_json_error()) do something ...`
*
* @return boolean TRUE if an error occurred, FALSE if none
* @throws JsonError
*
* @codeCoverageIgnore
*/
public function checkJsonError()
{
switch (json_last_error()) {
case JSON_ERROR_NONE:
return;
case JSON_ERROR_DEPTH:
$jsonError = 'JSON error: The maximum stack depth has been exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$jsonError = 'JSON error: Invalid or malformed JSON';
break;
case JSON_ERROR_CTRL_CHAR:
$jsonError = 'JSON error: Control character error, possibly incorrectly encoded';
break;
case JSON_ERROR_SYNTAX:
$jsonError = 'JSON error: Syntax error';
break;
case JSON_ERROR_UTF8:
$jsonError = 'JSON error: Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$jsonError = 'Unexpected JSON error';
break;
}
if (isset($jsonError)) {
throw new JsonError(Lang::translate($jsonError));
}
}
/**
* Returns a class that implements the HttpRequest interface.
*
* This can be stubbed out for unit testing and avoid making live calls.
*/
public function getHttpRequestObject($url, $method = 'GET', array $options = array())
{
return new Request\Curl($url, $method, $options);
}
/**
* Checks the attribute $property and only permits it if the prefix is
* in the specified $prefixes array
*
* This is to support extension namespaces in some services.
*
* @param string $property the name of the attribute
* @param array $prefixes a list of prefixes
* @return boolean TRUE if valid; FALSE if not
*/
private function checkAttributePrefix($property, array $prefixes = array())
{
$prefix = strstr($property, ':', true);
if (in_array($prefix, $prefixes)) {
return true;
} else {
return false;
}
}
/**
* Converts a value to an HTTP-displayable string form
*
* @param mixed $x a value to convert
* @return string
*/
private function to_string($x)
{
if (is_bool($x) && $x) {
return 'True';
} elseif (is_bool($x)) {
return 'False';
} else {
return (string) $x;
}
}
}

View File

@ -0,0 +1,320 @@
<?php
namespace OpenCloud\Common;
/**
* Provides an abstraction for working with ordered sets of objects
*
* Collection objects are used whenever there are multiples; for example,
* multiple objects in a container, or multiple servers in a service.
*
* @since 1.0
* @author Glen Campbell <glen.campbell@rackspace.com>
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
class Collection extends Base
{
private $service;
private $itemclass;
private $itemlist = array();
private $pointer = 0;
private $sortkey;
private $next_page_class;
private $next_page_callback;
private $next_page_url;
/**
* A Collection is an array of objects
*
* Some assumptions:
* * The `Collection` class assumes that there exists on its service
* a factory method with the same name of the class. For example, if
* you create a Collection of class `Foobar`, it will attempt to call
* the method `parent::Foobar()` to create instances of that class.
* * It assumes that the factory method can take an array of values, and
* it passes that to the method.
*
* @param Service $service - the service associated with the collection
* @param string $itemclass - the Class of each item in the collection
* (assumed to be the name of the factory method)
* @param array $arr - the input array
*/
public function __construct($service, $itemclass, $array)
{
$this->service = $service;
$this->getLogger()->info(
'Collection:service={class}, class={itemClass}, array={array}',
array(
'class' => get_class($service),
'itemClass' => $itemclass,
'array' => print_r($array, true)
)
);
$this->next_page_class = $itemclass;
if (false !== ($classNamePos = strrpos($itemclass, '\\'))) {
$this->itemclass = substr($itemclass, $classNamePos + 1);
} else {
$this->itemclass = $itemclass;
}
if (!is_array($array)) {
throw new Exceptions\CollectionError(
Lang::translate('Cannot create a Collection without an array')
);
}
// save the array of items
$this->setItemList($array);
}
/**
* Set the entire data array.
*
* @param array $array
*/
public function setItemList(array $array)
{
$this->itemlist = $array;
}
/**
* Retrieve the entire data array.
*
* @return array
*/
public function getItemList()
{
return $this->itemlist;
}
/**
* Returns the number of items in the collection
*
* For most services, this is the total number of items. If the Collection
* is paginated, however, this only returns the count of items in the
* current page of data.
*
* @return int
*/
public function count()
{
return count($this->itemlist);
}
/**
* Pseudonym for count()
*
* @codeCoverageIgnore
*/
public function size()
{
return $this->count();
}
/**
* Retrieves the service associated with the Collection
*
* @return Service
*/
public function service()
{
return $this->service;
}
/**
* Resets the pointer to the beginning, but does NOT return the first item
*
* @api
* @return void
*/
public function reset()
{
$this->pointer = 0;
}
/**
* Resets the collection pointer back to the first item in the page
* and returns it
*
* This is useful if you're only interested in the first item in the page.
*
* @api
* @return Base the first item in the set
*/
public function first()
{
$this->reset();
return $this->next();
}
/**
* Returns the next item in the page
*
* @api
* @return Base the next item or FALSE if at the end of the page
*/
public function next()
{
if ($this->pointer >= $this->count()) {
return false;
}
$service = $this->service();
if (method_exists($service, $this->itemclass)) {
return $service->{$this->itemclass}($this->itemlist[$this->pointer++]);
} elseif (method_exists($service, 'resource')) {
return $service->resource($this->itemclass, $this->itemlist[$this->pointer++]);
}
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}
/**
* sorts the collection on a specified key
*
* Note: only top-level keys can be used as the sort key. Note that this
* only sorts the data in the current page of the Collection (for
* multi-page data).
*
* @api
* @param string $keyname the name of the field to use as the sort key
* @return void
*/
public function sort($keyname = 'id')
{
$this->sortkey = $keyname;
usort($this->itemlist, array($this, 'sortCompare'));
}
/**
* selects only specified items from the Collection
*
* This provides a simple form of filtering on Collections. For each item
* in the collection, it calls the callback function, passing it the item.
* If the callback returns `TRUE`, then the item is retained; if it returns
* `FALSE`, then the item is deleted from the collection.
*
* Note that this should not supersede server-side filtering; the
* `Collection::Select()` method requires that *all* of the data for the
* Collection be retrieved from the server before the filtering is
* performed; this can be very inefficient, especially for large data
* sets. This method is mostly useful on smaller-sized sets.
*
* Example:
* <code>
* $services = $connection->ServiceList();
* $services->Select(function($item){ return $item->region=='ORD';});
* // now the $services Collection only has items from the ORD region
* </code>
*
* `Select()` is *destructive*; that is, it actually removes entries from
* the collection. For example, if you use `Select()` to find items with
* the ID > 10, then use it again to find items that are <= 10, it will
* return an empty list.
*
* @api
* @param callable $testfunc a callback function that is passed each item
* in turn. Note that `Select()` performs an explicit test for
* `FALSE`, so functions like `strpos()` need to be cast into a
* boolean value (and not just return the integer).
* @returns void
* @throws DomainError if callback doesn't return a boolean value
*/
public function select($testfunc)
{
foreach ($this->getItemList() as $index => $item) {
$test = call_user_func($testfunc, $item);
if (!is_bool($test)) {
throw new Exceptions\DomainError(
Lang::translate('Callback function for Collection::Select() did not return boolean')
);
}
if ($test === false) {
unset($this->itemlist[$index]);
}
}
}
/**
* returns the Collection object for the next page of results, or
* FALSE if there are no more pages
*
* Generally, the structure for a multi-page collection will look like
* this:
*
* $coll = $obj->Collection();
* do {
* while($item = $coll->Next()) {
* // do something with the item
* }
* } while ($coll = $coll->NextPage());
*
* @api
* @return Collection if there are more pages of results, otherwise FALSE
*/
public function nextPage()
{
if (isset($this->next_page_url)) {
return call_user_func(
$this->next_page_callback,
$this->next_page_class,
$this->next_page_url
);
}
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}
/**
* for paginated collection, sets the callback function and URL for
* the next page
*
* The callback function should have the signature:
*
* function Whatever($class, $url, $parent)
*
* and the `$url` should be the URL of the next page of results
*
* @param callable $callback the name of the function (or array of
* object, function name)
* @param string $url the URL of the next page of results
* @return void
*/
public function setNextPageCallback($callback, $url)
{
$this->next_page_callback = $callback;
$this->next_page_url = $url;
}
/**
* Compares two values of sort keys
*/
private function sortCompare($a, $b)
{
$key = $this->sortkey;
// handle strings with strcmp()
if (is_string($a->$key)) {
return strcmp($a->$key, $b->$key);
}
// handle others with logical comparisons
if ($a->$key == $b->$key) {
return 0;
}
if ($a->$key < $b->$key) {
return -1;
} else {
return 1;
}
}
}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class AsyncError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class AsyncHttpError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class AsyncTimeoutError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class AttributeError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class AuthenticationError extends \Exception {}

View File

@ -0,0 +1,7 @@
<?php
namespace OpenCloud\Common\Exceptions;
class BaseException extends \Exception
{
}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CdnError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CdnHttpError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CdnNotAvailableError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CdnTtlError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CollectionError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerNameError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerNotEmptyError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ContainerNotFoundError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CreateUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class CredentialError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DatabaseCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DatabaseDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DatabaseListError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DatabaseNameError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DatabaseUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DocumentError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class DomainError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class EmptyResponseError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class EndpointError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class FlavorError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpForbiddenError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpOverLimitError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpRetryError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpTimeoutError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpUnauthorizedError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class HttpUrlError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class IOError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class IdRequiredError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ImageError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceFlavorError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceNotFound extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InstanceUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InvalidArgumentError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InvalidIdTypeError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InvalidIpTypeError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InvalidParameterError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class InvalidRequestError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class JsonError extends \Exception {}

View File

@ -0,0 +1,16 @@
<?php
/**
* @copyright Copyright 2012-2013 Rackspace US, Inc.
See COPYING for licensing information.
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
* @version 1.5.9
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Common\Exceptions;
use Exception;
class LoggingException extends Exception
{
}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataJsonError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataKeyError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataPrefixError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MetadataUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MisMatchedChecksumError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class MissingValueError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NameError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NetworkCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NetworkDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NetworkError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NetworkUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NetworkUrlError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NoContentTypeError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class NoNameError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ObjFetchError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ObjectCopyError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ObjectError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class RebuildError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class RecordTypeError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerActionError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerCreateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerDeleteError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerImageScheduleError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerIpsError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerJsonError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerUpdateError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServerUrlError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class ServiceValueError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class SnapshotError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class TempUrlMethodError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class UnknownError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class UnknownParameterError extends \Exception {}

View File

@ -0,0 +1,5 @@
<?php
namespace OpenCloud\Common\Exceptions;
class UnrecognizedServiceError extends \Exception {}

Some files were not shown because too many files have changed in this diff Show More