Completed
Branch develop (eb876f)
by
unknown
21:14
created
htdocs/includes/restler/framework/Luracast/Restler/Format/iDecodeStream.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@
 block discarded – undo
16 16
 interface iDecodeStream
17 17
 {
18 18
 
19
-    /**
20
-     * Decode the given data stream
21
-     *
22
-     * @param string $stream A stream resource with data
23
-     *                       sent from client to the api
24
-     *                       in the given format.
25
-     *
26
-     * @return array associative array of the parsed data
27
-     */
28
-    public function decodeStream($stream);
19
+	/**
20
+	 * Decode the given data stream
21
+	 *
22
+	 * @param string $stream A stream resource with data
23
+	 *                       sent from client to the api
24
+	 *                       in the given format.
25
+	 *
26
+	 * @return array associative array of the parsed data
27
+	 */
28
+	public function decodeStream($stream);
29 29
 
30 30
 } 
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Redirect.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -16,53 +16,53 @@
 block discarded – undo
16 16
  */
17 17
 class Redirect
18 18
 {
19
-    /**
20
-     * Redirect to given url
21
-     *
22
-     * @param string $url       relative path or full url
23
-     * @param array  $params    associative array of query parameters
24
-     * @param array  $flashData associative array of properties to be set in $_SESSION for one time use
25
-     * @param int    $status    http status code to send the response with ideally 301 or 302
26
-     *
27
-     * @return array
28
-     */
29
-    public static function to($url, array $params = array(), array $flashData = array(), $status = 302)
30
-    {
31
-        $url = ltrim($url, '/');
32
-        /** @var $r Restler */
33
-        $r = Scope::get('Restler');
34
-        $base = $r->getBaseUrl() . '/';
35
-        if (0 !== strpos($url, 'http')) {
36
-            $url = $base . $url;
37
-        }
38
-        if (!empty($flashData) || $base . $r->url !== $url || Util::getRequestMethod() != 'GET') {
39
-            if ($r->responseFormat instanceof JsonFormat) {
40
-                return array('redirect' => $url);
41
-            }
42
-            if (!empty($params)) {
43
-                $url .= '?' . http_build_query($params);
44
-            }
45
-            Flash::set($flashData);
46
-            header(
47
-                "{$_SERVER['SERVER_PROTOCOL']} $status " .
48
-                (isset(RestException::$codes[$status]) ? RestException::$codes[$status] : '')
49
-            );
50
-            header("Location: $url");
51
-            die('');
52
-        }
19
+	/**
20
+	 * Redirect to given url
21
+	 *
22
+	 * @param string $url       relative path or full url
23
+	 * @param array  $params    associative array of query parameters
24
+	 * @param array  $flashData associative array of properties to be set in $_SESSION for one time use
25
+	 * @param int    $status    http status code to send the response with ideally 301 or 302
26
+	 *
27
+	 * @return array
28
+	 */
29
+	public static function to($url, array $params = array(), array $flashData = array(), $status = 302)
30
+	{
31
+		$url = ltrim($url, '/');
32
+		/** @var $r Restler */
33
+		$r = Scope::get('Restler');
34
+		$base = $r->getBaseUrl() . '/';
35
+		if (0 !== strpos($url, 'http')) {
36
+			$url = $base . $url;
37
+		}
38
+		if (!empty($flashData) || $base . $r->url !== $url || Util::getRequestMethod() != 'GET') {
39
+			if ($r->responseFormat instanceof JsonFormat) {
40
+				return array('redirect' => $url);
41
+			}
42
+			if (!empty($params)) {
43
+				$url .= '?' . http_build_query($params);
44
+			}
45
+			Flash::set($flashData);
46
+			header(
47
+				"{$_SERVER['SERVER_PROTOCOL']} $status " .
48
+				(isset(RestException::$codes[$status]) ? RestException::$codes[$status] : '')
49
+			);
50
+			header("Location: $url");
51
+			die('');
52
+		}
53 53
 
54
-        return array();
55
-    }
54
+		return array();
55
+	}
56 56
 
57
-    /**
58
-     * Redirect back to the previous page
59
-     *
60
-     * Makes use of http referrer for redirection
61
-     *
62
-     * @return array
63
-     */
64
-    public static function back()
65
-    {
66
-        return static::to($_SERVER['HTTP_REFERER']);
67
-    }
57
+	/**
58
+	 * Redirect back to the previous page
59
+	 *
60
+	 * Makes use of http referrer for redirection
61
+	 *
62
+	 * @return array
63
+	 */
64
+	public static function back()
65
+	{
66
+		return static::to($_SERVER['HTTP_REFERER']);
67
+	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,20 +31,20 @@
 block discarded – undo
31 31
         $url = ltrim($url, '/');
32 32
         /** @var $r Restler */
33 33
         $r = Scope::get('Restler');
34
-        $base = $r->getBaseUrl() . '/';
34
+        $base = $r->getBaseUrl().'/';
35 35
         if (0 !== strpos($url, 'http')) {
36
-            $url = $base . $url;
36
+            $url = $base.$url;
37 37
         }
38
-        if (!empty($flashData) || $base . $r->url !== $url || Util::getRequestMethod() != 'GET') {
38
+        if (!empty($flashData) || $base.$r->url !== $url || Util::getRequestMethod() != 'GET') {
39 39
             if ($r->responseFormat instanceof JsonFormat) {
40 40
                 return array('redirect' => $url);
41 41
             }
42 42
             if (!empty($params)) {
43
-                $url .= '?' . http_build_query($params);
43
+                $url .= '?'.http_build_query($params);
44 44
             }
45 45
             Flash::set($flashData);
46 46
             header(
47
-                "{$_SERVER['SERVER_PROTOCOL']} $status " .
47
+                "{$_SERVER['SERVER_PROTOCOL']} $status ".
48 48
                 (isset(RestException::$codes[$status]) ? RestException::$codes[$status] : '')
49 49
             );
50 50
             header("Location: $url");
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -14,116 +14,116 @@
 block discarded – undo
14 14
  */
15 15
 class HumanReadableCache implements iCache
16 16
 {
17
-    /**
18
-     * @var string path of the folder to hold cache files
19
-     */
20
-    public static $cacheDir;
17
+	/**
18
+	 * @var string path of the folder to hold cache files
19
+	 */
20
+	public static $cacheDir;
21 21
 
22
-    public function __construct()
23
-    {
24
-        if (is_null(self::$cacheDir)) {
25
-            self::$cacheDir = Defaults::$cacheDirectory;
26
-        }
27
-    }
22
+	public function __construct()
23
+	{
24
+		if (is_null(self::$cacheDir)) {
25
+			self::$cacheDir = Defaults::$cacheDirectory;
26
+		}
27
+	}
28 28
 
29
-    /**
30
-     * store data in the cache
31
-     *
32
-     * @param string $name
33
-     * @param mixed  $data
34
-     *
35
-     * @throws \Exception
36
-     * @return boolean true if successful
37
-     */
38
-    public function set($name, $data)
39
-    {
40
-        if (is_array($data)) {
41
-            $s = '$o = array();' . PHP_EOL . PHP_EOL;
42
-            $s .= '// ** THIS IS AN AUTO GENERATED FILE.'
43
-                . ' DO NOT EDIT MANUALLY ** ';
44
-            foreach ($data as $key => $value) {
45
-                $s .= PHP_EOL . PHP_EOL .
46
-                    "//==================== $key ===================="
47
-                    . PHP_EOL . PHP_EOL;
48
-                if (is_array($value)) {
49
-                    $s .= '$o[\'' . $key . '\'] = array();';
50
-                    foreach ($value as $ke => $va) {
51
-                        $s .= PHP_EOL . PHP_EOL . "//==== $key $ke ===="
52
-                            . PHP_EOL . PHP_EOL;
53
-                        $s .= '$o[\'' . $key . '\'][\'' . $ke . '\'] = ' .
54
-                            str_replace('  ', '    ',
55
-                                var_export($va, true)) . ';';
56
-                    }
57
-                } else {
58
-                    $s .= '$o[\'' . $key . '\'] = '
59
-                        . var_export($value, true) . ';';
60
-                }
61
-            }
62
-            $s .= PHP_EOL . 'return $o;';
63
-        } else {
64
-            $s = 'return ' . var_export($data, true) . ';';
65
-        }
66
-        $file = $this->_file($name);
67
-        $r = @file_put_contents($file, "<?php $s");
68
-        @chmod($file, 0777);
69
-        if ($r === false) {
70
-            $this->throwException();
71
-        }
72
-        return $r;
73
-    }
29
+	/**
30
+	 * store data in the cache
31
+	 *
32
+	 * @param string $name
33
+	 * @param mixed  $data
34
+	 *
35
+	 * @throws \Exception
36
+	 * @return boolean true if successful
37
+	 */
38
+	public function set($name, $data)
39
+	{
40
+		if (is_array($data)) {
41
+			$s = '$o = array();' . PHP_EOL . PHP_EOL;
42
+			$s .= '// ** THIS IS AN AUTO GENERATED FILE.'
43
+				. ' DO NOT EDIT MANUALLY ** ';
44
+			foreach ($data as $key => $value) {
45
+				$s .= PHP_EOL . PHP_EOL .
46
+					"//==================== $key ===================="
47
+					. PHP_EOL . PHP_EOL;
48
+				if (is_array($value)) {
49
+					$s .= '$o[\'' . $key . '\'] = array();';
50
+					foreach ($value as $ke => $va) {
51
+						$s .= PHP_EOL . PHP_EOL . "//==== $key $ke ===="
52
+							. PHP_EOL . PHP_EOL;
53
+						$s .= '$o[\'' . $key . '\'][\'' . $ke . '\'] = ' .
54
+							str_replace('  ', '    ',
55
+								var_export($va, true)) . ';';
56
+					}
57
+				} else {
58
+					$s .= '$o[\'' . $key . '\'] = '
59
+						. var_export($value, true) . ';';
60
+				}
61
+			}
62
+			$s .= PHP_EOL . 'return $o;';
63
+		} else {
64
+			$s = 'return ' . var_export($data, true) . ';';
65
+		}
66
+		$file = $this->_file($name);
67
+		$r = @file_put_contents($file, "<?php $s");
68
+		@chmod($file, 0777);
69
+		if ($r === false) {
70
+			$this->throwException();
71
+		}
72
+		return $r;
73
+	}
74 74
 
75
-    /**
76
-     * retrieve data from the cache
77
-     *
78
-     * @param string $name
79
-     * @param bool   $ignoreErrors
80
-     *
81
-     * @return mixed
82
-     */
83
-    public function get($name, $ignoreErrors = false)
84
-    {
85
-        $file = $this->_file($name);
86
-        if (file_exists($file)) {
87
-            return include($file);
88
-        }
89
-    }
75
+	/**
76
+	 * retrieve data from the cache
77
+	 *
78
+	 * @param string $name
79
+	 * @param bool   $ignoreErrors
80
+	 *
81
+	 * @return mixed
82
+	 */
83
+	public function get($name, $ignoreErrors = false)
84
+	{
85
+		$file = $this->_file($name);
86
+		if (file_exists($file)) {
87
+			return include($file);
88
+		}
89
+	}
90 90
 
91
-    /**
92
-     * delete data from the cache
93
-     *
94
-     * @param string $name
95
-     * @param bool   $ignoreErrors
96
-     *
97
-     * @return boolean true if successful
98
-     */
99
-    public function clear($name, $ignoreErrors = false)
100
-    {
101
-        return @unlink($this->_file($name));
102
-    }
91
+	/**
92
+	 * delete data from the cache
93
+	 *
94
+	 * @param string $name
95
+	 * @param bool   $ignoreErrors
96
+	 *
97
+	 * @return boolean true if successful
98
+	 */
99
+	public function clear($name, $ignoreErrors = false)
100
+	{
101
+		return @unlink($this->_file($name));
102
+	}
103 103
 
104
-    /**
105
-     * check if the given name is cached
106
-     *
107
-     * @param string $name
108
-     *
109
-     * @return boolean true if cached
110
-     */
111
-    public function isCached($name)
112
-    {
113
-        return file_exists($this->_file($name));
114
-    }
104
+	/**
105
+	 * check if the given name is cached
106
+	 *
107
+	 * @param string $name
108
+	 *
109
+	 * @return boolean true if cached
110
+	 */
111
+	public function isCached($name)
112
+	{
113
+		return file_exists($this->_file($name));
114
+	}
115 115
 
116
-    private function _file($name)
117
-    {
118
-        return self::$cacheDir . '/' . $name . '.php';
119
-    }
116
+	private function _file($name)
117
+	{
118
+		return self::$cacheDir . '/' . $name . '.php';
119
+	}
120 120
 
121
-    private function throwException()
122
-    {
123
-        throw new \Exception(
124
-            'The cache directory `'
125
-            . self::$cacheDir . '` should exist with write permission.'
126
-        );
127
-    }
121
+	private function throwException()
122
+	{
123
+		throw new \Exception(
124
+			'The cache directory `'
125
+			. self::$cacheDir . '` should exist with write permission.'
126
+		);
127
+	}
128 128
 }
129 129
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,30 +38,30 @@  discard block
 block discarded – undo
38 38
     public function set($name, $data)
39 39
     {
40 40
         if (is_array($data)) {
41
-            $s = '$o = array();' . PHP_EOL . PHP_EOL;
41
+            $s = '$o = array();'.PHP_EOL.PHP_EOL;
42 42
             $s .= '// ** THIS IS AN AUTO GENERATED FILE.'
43 43
                 . ' DO NOT EDIT MANUALLY ** ';
44 44
             foreach ($data as $key => $value) {
45
-                $s .= PHP_EOL . PHP_EOL .
45
+                $s .= PHP_EOL.PHP_EOL.
46 46
                     "//==================== $key ===================="
47
-                    . PHP_EOL . PHP_EOL;
47
+                    . PHP_EOL.PHP_EOL;
48 48
                 if (is_array($value)) {
49
-                    $s .= '$o[\'' . $key . '\'] = array();';
49
+                    $s .= '$o[\''.$key.'\'] = array();';
50 50
                     foreach ($value as $ke => $va) {
51
-                        $s .= PHP_EOL . PHP_EOL . "//==== $key $ke ===="
52
-                            . PHP_EOL . PHP_EOL;
53
-                        $s .= '$o[\'' . $key . '\'][\'' . $ke . '\'] = ' .
51
+                        $s .= PHP_EOL.PHP_EOL."//==== $key $ke ===="
52
+                            . PHP_EOL.PHP_EOL;
53
+                        $s .= '$o[\''.$key.'\'][\''.$ke.'\'] = '.
54 54
                             str_replace('  ', '    ',
55
-                                var_export($va, true)) . ';';
55
+                                var_export($va, true)).';';
56 56
                     }
57 57
                 } else {
58
-                    $s .= '$o[\'' . $key . '\'] = '
59
-                        . var_export($value, true) . ';';
58
+                    $s .= '$o[\''.$key.'\'] = '
59
+                        . var_export($value, true).';';
60 60
                 }
61 61
             }
62
-            $s .= PHP_EOL . 'return $o;';
62
+            $s .= PHP_EOL.'return $o;';
63 63
         } else {
64
-            $s = 'return ' . var_export($data, true) . ';';
64
+            $s = 'return '.var_export($data, true).';';
65 65
         }
66 66
         $file = $this->_file($name);
67 67
         $r = @file_put_contents($file, "<?php $s");
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 
116 116
     private function _file($name)
117 117
     {
118
-        return self::$cacheDir . '/' . $name . '.php';
118
+        return self::$cacheDir.'/'.$name.'.php';
119 119
     }
120 120
 
121 121
     private function throwException()
122 122
     {
123 123
         throw new \Exception(
124 124
             'The cache directory `'
125
-            . self::$cacheDir . '` should exist with write permission.'
125
+            . self::$cacheDir.'` should exist with write permission.'
126 126
         );
127 127
     }
128 128
 }
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Routes.php 4 patches
Indentation   +755 added lines, -755 removed lines patch added patch discarded remove patch
@@ -21,45 +21,45 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Routes
23 23
 {
24
-    public static $prefixingParameterNames = array(
25
-        'id'
26
-    );
24
+	public static $prefixingParameterNames = array(
25
+		'id'
26
+	);
27 27
 
28
-    public static $fieldTypesByName = array(
29
-        'email'       => 'email',
30
-        'password'    => 'password',
31
-        'phone'       => 'tel',
32
-        'mobile'      => 'tel',
33
-        'tel'         => 'tel',
34
-        'search'      => 'search',
35
-        'date'        => 'date',
36
-        'created_at'  => 'datetime',
37
-        'modified_at' => 'datetime',
38
-        'url'         => 'url',
39
-        'link'        => 'url',
40
-        'href'        => 'url',
41
-        'website'     => 'url',
42
-        'color'       => 'color',
43
-        'colour'      => 'color',
44
-    );
28
+	public static $fieldTypesByName = array(
29
+		'email'       => 'email',
30
+		'password'    => 'password',
31
+		'phone'       => 'tel',
32
+		'mobile'      => 'tel',
33
+		'tel'         => 'tel',
34
+		'search'      => 'search',
35
+		'date'        => 'date',
36
+		'created_at'  => 'datetime',
37
+		'modified_at' => 'datetime',
38
+		'url'         => 'url',
39
+		'link'        => 'url',
40
+		'href'        => 'url',
41
+		'website'     => 'url',
42
+		'color'       => 'color',
43
+		'colour'      => 'color',
44
+	);
45 45
 
46
-    protected static $routes = array();
46
+	protected static $routes = array();
47 47
 
48
-    protected static $models = array();
48
+	protected static $models = array();
49 49
 
50
-    /**
51
-     * Route the public and protected methods of an Api class
52
-     *
53
-     * @param string $className
54
-     * @param string $resourcePath
55
-     * @param int    $version
56
-     *
57
-     * @throws RestException
58
-     */
59
-    public static function addAPIClass($className, $resourcePath = '', $version = 1)
60
-    {
50
+	/**
51
+	 * Route the public and protected methods of an Api class
52
+	 *
53
+	 * @param string $className
54
+	 * @param string $resourcePath
55
+	 * @param int    $version
56
+	 *
57
+	 * @throws RestException
58
+	 */
59
+	public static function addAPIClass($className, $resourcePath = '', $version = 1)
60
+	{
61 61
 
62
-        /*
62
+		/*
63 63
          * Mapping Rules
64 64
          * =============
65 65
          *
@@ -74,749 +74,749 @@  discard block
 block discarded – undo
74 74
          * - If a required parameter is not primitive type
75 75
          *      - Do not include it in URL
76 76
          */
77
-        $class = new ReflectionClass($className);
78
-        $dataName = CommentParser::$embeddedDataName;
79
-        try {
80
-            $classMetadata = CommentParser::parse($class->getDocComment());
81
-        } catch (Exception $e) {
82
-            throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
83
-        }
84
-        $classMetadata['scope'] = $scope = static::scope($class);
85
-        $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
86
-            ReflectionMethod::IS_PROTECTED);
87
-        foreach ($methods as $method) {
88
-            $methodUrl = strtolower($method->getName());
89
-            //method name should not begin with _
90
-            if ($methodUrl[0] == '_') {
91
-                continue;
92
-            }
93
-            $doc = $method->getDocComment();
77
+		$class = new ReflectionClass($className);
78
+		$dataName = CommentParser::$embeddedDataName;
79
+		try {
80
+			$classMetadata = CommentParser::parse($class->getDocComment());
81
+		} catch (Exception $e) {
82
+			throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
83
+		}
84
+		$classMetadata['scope'] = $scope = static::scope($class);
85
+		$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
86
+			ReflectionMethod::IS_PROTECTED);
87
+		foreach ($methods as $method) {
88
+			$methodUrl = strtolower($method->getName());
89
+			//method name should not begin with _
90
+			if ($methodUrl[0] == '_') {
91
+				continue;
92
+			}
93
+			$doc = $method->getDocComment();
94 94
 
95
-            try {
96
-                $metadata = CommentParser::parse($doc) + $classMetadata;
97
-            } catch (Exception $e) {
98
-                throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. " . $e->getMessage());
99
-            }
100
-            //@access should not be private
101
-            if (isset($metadata['access'])
102
-                && $metadata['access'] == 'private'
103
-            ) {
104
-                continue;
105
-            }
106
-            $arguments = array();
107
-            $defaults = array();
108
-            $params = $method->getParameters();
109
-            $position = 0;
110
-            $pathParams = array();
111
-            $allowAmbiguity
112
-                = (isset($metadata['smart-auto-routing'])
113
-                    && $metadata['smart-auto-routing'] != 'true')
114
-                || !Defaults::$smartAutoRouting;
115
-            $metadata['resourcePath'] = trim($resourcePath, '/');
116
-            if (isset($classMetadata['description'])) {
117
-                $metadata['classDescription'] = $classMetadata['description'];
118
-            }
119
-            if (isset($classMetadata['classLongDescription'])) {
120
-                $metadata['classLongDescription']
121
-                    = $classMetadata['longDescription'];
122
-            }
123
-            if (!isset($metadata['param'])) {
124
-                $metadata['param'] = array();
125
-            }
126
-            if (isset($metadata['return']['type'])) {
127
-                if ($qualified = Scope::resolve($metadata['return']['type'], $scope))
128
-                    list($metadata['return']['type'], $metadata['return']['children']) =
129
-                        static::getTypeAndModel(new ReflectionClass($qualified), $scope);
130
-            } else {
131
-                //assume return type is array
132
-                $metadata['return']['type'] = 'array';
133
-            }
134
-            foreach ($params as $param) {
135
-                $children = array();
136
-                $type =
137
-                    $param->isArray() ? 'array' : $param->getClass();
138
-                $arguments[$param->getName()] = $position;
139
-                $defaults[$position] = $param->isDefaultValueAvailable() ?
140
-                    $param->getDefaultValue() : null;
141
-                if (!isset($metadata['param'][$position])) {
142
-                    $metadata['param'][$position] = array();
143
-                }
144
-                $m = & $metadata ['param'] [$position];
145
-                $m ['name'] = $param->getName();
146
-                if (!isset($m[$dataName])) {
147
-                    $m[$dataName] = array();
148
-                }
149
-                $p = &$m[$dataName];
150
-                if (empty($m['label']))
151
-                    $m['label'] = Text::title($m['name']);
152
-                if (is_null($type) && isset($m['type'])) {
153
-                    $type = $m['type'];
154
-                }
155
-                if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type == 'string') {
156
-                    $p['type'] = static::$fieldTypesByName[$m['name']];
157
-                }
158
-                $m ['default'] = $defaults [$position];
159
-                $m ['required'] = !$param->isOptional();
160
-                $contentType = Util::nestedValue($p,'type');
161
-                if ($type == 'array' && $contentType && $qualified = Scope::resolve($contentType, $scope)) {
162
-                    list($p['type'], $children, $modelName) = static::getTypeAndModel(
163
-                        new ReflectionClass($qualified), $scope,
164
-                        $className . Text::title($methodUrl), $p
165
-                    );
166
-                }
167
-                if ($type instanceof ReflectionClass) {
168
-                    list($type, $children, $modelName) = static::getTypeAndModel($type, $scope,
169
-                        $className . Text::title($methodUrl), $p);
170
-                } elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
171
-                    list($type, $children, $modelName)
172
-                        = static::getTypeAndModel(new ReflectionClass($qualified), $scope,
173
-                        $className . Text::title($methodUrl), $p);
174
-                }
175
-                if (isset($type)) {
176
-                    $m['type'] = $type;
177
-                }
95
+			try {
96
+				$metadata = CommentParser::parse($doc) + $classMetadata;
97
+			} catch (Exception $e) {
98
+				throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. " . $e->getMessage());
99
+			}
100
+			//@access should not be private
101
+			if (isset($metadata['access'])
102
+				&& $metadata['access'] == 'private'
103
+			) {
104
+				continue;
105
+			}
106
+			$arguments = array();
107
+			$defaults = array();
108
+			$params = $method->getParameters();
109
+			$position = 0;
110
+			$pathParams = array();
111
+			$allowAmbiguity
112
+				= (isset($metadata['smart-auto-routing'])
113
+					&& $metadata['smart-auto-routing'] != 'true')
114
+				|| !Defaults::$smartAutoRouting;
115
+			$metadata['resourcePath'] = trim($resourcePath, '/');
116
+			if (isset($classMetadata['description'])) {
117
+				$metadata['classDescription'] = $classMetadata['description'];
118
+			}
119
+			if (isset($classMetadata['classLongDescription'])) {
120
+				$metadata['classLongDescription']
121
+					= $classMetadata['longDescription'];
122
+			}
123
+			if (!isset($metadata['param'])) {
124
+				$metadata['param'] = array();
125
+			}
126
+			if (isset($metadata['return']['type'])) {
127
+				if ($qualified = Scope::resolve($metadata['return']['type'], $scope))
128
+					list($metadata['return']['type'], $metadata['return']['children']) =
129
+						static::getTypeAndModel(new ReflectionClass($qualified), $scope);
130
+			} else {
131
+				//assume return type is array
132
+				$metadata['return']['type'] = 'array';
133
+			}
134
+			foreach ($params as $param) {
135
+				$children = array();
136
+				$type =
137
+					$param->isArray() ? 'array' : $param->getClass();
138
+				$arguments[$param->getName()] = $position;
139
+				$defaults[$position] = $param->isDefaultValueAvailable() ?
140
+					$param->getDefaultValue() : null;
141
+				if (!isset($metadata['param'][$position])) {
142
+					$metadata['param'][$position] = array();
143
+				}
144
+				$m = & $metadata ['param'] [$position];
145
+				$m ['name'] = $param->getName();
146
+				if (!isset($m[$dataName])) {
147
+					$m[$dataName] = array();
148
+				}
149
+				$p = &$m[$dataName];
150
+				if (empty($m['label']))
151
+					$m['label'] = Text::title($m['name']);
152
+				if (is_null($type) && isset($m['type'])) {
153
+					$type = $m['type'];
154
+				}
155
+				if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type == 'string') {
156
+					$p['type'] = static::$fieldTypesByName[$m['name']];
157
+				}
158
+				$m ['default'] = $defaults [$position];
159
+				$m ['required'] = !$param->isOptional();
160
+				$contentType = Util::nestedValue($p,'type');
161
+				if ($type == 'array' && $contentType && $qualified = Scope::resolve($contentType, $scope)) {
162
+					list($p['type'], $children, $modelName) = static::getTypeAndModel(
163
+						new ReflectionClass($qualified), $scope,
164
+						$className . Text::title($methodUrl), $p
165
+					);
166
+				}
167
+				if ($type instanceof ReflectionClass) {
168
+					list($type, $children, $modelName) = static::getTypeAndModel($type, $scope,
169
+						$className . Text::title($methodUrl), $p);
170
+				} elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
171
+					list($type, $children, $modelName)
172
+						= static::getTypeAndModel(new ReflectionClass($qualified), $scope,
173
+						$className . Text::title($methodUrl), $p);
174
+				}
175
+				if (isset($type)) {
176
+					$m['type'] = $type;
177
+				}
178 178
 
179
-                $m['children'] = $children;
180
-                if (isset($modelName)) {
181
-                    $m['model'] = $modelName;
182
-                }
183
-                if ($m['name'] == Defaults::$fullRequestDataName) {
184
-                    $from = 'body';
185
-                    if (!isset($m['type'])) {
186
-                        $type = $m['type'] = 'array';
187
-                    }
179
+				$m['children'] = $children;
180
+				if (isset($modelName)) {
181
+					$m['model'] = $modelName;
182
+				}
183
+				if ($m['name'] == Defaults::$fullRequestDataName) {
184
+					$from = 'body';
185
+					if (!isset($m['type'])) {
186
+						$type = $m['type'] = 'array';
187
+					}
188 188
 
189
-                } elseif (isset($p['from'])) {
190
-                    $from = $p['from'];
191
-                } else {
192
-                    if ((isset($type) && Util::isObjectOrArray($type))
193
-                    ) {
194
-                        $from = 'body';
195
-                        if (!isset($type)) {
196
-                            $type = $m['type'] = 'array';
197
-                        }
198
-                    } elseif ($m['required'] && in_array($m['name'], static::$prefixingParameterNames)) {
199
-                        $from = 'path';
200
-                    } else {
201
-                        $from = 'body';
202
-                    }
203
-                }
204
-                $p['from'] = $from;
205
-                if (!isset($m['type'])) {
206
-                    $type = $m['type'] = static::type($defaults[$position]);
207
-                }
189
+				} elseif (isset($p['from'])) {
190
+					$from = $p['from'];
191
+				} else {
192
+					if ((isset($type) && Util::isObjectOrArray($type))
193
+					) {
194
+						$from = 'body';
195
+						if (!isset($type)) {
196
+							$type = $m['type'] = 'array';
197
+						}
198
+					} elseif ($m['required'] && in_array($m['name'], static::$prefixingParameterNames)) {
199
+						$from = 'path';
200
+					} else {
201
+						$from = 'body';
202
+					}
203
+				}
204
+				$p['from'] = $from;
205
+				if (!isset($m['type'])) {
206
+					$type = $m['type'] = static::type($defaults[$position]);
207
+				}
208 208
 
209
-                if ($allowAmbiguity || $from == 'path') {
210
-                    $pathParams [] = $position;
211
-                }
212
-                $position++;
213
-            }
214
-            $accessLevel = 0;
215
-            if ($method->isProtected()) {
216
-                $accessLevel = 3;
217
-            } elseif (isset($metadata['access'])) {
218
-                if ($metadata['access'] == 'protected') {
219
-                    $accessLevel = 2;
220
-                } elseif ($metadata['access'] == 'hybrid') {
221
-                    $accessLevel = 1;
222
-                }
223
-            } elseif (isset($metadata['protected'])) {
224
-                $accessLevel = 2;
225
-            }
226
-            /*
209
+				if ($allowAmbiguity || $from == 'path') {
210
+					$pathParams [] = $position;
211
+				}
212
+				$position++;
213
+			}
214
+			$accessLevel = 0;
215
+			if ($method->isProtected()) {
216
+				$accessLevel = 3;
217
+			} elseif (isset($metadata['access'])) {
218
+				if ($metadata['access'] == 'protected') {
219
+					$accessLevel = 2;
220
+				} elseif ($metadata['access'] == 'hybrid') {
221
+					$accessLevel = 1;
222
+				}
223
+			} elseif (isset($metadata['protected'])) {
224
+				$accessLevel = 2;
225
+			}
226
+			/*
227 227
             echo " access level $accessLevel for $className::"
228 228
             .$method->getName().$method->isProtected().PHP_EOL;
229 229
             */
230 230
 
231
-            // take note of the order
232
-            $call = array(
233
-                'url' => null,
234
-                'className' => $className,
235
-                'path' => rtrim($resourcePath, '/'),
236
-                'methodName' => $method->getName(),
237
-                'arguments' => $arguments,
238
-                'defaults' => $defaults,
239
-                'metadata' => $metadata,
240
-                'accessLevel' => $accessLevel,
241
-            );
242
-            // if manual route
243
-            if (preg_match_all(
244
-                '/@url\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)'
245
-                . '[ \t]*\/?(\S*)/s',
246
-                $doc, $matches, PREG_SET_ORDER
247
-            )
248
-            ) {
249
-                foreach ($matches as $match) {
250
-                    $httpMethod = $match[1];
251
-                    $url = rtrim($resourcePath . $match[2], '/');
252
-                    //deep copy the call, as it may change for each @url
253
-                    $copy = unserialize(serialize($call));
254
-                    foreach ($copy['metadata']['param'] as $i => $p) {
255
-                        $inPath =
256
-                            strpos($url, '{' . $p['name'] . '}') ||
257
-                            strpos($url, ':' . $p['name']);
258
-                        if ($inPath) {
259
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'path';
260
-                        } elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') {
261
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'query';
262
-                        } elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] == 'path') {
263
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'body';
264
-                        }
265
-                    }
266
-                    $url = preg_replace_callback('/{[^}]+}|:[^\/]+/',
267
-                        function ($matches) use ($copy) {
268
-                            $match = trim($matches[0], '{}:');
269
-                            $index = $copy['arguments'][$match];
270
-                            return '{' .
271
-                            Routes::typeChar(isset(
272
-                                $copy['metadata']['param'][$index]['type'])
273
-                                ? $copy['metadata']['param'][$index]['type']
274
-                                : null)
275
-                            . $index . '}';
276
-                        }, $url);
277
-                    static::addPath($url, $copy, $httpMethod, $version);
278
-                }
279
-                //if auto route enabled, do so
280
-            } elseif (Defaults::$autoRoutingEnabled) {
281
-                // no configuration found so use convention
282
-                if (preg_match_all(
283
-                    '/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)/i',
284
-                    $methodUrl, $matches)
285
-                ) {
286
-                    $httpMethod = strtoupper($matches[0][0]);
287
-                    $methodUrl = substr($methodUrl, strlen($httpMethod));
288
-                } else {
289
-                    $httpMethod = 'GET';
290
-                }
291
-                if ($methodUrl == 'index') {
292
-                    $methodUrl = '';
293
-                }
294
-                $url = empty($methodUrl) ? rtrim($resourcePath, '/')
295
-                    : $resourcePath . $methodUrl;
296
-                for ($position = 0; $position < count($params); $position++) {
297
-                    $from = $metadata['param'][$position][$dataName]['from'];
298
-                    if ($from == 'body' && ($httpMethod == 'GET' ||
299
-                            $httpMethod == 'DELETE')
300
-                    ) {
301
-                        $call['metadata']['param'][$position][$dataName]['from']
302
-                            = 'query';
303
-                    }
304
-                }
305
-                if (empty($pathParams) || $allowAmbiguity) {
306
-                    static::addPath($url, $call, $httpMethod, $version);
307
-                }
308
-                $lastPathParam = end($pathParams);
309
-                foreach ($pathParams as $position) {
310
-                    if (!empty($url))
311
-                        $url .= '/';
312
-                    $url .= '{' .
313
-                        static::typeChar(isset($call['metadata']['param'][$position]['type'])
314
-                            ? $call['metadata']['param'][$position]['type']
315
-                            : null)
316
-                        . $position . '}';
317
-                    if ($allowAmbiguity || $position == $lastPathParam) {
318
-                        static::addPath($url, $call, $httpMethod, $version);
319
-                    }
320
-                }
321
-            }
322
-        }
323
-    }
231
+			// take note of the order
232
+			$call = array(
233
+				'url' => null,
234
+				'className' => $className,
235
+				'path' => rtrim($resourcePath, '/'),
236
+				'methodName' => $method->getName(),
237
+				'arguments' => $arguments,
238
+				'defaults' => $defaults,
239
+				'metadata' => $metadata,
240
+				'accessLevel' => $accessLevel,
241
+			);
242
+			// if manual route
243
+			if (preg_match_all(
244
+				'/@url\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)'
245
+				. '[ \t]*\/?(\S*)/s',
246
+				$doc, $matches, PREG_SET_ORDER
247
+			)
248
+			) {
249
+				foreach ($matches as $match) {
250
+					$httpMethod = $match[1];
251
+					$url = rtrim($resourcePath . $match[2], '/');
252
+					//deep copy the call, as it may change for each @url
253
+					$copy = unserialize(serialize($call));
254
+					foreach ($copy['metadata']['param'] as $i => $p) {
255
+						$inPath =
256
+							strpos($url, '{' . $p['name'] . '}') ||
257
+							strpos($url, ':' . $p['name']);
258
+						if ($inPath) {
259
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'path';
260
+						} elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') {
261
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'query';
262
+						} elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] == 'path') {
263
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'body';
264
+						}
265
+					}
266
+					$url = preg_replace_callback('/{[^}]+}|:[^\/]+/',
267
+						function ($matches) use ($copy) {
268
+							$match = trim($matches[0], '{}:');
269
+							$index = $copy['arguments'][$match];
270
+							return '{' .
271
+							Routes::typeChar(isset(
272
+								$copy['metadata']['param'][$index]['type'])
273
+								? $copy['metadata']['param'][$index]['type']
274
+								: null)
275
+							. $index . '}';
276
+						}, $url);
277
+					static::addPath($url, $copy, $httpMethod, $version);
278
+				}
279
+				//if auto route enabled, do so
280
+			} elseif (Defaults::$autoRoutingEnabled) {
281
+				// no configuration found so use convention
282
+				if (preg_match_all(
283
+					'/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)/i',
284
+					$methodUrl, $matches)
285
+				) {
286
+					$httpMethod = strtoupper($matches[0][0]);
287
+					$methodUrl = substr($methodUrl, strlen($httpMethod));
288
+				} else {
289
+					$httpMethod = 'GET';
290
+				}
291
+				if ($methodUrl == 'index') {
292
+					$methodUrl = '';
293
+				}
294
+				$url = empty($methodUrl) ? rtrim($resourcePath, '/')
295
+					: $resourcePath . $methodUrl;
296
+				for ($position = 0; $position < count($params); $position++) {
297
+					$from = $metadata['param'][$position][$dataName]['from'];
298
+					if ($from == 'body' && ($httpMethod == 'GET' ||
299
+							$httpMethod == 'DELETE')
300
+					) {
301
+						$call['metadata']['param'][$position][$dataName]['from']
302
+							= 'query';
303
+					}
304
+				}
305
+				if (empty($pathParams) || $allowAmbiguity) {
306
+					static::addPath($url, $call, $httpMethod, $version);
307
+				}
308
+				$lastPathParam = end($pathParams);
309
+				foreach ($pathParams as $position) {
310
+					if (!empty($url))
311
+						$url .= '/';
312
+					$url .= '{' .
313
+						static::typeChar(isset($call['metadata']['param'][$position]['type'])
314
+							? $call['metadata']['param'][$position]['type']
315
+							: null)
316
+						. $position . '}';
317
+					if ($allowAmbiguity || $position == $lastPathParam) {
318
+						static::addPath($url, $call, $httpMethod, $version);
319
+					}
320
+				}
321
+			}
322
+		}
323
+	}
324 324
 
325
-    /**
326
-     * @access private
327
-     */
328
-    public static function typeChar($type = null)
329
-    {
330
-        if (!$type) {
331
-            return 's';
332
-        }
333
-        switch ($type[0]) {
334
-            case 'i':
335
-            case 'f':
336
-                return 'n';
337
-        }
338
-        return 's';
339
-    }
325
+	/**
326
+	 * @access private
327
+	 */
328
+	public static function typeChar($type = null)
329
+	{
330
+		if (!$type) {
331
+			return 's';
332
+		}
333
+		switch ($type[0]) {
334
+			case 'i':
335
+			case 'f':
336
+				return 'n';
337
+		}
338
+		return 's';
339
+	}
340 340
 
341
-    protected static function addPath($path, array $call,
342
-        $httpMethod = 'GET', $version = 1)
343
-    {
344
-        $call['url'] = preg_replace_callback(
345
-            "/\{\S(\d+)\}/",
346
-            function ($matches) use ($call) {
347
-                return '{' .
348
-                $call['metadata']['param'][$matches[1]]['name'] . '}';
349
-            },
350
-            $path
351
-        );
352
-        //check for wildcard routes
353
-        if (substr($path, -1, 1) == '*') {
354
-            $path = rtrim($path, '/*');
355
-            static::$routes["v$version"]['*'][$path][$httpMethod] = $call;
356
-        } else {
357
-            static::$routes["v$version"][$path][$httpMethod] = $call;
358
-            //create an alias with index if the method name is index
359
-            if ($call['methodName'] == 'index')
360
-                static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
361
-        }
362
-    }
341
+	protected static function addPath($path, array $call,
342
+		$httpMethod = 'GET', $version = 1)
343
+	{
344
+		$call['url'] = preg_replace_callback(
345
+			"/\{\S(\d+)\}/",
346
+			function ($matches) use ($call) {
347
+				return '{' .
348
+				$call['metadata']['param'][$matches[1]]['name'] . '}';
349
+			},
350
+			$path
351
+		);
352
+		//check for wildcard routes
353
+		if (substr($path, -1, 1) == '*') {
354
+			$path = rtrim($path, '/*');
355
+			static::$routes["v$version"]['*'][$path][$httpMethod] = $call;
356
+		} else {
357
+			static::$routes["v$version"][$path][$httpMethod] = $call;
358
+			//create an alias with index if the method name is index
359
+			if ($call['methodName'] == 'index')
360
+				static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
361
+		}
362
+	}
363 363
 
364
-    /**
365
-     * Find the api method for the given url and http method
366
-     *
367
-     * @param string $path       Requested url path
368
-     * @param string $httpMethod GET|POST|PUT|PATCH|DELETE etc
369
-     * @param int    $version    Api Version number
370
-     * @param array  $data       Data collected from the request
371
-     *
372
-     * @throws RestException
373
-     * @return ApiMethodInfo
374
-     */
375
-    public static function find($path, $httpMethod,
376
-        $version = 1, array $data = array())
377
-    {
378
-        $p = Util::nestedValue(static::$routes, "v$version");
379
-        if (!$p) {
380
-            throw new RestException(
381
-                404,
382
-                $version == 1 ? '' : "Version $version is not supported"
383
-            );
384
-        }
385
-        $status = 404;
386
-        $message = null;
387
-        $methods = array();
388
-        if (isset($p[$path][$httpMethod])) {
389
-            //================== static routes ==========================
390
-            return static::populate($p[$path][$httpMethod], $data);
391
-        } elseif (isset($p['*'])) {
392
-            //================== wildcard routes ========================
393
-            uksort($p['*'], function ($a, $b) {
394
-                return strlen($b) - strlen($a);
395
-            });
396
-            foreach ($p['*'] as $key => $value) {
397
-                if (strpos($path, $key) === 0 && isset($value[$httpMethod])) {
398
-                    //path found, convert rest of the path to parameters
399
-                    $path = substr($path, strlen($key) + 1);
400
-                    $call = ApiMethodInfo::__set_state($value[$httpMethod]);
401
-                    $call->parameters = empty($path)
402
-                        ? array()
403
-                        : explode('/', $path);
404
-                    return $call;
405
-                }
406
-            }
407
-        }
408
-        //================== dynamic routes =============================
409
-        //add newline char if trailing slash is found
410
-        if (substr($path, -1) == '/')
411
-            $path .= PHP_EOL;
412
-        //if double slash is found fill in newline char;
413
-        $path = str_replace('//', '/' . PHP_EOL . '/', $path);
414
-        ksort($p);
415
-        foreach ($p as $key => $value) {
416
-            if (!isset($value[$httpMethod])) {
417
-                continue;
418
-            }
419
-            $regex = str_replace(array('{', '}'),
420
-                array('(?P<', '>[^/]+)'), $key);
421
-            if (preg_match_all(":^$regex$:i", $path, $matches, PREG_SET_ORDER)) {
422
-                $matches = $matches[0];
423
-                $found = true;
424
-                foreach ($matches as $k => $v) {
425
-                    if (is_numeric($k)) {
426
-                        unset($matches[$k]);
427
-                        continue;
428
-                    }
429
-                    $index = intval(substr($k, 1));
430
-                    $details = $value[$httpMethod]['metadata']['param'][$index];
431
-                    if ($k[0] == 's' || strpos($k, static::pathVarTypeOf($v)) === 0) {
432
-                        //remove the newlines
433
-                        $data[$details['name']] = trim($v, PHP_EOL);
434
-                    } else {
435
-                        $status = 400;
436
-                        $message = 'invalid value specified for `'
437
-                            . $details['name'] . '`';
438
-                        $found = false;
439
-                        break;
440
-                    }
441
-                }
442
-                if ($found) {
443
-                    return static::populate($value[$httpMethod], $data);
444
-                }
445
-            }
446
-        }
447
-        if ($status == 404) {
448
-            //check if other methods are allowed
449
-            if (isset($p[$path])) {
450
-                $status = 405;
451
-                $methods = array_keys($p[$path]);
452
-            }
453
-        }
454
-        if ($status == 405) {
455
-            header('Allow: ' . implode(', ', $methods));
456
-        }
457
-        throw new RestException($status, $message);
458
-    }
364
+	/**
365
+	 * Find the api method for the given url and http method
366
+	 *
367
+	 * @param string $path       Requested url path
368
+	 * @param string $httpMethod GET|POST|PUT|PATCH|DELETE etc
369
+	 * @param int    $version    Api Version number
370
+	 * @param array  $data       Data collected from the request
371
+	 *
372
+	 * @throws RestException
373
+	 * @return ApiMethodInfo
374
+	 */
375
+	public static function find($path, $httpMethod,
376
+		$version = 1, array $data = array())
377
+	{
378
+		$p = Util::nestedValue(static::$routes, "v$version");
379
+		if (!$p) {
380
+			throw new RestException(
381
+				404,
382
+				$version == 1 ? '' : "Version $version is not supported"
383
+			);
384
+		}
385
+		$status = 404;
386
+		$message = null;
387
+		$methods = array();
388
+		if (isset($p[$path][$httpMethod])) {
389
+			//================== static routes ==========================
390
+			return static::populate($p[$path][$httpMethod], $data);
391
+		} elseif (isset($p['*'])) {
392
+			//================== wildcard routes ========================
393
+			uksort($p['*'], function ($a, $b) {
394
+				return strlen($b) - strlen($a);
395
+			});
396
+			foreach ($p['*'] as $key => $value) {
397
+				if (strpos($path, $key) === 0 && isset($value[$httpMethod])) {
398
+					//path found, convert rest of the path to parameters
399
+					$path = substr($path, strlen($key) + 1);
400
+					$call = ApiMethodInfo::__set_state($value[$httpMethod]);
401
+					$call->parameters = empty($path)
402
+						? array()
403
+						: explode('/', $path);
404
+					return $call;
405
+				}
406
+			}
407
+		}
408
+		//================== dynamic routes =============================
409
+		//add newline char if trailing slash is found
410
+		if (substr($path, -1) == '/')
411
+			$path .= PHP_EOL;
412
+		//if double slash is found fill in newline char;
413
+		$path = str_replace('//', '/' . PHP_EOL . '/', $path);
414
+		ksort($p);
415
+		foreach ($p as $key => $value) {
416
+			if (!isset($value[$httpMethod])) {
417
+				continue;
418
+			}
419
+			$regex = str_replace(array('{', '}'),
420
+				array('(?P<', '>[^/]+)'), $key);
421
+			if (preg_match_all(":^$regex$:i", $path, $matches, PREG_SET_ORDER)) {
422
+				$matches = $matches[0];
423
+				$found = true;
424
+				foreach ($matches as $k => $v) {
425
+					if (is_numeric($k)) {
426
+						unset($matches[$k]);
427
+						continue;
428
+					}
429
+					$index = intval(substr($k, 1));
430
+					$details = $value[$httpMethod]['metadata']['param'][$index];
431
+					if ($k[0] == 's' || strpos($k, static::pathVarTypeOf($v)) === 0) {
432
+						//remove the newlines
433
+						$data[$details['name']] = trim($v, PHP_EOL);
434
+					} else {
435
+						$status = 400;
436
+						$message = 'invalid value specified for `'
437
+							. $details['name'] . '`';
438
+						$found = false;
439
+						break;
440
+					}
441
+				}
442
+				if ($found) {
443
+					return static::populate($value[$httpMethod], $data);
444
+				}
445
+			}
446
+		}
447
+		if ($status == 404) {
448
+			//check if other methods are allowed
449
+			if (isset($p[$path])) {
450
+				$status = 405;
451
+				$methods = array_keys($p[$path]);
452
+			}
453
+		}
454
+		if ($status == 405) {
455
+			header('Allow: ' . implode(', ', $methods));
456
+		}
457
+		throw new RestException($status, $message);
458
+	}
459 459
 
460
-    public static function findAll(array $excludedPaths = array(), array $excludedHttpMethods = array(), $version = 1)
461
-    {
462
-        $map = array();
463
-        $all = Util::nestedValue(self::$routes, "v$version");
464
-        $filter = array();
465
-        if (isset($all['*'])) {
466
-            $all = $all['*'] + $all;
467
-            unset($all['*']);
468
-        }
469
-        if(is_array($all)){
470
-            foreach ($all as $fullPath => $routes) {
471
-                foreach ($routes as $httpMethod => $route) {
472
-                    if (in_array($httpMethod, $excludedHttpMethods)) {
473
-                        continue;
474
-                    }
475
-                    foreach ($excludedPaths as $exclude) {
476
-                        if (empty($exclude)) {
477
-                            if ($fullPath == $exclude || $fullPath == 'index')
478
-                                continue 2;
479
-                        } elseif (Text::beginsWith($fullPath, $exclude)) {
480
-                            continue 2;
481
-                        }
482
-                    }
483
-                    $hash = "$httpMethod " . $route['url'];
484
-                    if (!isset($filter[$hash])) {
485
-                        $route['httpMethod'] = $httpMethod;
486
-                        $map[$route['metadata']['resourcePath']][]
487
-                            = array('access' => static::verifyAccess($route), 'route' => $route, 'hash' => $hash);
488
-                        $filter[$hash] = true;
489
-                    }
490
-                }
491
-            }
492
-        }
493
-        return $map;
494
-    }
460
+	public static function findAll(array $excludedPaths = array(), array $excludedHttpMethods = array(), $version = 1)
461
+	{
462
+		$map = array();
463
+		$all = Util::nestedValue(self::$routes, "v$version");
464
+		$filter = array();
465
+		if (isset($all['*'])) {
466
+			$all = $all['*'] + $all;
467
+			unset($all['*']);
468
+		}
469
+		if(is_array($all)){
470
+			foreach ($all as $fullPath => $routes) {
471
+				foreach ($routes as $httpMethod => $route) {
472
+					if (in_array($httpMethod, $excludedHttpMethods)) {
473
+						continue;
474
+					}
475
+					foreach ($excludedPaths as $exclude) {
476
+						if (empty($exclude)) {
477
+							if ($fullPath == $exclude || $fullPath == 'index')
478
+								continue 2;
479
+						} elseif (Text::beginsWith($fullPath, $exclude)) {
480
+							continue 2;
481
+						}
482
+					}
483
+					$hash = "$httpMethod " . $route['url'];
484
+					if (!isset($filter[$hash])) {
485
+						$route['httpMethod'] = $httpMethod;
486
+						$map[$route['metadata']['resourcePath']][]
487
+							= array('access' => static::verifyAccess($route), 'route' => $route, 'hash' => $hash);
488
+						$filter[$hash] = true;
489
+					}
490
+				}
491
+			}
492
+		}
493
+		return $map;
494
+	}
495 495
 
496
-    public static function verifyAccess($route)
497
-    {
498
-        if ($route['accessLevel'] < 2)
499
-            return true;
500
-        /** @var Restler $r */
501
-        $r = Scope::get('Restler');
502
-        $authenticated = $r->_authenticated;
503
-        if (!$authenticated && $route['accessLevel'] > 1)
504
-            return false;
505
-        if (
506
-            $authenticated &&
507
-            Defaults::$accessControlFunction &&
508
-            (!call_user_func(Defaults::$accessControlFunction, $route['metadata']))
509
-        ) {
510
-            return false;
511
-        }
512
-        return true;
513
-    }
496
+	public static function verifyAccess($route)
497
+	{
498
+		if ($route['accessLevel'] < 2)
499
+			return true;
500
+		/** @var Restler $r */
501
+		$r = Scope::get('Restler');
502
+		$authenticated = $r->_authenticated;
503
+		if (!$authenticated && $route['accessLevel'] > 1)
504
+			return false;
505
+		if (
506
+			$authenticated &&
507
+			Defaults::$accessControlFunction &&
508
+			(!call_user_func(Defaults::$accessControlFunction, $route['metadata']))
509
+		) {
510
+			return false;
511
+		}
512
+		return true;
513
+	}
514 514
 
515 515
 
516
-    /**
517
-     * Populates the parameter values
518
-     *
519
-     * @param array $call
520
-     * @param       $data
521
-     *
522
-     * @return ApiMethodInfo
523
-     *
524
-     * @access private
525
-     */
526
-    protected static function populate(array $call, $data)
527
-    {
528
-        $call['parameters'] = $call['defaults'];
529
-        $p = & $call['parameters'];
530
-        $dataName = CommentParser::$embeddedDataName;
531
-        foreach ($data as $key => $value) {
532
-            if (isset($call['arguments'][$key])) {
533
-                $p[$call['arguments'][$key]] = $value;
534
-            }
535
-        }
536
-        if (Defaults::$smartParameterParsing) {
537
-            if (
538
-                ($m = Util::nestedValue($call, 'metadata', 'param', 0)) &&
539
-                !array_key_exists($m['name'], $data) &&
540
-                array_key_exists(Defaults::$fullRequestDataName, $data) &&
541
-                !is_null($d = $data[Defaults::$fullRequestDataName]) &&
542
-                isset($m['type']) &&
543
-                static::typeMatch($m['type'], $d)
544
-            ) {
545
-                $p[0] = $d;
546
-            } else {
547
-                $bodyParamCount = 0;
548
-                $lastBodyParamIndex = -1;
549
-                $lastM = null;
550
-                foreach ($call['metadata']['param'] as $k => $m) {
551
-                    if ($m[$dataName]['from'] == 'body') {
552
-                        $bodyParamCount++;
553
-                        $lastBodyParamIndex = $k;
554
-                        $lastM = $m;
555
-                    }
556
-                }
557
-                if (
558
-                    $bodyParamCount == 1 &&
559
-                    !array_key_exists($lastM['name'], $data) &&
560
-                    array_key_exists(Defaults::$fullRequestDataName, $data) &&
561
-                    !is_null($d = $data[Defaults::$fullRequestDataName])
562
-                ) {
563
-                    $p[$lastBodyParamIndex] = $d;
564
-                }
565
-            }
566
-        }
567
-        $r = ApiMethodInfo::__set_state($call);
568
-        $modifier = "_modify_{$r->methodName}_api";
569
-        if (method_exists($r->className, $modifier)) {
570
-            $stage = end(Scope::get('Restler')->getEvents());
571
-            if (empty($stage))
572
-                $stage = 'setup';
573
-            $r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
574
-        }
575
-        return $r;
576
-    }
516
+	/**
517
+	 * Populates the parameter values
518
+	 *
519
+	 * @param array $call
520
+	 * @param       $data
521
+	 *
522
+	 * @return ApiMethodInfo
523
+	 *
524
+	 * @access private
525
+	 */
526
+	protected static function populate(array $call, $data)
527
+	{
528
+		$call['parameters'] = $call['defaults'];
529
+		$p = & $call['parameters'];
530
+		$dataName = CommentParser::$embeddedDataName;
531
+		foreach ($data as $key => $value) {
532
+			if (isset($call['arguments'][$key])) {
533
+				$p[$call['arguments'][$key]] = $value;
534
+			}
535
+		}
536
+		if (Defaults::$smartParameterParsing) {
537
+			if (
538
+				($m = Util::nestedValue($call, 'metadata', 'param', 0)) &&
539
+				!array_key_exists($m['name'], $data) &&
540
+				array_key_exists(Defaults::$fullRequestDataName, $data) &&
541
+				!is_null($d = $data[Defaults::$fullRequestDataName]) &&
542
+				isset($m['type']) &&
543
+				static::typeMatch($m['type'], $d)
544
+			) {
545
+				$p[0] = $d;
546
+			} else {
547
+				$bodyParamCount = 0;
548
+				$lastBodyParamIndex = -1;
549
+				$lastM = null;
550
+				foreach ($call['metadata']['param'] as $k => $m) {
551
+					if ($m[$dataName]['from'] == 'body') {
552
+						$bodyParamCount++;
553
+						$lastBodyParamIndex = $k;
554
+						$lastM = $m;
555
+					}
556
+				}
557
+				if (
558
+					$bodyParamCount == 1 &&
559
+					!array_key_exists($lastM['name'], $data) &&
560
+					array_key_exists(Defaults::$fullRequestDataName, $data) &&
561
+					!is_null($d = $data[Defaults::$fullRequestDataName])
562
+				) {
563
+					$p[$lastBodyParamIndex] = $d;
564
+				}
565
+			}
566
+		}
567
+		$r = ApiMethodInfo::__set_state($call);
568
+		$modifier = "_modify_{$r->methodName}_api";
569
+		if (method_exists($r->className, $modifier)) {
570
+			$stage = end(Scope::get('Restler')->getEvents());
571
+			if (empty($stage))
572
+				$stage = 'setup';
573
+			$r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
574
+		}
575
+		return $r;
576
+	}
577 577
 
578
-    /**
579
-     * @access private
580
-     */
581
-    protected static function pathVarTypeOf($var)
582
-    {
583
-        if (is_numeric($var)) {
584
-            return 'n';
585
-        }
586
-        if ($var === 'true' || $var === 'false') {
587
-            return 'b';
588
-        }
589
-        return 's';
590
-    }
578
+	/**
579
+	 * @access private
580
+	 */
581
+	protected static function pathVarTypeOf($var)
582
+	{
583
+		if (is_numeric($var)) {
584
+			return 'n';
585
+		}
586
+		if ($var === 'true' || $var === 'false') {
587
+			return 'b';
588
+		}
589
+		return 's';
590
+	}
591 591
 
592
-    protected static function typeMatch($type, $var)
593
-    {
594
-        switch ($type) {
595
-            case 'boolean':
596
-            case 'bool':
597
-                return is_bool($var);
598
-            case 'array':
599
-            case 'object':
600
-                return is_array($var);
601
-            case 'string':
602
-            case 'int':
603
-            case 'integer':
604
-            case 'float':
605
-            case 'number':
606
-                return is_scalar($var);
607
-        }
608
-        return true;
609
-    }
592
+	protected static function typeMatch($type, $var)
593
+	{
594
+		switch ($type) {
595
+			case 'boolean':
596
+			case 'bool':
597
+				return is_bool($var);
598
+			case 'array':
599
+			case 'object':
600
+				return is_array($var);
601
+			case 'string':
602
+			case 'int':
603
+			case 'integer':
604
+			case 'float':
605
+			case 'number':
606
+				return is_scalar($var);
607
+		}
608
+		return true;
609
+	}
610 610
 
611
-    protected static function parseMagic(ReflectionClass $class, $forResponse = true)
612
-    {
613
-        if (!$c = CommentParser::parse($class->getDocComment())) {
614
-            return false;
615
-        }
616
-        $p = 'property';
617
-        $r = empty($c[$p]) ? array() : $c[$p];
618
-        $p .= '-' . ($forResponse ? 'read' : 'write');
619
-        if (!empty($c[$p])) {
620
-            $r = array_merge($r, $c[$p]);
621
-        }
611
+	protected static function parseMagic(ReflectionClass $class, $forResponse = true)
612
+	{
613
+		if (!$c = CommentParser::parse($class->getDocComment())) {
614
+			return false;
615
+		}
616
+		$p = 'property';
617
+		$r = empty($c[$p]) ? array() : $c[$p];
618
+		$p .= '-' . ($forResponse ? 'read' : 'write');
619
+		if (!empty($c[$p])) {
620
+			$r = array_merge($r, $c[$p]);
621
+		}
622 622
 
623
-        return $r;
624
-    }
623
+		return $r;
624
+	}
625 625
 
626
-    /**
627
-     * Get the type and associated model
628
-     *
629
-     * @param ReflectionClass $class
630
-     * @param array           $scope
631
-     *
632
-     * @throws RestException
633
-     * @throws \Exception
634
-     * @return array
635
-     *
636
-     * @access protected
637
-     */
638
-    protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix='', array $rules=array())
639
-    {
640
-        $className = $class->getName();
641
-        $dataName = CommentParser::$embeddedDataName;
642
-        if (isset(static::$models[$prefix.$className])) {
643
-            return static::$models[$prefix.$className];
644
-        }
645
-        $children = array();
646
-        try {
647
-            if ($magic_properties = static::parseMagic($class, empty($prefix))) {
648
-                foreach ($magic_properties as $prop) {
649
-                    if (!isset($prop['name'])) {
650
-                        throw new Exception('@property comment is not properly defined in ' . $className . ' class');
651
-                    }
652
-                    if (!isset($prop[$dataName]['label'])) {
653
-                        $prop[$dataName]['label'] = Text::title($prop['name']);
654
-                    }
655
-                    if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] == 'string' && !isset($prop[$dataName]['type'])) {
656
-                        $prop[$dataName]['type'] = static::$fieldTypesByName[$prop['name']];
657
-                    }
658
-                    $children[$prop['name']] = $prop;
659
-                }
660
-            } else {
661
-                $props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
662
-                foreach ($props as $prop) {
663
-                    $name = $prop->getName();
664
-                    $child = array('name' => $name);
665
-                    if ($c = $prop->getDocComment()) {
666
-                        $child += Util::nestedValue(CommentParser::parse($c), 'var') ?: array();
667
-                    } else {
668
-                        $o = $class->newInstance();
669
-                        $p = $prop->getValue($o);
670
-                        if (is_object($p)) {
671
-                            $child['type'] = get_class($p);
672
-                        } elseif (is_array($p)) {
673
-                            $child['type'] = 'array';
674
-                            if (count($p)) {
675
-                                $pc = reset($p);
676
-                                if (is_object($pc)) {
677
-                                    $child['contentType'] = get_class($pc);
678
-                                }
679
-                            }
680
-                        }
681
-                    }
682
-                    $child += array(
683
-                        'type'  => isset(static::$fieldTypesByName[$child['name']])
684
-                            ? static::$fieldTypesByName[$child['name']]
685
-                            : 'string',
686
-                        'label' => Text::title($child['name'])
687
-                    );
688
-                    isset($child[$dataName])
689
-                        ? $child[$dataName] += array('required' => true)
690
-                        : $child[$dataName]['required'] = true;
691
-                    if ($prop->class != $className && $qualified = Scope::resolve($child['type'], $scope)) {
692
-                        list($child['type'], $child['children'])
693
-                            = static::getTypeAndModel(new ReflectionClass($qualified), $scope);
694
-                    } elseif (
695
-                        ($contentType = Util::nestedValue($child, $dataName, 'type')) &&
696
-                        ($qualified = Scope::resolve($contentType, $scope))
697
-                    ) {
698
-                        list($child['contentType'], $child['children'])
699
-                            = static::getTypeAndModel(new ReflectionClass($qualified), $scope);
700
-                    }
701
-                    $children[$name] = $child;
702
-                }
703
-            }
704
-        } catch (Exception $e) {
705
-            if (Text::endsWith($e->getFile(), 'CommentParser.php')) {
706
-                throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
707
-            }
708
-            throw $e;
709
-        }
710
-        if ($properties = Util::nestedValue($rules, 'properties')) {
711
-            if (is_string($properties)) {
712
-                $properties = array($properties);
713
-            }
714
-            $c = array();
715
-            foreach ($properties as $property) {
716
-                if (isset($children[$property])) {
717
-                    $c[$property] = $children[$property];
718
-                }
719
-            }
720
-            $children = $c;
721
-        }
722
-        if ($required = Util::nestedValue($rules, 'required')) {
723
-            //override required on children
724
-            if (is_bool($required)) {
725
-                // true means all are required false means none are required
726
-                $required = $required ? array_keys($children) : array();
727
-            } elseif (is_string($required)) {
728
-                $required = array($required);
729
-            }
730
-            $required = array_fill_keys($required, true);
731
-            foreach ($children as $name => $child) {
732
-                $children[$name][$dataName]['required'] = isset($required[$name]);
733
-            }
734
-        }
735
-        static::$models[$prefix.$className] = array($className, $children, $prefix.$className);
736
-        return static::$models[$prefix.$className];
737
-    }
626
+	/**
627
+	 * Get the type and associated model
628
+	 *
629
+	 * @param ReflectionClass $class
630
+	 * @param array           $scope
631
+	 *
632
+	 * @throws RestException
633
+	 * @throws \Exception
634
+	 * @return array
635
+	 *
636
+	 * @access protected
637
+	 */
638
+	protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix='', array $rules=array())
639
+	{
640
+		$className = $class->getName();
641
+		$dataName = CommentParser::$embeddedDataName;
642
+		if (isset(static::$models[$prefix.$className])) {
643
+			return static::$models[$prefix.$className];
644
+		}
645
+		$children = array();
646
+		try {
647
+			if ($magic_properties = static::parseMagic($class, empty($prefix))) {
648
+				foreach ($magic_properties as $prop) {
649
+					if (!isset($prop['name'])) {
650
+						throw new Exception('@property comment is not properly defined in ' . $className . ' class');
651
+					}
652
+					if (!isset($prop[$dataName]['label'])) {
653
+						$prop[$dataName]['label'] = Text::title($prop['name']);
654
+					}
655
+					if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] == 'string' && !isset($prop[$dataName]['type'])) {
656
+						$prop[$dataName]['type'] = static::$fieldTypesByName[$prop['name']];
657
+					}
658
+					$children[$prop['name']] = $prop;
659
+				}
660
+			} else {
661
+				$props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
662
+				foreach ($props as $prop) {
663
+					$name = $prop->getName();
664
+					$child = array('name' => $name);
665
+					if ($c = $prop->getDocComment()) {
666
+						$child += Util::nestedValue(CommentParser::parse($c), 'var') ?: array();
667
+					} else {
668
+						$o = $class->newInstance();
669
+						$p = $prop->getValue($o);
670
+						if (is_object($p)) {
671
+							$child['type'] = get_class($p);
672
+						} elseif (is_array($p)) {
673
+							$child['type'] = 'array';
674
+							if (count($p)) {
675
+								$pc = reset($p);
676
+								if (is_object($pc)) {
677
+									$child['contentType'] = get_class($pc);
678
+								}
679
+							}
680
+						}
681
+					}
682
+					$child += array(
683
+						'type'  => isset(static::$fieldTypesByName[$child['name']])
684
+							? static::$fieldTypesByName[$child['name']]
685
+							: 'string',
686
+						'label' => Text::title($child['name'])
687
+					);
688
+					isset($child[$dataName])
689
+						? $child[$dataName] += array('required' => true)
690
+						: $child[$dataName]['required'] = true;
691
+					if ($prop->class != $className && $qualified = Scope::resolve($child['type'], $scope)) {
692
+						list($child['type'], $child['children'])
693
+							= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
694
+					} elseif (
695
+						($contentType = Util::nestedValue($child, $dataName, 'type')) &&
696
+						($qualified = Scope::resolve($contentType, $scope))
697
+					) {
698
+						list($child['contentType'], $child['children'])
699
+							= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
700
+					}
701
+					$children[$name] = $child;
702
+				}
703
+			}
704
+		} catch (Exception $e) {
705
+			if (Text::endsWith($e->getFile(), 'CommentParser.php')) {
706
+				throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
707
+			}
708
+			throw $e;
709
+		}
710
+		if ($properties = Util::nestedValue($rules, 'properties')) {
711
+			if (is_string($properties)) {
712
+				$properties = array($properties);
713
+			}
714
+			$c = array();
715
+			foreach ($properties as $property) {
716
+				if (isset($children[$property])) {
717
+					$c[$property] = $children[$property];
718
+				}
719
+			}
720
+			$children = $c;
721
+		}
722
+		if ($required = Util::nestedValue($rules, 'required')) {
723
+			//override required on children
724
+			if (is_bool($required)) {
725
+				// true means all are required false means none are required
726
+				$required = $required ? array_keys($children) : array();
727
+			} elseif (is_string($required)) {
728
+				$required = array($required);
729
+			}
730
+			$required = array_fill_keys($required, true);
731
+			foreach ($children as $name => $child) {
732
+				$children[$name][$dataName]['required'] = isset($required[$name]);
733
+			}
734
+		}
735
+		static::$models[$prefix.$className] = array($className, $children, $prefix.$className);
736
+		return static::$models[$prefix.$className];
737
+	}
738 738
 
739
-    /**
740
-     * Import previously created routes from cache
741
-     *
742
-     * @param array $routes
743
-     */
744
-    public static function fromArray(array $routes)
745
-    {
746
-        static::$routes = $routes;
747
-    }
739
+	/**
740
+	 * Import previously created routes from cache
741
+	 *
742
+	 * @param array $routes
743
+	 */
744
+	public static function fromArray(array $routes)
745
+	{
746
+		static::$routes = $routes;
747
+	}
748 748
 
749
-    /**
750
-     * Export current routes for cache
751
-     *
752
-     * @return array
753
-     */
754
-    public static function toArray()
755
-    {
756
-        return static::$routes;
757
-    }
749
+	/**
750
+	 * Export current routes for cache
751
+	 *
752
+	 * @return array
753
+	 */
754
+	public static function toArray()
755
+	{
756
+		return static::$routes;
757
+	}
758 758
 
759
-    public static function type($var)
760
-    {
761
-        if (is_object($var)) return get_class($var);
762
-        if (is_array($var)) return 'array';
763
-        if (is_bool($var)) return 'boolean';
764
-        if (is_numeric($var)) return is_float($var) ? 'float' : 'int';
765
-        return 'string';
766
-    }
759
+	public static function type($var)
760
+	{
761
+		if (is_object($var)) return get_class($var);
762
+		if (is_array($var)) return 'array';
763
+		if (is_bool($var)) return 'boolean';
764
+		if (is_numeric($var)) return is_float($var) ? 'float' : 'int';
765
+		return 'string';
766
+	}
767 767
 
768
-    public static function scope(ReflectionClass $class)
769
-    {
770
-        $namespace = $class->getNamespaceName();
771
-        $imports = array(
772
-            '*' => empty($namespace) ? '' : $namespace . '\\'
773
-        );
774
-        $file = file_get_contents($class->getFileName());
775
-        $tokens = token_get_all($file);
776
-        $namespace = '';
777
-        $alias = '';
778
-        $reading = false;
779
-        $last = 0;
780
-        foreach ($tokens as $token) {
781
-            if (is_string($token)) {
782
-                if ($reading && ',' == $token) {
783
-                    //===== STOP =====//
784
-                    $reading = false;
785
-                    if (!empty($namespace))
786
-                        $imports[$alias] = trim($namespace, '\\');
787
-                    //===== START =====//
788
-                    $reading = true;
789
-                    $namespace = '';
790
-                    $alias = '';
791
-                } else {
792
-                    //===== STOP =====//
793
-                    $reading = false;
794
-                    if (!empty($namespace))
795
-                        $imports[$alias] = trim($namespace, '\\');
796
-                }
797
-            } elseif (T_USE == $token[0]) {
798
-                //===== START =====//
799
-                $reading = true;
800
-                $namespace = '';
801
-                $alias = '';
802
-            } elseif ($reading) {
803
-                //echo token_name($token[0]) . ' ' . $token[1] . PHP_EOL;
804
-                switch ($token[0]) {
805
-                    case T_WHITESPACE:
806
-                        continue 2;
807
-                    case T_STRING:
808
-                        $alias = $token[1];
809
-                        if (T_AS == $last) {
810
-                            break;
811
-                        }
812
-                    //don't break;
813
-                    case T_NS_SEPARATOR:
814
-                        $namespace .= $token[1];
815
-                        break;
816
-                }
817
-                $last = $token[0];
818
-            }
819
-        }
820
-        return $imports;
821
-    }
768
+	public static function scope(ReflectionClass $class)
769
+	{
770
+		$namespace = $class->getNamespaceName();
771
+		$imports = array(
772
+			'*' => empty($namespace) ? '' : $namespace . '\\'
773
+		);
774
+		$file = file_get_contents($class->getFileName());
775
+		$tokens = token_get_all($file);
776
+		$namespace = '';
777
+		$alias = '';
778
+		$reading = false;
779
+		$last = 0;
780
+		foreach ($tokens as $token) {
781
+			if (is_string($token)) {
782
+				if ($reading && ',' == $token) {
783
+					//===== STOP =====//
784
+					$reading = false;
785
+					if (!empty($namespace))
786
+						$imports[$alias] = trim($namespace, '\\');
787
+					//===== START =====//
788
+					$reading = true;
789
+					$namespace = '';
790
+					$alias = '';
791
+				} else {
792
+					//===== STOP =====//
793
+					$reading = false;
794
+					if (!empty($namespace))
795
+						$imports[$alias] = trim($namespace, '\\');
796
+				}
797
+			} elseif (T_USE == $token[0]) {
798
+				//===== START =====//
799
+				$reading = true;
800
+				$namespace = '';
801
+				$alias = '';
802
+			} elseif ($reading) {
803
+				//echo token_name($token[0]) . ' ' . $token[1] . PHP_EOL;
804
+				switch ($token[0]) {
805
+					case T_WHITESPACE:
806
+						continue 2;
807
+					case T_STRING:
808
+						$alias = $token[1];
809
+						if (T_AS == $last) {
810
+							break;
811
+						}
812
+					//don't break;
813
+					case T_NS_SEPARATOR:
814
+						$namespace .= $token[1];
815
+						break;
816
+				}
817
+				$last = $token[0];
818
+			}
819
+		}
820
+		return $imports;
821
+	}
822 822
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         try {
80 80
             $classMetadata = CommentParser::parse($class->getDocComment());
81 81
         } catch (Exception $e) {
82
-            throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
82
+            throw new RestException(500, "Error while parsing comments of `$className` class. ".$e->getMessage());
83 83
         }
84 84
         $classMetadata['scope'] = $scope = static::scope($class);
85 85
         $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             try {
96 96
                 $metadata = CommentParser::parse($doc) + $classMetadata;
97 97
             } catch (Exception $e) {
98
-                throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. " . $e->getMessage());
98
+                throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. ".$e->getMessage());
99 99
             }
100 100
             //@access should not be private
101 101
             if (isset($metadata['access'])
@@ -157,20 +157,20 @@  discard block
 block discarded – undo
157 157
                 }
158 158
                 $m ['default'] = $defaults [$position];
159 159
                 $m ['required'] = !$param->isOptional();
160
-                $contentType = Util::nestedValue($p,'type');
160
+                $contentType = Util::nestedValue($p, 'type');
161 161
                 if ($type == 'array' && $contentType && $qualified = Scope::resolve($contentType, $scope)) {
162 162
                     list($p['type'], $children, $modelName) = static::getTypeAndModel(
163 163
                         new ReflectionClass($qualified), $scope,
164
-                        $className . Text::title($methodUrl), $p
164
+                        $className.Text::title($methodUrl), $p
165 165
                     );
166 166
                 }
167 167
                 if ($type instanceof ReflectionClass) {
168 168
                     list($type, $children, $modelName) = static::getTypeAndModel($type, $scope,
169
-                        $className . Text::title($methodUrl), $p);
169
+                        $className.Text::title($methodUrl), $p);
170 170
                 } elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
171 171
                     list($type, $children, $modelName)
172 172
                         = static::getTypeAndModel(new ReflectionClass($qualified), $scope,
173
-                        $className . Text::title($methodUrl), $p);
173
+                        $className.Text::title($methodUrl), $p);
174 174
                 }
175 175
                 if (isset($type)) {
176 176
                     $m['type'] = $type;
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
             ) {
249 249
                 foreach ($matches as $match) {
250 250
                     $httpMethod = $match[1];
251
-                    $url = rtrim($resourcePath . $match[2], '/');
251
+                    $url = rtrim($resourcePath.$match[2], '/');
252 252
                     //deep copy the call, as it may change for each @url
253 253
                     $copy = unserialize(serialize($call));
254 254
                     foreach ($copy['metadata']['param'] as $i => $p) {
255 255
                         $inPath =
256
-                            strpos($url, '{' . $p['name'] . '}') ||
257
-                            strpos($url, ':' . $p['name']);
256
+                            strpos($url, '{'.$p['name'].'}') ||
257
+                            strpos($url, ':'.$p['name']);
258 258
                         if ($inPath) {
259 259
                             $copy['metadata']['param'][$i][$dataName]['from'] = 'path';
260 260
                         } elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') {
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
                         }
265 265
                     }
266 266
                     $url = preg_replace_callback('/{[^}]+}|:[^\/]+/',
267
-                        function ($matches) use ($copy) {
267
+                        function($matches) use ($copy) {
268 268
                             $match = trim($matches[0], '{}:');
269 269
                             $index = $copy['arguments'][$match];
270
-                            return '{' .
270
+                            return '{'.
271 271
                             Routes::typeChar(isset(
272 272
                                 $copy['metadata']['param'][$index]['type'])
273 273
                                 ? $copy['metadata']['param'][$index]['type']
274 274
                                 : null)
275
-                            . $index . '}';
275
+                            . $index.'}';
276 276
                         }, $url);
277 277
                     static::addPath($url, $copy, $httpMethod, $version);
278 278
                 }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
                     $methodUrl = '';
293 293
                 }
294 294
                 $url = empty($methodUrl) ? rtrim($resourcePath, '/')
295
-                    : $resourcePath . $methodUrl;
295
+                    : $resourcePath.$methodUrl;
296 296
                 for ($position = 0; $position < count($params); $position++) {
297 297
                     $from = $metadata['param'][$position][$dataName]['from'];
298 298
                     if ($from == 'body' && ($httpMethod == 'GET' ||
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
                 foreach ($pathParams as $position) {
310 310
                     if (!empty($url))
311 311
                         $url .= '/';
312
-                    $url .= '{' .
312
+                    $url .= '{'.
313 313
                         static::typeChar(isset($call['metadata']['param'][$position]['type'])
314 314
                             ? $call['metadata']['param'][$position]['type']
315 315
                             : null)
316
-                        . $position . '}';
316
+                        . $position.'}';
317 317
                     if ($allowAmbiguity || $position == $lastPathParam) {
318 318
                         static::addPath($url, $call, $httpMethod, $version);
319 319
                     }
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
     {
344 344
         $call['url'] = preg_replace_callback(
345 345
             "/\{\S(\d+)\}/",
346
-            function ($matches) use ($call) {
347
-                return '{' .
348
-                $call['metadata']['param'][$matches[1]]['name'] . '}';
346
+            function($matches) use ($call) {
347
+                return '{'.
348
+                $call['metadata']['param'][$matches[1]]['name'].'}';
349 349
             },
350 350
             $path
351 351
         );
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
             return static::populate($p[$path][$httpMethod], $data);
391 391
         } elseif (isset($p['*'])) {
392 392
             //================== wildcard routes ========================
393
-            uksort($p['*'], function ($a, $b) {
393
+            uksort($p['*'], function($a, $b) {
394 394
                 return strlen($b) - strlen($a);
395 395
             });
396 396
             foreach ($p['*'] as $key => $value) {
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
         if (substr($path, -1) == '/')
411 411
             $path .= PHP_EOL;
412 412
         //if double slash is found fill in newline char;
413
-        $path = str_replace('//', '/' . PHP_EOL . '/', $path);
413
+        $path = str_replace('//', '/'.PHP_EOL.'/', $path);
414 414
         ksort($p);
415 415
         foreach ($p as $key => $value) {
416 416
             if (!isset($value[$httpMethod])) {
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
                     } else {
435 435
                         $status = 400;
436 436
                         $message = 'invalid value specified for `'
437
-                            . $details['name'] . '`';
437
+                            . $details['name'].'`';
438 438
                         $found = false;
439 439
                         break;
440 440
                     }
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
             }
453 453
         }
454 454
         if ($status == 405) {
455
-            header('Allow: ' . implode(', ', $methods));
455
+            header('Allow: '.implode(', ', $methods));
456 456
         }
457 457
         throw new RestException($status, $message);
458 458
     }
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             $all = $all['*'] + $all;
467 467
             unset($all['*']);
468 468
         }
469
-        if(is_array($all)){
469
+        if (is_array($all)) {
470 470
             foreach ($all as $fullPath => $routes) {
471 471
                 foreach ($routes as $httpMethod => $route) {
472 472
                     if (in_array($httpMethod, $excludedHttpMethods)) {
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                             continue 2;
481 481
                         }
482 482
                     }
483
-                    $hash = "$httpMethod " . $route['url'];
483
+                    $hash = "$httpMethod ".$route['url'];
484 484
                     if (!isset($filter[$hash])) {
485 485
                         $route['httpMethod'] = $httpMethod;
486 486
                         $map[$route['metadata']['resourcePath']][]
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
             $stage = end(Scope::get('Restler')->getEvents());
571 571
             if (empty($stage))
572 572
                 $stage = 'setup';
573
-            $r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
573
+            $r = Scope::get($r->className)->$modifier($r, $stage) ?: $r;
574 574
         }
575 575
         return $r;
576 576
     }
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
         }
616 616
         $p = 'property';
617 617
         $r = empty($c[$p]) ? array() : $c[$p];
618
-        $p .= '-' . ($forResponse ? 'read' : 'write');
618
+        $p .= '-'.($forResponse ? 'read' : 'write');
619 619
         if (!empty($c[$p])) {
620 620
             $r = array_merge($r, $c[$p]);
621 621
         }
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
      *
636 636
      * @access protected
637 637
      */
638
-    protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix='', array $rules=array())
638
+    protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix = '', array $rules = array())
639 639
     {
640 640
         $className = $class->getName();
641 641
         $dataName = CommentParser::$embeddedDataName;
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
             if ($magic_properties = static::parseMagic($class, empty($prefix))) {
648 648
                 foreach ($magic_properties as $prop) {
649 649
                     if (!isset($prop['name'])) {
650
-                        throw new Exception('@property comment is not properly defined in ' . $className . ' class');
650
+                        throw new Exception('@property comment is not properly defined in '.$className.' class');
651 651
                     }
652 652
                     if (!isset($prop[$dataName]['label'])) {
653 653
                         $prop[$dataName]['label'] = Text::title($prop['name']);
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
             }
704 704
         } catch (Exception $e) {
705 705
             if (Text::endsWith($e->getFile(), 'CommentParser.php')) {
706
-                throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
706
+                throw new RestException(500, "Error while parsing comments of `$className` class. ".$e->getMessage());
707 707
             }
708 708
             throw $e;
709 709
         }
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
     {
770 770
         $namespace = $class->getNamespaceName();
771 771
         $imports = array(
772
-            '*' => empty($namespace) ? '' : $namespace . '\\'
772
+            '*' => empty($namespace) ? '' : $namespace.'\\'
773 773
         );
774 774
         $file = file_get_contents($class->getFileName());
775 775
         $tokens = token_get_all($file);
Please login to merge, or discard this patch.
Braces   +45 added lines, -26 removed lines patch added patch discarded remove patch
@@ -124,9 +124,10 @@  discard block
 block discarded – undo
124 124
                 $metadata['param'] = array();
125 125
             }
126 126
             if (isset($metadata['return']['type'])) {
127
-                if ($qualified = Scope::resolve($metadata['return']['type'], $scope))
128
-                    list($metadata['return']['type'], $metadata['return']['children']) =
127
+                if ($qualified = Scope::resolve($metadata['return']['type'], $scope)) {
128
+                                    list($metadata['return']['type'], $metadata['return']['children']) =
129 129
                         static::getTypeAndModel(new ReflectionClass($qualified), $scope);
130
+                }
130 131
             } else {
131 132
                 //assume return type is array
132 133
                 $metadata['return']['type'] = 'array';
@@ -147,8 +148,9 @@  discard block
 block discarded – undo
147 148
                     $m[$dataName] = array();
148 149
                 }
149 150
                 $p = &$m[$dataName];
150
-                if (empty($m['label']))
151
-                    $m['label'] = Text::title($m['name']);
151
+                if (empty($m['label'])) {
152
+                                    $m['label'] = Text::title($m['name']);
153
+                }
152 154
                 if (is_null($type) && isset($m['type'])) {
153 155
                     $type = $m['type'];
154 156
                 }
@@ -307,8 +309,9 @@  discard block
 block discarded – undo
307 309
                 }
308 310
                 $lastPathParam = end($pathParams);
309 311
                 foreach ($pathParams as $position) {
310
-                    if (!empty($url))
311
-                        $url .= '/';
312
+                    if (!empty($url)) {
313
+                                            $url .= '/';
314
+                    }
312 315
                     $url .= '{' .
313 316
                         static::typeChar(isset($call['metadata']['param'][$position]['type'])
314 317
                             ? $call['metadata']['param'][$position]['type']
@@ -356,8 +359,9 @@  discard block
 block discarded – undo
356 359
         } else {
357 360
             static::$routes["v$version"][$path][$httpMethod] = $call;
358 361
             //create an alias with index if the method name is index
359
-            if ($call['methodName'] == 'index')
360
-                static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
362
+            if ($call['methodName'] == 'index') {
363
+                            static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
364
+            }
361 365
         }
362 366
     }
363 367
 
@@ -407,8 +411,9 @@  discard block
 block discarded – undo
407 411
         }
408 412
         //================== dynamic routes =============================
409 413
         //add newline char if trailing slash is found
410
-        if (substr($path, -1) == '/')
411
-            $path .= PHP_EOL;
414
+        if (substr($path, -1) == '/') {
415
+                    $path .= PHP_EOL;
416
+        }
412 417
         //if double slash is found fill in newline char;
413 418
         $path = str_replace('//', '/' . PHP_EOL . '/', $path);
414 419
         ksort($p);
@@ -474,8 +479,9 @@  discard block
 block discarded – undo
474 479
                     }
475 480
                     foreach ($excludedPaths as $exclude) {
476 481
                         if (empty($exclude)) {
477
-                            if ($fullPath == $exclude || $fullPath == 'index')
478
-                                continue 2;
482
+                            if ($fullPath == $exclude || $fullPath == 'index') {
483
+                                                            continue 2;
484
+                            }
479 485
                         } elseif (Text::beginsWith($fullPath, $exclude)) {
480 486
                             continue 2;
481 487
                         }
@@ -495,13 +501,15 @@  discard block
 block discarded – undo
495 501
 
496 502
     public static function verifyAccess($route)
497 503
     {
498
-        if ($route['accessLevel'] < 2)
499
-            return true;
504
+        if ($route['accessLevel'] < 2) {
505
+                    return true;
506
+        }
500 507
         /** @var Restler $r */
501 508
         $r = Scope::get('Restler');
502 509
         $authenticated = $r->_authenticated;
503
-        if (!$authenticated && $route['accessLevel'] > 1)
504
-            return false;
510
+        if (!$authenticated && $route['accessLevel'] > 1) {
511
+                    return false;
512
+        }
505 513
         if (
506 514
             $authenticated &&
507 515
             Defaults::$accessControlFunction &&
@@ -568,8 +576,9 @@  discard block
 block discarded – undo
568 576
         $modifier = "_modify_{$r->methodName}_api";
569 577
         if (method_exists($r->className, $modifier)) {
570 578
             $stage = end(Scope::get('Restler')->getEvents());
571
-            if (empty($stage))
572
-                $stage = 'setup';
579
+            if (empty($stage)) {
580
+                            $stage = 'setup';
581
+            }
573 582
             $r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
574 583
         }
575 584
         return $r;
@@ -758,10 +767,18 @@  discard block
 block discarded – undo
758 767
 
759 768
     public static function type($var)
760 769
     {
761
-        if (is_object($var)) return get_class($var);
762
-        if (is_array($var)) return 'array';
763
-        if (is_bool($var)) return 'boolean';
764
-        if (is_numeric($var)) return is_float($var) ? 'float' : 'int';
770
+        if (is_object($var)) {
771
+        	return get_class($var);
772
+        }
773
+        if (is_array($var)) {
774
+        	return 'array';
775
+        }
776
+        if (is_bool($var)) {
777
+        	return 'boolean';
778
+        }
779
+        if (is_numeric($var)) {
780
+        	return is_float($var) ? 'float' : 'int';
781
+        }
765 782
         return 'string';
766 783
     }
767 784
 
@@ -782,8 +799,9 @@  discard block
 block discarded – undo
782 799
                 if ($reading && ',' == $token) {
783 800
                     //===== STOP =====//
784 801
                     $reading = false;
785
-                    if (!empty($namespace))
786
-                        $imports[$alias] = trim($namespace, '\\');
802
+                    if (!empty($namespace)) {
803
+                                            $imports[$alias] = trim($namespace, '\\');
804
+                    }
787 805
                     //===== START =====//
788 806
                     $reading = true;
789 807
                     $namespace = '';
@@ -791,8 +809,9 @@  discard block
 block discarded – undo
791 809
                 } else {
792 810
                     //===== STOP =====//
793 811
                     $reading = false;
794
-                    if (!empty($namespace))
795
-                        $imports[$alias] = trim($namespace, '\\');
812
+                    if (!empty($namespace)) {
813
+                                            $imports[$alias] = trim($namespace, '\\');
814
+                    }
796 815
                 }
797 816
             } elseif (T_USE == $token[0]) {
798 817
                 //===== START =====//
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -379,7 +379,7 @@
 block discarded – undo
379 379
         if (!$p) {
380 380
             throw new RestException(
381 381
                 404,
382
-                $version == 1 ? '' : "Version $version is not supported"
382
+                $version == 1 ? '' : "version $version is not supported"
383 383
             );
384 384
         }
385 385
         $status = 404;
Please login to merge, or discard this patch.
includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@
 block discarded – undo
9 9
  */
10 10
 interface iProvideMultiVersionApi
11 11
 {
12
-    /**
13
-     * Maximum api version supported by the api class
14
-     * @return int
15
-     */
16
-    public static function __getMaximumSupportedVersion();
12
+	/**
13
+	 * Maximum api version supported by the api class
14
+	 * @return int
15
+	 */
16
+	public static function __getMaximumSupportedVersion();
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/iCompose.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@
 block discarded – undo
16 16
  *
17 17
  */
18 18
 interface iCompose {
19
-    /**
20
-     * Result of an api call is passed to this method
21
-     * to create a standard structure for the data
22
-     *
23
-     * @param mixed $result can be a primitive or array or object
24
-     */
25
-    public function response($result);
19
+	/**
20
+	 * Result of an api call is passed to this method
21
+	 * to create a standard structure for the data
22
+	 *
23
+	 * @param mixed $result can be a primitive or array or object
24
+	 */
25
+	public function response($result);
26 26
 
27
-    /**
28
-     * When the api call results in RestException this method
29
-     * will be called to return the error message
30
-     *
31
-     * @param RestException $exception exception that has reasons for failure
32
-     *
33
-     * @return
34
-     */
35
-    public function message(RestException $exception);
27
+	/**
28
+	 * When the api call results in RestException this method
29
+	 * will be called to return the error message
30
+	 *
31
+	 * @param RestException $exception exception that has reasons for failure
32
+	 *
33
+	 * @return
34
+	 */
35
+	public function message(RestException $exception);
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php 3 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,84 +15,84 @@
 block discarded – undo
15 15
 
16 16
 class EventDispatcher
17 17
 {
18
-    private $listeners = array();
19
-    protected static $_waitList = array();
18
+	private $listeners = array();
19
+	protected static $_waitList = array();
20 20
 
21
-    public static $self;
22
-    protected $events = array();
21
+	public static $self;
22
+	protected $events = array();
23 23
 
24
-    public function __construct() {
25
-        static::$self = $this;
26
-        if (!empty(static::$_waitList)) {
27
-            foreach (static::$_waitList as $param) {
28
-                call_user_func_array(array($this,$param[0]), $param[1]);
29
-            }
30
-        }
31
-    }
24
+	public function __construct() {
25
+		static::$self = $this;
26
+		if (!empty(static::$_waitList)) {
27
+			foreach (static::$_waitList as $param) {
28
+				call_user_func_array(array($this,$param[0]), $param[1]);
29
+			}
30
+		}
31
+	}
32 32
 
33
-    public static function __callStatic($eventName, $params)
34
-    {
35
-        if (0 === strpos($eventName, 'on')) {
36
-            if(static::$self){
37
-                return call_user_func_array(array(static::$self, $eventName), $params);
38
-            }
39
-            static::$_waitList[] = func_get_args();
40
-            return false;
41
-        }
42
-    }
33
+	public static function __callStatic($eventName, $params)
34
+	{
35
+		if (0 === strpos($eventName, 'on')) {
36
+			if(static::$self){
37
+				return call_user_func_array(array(static::$self, $eventName), $params);
38
+			}
39
+			static::$_waitList[] = func_get_args();
40
+			return false;
41
+		}
42
+	}
43 43
 
44
-    public function __call($eventName, $params)
45
-    {
46
-        if (0 === strpos($eventName, 'on')) {
47
-            if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName]))
48
-                $this->listeners[$eventName] = array();
49
-            $this->listeners[$eventName][] = $params[0];
50
-        }
51
-        return $this;
52
-    }
44
+	public function __call($eventName, $params)
45
+	{
46
+		if (0 === strpos($eventName, 'on')) {
47
+			if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName]))
48
+				$this->listeners[$eventName] = array();
49
+			$this->listeners[$eventName][] = $params[0];
50
+		}
51
+		return $this;
52
+	}
53 53
 
54
-    public static function addListener($eventName, Closure $callback)
55
-    {
56
-        return static::$eventName($callback);
57
-    }
54
+	public static function addListener($eventName, Closure $callback)
55
+	{
56
+		return static::$eventName($callback);
57
+	}
58 58
 
59
-    public function on(array $eventHandlers)
60
-    {
61
-        for (
62
-            $count = count($eventHandlers),
63
-                $events = array_map(
64
-                    'ucfirst',
65
-                    $keys = array_keys(
66
-                        $eventHandlers = array_change_key_case(
67
-                            $eventHandlers,
68
-                            CASE_LOWER
69
-                        )
70
-                    )
71
-                ),
72
-                $i = 0;
73
-            $i < $count;
74
-            call_user_func(
75
-                array($this, "on{$events[$i]}"),
76
-                $eventHandlers[$keys[$i++]]
77
-            )
78
-        );
79
-    }
59
+	public function on(array $eventHandlers)
60
+	{
61
+		for (
62
+			$count = count($eventHandlers),
63
+				$events = array_map(
64
+					'ucfirst',
65
+					$keys = array_keys(
66
+						$eventHandlers = array_change_key_case(
67
+							$eventHandlers,
68
+							CASE_LOWER
69
+						)
70
+					)
71
+				),
72
+				$i = 0;
73
+			$i < $count;
74
+			call_user_func(
75
+				array($this, "on{$events[$i]}"),
76
+				$eventHandlers[$keys[$i++]]
77
+			)
78
+		);
79
+	}
80 80
 
81
-    /**
82
-     * Fire an event to notify all listeners
83
-     *
84
-     * @param string $eventName name of the event
85
-     * @param array  $params    event related data
86
-     */
87
-    protected function dispatch($eventName, array $params = array())
88
-    {
89
-        $this->events[] = $eventName;
90
-        $params = func_get_args();
91
-        $eventName = 'on'.ucfirst(array_shift($params));
92
-        if (isset($this->listeners[$eventName]))
93
-            foreach ($this->listeners[$eventName] as $callback)
94
-                call_user_func_array($callback, $params);
95
-    }
81
+	/**
82
+	 * Fire an event to notify all listeners
83
+	 *
84
+	 * @param string $eventName name of the event
85
+	 * @param array  $params    event related data
86
+	 */
87
+	protected function dispatch($eventName, array $params = array())
88
+	{
89
+		$this->events[] = $eventName;
90
+		$params = func_get_args();
91
+		$eventName = 'on'.ucfirst(array_shift($params));
92
+		if (isset($this->listeners[$eventName]))
93
+			foreach ($this->listeners[$eventName] as $callback)
94
+				call_user_func_array($callback, $params);
95
+	}
96 96
 
97 97
 }
98 98
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         static::$self = $this;
26 26
         if (!empty(static::$_waitList)) {
27 27
             foreach (static::$_waitList as $param) {
28
-                call_user_func_array(array($this,$param[0]), $param[1]);
28
+                call_user_func_array(array($this, $param[0]), $param[1]);
29 29
             }
30 30
         }
31 31
     }
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public static function __callStatic($eventName, $params)
34 34
     {
35 35
         if (0 === strpos($eventName, 'on')) {
36
-            if(static::$self){
36
+            if (static::$self) {
37 37
                 return call_user_func_array(array(static::$self, $eventName), $params);
38 38
             }
39 39
             static::$_waitList[] = func_get_args();
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,8 +44,9 @@  discard block
 block discarded – undo
44 44
     public function __call($eventName, $params)
45 45
     {
46 46
         if (0 === strpos($eventName, 'on')) {
47
-            if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName]))
48
-                $this->listeners[$eventName] = array();
47
+            if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName])) {
48
+                            $this->listeners[$eventName] = array();
49
+            }
49 50
             $this->listeners[$eventName][] = $params[0];
50 51
         }
51 52
         return $this;
@@ -89,9 +90,10 @@  discard block
 block discarded – undo
89 90
         $this->events[] = $eventName;
90 91
         $params = func_get_args();
91 92
         $eventName = 'on'.ucfirst(array_shift($params));
92
-        if (isset($this->listeners[$eventName]))
93
-            foreach ($this->listeners[$eventName] as $callback)
93
+        if (isset($this->listeners[$eventName])) {
94
+                    foreach ($this->listeners[$eventName] as $callback)
94 95
                 call_user_func_array($callback, $params);
96
+        }
95 97
     }
96 98
 
97 99
 }
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/ExplorerInfo.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
  */
9 9
 class ExplorerInfo
10 10
 {
11
-    public static $title = 'Restler API Explorer';
12
-    public static $description = 'Live API Documentation';
13
-    public static $termsOfService = null;
14
-    public static $contact = array(
15
-        'name'  => 'Restler Support',
16
-        'url'   => 'luracast.com/products/restler',
17
-        'email' => '[email protected]',
18
-    );
19
-    public static $license = array(
20
-        'name' => 'LGPL-2.1',
21
-        'url'  => 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html',
22
-    );
11
+	public static $title = 'Restler API Explorer';
12
+	public static $description = 'Live API Documentation';
13
+	public static $termsOfService = null;
14
+	public static $contact = array(
15
+		'name'  => 'Restler Support',
16
+		'url'   => 'luracast.com/products/restler',
17
+		'email' => '[email protected]',
18
+	);
19
+	public static $license = array(
20
+		'name' => 'LGPL-2.1',
21
+		'url'  => 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html',
22
+	);
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/printipp/CupsPrintIPP.php 3 patches
Indentation   +721 added lines, -721 removed lines patch added patch discarded remove patch
@@ -40,735 +40,735 @@
 block discarded – undo
40 40
 
41 41
 class CupsPrintIPP extends ExtendedPrintIPP
42 42
 {
43
-    public $printers_attributes;
44
-    public $defaults_attributes;
43
+	public $printers_attributes;
44
+	public $defaults_attributes;
45 45
 
46
-    protected $parsed;
47
-    protected $output;
46
+	protected $parsed;
47
+	protected $output;
48 48
 
49
-    public function __construct()
50
-    {
51
-        parent::__construct();
52
-        self::_initTags();
53
-    }
49
+	public function __construct()
50
+	{
51
+		parent::__construct();
52
+		self::_initTags();
53
+	}
54 54
 
55 55
 //
56 56
 // OPERATIONS
57 57
 //
58
-    public function cupsGetDefaults($attributes=array("all"))
59
-    {
60
-        //The CUPS-Get-Default operation returns the default printer URI and attributes
61
-
62
-        $this->jobs = array_merge($this->jobs,array(""));
63
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
64
-        $this->parsed = array();
65
-        unset($this->printer_attributes);
66
-
67
-        if (!isset($this->setup->charset))
68
-        {
69
-            self::setCharset();
70
-        }
71
-
72
-        if (!isset($this->setup->language))
73
-        {
74
-            self::setLanguage('en');
75
-        }
76
-
77
-        self::_setOperationId();
78
-
79
-        for($i = 0 ; $i < count($attributes) ; $i++)
80
-        {
81
-            if ($i == 0)
82
-            {
83
-                $this->meta->attributes = chr(0x44) // Keyword
84
-                                        . self::_giveMeStringLength('requested-attributes')
85
-                                        . 'requested-attributes'
86
-                                        . self::_giveMeStringLength($attributes[0])
87
-                                        . $attributes[0];
88
-            }
89
-            else
90
-            {
91
-                $this->meta->attributes .= chr(0x44) // Keyword
92
-                                        .  chr(0x0).chr(0x0) // zero-length name
93
-                                        .  self::_giveMeStringLength($attributes[$i])
94
-                                        .  $attributes[$i];
95
-            }
96
-        }
97
-
98
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
99
-                         . chr(0x40). chr(0x01) // operation:  cups vendor extension: get defaults
100
-                         . $this->meta->operation_id // request-id
101
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
102
-                         . $this->meta->charset
103
-                         . $this->meta->language
104
-                         . $this->meta->attributes
105
-                         . chr(0x03); // end operations attribute
106
-
107
-        $this->output = $this->stringjob;
108
-
109
-        self::_putDebug("Request: ".$this->output);
110
-
111
-        $post_values = array( "Content-Type" => "application/ipp",
112
-                              "Data" => $this->output);
113
-
114
-        if (self::_sendHttp ($post_values,'/'))
115
-        {
116
-
117
-            if(self::_parseServerOutput())
118
-            {
119
-                self::_parsePrinterAttributes();
120
-            }
121
-        }
122
-
123
-       $this->attributes = &$this->printer_attributes;
124
-
125
-       if (isset($this->printer_attributes->printer_type))
126
-       {
127
-                    $printer_type = $this->printer_attributes->printer_type->_value0;
128
-                    $table = self::_interpretPrinterType($printer_type);
129
-
130
-                    for($i = 0 ; $i < count($table) ; $i++ )
131
-                    {
132
-                        $index = '_value'.$i;
133
-                        $this->printer_attributes->printer_type->$index = $table[$i];
134
-                        }
135
-                    }
136
-
137
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
138
-        {
139
-
140
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
141
-            if ($this->serveroutput->status == "successfull-ok")
142
-            {
143
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
144
-            }
145
-            else
146
-            {
147
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
148
-            }
149
-
150
-            return $this->serveroutput->status;
151
-        }
152
-        else
153
-        {
154
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
155
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
156
-            }
157
-    return false;
158
-    }
159
-
160
-
161
-    public function cupsAcceptJobs($printer_uri)
162
-    {
163
-    //The CUPS-Get-Default operation returns the default printer URI and attributes
164
-
165
-        $this->jobs = array_merge($this->jobs,array(""));
166
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
167
-        $this->parsed = array();
168
-        unset($this->printer_attributes);
169
-
170
-        if (!isset($this->setup->charset))
171
-        {
172
-            self::setCharset();
173
-        }
174
-
175
-        if (!isset($this->setup->language))
176
-        {
177
-            self::setLanguage('en');
178
-        }
179
-
180
-        self::_setOperationId();
181
-
182
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
183
-                         . chr(0x40). chr(0x08) // operation:  cups vendor extension: Accept-Jobs
184
-                         . $this->meta->operation_id // request-id
185
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
186
-                         . $this->meta->charset
187
-                         . $this->meta->language
188
-                         . chr(0x45) // uri
189
-                         . self::_giveMeStringLength('printer-uri')
190
-                         . 'printer-uri'
191
-                         . self::_giveMeStringLength($printer_uri)
192
-                         . $printer_uri
193
-                         . chr(0x03); // end operations attribute
194
-
195
-        $this->output = $this->stringjob;
196
-
197
-        self::_putDebug("Request: ".$this->output);
198
-
199
-        $post_values = array( "Content-Type" => "application/ipp",
200
-                              "Data" => $this->output);
201
-
202
-        if (self::_sendHttp ($post_values,'/admin/'))
203
-        {
204
-
205
-            if(self::_parseServerOutput())
206
-            {
207
-                self::_parseAttributes();
208
-            }
209
-        }
210
-
211
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
212
-        {
213
-
214
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
215
-            if ($this->serveroutput->status == "successfull-ok")
216
-            {
217
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
218
-            }
219
-            else
220
-            {
221
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
222
-            }
223
-
224
-            return $this->serveroutput->status;
225
-        }
226
-        else
227
-        {
228
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
229
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
230
-            }
231
-    return false;
232
-    }
233
-
234
-
235
-    public function cupsRejectJobs($printer_uri,$printer_state_message)
236
-    {
237
-    //The CUPS-Get-Default operation returns the default printer URI and attributes
238
-
239
-        $this->jobs = array_merge($this->jobs,array(""));
240
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
241
-        $this->parsed = array();
242
-        unset($this->attributes);
243
-
244
-        if (!isset($this->setup->charset))
245
-        {
246
-            self::setCharset();
247
-        }
248
-
249
-        if (!isset($this->setup->language))
250
-        {
251
-            self::setLanguage('en');
252
-        }
253
-
254
-        self::_setOperationId();
255
-
256
-        $message = "";
257
-        if ($printer_state_message)
258
-        {
259
-            $message = chr(0x04) // start printer-attributes
260
-                     . chr(0x41) // textWithoutLanguage
261
-                     . self::_giveMeStringLength("printer-state-message")
262
-                     . "printer-state-message"
263
-                     . self::_giveMeStringLength($printer_state_message)
264
-                     . $printer_state_message;
265
-        }
266
-
267
-       $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
268
-                         . chr(0x40). chr(0x09) // operation:  cups vendor extension: Reject-Jobs
269
-                         . $this->meta->operation_id // request-id
270
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
271
-                         . $this->meta->charset
272
-                         . $this->meta->language
273
-                         . chr(0x45) // uri
274
-                         . self::_giveMeStringLength('printer-uri')
275
-                         . 'printer-uri'
276
-                         . self::_giveMeStringLength($printer_uri)
277
-                         . $printer_uri
278
-                         . $message
279
-                         . chr(0x03); // end operations attribute
280
-
281
-        $this->output = $this->stringjob;
282
-
283
-        self::_putDebug("Request: ".$this->output);
284
-
285
-        $post_values = array( "Content-Type" => "application/ipp",
286
-                              "Data" => $this->output);
287
-
288
-        if (self::_sendHttp ($post_values,'/admin/'))
289
-        {
290
-
291
-            if(self::_parseServerOutput())
292
-            {
293
-                self::_parseAttributes();
294
-            }
295
-        }
296
-
297
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
298
-        {
299
-
300
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
301
-            if ($this->serveroutput->status == "successfull-ok")
302
-            {
303
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
304
-            }
305
-            else
306
-            {
307
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
308
-            }
309
-
310
-            return $this->serveroutput->status;
311
-        }
312
-        else
313
-        {
314
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
315
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
316
-        }
317
-        return false;
318
-    }
319
-
320
-
321
-    public function getPrinters($printer_location=false,$printer_info=false,$attributes=array())
322
-    {
323
-        if (count($attributes) == 0)
324
-        {
325
-            true;
326
-        }
327
-        $attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
-        $this->jobs = array_merge($this->jobs,array(""));
329
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
330
-
331
-        unset ($this->printers_attributes);
332
-
333
-        if (!isset($this->setup->charset))
334
-        {
335
-            self::setCharset();
336
-        }
337
-
338
-        if (!isset($this->setup->language))
339
-        {
340
-            self::setLanguage('en-us');
341
-        }
342
-
343
-        self::_setOperationId();
344
-
345
-        $this->meta->attributes='';
346
-
347
-        if ($printer_location)
348
-        {
349
-            $this->meta->attributes .= chr(0x41) // textWithoutLanguage
350
-                                    . self::_giveMeStringLength('printer-location')
351
-                                    . 'printer-location'
352
-                                    . self::_giveMeStringLength($printer_location)
353
-                                    . $printer_location;
354
-        }
355
-
356
-        if ($printer_info)
357
-        {
358
-            $this->meta->attributes .= chr(0x41) // textWithoutLanguage
359
-                                    . self::_giveMeStringLength('printer-info')
360
-                                    . 'printer-info'
361
-                                    . self::_giveMeStringLength($printer_info)
362
-                                    . $printer_info;
363
-        }
364
-
365
-        for($i = 0 ; $i < count($attributes) ; $i++)
366
-        {
367
-            if ($i == 0)
368
-            {
369
-                $this->meta->attributes .= chr(0x44) // Keyword
370
-                                        . self::_giveMeStringLength('requested-attributes')
371
-                                        . 'requested-attributes'
372
-                                        . self::_giveMeStringLength($attributes[0])
373
-                                        . $attributes[0];
374
-            }
375
-            else
376
-            {
377
-                $this->meta->attributes .= chr(0x44) // Keyword
378
-                                        .  chr(0x0).chr(0x0) // zero-length name
379
-                                        .  self::_giveMeStringLength($attributes[$i])
380
-                                        .  $attributes[$i];
381
-            }
382
-        }
383
-
384
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
385
-                         . chr(0x40). chr(0x02) // operation:  cups vendor extension: get printers
386
-                         . $this->meta->operation_id //           request-id
387
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
388
-                         . $this->meta->charset
389
-                         . $this->meta->language
390
-                         . $this->meta->attributes
391
-                         . chr(0x03); // end operations attribute
392
-
393
-        $this->output = $this->stringjob;
394
-
395
-        $post_values = array( "Content-Type" => "application/ipp",
396
-                              "Data" => $this->output);
397
-
398
-        if (self::_sendHttp ($post_values,'/'))
399
-        {
400
-
401
-            if(self::_parseServerOutput())
402
-            {
403
-                $this->_getAvailablePrinters();
404
-            }
405
-        }
406
-
407
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
408
-        {
409
-
410
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
411
-            if ($this->serveroutput->status == "successfull-ok")
412
-            {
413
-                self::_errorLog("getting printers: ".$this->serveroutput->status,3);
414
-            }
415
-            else
416
-            {
417
-                self::_errorLog("getting printers: ".$this->serveroutput->status,1);
418
-            }
419
-            return $this->serveroutput->status;
420
-        }
421
-        else
422
-        {
423
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
424
-            self::_errorLog("getting printers : OPERATION FAILED",1);
425
-        }
426
-        return false;
427
-    }
428
-
429
-
430
-    public function cupsGetPrinters ()
431
-    {
432
-        // alias for getPrinters();
433
-        self::getPrinters();
434
-    }
435
-
436
-
437
-    public function getPrinterAttributes()
438
-    {
439
-        // complete informations from parent with Cups-specific stuff
440
-
441
-        if(!$result = parent::getPrinterAttributes())
442
-        {
443
-            return FALSE;
444
-        }
445
-        if(!isset($this->printer_attributes))
446
-        {
447
-            return FALSE;
448
-        }
449
-
450
-        if (isset ($this->printer_attributes->printer_type))
451
-        {
452
-            $printer_type = $this->printer_attributes->printer_type->_value0;
453
-            $table = self::_interpretPrinterType($printer_type);
454
-
455
-            for($i = 0 ; $i < count($table) ; $i++ )
456
-            {
457
-                $index = '_value'.$i;
458
-                $this->printer_attributes->printer_type->$index = $table[$i];
459
-            }
460
-        }
461
-
462
-        return $result;
463
-    }
58
+	public function cupsGetDefaults($attributes=array("all"))
59
+	{
60
+		//The CUPS-Get-Default operation returns the default printer URI and attributes
61
+
62
+		$this->jobs = array_merge($this->jobs,array(""));
63
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
64
+		$this->parsed = array();
65
+		unset($this->printer_attributes);
66
+
67
+		if (!isset($this->setup->charset))
68
+		{
69
+			self::setCharset();
70
+		}
71
+
72
+		if (!isset($this->setup->language))
73
+		{
74
+			self::setLanguage('en');
75
+		}
76
+
77
+		self::_setOperationId();
78
+
79
+		for($i = 0 ; $i < count($attributes) ; $i++)
80
+		{
81
+			if ($i == 0)
82
+			{
83
+				$this->meta->attributes = chr(0x44) // Keyword
84
+										. self::_giveMeStringLength('requested-attributes')
85
+										. 'requested-attributes'
86
+										. self::_giveMeStringLength($attributes[0])
87
+										. $attributes[0];
88
+			}
89
+			else
90
+			{
91
+				$this->meta->attributes .= chr(0x44) // Keyword
92
+										.  chr(0x0).chr(0x0) // zero-length name
93
+										.  self::_giveMeStringLength($attributes[$i])
94
+										.  $attributes[$i];
95
+			}
96
+		}
97
+
98
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
99
+						 . chr(0x40). chr(0x01) // operation:  cups vendor extension: get defaults
100
+						 . $this->meta->operation_id // request-id
101
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
102
+						 . $this->meta->charset
103
+						 . $this->meta->language
104
+						 . $this->meta->attributes
105
+						 . chr(0x03); // end operations attribute
106
+
107
+		$this->output = $this->stringjob;
108
+
109
+		self::_putDebug("Request: ".$this->output);
110
+
111
+		$post_values = array( "Content-Type" => "application/ipp",
112
+							  "Data" => $this->output);
113
+
114
+		if (self::_sendHttp ($post_values,'/'))
115
+		{
116
+
117
+			if(self::_parseServerOutput())
118
+			{
119
+				self::_parsePrinterAttributes();
120
+			}
121
+		}
122
+
123
+	   $this->attributes = &$this->printer_attributes;
124
+
125
+	   if (isset($this->printer_attributes->printer_type))
126
+	   {
127
+					$printer_type = $this->printer_attributes->printer_type->_value0;
128
+					$table = self::_interpretPrinterType($printer_type);
129
+
130
+					for($i = 0 ; $i < count($table) ; $i++ )
131
+					{
132
+						$index = '_value'.$i;
133
+						$this->printer_attributes->printer_type->$index = $table[$i];
134
+						}
135
+					}
136
+
137
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
138
+		{
139
+
140
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
141
+			if ($this->serveroutput->status == "successfull-ok")
142
+			{
143
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
144
+			}
145
+			else
146
+			{
147
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
148
+			}
149
+
150
+			return $this->serveroutput->status;
151
+		}
152
+		else
153
+		{
154
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
155
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
156
+			}
157
+	return false;
158
+	}
159
+
160
+
161
+	public function cupsAcceptJobs($printer_uri)
162
+	{
163
+	//The CUPS-Get-Default operation returns the default printer URI and attributes
164
+
165
+		$this->jobs = array_merge($this->jobs,array(""));
166
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
167
+		$this->parsed = array();
168
+		unset($this->printer_attributes);
169
+
170
+		if (!isset($this->setup->charset))
171
+		{
172
+			self::setCharset();
173
+		}
174
+
175
+		if (!isset($this->setup->language))
176
+		{
177
+			self::setLanguage('en');
178
+		}
179
+
180
+		self::_setOperationId();
181
+
182
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
183
+						 . chr(0x40). chr(0x08) // operation:  cups vendor extension: Accept-Jobs
184
+						 . $this->meta->operation_id // request-id
185
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
186
+						 . $this->meta->charset
187
+						 . $this->meta->language
188
+						 . chr(0x45) // uri
189
+						 . self::_giveMeStringLength('printer-uri')
190
+						 . 'printer-uri'
191
+						 . self::_giveMeStringLength($printer_uri)
192
+						 . $printer_uri
193
+						 . chr(0x03); // end operations attribute
194
+
195
+		$this->output = $this->stringjob;
196
+
197
+		self::_putDebug("Request: ".$this->output);
198
+
199
+		$post_values = array( "Content-Type" => "application/ipp",
200
+							  "Data" => $this->output);
201
+
202
+		if (self::_sendHttp ($post_values,'/admin/'))
203
+		{
204
+
205
+			if(self::_parseServerOutput())
206
+			{
207
+				self::_parseAttributes();
208
+			}
209
+		}
210
+
211
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
212
+		{
213
+
214
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
215
+			if ($this->serveroutput->status == "successfull-ok")
216
+			{
217
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
218
+			}
219
+			else
220
+			{
221
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
222
+			}
223
+
224
+			return $this->serveroutput->status;
225
+		}
226
+		else
227
+		{
228
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
229
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
230
+			}
231
+	return false;
232
+	}
233
+
234
+
235
+	public function cupsRejectJobs($printer_uri,$printer_state_message)
236
+	{
237
+	//The CUPS-Get-Default operation returns the default printer URI and attributes
238
+
239
+		$this->jobs = array_merge($this->jobs,array(""));
240
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
241
+		$this->parsed = array();
242
+		unset($this->attributes);
243
+
244
+		if (!isset($this->setup->charset))
245
+		{
246
+			self::setCharset();
247
+		}
248
+
249
+		if (!isset($this->setup->language))
250
+		{
251
+			self::setLanguage('en');
252
+		}
253
+
254
+		self::_setOperationId();
255
+
256
+		$message = "";
257
+		if ($printer_state_message)
258
+		{
259
+			$message = chr(0x04) // start printer-attributes
260
+					 . chr(0x41) // textWithoutLanguage
261
+					 . self::_giveMeStringLength("printer-state-message")
262
+					 . "printer-state-message"
263
+					 . self::_giveMeStringLength($printer_state_message)
264
+					 . $printer_state_message;
265
+		}
266
+
267
+	   $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
268
+						 . chr(0x40). chr(0x09) // operation:  cups vendor extension: Reject-Jobs
269
+						 . $this->meta->operation_id // request-id
270
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
271
+						 . $this->meta->charset
272
+						 . $this->meta->language
273
+						 . chr(0x45) // uri
274
+						 . self::_giveMeStringLength('printer-uri')
275
+						 . 'printer-uri'
276
+						 . self::_giveMeStringLength($printer_uri)
277
+						 . $printer_uri
278
+						 . $message
279
+						 . chr(0x03); // end operations attribute
280
+
281
+		$this->output = $this->stringjob;
282
+
283
+		self::_putDebug("Request: ".$this->output);
284
+
285
+		$post_values = array( "Content-Type" => "application/ipp",
286
+							  "Data" => $this->output);
287
+
288
+		if (self::_sendHttp ($post_values,'/admin/'))
289
+		{
290
+
291
+			if(self::_parseServerOutput())
292
+			{
293
+				self::_parseAttributes();
294
+			}
295
+		}
296
+
297
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
298
+		{
299
+
300
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
301
+			if ($this->serveroutput->status == "successfull-ok")
302
+			{
303
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
304
+			}
305
+			else
306
+			{
307
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
308
+			}
309
+
310
+			return $this->serveroutput->status;
311
+		}
312
+		else
313
+		{
314
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
315
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
316
+		}
317
+		return false;
318
+	}
319
+
320
+
321
+	public function getPrinters($printer_location=false,$printer_info=false,$attributes=array())
322
+	{
323
+		if (count($attributes) == 0)
324
+		{
325
+			true;
326
+		}
327
+		$attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
+		$this->jobs = array_merge($this->jobs,array(""));
329
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
330
+
331
+		unset ($this->printers_attributes);
332
+
333
+		if (!isset($this->setup->charset))
334
+		{
335
+			self::setCharset();
336
+		}
337
+
338
+		if (!isset($this->setup->language))
339
+		{
340
+			self::setLanguage('en-us');
341
+		}
342
+
343
+		self::_setOperationId();
344
+
345
+		$this->meta->attributes='';
346
+
347
+		if ($printer_location)
348
+		{
349
+			$this->meta->attributes .= chr(0x41) // textWithoutLanguage
350
+									. self::_giveMeStringLength('printer-location')
351
+									. 'printer-location'
352
+									. self::_giveMeStringLength($printer_location)
353
+									. $printer_location;
354
+		}
355
+
356
+		if ($printer_info)
357
+		{
358
+			$this->meta->attributes .= chr(0x41) // textWithoutLanguage
359
+									. self::_giveMeStringLength('printer-info')
360
+									. 'printer-info'
361
+									. self::_giveMeStringLength($printer_info)
362
+									. $printer_info;
363
+		}
364
+
365
+		for($i = 0 ; $i < count($attributes) ; $i++)
366
+		{
367
+			if ($i == 0)
368
+			{
369
+				$this->meta->attributes .= chr(0x44) // Keyword
370
+										. self::_giveMeStringLength('requested-attributes')
371
+										. 'requested-attributes'
372
+										. self::_giveMeStringLength($attributes[0])
373
+										. $attributes[0];
374
+			}
375
+			else
376
+			{
377
+				$this->meta->attributes .= chr(0x44) // Keyword
378
+										.  chr(0x0).chr(0x0) // zero-length name
379
+										.  self::_giveMeStringLength($attributes[$i])
380
+										.  $attributes[$i];
381
+			}
382
+		}
383
+
384
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
385
+						 . chr(0x40). chr(0x02) // operation:  cups vendor extension: get printers
386
+						 . $this->meta->operation_id //           request-id
387
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
388
+						 . $this->meta->charset
389
+						 . $this->meta->language
390
+						 . $this->meta->attributes
391
+						 . chr(0x03); // end operations attribute
392
+
393
+		$this->output = $this->stringjob;
394
+
395
+		$post_values = array( "Content-Type" => "application/ipp",
396
+							  "Data" => $this->output);
397
+
398
+		if (self::_sendHttp ($post_values,'/'))
399
+		{
400
+
401
+			if(self::_parseServerOutput())
402
+			{
403
+				$this->_getAvailablePrinters();
404
+			}
405
+		}
406
+
407
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
408
+		{
409
+
410
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
411
+			if ($this->serveroutput->status == "successfull-ok")
412
+			{
413
+				self::_errorLog("getting printers: ".$this->serveroutput->status,3);
414
+			}
415
+			else
416
+			{
417
+				self::_errorLog("getting printers: ".$this->serveroutput->status,1);
418
+			}
419
+			return $this->serveroutput->status;
420
+		}
421
+		else
422
+		{
423
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
424
+			self::_errorLog("getting printers : OPERATION FAILED",1);
425
+		}
426
+		return false;
427
+	}
428
+
429
+
430
+	public function cupsGetPrinters ()
431
+	{
432
+		// alias for getPrinters();
433
+		self::getPrinters();
434
+	}
435
+
436
+
437
+	public function getPrinterAttributes()
438
+	{
439
+		// complete informations from parent with Cups-specific stuff
440
+
441
+		if(!$result = parent::getPrinterAttributes())
442
+		{
443
+			return FALSE;
444
+		}
445
+		if(!isset($this->printer_attributes))
446
+		{
447
+			return FALSE;
448
+		}
449
+
450
+		if (isset ($this->printer_attributes->printer_type))
451
+		{
452
+			$printer_type = $this->printer_attributes->printer_type->_value0;
453
+			$table = self::_interpretPrinterType($printer_type);
454
+
455
+			for($i = 0 ; $i < count($table) ; $i++ )
456
+			{
457
+				$index = '_value'.$i;
458
+				$this->printer_attributes->printer_type->$index = $table[$i];
459
+			}
460
+		}
461
+
462
+		return $result;
463
+	}
464 464
 
465 465
 //
466 466
 // SETUP
467 467
 //
468
-    protected function _initTags ()
469
-    {
470
-        // override parent with specific cups attributes
471
-
472
-        $operation_tags = array ();
473
-        $this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
474
-
475
-        $job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
476
-                            "blackplot" => array("tag" => "boolean"),
477
-                            "brightness" => array("tag" => "integer"),
478
-                            "columns" => array("tag" => "integer"),
479
-                            "cpi" => array("tag" => "enum"),
480
-                            "fitplot" => array("tag" => "boolean"),
481
-                            "gamma" => array("tag" => "integer"),
482
-                            "hue" => array("tag" => "integer"),
483
-                            "lpi" => array("tag" => "enum"),
484
-                            "mirror" => array("tag","boolean"),
485
-                            "natural-scaling" => array("tag" => "integer"),
486
-                            "number-up-layout" => array("tag" => "keyword"),
487
-                            "page-border" => array("tag" => "keyword"),
488
-                            "page-bottom" => array("tag" => "integer"),
489
-                            "page-label" => array("tag" => "textWithoutLanguage"),
490
-                            "page-left" => array("tag" => "integer"),
491
-                            "page-right" => array("tag" => "integer"),
492
-                            "page-set" => array("tag" => "keyword"),
493
-                            "page-top" => array("tag" => "integer"),
494
-                            "penwidth" => array("tag" => "integer"),
495
-                            "position" => array("tag" => "keyword"),
496
-                            "ppi" => array("tag" => "integer"),
497
-                            "prettyprint" => array("tag","boolean"),
498
-                            "saturation" => array("tag" => "integer"),
499
-                            "scaling" => array("tag" => "integer"),
500
-                            "wrap" => array("tag","boolean"),
501
-
502
-                            );
503
-        $this->job_tags = array_merge ($this->job_tags, $job_tags);
504
-    }
505
-
506
-    //
507
-    // REQUEST BUILDING
508
-    //
509
-    protected function _enumBuild ($tag,$value)
510
-    {
511
-        $value_built = parent::_enumBuild($tag,$value);
512
-
513
-        switch ($tag)
514
-        {
515
-           case "cpi":
516
-                switch ($value)
517
-                {
518
-                    case '10':
519
-                        $value_built = chr(10);
520
-                        break;
521
-                    case '12':
522
-                        $value_built = chr(12);
523
-                        break;
524
-                    case '17':
525
-                        $value_built = chr(17);
526
-                        break;
527
-                    default:
528
-                        $value_built = chr(10);
529
-                }
530
-            break;
531
-            case "lpi":
532
-                switch ($value)
533
-                {
534
-                    case '6':
535
-                        $value_built = chr(6);
536
-                        break;
537
-                    case '8':
538
-                        $value_built = chr(8);
539
-                        break;
540
-                    default:
541
-                        $value_built = chr(6);
542
-                }
543
-            break;
544
-            }
545
-
546
-        $prepend = '';
547
-        while ((strlen($value_built) + strlen($prepend)) < 4)
548
-            $prepend .= chr(0);
549
-        return $prepend.$value_built;
550
-    }
551
-
552
-    //
553
-    // RESPONSE PARSING
554
-    //
555
-    private function _getAvailablePrinters ()
556
-    {
557
-        $this->available_printers = array();
558
-        $this->printer_map = array();
559
-        $k = 0;
560
-        $this->printers_attributes = new \stdClass();
561
-
562
-        for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
563
-        {
564
-            if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes")
565
-            {
566
-                $phpname = "_printer".$k;
567
-                $this->printers_attributes->$phpname = new \stdClass();
568
-                for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
569
-                {
570
-
571
-                    $value = $this->serveroutput->response[$i][$j]['value'];
572
-                    $name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
573
-
574
-                    switch ($name)
575
-                    {
576
-                        case "printer_uri_supported":
577
-                            $this->available_printers = array_merge($this->available_printers,array($value));
578
-                            break;
579
-                        case "printer_type":
580
-                            $table = self::_interpretPrinterType($value);
581
-                            $this->printers_attributes->$phpname->$name = new \stdClass();
582
-
583
-                            for($l = 0 ; $l < count($table) ; $l++ )
584
-                            {
585
-                                $index = '_value'.$l;
586
-                                $this->printers_attributes->$phpname->$name->$index = $table[$l];
587
-                            }
588
-
589
-                            break;
590
-                        case '':
591
-                            break;
592
-                        case 'printer_name':
593
-                            $this->printer_map[$value] = $k;
594
-                            break;
595
-                        default:
596
-                            $this->printers_attributes->$phpname->$name = $value;
597
-                            break;
598
-                    }
599
-                }
600
-                $k ++;
601
-            }
602
-        }
603
-    }
604
-
605
-    protected function _getEnumVendorExtensions ($value_parsed)
606
-    {
607
-        switch ($value_parsed)
608
-        {
609
-            case 0x4002:
610
-                $value = 'Get-Availables-Printers';
611
-                break;
612
-            default:
613
-                $value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
614
-                break;
615
-        }
616
-
617
-        if (isset($value))
618
-        {
619
-            return ($value);
620
-        }
621
-
622
-        return sprintf('Unknown: 0x%x',$value_parsed);
623
-    }
624
-
625
-
626
-    private function _interpretPrinterType($value)
627
-    {
628
-        $value_parsed = 0;
629
-        for ($i = strlen($value) ; $i > 0 ; $i --)
630
-        {
631
-            $value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
632
-        }
633
-
634
-        $type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
635
-        $type[6] = $type[7] = $type[8] = $type[9] = $type[10] = '';
636
-        $type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
637
-        $type[16] = $type[17] = $type[18] = $type[19] = '';
638
-
639
-        if ($value_parsed %2 == 1)
640
-        {
641
-            $type[0] = 'printer-class';
642
-            $value_parsed -= 1;
643
-        }
644
-
645
-        if ($value_parsed %4 == 2 )
646
-        {
647
-            $type[1] = 'remote-destination';
648
-            $value_parsed -= 2;
649
-        }
650
-
651
-        if ($value_parsed %8 == 4 )
652
-        {
653
-            $type[2] = 'print-black';
654
-            $value_parsed -= 4;
655
-        }
656
-
657
-        if ($value_parsed %16 == 8 )
658
-        {
659
-            $type[3] = 'print-color';
660
-            $value_parsed -= 8;
661
-        }
662
-
663
-        if ($value_parsed %32 == 16)
664
-        {
665
-            $type[4] = 'hardware-print-on-both-sides';
666
-            $value_parsed -= 16;
667
-        }
668
-
669
-        if ($value_parsed %64 == 32)
670
-        {
671
-            $type[5] = 'hardware-staple-output';
672
-            $value_parsed -= 32;
673
-        }
674
-
675
-        if ($value_parsed %128 == 64)
676
-        {
677
-            $type[6] = 'hardware-fast-copies';
678
-            $value_parsed -= 64;
679
-        }
680
-
681
-        if ($value_parsed %256 == 128)
682
-        {
683
-            $type[7] = 'hardware-fast-copy-collation';
684
-            $value_parsed -= 128;
685
-        }
686
-
687
-        if ($value_parsed %512 == 256)
688
-        {
689
-            $type[8] = 'punch-output';
690
-            $value_parsed -= 256;
691
-        }
692
-
693
-        if ($value_parsed %1024 == 512)
694
-        {
695
-            $type[9] = 'cover-output';
696
-            $value_parsed -= 512;
697
-        }
698
-
699
-        if ($value_parsed %2048 == 1024)
700
-        {
701
-            $type[10] = 'bind-output';
702
-            $value_parsed -= 1024;
703
-        }
704
-
705
-        if ($value_parsed %4096 == 2048)
706
-        {
707
-            $type[11] = 'sort-output';
708
-            $value_parsed -= 2048;
709
-        }
710
-
711
-        if ($value_parsed %8192 == 4096)
712
-        {
713
-            $type[12] = 'handle-media-up-to-US-Legal-A4';
714
-            $value_parsed -= 4096;
715
-        }
716
-
717
-        if ($value_parsed %16384 == 8192)
718
-        {
719
-            $type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
720
-            $value_parsed -= 8192;
721
-        }
722
-
723
-        if ($value_parsed %32768 == 16384)
724
-        {
725
-            $type[14] = 'handle-media-larger-than-ISO_C-A2';
726
-            $value_parsed -= 16384;
727
-        }
728
-
729
-        if ($value_parsed %65536 == 32768)
730
-        {
731
-            $type[15] = 'handle-user-defined-media-sizes';
732
-            $value_parsed -= 32768;
733
-        }
734
-
735
-        if ($value_parsed %131072 == 65536)
736
-        {
737
-            $type[16] = 'implicit-server-generated-class';
738
-            $value_parsed -= 65536;
739
-        }
740
-
741
-        if ($value_parsed %262144 == 131072)
742
-        {
743
-            $type[17] = 'network-default-printer';
744
-            $value_parsed -= 131072;
745
-        }
746
-
747
-        if ($value_parsed %524288 == 262144)
748
-        {
749
-            $type[18] = 'fax-device';
750
-            $value_parsed -= 262144;
751
-        }
752
-
753
-        return $type;
754
-    }
755
-
756
-
757
-    protected function _interpretEnum($attribute_name,$value)
758
-    {
759
-        $value_parsed = self::_interpretInteger($value);
760
-
761
-        switch ($attribute_name)
762
-        {
763
-            case 'cpi':
764
-            case 'lpi':
765
-                $value = $value_parsed;
766
-                break;
767
-            default:
768
-                $value = parent::_interpretEnum($attribute_name,$value);
769
-                break;
770
-        }
771
-
772
-        return $value;
773
-    }
468
+	protected function _initTags ()
469
+	{
470
+		// override parent with specific cups attributes
471
+
472
+		$operation_tags = array ();
473
+		$this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
474
+
475
+		$job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
476
+							"blackplot" => array("tag" => "boolean"),
477
+							"brightness" => array("tag" => "integer"),
478
+							"columns" => array("tag" => "integer"),
479
+							"cpi" => array("tag" => "enum"),
480
+							"fitplot" => array("tag" => "boolean"),
481
+							"gamma" => array("tag" => "integer"),
482
+							"hue" => array("tag" => "integer"),
483
+							"lpi" => array("tag" => "enum"),
484
+							"mirror" => array("tag","boolean"),
485
+							"natural-scaling" => array("tag" => "integer"),
486
+							"number-up-layout" => array("tag" => "keyword"),
487
+							"page-border" => array("tag" => "keyword"),
488
+							"page-bottom" => array("tag" => "integer"),
489
+							"page-label" => array("tag" => "textWithoutLanguage"),
490
+							"page-left" => array("tag" => "integer"),
491
+							"page-right" => array("tag" => "integer"),
492
+							"page-set" => array("tag" => "keyword"),
493
+							"page-top" => array("tag" => "integer"),
494
+							"penwidth" => array("tag" => "integer"),
495
+							"position" => array("tag" => "keyword"),
496
+							"ppi" => array("tag" => "integer"),
497
+							"prettyprint" => array("tag","boolean"),
498
+							"saturation" => array("tag" => "integer"),
499
+							"scaling" => array("tag" => "integer"),
500
+							"wrap" => array("tag","boolean"),
501
+
502
+							);
503
+		$this->job_tags = array_merge ($this->job_tags, $job_tags);
504
+	}
505
+
506
+	//
507
+	// REQUEST BUILDING
508
+	//
509
+	protected function _enumBuild ($tag,$value)
510
+	{
511
+		$value_built = parent::_enumBuild($tag,$value);
512
+
513
+		switch ($tag)
514
+		{
515
+		   case "cpi":
516
+				switch ($value)
517
+				{
518
+					case '10':
519
+						$value_built = chr(10);
520
+						break;
521
+					case '12':
522
+						$value_built = chr(12);
523
+						break;
524
+					case '17':
525
+						$value_built = chr(17);
526
+						break;
527
+					default:
528
+						$value_built = chr(10);
529
+				}
530
+			break;
531
+			case "lpi":
532
+				switch ($value)
533
+				{
534
+					case '6':
535
+						$value_built = chr(6);
536
+						break;
537
+					case '8':
538
+						$value_built = chr(8);
539
+						break;
540
+					default:
541
+						$value_built = chr(6);
542
+				}
543
+			break;
544
+			}
545
+
546
+		$prepend = '';
547
+		while ((strlen($value_built) + strlen($prepend)) < 4)
548
+			$prepend .= chr(0);
549
+		return $prepend.$value_built;
550
+	}
551
+
552
+	//
553
+	// RESPONSE PARSING
554
+	//
555
+	private function _getAvailablePrinters ()
556
+	{
557
+		$this->available_printers = array();
558
+		$this->printer_map = array();
559
+		$k = 0;
560
+		$this->printers_attributes = new \stdClass();
561
+
562
+		for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
563
+		{
564
+			if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes")
565
+			{
566
+				$phpname = "_printer".$k;
567
+				$this->printers_attributes->$phpname = new \stdClass();
568
+				for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
569
+				{
570
+
571
+					$value = $this->serveroutput->response[$i][$j]['value'];
572
+					$name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
573
+
574
+					switch ($name)
575
+					{
576
+						case "printer_uri_supported":
577
+							$this->available_printers = array_merge($this->available_printers,array($value));
578
+							break;
579
+						case "printer_type":
580
+							$table = self::_interpretPrinterType($value);
581
+							$this->printers_attributes->$phpname->$name = new \stdClass();
582
+
583
+							for($l = 0 ; $l < count($table) ; $l++ )
584
+							{
585
+								$index = '_value'.$l;
586
+								$this->printers_attributes->$phpname->$name->$index = $table[$l];
587
+							}
588
+
589
+							break;
590
+						case '':
591
+							break;
592
+						case 'printer_name':
593
+							$this->printer_map[$value] = $k;
594
+							break;
595
+						default:
596
+							$this->printers_attributes->$phpname->$name = $value;
597
+							break;
598
+					}
599
+				}
600
+				$k ++;
601
+			}
602
+		}
603
+	}
604
+
605
+	protected function _getEnumVendorExtensions ($value_parsed)
606
+	{
607
+		switch ($value_parsed)
608
+		{
609
+			case 0x4002:
610
+				$value = 'Get-Availables-Printers';
611
+				break;
612
+			default:
613
+				$value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
614
+				break;
615
+		}
616
+
617
+		if (isset($value))
618
+		{
619
+			return ($value);
620
+		}
621
+
622
+		return sprintf('Unknown: 0x%x',$value_parsed);
623
+	}
624
+
625
+
626
+	private function _interpretPrinterType($value)
627
+	{
628
+		$value_parsed = 0;
629
+		for ($i = strlen($value) ; $i > 0 ; $i --)
630
+		{
631
+			$value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
632
+		}
633
+
634
+		$type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
635
+		$type[6] = $type[7] = $type[8] = $type[9] = $type[10] = '';
636
+		$type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
637
+		$type[16] = $type[17] = $type[18] = $type[19] = '';
638
+
639
+		if ($value_parsed %2 == 1)
640
+		{
641
+			$type[0] = 'printer-class';
642
+			$value_parsed -= 1;
643
+		}
644
+
645
+		if ($value_parsed %4 == 2 )
646
+		{
647
+			$type[1] = 'remote-destination';
648
+			$value_parsed -= 2;
649
+		}
650
+
651
+		if ($value_parsed %8 == 4 )
652
+		{
653
+			$type[2] = 'print-black';
654
+			$value_parsed -= 4;
655
+		}
656
+
657
+		if ($value_parsed %16 == 8 )
658
+		{
659
+			$type[3] = 'print-color';
660
+			$value_parsed -= 8;
661
+		}
662
+
663
+		if ($value_parsed %32 == 16)
664
+		{
665
+			$type[4] = 'hardware-print-on-both-sides';
666
+			$value_parsed -= 16;
667
+		}
668
+
669
+		if ($value_parsed %64 == 32)
670
+		{
671
+			$type[5] = 'hardware-staple-output';
672
+			$value_parsed -= 32;
673
+		}
674
+
675
+		if ($value_parsed %128 == 64)
676
+		{
677
+			$type[6] = 'hardware-fast-copies';
678
+			$value_parsed -= 64;
679
+		}
680
+
681
+		if ($value_parsed %256 == 128)
682
+		{
683
+			$type[7] = 'hardware-fast-copy-collation';
684
+			$value_parsed -= 128;
685
+		}
686
+
687
+		if ($value_parsed %512 == 256)
688
+		{
689
+			$type[8] = 'punch-output';
690
+			$value_parsed -= 256;
691
+		}
692
+
693
+		if ($value_parsed %1024 == 512)
694
+		{
695
+			$type[9] = 'cover-output';
696
+			$value_parsed -= 512;
697
+		}
698
+
699
+		if ($value_parsed %2048 == 1024)
700
+		{
701
+			$type[10] = 'bind-output';
702
+			$value_parsed -= 1024;
703
+		}
704
+
705
+		if ($value_parsed %4096 == 2048)
706
+		{
707
+			$type[11] = 'sort-output';
708
+			$value_parsed -= 2048;
709
+		}
710
+
711
+		if ($value_parsed %8192 == 4096)
712
+		{
713
+			$type[12] = 'handle-media-up-to-US-Legal-A4';
714
+			$value_parsed -= 4096;
715
+		}
716
+
717
+		if ($value_parsed %16384 == 8192)
718
+		{
719
+			$type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
720
+			$value_parsed -= 8192;
721
+		}
722
+
723
+		if ($value_parsed %32768 == 16384)
724
+		{
725
+			$type[14] = 'handle-media-larger-than-ISO_C-A2';
726
+			$value_parsed -= 16384;
727
+		}
728
+
729
+		if ($value_parsed %65536 == 32768)
730
+		{
731
+			$type[15] = 'handle-user-defined-media-sizes';
732
+			$value_parsed -= 32768;
733
+		}
734
+
735
+		if ($value_parsed %131072 == 65536)
736
+		{
737
+			$type[16] = 'implicit-server-generated-class';
738
+			$value_parsed -= 65536;
739
+		}
740
+
741
+		if ($value_parsed %262144 == 131072)
742
+		{
743
+			$type[17] = 'network-default-printer';
744
+			$value_parsed -= 131072;
745
+		}
746
+
747
+		if ($value_parsed %524288 == 262144)
748
+		{
749
+			$type[18] = 'fax-device';
750
+			$value_parsed -= 262144;
751
+		}
752
+
753
+		return $type;
754
+	}
755
+
756
+
757
+	protected function _interpretEnum($attribute_name,$value)
758
+	{
759
+		$value_parsed = self::_interpretInteger($value);
760
+
761
+		switch ($attribute_name)
762
+		{
763
+			case 'cpi':
764
+			case 'lpi':
765
+				$value = $value_parsed;
766
+				break;
767
+			default:
768
+				$value = parent::_interpretEnum($attribute_name,$value);
769
+				break;
770
+		}
771
+
772
+		return $value;
773
+	}
774 774
 }
775 775
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 //
56 56
 // OPERATIONS
57 57
 //
58
-    public function cupsGetDefaults($attributes=array("all"))
58
+    public function cupsGetDefaults($attributes = array("all"))
59 59
     {
60 60
         //The CUPS-Get-Default operation returns the default printer URI and attributes
61 61
 
62
-        $this->jobs = array_merge($this->jobs,array(""));
63
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
62
+        $this->jobs = array_merge($this->jobs, array(""));
63
+        $this->jobs_uri = array_merge($this->jobs_uri, array(""));
64 64
         $this->parsed = array();
65 65
         unset($this->printer_attributes);
66 66
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
         self::_setOperationId();
78 78
 
79
-        for($i = 0 ; $i < count($attributes) ; $i++)
79
+        for ($i = 0; $i < count($attributes); $i++)
80 80
         {
81 81
             if ($i == 0)
82 82
             {
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
             }
96 96
         }
97 97
 
98
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
99
-                         . chr(0x40). chr(0x01) // operation:  cups vendor extension: get defaults
98
+        $this->stringjob = chr(0x01).chr(0x01) // IPP version 1.1
99
+                         . chr(0x40).chr(0x01) // operation:  cups vendor extension: get defaults
100 100
                          . $this->meta->operation_id // request-id
101 101
                          . chr(0x01) // start operation-attributes | operation-attributes-tag
102 102
                          . $this->meta->charset
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 
109 109
         self::_putDebug("Request: ".$this->output);
110 110
 
111
-        $post_values = array( "Content-Type" => "application/ipp",
111
+        $post_values = array("Content-Type" => "application/ipp",
112 112
                               "Data" => $this->output);
113 113
 
114
-        if (self::_sendHttp ($post_values,'/'))
114
+        if (self::_sendHttp($post_values, '/'))
115 115
         {
116 116
 
117
-            if(self::_parseServerOutput())
117
+            if (self::_parseServerOutput())
118 118
             {
119 119
                 self::_parsePrinterAttributes();
120 120
             }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                     $printer_type = $this->printer_attributes->printer_type->_value0;
128 128
                     $table = self::_interpretPrinterType($printer_type);
129 129
 
130
-                    for($i = 0 ; $i < count($table) ; $i++ )
130
+                    for ($i = 0; $i < count($table); $i++)
131 131
                     {
132 132
                         $index = '_value'.$i;
133 133
                         $this->printer_attributes->printer_type->$index = $table[$i];
@@ -137,22 +137,22 @@  discard block
 block discarded – undo
137 137
         if (isset($this->serveroutput) && isset($this->serveroutput->status))
138 138
         {
139 139
 
140
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
140
+            $this->status = array_merge($this->status, array($this->serveroutput->status));
141 141
             if ($this->serveroutput->status == "successfull-ok")
142 142
             {
143
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
143
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 3);
144 144
             }
145 145
             else
146 146
             {
147
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
147
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 1);
148 148
             }
149 149
 
150 150
             return $this->serveroutput->status;
151 151
         }
152 152
         else
153 153
         {
154
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
155
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
154
+            $this->status = array_merge($this->status, array("OPERATION FAILED"));
155
+            self::_errorLog("getting defaults : OPERATION FAILED", 1);
156 156
             }
157 157
     return false;
158 158
     }
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
     {
163 163
     //The CUPS-Get-Default operation returns the default printer URI and attributes
164 164
 
165
-        $this->jobs = array_merge($this->jobs,array(""));
166
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
165
+        $this->jobs = array_merge($this->jobs, array(""));
166
+        $this->jobs_uri = array_merge($this->jobs_uri, array(""));
167 167
         $this->parsed = array();
168 168
         unset($this->printer_attributes);
169 169
 
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 
180 180
         self::_setOperationId();
181 181
 
182
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
183
-                         . chr(0x40). chr(0x08) // operation:  cups vendor extension: Accept-Jobs
182
+        $this->stringjob = chr(0x01).chr(0x01) // IPP version 1.1
183
+                         . chr(0x40).chr(0x08) // operation:  cups vendor extension: Accept-Jobs
184 184
                          . $this->meta->operation_id // request-id
185 185
                          . chr(0x01) // start operation-attributes | operation-attributes-tag
186 186
                          . $this->meta->charset
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 
197 197
         self::_putDebug("Request: ".$this->output);
198 198
 
199
-        $post_values = array( "Content-Type" => "application/ipp",
199
+        $post_values = array("Content-Type" => "application/ipp",
200 200
                               "Data" => $this->output);
201 201
 
202
-        if (self::_sendHttp ($post_values,'/admin/'))
202
+        if (self::_sendHttp($post_values, '/admin/'))
203 203
         {
204 204
 
205
-            if(self::_parseServerOutput())
205
+            if (self::_parseServerOutput())
206 206
             {
207 207
                 self::_parseAttributes();
208 208
             }
@@ -211,33 +211,33 @@  discard block
 block discarded – undo
211 211
         if (isset($this->serveroutput) && isset($this->serveroutput->status))
212 212
         {
213 213
 
214
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
214
+            $this->status = array_merge($this->status, array($this->serveroutput->status));
215 215
             if ($this->serveroutput->status == "successfull-ok")
216 216
             {
217
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
217
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 3);
218 218
             }
219 219
             else
220 220
             {
221
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
221
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 1);
222 222
             }
223 223
 
224 224
             return $this->serveroutput->status;
225 225
         }
226 226
         else
227 227
         {
228
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
229
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
228
+            $this->status = array_merge($this->status, array("OPERATION FAILED"));
229
+            self::_errorLog("getting defaults : OPERATION FAILED", 1);
230 230
             }
231 231
     return false;
232 232
     }
233 233
 
234 234
 
235
-    public function cupsRejectJobs($printer_uri,$printer_state_message)
235
+    public function cupsRejectJobs($printer_uri, $printer_state_message)
236 236
     {
237 237
     //The CUPS-Get-Default operation returns the default printer URI and attributes
238 238
 
239
-        $this->jobs = array_merge($this->jobs,array(""));
240
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
239
+        $this->jobs = array_merge($this->jobs, array(""));
240
+        $this->jobs_uri = array_merge($this->jobs_uri, array(""));
241 241
         $this->parsed = array();
242 242
         unset($this->attributes);
243 243
 
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
                      . $printer_state_message;
265 265
         }
266 266
 
267
-       $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
268
-                         . chr(0x40). chr(0x09) // operation:  cups vendor extension: Reject-Jobs
267
+       $this->stringjob = chr(0x01).chr(0x01) // IPP version 1.1
268
+                         . chr(0x40).chr(0x09) // operation:  cups vendor extension: Reject-Jobs
269 269
                          . $this->meta->operation_id // request-id
270 270
                          . chr(0x01) // start operation-attributes | operation-attributes-tag
271 271
                          . $this->meta->charset
@@ -282,13 +282,13 @@  discard block
 block discarded – undo
282 282
 
283 283
         self::_putDebug("Request: ".$this->output);
284 284
 
285
-        $post_values = array( "Content-Type" => "application/ipp",
285
+        $post_values = array("Content-Type" => "application/ipp",
286 286
                               "Data" => $this->output);
287 287
 
288
-        if (self::_sendHttp ($post_values,'/admin/'))
288
+        if (self::_sendHttp($post_values, '/admin/'))
289 289
         {
290 290
 
291
-            if(self::_parseServerOutput())
291
+            if (self::_parseServerOutput())
292 292
             {
293 293
                 self::_parseAttributes();
294 294
             }
@@ -297,36 +297,36 @@  discard block
 block discarded – undo
297 297
         if (isset($this->serveroutput) && isset($this->serveroutput->status))
298 298
         {
299 299
 
300
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
300
+            $this->status = array_merge($this->status, array($this->serveroutput->status));
301 301
             if ($this->serveroutput->status == "successfull-ok")
302 302
             {
303
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
303
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 3);
304 304
             }
305 305
             else
306 306
             {
307
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
307
+                self::_errorLog("getting defaults: ".$this->serveroutput->status, 1);
308 308
             }
309 309
 
310 310
             return $this->serveroutput->status;
311 311
         }
312 312
         else
313 313
         {
314
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
315
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
314
+            $this->status = array_merge($this->status, array("OPERATION FAILED"));
315
+            self::_errorLog("getting defaults : OPERATION FAILED", 1);
316 316
         }
317 317
         return false;
318 318
     }
319 319
 
320 320
 
321
-    public function getPrinters($printer_location=false,$printer_info=false,$attributes=array())
321
+    public function getPrinters($printer_location = false, $printer_info = false, $attributes = array())
322 322
     {
323 323
         if (count($attributes) == 0)
324 324
         {
325 325
             true;
326 326
         }
327
-        $attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
-        $this->jobs = array_merge($this->jobs,array(""));
329
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
327
+        $attributes = array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
+        $this->jobs = array_merge($this->jobs, array(""));
329
+        $this->jobs_uri = array_merge($this->jobs_uri, array(""));
330 330
 
331 331
         unset ($this->printers_attributes);
332 332
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
         self::_setOperationId();
344 344
 
345
-        $this->meta->attributes='';
345
+        $this->meta->attributes = '';
346 346
 
347 347
         if ($printer_location)
348 348
         {
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                                     . $printer_info;
363 363
         }
364 364
 
365
-        for($i = 0 ; $i < count($attributes) ; $i++)
365
+        for ($i = 0; $i < count($attributes); $i++)
366 366
         {
367 367
             if ($i == 0)
368 368
             {
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
             }
382 382
         }
383 383
 
384
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
385
-                         . chr(0x40). chr(0x02) // operation:  cups vendor extension: get printers
384
+        $this->stringjob = chr(0x01).chr(0x01) // IPP version 1.1
385
+                         . chr(0x40).chr(0x02) // operation:  cups vendor extension: get printers
386 386
                          . $this->meta->operation_id //           request-id
387 387
                          . chr(0x01) // start operation-attributes | operation-attributes-tag
388 388
                          . $this->meta->charset
@@ -392,13 +392,13 @@  discard block
 block discarded – undo
392 392
 
393 393
         $this->output = $this->stringjob;
394 394
 
395
-        $post_values = array( "Content-Type" => "application/ipp",
395
+        $post_values = array("Content-Type" => "application/ipp",
396 396
                               "Data" => $this->output);
397 397
 
398
-        if (self::_sendHttp ($post_values,'/'))
398
+        if (self::_sendHttp($post_values, '/'))
399 399
         {
400 400
 
401
-            if(self::_parseServerOutput())
401
+            if (self::_parseServerOutput())
402 402
             {
403 403
                 $this->_getAvailablePrinters();
404 404
             }
@@ -407,27 +407,27 @@  discard block
 block discarded – undo
407 407
         if (isset($this->serveroutput) && isset($this->serveroutput->status))
408 408
         {
409 409
 
410
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
410
+            $this->status = array_merge($this->status, array($this->serveroutput->status));
411 411
             if ($this->serveroutput->status == "successfull-ok")
412 412
             {
413
-                self::_errorLog("getting printers: ".$this->serveroutput->status,3);
413
+                self::_errorLog("getting printers: ".$this->serveroutput->status, 3);
414 414
             }
415 415
             else
416 416
             {
417
-                self::_errorLog("getting printers: ".$this->serveroutput->status,1);
417
+                self::_errorLog("getting printers: ".$this->serveroutput->status, 1);
418 418
             }
419 419
             return $this->serveroutput->status;
420 420
         }
421 421
         else
422 422
         {
423
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
424
-            self::_errorLog("getting printers : OPERATION FAILED",1);
423
+            $this->status = array_merge($this->status, array("OPERATION FAILED"));
424
+            self::_errorLog("getting printers : OPERATION FAILED", 1);
425 425
         }
426 426
         return false;
427 427
     }
428 428
 
429 429
 
430
-    public function cupsGetPrinters ()
430
+    public function cupsGetPrinters()
431 431
     {
432 432
         // alias for getPrinters();
433 433
         self::getPrinters();
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
     {
439 439
         // complete informations from parent with Cups-specific stuff
440 440
 
441
-        if(!$result = parent::getPrinterAttributes())
441
+        if (!$result = parent::getPrinterAttributes())
442 442
         {
443 443
             return FALSE;
444 444
         }
445
-        if(!isset($this->printer_attributes))
445
+        if (!isset($this->printer_attributes))
446 446
         {
447 447
             return FALSE;
448 448
         }
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
             $printer_type = $this->printer_attributes->printer_type->_value0;
453 453
             $table = self::_interpretPrinterType($printer_type);
454 454
 
455
-            for($i = 0 ; $i < count($table) ; $i++ )
455
+            for ($i = 0; $i < count($table); $i++)
456 456
             {
457 457
                 $index = '_value'.$i;
458 458
                 $this->printer_attributes->printer_type->$index = $table[$i];
@@ -465,14 +465,14 @@  discard block
 block discarded – undo
465 465
 //
466 466
 // SETUP
467 467
 //
468
-    protected function _initTags ()
468
+    protected function _initTags()
469 469
     {
470 470
         // override parent with specific cups attributes
471 471
 
472
-        $operation_tags = array ();
473
-        $this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
472
+        $operation_tags = array();
473
+        $this->operation_tags = array_merge($this->operation_tags, $operation_tags);
474 474
 
475
-        $job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
475
+        $job_tags = array("job-billing" => array("tag" => "textWithoutLanguage"),
476 476
                             "blackplot" => array("tag" => "boolean"),
477 477
                             "brightness" => array("tag" => "integer"),
478 478
                             "columns" => array("tag" => "integer"),
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                             "gamma" => array("tag" => "integer"),
482 482
                             "hue" => array("tag" => "integer"),
483 483
                             "lpi" => array("tag" => "enum"),
484
-                            "mirror" => array("tag","boolean"),
484
+                            "mirror" => array("tag", "boolean"),
485 485
                             "natural-scaling" => array("tag" => "integer"),
486 486
                             "number-up-layout" => array("tag" => "keyword"),
487 487
                             "page-border" => array("tag" => "keyword"),
@@ -494,21 +494,21 @@  discard block
 block discarded – undo
494 494
                             "penwidth" => array("tag" => "integer"),
495 495
                             "position" => array("tag" => "keyword"),
496 496
                             "ppi" => array("tag" => "integer"),
497
-                            "prettyprint" => array("tag","boolean"),
497
+                            "prettyprint" => array("tag", "boolean"),
498 498
                             "saturation" => array("tag" => "integer"),
499 499
                             "scaling" => array("tag" => "integer"),
500
-                            "wrap" => array("tag","boolean"),
500
+                            "wrap" => array("tag", "boolean"),
501 501
 
502 502
                             );
503
-        $this->job_tags = array_merge ($this->job_tags, $job_tags);
503
+        $this->job_tags = array_merge($this->job_tags, $job_tags);
504 504
     }
505 505
 
506 506
     //
507 507
     // REQUEST BUILDING
508 508
     //
509
-    protected function _enumBuild ($tag,$value)
509
+    protected function _enumBuild($tag, $value)
510 510
     {
511
-        $value_built = parent::_enumBuild($tag,$value);
511
+        $value_built = parent::_enumBuild($tag, $value);
512 512
 
513 513
         switch ($tag)
514 514
         {
@@ -552,35 +552,35 @@  discard block
 block discarded – undo
552 552
     //
553 553
     // RESPONSE PARSING
554 554
     //
555
-    private function _getAvailablePrinters ()
555
+    private function _getAvailablePrinters()
556 556
     {
557 557
         $this->available_printers = array();
558 558
         $this->printer_map = array();
559 559
         $k = 0;
560 560
         $this->printers_attributes = new \stdClass();
561 561
 
562
-        for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
562
+        for ($i = 0; (array_key_exists($i, $this->serveroutput->response)); $i++)
563 563
         {
564 564
             if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes")
565 565
             {
566 566
                 $phpname = "_printer".$k;
567 567
                 $this->printers_attributes->$phpname = new \stdClass();
568
-                for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
568
+                for ($j = 0; array_key_exists($j, $this->serveroutput->response[$i]); $j++)
569 569
                 {
570 570
 
571 571
                     $value = $this->serveroutput->response[$i][$j]['value'];
572
-                    $name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
572
+                    $name = str_replace("-", "_", $this->serveroutput->response[$i][$j]['name']);
573 573
 
574 574
                     switch ($name)
575 575
                     {
576 576
                         case "printer_uri_supported":
577
-                            $this->available_printers = array_merge($this->available_printers,array($value));
577
+                            $this->available_printers = array_merge($this->available_printers, array($value));
578 578
                             break;
579 579
                         case "printer_type":
580 580
                             $table = self::_interpretPrinterType($value);
581 581
                             $this->printers_attributes->$phpname->$name = new \stdClass();
582 582
 
583
-                            for($l = 0 ; $l < count($table) ; $l++ )
583
+                            for ($l = 0; $l < count($table); $l++)
584 584
                             {
585 585
                                 $index = '_value'.$l;
586 586
                                 $this->printers_attributes->$phpname->$name->$index = $table[$l];
@@ -597,12 +597,12 @@  discard block
 block discarded – undo
597 597
                             break;
598 598
                     }
599 599
                 }
600
-                $k ++;
600
+                $k++;
601 601
             }
602 602
         }
603 603
     }
604 604
 
605
-    protected function _getEnumVendorExtensions ($value_parsed)
605
+    protected function _getEnumVendorExtensions($value_parsed)
606 606
     {
607 607
         switch ($value_parsed)
608 608
         {
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
                 $value = 'Get-Availables-Printers';
611 611
                 break;
612 612
             default:
613
-                $value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
613
+                $value = sprintf('Unknown(Cups extension for operations): 0x%x', $value_parsed);
614 614
                 break;
615 615
         }
616 616
 
@@ -619,16 +619,16 @@  discard block
 block discarded – undo
619 619
             return ($value);
620 620
         }
621 621
 
622
-        return sprintf('Unknown: 0x%x',$value_parsed);
622
+        return sprintf('Unknown: 0x%x', $value_parsed);
623 623
     }
624 624
 
625 625
 
626 626
     private function _interpretPrinterType($value)
627 627
     {
628 628
         $value_parsed = 0;
629
-        for ($i = strlen($value) ; $i > 0 ; $i --)
629
+        for ($i = strlen($value); $i > 0; $i--)
630 630
         {
631
-            $value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
631
+            $value_parsed += pow(256, ($i - 1)) * ord($value[strlen($value) - $i]);
632 632
         }
633 633
 
634 634
         $type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
@@ -636,115 +636,115 @@  discard block
 block discarded – undo
636 636
         $type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
637 637
         $type[16] = $type[17] = $type[18] = $type[19] = '';
638 638
 
639
-        if ($value_parsed %2 == 1)
639
+        if ($value_parsed % 2 == 1)
640 640
         {
641 641
             $type[0] = 'printer-class';
642 642
             $value_parsed -= 1;
643 643
         }
644 644
 
645
-        if ($value_parsed %4 == 2 )
645
+        if ($value_parsed % 4 == 2)
646 646
         {
647 647
             $type[1] = 'remote-destination';
648 648
             $value_parsed -= 2;
649 649
         }
650 650
 
651
-        if ($value_parsed %8 == 4 )
651
+        if ($value_parsed % 8 == 4)
652 652
         {
653 653
             $type[2] = 'print-black';
654 654
             $value_parsed -= 4;
655 655
         }
656 656
 
657
-        if ($value_parsed %16 == 8 )
657
+        if ($value_parsed % 16 == 8)
658 658
         {
659 659
             $type[3] = 'print-color';
660 660
             $value_parsed -= 8;
661 661
         }
662 662
 
663
-        if ($value_parsed %32 == 16)
663
+        if ($value_parsed % 32 == 16)
664 664
         {
665 665
             $type[4] = 'hardware-print-on-both-sides';
666 666
             $value_parsed -= 16;
667 667
         }
668 668
 
669
-        if ($value_parsed %64 == 32)
669
+        if ($value_parsed % 64 == 32)
670 670
         {
671 671
             $type[5] = 'hardware-staple-output';
672 672
             $value_parsed -= 32;
673 673
         }
674 674
 
675
-        if ($value_parsed %128 == 64)
675
+        if ($value_parsed % 128 == 64)
676 676
         {
677 677
             $type[6] = 'hardware-fast-copies';
678 678
             $value_parsed -= 64;
679 679
         }
680 680
 
681
-        if ($value_parsed %256 == 128)
681
+        if ($value_parsed % 256 == 128)
682 682
         {
683 683
             $type[7] = 'hardware-fast-copy-collation';
684 684
             $value_parsed -= 128;
685 685
         }
686 686
 
687
-        if ($value_parsed %512 == 256)
687
+        if ($value_parsed % 512 == 256)
688 688
         {
689 689
             $type[8] = 'punch-output';
690 690
             $value_parsed -= 256;
691 691
         }
692 692
 
693
-        if ($value_parsed %1024 == 512)
693
+        if ($value_parsed % 1024 == 512)
694 694
         {
695 695
             $type[9] = 'cover-output';
696 696
             $value_parsed -= 512;
697 697
         }
698 698
 
699
-        if ($value_parsed %2048 == 1024)
699
+        if ($value_parsed % 2048 == 1024)
700 700
         {
701 701
             $type[10] = 'bind-output';
702 702
             $value_parsed -= 1024;
703 703
         }
704 704
 
705
-        if ($value_parsed %4096 == 2048)
705
+        if ($value_parsed % 4096 == 2048)
706 706
         {
707 707
             $type[11] = 'sort-output';
708 708
             $value_parsed -= 2048;
709 709
         }
710 710
 
711
-        if ($value_parsed %8192 == 4096)
711
+        if ($value_parsed % 8192 == 4096)
712 712
         {
713 713
             $type[12] = 'handle-media-up-to-US-Legal-A4';
714 714
             $value_parsed -= 4096;
715 715
         }
716 716
 
717
-        if ($value_parsed %16384 == 8192)
717
+        if ($value_parsed % 16384 == 8192)
718 718
         {
719 719
             $type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
720 720
             $value_parsed -= 8192;
721 721
         }
722 722
 
723
-        if ($value_parsed %32768 == 16384)
723
+        if ($value_parsed % 32768 == 16384)
724 724
         {
725 725
             $type[14] = 'handle-media-larger-than-ISO_C-A2';
726 726
             $value_parsed -= 16384;
727 727
         }
728 728
 
729
-        if ($value_parsed %65536 == 32768)
729
+        if ($value_parsed % 65536 == 32768)
730 730
         {
731 731
             $type[15] = 'handle-user-defined-media-sizes';
732 732
             $value_parsed -= 32768;
733 733
         }
734 734
 
735
-        if ($value_parsed %131072 == 65536)
735
+        if ($value_parsed % 131072 == 65536)
736 736
         {
737 737
             $type[16] = 'implicit-server-generated-class';
738 738
             $value_parsed -= 65536;
739 739
         }
740 740
 
741
-        if ($value_parsed %262144 == 131072)
741
+        if ($value_parsed % 262144 == 131072)
742 742
         {
743 743
             $type[17] = 'network-default-printer';
744 744
             $value_parsed -= 131072;
745 745
         }
746 746
 
747
-        if ($value_parsed %524288 == 262144)
747
+        if ($value_parsed % 524288 == 262144)
748 748
         {
749 749
             $type[18] = 'fax-device';
750 750
             $value_parsed -= 262144;
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
     }
755 755
 
756 756
 
757
-    protected function _interpretEnum($attribute_name,$value)
757
+    protected function _interpretEnum($attribute_name, $value)
758 758
     {
759 759
         $value_parsed = self::_interpretInteger($value);
760 760
 
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
                 $value = $value_parsed;
766 766
                 break;
767 767
             default:
768
-                $value = parent::_interpretEnum($attribute_name,$value);
768
+                $value = parent::_interpretEnum($attribute_name, $value);
769 769
                 break;
770 770
         }
771 771
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -22 removed lines patch added patch discarded remove patch
@@ -85,8 +85,7 @@  discard block
 block discarded – undo
85 85
                                         . 'requested-attributes'
86 86
                                         . self::_giveMeStringLength($attributes[0])
87 87
                                         . $attributes[0];
88
-            }
89
-            else
88
+            } else
90 89
             {
91 90
                 $this->meta->attributes .= chr(0x44) // Keyword
92 91
                                         .  chr(0x0).chr(0x0) // zero-length name
@@ -141,15 +140,13 @@  discard block
 block discarded – undo
141 140
             if ($this->serveroutput->status == "successfull-ok")
142 141
             {
143 142
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
144
-            }
145
-            else
143
+            } else
146 144
             {
147 145
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
148 146
             }
149 147
 
150 148
             return $this->serveroutput->status;
151
-        }
152
-        else
149
+        } else
153 150
         {
154 151
             $this->status = array_merge($this->status,array("OPERATION FAILED"));
155 152
             self::_errorLog("getting defaults : OPERATION FAILED",1);
@@ -215,15 +212,13 @@  discard block
 block discarded – undo
215 212
             if ($this->serveroutput->status == "successfull-ok")
216 213
             {
217 214
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
218
-            }
219
-            else
215
+            } else
220 216
             {
221 217
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
222 218
             }
223 219
 
224 220
             return $this->serveroutput->status;
225
-        }
226
-        else
221
+        } else
227 222
         {
228 223
             $this->status = array_merge($this->status,array("OPERATION FAILED"));
229 224
             self::_errorLog("getting defaults : OPERATION FAILED",1);
@@ -301,15 +296,13 @@  discard block
 block discarded – undo
301 296
             if ($this->serveroutput->status == "successfull-ok")
302 297
             {
303 298
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
304
-            }
305
-            else
299
+            } else
306 300
             {
307 301
                 self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
308 302
             }
309 303
 
310 304
             return $this->serveroutput->status;
311
-        }
312
-        else
305
+        } else
313 306
         {
314 307
             $this->status = array_merge($this->status,array("OPERATION FAILED"));
315 308
             self::_errorLog("getting defaults : OPERATION FAILED",1);
@@ -371,8 +364,7 @@  discard block
 block discarded – undo
371 364
                                         . 'requested-attributes'
372 365
                                         . self::_giveMeStringLength($attributes[0])
373 366
                                         . $attributes[0];
374
-            }
375
-            else
367
+            } else
376 368
             {
377 369
                 $this->meta->attributes .= chr(0x44) // Keyword
378 370
                                         .  chr(0x0).chr(0x0) // zero-length name
@@ -411,14 +403,12 @@  discard block
 block discarded – undo
411 403
             if ($this->serveroutput->status == "successfull-ok")
412 404
             {
413 405
                 self::_errorLog("getting printers: ".$this->serveroutput->status,3);
414
-            }
415
-            else
406
+            } else
416 407
             {
417 408
                 self::_errorLog("getting printers: ".$this->serveroutput->status,1);
418 409
             }
419 410
             return $this->serveroutput->status;
420
-        }
421
-        else
411
+        } else
422 412
         {
423 413
             $this->status = array_merge($this->status,array("OPERATION FAILED"));
424 414
             self::_errorLog("getting printers : OPERATION FAILED",1);
@@ -544,8 +534,9 @@  discard block
 block discarded – undo
544 534
             }
545 535
 
546 536
         $prepend = '';
547
-        while ((strlen($value_built) + strlen($prepend)) < 4)
548
-            $prepend .= chr(0);
537
+        while ((strlen($value_built) + strlen($prepend)) < 4) {
538
+                    $prepend .= chr(0);
539
+        }
549 540
         return $prepend.$value_built;
550 541
     }
551 542
 
Please login to merge, or discard this patch.