Completed
Push — stable10 ( b85e94...1e5021 )
by
unknown
23:18 queued 12:32
created
lib/private/DateTimeZone.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -29,100 +29,100 @@
 block discarded – undo
29 29
 use OCP\ISession;
30 30
 
31 31
 class DateTimeZone implements IDateTimeZone {
32
-	/** @var IConfig */
33
-	protected $config;
32
+    /** @var IConfig */
33
+    protected $config;
34 34
 
35
-	/** @var ISession */
36
-	protected $session;
35
+    /** @var ISession */
36
+    protected $session;
37 37
 
38
-	/**
39
-	 * Constructor
40
-	 *
41
-	 * @param IConfig $config
42
-	 * @param ISession $session
43
-	 */
44
-	public function __construct(IConfig $config, ISession $session) {
45
-		$this->config = $config;
46
-		$this->session = $session;
47
-	}
38
+    /**
39
+     * Constructor
40
+     *
41
+     * @param IConfig $config
42
+     * @param ISession $session
43
+     */
44
+    public function __construct(IConfig $config, ISession $session) {
45
+        $this->config = $config;
46
+        $this->session = $session;
47
+    }
48 48
 
49
-	/**
50
-	 * Get the timezone of the current user, based on his session information and config data
51
-	 *
52
-	 * @param bool|int $timestamp
53
-	 * @return \DateTimeZone
54
-	 */
55
-	public function getTimeZone($timestamp = false) {
56
-		$timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
57
-		if ($timeZone === null) {
58
-			if ($this->session->exists('timezone')) {
59
-				return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
60
-			}
61
-			$timeZone = $this->getDefaultTimeZone();
62
-		}
49
+    /**
50
+     * Get the timezone of the current user, based on his session information and config data
51
+     *
52
+     * @param bool|int $timestamp
53
+     * @return \DateTimeZone
54
+     */
55
+    public function getTimeZone($timestamp = false) {
56
+        $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
57
+        if ($timeZone === null) {
58
+            if ($this->session->exists('timezone')) {
59
+                return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
60
+            }
61
+            $timeZone = $this->getDefaultTimeZone();
62
+        }
63 63
 
64
-		try {
65
-			return new \DateTimeZone($timeZone);
66
-		} catch (\Exception $e) {
67
-			\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
68
-			return new \DateTimeZone($this->getDefaultTimeZone());
69
-		}
70
-	}
64
+        try {
65
+            return new \DateTimeZone($timeZone);
66
+        } catch (\Exception $e) {
67
+            \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
68
+            return new \DateTimeZone($this->getDefaultTimeZone());
69
+        }
70
+    }
71 71
 
72
-	/**
73
-	 * Guess the DateTimeZone for a given offset
74
-	 *
75
-	 * We first try to find a Etc/GMT* timezone, if that does not exist,
76
-	 * we try to find it manually, before falling back to UTC.
77
-	 *
78
-	 * @param mixed $offset
79
-	 * @param bool|int $timestamp
80
-	 * @return \DateTimeZone
81
-	 */
82
-	protected function guessTimeZoneFromOffset($offset, $timestamp) {
83
-		try {
84
-			// Note: the timeZone name is the inverse to the offset,
85
-			// so a positive offset means negative timeZone
86
-			// and the other way around.
87
-			if ($offset > 0) {
88
-				$timeZone = 'Etc/GMT-' . $offset;
89
-			} else {
90
-				$timeZone = 'Etc/GMT+' . abs($offset);
91
-			}
72
+    /**
73
+     * Guess the DateTimeZone for a given offset
74
+     *
75
+     * We first try to find a Etc/GMT* timezone, if that does not exist,
76
+     * we try to find it manually, before falling back to UTC.
77
+     *
78
+     * @param mixed $offset
79
+     * @param bool|int $timestamp
80
+     * @return \DateTimeZone
81
+     */
82
+    protected function guessTimeZoneFromOffset($offset, $timestamp) {
83
+        try {
84
+            // Note: the timeZone name is the inverse to the offset,
85
+            // so a positive offset means negative timeZone
86
+            // and the other way around.
87
+            if ($offset > 0) {
88
+                $timeZone = 'Etc/GMT-' . $offset;
89
+            } else {
90
+                $timeZone = 'Etc/GMT+' . abs($offset);
91
+            }
92 92
 
93
-			return new \DateTimeZone($timeZone);
94
-		} catch (\Exception $e) {
95
-			// If the offset has no Etc/GMT* timezone,
96
-			// we try to guess one timezone that has the same offset
97
-			foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
98
-				$dtz = new \DateTimeZone($timeZone);
99
-				$dateTime = new \DateTime();
93
+            return new \DateTimeZone($timeZone);
94
+        } catch (\Exception $e) {
95
+            // If the offset has no Etc/GMT* timezone,
96
+            // we try to guess one timezone that has the same offset
97
+            foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
98
+                $dtz = new \DateTimeZone($timeZone);
99
+                $dateTime = new \DateTime();
100 100
 
101
-				if ($timestamp !== false) {
102
-					$dateTime->setTimestamp($timestamp);
103
-				}
101
+                if ($timestamp !== false) {
102
+                    $dateTime->setTimestamp($timestamp);
103
+                }
104 104
 
105
-				$dtOffset = $dtz->getOffset($dateTime);
106
-				if ($dtOffset == 3600 * $offset) {
107
-					return $dtz;
108
-				}
109
-			}
105
+                $dtOffset = $dtz->getOffset($dateTime);
106
+                if ($dtOffset == 3600 * $offset) {
107
+                    return $dtz;
108
+                }
109
+            }
110 110
 
111
-			// No timezone found, fallback to UTC
112
-			\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
113
-			return new \DateTimeZone($this->getDefaultTimeZone());
114
-		}
115
-	}
111
+            // No timezone found, fallback to UTC
112
+            \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
113
+            return new \DateTimeZone($this->getDefaultTimeZone());
114
+        }
115
+    }
116 116
 
117
-	/**
118
-	 * Get the default timezone of the server
119
-	 *
120
-	 * Falls back to UTC if it is not yet set.
121
-	 * 
122
-	 * @return string
123
-	 */
124
-	protected function getDefaultTimeZone() {
125
-		$serverTimeZone = date_default_timezone_get();
126
-		return $serverTimeZone ?: 'UTC';
127
-	}
117
+    /**
118
+     * Get the default timezone of the server
119
+     *
120
+     * Falls back to UTC if it is not yet set.
121
+     * 
122
+     * @return string
123
+     */
124
+    protected function getDefaultTimeZone() {
125
+        $serverTimeZone = date_default_timezone_get();
126
+        return $serverTimeZone ?: 'UTC';
127
+    }
128 128
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		try {
65 65
 			return new \DateTimeZone($timeZone);
66 66
 		} catch (\Exception $e) {
67
-			\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
67
+			\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "'.$timeZone."'", \OCP\Util::DEBUG);
68 68
 			return new \DateTimeZone($this->getDefaultTimeZone());
69 69
 		}
70 70
 	}
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 			// so a positive offset means negative timeZone
86 86
 			// and the other way around.
87 87
 			if ($offset > 0) {
88
-				$timeZone = 'Etc/GMT-' . $offset;
88
+				$timeZone = 'Etc/GMT-'.$offset;
89 89
 			} else {
90
-				$timeZone = 'Etc/GMT+' . abs($offset);
90
+				$timeZone = 'Etc/GMT+'.abs($offset);
91 91
 			}
92 92
 
93 93
 			return new \DateTimeZone($timeZone);
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			}
110 110
 
111 111
 			// No timezone found, fallback to UTC
112
-			\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
112
+			\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "'.$offset."'", \OCP\Util::DEBUG);
113 113
 			return new \DateTimeZone($this->getDefaultTimeZone());
114 114
 		}
115 115
 	}
Please login to merge, or discard this patch.
lib/private/Tagging/TagMapper.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -33,47 +33,47 @@
 block discarded – undo
33 33
  */
34 34
 class TagMapper extends Mapper {
35 35
 
36
-	/**
37
-	* Constructor.
38
-	*
39
-	* @param IDBConnection $db Instance of the Db abstraction layer.
40
-	*/
41
-	public function __construct(IDBConnection $db) {
42
-		parent::__construct($db, 'vcategory', 'OC\Tagging\Tag');
43
-	}
36
+    /**
37
+     * Constructor.
38
+     *
39
+     * @param IDBConnection $db Instance of the Db abstraction layer.
40
+     */
41
+    public function __construct(IDBConnection $db) {
42
+        parent::__construct($db, 'vcategory', 'OC\Tagging\Tag');
43
+    }
44 44
 
45
-	/**
46
-	* Load tags from the database.
47
-	*
48
-	* @param array|string $owners The user(s) whose tags we are going to load.
49
-	* @param string $type The type of item for which we are loading tags.
50
-	* @return array An array of Tag objects.
51
-	*/
52
-	public function loadTags($owners, $type) {
53
-		if(!is_array($owners)) {
54
-			$owners = array($owners);
55
-		}
45
+    /**
46
+     * Load tags from the database.
47
+     *
48
+     * @param array|string $owners The user(s) whose tags we are going to load.
49
+     * @param string $type The type of item for which we are loading tags.
50
+     * @return array An array of Tag objects.
51
+     */
52
+    public function loadTags($owners, $type) {
53
+        if(!is_array($owners)) {
54
+            $owners = array($owners);
55
+        }
56 56
 
57
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`';
59
-		return $this->findEntities($sql, array_merge($owners, array($type)));
60
-	}
57
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
+            . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`';
59
+        return $this->findEntities($sql, array_merge($owners, array($type)));
60
+    }
61 61
 
62
-	/**
63
-	* Check if a given Tag object already exists in the database.
64
-	*
65
-	* @param Tag $tag The tag to look for in the database.
66
-	* @return bool
67
-	*/
68
-	public function tagExists($tag) {
69
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
70
-			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71
-		try {
72
-			$this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName()));
73
-		} catch (DoesNotExistException $e) {
74
-			return false;
75
-		}
76
-		return true;
77
-	}
62
+    /**
63
+     * Check if a given Tag object already exists in the database.
64
+     *
65
+     * @param Tag $tag The tag to look for in the database.
66
+     * @return bool
67
+     */
68
+    public function tagExists($tag) {
69
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
70
+            . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71
+        try {
72
+            $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName()));
73
+        } catch (DoesNotExistException $e) {
74
+            return false;
75
+        }
76
+        return true;
77
+    }
78 78
 }
79 79
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 	* @return array An array of Tag objects.
51 51
 	*/
52 52
 	public function loadTags($owners, $type) {
53
-		if(!is_array($owners)) {
53
+		if (!is_array($owners)) {
54 54
 			$owners = array($owners);
55 55
 		}
56 56
 
57
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`';
57
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
58
+			. 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`';
59 59
 		return $this->findEntities($sql, array_merge($owners, array($type)));
60 60
 	}
61 61
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	* @return bool
67 67
 	*/
68 68
 	public function tagExists($tag) {
69
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
69
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
70 70
 			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71 71
 		try {
72 72
 			$this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName()));
Please login to merge, or discard this patch.
lib/private/Tagging/Tag.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,54 +37,54 @@
 block discarded – undo
37 37
  */
38 38
 class Tag extends Entity {
39 39
 
40
-	protected $owner;
41
-	protected $type;
42
-	protected $name;
40
+    protected $owner;
41
+    protected $type;
42
+    protected $name;
43 43
 
44
-	/**
45
-	* Constructor.
46
-	*
47
-	* @param string $owner The tag's owner
48
-	* @param string $type The type of item this tag is used for
49
-	* @param string $name The tag's name
50
-	*/
51
-	public function __construct($owner = null, $type = null, $name = null) {
52
-		$this->setOwner($owner);
53
-		$this->setType($type);
54
-		$this->setName($name);
55
-	}
44
+    /**
45
+     * Constructor.
46
+     *
47
+     * @param string $owner The tag's owner
48
+     * @param string $type The type of item this tag is used for
49
+     * @param string $name The tag's name
50
+     */
51
+    public function __construct($owner = null, $type = null, $name = null) {
52
+        $this->setOwner($owner);
53
+        $this->setType($type);
54
+        $this->setName($name);
55
+    }
56 56
 
57
-	/**
58
-	 * Transform a database columnname to a property
59
-	 *
60
-	 * @param string $columnName the name of the column
61
-	 * @return string the property name
62
-	 * @todo migrate existing database columns to the correct names
63
-	 * to be able to drop this direct mapping
64
-	 */
65
-	public function columnToProperty($columnName){
66
-		if ($columnName === 'category') {
67
-		    return 'name';
68
-		} elseif ($columnName === 'uid') {
69
-		    return 'owner';
70
-		} else {
71
-		    return parent::columnToProperty($columnName);
72
-		}
73
-	}
57
+    /**
58
+     * Transform a database columnname to a property
59
+     *
60
+     * @param string $columnName the name of the column
61
+     * @return string the property name
62
+     * @todo migrate existing database columns to the correct names
63
+     * to be able to drop this direct mapping
64
+     */
65
+    public function columnToProperty($columnName){
66
+        if ($columnName === 'category') {
67
+            return 'name';
68
+        } elseif ($columnName === 'uid') {
69
+            return 'owner';
70
+        } else {
71
+            return parent::columnToProperty($columnName);
72
+        }
73
+    }
74 74
 
75
-	/**
76
-	 * Transform a property to a database column name
77
-	 *
78
-	 * @param string $property the name of the property
79
-	 * @return string the column name
80
-	 */
81
-	public function propertyToColumn($property){
82
-		if ($property === 'name') {
83
-		    return 'category';
84
-		} elseif ($property === 'owner') {
85
-		    return 'uid';
86
-		} else {
87
-		    return parent::propertyToColumn($property);
88
-		}
89
-	}
75
+    /**
76
+     * Transform a property to a database column name
77
+     *
78
+     * @param string $property the name of the property
79
+     * @return string the column name
80
+     */
81
+    public function propertyToColumn($property){
82
+        if ($property === 'name') {
83
+            return 'category';
84
+        } elseif ($property === 'owner') {
85
+            return 'uid';
86
+        } else {
87
+            return parent::propertyToColumn($property);
88
+        }
89
+    }
90 90
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @todo migrate existing database columns to the correct names
63 63
 	 * to be able to drop this direct mapping
64 64
 	 */
65
-	public function columnToProperty($columnName){
65
+	public function columnToProperty($columnName) {
66 66
 		if ($columnName === 'category') {
67 67
 		    return 'name';
68 68
 		} elseif ($columnName === 'uid') {
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @param string $property the name of the property
79 79
 	 * @return string the column name
80 80
 	 */
81
-	public function propertyToColumn($property){
81
+	public function propertyToColumn($property) {
82 82
 		if ($property === 'name') {
83 83
 		    return 'category';
84 84
 		} elseif ($property === 'owner') {
Please login to merge, or discard this patch.
lib/private/Route/Route.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -32,127 +32,127 @@
 block discarded – undo
32 32
 use Symfony\Component\Routing\Route as SymfonyRoute;
33 33
 
34 34
 class Route extends SymfonyRoute implements IRoute {
35
-	/**
36
-	 * Specify the method when this route is to be used
37
-	 *
38
-	 * @param string $method HTTP method (uppercase)
39
-	 * @return \OC\Route\Route
40
-	 */
41
-	public function method($method) {
42
-		$this->setMethods($method);
43
-		return $this;
44
-	}
35
+    /**
36
+     * Specify the method when this route is to be used
37
+     *
38
+     * @param string $method HTTP method (uppercase)
39
+     * @return \OC\Route\Route
40
+     */
41
+    public function method($method) {
42
+        $this->setMethods($method);
43
+        return $this;
44
+    }
45 45
 
46
-	/**
47
-	 * Specify POST as the method to use with this route
48
-	 * @return \OC\Route\Route
49
-	 */
50
-	public function post() {
51
-		$this->method('POST');
52
-		return $this;
53
-	}
46
+    /**
47
+     * Specify POST as the method to use with this route
48
+     * @return \OC\Route\Route
49
+     */
50
+    public function post() {
51
+        $this->method('POST');
52
+        return $this;
53
+    }
54 54
 
55
-	/**
56
-	 * Specify GET as the method to use with this route
57
-	 * @return \OC\Route\Route
58
-	 */
59
-	public function get() {
60
-		$this->method('GET');
61
-		return $this;
62
-	}
55
+    /**
56
+     * Specify GET as the method to use with this route
57
+     * @return \OC\Route\Route
58
+     */
59
+    public function get() {
60
+        $this->method('GET');
61
+        return $this;
62
+    }
63 63
 
64
-	/**
65
-	 * Specify PUT as the method to use with this route
66
-	 * @return \OC\Route\Route
67
-	 */
68
-	public function put() {
69
-		$this->method('PUT');
70
-		return $this;
71
-	}
64
+    /**
65
+     * Specify PUT as the method to use with this route
66
+     * @return \OC\Route\Route
67
+     */
68
+    public function put() {
69
+        $this->method('PUT');
70
+        return $this;
71
+    }
72 72
 
73
-	/**
74
-	 * Specify DELETE as the method to use with this route
75
-	 * @return \OC\Route\Route
76
-	 */
77
-	public function delete() {
78
-		$this->method('DELETE');
79
-		return $this;
80
-	}
73
+    /**
74
+     * Specify DELETE as the method to use with this route
75
+     * @return \OC\Route\Route
76
+     */
77
+    public function delete() {
78
+        $this->method('DELETE');
79
+        return $this;
80
+    }
81 81
 
82
-	/**
83
-	 * Specify PATCH as the method to use with this route
84
-	 * @return \OC\Route\Route
85
-	 */
86
-	public function patch() {
87
-		$this->method('PATCH');
88
-		return $this;
89
-	}
82
+    /**
83
+     * Specify PATCH as the method to use with this route
84
+     * @return \OC\Route\Route
85
+     */
86
+    public function patch() {
87
+        $this->method('PATCH');
88
+        return $this;
89
+    }
90 90
 
91
-	/**
92
-	 * Defaults to use for this route
93
-	 *
94
-	 * @param array $defaults The defaults
95
-	 * @return \OC\Route\Route
96
-	 */
97
-	public function defaults($defaults) {
98
-		$action = $this->getDefault('action');
99
-		$this->setDefaults($defaults);
100
-		if (isset($defaults['action'])) {
101
-			$action = $defaults['action'];
102
-		}
103
-		$this->action($action);
104
-		return $this;
105
-	}
91
+    /**
92
+     * Defaults to use for this route
93
+     *
94
+     * @param array $defaults The defaults
95
+     * @return \OC\Route\Route
96
+     */
97
+    public function defaults($defaults) {
98
+        $action = $this->getDefault('action');
99
+        $this->setDefaults($defaults);
100
+        if (isset($defaults['action'])) {
101
+            $action = $defaults['action'];
102
+        }
103
+        $this->action($action);
104
+        return $this;
105
+    }
106 106
 
107
-	/**
108
-	 * Requirements for this route
109
-	 *
110
-	 * @param array $requirements The requirements
111
-	 * @return \OC\Route\Route
112
-	 */
113
-	public function requirements($requirements) {
114
-		$method = $this->getMethods();
115
-		$this->setRequirements($requirements);
116
-		if (isset($requirements['_method'])) {
117
-			$method = $requirements['_method'];
118
-		}
119
-		if ($method) {
120
-			$this->method($method);
121
-		}
122
-		return $this;
123
-	}
107
+    /**
108
+     * Requirements for this route
109
+     *
110
+     * @param array $requirements The requirements
111
+     * @return \OC\Route\Route
112
+     */
113
+    public function requirements($requirements) {
114
+        $method = $this->getMethods();
115
+        $this->setRequirements($requirements);
116
+        if (isset($requirements['_method'])) {
117
+            $method = $requirements['_method'];
118
+        }
119
+        if ($method) {
120
+            $this->method($method);
121
+        }
122
+        return $this;
123
+    }
124 124
 
125
-	/**
126
-	 * The action to execute when this route matches
127
-	 *
128
-	 * @param string|callable $class the class or a callable
129
-	 * @param string $function the function to use with the class
130
-	 * @return \OC\Route\Route
131
-	 *
132
-	 * This function is called with $class set to a callable or
133
-	 * to the class with $function
134
-	 */
135
-	public function action($class, $function = null) {
136
-		$action = array($class, $function);
137
-		if (is_null($function)) {
138
-			$action = $class;
139
-		}
140
-		$this->setDefault('action', $action);
141
-		return $this;
142
-	}
125
+    /**
126
+     * The action to execute when this route matches
127
+     *
128
+     * @param string|callable $class the class or a callable
129
+     * @param string $function the function to use with the class
130
+     * @return \OC\Route\Route
131
+     *
132
+     * This function is called with $class set to a callable or
133
+     * to the class with $function
134
+     */
135
+    public function action($class, $function = null) {
136
+        $action = array($class, $function);
137
+        if (is_null($function)) {
138
+            $action = $class;
139
+        }
140
+        $this->setDefault('action', $action);
141
+        return $this;
142
+    }
143 143
 
144
-	/**
145
-	 * The action to execute when this route matches, includes a file like
146
-	 * it is called directly
147
-	 * @param string $file
148
-	 * @return void
149
-	 */
150
-	public function actionInclude($file) {
151
-		$function = create_function('$param',
152
-			'unset($param["_route"]);'
153
-			.'$_GET=array_merge($_GET, $param);'
154
-			.'unset($param);'
155
-			.'require_once "'.$file.'";');
156
-		$this->action($function);
157
-	}
144
+    /**
145
+     * The action to execute when this route matches, includes a file like
146
+     * it is called directly
147
+     * @param string $file
148
+     * @return void
149
+     */
150
+    public function actionInclude($file) {
151
+        $function = create_function('$param',
152
+            'unset($param["_route"]);'
153
+            .'$_GET=array_merge($_GET, $param);'
154
+            .'unset($param);'
155
+            .'require_once "'.$file.'";');
156
+        $this->action($function);
157
+    }
158 158
 }
Please login to merge, or discard this patch.
lib/private/Route/CachingRouter.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -28,38 +28,38 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 class CachingRouter extends Router {
31
-	/**
32
-	 * @var \OCP\ICache
33
-	 */
34
-	protected $cache;
31
+    /**
32
+     * @var \OCP\ICache
33
+     */
34
+    protected $cache;
35 35
 
36
-	/**
37
-	 * @param \OCP\ICache $cache
38
-	 * @param ILogger $logger
39
-	 */
40
-	public function __construct($cache, ILogger $logger) {
41
-		$this->cache = $cache;
42
-		parent::__construct($logger);
43
-	}
36
+    /**
37
+     * @param \OCP\ICache $cache
38
+     * @param ILogger $logger
39
+     */
40
+    public function __construct($cache, ILogger $logger) {
41
+        $this->cache = $cache;
42
+        parent::__construct($logger);
43
+    }
44 44
 
45
-	/**
46
-	 * Generate url based on $name and $parameters
47
-	 *
48
-	 * @param string $name Name of the route to use.
49
-	 * @param array $parameters Parameters for the route
50
-	 * @param bool $absolute
51
-	 * @return string
52
-	 */
53
-	public function generate($name, $parameters = array(), $absolute = false) {
54
-		asort($parameters);
55
-		$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute);
56
-		$cachedKey = $this->cache->get($key);
57
-		if ($cachedKey) {
58
-			return $cachedKey;
59
-		} else {
60
-			$url = parent::generate($name, $parameters, $absolute);
61
-			$this->cache->set($key, $url, 3600);
62
-			return $url;
63
-		}
64
-	}
45
+    /**
46
+     * Generate url based on $name and $parameters
47
+     *
48
+     * @param string $name Name of the route to use.
49
+     * @param array $parameters Parameters for the route
50
+     * @param bool $absolute
51
+     * @return string
52
+     */
53
+    public function generate($name, $parameters = array(), $absolute = false) {
54
+        asort($parameters);
55
+        $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute);
56
+        $cachedKey = $this->cache->get($key);
57
+        if ($cachedKey) {
58
+            return $cachedKey;
59
+        } else {
60
+            $url = parent::generate($name, $parameters, $absolute);
61
+            $this->cache->set($key, $url, 3600);
62
+            return $url;
63
+        }
64
+    }
65 65
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
 	 */
53 53
 	public function generate($name, $parameters = array(), $absolute = false) {
54 54
 		asort($parameters);
55
-		$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute);
55
+		$key = $this->context->getHost().'#'.$this->context->getBaseUrl().$name.sha1(json_encode($parameters)).intval($absolute);
56 56
 		$cachedKey = $this->cache->get($key);
57 57
 		if ($cachedKey) {
58 58
 			return $cachedKey;
Please login to merge, or discard this patch.
lib/private/TagManager.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -40,53 +40,53 @@
 block discarded – undo
40 40
 
41 41
 class TagManager implements \OCP\ITagManager {
42 42
 
43
-	/**
44
-	 * User session
45
-	 *
46
-	 * @var \OCP\IUserSession
47
-	 */
48
-	private $userSession;
43
+    /**
44
+     * User session
45
+     *
46
+     * @var \OCP\IUserSession
47
+     */
48
+    private $userSession;
49 49
 
50
-	/**
51
-	 * TagMapper
52
-	 *
53
-	 * @var TagMapper
54
-	 */
55
-	private $mapper;
50
+    /**
51
+     * TagMapper
52
+     *
53
+     * @var TagMapper
54
+     */
55
+    private $mapper;
56 56
 
57
-	/**
58
-	* Constructor.
59
-	*
60
-	* @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
-	* @param \OCP\IUserSession $userSession the user session
62
-	*/
63
-	public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
-		$this->mapper = $mapper;
65
-		$this->userSession = $userSession;
57
+    /**
58
+     * Constructor.
59
+     *
60
+     * @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
+     * @param \OCP\IUserSession $userSession the user session
62
+     */
63
+    public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
+        $this->mapper = $mapper;
65
+        $this->userSession = $userSession;
66 66
 
67
-	}
67
+    }
68 68
 
69
-	/**
70
-	* Create a new \OCP\ITags instance and load tags from db.
71
-	*
72
-	* @see \OCP\ITags
73
-	* @param string $type The type identifier e.g. 'contact' or 'event'.
74
-	* @param array $defaultTags An array of default tags to be used if none are stored.
75
-	* @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
-	* @param string $userId user for which to retrieve the tags, defaults to the currently
77
-	* logged in user
78
-	* @return \OCP\ITags
79
-	*/
80
-	public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
-		if (is_null($userId)) {
82
-			$user = $this->userSession->getUser();
83
-			if ($user === null) {
84
-				// nothing we can do without a user
85
-				return null;
86
-			}
87
-			$userId = $this->userSession->getUser()->getUId();
88
-		}
89
-		return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
-	}
69
+    /**
70
+     * Create a new \OCP\ITags instance and load tags from db.
71
+     *
72
+     * @see \OCP\ITags
73
+     * @param string $type The type identifier e.g. 'contact' or 'event'.
74
+     * @param array $defaultTags An array of default tags to be used if none are stored.
75
+     * @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
+     * @param string $userId user for which to retrieve the tags, defaults to the currently
77
+     * logged in user
78
+     * @return \OCP\ITags
79
+     */
80
+    public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
+        if (is_null($userId)) {
82
+            $user = $this->userSession->getUser();
83
+            if ($user === null) {
84
+                // nothing we can do without a user
85
+                return null;
86
+            }
87
+            $userId = $this->userSession->getUser()->getUId();
88
+        }
89
+        return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
lib/private/ContactsManager.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -27,164 +27,164 @@
 block discarded – undo
27 27
 
28 28
 namespace OC {
29 29
 
30
-	class ContactsManager implements \OCP\Contacts\IManager {
31
-
32
-		/**
33
-		 * This function is used to search and find contacts within the users address books.
34
-		 * In case $pattern is empty all contacts will be returned.
35
-		 *
36
-		 * @param string $pattern which should match within the $searchProperties
37
-		 * @param array $searchProperties defines the properties within the query pattern should match
38
-		 * @param array $options - for future use. One should always have options!
39
-		 * @return array an array of contacts which are arrays of key-value-pairs
40
-		 */
41
-		public function search($pattern, $searchProperties = array(), $options = array()) {
42
-			$this->loadAddressBooks();
43
-			$result = array();
44
-			foreach($this->addressBooks as $addressBook) {
45
-				$r = $addressBook->search($pattern, $searchProperties, $options);
46
-				$contacts = array();
47
-				foreach($r as $c){
48
-					$c['addressbook-key'] = $addressBook->getKey();
49
-					$contacts[] = $c;
50
-				}
51
-				$result = array_merge($result, $contacts);
52
-			}
53
-
54
-			return $result;
55
-		}
56
-
57
-		/**
58
-		 * This function can be used to delete the contact identified by the given id
59
-		 *
60
-		 * @param object $id the unique identifier to a contact
61
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
-		 * @return bool successful or not
63
-		 */
64
-		public function delete($id, $addressBookKey) {
65
-			$addressBook = $this->getAddressBook($addressBookKey);
66
-			if (!$addressBook) {
67
-				return null;
68
-			}
69
-
70
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
-				return $addressBook->delete($id);
72
-			}
73
-
74
-			return null;
75
-		}
76
-
77
-		/**
78
-		 * This function is used to create a new contact if 'id' is not given or not present.
79
-		 * Otherwise the contact will be updated by replacing the entire data set.
80
-		 *
81
-		 * @param array $properties this array if key-value-pairs defines a contact
82
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
-		 * @return array representing the contact just created or updated
84
-		 */
85
-		public function createOrUpdate($properties, $addressBookKey) {
86
-			$addressBook = $this->getAddressBook($addressBookKey);
87
-			if (!$addressBook) {
88
-				return null;
89
-			}
90
-
91
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
-				return $addressBook->createOrUpdate($properties);
93
-			}
94
-
95
-			return null;
96
-		}
97
-
98
-		/**
99
-		 * Check if contacts are available (e.g. contacts app enabled)
100
-		 *
101
-		 * @return bool true if enabled, false if not
102
-		 */
103
-		public function isEnabled() {
104
-			return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
-		}
106
-
107
-		/**
108
-		 * @param \OCP\IAddressBook $addressBook
109
-		 */
110
-		public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
-			$this->addressBooks[$addressBook->getKey()] = $addressBook;
112
-		}
113
-
114
-		/**
115
-		 * @param \OCP\IAddressBook $addressBook
116
-		 */
117
-		public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
-			unset($this->addressBooks[$addressBook->getKey()]);
119
-		}
120
-
121
-		/**
122
-		 * @return array
123
-		 */
124
-		public function getAddressBooks() {
125
-			$this->loadAddressBooks();
126
-			$result = array();
127
-			foreach($this->addressBooks as $addressBook) {
128
-				$result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
-			}
130
-
131
-			return $result;
132
-		}
133
-
134
-		/**
135
-		 * removes all registered address book instances
136
-		 */
137
-		public function clear() {
138
-			$this->addressBooks = array();
139
-			$this->addressBookLoaders = array();
140
-		}
141
-
142
-		/**
143
-		 * @var \OCP\IAddressBook[] which holds all registered address books
144
-		 */
145
-		private $addressBooks = array();
146
-
147
-		/**
148
-		 * @var \Closure[] to call to load/register address books
149
-		 */
150
-		private $addressBookLoaders = array();
151
-
152
-		/**
153
-		 * In order to improve lazy loading a closure can be registered which will be called in case
154
-		 * address books are actually requested
155
-		 *
156
-		 * @param \Closure $callable
157
-		 */
158
-		public function register(\Closure $callable)
159
-		{
160
-			$this->addressBookLoaders[] = $callable;
161
-		}
162
-
163
-		/**
164
-		 * Get (and load when needed) the address book for $key
165
-		 *
166
-		 * @param string $addressBookKey
167
-		 * @return \OCP\IAddressBook
168
-		 */
169
-		protected function getAddressBook($addressBookKey)
170
-		{
171
-			$this->loadAddressBooks();
172
-			if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
-				return null;
174
-			}
175
-
176
-			return $this->addressBooks[$addressBookKey];
177
-		}
178
-
179
-		/**
180
-		 * Load all address books registered with 'register'
181
-		 */
182
-		protected function loadAddressBooks()
183
-		{
184
-			foreach($this->addressBookLoaders as $callable) {
185
-				$callable($this);
186
-			}
187
-			$this->addressBookLoaders = array();
188
-		}
189
-	}
30
+    class ContactsManager implements \OCP\Contacts\IManager {
31
+
32
+        /**
33
+         * This function is used to search and find contacts within the users address books.
34
+         * In case $pattern is empty all contacts will be returned.
35
+         *
36
+         * @param string $pattern which should match within the $searchProperties
37
+         * @param array $searchProperties defines the properties within the query pattern should match
38
+         * @param array $options - for future use. One should always have options!
39
+         * @return array an array of contacts which are arrays of key-value-pairs
40
+         */
41
+        public function search($pattern, $searchProperties = array(), $options = array()) {
42
+            $this->loadAddressBooks();
43
+            $result = array();
44
+            foreach($this->addressBooks as $addressBook) {
45
+                $r = $addressBook->search($pattern, $searchProperties, $options);
46
+                $contacts = array();
47
+                foreach($r as $c){
48
+                    $c['addressbook-key'] = $addressBook->getKey();
49
+                    $contacts[] = $c;
50
+                }
51
+                $result = array_merge($result, $contacts);
52
+            }
53
+
54
+            return $result;
55
+        }
56
+
57
+        /**
58
+         * This function can be used to delete the contact identified by the given id
59
+         *
60
+         * @param object $id the unique identifier to a contact
61
+         * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
+         * @return bool successful or not
63
+         */
64
+        public function delete($id, $addressBookKey) {
65
+            $addressBook = $this->getAddressBook($addressBookKey);
66
+            if (!$addressBook) {
67
+                return null;
68
+            }
69
+
70
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
+                return $addressBook->delete($id);
72
+            }
73
+
74
+            return null;
75
+        }
76
+
77
+        /**
78
+         * This function is used to create a new contact if 'id' is not given or not present.
79
+         * Otherwise the contact will be updated by replacing the entire data set.
80
+         *
81
+         * @param array $properties this array if key-value-pairs defines a contact
82
+         * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
+         * @return array representing the contact just created or updated
84
+         */
85
+        public function createOrUpdate($properties, $addressBookKey) {
86
+            $addressBook = $this->getAddressBook($addressBookKey);
87
+            if (!$addressBook) {
88
+                return null;
89
+            }
90
+
91
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
+                return $addressBook->createOrUpdate($properties);
93
+            }
94
+
95
+            return null;
96
+        }
97
+
98
+        /**
99
+         * Check if contacts are available (e.g. contacts app enabled)
100
+         *
101
+         * @return bool true if enabled, false if not
102
+         */
103
+        public function isEnabled() {
104
+            return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
+        }
106
+
107
+        /**
108
+         * @param \OCP\IAddressBook $addressBook
109
+         */
110
+        public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
+            $this->addressBooks[$addressBook->getKey()] = $addressBook;
112
+        }
113
+
114
+        /**
115
+         * @param \OCP\IAddressBook $addressBook
116
+         */
117
+        public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
+            unset($this->addressBooks[$addressBook->getKey()]);
119
+        }
120
+
121
+        /**
122
+         * @return array
123
+         */
124
+        public function getAddressBooks() {
125
+            $this->loadAddressBooks();
126
+            $result = array();
127
+            foreach($this->addressBooks as $addressBook) {
128
+                $result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
+            }
130
+
131
+            return $result;
132
+        }
133
+
134
+        /**
135
+         * removes all registered address book instances
136
+         */
137
+        public function clear() {
138
+            $this->addressBooks = array();
139
+            $this->addressBookLoaders = array();
140
+        }
141
+
142
+        /**
143
+         * @var \OCP\IAddressBook[] which holds all registered address books
144
+         */
145
+        private $addressBooks = array();
146
+
147
+        /**
148
+         * @var \Closure[] to call to load/register address books
149
+         */
150
+        private $addressBookLoaders = array();
151
+
152
+        /**
153
+         * In order to improve lazy loading a closure can be registered which will be called in case
154
+         * address books are actually requested
155
+         *
156
+         * @param \Closure $callable
157
+         */
158
+        public function register(\Closure $callable)
159
+        {
160
+            $this->addressBookLoaders[] = $callable;
161
+        }
162
+
163
+        /**
164
+         * Get (and load when needed) the address book for $key
165
+         *
166
+         * @param string $addressBookKey
167
+         * @return \OCP\IAddressBook
168
+         */
169
+        protected function getAddressBook($addressBookKey)
170
+        {
171
+            $this->loadAddressBooks();
172
+            if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
+                return null;
174
+            }
175
+
176
+            return $this->addressBooks[$addressBookKey];
177
+        }
178
+
179
+        /**
180
+         * Load all address books registered with 'register'
181
+         */
182
+        protected function loadAddressBooks()
183
+        {
184
+            foreach($this->addressBookLoaders as $callable) {
185
+                $callable($this);
186
+            }
187
+            $this->addressBookLoaders = array();
188
+        }
189
+    }
190 190
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 		public function search($pattern, $searchProperties = array(), $options = array()) {
42 42
 			$this->loadAddressBooks();
43 43
 			$result = array();
44
-			foreach($this->addressBooks as $addressBook) {
44
+			foreach ($this->addressBooks as $addressBook) {
45 45
 				$r = $addressBook->search($pattern, $searchProperties, $options);
46 46
 				$contacts = array();
47
-				foreach($r as $c){
47
+				foreach ($r as $c) {
48 48
 					$c['addressbook-key'] = $addressBook->getKey();
49 49
 					$contacts[] = $c;
50 50
 				}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		public function getAddressBooks() {
125 125
 			$this->loadAddressBooks();
126 126
 			$result = array();
127
-			foreach($this->addressBooks as $addressBook) {
127
+			foreach ($this->addressBooks as $addressBook) {
128 128
 				$result[$addressBook->getKey()] = $addressBook->getDisplayName();
129 129
 			}
130 130
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 */
182 182
 		protected function loadAddressBooks()
183 183
 		{
184
-			foreach($this->addressBookLoaders as $callable) {
184
+			foreach ($this->addressBookLoaders as $callable) {
185 185
 				$callable($this);
186 186
 			}
187 187
 			$this->addressBookLoaders = array();
Please login to merge, or discard this patch.
lib/private/Archive/ZIP.php 3 patches
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		$this->path=$source;
48 48
 		$this->zip=new \ZipArchive();
49 49
 		if($this->zip->open($source, \ZipArchive::CREATE)) {
50
-		}else{
50
+		} else{
51 51
 			\OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
52 52
 		}
53 53
 	}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	function addFile($path, $source='') {
69 69
 		if($source and $source[0]=='/' and file_exists($source)) {
70 70
 			$result=$this->zip->addFile($source, $path);
71
-		}else{
71
+		} else{
72 72
 			$result=$this->zip->addFromString($path, $source);
73 73
 		}
74 74
 		if($result) {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	function remove($path) {
178 178
 		if($this->fileExists($path.'/')) {
179 179
 			return $this->zip->deleteName($path.'/');
180
-		}else{
180
+		} else{
181 181
 			return $this->zip->deleteName($path);
182 182
 		}
183 183
 	}
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 			//in the archive when the stream is closed
197 197
 			if(strrpos($path, '.')!==false) {
198 198
 				$ext=substr($path, strrpos($path, '.'));
199
-			}else{
199
+			} else{
200 200
 				$ext='';
201 201
 			}
202 202
 			$tmpFile=\OCP\Files::tmpFile($ext);
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	private function stripPath($path) {
226 226
 		if(!$path || $path[0]=='/') {
227 227
 			return substr($path, 1);
228
-		}else{
228
+		} else{
229 229
 			return $path;
230 230
 		}
231 231
 	}
Please login to merge, or discard this patch.
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -32,201 +32,201 @@
 block discarded – undo
32 32
 namespace OC\Archive;
33 33
 
34 34
 class ZIP extends Archive{
35
-	/**
36
-	 * @var \ZipArchive zip
37
-	 */
38
-	private $zip=null;
39
-	private $path;
35
+    /**
36
+     * @var \ZipArchive zip
37
+     */
38
+    private $zip=null;
39
+    private $path;
40 40
 
41
-	/**
42
-	 * @param string $source
43
-	 */
44
-	function __construct($source) {
45
-		$this->path=$source;
46
-		$this->zip=new \ZipArchive();
47
-		if($this->zip->open($source, \ZipArchive::CREATE)) {
48
-		}else{
49
-			\OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
50
-		}
51
-	}
52
-	/**
53
-	 * add an empty folder to the archive
54
-	 * @param string $path
55
-	 * @return bool
56
-	 */
57
-	function addFolder($path) {
58
-		return $this->zip->addEmptyDir($path);
59
-	}
60
-	/**
61
-	 * add a file to the archive
62
-	 * @param string $path
63
-	 * @param string $source either a local file or string data
64
-	 * @return bool
65
-	 */
66
-	function addFile($path, $source='') {
67
-		if($source and $source[0]=='/' and file_exists($source)) {
68
-			$result=$this->zip->addFile($source, $path);
69
-		}else{
70
-			$result=$this->zip->addFromString($path, $source);
71
-		}
72
-		if($result) {
73
-			$this->zip->close();//close and reopen to save the zip
74
-			$this->zip->open($this->path);
75
-		}
76
-		return $result;
77
-	}
78
-	/**
79
-	 * rename a file or folder in the archive
80
-	 * @param string $source
81
-	 * @param string $dest
82
-	 * @return boolean|null
83
-	 */
84
-	function rename($source, $dest) {
85
-		$source=$this->stripPath($source);
86
-		$dest=$this->stripPath($dest);
87
-		$this->zip->renameName($source, $dest);
88
-	}
89
-	/**
90
-	 * get the uncompressed size of a file in the archive
91
-	 * @param string $path
92
-	 * @return int
93
-	 */
94
-	function filesize($path) {
95
-		$stat=$this->zip->statName($path);
96
-		return $stat['size'];
97
-	}
98
-	/**
99
-	 * get the last modified time of a file in the archive
100
-	 * @param string $path
101
-	 * @return int
102
-	 */
103
-	function mtime($path) {
104
-		return filemtime($this->path);
105
-	}
106
-	/**
107
-	 * get the files in a folder
108
-	 * @param string $path
109
-	 * @return array
110
-	 */
111
-	function getFolder($path) {
112
-		$files=$this->getFiles();
113
-		$folderContent=array();
114
-		$pathLength=strlen($path);
115
-		foreach($files as $file) {
116
-			if(substr($file, 0, $pathLength)==$path and $file!=$path) {
117
-				if(strrpos(substr($file, 0, -1), '/')<=$pathLength) {
118
-					$folderContent[]=substr($file, $pathLength);
119
-				}
120
-			}
121
-		}
122
-		return $folderContent;
123
-	}
124
-	/**
125
-	 * get all files in the archive
126
-	 * @return array
127
-	 */
128
-	function getFiles() {
129
-		$fileCount=$this->zip->numFiles;
130
-		$files=array();
131
-		for($i=0;$i<$fileCount;$i++) {
132
-			$files[]=$this->zip->getNameIndex($i);
133
-		}
134
-		return $files;
135
-	}
136
-	/**
137
-	 * get the content of a file
138
-	 * @param string $path
139
-	 * @return string
140
-	 */
141
-	function getFile($path) {
142
-		return $this->zip->getFromName($path);
143
-	}
144
-	/**
145
-	 * extract a single file from the archive
146
-	 * @param string $path
147
-	 * @param string $dest
148
-	 * @return boolean|null
149
-	 */
150
-	function extractFile($path, $dest) {
151
-		$fp = $this->zip->getStream($path);
152
-		file_put_contents($dest, $fp);
153
-	}
154
-	/**
155
-	 * extract the archive
156
-	 * @param string $dest
157
-	 * @return bool
158
-	 */
159
-	function extract($dest) {
160
-		return $this->zip->extractTo($dest);
161
-	}
162
-	/**
163
-	 * check if a file or folder exists in the archive
164
-	 * @param string $path
165
-	 * @return bool
166
-	 */
167
-	function fileExists($path) {
168
-		return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
169
-	}
170
-	/**
171
-	 * remove a file or folder from the archive
172
-	 * @param string $path
173
-	 * @return bool
174
-	 */
175
-	function remove($path) {
176
-		if($this->fileExists($path.'/')) {
177
-			return $this->zip->deleteName($path.'/');
178
-		}else{
179
-			return $this->zip->deleteName($path);
180
-		}
181
-	}
182
-	/**
183
-	 * get a file handler
184
-	 * @param string $path
185
-	 * @param string $mode
186
-	 * @return resource
187
-	 */
188
-	function getStream($path, $mode) {
189
-		if($mode=='r' or $mode=='rb') {
190
-			return $this->zip->getStream($path);
191
-		} else {
192
-			//since we can't directly get a writable stream,
193
-			//make a temp copy of the file and put it back
194
-			//in the archive when the stream is closed
195
-			if(strrpos($path, '.')!==false) {
196
-				$ext=substr($path, strrpos($path, '.'));
197
-			}else{
198
-				$ext='';
199
-			}
200
-			$tmpFile=\OCP\Files::tmpFile($ext);
201
-			\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
202
-			if($this->fileExists($path)) {
203
-				$this->extractFile($path, $tmpFile);
204
-			}
205
-			self::$tempFiles[$tmpFile]=$path;
206
-			return fopen('close://'.$tmpFile, $mode);
207
-		}
208
-	}
41
+    /**
42
+     * @param string $source
43
+     */
44
+    function __construct($source) {
45
+        $this->path=$source;
46
+        $this->zip=new \ZipArchive();
47
+        if($this->zip->open($source, \ZipArchive::CREATE)) {
48
+        }else{
49
+            \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
50
+        }
51
+    }
52
+    /**
53
+     * add an empty folder to the archive
54
+     * @param string $path
55
+     * @return bool
56
+     */
57
+    function addFolder($path) {
58
+        return $this->zip->addEmptyDir($path);
59
+    }
60
+    /**
61
+     * add a file to the archive
62
+     * @param string $path
63
+     * @param string $source either a local file or string data
64
+     * @return bool
65
+     */
66
+    function addFile($path, $source='') {
67
+        if($source and $source[0]=='/' and file_exists($source)) {
68
+            $result=$this->zip->addFile($source, $path);
69
+        }else{
70
+            $result=$this->zip->addFromString($path, $source);
71
+        }
72
+        if($result) {
73
+            $this->zip->close();//close and reopen to save the zip
74
+            $this->zip->open($this->path);
75
+        }
76
+        return $result;
77
+    }
78
+    /**
79
+     * rename a file or folder in the archive
80
+     * @param string $source
81
+     * @param string $dest
82
+     * @return boolean|null
83
+     */
84
+    function rename($source, $dest) {
85
+        $source=$this->stripPath($source);
86
+        $dest=$this->stripPath($dest);
87
+        $this->zip->renameName($source, $dest);
88
+    }
89
+    /**
90
+     * get the uncompressed size of a file in the archive
91
+     * @param string $path
92
+     * @return int
93
+     */
94
+    function filesize($path) {
95
+        $stat=$this->zip->statName($path);
96
+        return $stat['size'];
97
+    }
98
+    /**
99
+     * get the last modified time of a file in the archive
100
+     * @param string $path
101
+     * @return int
102
+     */
103
+    function mtime($path) {
104
+        return filemtime($this->path);
105
+    }
106
+    /**
107
+     * get the files in a folder
108
+     * @param string $path
109
+     * @return array
110
+     */
111
+    function getFolder($path) {
112
+        $files=$this->getFiles();
113
+        $folderContent=array();
114
+        $pathLength=strlen($path);
115
+        foreach($files as $file) {
116
+            if(substr($file, 0, $pathLength)==$path and $file!=$path) {
117
+                if(strrpos(substr($file, 0, -1), '/')<=$pathLength) {
118
+                    $folderContent[]=substr($file, $pathLength);
119
+                }
120
+            }
121
+        }
122
+        return $folderContent;
123
+    }
124
+    /**
125
+     * get all files in the archive
126
+     * @return array
127
+     */
128
+    function getFiles() {
129
+        $fileCount=$this->zip->numFiles;
130
+        $files=array();
131
+        for($i=0;$i<$fileCount;$i++) {
132
+            $files[]=$this->zip->getNameIndex($i);
133
+        }
134
+        return $files;
135
+    }
136
+    /**
137
+     * get the content of a file
138
+     * @param string $path
139
+     * @return string
140
+     */
141
+    function getFile($path) {
142
+        return $this->zip->getFromName($path);
143
+    }
144
+    /**
145
+     * extract a single file from the archive
146
+     * @param string $path
147
+     * @param string $dest
148
+     * @return boolean|null
149
+     */
150
+    function extractFile($path, $dest) {
151
+        $fp = $this->zip->getStream($path);
152
+        file_put_contents($dest, $fp);
153
+    }
154
+    /**
155
+     * extract the archive
156
+     * @param string $dest
157
+     * @return bool
158
+     */
159
+    function extract($dest) {
160
+        return $this->zip->extractTo($dest);
161
+    }
162
+    /**
163
+     * check if a file or folder exists in the archive
164
+     * @param string $path
165
+     * @return bool
166
+     */
167
+    function fileExists($path) {
168
+        return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
169
+    }
170
+    /**
171
+     * remove a file or folder from the archive
172
+     * @param string $path
173
+     * @return bool
174
+     */
175
+    function remove($path) {
176
+        if($this->fileExists($path.'/')) {
177
+            return $this->zip->deleteName($path.'/');
178
+        }else{
179
+            return $this->zip->deleteName($path);
180
+        }
181
+    }
182
+    /**
183
+     * get a file handler
184
+     * @param string $path
185
+     * @param string $mode
186
+     * @return resource
187
+     */
188
+    function getStream($path, $mode) {
189
+        if($mode=='r' or $mode=='rb') {
190
+            return $this->zip->getStream($path);
191
+        } else {
192
+            //since we can't directly get a writable stream,
193
+            //make a temp copy of the file and put it back
194
+            //in the archive when the stream is closed
195
+            if(strrpos($path, '.')!==false) {
196
+                $ext=substr($path, strrpos($path, '.'));
197
+            }else{
198
+                $ext='';
199
+            }
200
+            $tmpFile=\OCP\Files::tmpFile($ext);
201
+            \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
202
+            if($this->fileExists($path)) {
203
+                $this->extractFile($path, $tmpFile);
204
+            }
205
+            self::$tempFiles[$tmpFile]=$path;
206
+            return fopen('close://'.$tmpFile, $mode);
207
+        }
208
+    }
209 209
 
210
-	private static $tempFiles=array();
211
-	/**
212
-	 * write back temporary files
213
-	 */
214
-	function writeBack($tmpFile) {
215
-		if(isset(self::$tempFiles[$tmpFile])) {
216
-			$this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
217
-			unlink($tmpFile);
218
-		}
219
-	}
210
+    private static $tempFiles=array();
211
+    /**
212
+     * write back temporary files
213
+     */
214
+    function writeBack($tmpFile) {
215
+        if(isset(self::$tempFiles[$tmpFile])) {
216
+            $this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
217
+            unlink($tmpFile);
218
+        }
219
+    }
220 220
 
221
-	/**
222
-	 * @param string $path
223
-	 * @return string
224
-	 */
225
-	private function stripPath($path) {
226
-		if(!$path || $path[0]=='/') {
227
-			return substr($path, 1);
228
-		}else{
229
-			return $path;
230
-		}
231
-	}
221
+    /**
222
+     * @param string $path
223
+     * @return string
224
+     */
225
+    private function stripPath($path) {
226
+        if(!$path || $path[0]=='/') {
227
+            return substr($path, 1);
228
+        }else{
229
+            return $path;
230
+        }
231
+    }
232 232
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -31,21 +31,21 @@  discard block
 block discarded – undo
31 31
 
32 32
 namespace OC\Archive;
33 33
 
34
-class ZIP extends Archive{
34
+class ZIP extends Archive {
35 35
 	/**
36 36
 	 * @var \ZipArchive zip
37 37
 	 */
38
-	private $zip=null;
38
+	private $zip = null;
39 39
 	private $path;
40 40
 
41 41
 	/**
42 42
 	 * @param string $source
43 43
 	 */
44 44
 	function __construct($source) {
45
-		$this->path=$source;
46
-		$this->zip=new \ZipArchive();
47
-		if($this->zip->open($source, \ZipArchive::CREATE)) {
48
-		}else{
45
+		$this->path = $source;
46
+		$this->zip = new \ZipArchive();
47
+		if ($this->zip->open($source, \ZipArchive::CREATE)) {
48
+		} else {
49 49
 			\OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN);
50 50
 		}
51 51
 	}
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
 	 * @param string $source either a local file or string data
64 64
 	 * @return bool
65 65
 	 */
66
-	function addFile($path, $source='') {
67
-		if($source and $source[0]=='/' and file_exists($source)) {
68
-			$result=$this->zip->addFile($source, $path);
69
-		}else{
70
-			$result=$this->zip->addFromString($path, $source);
66
+	function addFile($path, $source = '') {
67
+		if ($source and $source[0] == '/' and file_exists($source)) {
68
+			$result = $this->zip->addFile($source, $path);
69
+		} else {
70
+			$result = $this->zip->addFromString($path, $source);
71 71
 		}
72
-		if($result) {
73
-			$this->zip->close();//close and reopen to save the zip
72
+		if ($result) {
73
+			$this->zip->close(); //close and reopen to save the zip
74 74
 			$this->zip->open($this->path);
75 75
 		}
76 76
 		return $result;
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @return boolean|null
83 83
 	 */
84 84
 	function rename($source, $dest) {
85
-		$source=$this->stripPath($source);
86
-		$dest=$this->stripPath($dest);
85
+		$source = $this->stripPath($source);
86
+		$dest = $this->stripPath($dest);
87 87
 		$this->zip->renameName($source, $dest);
88 88
 	}
89 89
 	/**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @return int
93 93
 	 */
94 94
 	function filesize($path) {
95
-		$stat=$this->zip->statName($path);
95
+		$stat = $this->zip->statName($path);
96 96
 		return $stat['size'];
97 97
 	}
98 98
 	/**
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 	 * @return array
110 110
 	 */
111 111
 	function getFolder($path) {
112
-		$files=$this->getFiles();
113
-		$folderContent=array();
114
-		$pathLength=strlen($path);
115
-		foreach($files as $file) {
116
-			if(substr($file, 0, $pathLength)==$path and $file!=$path) {
117
-				if(strrpos(substr($file, 0, -1), '/')<=$pathLength) {
118
-					$folderContent[]=substr($file, $pathLength);
112
+		$files = $this->getFiles();
113
+		$folderContent = array();
114
+		$pathLength = strlen($path);
115
+		foreach ($files as $file) {
116
+			if (substr($file, 0, $pathLength) == $path and $file != $path) {
117
+				if (strrpos(substr($file, 0, -1), '/') <= $pathLength) {
118
+					$folderContent[] = substr($file, $pathLength);
119 119
 				}
120 120
 			}
121 121
 		}
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 	 * @return array
127 127
 	 */
128 128
 	function getFiles() {
129
-		$fileCount=$this->zip->numFiles;
130
-		$files=array();
131
-		for($i=0;$i<$fileCount;$i++) {
132
-			$files[]=$this->zip->getNameIndex($i);
129
+		$fileCount = $this->zip->numFiles;
130
+		$files = array();
131
+		for ($i = 0; $i < $fileCount; $i++) {
132
+			$files[] = $this->zip->getNameIndex($i);
133 133
 		}
134 134
 		return $files;
135 135
 	}
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	function fileExists($path) {
168
-		return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false);
168
+		return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false);
169 169
 	}
170 170
 	/**
171 171
 	 * remove a file or folder from the archive
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
 	 * @return bool
174 174
 	 */
175 175
 	function remove($path) {
176
-		if($this->fileExists($path.'/')) {
176
+		if ($this->fileExists($path.'/')) {
177 177
 			return $this->zip->deleteName($path.'/');
178
-		}else{
178
+		} else {
179 179
 			return $this->zip->deleteName($path);
180 180
 		}
181 181
 	}
@@ -186,33 +186,33 @@  discard block
 block discarded – undo
186 186
 	 * @return resource
187 187
 	 */
188 188
 	function getStream($path, $mode) {
189
-		if($mode=='r' or $mode=='rb') {
189
+		if ($mode == 'r' or $mode == 'rb') {
190 190
 			return $this->zip->getStream($path);
191 191
 		} else {
192 192
 			//since we can't directly get a writable stream,
193 193
 			//make a temp copy of the file and put it back
194 194
 			//in the archive when the stream is closed
195
-			if(strrpos($path, '.')!==false) {
196
-				$ext=substr($path, strrpos($path, '.'));
197
-			}else{
198
-				$ext='';
195
+			if (strrpos($path, '.') !== false) {
196
+				$ext = substr($path, strrpos($path, '.'));
197
+			} else {
198
+				$ext = '';
199 199
 			}
200
-			$tmpFile=\OCP\Files::tmpFile($ext);
200
+			$tmpFile = \OCP\Files::tmpFile($ext);
201 201
 			\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
202
-			if($this->fileExists($path)) {
202
+			if ($this->fileExists($path)) {
203 203
 				$this->extractFile($path, $tmpFile);
204 204
 			}
205
-			self::$tempFiles[$tmpFile]=$path;
205
+			self::$tempFiles[$tmpFile] = $path;
206 206
 			return fopen('close://'.$tmpFile, $mode);
207 207
 		}
208 208
 	}
209 209
 
210
-	private static $tempFiles=array();
210
+	private static $tempFiles = array();
211 211
 	/**
212 212
 	 * write back temporary files
213 213
 	 */
214 214
 	function writeBack($tmpFile) {
215
-		if(isset(self::$tempFiles[$tmpFile])) {
215
+		if (isset(self::$tempFiles[$tmpFile])) {
216 216
 			$this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
217 217
 			unlink($tmpFile);
218 218
 		}
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
 	 * @return string
224 224
 	 */
225 225
 	private function stripPath($path) {
226
-		if(!$path || $path[0]=='/') {
226
+		if (!$path || $path[0] == '/') {
227 227
 			return substr($path, 1);
228
-		}else{
228
+		} else {
229 229
 			return $path;
230 230
 		}
231 231
 	}
Please login to merge, or discard this patch.
lib/private/Archive/Archive.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 				}
135 135
 				if(is_dir($source.'/'.$file)) {
136 136
 					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
-				}else{
137
+				} else{
138 138
 					$this->addFile($path.'/'.$file, $source.'/'.$file);
139 139
 				}
140 140
 			}
Please login to merge, or discard this patch.
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -33,130 +33,130 @@
 block discarded – undo
33 33
 namespace OC\Archive;
34 34
 
35 35
 abstract class Archive{
36
-	/**
37
-	 * Open any of the supported archive types
38
-	 *
39
-	 * @param string $path
40
-	 * @return Archive|void
41
-	 */
42
-	public static function open($path) {
43
-		$mime = \OC::$server->getMimeTypeDetector()->detect($path);
36
+    /**
37
+     * Open any of the supported archive types
38
+     *
39
+     * @param string $path
40
+     * @return Archive|void
41
+     */
42
+    public static function open($path) {
43
+        $mime = \OC::$server->getMimeTypeDetector()->detect($path);
44 44
 
45
-		switch($mime) {
46
-			case 'application/zip':
47
-				return new ZIP($path);
48
-			case 'application/x-gzip':
49
-				return new TAR($path);
50
-			case 'application/x-bzip2':
51
-				return new TAR($path);
52
-		}
53
-	}
45
+        switch($mime) {
46
+            case 'application/zip':
47
+                return new ZIP($path);
48
+            case 'application/x-gzip':
49
+                return new TAR($path);
50
+            case 'application/x-bzip2':
51
+                return new TAR($path);
52
+        }
53
+    }
54 54
 
55
-	/**
56
-	 * @param $source
57
-	 */
58
-	abstract function __construct($source);
59
-	/**
60
-	 * add an empty folder to the archive
61
-	 * @param string $path
62
-	 * @return bool
63
-	 */
64
-	abstract function addFolder($path);
65
-	/**
66
-	 * add a file to the archive
67
-	 * @param string $path
68
-	 * @param string $source either a local file or string data
69
-	 * @return bool
70
-	 */
71
-	abstract function addFile($path, $source='');
72
-	/**
73
-	 * rename a file or folder in the archive
74
-	 * @param string $source
75
-	 * @param string $dest
76
-	 * @return bool
77
-	 */
78
-	abstract function rename($source, $dest);
79
-	/**
80
-	 * get the uncompressed size of a file in the archive
81
-	 * @param string $path
82
-	 * @return int
83
-	 */
84
-	abstract function filesize($path);
85
-	/**
86
-	 * get the last modified time of a file in the archive
87
-	 * @param string $path
88
-	 * @return int
89
-	 */
90
-	abstract function mtime($path);
91
-	/**
92
-	 * get the files in a folder
93
-	 * @param string $path
94
-	 * @return array
95
-	 */
96
-	abstract function getFolder($path);
97
-	/**
98
-	 * get all files in the archive
99
-	 * @return array
100
-	 */
101
-	abstract function getFiles();
102
-	/**
103
-	 * get the content of a file
104
-	 * @param string $path
105
-	 * @return string
106
-	 */
107
-	abstract function getFile($path);
108
-	/**
109
-	 * extract a single file from the archive
110
-	 * @param string $path
111
-	 * @param string $dest
112
-	 * @return bool
113
-	 */
114
-	abstract function extractFile($path, $dest);
115
-	/**
116
-	 * extract the archive
117
-	 * @param string $dest
118
-	 * @return bool
119
-	 */
120
-	abstract function extract($dest);
121
-	/**
122
-	 * check if a file or folder exists in the archive
123
-	 * @param string $path
124
-	 * @return bool
125
-	 */
126
-	abstract function fileExists($path);
127
-	/**
128
-	 * remove a file or folder from the archive
129
-	 * @param string $path
130
-	 * @return bool
131
-	 */
132
-	abstract function remove($path);
133
-	/**
134
-	 * get a file handler
135
-	 * @param string $path
136
-	 * @param string $mode
137
-	 * @return resource
138
-	 */
139
-	abstract function getStream($path, $mode);
140
-	/**
141
-	 * add a folder and all its content
142
-	 * @param string $path
143
-	 * @param string $source
144
-	 * @return boolean|null
145
-	 */
146
-	function addRecursive($path, $source) {
147
-		$dh = opendir($source);
148
-		if(is_resource($dh)) {
149
-			$this->addFolder($path);
150
-			while (($file = readdir($dh)) !== false) {
151
-				if($file=='.' or $file=='..') {
152
-					continue;
153
-				}
154
-				if(is_dir($source.'/'.$file)) {
155
-					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
156
-				}else{
157
-					$this->addFile($path.'/'.$file, $source.'/'.$file);
158
-				}
159
-			}
160
-		}
161
-	}
55
+    /**
56
+     * @param $source
57
+     */
58
+    abstract function __construct($source);
59
+    /**
60
+     * add an empty folder to the archive
61
+     * @param string $path
62
+     * @return bool
63
+     */
64
+    abstract function addFolder($path);
65
+    /**
66
+     * add a file to the archive
67
+     * @param string $path
68
+     * @param string $source either a local file or string data
69
+     * @return bool
70
+     */
71
+    abstract function addFile($path, $source='');
72
+    /**
73
+     * rename a file or folder in the archive
74
+     * @param string $source
75
+     * @param string $dest
76
+     * @return bool
77
+     */
78
+    abstract function rename($source, $dest);
79
+    /**
80
+     * get the uncompressed size of a file in the archive
81
+     * @param string $path
82
+     * @return int
83
+     */
84
+    abstract function filesize($path);
85
+    /**
86
+     * get the last modified time of a file in the archive
87
+     * @param string $path
88
+     * @return int
89
+     */
90
+    abstract function mtime($path);
91
+    /**
92
+     * get the files in a folder
93
+     * @param string $path
94
+     * @return array
95
+     */
96
+    abstract function getFolder($path);
97
+    /**
98
+     * get all files in the archive
99
+     * @return array
100
+     */
101
+    abstract function getFiles();
102
+    /**
103
+     * get the content of a file
104
+     * @param string $path
105
+     * @return string
106
+     */
107
+    abstract function getFile($path);
108
+    /**
109
+     * extract a single file from the archive
110
+     * @param string $path
111
+     * @param string $dest
112
+     * @return bool
113
+     */
114
+    abstract function extractFile($path, $dest);
115
+    /**
116
+     * extract the archive
117
+     * @param string $dest
118
+     * @return bool
119
+     */
120
+    abstract function extract($dest);
121
+    /**
122
+     * check if a file or folder exists in the archive
123
+     * @param string $path
124
+     * @return bool
125
+     */
126
+    abstract function fileExists($path);
127
+    /**
128
+     * remove a file or folder from the archive
129
+     * @param string $path
130
+     * @return bool
131
+     */
132
+    abstract function remove($path);
133
+    /**
134
+     * get a file handler
135
+     * @param string $path
136
+     * @param string $mode
137
+     * @return resource
138
+     */
139
+    abstract function getStream($path, $mode);
140
+    /**
141
+     * add a folder and all its content
142
+     * @param string $path
143
+     * @param string $source
144
+     * @return boolean|null
145
+     */
146
+    function addRecursive($path, $source) {
147
+        $dh = opendir($source);
148
+        if(is_resource($dh)) {
149
+            $this->addFolder($path);
150
+            while (($file = readdir($dh)) !== false) {
151
+                if($file=='.' or $file=='..') {
152
+                    continue;
153
+                }
154
+                if(is_dir($source.'/'.$file)) {
155
+                    $this->addRecursive($path.'/'.$file, $source.'/'.$file);
156
+                }else{
157
+                    $this->addFile($path.'/'.$file, $source.'/'.$file);
158
+                }
159
+            }
160
+        }
161
+    }
162 162
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 namespace OC\Archive;
34 34
 
35
-abstract class Archive{
35
+abstract class Archive {
36 36
 	/**
37 37
 	 * Open any of the supported archive types
38 38
 	 *
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public static function open($path) {
43 43
 		$mime = \OC::$server->getMimeTypeDetector()->detect($path);
44 44
 
45
-		switch($mime) {
45
+		switch ($mime) {
46 46
 			case 'application/zip':
47 47
 				return new ZIP($path);
48 48
 			case 'application/x-gzip':
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @param string $source either a local file or string data
69 69
 	 * @return bool
70 70
 	 */
71
-	abstract function addFile($path, $source='');
71
+	abstract function addFile($path, $source = '');
72 72
 	/**
73 73
 	 * rename a file or folder in the archive
74 74
 	 * @param string $source
@@ -145,15 +145,15 @@  discard block
 block discarded – undo
145 145
 	 */
146 146
 	function addRecursive($path, $source) {
147 147
 		$dh = opendir($source);
148
-		if(is_resource($dh)) {
148
+		if (is_resource($dh)) {
149 149
 			$this->addFolder($path);
150 150
 			while (($file = readdir($dh)) !== false) {
151
-				if($file=='.' or $file=='..') {
151
+				if ($file == '.' or $file == '..') {
152 152
 					continue;
153 153
 				}
154
-				if(is_dir($source.'/'.$file)) {
154
+				if (is_dir($source.'/'.$file)) {
155 155
 					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
156
-				}else{
156
+				} else {
157 157
 					$this->addFile($path.'/'.$file, $source.'/'.$file);
158 158
 				}
159 159
 			}
Please login to merge, or discard this patch.