Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Metadata.php « Common « OpenCloud « lib « php-opencloud « 3rdparty « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be6903e897ed8560e0a1fe2db9738573e28acb8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
 * A metadata object, used by other components in Compute and Object Storage
 *
 * @copyright 2012-2013 Rackspace Hosting, Inc.
 * See COPYING for licensing information
 *
 * @package phpOpenCloud
 * @version 1.0
 * @author Glen Campbell <glen.campbell@rackspace.com>
 */

namespace OpenCloud\Common;

/**
 * The Metadata class represents either Server or Image metadata
 *
 * @api
 * @author Glen Campbell <glen.campbell@rackspace.com>
 */
class Metadata extends Base 
{

    // array holding the names of keys that were set
    private $_keylist = array();    

    /**
     * This setter overrides the base one, since the metadata key can be
     * anything
     *
     * @param string $key
     * @param string $value
     * @return void
     */
    public function __set($key, $value) 
    {
        // set the value and track the keys
        if (!in_array($key, $this->_keylist)) {
            $this->_keylist[] = $key;
        }

        $this->$key = $value;
    }

    /**
     * Returns the list of keys defined
     *
     * @return array
     */
    public function Keylist() 
    {
        return $this->_keylist;
    }

    /**
     * Sets metadata values from an array, with optional prefix
     *
     * If $prefix is provided, then only array keys that match the prefix
     * are set as metadata values, and $prefix is stripped from the key name.
     *
     * @param array $values an array of key/value pairs to set
     * @param string $prefix if provided, a prefix that is used to identify
     *      metadata values. For example, you can set values from headers
     *      for a Container by using $prefix='X-Container-Meta-'.
     * @return void
     */
    public function setArray($values, $prefix = null) 
    {
        if (empty($values)) {
            return false;
        }
        
        foreach ($values as $key => $value) {
            if ($prefix) {
                if (strpos($key, $prefix) === 0) {
                    $name = substr($key, strlen($prefix));
                    $this->getLogger()->info(
                        Lang::translate('Setting [{name}] to [{value}]'), 
                    	array(
                            'name'  => $name, 
                            'value' => $value
                        )
                    );
                    $this->$name = $value;
                }
            } else {
                $this->$key = $value;
            }
        }
    }

}