Changeset 2525480
- Timestamp:
- 05/03/2021 05:21:52 PM (5 years ago)
- Location:
- redisearch
- Files:
-
- 1 deleted
- 34 edited
- 46 copied
-
tags/0.3.3 (copied) (copied from redisearch/trunk)
-
tags/0.3.3/README.md (copied) (copied from redisearch/trunk/README.md) (1 diff)
-
tags/0.3.3/composer.json (copied) (copied from redisearch/trunk/composer.json)
-
tags/0.3.3/composer.lock (copied) (copied from redisearch/trunk/composer.lock)
-
tags/0.3.3/lib (deleted)
-
tags/0.3.3/readme.txt (copied) (copied from redisearch/trunk/readme.txt) (2 diffs)
-
tags/0.3.3/src (copied) (copied from redisearch/trunk/src)
-
tags/0.3.3/src/Admin/Admin.php (copied) (copied from redisearch/trunk/src/Admin/Admin.php) (1 diff)
-
tags/0.3.3/src/Features/LiveSearch/assets/js/live-search.min.js (copied) (copied from redisearch/trunk/src/Features/LiveSearch/assets/js/live-search.min.js)
-
tags/0.3.3/src/Features/LiveSearch/assets/js/src/live-search.js (copied) (copied from redisearch/trunk/src/Features/LiveSearch/assets/js/src/live-search.js)
-
tags/0.3.3/src/RediSearch/Client.php (modified) (1 diff)
-
tags/0.3.3/src/RediSearch/Index.php (copied) (copied from redisearch/trunk/src/RediSearch/Index.php)
-
tags/0.3.3/src/RedisRaw/PredisAdapter.php (modified) (1 diff)
-
tags/0.3.3/src/Settings.php (modified) (1 diff)
-
tags/0.3.3/vendor/composer/ClassLoader.php (copied) (copied from redisearch/trunk/vendor/composer/ClassLoader.php)
-
tags/0.3.3/vendor/composer/autoload_classmap.php (copied) (copied from redisearch/trunk/vendor/composer/autoload_classmap.php)
-
tags/0.3.3/vendor/composer/autoload_psr4.php (copied) (copied from redisearch/trunk/vendor/composer/autoload_psr4.php)
-
tags/0.3.3/vendor/composer/autoload_real.php (copied) (copied from redisearch/trunk/vendor/composer/autoload_real.php)
-
tags/0.3.3/vendor/composer/autoload_static.php (copied) (copied from redisearch/trunk/vendor/composer/autoload_static.php)
-
tags/0.3.3/vendor/composer/installed.json (copied) (copied from redisearch/trunk/vendor/composer/installed.json)
-
tags/0.3.3/vendor/foadyousefi/seven-fields/src/Fields/Fields.php (modified) (1 diff)
-
tags/0.3.3/vendor/foadyousefi/seven-fields/src/Fields/Select.php (modified) (1 diff)
-
tags/0.3.3/vendor/front (copied) (copied from redisearch/trunk/vendor/front)
-
tags/0.3.3/vendor/front/redisearch/src/RedisRaw/PredisAdapter.php (modified) (1 diff)
-
tags/0.3.3/vendor/front/redisearch/src/Setup.php (modified) (1 diff)
-
tags/0.3.3/vendor/predis/predis/CHANGELOG.md (copied) (copied from redisearch/trunk/vendor/predis/predis/CHANGELOG.md)
-
tags/0.3.3/vendor/predis/predis/CONTRIBUTING.md (copied) (copied from redisearch/trunk/vendor/predis/predis/CONTRIBUTING.md)
-
tags/0.3.3/vendor/predis/predis/FAQ.md (copied) (copied from redisearch/trunk/vendor/predis/predis/FAQ.md)
-
tags/0.3.3/vendor/predis/predis/README.md (copied) (copied from redisearch/trunk/vendor/predis/predis/README.md)
-
tags/0.3.3/vendor/predis/predis/VERSION (copied) (copied from redisearch/trunk/vendor/predis/predis/VERSION)
-
tags/0.3.3/vendor/predis/predis/bin/create-pear (copied) (copied from redisearch/trunk/vendor/predis/predis/bin/create-pear)
-
tags/0.3.3/vendor/predis/predis/bin/create-phar (copied) (copied from redisearch/trunk/vendor/predis/predis/bin/create-phar)
-
tags/0.3.3/vendor/predis/predis/composer.json (copied) (copied from redisearch/trunk/vendor/predis/predis/composer.json)
-
tags/0.3.3/vendor/predis/predis/package.ini (copied) (copied from redisearch/trunk/vendor/predis/predis/package.ini)
-
tags/0.3.3/vendor/predis/predis/src/Client.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Client.php)
-
tags/0.3.3/vendor/predis/predis/src/ClientContextInterface.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/ClientContextInterface.php)
-
tags/0.3.3/vendor/predis/predis/src/ClientInterface.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/ClientInterface.php)
-
tags/0.3.3/vendor/predis/predis/src/Cluster/Distributor/HashRing.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Cluster/Distributor/HashRing.php)
-
tags/0.3.3/vendor/predis/predis/src/Configuration/ReplicationOption.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Configuration/ReplicationOption.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/Aggregate/SentinelReplication.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/Aggregate/SentinelReplication.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/Factory.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/Factory.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/Parameters.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/Parameters.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/PhpiredisSocketConnection.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/PhpiredisSocketConnection.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/PhpiredisStreamConnection.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/PhpiredisStreamConnection.php)
-
tags/0.3.3/vendor/predis/predis/src/Connection/WebdisConnection.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Connection/WebdisConnection.php)
-
tags/0.3.3/vendor/predis/predis/src/Replication/ReplicationStrategy.php (copied) (copied from redisearch/trunk/vendor/predis/predis/src/Replication/ReplicationStrategy.php)
-
tags/0.3.3/vendor/vaites/php-apache-tika/README.md (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/README.md)
-
tags/0.3.3/vendor/vaites/php-apache-tika/composer.json (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/composer.json)
-
tags/0.3.3/vendor/vaites/php-apache-tika/phpunit.xml (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/phpunit.xml)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Client.php (modified) (20 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Clients/CLIClient.php (modified) (15 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Clients/WebClient.php (modified) (31 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Metadata/DocumentMetadata.php (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/src/Metadata/DocumentMetadata.php)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Metadata/ImageMetadata.php (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/src/Metadata/ImageMetadata.php)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Metadata/Metadata.php (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/src/Metadata/Metadata.php)
-
tags/0.3.3/vendor/vaites/php-apache-tika/src/Metadata/MetadataInterface.php (copied) (copied from redisearch/trunk/vendor/vaites/php-apache-tika/src/Metadata/MetadataInterface.php)
-
tags/0.3.3/vendor/vaites/php-apache-tika/tests/BaseTest.php (modified) (10 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/tests/CLITest.php (modified) (3 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/tests/CommonTest.php (modified) (8 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/tests/ErrorTest.php (modified) (22 diffs)
-
tags/0.3.3/vendor/vaites/php-apache-tika/tests/WebTest.php (modified) (9 diffs)
-
tags/0.3.3/wp-redisearch.php (copied) (copied from redisearch/trunk/wp-redisearch.php) (2 diffs)
-
trunk/README.md (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Admin/Admin.php (modified) (1 diff)
-
trunk/src/RediSearch/Client.php (modified) (1 diff)
-
trunk/src/RedisRaw/PredisAdapter.php (modified) (1 diff)
-
trunk/src/Settings.php (modified) (1 diff)
-
trunk/vendor/foadyousefi/seven-fields/src/Fields/Fields.php (modified) (1 diff)
-
trunk/vendor/foadyousefi/seven-fields/src/Fields/Select.php (modified) (1 diff)
-
trunk/vendor/front/redisearch/src/RedisRaw/PredisAdapter.php (modified) (1 diff)
-
trunk/vendor/front/redisearch/src/Setup.php (modified) (1 diff)
-
trunk/vendor/vaites/php-apache-tika/src/Client.php (modified) (20 diffs)
-
trunk/vendor/vaites/php-apache-tika/src/Clients/CLIClient.php (modified) (15 diffs)
-
trunk/vendor/vaites/php-apache-tika/src/Clients/WebClient.php (modified) (31 diffs)
-
trunk/vendor/vaites/php-apache-tika/tests/BaseTest.php (modified) (10 diffs)
-
trunk/vendor/vaites/php-apache-tika/tests/CLITest.php (modified) (3 diffs)
-
trunk/vendor/vaites/php-apache-tika/tests/CommonTest.php (modified) (8 diffs)
-
trunk/vendor/vaites/php-apache-tika/tests/ErrorTest.php (modified) (22 diffs)
-
trunk/vendor/vaites/php-apache-tika/tests/WebTest.php (modified) (9 diffs)
-
trunk/wp-redisearch.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
redisearch/tags/0.3.3/README.md
r2455651 r2525480 53 53 54 54 ### Changelog 55 56 ##### 0.3.3 57 * **Added**: Ability to connect via UNIX sockets 58 55 59 56 60 ##### 0.3.2 -
redisearch/tags/0.3.3/readme.txt
r2455651 r2525480 6 6 Tags: search, redisearch, redis, fuzzy, aggregation, searching, autosuggest, suggest, advanced search, woocommerce 7 7 Requires at least: 5.0 8 Tested up to: 5. 69 Stable tag: 0.3. 28 Tested up to: 5.7 9 Stable tag: 0.3.3 10 10 Requires PHP: 7.2 11 11 License: GPLv2 or later … … 66 66 67 67 == Changelog == 68 69 = 0.3.3 = 70 * Added: Ability to connect via UNIX sockets 68 71 69 72 = 0.3.2 = -
redisearch/tags/0.3.3/src/Admin/Admin.php
r2455651 r2525480 151 151 public static function RedisServerConf() { 152 152 Fields::add( 'header', null, __( 'Redis server configurations', 'wp-redisearch' ) ); 153 Fields::add( 'text', 'wp_redisearch_server', __( 'Redis server', 'wp-redisearch' ), __( 'Redis server url, usually it is 127.0.0.1', 'wp-redisearch' ) ); 153 Fields::add( 'select', 'wp_redisearch_connection_scheme', __( 'Server communication scheme', 'wp-redisearch' ), __( 'Choose Redis server communication scheme.', 'wp-redisearch'), array('tcp' => 'TCP', 'unix' => 'UNIX') ); 154 Fields::add( 'text', 'wp_redisearch_server', __( 'Redis server/path', 'wp-redisearch' ), __( 'Redis server url, usually it is 127.0.0.1 and in case of using UNIX socket, the socket path.', 'wp-redisearch' ) ); 154 155 Fields::add( 'text', 'wp_redisearch_port', __( 'Redis port', 'wp-redisearch' ), __( 'Redis port number, by default it is 6379', 'wp-redisearch' ) ); 155 156 Fields::add( 'password', 'wp_redisearch_password', __( 'Redis server password', 'wp-redisearch' ), __( 'If your redis server is not password protected, leave this field blank', 'wp-redisearch' ) ); -
redisearch/tags/0.3.3/src/RediSearch/Client.php
r2452159 r2525480 19 19 Settings::RedisPort(), 20 20 Settings::RedisPassword(), 21 0 21 0, 22 Settings::RedisScheme() 22 23 ); 23 24 } -
redisearch/tags/0.3.3/src/RedisRaw/PredisAdapter.php
r2452159 r2525480 17 17 public $redis; 18 18 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null): RedisRawClientInterface { 20 $this->redis = new Client([ 21 'scheme' => 'tcp', 22 'host' => $hostname, 23 'port' => $port, 24 'database' => $db, 25 'password' => $password, 26 ]); 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null, $scheme = 'tcp'): RedisRawClientInterface { 20 $clientArgs = array(); 21 if ( $scheme === 'tcp' ) { 22 $clientArgs = array( 23 'scheme' => 'tcp', 24 'host' => $hostname, 25 'port' => $port, 26 'database' => $db, 27 'password' => $password, 28 ); 29 } else { 30 $clientArgs = array( 31 'scheme' => 'unix', 32 'path' => $host 33 ); 34 } 35 $this->redis = new Client( $clientArgs ); 27 36 $this->redis->connect(); 28 37 return $this; -
redisearch/tags/0.3.3/src/Settings.php
r2452159 r2525480 45 45 46 46 return isset( $redis_server ) && !empty( $redis_server ) ? $redis_server : '127.0.0.1'; 47 } 48 49 /** 50 * Using UNIX socket for communicating with Redis server or not. 51 * @since 0.1.0 52 * @param 53 * @return bool $unixServer 54 */ 55 public static function RedisScheme() { 56 /** 57 * First we try to get the WP_REDIS_SCHEME option from wp-config.php 58 * @since 0.3.3 59 */ 60 $redis_server = ( defined( 'WP_REDIS_SCHEME' ) ) ? WP_REDIS_SCHEME : get_option( 'wp_redisearch_connection_scheme' ); 61 62 return get_option( 'wp_redisearch_connection_scheme' ); 47 63 } 48 64 -
redisearch/tags/0.3.3/vendor/foadyousefi/seven-fields/src/Fields/Fields.php
r2013762 r2525480 77 77 update_option( $name, $value ); 78 78 break; 79 case 'select': 80 update_option( $name, $value ); 81 break; 79 82 case 'checkbox': 80 83 $value = isset( $value ) ? true : false; -
redisearch/tags/0.3.3/vendor/foadyousefi/seven-fields/src/Fields/Select.php
r1949960 r2525480 39 39 self::$description = $description; 40 40 self::$options = $options; 41 // Save value in as wp_option in database 42 parent::save( self::$name, 'select' ); 41 43 return $this->field_html(); 42 44 } -
redisearch/tags/0.3.3/vendor/front/redisearch/src/RedisRaw/PredisAdapter.php
r2452159 r2525480 17 17 public $redis; 18 18 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null): RedisRawClientInterface { 20 $this->redis = new Client([ 21 'scheme' => 'tcp', 22 'host' => $hostname, 23 'port' => $port, 24 'database' => $db, 25 'password' => $password, 26 ]); 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null, $scheme = 'tcp'): RedisRawClientInterface { 20 $clientArgs = array( 21 'database' => $db, 22 'password' => $password 23 ); 24 if ( $scheme === 'tcp' ) { 25 $clientArgs = array( 26 'scheme' => 'tcp', 27 'port' => $port, 28 'host' => $hostname 29 ); 30 } else if ( $scheme === 'unix' ) { 31 $clientArgs = array( 32 'scheme' => 'unix', 33 'path' => $host 34 ); 35 } 36 $this->redis = new Client( $clientArgs ); 27 37 $this->redis->connect(); 28 38 return $this; -
redisearch/tags/0.3.3/vendor/front/redisearch/src/Setup.php
r2452159 r2525480 17 17 * @return PredisAdapter 18 18 */ 19 public static function connect( $server = '127.0.0.1', $port = 6379, $password = null, $database = 0 ) {19 public static function connect( $server = '127.0.0.1', $port = 6379, $password = null, $database = 0, $scheme = 'tcp' ) { 20 20 // Connect to server 21 $client = ( new PredisAdapter() )->connect( $server, $port, $database, $password );21 $client = ( new PredisAdapter() )->connect( $server, $port, $database, $password, $database, $scheme ); 22 22 return $client; 23 23 } -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/src/Client.php
r2002534 r2525480 5 5 use Closure; 6 6 use Exception; 7 use stdClass; 7 8 8 9 use Vaites\ApacheTika\Clients\CLIClient; 9 10 use Vaites\ApacheTika\Clients\WebClient; 11 use Vaites\ApacheTika\Metadata\Metadata; 12 use Vaites\ApacheTika\Metadata\MetadataInterface; 10 13 11 14 /** … … 13 16 * 14 17 * @author David Martínez <contacto@davidmartinez.net> 15 * @link http://wiki.apache.org/tika/TikaJAXRS 16 * @link https://tika.apache.org/1.10/formats.html 18 * @link https://tika.apache.org/1.24/formats.html 17 19 */ 18 20 abstract class Client 19 21 { 20 /** 21 * List of supported Apache Tika versions 22 protected const MODE = null; 23 24 /** 25 * Checked flag 26 * 27 * @var bool 28 */ 29 protected $checked = false; 30 31 /** 32 * Response using callbacks 33 * 34 * @var string 35 */ 36 protected $response = null; 37 38 /** 39 * Platform (unix or win) 40 * 41 * @var string 42 */ 43 protected $platform = null; 44 45 /** 46 * Cached responses to avoid multiple request for the same file. 22 47 * 23 48 * @var array 24 49 */ 25 protected static $supportedVersions =26 [27 '1.7', '1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.19.1'28 ];29 30 /**31 * Response using callbacks32 *33 * @var string34 */35 protected $response = null;36 37 /**38 * Cached responses to avoid multiple request for the same file.39 *40 * @var array41 */42 50 protected $cache = []; 43 51 44 52 /** 53 * Text encoding 54 * 55 * @var string|null 56 */ 57 protected $encoding = null; 58 59 /** 45 60 * Callback called on secuential read 46 61 * 47 * @var \Closure62 * @var callable|null 48 63 */ 49 64 protected $callback = null; 50 65 51 66 /** 67 * Enable or disable appending when using callback 68 * 69 * @var bool 70 */ 71 protected $callbackAppend = true; 72 73 /** 52 74 * Size of chunks for callback 53 75 * … … 64 86 65 87 /** 66 * Get a class instance 67 * 68 * @param string $param1 path or host 69 * @param int $param2 Java binary path or port for web client 70 * @param array $options options for cURL request 71 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 72 * @throws \Exception 73 */ 74 public static function make($param1 = null, $param2 = null, $options = []) 75 { 76 if (preg_match('/\.jar$/', func_get_arg(0))) 77 { 78 return new CLIClient($param1, $param2); 88 * Configure client 89 */ 90 public function __construct() 91 { 92 $this->platform = defined('PHP_WINDOWS_VERSION_MAJOR') ? 'win' : 'unix'; 93 } 94 95 /** 96 * Get a class instance throwing an exception if check fails 97 * 98 * @param string $param1 path or host 99 * @param string|int $param2 Java binary path or port for web client 100 * @param array $options options for cURL request 101 * @param bool $check check JAR file or server connection 102 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 103 * @throws \Exception 104 */ 105 public static function make(string $param1 = null, $param2 = null, array $options = [], bool $check = true): Client 106 { 107 if(preg_match('/\.jar$/', func_get_arg(0))) 108 { 109 return new CLIClient($param1, $param2, $check); 79 110 } 80 111 else 81 112 { 82 return new WebClient($param1, $param2, $options); 83 } 113 return new WebClient($param1, $param2, $options, $check); 114 } 115 } 116 117 /** 118 * Get a class instance delaying the check 119 * 120 * @param string $param1 path or host 121 * @param int $param2 Java binary path or port for web client 122 * @param array $options options for cURL request 123 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 124 * @throws \Exception 125 */ 126 public static function prepare($param1 = null, $param2 = null, $options = []): Client 127 { 128 return self::make($param1, $param2, $options, false); 129 } 130 131 /** 132 * Get the encoding 133 */ 134 public function getEncoding(): ?string 135 { 136 return $this->encoding; 137 } 138 139 /** 140 * Set the encoding 141 * 142 * @throws \Exception 143 */ 144 public function setEncoding(string $encoding): self 145 { 146 if(!empty($encoding)) 147 { 148 $this->encoding = $encoding; 149 } 150 else 151 { 152 throw new Exception('Invalid encoding'); 153 } 154 155 return $this; 84 156 } 85 157 86 158 /** 87 159 * Get the callback 88 * 89 * @return \Closure|null 90 */ 91 public function getCallback() 160 */ 161 public function getCallback(): ?Closure 92 162 { 93 163 return $this->callback; … … 97 167 * Set the callback (callable or closure) for call on secuential read 98 168 * 99 * @param mixed $callback 100 * @return $this 101 * @throws \Exception 102 */ 103 public function setCallback($callback) 104 { 105 if($callback instanceof Closure) 106 { 169 * @throws \Exception 170 */ 171 public function setCallback(callable $callback, bool $append = true): self 172 { 173 if($callback instanceof Closure || is_array($callback)) 174 { 175 $this->callbackAppend = (bool) $append; 107 176 $this->callback = $callback; 108 177 } 109 elseif(is_callable($callback)) 110 { 111 $this->callback = function($chunk) use($callback) 178 elseif(is_string($callback)) 179 { 180 $this->callbackAppend = (bool) $append; 181 $this->callback = function($chunk) use ($callback) 112 182 { 113 183 return call_user_func_array($callback, [$chunk]); … … 124 194 /** 125 195 * Get the chunk size 126 * 127 * @return int 128 */ 129 public function getChunkSize() 196 */ 197 public function getChunkSize(): int 130 198 { 131 199 return $this->chunkSize; … … 135 203 * Set the chunk size for secuential read 136 204 * 137 * @param int $size 138 * @return $this 139 * @throws \Exception 140 */ 141 public function setChunkSize($size) 142 { 143 if(static::MODE == 'cli' && is_numeric($size)) 144 { 145 $this->chunkSize = (int)$size; 146 } 147 elseif(static::MODE == 'web') 205 * @throws \Exception 206 */ 207 public function setChunkSize(int $size): self 208 { 209 if(static::MODE == 'cli') 210 { 211 $this->chunkSize = $size; 212 } 213 else 148 214 { 149 215 throw new Exception('Chunk size is not supported on web mode'); 150 216 } 151 else152 {153 throw new Exception("$size is not a valid chunk size");154 }155 217 156 218 return $this; … … 159 221 /** 160 222 * Get the remote download flag 161 * 162 * @return bool 163 */ 164 public function getDownloadRemote() 223 */ 224 public function getDownloadRemote(): bool 165 225 { 166 226 return $this->downloadRemote; … … 169 229 /** 170 230 * Set the remote download flag 171 * 172 * @param bool $download 173 * @return $this 174 */ 175 public function setDownloadRemote($download) 231 */ 232 public function setDownloadRemote(bool $download): self 176 233 { 177 234 $this->downloadRemote = (bool) $download; … … 183 240 * Gets file metadata 184 241 * 185 * @param string $file 186 * @return \Vaites\ApacheTika\Metadata\Metadata 187 * @throws \Exception 188 */ 189 public function getMetadata($file) 190 { 191 return $this->request('meta', $file); 242 * @throws \Exception 243 */ 244 public function getMetadata(string $file): MetadataInterface 245 { 246 $response = $this->parseJsonResponse($this->request('meta', $file)); 247 248 if($response instanceof stdClass == false) 249 { 250 throw new Exception("Unexpected metadata response for $file"); 251 } 252 253 return Metadata::make($response, $file); 254 } 255 256 /** 257 * Gets recursive file metadata where the returned array indexes are the file name. 258 * 259 * Example: for a sample.zip with an example.doc file, the return array looks like if be defined as: 260 * 261 * [ 262 * 'sample.zip' => new Metadata() 263 * 'sample.zip/example.doc' => new DocumentMetadata() 264 * ] 265 * 266 * @link https://cwiki.apache.org/confluence/display/TIKA/TikaServer#TikaServer-RecursiveMetadataandContent 267 * @throws \Exception 268 */ 269 public function getRecursiveMetadata(string $file, ?string $format = 'ignore'): array 270 { 271 if(in_array($format, ['text', 'html', 'ignore']) == false) 272 { 273 throw new Exception("Unknown recursive type (must be text, html, ignore or null)"); 274 } 275 276 $response = $this->parseJsonResponse($this->request("rmeta/$format", $file)); 277 278 if(is_array($response) == false) 279 { 280 throw new Exception("Unexpected metadata response for $file"); 281 } 282 283 $metadata = []; 284 285 foreach($response as $item) 286 { 287 $name = basename($file); 288 if(isset($item->{'X-TIKA:embedded_resource_path'})) 289 { 290 $name .= $item->{'X-TIKA:embedded_resource_path'}; 291 } 292 293 $metadata[$name] = Metadata::make($item, $file); 294 } 295 296 return $metadata; 192 297 } 193 298 … … 195 300 * Detect language 196 301 * 197 * @param string $file 198 * @return string 199 * @throws \Exception 200 */ 201 public function getLanguage($file) 302 * @throws \Exception 303 */ 304 public function getLanguage(string $file): string 202 305 { 203 306 return $this->request('lang', $file); … … 207 310 * Detect MIME type 208 311 * 209 * @param string $file 210 * @return string 211 * @throws \Exception 212 */ 213 public function getMIME($file) 312 * @throws \Exception 313 */ 314 public function getMIME(string $file): string 214 315 { 215 316 return $this->request('mime', $file); … … 219 320 * Extracts HTML 220 321 * 221 * @param string $file 222 * @param mixed $callback 223 * @return string 224 * @throws \Exception 225 */ 226 public function getHTML($file, $callback = null) 322 * @throws \Exception 323 */ 324 public function getHTML(string $file, callable $callback = null, bool $append = true): string 227 325 { 228 326 if(!is_null($callback)) 229 327 { 230 $this->setCallback($callback );328 $this->setCallback($callback, $append); 231 329 } 232 330 … … 235 333 236 334 /** 335 * Extracts XHTML 336 * 337 * @throws \Exception 338 */ 339 public function getXHTML(string $file, callable $callback = null, bool $append = true): string 340 { 341 if(!is_null($callback)) 342 { 343 $this->setCallback($callback, $append); 344 } 345 346 return $this->request('xhtml', $file); 347 } 348 349 /** 237 350 * Extracts text 238 351 * 239 * @param string $file 240 * @param mixed $callback 241 * @return string 242 * @throws \Exception 243 */ 244 public function getText($file, $callback = null) 352 * @throws \Exception 353 */ 354 public function getText(string $file, callable $callback = null, bool $append = true): string 245 355 { 246 356 if(!is_null($callback)) 247 357 { 248 $this->setCallback($callback );358 $this->setCallback($callback, $append); 249 359 } 250 360 … … 255 365 * Extracts main text 256 366 * 257 * @param string $file 258 * @param mixed $callback 259 * @return string 260 * @throws \Exception 261 */ 262 public function getMainText($file, $callback = null) 367 * @throws \Exception 368 */ 369 public function getMainText(string $file, callable $callback = null, bool $append = true): string 263 370 { 264 371 if(!is_null($callback)) 265 372 { 266 $this->setCallback($callback );373 $this->setCallback($callback, $append); 267 374 } 268 375 … … 271 378 272 379 /** 273 * Returns the supported MIME types274 *275 * @return string276 * @throws \Exception277 */278 public function getSupportedMIMETypes()279 {280 return $this->request('mime-types');281 }282 283 /**284 * Returns the available detectors285 *286 * @return string287 * @throws \Exception288 */289 public function getAvailableDetectors()290 {291 return $this->request('detectors');292 }293 294 /**295 * Returns the available parsers296 *297 * @return string298 * @throws \Exception299 */300 public function getAvailableParsers()301 {302 return $this->request('parsers');303 }304 305 /**306 380 * Returns current Tika version 307 381 * 308 * @return string 309 * @throws \Exception 310 */ 311 public function getVersion() 382 * @throws \Exception 383 */ 384 public function getVersion(): string 312 385 { 313 386 return $this->request('version'); … … 317 390 * Return the list of Apache Tika supported versions 318 391 * 319 * @return array 320 */ 321 public static function getSupportedVersions() 322 { 323 return self::$supportedVersions; 392 * @throws \Exception 393 */ 394 public function getSupportedVersions(): array 395 { 396 static $versions = null; 397 398 if(is_null($versions)) 399 { 400 $composer = json_decode(file_get_contents(dirname(__DIR__) . '/composer.json'), true); 401 $versions = $composer['extra']['supported-versions'] ?? null; 402 403 if(empty($versions)) 404 { 405 throw new Exception("An error ocurred trying to read package's composer.json file"); 406 } 407 } 408 409 return $versions; 410 } 411 412 /** 413 * Sets the checked flag 414 */ 415 public function setChecked(bool $checked): self 416 { 417 $this->checked = (bool) $checked; 418 419 return $this; 420 } 421 422 /** 423 * Checks if instance is checked 424 */ 425 public function isChecked(): bool 426 { 427 return $this->checked; 428 } 429 430 /** 431 * Check if a response is cached 432 */ 433 protected function isCached(string $type, string $file): bool 434 { 435 return isset($this->cache[sha1($file)][$type]); 436 } 437 438 /** 439 * Get a cached response 440 */ 441 protected function getCachedResponse(string $type, string $file) 442 { 443 return $this->cache[sha1($file)][$type] ?? null; 444 } 445 446 /** 447 * Check if a request type must be cached 448 */ 449 protected function isCacheable(string $type): bool 450 { 451 return in_array($type, ['lang', 'meta']); 452 } 453 454 /** 455 * Caches a response 456 */ 457 protected function cacheResponse(string $type, $response, string $file): bool 458 { 459 $this->cache[sha1($file)][$type] = $response; 460 461 return true; 324 462 } 325 463 326 464 /** 327 465 * Checks if a specific version is supported 328 * 329 * @param string $version 330 * @return bool 331 */ 332 public static function isVersionSupported($version) 333 { 334 return in_array($version, self::getSupportedVersions()); 466 */ 467 public function isVersionSupported(string $version): bool 468 { 469 return in_array($version, $this->getSupportedVersions()); 470 } 471 472 /** 473 * Check if a mime type is supported 474 * 475 * @param string $mime 476 * @return bool 477 * @throws \Exception 478 */ 479 public function isMIMETypeSupported(string $mime): bool 480 { 481 return array_key_exists($mime, $this->getSupportedMIMETypes()); 335 482 } 336 483 … … 338 485 * Check the request before executing 339 486 * 340 * @param string $type 341 * @param string $file 342 * @return string 343 * @throws \Exception 344 */ 345 public function checkRequest($type, $file) 487 * @throws \Exception 488 */ 489 public function checkRequest(string $type, string $file = null): ?string 346 490 { 347 491 // no checks for getters … … 349 493 { 350 494 // 351 } 352 // invalid local file 495 } // invalid local file 353 496 elseif(!preg_match('/^http/', $file) && !file_exists($file)) 354 497 { 355 498 throw new Exception("File $file can't be opened"); 356 } 357 // invalid remote file 499 } // invalid remote file 358 500 elseif(preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0])) 359 501 { 360 502 throw new Exception("File $file can't be opened", 2); 361 } 362 // download remote file if required only for integrated downloader 503 } // download remote file if required only for integrated downloader 363 504 elseif(preg_match('/^http/', $file) && $this->downloadRemote) 364 505 { … … 370 511 371 512 /** 513 * Parse the response returned by Apache Tika 514 * 515 * @return mixed 516 * @throws \Exception 517 */ 518 protected function parseJsonResponse(string $response) 519 { 520 // an empty response throws an error 521 if(empty($response) || trim($response) == '') 522 { 523 throw new Exception('Empty response'); 524 } 525 526 // decode the JSON response 527 $json = json_decode($response); 528 529 // exceptions if metadata is not valid 530 if(json_last_error()) 531 { 532 $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Error parsing JSON response'; 533 534 throw new Exception($message, json_last_error()); 535 } 536 537 return $json; 538 } 539 540 /** 372 541 * Download file to a temporary folder 373 542 * 374 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 375 * @param string $file 376 * @return string 377 * @throws \Exception 378 */ 379 protected function downloadFile($file) 543 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 544 * @throws \Exception 545 */ 546 protected function downloadFile(string $file): string 380 547 { 381 548 $dest = tempnam(sys_get_temp_dir(), 'TIKA'); … … 411 578 412 579 /** 580 * Must return the supported MIME types 581 * 582 * @throws \Exception 583 */ 584 abstract public function getSupportedMIMETypes(): array; 585 586 /** 587 * Must return the available detectors 588 * 589 * @throws \Exception 590 */ 591 abstract public function getAvailableDetectors(): array; 592 593 /** 594 * Must return the available parsers 595 * 596 * @throws \Exception 597 */ 598 abstract public function getAvailableParsers(): array; 599 600 /** 601 * Check Java binary, JAR path or server connection 602 */ 603 abstract public function check(): void; 604 605 /** 413 606 * Configure and make a request and return its results. 414 607 * 415 * @param string $type 416 * @param string $file 417 * @return string 418 * @throws \Exception 419 */ 420 abstract public function request($type, $file); 608 * @throws \Exception 609 */ 610 abstract public function request(string $type, string $file = null): string; 421 611 } -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/src/Clients/CLIClient.php
r2002534 r2525480 6 6 7 7 use Vaites\ApacheTika\Client; 8 use Vaites\ApacheTika\Metadata\Metadata;9 8 10 9 /** … … 12 11 * 13 12 * @author David Martínez <contacto@davidmartinez.net> 14 * @link http://wiki.apache.org/tika/TikaJAXRS 15 * @link https://tika.apache.org/1.12/formats.html 13 * @link https://tika.apache.org/1.23/gettingstarted.html#Using_Tika_as_a_command_line_utility 16 14 */ 17 15 class CLIClient extends Client 18 16 { 19 const MODE = 'cli';17 protected const MODE = 'cli'; 20 18 21 19 /** … … 34 32 35 33 /** 34 * Java arguments 35 * 36 * @var string 37 */ 38 protected $javaArgs = null; 39 40 /** 36 41 * Configure client 37 42 * 38 * @param string $path 39 * @param string $java 40 * 41 * @throws Exception 42 */ 43 public function __construct($path = null, $java = null) 44 { 43 * @throws \Exception 44 */ 45 public function __construct(string $path = null, string $java = null, bool $check = true) 46 { 47 parent::__construct(); 48 45 49 if($path) 46 50 { … … 52 56 $this->setJava($java); 53 57 } 58 59 if($check === true) 60 { 61 $this->check(); 62 } 54 63 } 55 64 56 65 /** 57 66 * Get the path 58 * 59 * @return null|string 60 */ 61 public function getPath() 67 */ 68 public function getPath(): ?string 62 69 { 63 70 return $this->path; … … 66 73 /** 67 74 * Set the path 68 * 69 * @param string $path 70 * @return $this 71 */ 72 public function setPath($path) 75 */ 76 public function setPath($path): self 73 77 { 74 78 $this->path = $path; … … 79 83 /** 80 84 * Get the Java path 81 * 82 * @return null|int 83 */ 84 public function getJava() 85 */ 86 public function getJava(): ?string 85 87 { 86 88 return $this->java; … … 89 91 /** 90 92 * Set the Java path 91 * 92 * @param string $java 93 * @return $this 94 */ 95 public function setJava($java) 93 */ 94 public function setJava(string $java): self 96 95 { 97 96 $this->java = $java; … … 101 100 102 101 /** 102 * Get the Java arguments 103 */ 104 public function getJavaArgs(): ?string 105 { 106 return $this->javaArgs; 107 } 108 109 /** 110 * Set the Java arguments 111 * 112 * NOTE: to modify child process jvm args, prepend "J" to each argument (-JXmx4g) 113 */ 114 public function setJavaArgs(string $args): self 115 { 116 $this->javaArgs = $args; 117 118 return $this; 119 } 120 121 /** 122 * Returns the supported MIME types 123 * 124 * NOTE: the data provided by the CLI must be parsed: mime type has no spaces, aliases go next prefixed with spaces 125 * 126 * @throws \Exception 127 */ 128 public function getSupportedMIMETypes(): array 129 { 130 $mime = null; 131 $mimeTypes = []; 132 133 $response = preg_split("/\n/", $this->request('mime-types')); 134 135 foreach($response as $line) 136 { 137 if(preg_match('/^\w+/', $line)) 138 { 139 $mime = trim($line); 140 $mimeTypes[$mime] = ['alias' => []]; 141 } 142 else 143 { 144 [$key, $value] = preg_split('/:\s+/', trim($line)); 145 146 if($key == 'alias') 147 { 148 $mimeTypes[$mime]['alias'][] = $value; 149 } 150 else 151 { 152 $mimeTypes[$mime][$key] = $value; 153 } 154 } 155 } 156 157 158 return $mimeTypes; 159 } 160 161 /** 162 * Returns the available detectors 163 * 164 * @throws \Exception 165 */ 166 public function getAvailableDetectors(): array 167 { 168 $detectors = []; 169 170 $split = preg_split("/\n/", $this->request('detectors')); 171 172 $parent = null; 173 foreach($split as $line) 174 { 175 if(preg_match('/composite/i', $line)) 176 { 177 $parent = trim(preg_replace('/\(.+\):/', '', $line)); 178 $detectors[$parent] = ['children' => [], 'composite' => true, 'name' => $parent]; 179 } 180 else 181 { 182 $child = trim($line); 183 $detectors[$parent]['children'][$child] = ['composite' => false, 'name' => $child]; 184 } 185 } 186 187 return $detectors; 188 } 189 190 /** 191 * Returns the available parsers 192 * 193 * @throws \Exception 194 */ 195 public function getAvailableParsers(): array 196 { 197 $parsers = []; 198 199 $split = preg_split("/\n/", $this->request('parsers')); 200 array_shift($split); 201 202 $parent = null; 203 foreach($split as $line) 204 { 205 if(preg_match('/composite/i', $line)) 206 { 207 $parent = trim(preg_replace('/\(.+\):/', '', $line)); 208 209 $parsers[$parent] = ['children' => [], 'composite' => true, 'name' => $parent, 'decorated' => false]; 210 } 211 else 212 { 213 $child = trim($line); 214 215 $parsers[$parent]['children'][$child] = ['composite' => false, 'name' => $child, 'decorated' => false]; 216 } 217 } 218 219 return $parsers; 220 } 221 222 /** 223 * Check Java binary, JAR path or server connection 224 * 225 * @throws \Exception 226 */ 227 public function check(): void 228 { 229 if($this->isChecked() === false) 230 { 231 // Java command must not return an error 232 try 233 { 234 $this->exec(($this->java ?: 'java') . ' -version'); 235 } 236 catch(Exception $exception) 237 { 238 throw new Exception('Java command not found'); 239 } 240 241 // JAR path must exists 242 if(file_exists($this->path) === false) 243 { 244 throw new Exception('Apache Tika app JAR not found'); 245 } 246 247 $this->setChecked(true); 248 } 249 } 250 251 /** 103 252 * Configure and make a request and return its results 104 253 * 105 * @ param string $type106 * @param string $file107 * @returnstring108 * @throws \Exception109 */110 public function request($type, $file = null)111 { 254 * @throws \Exception 255 */ 256 public function request(string $type, string $file = null): string 257 { 258 // check if not checked 259 $this->check(); 260 112 261 // check if is cached 113 if( isset($this->cache[sha1($file)][$type]))114 { 115 return $this-> cache[sha1($file)][$type];262 if($file !== null && $this->isCached($type, $file)) 263 { 264 return $this->getCachedResponse($type, $file); 116 265 } 117 266 … … 120 269 121 270 // check the request 122 $file = parent::checkRequest($type, $file);271 $file = $this->checkRequest($type, $file); 123 272 124 273 // add last argument … … 130 279 // build command 131 280 $jar = escapeshellarg($this->path); 132 $command = ($this->java ?: 'java') . " -jar $jar " . implode(' ', $arguments);281 $command = trim(($this->java ?: 'java') . " -jar $jar " . implode(' ', $arguments) . " {$this->javaArgs}"); 133 282 134 283 // run command … … 136 285 137 286 // metadata response 138 if( $type == 'meta')287 if(in_array(preg_replace('/\/.+/', '', $type), ['meta', 'rmeta'])) 139 288 { 140 289 // fix for invalid? json returned only with images 141 290 $response = str_replace(basename($file) . '"}{', '", ', $response); 142 291 143 // on Windows, response comes in another charset 144 if(defined('PHP_WINDOWS_VERSION_MAJOR')) 145 { 146 $response = utf8_encode($response); 147 } 148 149 $response = Metadata::make($response, $file); 292 // on Windows, response must be encoded to UTF8 293 $response = $this->platform == 'win' ? utf8_encode($response) : $response; 150 294 } 151 295 152 296 // cache certain responses 153 if( in_array($type, ['lang', 'meta']))154 { 155 $this->cache [sha1($file)][$type] = $response;297 if($this->isCacheable($type)) 298 { 299 $this->cacheResponse($type, $response, $file); 156 300 } 157 301 … … 162 306 * Run the command and return its results 163 307 * 164 * @param string $command 165 * @return null|string 166 * @throws \Exception 167 */ 168 public function exec($command) 308 * @throws \Exception 309 */ 310 public function exec(string $command): ?string 169 311 { 170 312 // run command … … 187 329 } 188 330 189 $this->response .= $chunk; 331 if($this->callbackAppend === true) 332 { 333 $this->response .= $chunk; 334 } 190 335 } 191 336 fclose($pipes[1]); … … 205 350 * Get the arguments to run the command 206 351 * 207 * @param string $type208 * @param string $file209 * @return array210 352 * @throws Exception 211 353 */ 212 protected function getArguments( $type, $file = null)213 { 214 // parameters for command215 $arguments = []; 354 protected function getArguments(string $type, string $file = null): array 355 { 356 $arguments = $this->encoding ? ["--encoding={$this->encoding}"] : []; 357 216 358 switch($type) 217 359 { … … 256 398 break; 257 399 400 case 'rmeta/ignore': 401 $arguments[] = '--metadata --jsonRecursive'; 402 break; 403 404 case 'rmeta/html': 405 $arguments[] = '--html --jsonRecursive'; 406 break; 407 408 case 'rmeta/text': 409 $arguments[] = '--text --jsonRecursive'; 410 break; 411 412 case 'xhtml': 413 $arguments[] = '--xml'; 414 break; 415 258 416 default: 259 throw new Exception( "Unknown type $type");417 throw new Exception($file ? "Unknown type $type for $file" : "Unknown type $type"); 260 418 } 261 419 -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/src/Clients/WebClient.php
r2002534 r2525480 6 6 7 7 use Vaites\ApacheTika\Client; 8 use Vaites\ApacheTika\Metadata\Metadata;9 8 10 9 /** … … 12 11 * 13 12 * @author David Martínez <contacto@davidmartinez.net> 14 * @link http://wiki.apache.org/tika/TikaJAXRS 15 * @link https://tika.apache.org/1.12/formats.html 13 * @link https://cwiki.apache.org/confluence/display/TIKA/TikaServer 16 14 */ 17 15 class WebClient extends Client 18 16 { 19 const MODE = 'web';17 protected const MODE = 'web'; 20 18 21 19 /** … … 31 29 * @var string 32 30 */ 33 protected $host = '127.0.0.1';31 protected $host = null; 34 32 35 33 /** … … 38 36 * @var int 39 37 */ 40 protected $port = 9998;38 protected $port = null; 41 39 42 40 /** … … 54 52 protected $options = 55 53 [ 56 CURLINFO_HEADER_OUT => true,57 CURLOPT_HTTPHEADER => [],58 CURLOPT_PUT => true,59 CURLOPT_RETURNTRANSFER => true,60 CURLOPT_TIMEOUT => 5,54 CURLINFO_HEADER_OUT => true, 55 CURLOPT_HTTPHEADER => [], 56 CURLOPT_PUT => true, 57 CURLOPT_RETURNTRANSFER => true, 58 CURLOPT_TIMEOUT => 5 61 59 ]; 62 60 … … 64 62 * Configure class and test if server is running 65 63 * 66 * @param string $host 67 * @param int $port 68 * @param array $options 69 * @throws \Exception 70 */ 71 public function __construct($host = null, $port = null, $options = []) 72 { 73 if($host) 64 * @throws \Exception 65 */ 66 public function __construct(string $host = null, int $port = null, array $options = [], bool $check = true) 67 { 68 parent::__construct(); 69 70 if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL)) 71 { 72 $this->setUrl($host); 73 } 74 elseif($host) 74 75 { 75 76 $this->setHost($host); 76 77 } 77 78 78 if( $port)79 if(is_numeric($port)) 79 80 { 80 81 $this->setPort($port); … … 88 89 $this->setDownloadRemote(true); 89 90 90 $this->getVersion(); // exception if not running 91 if($check === true) 92 { 93 $this->check(); 94 } 95 } 96 97 /** 98 * Get the base URL 99 */ 100 public function getUrl(): string 101 { 102 return sprintf('http://%s:%d', $this->host, $this->port ?: 9998); 103 } 104 105 /** 106 * Set the host and port using an URL 107 */ 108 public function setUrl(string $url): self 109 { 110 $url = parse_url($url); 111 112 $this->setHost($url['host']); 113 114 if(isset($url['port'])) 115 { 116 $this->setPort($url['port']); 117 } 118 119 return $this; 91 120 } 92 121 93 122 /** 94 123 * Get the host 95 * 96 * @return null|string 97 */ 98 public function getHost() 124 */ 125 public function getHost(): ?string 99 126 { 100 127 return $this->host; … … 103 130 /** 104 131 * Set the host 105 * 106 * @param string $host 107 * @return $this 108 */ 109 public function setHost($host) 132 */ 133 public function setHost(string $host): self 110 134 { 111 135 $this->host = $host; … … 116 140 /** 117 141 * Get the port 118 * 119 * @return null|int 120 */ 121 public function getPort() 142 */ 143 public function getPort(): ?int 122 144 { 123 145 return $this->port; … … 126 148 /** 127 149 * Set the port 128 * 129 * @param int $port 130 * @return $this 131 */ 132 public function setPort($port) 150 */ 151 public function setPort(int $port): self 133 152 { 134 153 $this->port = $port; … … 139 158 /** 140 159 * Get the number of retries 141 * 142 * @return int 143 */ 144 public function getRetries() 160 */ 161 public function getRetries(): int 145 162 { 146 163 return $this->retries; … … 149 166 /** 150 167 * Set the number of retries 151 * 152 * @param int $retries 153 * @return $this 154 */ 155 public function setRetries($retries) 168 */ 169 public function setRetries(int $retries): self 156 170 { 157 171 $this->retries = $retries; … … 162 176 /** 163 177 * Get all the options 164 * 165 * @return null|array 166 */ 167 public function getOptions() 178 */ 179 public function getOptions(): array 168 180 { 169 181 return $this->options; … … 173 185 * Get an specified option 174 186 * 175 * @param string $key176 187 * @return mixed 177 188 */ 178 public function getOption( $key)179 { 180 return isset($this->options[$key]) ? $this->options[$key] :null;189 public function getOption(int $key) 190 { 191 return $this->options[$key] ?? null; 181 192 } 182 193 … … 184 195 * Set a cURL option to be set with curl_setopt() 185 196 * 186 * @link http://php.net/manual/en/curl.constants.php 187 * @link http://php.net/manual/en/function.curl-setopt.php 188 * @param string $key 189 * @param mixed $value 190 * @return $this 191 * @throws \Exception 192 */ 193 public function setOption($key, $value) 197 * @link http://php.net/manual/en/curl.constants.php 198 * @link http://php.net/manual/en/function.curl-setopt.php 199 * @throws \Exception 200 */ 201 public function setOption(int $key, $value): self 194 202 { 195 203 if(in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER])) … … 206 214 * Set the cURL options 207 215 * 208 * @param array $options 209 * @return $this 210 * @throws \Exception 211 */ 212 public function setOptions($options) 216 * @throws \Exception 217 */ 218 public function setOptions(array $options): self 213 219 { 214 220 foreach($options as $key => $value) … … 222 228 /** 223 229 * Get the timeout value for cURL 224 * 225 * @return int 226 */ 227 public function getTimeout() 230 */ 231 public function getTimeout(): int 228 232 { 229 233 return $this->getOption(CURLOPT_TIMEOUT); … … 233 237 * Set the timeout value for cURL 234 238 * 235 * @param int $value 236 * @return $this 237 * @throws \Exception 238 */ 239 public function setTimeout($value) 239 * @throws \Exception 240 */ 241 public function setTimeout(int $value): self 240 242 { 241 243 $this->setOption(CURLOPT_TIMEOUT, (int) $value); … … 245 247 246 248 /** 249 * Returns the supported MIME types 250 * 251 * @throws \Exception 252 */ 253 public function getSupportedMIMETypes(): array 254 { 255 $mimeTypes = json_decode($this->request('mime-types'), true); 256 257 ksort($mimeTypes); 258 259 return $mimeTypes; 260 } 261 262 /** 263 * Returns the available detectors 264 * 265 * @throws \Exception 266 */ 267 public function getAvailableDetectors(): array 268 { 269 $detectors = [json_decode($this->request('detectors'), true)]; 270 271 foreach($detectors as $index => $parent) 272 { 273 $detectors[$parent['name']] = $parent; 274 275 if(isset($parent['children'])) 276 { 277 foreach($parent['children'] as $subindex => $child) 278 { 279 $detectors[$parent['name']]['children'][$child['name']] = $child; 280 281 unset($detectors[$parent['name']]['children'][$subindex]); 282 } 283 } 284 285 unset($detectors[$index]); 286 } 287 288 return $detectors; 289 } 290 291 /** 292 * Returns the available parsers 293 * 294 * @throws \Exception 295 */ 296 public function getAvailableParsers(): array 297 { 298 $parsers = [json_decode($this->request('parsers'), true)]; 299 300 foreach($parsers as $index => $parent) 301 { 302 $parsers[$parent['name']] = $parent; 303 304 if(isset($parent['children'])) 305 { 306 foreach($parent['children'] as $subindex => $child) 307 { 308 $parsers[$parent['name']]['children'][$child['name']] = $child; 309 310 unset($parsers[$parent['name']]['children'][$subindex]); 311 } 312 } 313 314 unset($parsers[$index]); 315 } 316 317 return $parsers; 318 } 319 320 /** 321 * Check if server is running 322 * 323 * @throws \Exception 324 */ 325 public function check(): void 326 { 327 if($this->isChecked() === false) 328 { 329 $this->setChecked(true); 330 331 // throws an exception if server is unreachable or can't connect 332 $this->request('version'); 333 } 334 } 335 336 /** 247 337 * Configure, make a request and return its results 248 338 * 249 * @param string $type 250 * @param string $file 251 * @return string 252 * @throws \Exception 253 */ 254 public function request($type, $file = null) 339 * @throws \Exception 340 */ 341 public function request(string $type, string $file = null): string 255 342 { 256 343 static $retries = []; 257 344 345 // check if not checked 346 $this->check(); 347 258 348 // check if is cached 259 if( isset($this->cache[sha1($file)][$type]))260 { 261 return $this-> cache[sha1($file)][$type];349 if($file !== null && $this->isCached($type, $file)) 350 { 351 return $this->getCachedResponse($type, $file); 262 352 } 263 353 elseif(!isset($retries[sha1($file)])) … … 267 357 268 358 // parameters for cURL request 269 list($resource, $headers)= $this->getParameters($type, $file);359 [$resource, $headers] = $this->getParameters($type, $file); 270 360 271 361 // check the request 272 $file = parent::checkRequest($type, $file);362 $file = $this->checkRequest($type, $file); 273 363 274 364 // cURL options … … 282 372 283 373 // cURL init and options 284 $options[CURLOPT_URL] = "http://{$this->host}:{$this->port}". "/$resource";374 $options[CURLOPT_URL] = $this->getUrl() . "/$resource"; 285 375 286 376 // get the response and the HTTP status code 287 list($response, $status) = $this->exec($options); 377 [$response, $status] = $this->exec($options); 378 379 // reduce memory usage closing cURL resource 380 if(isset($options[CURLOPT_INFILE]) && is_resource($options[CURLOPT_INFILE])) 381 { 382 fclose($options[CURLOPT_INFILE]); 383 } 288 384 289 385 // request completed successfully 290 386 if($status == 200) 291 387 { 292 if($type == 'meta') 388 // cache certain responses 389 if($this->isCacheable($type)) 293 390 { 294 $ response = Metadata::make($response, $file);391 $this->cacheResponse($type, $response, $file); 295 392 } 296 297 // cache certain responses 298 if(in_array($type, ['lang', 'meta'])) 299 { 300 $this->cache[sha1($file)][$type] = $response; 301 } 302 } 303 // request completed successfully but result is empty 393 } // request completed successfully but result is empty 304 394 elseif($status == 204) 305 395 { 306 396 $response = null; 307 } 308 // retry on request failed with error 500 397 } // retry on request failed with error 500 309 398 elseif($status == 500 && $retries[sha1($file)]--) 310 399 { 311 400 $response = $this->request($type, $file); 312 } 313 // other status code is an error 401 } // other status code is an error 314 402 else 315 403 { 316 $this->error($status, $resource );404 $this->error($status, $resource, $file); 317 405 } 318 406 … … 323 411 * Make a request to Apache Tika Server 324 412 * 325 * @param array $options 326 * @return array 327 * @throws \Exception 328 */ 329 protected function exec(array $options = []) 413 * @throws \Exception 414 */ 415 protected function exec(array $options = []): array 330 416 { 331 417 // cURL init and options 332 418 $curl = curl_init(); 333 419 334 // we avoid curl_setopt_array($curl, $options) because extrange Windows behaviour (issue #8)420 // we avoid curl_setopt_array($curl, $options) because strange Windows behaviour (issue #8) 335 421 foreach($options as $option => $value) 336 422 { … … 338 424 } 339 425 340 // make the request 426 // make the request directly 341 427 if(is_null($this->callback)) 342 428 { 343 $this->response = curl_exec($curl) ;344 } 429 $this->response = curl_exec($curl) ?: ''; 430 } // with a callback, the response is appended on each block inside the callback 345 431 else 346 432 { … … 362 448 * Throws an exception for an error status code 363 449 * 364 * @codeCoverageIgnore 365 * 366 * @param int $status 367 * @param string $resource 368 * @throws \Exception 369 */ 370 protected function error($status, $resource) 450 * @throws \Exception 451 */ 452 protected function error(int $status, string $resource, string $file = null): void 371 453 { 372 454 switch($status) … … 374 456 // method not allowed 375 457 case 405: 376 throw new Exception('Method not allowed', 405);458 $message = 'Method not allowed'; 377 459 break; 378 460 379 461 // unsupported media type 380 462 case 415: 381 throw new Exception('Unsupported media type', 415);463 $message = 'Unsupported media type'; 382 464 break; 383 465 384 466 // unprocessable entity 385 467 case 422: 386 throw new Exception('Unprocessable document', 422); 468 $message = 'Unprocessable document'; 469 470 // using remote files require Tika server to be launched with specific options 471 if($this->downloadRemote == false && preg_match('/^http/', $file)) 472 { 473 $message .= ' (is server launched using "-enableUnsecureFeatures -enableFileUrl" arguments?)'; 474 } 475 387 476 break; 388 477 389 478 // server error 390 479 case 500: 391 throw new Exception('Error while processing document', 500);480 $message = 'Error while processing document'; 392 481 break; 393 482 394 483 // unexpected 395 484 default: 396 throw new Exception("Unexpected response for /$resource ($status)", 501); 397 } 485 $message = "Unexpected response for /$resource ($status)"; 486 $status = 501; 487 } 488 489 throw new Exception($message, $status); 398 490 } 399 491 … … 401 493 * Get the parameters to make the request 402 494 * 403 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 404 * @param string $type 405 * @param string file 406 * @return array 407 * @throws \Exception 408 */ 409 protected function getParameters($type, $file = null) 495 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 496 * @throws \Exception 497 */ 498 protected function getParameters(string $type, string $file = null): array 410 499 { 411 500 $headers = []; 501 $callback = null; 412 502 413 503 if(!empty($file) && preg_match('/^http/', $file)) … … 433 523 break; 434 524 525 case 'detectors': 526 case 'parsers': 435 527 case 'meta': 436 $resource = 'meta'; 528 case 'mime-types': 529 case 'rmeta/html': 530 case 'rmeta/ignore': 531 case 'rmeta/text': 532 $resource = $type; 437 533 $headers[] = 'Accept: application/json'; 534 $callback = function($response) 535 { 536 return json_decode($response, true); 537 }; 438 538 break; 439 539 … … 448 548 break; 449 549 450 case 'detectors':451 case 'parsers':452 case 'mime-types':453 550 case 'version': 454 551 $resource = $type; 455 552 break; 456 553 554 case 'xhtml': 555 throw new Exception("Tika Server does not support XHTML output"); 556 break; 557 457 558 default: 458 559 throw new Exception("Unknown type $type"); 459 560 } 460 561 461 return [$resource, $headers ];562 return [$resource, $headers, $callback]; 462 563 } 463 564 … … 465 566 * Get the cURL options 466 567 * 467 * @param string $type 468 * @param string file 469 * @return array 470 * @throws \Exception 471 */ 472 protected function getCurlOptions($type, $file = null) 568 * @throws \Exception 569 */ 570 protected function getCurlOptions(string $type, string $file = null): array 473 571 { 474 572 // base options … … 480 578 $callback = $this->callback; 481 579 482 $options[CURLOPT_WRITEFUNCTION] = function($handler, $data) use ($callback)580 $options[CURLOPT_WRITEFUNCTION] = function($handler, $data) use ($callback) 483 581 { 484 $this->response .= $data; 582 if($this->callbackAppend === true) 583 { 584 $this->response .= $data; 585 } 485 586 486 587 $callback($data); … … 495 596 { 496 597 // 497 } 498 // local file options 598 } // local file options 499 599 elseif($file && file_exists($file) && is_readable($file)) 500 600 { 501 601 $options[CURLOPT_INFILE] = fopen($file, 'r'); 502 602 $options[CURLOPT_INFILESIZE] = filesize($file); 503 } 504 // other options for specific requests 505 elseif(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) 603 } // other options for specific requests 604 elseif(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) 506 605 { 507 606 $options[CURLOPT_PUT] = false; 508 } 509 // file not accesible 607 } // file not accesible 510 608 else 511 609 { -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/tests/BaseTest.php
r2002534 r2525480 3 3 namespace Vaites\ApacheTika\Tests; 4 4 5 use PHPUnit_Framework_TestCase; 5 use Exception; 6 7 use PHPUnit\Framework\TestCase; 6 8 7 9 /** 8 10 * Common test functionality 9 11 */ 10 abstract class BaseTest extends PHPUnit_Framework_TestCase12 abstract class BaseTest extends TestCase 11 13 { 12 14 /** … … 40 42 /** 41 43 * Get env variables 42 * 43 * @param null $name 44 * @param array $data 45 * @param string $dataName 46 */ 47 public function __construct($name = null, array $data = array(), $dataName = '') 44 * 45 * @throws \Exception 46 */ 47 public function __construct(string $name = null, array $data = array(), $dataName = '') 48 48 { 49 49 self::$version = getenv('APACHE_TIKA_VERSION'); 50 50 self::$binaries = getenv('APACHE_TIKA_BINARIES'); 51 51 52 if(empty(self::$version)) 53 { 54 throw new Exception('APACHE_TIKA_VERSION environment variable not defined'); 55 } 56 52 57 parent::__construct($name, $data, $dataName); 53 58 } … … 56 61 * Version test 57 62 */ 58 public function testVersion() 63 public function testVersion(): void 59 64 { 60 65 $this->assertEquals('Apache Tika ' . self::$version, self::$client->getVersion()); … … 64 69 * Metadata test 65 70 * 66 * @dataProvider documentProvider 67 * 68 * @param string $file 69 * @param string $class 70 * @throws \Exception 71 */ 72 public function testMetadata($file, $class = 'Metadata') 71 * @dataProvider documentProvider 72 */ 73 public function testMetadata(string $file, string $class = 'Metadata'): void 74 { 75 $this->assertInstanceOf("\\Vaites\\ApacheTika\\Metadata\\$class", self::$client->getMetadata($file)); 76 } 77 78 /** 79 * Metadata test 80 * 81 * @dataProvider documentProvider 82 */ 83 public function testDocumentMetadata(string $file, string $class = 'DocumentMetadata'): void 84 { 85 $this->testMetadata($file, $class); 86 } 87 88 /** 89 * Metadata title test 90 * 91 * @dataProvider documentProvider 92 */ 93 public function testDocumentMetadataTitle(string $file): void 94 { 95 $this->assertEquals('Lorem ipsum dolor sit amet', self::$client->getMetadata($file)->title); 96 } 97 98 /** 99 * Metadata author test 100 * 101 * @dataProvider documentProvider 102 */ 103 public function testDocumentMetadataAuthor(string $file): void 104 { 105 $this->assertEquals('David Martínez', self::$client->getMetadata($file)->author); 106 } 107 108 /** 109 * Metadata dates test 110 * 111 * @dataProvider documentProvider 112 */ 113 public function testDocumentMetadataCreated(string $file): void 114 { 115 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->created); 116 } 117 118 /** 119 * Metadata dates test 120 * 121 * @dataProvider documentProvider 122 */ 123 public function testDocumentMetadataUpdated(string $file): void 124 { 125 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->updated); 126 } 127 128 /** 129 * Metadata keywords test 130 * 131 * @dataProvider documentProvider 132 */ 133 public function testDocumentMetadataKeywords(string $file): void 134 { 135 $this->assertContains('ipsum', self::$client->getMetadata($file)->keywords); 136 } 137 138 /** 139 * Recursive text metadata test 140 * 141 * @dataProvider recursiveProvider 142 */ 143 public function testTextRecursiveMetadata(string $file): void 144 { 145 $nested = 'sample8.zip/sample1.doc'; 146 147 $metadata = self::$client->getRecursiveMetadata($file, 'text'); 148 149 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', $metadata[$nested]->content ?? 'ERROR'); 150 } 151 152 /** 153 * Recursive HTML metadata test 154 * 155 * @dataProvider recursiveProvider 156 */ 157 public function testHtmlRecursiveMetadata(string $file): void 158 { 159 $nested = 'sample8.zip/sample1.doc'; 160 161 $metadata = self::$client->getRecursiveMetadata($file, 'html'); 162 163 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', $metadata[$nested]->content ?? 'ERROR'); 164 } 165 166 /** 167 * Recursive ignore metadata test 168 * 169 * @dataProvider ocrProvider 170 */ 171 public function testIgnoreRecursiveMetadata(string $file): void 172 { 173 $metadata = self::$client->getRecursiveMetadata($file, 'ignore'); 174 175 $this->assertNull(array_shift($metadata)->content); 176 } 177 178 /** 179 * Language test 180 * 181 * @dataProvider documentProvider 182 */ 183 public function testDocumentLanguage(string $file): void 184 { 185 $this->assertRegExp('/^[a-z]{2}$/', self::$client->getLanguage($file)); 186 } 187 188 /** 189 * MIME test 190 * 191 * @dataProvider documentProvider 192 */ 193 public function testDocumentMIME(string $file): void 194 { 195 $this->assertNotEmpty(self::$client->getMIME($file)); 196 } 197 198 /** 199 * HTML test 200 * 201 * @dataProvider documentProvider 202 */ 203 public function testDocumentHTML(string $file): void 204 { 205 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', self::$client->getHTML($file)); 206 } 207 208 /** 209 * Text test 210 * 211 * @dataProvider documentProvider 212 */ 213 public function testDocumentText(string $file): void 214 { 215 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', self::$client->getText($file)); 216 } 217 218 /** 219 * Main text test 220 * 221 * @dataProvider documentProvider 222 */ 223 public function testDocumentMainText(string $file): void 224 { 225 $this->assertStringContainsString('Lorem ipsum dolor sit amet', self::$client->getMainText($file)); 226 } 227 228 /** 229 * Metadata test 230 * 231 * @dataProvider imageProvider 232 */ 233 public function testImageMetadata(string $file, string $class = 'ImageMetadata'): void 234 { 235 $this->testMetadata($file, $class); 236 } 237 238 /** 239 * Metadata width test 240 * 241 * @dataProvider imageProvider 242 */ 243 public function testImageMetadataWidth(string $file): void 244 { 245 $meta = self::$client->getMetadata($file); 246 247 $this->assertEquals(1600, $meta->width, basename($file)); 248 } 249 250 /** 251 * Metadata height test 252 * 253 * @dataProvider imageProvider 254 */ 255 public function testImageMetadataHeight(string $file): void 256 { 257 $meta = self::$client->getMetadata($file); 258 259 $this->assertEquals(900, $meta->height, basename($file)); 260 } 261 262 /** 263 * OCR test 264 * 265 * @dataProvider ocrProvider 266 */ 267 public function testImageOCR(string $file): void 268 { 269 $text = self::$client->getText($file); 270 271 $this->assertRegExp('/voluptate/i', $text); 272 } 273 274 /** 275 * Text callback test 276 * 277 * @dataProvider callbackProvider 278 */ 279 public function testTextCallback(string $file): void 280 { 281 BaseTest::$shared = 0; 282 283 self::$client->getText($file, [$this, 'callableCallback']); 284 285 $this->assertGreaterThan(1, BaseTest::$shared); 286 } 287 288 /** 289 * Text callback test 290 * 291 * @dataProvider callbackProvider 292 */ 293 public function testTextCallbackWithoutAppend(string $file): void 294 { 295 BaseTest::$shared = 0; 296 297 $response = self::$client->getText($file, [$this, 'callableCallback'], false); 298 299 $this->assertEmpty($response); 300 } 301 302 /** 303 * Main text callback test 304 * 305 * @dataProvider callbackProvider 306 */ 307 public function testMainTextCallback(string $file): void 308 { 309 BaseTest::$shared = 0; 310 311 self::$client->getMainText($file, function() 312 { 313 BaseTest::$shared++; 314 }); 315 316 $this->assertGreaterThan(1, BaseTest::$shared); 317 } 318 319 /** 320 * Main text callback test 321 * 322 * @dataProvider callbackProvider 323 */ 324 public function testHtmlCallback(string $file): void 325 { 326 BaseTest::$shared = 0; 327 328 self::$client->getHtml($file, function() 329 { 330 BaseTest::$shared++; 331 }); 332 333 $this->assertGreaterThan(1, BaseTest::$shared); 334 } 335 336 /** 337 * Remote file test with integrated download 338 * 339 * @dataProvider remoteProvider 340 */ 341 public function testRemoteDocumentText(string $file): void 342 { 343 $this->assertStringContainsString('Rationis enim perfectio est virtus', self::$client->getText($file)); 344 } 345 346 /** 347 * Remote file test with internal downloader 348 * 349 * @dataProvider remoteProvider 350 */ 351 public function testDirectRemoteDocumentText(string $file): void 73 352 { 74 353 $client =& self::$client; 75 354 76 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 77 { 78 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 79 } 80 else 81 { 82 $this->assertInstanceOf("\\Vaites\\ApacheTika\\Metadata\\$class", self::$client->getMetadata($file)); 83 } 84 } 85 86 /** 87 * Metadata test 88 * 89 * @dataProvider documentProvider 90 * 91 * @param string $file 92 * @param string $class 93 * @throws \Exception 94 */ 95 public function testDocumentMetadata($file, $class = 'DocumentMetadata') 355 $client->setDownloadRemote(false); 356 357 $this->assertStringContainsString('Rationis enim perfectio est virtus', $client->getText($file)); 358 } 359 360 /** 361 * Encoding tests 362 * 363 * @dataProvider encodingProvider 364 */ 365 public function testEncodingDocumentText(string $file): void 96 366 { 97 367 $client =& self::$client; 98 368 99 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 100 { 101 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 102 } 103 else 104 { 105 $this->testMetadata($file, $class); 106 } 107 } 108 109 /** 110 * Metadata title test 111 * 112 * @dataProvider documentProvider 113 * 114 * @param string $file 115 * @throws \Exception 116 */ 117 public function testDocumentMetadataTitle($file) 118 { 119 $client =& self::$client; 120 121 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 122 { 123 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 124 } 125 else 126 { 127 $this->assertEquals('Lorem ipsum dolor sit amet', self::$client->getMetadata($file)->title); 128 } 129 } 130 131 /** 132 * Metadata author test 133 * 134 * @dataProvider documentProvider 135 * 136 * @param string $file 137 * @throws \Exception 138 */ 139 public function testDocumentMetadataAuthor($file) 140 { 141 $client =& self::$client; 142 143 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 144 { 145 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 146 } 147 else 148 { 149 $this->assertEquals('David Martínez', self::$client->getMetadata($file)->author); 150 } 151 } 152 153 /** 154 * Metadata dates test 155 * 156 * @dataProvider documentProvider 157 * 158 * @param string $file 159 * @throws \Exception 160 */ 161 public function testDocumentMetadataCreated($file) 162 { 163 $client =& self::$client; 164 165 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 166 { 167 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 168 } 169 else 170 { 171 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->created); 172 } 173 } 174 175 /** 176 * Metadata dates test 177 * 178 * @dataProvider documentProvider 179 * 180 * @param string $file 181 * @throws \Exception 182 */ 183 public function testDocumentMetadataUpdated($file) 184 { 185 $client =& self::$client; 186 187 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 188 { 189 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 190 } 191 else 192 { 193 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->updated); 194 } 195 } 196 197 /** 198 * Metadata keywords test 199 * 200 * @dataProvider documentProvider 201 * 202 * @param string $file 203 * @throws \Exception 204 */ 205 public function testDocumentMetadataKeywords($file) 206 { 207 $client =& self::$client; 208 209 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 210 { 211 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 212 } 213 else 214 { 215 $this->assertContains('ipsum', self::$client->getMetadata($file)->keywords); 216 } 217 } 218 219 /** 220 * Language test 221 * 222 * @dataProvider documentProvider 223 * 224 * @param string $file 225 * @throws \Exception 226 */ 227 public function testDocumentLanguage($file) 228 { 229 $client =& self::$client; 230 231 if($client::MODE == 'web' && version_compare(self::$version, '1.9') < 0) 232 { 233 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks REST language identification'); 234 } 235 else 236 { 237 $this->assertRegExp('/^[a-z]{2}$/', self::$client->getLanguage($file)); 238 } 239 } 240 241 /** 242 * MIME test 243 * 244 * @dataProvider documentProvider 245 * 246 * @param string $file 247 * @throws \Exception 248 */ 249 public function testDocumentMIME($file) 250 { 251 $client =& self::$client; 252 253 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 254 { 255 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 256 } 257 else 258 { 259 $this->assertNotEmpty(self::$client->getMIME($file)); 260 } 261 } 262 263 /** 264 * HTML test 265 * 266 * @dataProvider documentProvider 267 * 268 * @param string $file 269 * @throws \Exception 270 */ 271 public function testDocumentHTML($file) 272 { 273 $client =& self::$client; 274 275 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 276 { 277 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 278 } 279 else 280 { 281 $this->assertContains('Zenonis est, inquam, hoc Stoici', self::$client->getHTML($file)); 282 } 283 } 284 285 /** 286 * Text test 287 * 288 * @dataProvider documentProvider 289 * 290 * @param string $file 291 * @throws \Exception 292 */ 293 public function testDocumentText($file) 294 { 295 $client =& self::$client; 296 297 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 298 { 299 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 300 } 301 else 302 { 303 $this->assertContains('Zenonis est, inquam, hoc Stoici', self::$client->getText($file)); 304 } 305 } 306 307 /** 308 * Main text test 309 * 310 * @dataProvider documentProvider 311 * 312 * @param string $file 313 * @throws \Exception 314 */ 315 public function testDocumentMainText($file) 316 { 317 $client =& self::$client; 318 319 if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 320 { 321 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction'); 322 } 323 else 324 { 325 $this->assertContains('Lorem ipsum dolor sit amet', self::$client->getMainText($file)); 326 } 327 } 328 329 /** 330 * Metadata test 331 * 332 * @dataProvider imageProvider 333 * 334 * @param string $file 335 * @param string $class 336 * @throws \Exception 337 */ 338 public function testImageMetadata($file, $class = 'ImageMetadata') 339 { 340 $client =& self::$client; 341 342 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 343 { 344 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 345 } 346 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 347 { 348 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 349 } 350 else 351 { 352 $this->testMetadata($file, $class); 353 } 354 } 355 356 /** 357 * Metadata width test 358 * 359 * @dataProvider imageProvider 360 * 361 * @param string $file 362 * @throws \Exception 363 */ 364 public function testImageMetadataWidth($file) 365 { 366 $client =& self::$client; 367 368 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 369 { 370 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 371 } 372 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 373 { 374 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 375 } 376 else 377 { 378 $meta = self::$client->getMetadata($file); 379 380 $this->assertEquals(1600, $meta->width, basename($file)); 381 } 382 } 383 384 /** 385 * Metadata height test 386 * 387 * @dataProvider imageProvider 388 * 389 * @param string $file 390 * @throws \Exception 391 */ 392 public function testImageMetadataHeight($file) 393 { 394 $client =& self::$client; 395 396 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 397 { 398 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 399 } 400 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 401 { 402 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 403 } 404 else 405 { 406 $meta = self::$client->getMetadata($file); 407 408 $this->assertEquals(900, $meta->height, basename($file)); 409 } 410 } 411 412 /** 413 * OCR test 414 * 415 * @dataProvider ocrProvider 416 * 417 * @param string $file 418 * @throws \Exception 419 */ 420 public function testImageOCR($file) 421 { 422 $client =& self::$client; 423 424 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 425 { 426 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 427 } 428 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 429 { 430 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 431 } 432 else 433 { 434 $text = self::$client->getText($file); 435 436 $this->assertRegExp('/voluptate/i', $text); 437 } 438 } 439 440 /** 441 * Text callback test 442 * 443 * @dataProvider callbackProvider 444 * 445 * @param string $file 446 * @throws \Exception 447 */ 448 public function testTextCallback($file) 449 { 450 $client =& self::$client; 451 452 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 453 { 454 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 455 } 456 else 457 { 458 BaseTest::$shared = 0; 459 460 self::$client->getText($file, [$this, 'callableCallback']); 461 462 $this->assertGreaterThan(1, BaseTest::$shared); 463 } 464 } 465 466 /** 467 * Main text callback test 468 * 469 * @dataProvider callbackProvider 470 * 471 * @param string $file 472 * @throws \Exception 473 */ 474 public function testMainTextCallback($file) 475 { 476 $client =& self::$client; 477 478 if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 479 { 480 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction'); 481 } 482 else 483 { 484 BaseTest::$shared = 0; 485 486 self::$client->getMainText($file, function ($chunk) { 487 BaseTest::$shared++; 488 }); 489 490 $this->assertGreaterThan(1, BaseTest::$shared); 491 } 492 } 493 494 /** 495 * Main text callback test 496 * 497 * @dataProvider callbackProvider 498 * 499 * @param string $file 500 * @throws \Exception 501 */ 502 public function testHtmlCallback($file) 503 { 504 $client =& self::$client; 505 506 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 507 { 508 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 509 } 510 else 511 { 512 BaseTest::$shared = 0; 513 514 self::$client->getHtml($file, function($chunk) 515 { 516 BaseTest::$shared++; 517 }); 518 519 $this->assertGreaterThan(1, BaseTest::$shared); 520 } 521 } 522 523 /** 524 * Remote file test with integrated download 525 * 526 * @dataProvider remoteProvider 527 * 528 * @param string $file 529 * @throws \Exception 530 */ 531 public function testRemoteDocumentText($file) 532 { 533 $client =& self::$client; 534 535 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 536 { 537 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 538 } 539 else 540 { 541 $this->assertContains('This is a small demonstration .pdf file', $client->getText($file)); 542 } 543 } 544 545 /** 546 * Remote file test with internal downloader 547 * 548 * @dataProvider remoteProvider 549 * 550 * @param string $file 551 * @throws \Exception 552 */ 553 public function testDirectRemoteDocumentText($file) 554 { 555 $client =& self::$client; 556 557 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 558 { 559 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 560 } 561 elseif($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 562 { 563 $this->markTestSkipped('Apache Tika between 1.10 and 1.14 doesn\'t supports unsecure features'); 564 } 565 else 566 { 567 $client->setDownloadRemote(false); 568 569 $this->assertContains('This is a small demonstration .pdf file', $client->getText($file)); 570 } 369 $client->setEncoding('UTF-8'); 370 371 $this->assertThat($client->getText($file), $this->logicalAnd 372 ( 373 $this->stringContains('L’espéranto'), 374 $this->stringContains('世界語'), 375 $this->stringContains('Эспера́нто') 376 )); 571 377 } 572 378 573 379 /** 574 380 * Test available detectors 575 * 576 * @throws \Exception577 */578 public function testAvailableDetectors()579 { 580 $this->assert Contains('org.apache.tika.mime.MimeTypes', self::$client->getAvailableDetectors());381 */ 382 public function testAvailableDetectors(): void 383 { 384 $detectors = self::$client->getAvailableDetectors(); 385 386 $this->assertArrayHasKey('org.apache.tika.detect.DefaultDetector', $detectors); 581 387 } 582 388 583 389 /** 584 390 * Test available parsers 585 * 586 * @throws \Exception587 */588 public function testAvailableParsers()589 { 590 $this->assert Contains('org.apache.tika.parser.DefaultParser', self::$client->getAvailableParsers());391 */ 392 public function testAvailableParsers(): void 393 { 394 $parsers = self::$client->getAvailableParsers(); 395 396 $this->assertArrayHasKey('org.apache.tika.parser.DefaultParser', $parsers); 591 397 } 592 398 593 399 /** 594 400 * Test supported MIME types 595 * 596 * @throws \Exception 597 */ 598 public function testSupportedMIMETypes() 599 { 600 $this->assertContains('application/x-pdf', self::$client->getSupportedMIMETypes()); 401 */ 402 public function testSupportedMIMETypes(): void 403 { 404 $this->assertArrayHasKey('application/pdf', self::$client->getSupportedMIMETypes()); 405 } 406 407 408 /** 409 * Test supported MIME types 410 */ 411 public function testIsMIMETypeSupported(): void 412 { 413 $this->assertTrue(self::$client->isMIMETypeSupported('application/pdf')); 601 414 } 602 415 603 416 /** 604 417 * Static method to test callback 605 * 606 * @param string $chunk 607 */ 608 public static function callableCallback($chunk) 418 */ 419 public static function callableCallback(): void 609 420 { 610 421 BaseTest::$shared++; … … 613 424 /** 614 425 * Document file provider 615 * 616 * @return array 617 */ 618 public function documentProvider() 426 */ 427 public function documentProvider(): array 619 428 { 620 429 return $this->samples('sample1'); … … 623 432 /** 624 433 * Image file provider 625 * 626 * @return array 627 */ 628 public function imageProvider() 434 */ 435 public function imageProvider(): array 629 436 { 630 437 return $this->samples('sample2'); … … 633 440 /** 634 441 * File provider for OCR testing 635 * 636 * @return array 637 */ 638 public function ocrProvider() 442 */ 443 public function ocrProvider(): array 639 444 { 640 445 return $this->samples('sample3'); … … 643 448 /** 644 449 * File provider for callback testing 645 * 646 * @return array 647 */ 648 public function callbackProvider() 450 */ 451 public function callbackProvider(): array 649 452 { 650 453 return $this->samples('sample5'); … … 653 456 /** 654 457 * File provider for remote testing 655 * 656 * @return array 657 */ 658 public function remoteProvider() 458 */ 459 public function remoteProvider(): array 659 460 { 660 461 return 661 462 [ 662 463 [ 663 'http ://www.africau.edu/images/default/sample.pdf'464 'https://raw.githubusercontent.com/vaites/php-apache-tika/master/samples/sample6.pdf' 664 465 ] 665 466 ]; … … 667 468 668 469 /** 470 * File provider for encoding testing 471 */ 472 public function encodingProvider(): array 473 { 474 return $this->samples('sample7'); 475 } 476 477 /** 478 * File provider for recursive testing 479 */ 480 public function recursiveProvider(): array 481 { 482 return $this->samples('sample8'); 483 } 484 485 /** 669 486 * File provider using "samples" folder 670 * 671 * @param string $sample 672 * @return array 673 */ 674 protected function samples($sample) 487 */ 488 protected function samples(string $sample): array 675 489 { 676 490 $samples = []; -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/tests/CLITest.php
r2002534 r2525480 13 13 * Create shared instances of clients 14 14 */ 15 public static function setUpBeforeClass() 15 public static function setUpBeforeClass(): void 16 16 { 17 17 self::$client = Client::make(self::getPathForVersion(self::$version)); … … 19 19 20 20 /** 21 * XHTML test 22 * 23 * @dataProvider encodingProvider 24 */ 25 public function testDocumentHTML(string $file): void 26 { 27 $this->assertStringStartsWith('<?xml version="1.0"', self::$client->getXHTML($file)); 28 } 29 30 /** 21 31 * Set path test 22 32 */ 23 public function testSetPath() 33 public function testSetPath(): void 24 34 { 25 $ client = Client::make(self::getPathForVersion('1.0'));35 $path = self::getPathForVersion(self::$version); 26 36 27 $this->assertEquals(self::getPathForVersion('1.0'), $client->getPath()); 37 $client = Client::make($path); 38 39 $this->assertEquals($path, $client->getPath()); 28 40 } 29 41 … … 31 43 * Set Java test 32 44 */ 33 public function testSet Port()45 public function testSetBinary(): void 34 46 { 35 $ client = Client::make(self::getPathForVersion('1.0'), '/opt/jdk/bin/java');47 $path = self::getPathForVersion(self::$version); 36 48 37 $this->assertEquals('/opt/jdk/bin/java', $client->getJava()); 49 $client = Client::make($path, 'java'); 50 51 $this->assertEquals('java', $client->getJava()); 52 } 53 54 /** 55 * Set Java test 56 */ 57 public function testSetArguments(): void 58 { 59 $path = self::getPathForVersion(self::$version); 60 61 $client = Client::make($path); 62 $client->setJavaArgs('-JXmx4g'); 63 64 $this->assertEquals('-JXmx4g', $client->getJavaArgs()); 65 } 66 67 /** 68 * Test delayed check 69 */ 70 public function testDelayedCheck(): void 71 { 72 $path = self::getPathForVersion(self::$version); 73 74 $client = Client::prepare('/nonexistent/path/to/apache-tika.jar'); 75 $client->setPath($path); 76 77 $this->assertStringEndsWith(self::$version, $client->getVersion()); 38 78 } 39 79 40 80 /** 41 81 * Get the full path of Tika app for a specified version 42 *43 * @param string $version44 * @return string45 82 */ 46 private static function getPathForVersion( $version)83 private static function getPathForVersion(string $version): string 47 84 { 48 85 return self::$binaries . "/tika-app-{$version}.jar"; -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/tests/CommonTest.php
r2002534 r2525480 1 1 <?php namespace Vaites\ApacheTika\Tests; 2 2 3 use PHPUnit _Framework_TestCase;3 use PHPUnit\Framework\TestCase; 4 4 5 5 use Vaites\ApacheTika\Client; … … 8 8 * Common test functionality 9 9 */ 10 class CommonTest extends PHPUnit_Framework_TestCase10 class CommonTest extends TestCase 11 11 { 12 12 /** … … 33 33 /** 34 34 * Get env variables 35 *36 * @param null $name37 * @param array $data38 * @param string $dataName39 * @throws \Exception40 35 */ 41 public function __construct( $name = null, array $data = array(), $dataName = '')36 public function __construct(string $name = null, array $data = array(), $dataName = '') 42 37 { 43 38 self::$version = getenv('APACHE_TIKA_VERSION'); … … 51 46 * Set chunk size test 52 47 */ 53 public function testSetChunkSize() 48 public function testSetChunkSize(): void 54 49 { 55 50 self::$client->setChunkSize(42); … … 59 54 60 55 /** 56 * Set download remote 57 */ 58 public function testDownloadRemote(): void 59 { 60 self::$client->setDownloadRemote(true); 61 62 $this->assertTrue(self::$client->getDownloadRemote()); 63 } 64 65 /** 61 66 * Set callback (closure) test 62 67 */ 63 public function testSetClosureCallback() 68 public function testSetClosureCallback(): void 64 69 { 65 70 self::$client->setCallback(function($chunk) … … 74 79 * Set callback (callable) test 75 80 */ 76 public function testSetCallableCallback() 81 public function testSetCallableCallback(): void 77 82 { 78 83 self::$client->setCallback('trim'); … … 84 89 * Get supported versions test 85 90 */ 86 public function testGetSupportedVersions() 91 public function testGetSupportedVersions(): void 87 92 { 88 $this->assertTrue(in_array( '1.10', Client::getSupportedVersions()));93 $this->assertTrue(in_array(self::$version, self::$client->getSupportedVersions())); 89 94 } 90 95 … … 92 97 * Is version supported vtest 93 98 */ 94 public function testIsVersionSupported() 99 public function testIsVersionSupported(): void 95 100 { 96 $this->assertTrue( Client::isVersionSupported('1.10'));101 $this->assertTrue(self::$client->isVersionSupported(self::$version)); 97 102 } 98 103 } -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/tests/ErrorTest.php
r2002534 r2525480 2 2 3 3 use Exception; 4 use PHPUnit_Framework_TestCase; 4 5 use PHPUnit\Framework\TestCase; 5 6 6 7 use Vaites\ApacheTika\Client; … … 10 11 * Error tests 11 12 */ 12 class ErrorTest extends PHPUnit_Framework_TestCase13 class ErrorTest extends TestCase 13 14 { 14 15 /** … … 28 29 /** 29 30 * Get env variables 30 * 31 * @param null $name 32 * @param array $data 33 * @param string $dataName 34 */ 35 public function __construct($name = null, array $data = array(), $dataName = '') 31 */ 32 public function __construct(string $name = null, array $data = array(), $dataName = '') 36 33 { 37 34 self::$version = getenv('APACHE_TIKA_VERSION'); … … 44 41 * Test wrong command line mode path 45 42 */ 46 public function testAppPath() 47 { 48 try 49 { 50 $client = Client:: make('/nonexistent/path/to/apache-tika.jar');43 public function testAppPath(): void 44 { 45 try 46 { 47 $client = Client::prepare('/nonexistent/path/to/apache-tika.jar'); 51 48 $client->getVersion(); 52 49 } 53 50 catch(Exception $exception) 54 51 { 55 $this->assert Contains('Unexpected exit value', $exception->getMessage());52 $this->assertStringContainsString('Apache Tika app JAR not found', $exception->getMessage()); 56 53 } 57 54 } … … 60 57 * Test unexpected exit value for command line mode 61 58 */ 62 public function testAppExitValue() 59 public function testAppExitValue(): void 63 60 { 64 61 $path = self::getPathForVersion(self::$version); … … 76 73 rename($path . '.bak', $path); 77 74 78 $this->assert Contains('Unexpected exit value', $exception->getMessage());75 $this->assertStringContainsString('Unexpected exit value', $exception->getMessage()); 79 76 } 80 77 } … … 83 80 * Test invalid Java binary path for command line mode 84 81 */ 85 public function test AppJavaBinary()82 public function testJavaBinary(): void 86 83 { 87 84 $path = self::getPathForVersion(self::$version); … … 94 91 catch(Exception $exception) 95 92 { 96 $this->assert Contains('Unexpected exit value', $exception->getMessage());93 $this->assertStringContainsString('Java command not found', $exception->getMessage()); 97 94 } 98 95 } … … 101 98 * Test wrong server 102 99 */ 103 public function testServerConnection() 104 { 105 try 106 { 107 Client::make('localhost', 9997); 108 109 $this->fail(); 110 } 111 catch(Exception $exception) 112 { 113 $this->assertEquals(7, $exception->getCode()); 100 public function testServerConnection(): void 101 { 102 try 103 { 104 $client = Client::prepare('localhost', 9997); 105 $client->getVersion(); 106 107 $this->fail(); 108 } 109 catch(Exception $exception) 110 { 111 $this->assertThat($exception->getCode(), $this->logicalOr 112 ( 113 $this->equalTo(CURLE_COULDNT_CONNECT), 114 $this->equalTo(CURLE_OPERATION_TIMEDOUT) 115 )); 114 116 } 115 117 } … … 118 120 * Test wrong request options 119 121 */ 120 public function testRequestOptions() 121 { 122 try 123 { 124 $client = Client::make('localhost', 9998 , [CURLOPT_PROXY => 'localhost']);122 public function testRequestOptions(): void 123 { 124 try 125 { 126 $client = Client::make('localhost', 9998); 125 127 $client->request('bad'); 126 128 … … 129 131 catch(Exception $exception) 130 132 { 131 $this->assert Equals(7, $exception->getCode());133 $this->assertStringContainsString('Unknown type bad', $exception->getMessage()); 132 134 } 133 135 } … … 136 138 * Test invalidrequest options 137 139 */ 138 public function testRequestRestrictedOptions() 139 { 140 try 141 { 142 $client =Client::make('localhost', 9998, [CURLOPT_PUT => false]);140 public function testRequestRestrictedOptions(): void 141 { 142 try 143 { 144 Client::make('localhost', 9998, [CURLOPT_PUT => false]); 143 145 } 144 146 catch(Exception $exception) … … 149 151 150 152 /** 153 * Test wrong recursive metadata type 154 */ 155 public function testRequestMetadataType(): void 156 { 157 try 158 { 159 $client = Client::make('localhost', 9998); 160 $client->getRecursiveMetadata(dirname(__DIR__) . '/samples/sample3.png', 'bad'); 161 162 $this->fail(); 163 } 164 catch(Exception $exception) 165 { 166 $this->assertStringContainsString('Unknown recursive type', $exception->getMessage()); 167 } 168 } 169 170 /** 151 171 * Test unsupported media type 152 */ 153 public function testUnsupportedMedia() 172 * 173 * NOTE: return value was changed in version 1.23 174 * 175 * @link https://github.com/apache/tika/blob/master/CHANGES.txt 176 */ 177 public function testUnsupportedMedia(): void 154 178 { 155 179 try … … 162 186 catch(Exception $exception) 163 187 { 164 $this->assertEquals(415, $exception->getCode()); 165 } 166 } 167 168 /** 169 * Test invalid callback 170 */ 171 public function testInvalidCallback() 172 { 173 try 174 { 175 $client = Client::make(self::$binaries . '/tika-app-' . self::$version . '.jar'); 176 $client->setCallback('unknown_function'); 177 } 178 catch(Exception $exception) 179 { 180 $this->assertContains('Invalid callback', $exception->getMessage()); 188 if(version_compare(self::$version, '1.23') < 0) 189 { 190 $this->assertEquals(415, $exception->getCode()); 191 } 192 else 193 { 194 $this->assertEquals(0, $exception->getCode()); 195 } 196 } 197 } 198 199 /** 200 * Test unknown recursive metadata type 201 */ 202 public function testUnknownRecursiveMetadataType(): void 203 { 204 try 205 { 206 $client = Client::make('localhost', 9998); 207 $client->getRecursiveMetadata('example.doc', 'error'); 208 209 $this->fail(); 210 } 211 catch(Exception $exception) 212 { 213 $this->assertStringContainsString('Unknown recursive type', $exception->getMessage()); 181 214 } 182 215 } … … 185 218 * Test invalid chunk size 186 219 */ 187 public function testInvalidChunkSize() 188 { 189 try 190 { 191 $client = Client::make(self::$binaries . '/tika-app-' . self::$version . '.jar'); 192 $client->setChunkSize('string'); 193 } 194 catch(Exception $exception) 195 { 196 $this->assertContains('is not a valid chunk size', $exception->getMessage()); 197 } 198 } 199 200 /** 201 * Test invalid chunk size 202 */ 203 public function testUnsupportedChunkSize() 220 public function testUnsupportedChunkSize(): void 204 221 { 205 222 try … … 210 227 catch(Exception $exception) 211 228 { 212 $this->assertContains('Chunk size is not supported', $exception->getMessage()); 213 } 214 } 215 216 /** 217 * Test invalid metadata 218 */ 219 public function testInvalidMetadata() 220 { 221 try 222 { 223 $metadata = Metadata::make('InvalidJsonString', './samples/sample1.doc'); 224 } 225 catch(Exception $exception) 226 { 227 $this->assertEquals(JSON_ERROR_SYNTAX, $exception->getCode()); 228 } 229 } 230 231 /** 232 * Test empty metadata 233 */ 234 public function testEmptyMetadata() 235 { 236 try 237 { 238 $metadata = Metadata::make('', './samples/sample1.doc'); 239 } 240 catch(Exception $exception) 241 { 242 $this->assertContains('Empty response', $exception->getMessage()); 229 $this->assertStringContainsString('Chunk size is not supported', $exception->getMessage()); 243 230 } 244 231 } … … 248 235 * 249 236 * @dataProvider parameterProvider 250 * 251 * @param array $parameters 252 */ 253 public function testRequestType($parameters) 237 */ 238 public function testRequestType(array $parameters): void 254 239 { 255 240 try … … 262 247 catch(Exception $exception) 263 248 { 264 $this->assert Contains('Unknown type bad', $exception->getMessage());249 $this->assertStringContainsString('Unknown type bad', $exception->getMessage()); 265 250 } 266 251 } … … 270 255 * 271 256 * @dataProvider parameterProvider 272 * 273 * @param array $parameters 274 */ 275 public function testLocalFile($parameters) 257 */ 258 public function testLocalFile(array $parameters): void 276 259 { 277 260 try … … 292 275 * 293 276 * @dataProvider parameterProvider 294 * 295 * @param array $parameters 296 */ 297 public function testRemoteFile($parameters) 277 */ 278 public function testRemoteFile(array $parameters): void 298 279 { 299 280 try … … 312 293 /** 313 294 * Client parameters provider 314 * 315 * @return array 316 */ 317 public function parameterProvider() 295 */ 296 public function parameterProvider(): array 318 297 { 319 298 return … … 326 305 /** 327 306 * Get the full path of Tika app for a specified version 328 * 329 * @param string $version 330 * @return string 331 */ 332 private static function getPathForVersion($version) 307 */ 308 private static function getPathForVersion(string $version): string 333 309 { 334 310 return self::$binaries . "/tika-app-{$version}.jar"; -
redisearch/tags/0.3.3/vendor/vaites/php-apache-tika/tests/WebTest.php
r2002534 r2525480 15 15 * Start Tika server and create shared instance of clients 16 16 */ 17 public static function setUpBeforeClass() 17 public static function setUpBeforeClass(): void 18 18 { 19 19 self::$client = Client::make('localhost', 9998, [CURLOPT_TIMEOUT => 30]); … … 23 23 * cURL multiple options test 24 24 */ 25 public function testCurlOptions() 25 public function testCurlOptions(): void 26 26 { 27 27 $client = Client::make('localhost', 9998, [CURLOPT_TIMEOUT => 3]); … … 34 34 * cURL single option test 35 35 */ 36 public function testCurlSingleOption() 36 public function testCurlSingleOption(): void 37 37 { 38 38 $client = Client::make('localhost', 9998)->setOption(CURLOPT_TIMEOUT, 3); … … 44 44 * cURL timeout option test 45 45 */ 46 public function testCurlTimeoutOption() 46 public function testCurlTimeoutOption(): void 47 47 { 48 48 $client = Client::make('localhost', 9998)->setTimeout(3); … … 54 54 * cURL headers test 55 55 */ 56 public function testCurlHeaders() 56 public function testCurlHeaders(): void 57 57 { 58 58 $header = 'Content-Type: image/jpeg'; … … 67 67 * Set host test 68 68 */ 69 public function testSetHost() 69 public function testSetHost(): void 70 70 { 71 71 $client = Client::make('localhost', 9998); … … 78 78 * Set port test 79 79 */ 80 public function testSetPort() 80 public function testSetPort(): void 81 81 { 82 82 $client = Client::make('localhost', 9998); … … 87 87 88 88 /** 89 * Set url host test 90 */ 91 public function testSetUrlHost(): void 92 { 93 $client = Client::make('http://localhost:9998'); 94 95 $this->assertEquals('localhost', $client->getHost()); 96 } 97 98 /** 99 * Set url port test 100 */ 101 public function testSetUrlPort(): void 102 { 103 $client = Client::make('http://localhost:9998'); 104 105 $this->assertEquals(9998, $client->getPort()); 106 } 107 108 /** 89 109 * Set retries test 90 110 */ 91 public function test RetriesPort()111 public function testSetRetries(): void 92 112 { 93 113 $client = Client::make('localhost', 9998); … … 96 116 $this->assertEquals(5, $client->getRetries()); 97 117 } 118 119 /** 120 * Test delayed check 121 */ 122 public function testDelayedCheck(): void 123 { 124 $client = Client::prepare('localhost', 9997); 125 $client->setPort(9998); 126 127 $this->assertStringEndsWith(self::$version, $client->getVersion()); 128 } 98 129 } -
redisearch/tags/0.3.3/wp-redisearch.php
r2455651 r2525480 2 2 /* 3 3 Plugin Name: RediSearch 4 Version: 0.3. 24 Version: 0.3.3 5 5 Description: Replace Wordpress search by RediSearch. 6 6 Author: Foad Yousefi … … 29 29 // Plugin version . 30 30 if ( ! defined( 'WPRS_VERSION' ) ) { 31 define( 'WPRS_VERSION', '0.3. 2' );31 define( 'WPRS_VERSION', '0.3.3' ); 32 32 } 33 33 -
redisearch/trunk/README.md
r2455651 r2525480 53 53 54 54 ### Changelog 55 56 ##### 0.3.3 57 * **Added**: Ability to connect via UNIX sockets 58 55 59 56 60 ##### 0.3.2 -
redisearch/trunk/readme.txt
r2455651 r2525480 6 6 Tags: search, redisearch, redis, fuzzy, aggregation, searching, autosuggest, suggest, advanced search, woocommerce 7 7 Requires at least: 5.0 8 Tested up to: 5. 69 Stable tag: 0.3. 28 Tested up to: 5.7 9 Stable tag: 0.3.3 10 10 Requires PHP: 7.2 11 11 License: GPLv2 or later … … 66 66 67 67 == Changelog == 68 69 = 0.3.3 = 70 * Added: Ability to connect via UNIX sockets 68 71 69 72 = 0.3.2 = -
redisearch/trunk/src/Admin/Admin.php
r2455651 r2525480 151 151 public static function RedisServerConf() { 152 152 Fields::add( 'header', null, __( 'Redis server configurations', 'wp-redisearch' ) ); 153 Fields::add( 'text', 'wp_redisearch_server', __( 'Redis server', 'wp-redisearch' ), __( 'Redis server url, usually it is 127.0.0.1', 'wp-redisearch' ) ); 153 Fields::add( 'select', 'wp_redisearch_connection_scheme', __( 'Server communication scheme', 'wp-redisearch' ), __( 'Choose Redis server communication scheme.', 'wp-redisearch'), array('tcp' => 'TCP', 'unix' => 'UNIX') ); 154 Fields::add( 'text', 'wp_redisearch_server', __( 'Redis server/path', 'wp-redisearch' ), __( 'Redis server url, usually it is 127.0.0.1 and in case of using UNIX socket, the socket path.', 'wp-redisearch' ) ); 154 155 Fields::add( 'text', 'wp_redisearch_port', __( 'Redis port', 'wp-redisearch' ), __( 'Redis port number, by default it is 6379', 'wp-redisearch' ) ); 155 156 Fields::add( 'password', 'wp_redisearch_password', __( 'Redis server password', 'wp-redisearch' ), __( 'If your redis server is not password protected, leave this field blank', 'wp-redisearch' ) ); -
redisearch/trunk/src/RediSearch/Client.php
r2452159 r2525480 19 19 Settings::RedisPort(), 20 20 Settings::RedisPassword(), 21 0 21 0, 22 Settings::RedisScheme() 22 23 ); 23 24 } -
redisearch/trunk/src/RedisRaw/PredisAdapter.php
r2452159 r2525480 17 17 public $redis; 18 18 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null): RedisRawClientInterface { 20 $this->redis = new Client([ 21 'scheme' => 'tcp', 22 'host' => $hostname, 23 'port' => $port, 24 'database' => $db, 25 'password' => $password, 26 ]); 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null, $scheme = 'tcp'): RedisRawClientInterface { 20 $clientArgs = array(); 21 if ( $scheme === 'tcp' ) { 22 $clientArgs = array( 23 'scheme' => 'tcp', 24 'host' => $hostname, 25 'port' => $port, 26 'database' => $db, 27 'password' => $password, 28 ); 29 } else { 30 $clientArgs = array( 31 'scheme' => 'unix', 32 'path' => $host 33 ); 34 } 35 $this->redis = new Client( $clientArgs ); 27 36 $this->redis->connect(); 28 37 return $this; -
redisearch/trunk/src/Settings.php
r2452159 r2525480 45 45 46 46 return isset( $redis_server ) && !empty( $redis_server ) ? $redis_server : '127.0.0.1'; 47 } 48 49 /** 50 * Using UNIX socket for communicating with Redis server or not. 51 * @since 0.1.0 52 * @param 53 * @return bool $unixServer 54 */ 55 public static function RedisScheme() { 56 /** 57 * First we try to get the WP_REDIS_SCHEME option from wp-config.php 58 * @since 0.3.3 59 */ 60 $redis_server = ( defined( 'WP_REDIS_SCHEME' ) ) ? WP_REDIS_SCHEME : get_option( 'wp_redisearch_connection_scheme' ); 61 62 return get_option( 'wp_redisearch_connection_scheme' ); 47 63 } 48 64 -
redisearch/trunk/vendor/foadyousefi/seven-fields/src/Fields/Fields.php
r2013762 r2525480 77 77 update_option( $name, $value ); 78 78 break; 79 case 'select': 80 update_option( $name, $value ); 81 break; 79 82 case 'checkbox': 80 83 $value = isset( $value ) ? true : false; -
redisearch/trunk/vendor/foadyousefi/seven-fields/src/Fields/Select.php
r1949960 r2525480 39 39 self::$description = $description; 40 40 self::$options = $options; 41 // Save value in as wp_option in database 42 parent::save( self::$name, 'select' ); 41 43 return $this->field_html(); 42 44 } -
redisearch/trunk/vendor/front/redisearch/src/RedisRaw/PredisAdapter.php
r2452159 r2525480 17 17 public $redis; 18 18 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null): RedisRawClientInterface { 20 $this->redis = new Client([ 21 'scheme' => 'tcp', 22 'host' => $hostname, 23 'port' => $port, 24 'database' => $db, 25 'password' => $password, 26 ]); 19 public function connect($hostname = '127.0.0.1', $port = 6379, $db = 0, $password = null, $scheme = 'tcp'): RedisRawClientInterface { 20 $clientArgs = array( 21 'database' => $db, 22 'password' => $password 23 ); 24 if ( $scheme === 'tcp' ) { 25 $clientArgs = array( 26 'scheme' => 'tcp', 27 'port' => $port, 28 'host' => $hostname 29 ); 30 } else if ( $scheme === 'unix' ) { 31 $clientArgs = array( 32 'scheme' => 'unix', 33 'path' => $host 34 ); 35 } 36 $this->redis = new Client( $clientArgs ); 27 37 $this->redis->connect(); 28 38 return $this; -
redisearch/trunk/vendor/front/redisearch/src/Setup.php
r2452159 r2525480 17 17 * @return PredisAdapter 18 18 */ 19 public static function connect( $server = '127.0.0.1', $port = 6379, $password = null, $database = 0 ) {19 public static function connect( $server = '127.0.0.1', $port = 6379, $password = null, $database = 0, $scheme = 'tcp' ) { 20 20 // Connect to server 21 $client = ( new PredisAdapter() )->connect( $server, $port, $database, $password );21 $client = ( new PredisAdapter() )->connect( $server, $port, $database, $password, $database, $scheme ); 22 22 return $client; 23 23 } -
redisearch/trunk/vendor/vaites/php-apache-tika/src/Client.php
r2002534 r2525480 5 5 use Closure; 6 6 use Exception; 7 use stdClass; 7 8 8 9 use Vaites\ApacheTika\Clients\CLIClient; 9 10 use Vaites\ApacheTika\Clients\WebClient; 11 use Vaites\ApacheTika\Metadata\Metadata; 12 use Vaites\ApacheTika\Metadata\MetadataInterface; 10 13 11 14 /** … … 13 16 * 14 17 * @author David Martínez <contacto@davidmartinez.net> 15 * @link http://wiki.apache.org/tika/TikaJAXRS 16 * @link https://tika.apache.org/1.10/formats.html 18 * @link https://tika.apache.org/1.24/formats.html 17 19 */ 18 20 abstract class Client 19 21 { 20 /** 21 * List of supported Apache Tika versions 22 protected const MODE = null; 23 24 /** 25 * Checked flag 26 * 27 * @var bool 28 */ 29 protected $checked = false; 30 31 /** 32 * Response using callbacks 33 * 34 * @var string 35 */ 36 protected $response = null; 37 38 /** 39 * Platform (unix or win) 40 * 41 * @var string 42 */ 43 protected $platform = null; 44 45 /** 46 * Cached responses to avoid multiple request for the same file. 22 47 * 23 48 * @var array 24 49 */ 25 protected static $supportedVersions =26 [27 '1.7', '1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.19.1'28 ];29 30 /**31 * Response using callbacks32 *33 * @var string34 */35 protected $response = null;36 37 /**38 * Cached responses to avoid multiple request for the same file.39 *40 * @var array41 */42 50 protected $cache = []; 43 51 44 52 /** 53 * Text encoding 54 * 55 * @var string|null 56 */ 57 protected $encoding = null; 58 59 /** 45 60 * Callback called on secuential read 46 61 * 47 * @var \Closure62 * @var callable|null 48 63 */ 49 64 protected $callback = null; 50 65 51 66 /** 67 * Enable or disable appending when using callback 68 * 69 * @var bool 70 */ 71 protected $callbackAppend = true; 72 73 /** 52 74 * Size of chunks for callback 53 75 * … … 64 86 65 87 /** 66 * Get a class instance 67 * 68 * @param string $param1 path or host 69 * @param int $param2 Java binary path or port for web client 70 * @param array $options options for cURL request 71 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 72 * @throws \Exception 73 */ 74 public static function make($param1 = null, $param2 = null, $options = []) 75 { 76 if (preg_match('/\.jar$/', func_get_arg(0))) 77 { 78 return new CLIClient($param1, $param2); 88 * Configure client 89 */ 90 public function __construct() 91 { 92 $this->platform = defined('PHP_WINDOWS_VERSION_MAJOR') ? 'win' : 'unix'; 93 } 94 95 /** 96 * Get a class instance throwing an exception if check fails 97 * 98 * @param string $param1 path or host 99 * @param string|int $param2 Java binary path or port for web client 100 * @param array $options options for cURL request 101 * @param bool $check check JAR file or server connection 102 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 103 * @throws \Exception 104 */ 105 public static function make(string $param1 = null, $param2 = null, array $options = [], bool $check = true): Client 106 { 107 if(preg_match('/\.jar$/', func_get_arg(0))) 108 { 109 return new CLIClient($param1, $param2, $check); 79 110 } 80 111 else 81 112 { 82 return new WebClient($param1, $param2, $options); 83 } 113 return new WebClient($param1, $param2, $options, $check); 114 } 115 } 116 117 /** 118 * Get a class instance delaying the check 119 * 120 * @param string $param1 path or host 121 * @param int $param2 Java binary path or port for web client 122 * @param array $options options for cURL request 123 * @return \Vaites\ApacheTika\Clients\CLIClient|\Vaites\ApacheTika\Clients\WebClient 124 * @throws \Exception 125 */ 126 public static function prepare($param1 = null, $param2 = null, $options = []): Client 127 { 128 return self::make($param1, $param2, $options, false); 129 } 130 131 /** 132 * Get the encoding 133 */ 134 public function getEncoding(): ?string 135 { 136 return $this->encoding; 137 } 138 139 /** 140 * Set the encoding 141 * 142 * @throws \Exception 143 */ 144 public function setEncoding(string $encoding): self 145 { 146 if(!empty($encoding)) 147 { 148 $this->encoding = $encoding; 149 } 150 else 151 { 152 throw new Exception('Invalid encoding'); 153 } 154 155 return $this; 84 156 } 85 157 86 158 /** 87 159 * Get the callback 88 * 89 * @return \Closure|null 90 */ 91 public function getCallback() 160 */ 161 public function getCallback(): ?Closure 92 162 { 93 163 return $this->callback; … … 97 167 * Set the callback (callable or closure) for call on secuential read 98 168 * 99 * @param mixed $callback 100 * @return $this 101 * @throws \Exception 102 */ 103 public function setCallback($callback) 104 { 105 if($callback instanceof Closure) 106 { 169 * @throws \Exception 170 */ 171 public function setCallback(callable $callback, bool $append = true): self 172 { 173 if($callback instanceof Closure || is_array($callback)) 174 { 175 $this->callbackAppend = (bool) $append; 107 176 $this->callback = $callback; 108 177 } 109 elseif(is_callable($callback)) 110 { 111 $this->callback = function($chunk) use($callback) 178 elseif(is_string($callback)) 179 { 180 $this->callbackAppend = (bool) $append; 181 $this->callback = function($chunk) use ($callback) 112 182 { 113 183 return call_user_func_array($callback, [$chunk]); … … 124 194 /** 125 195 * Get the chunk size 126 * 127 * @return int 128 */ 129 public function getChunkSize() 196 */ 197 public function getChunkSize(): int 130 198 { 131 199 return $this->chunkSize; … … 135 203 * Set the chunk size for secuential read 136 204 * 137 * @param int $size 138 * @return $this 139 * @throws \Exception 140 */ 141 public function setChunkSize($size) 142 { 143 if(static::MODE == 'cli' && is_numeric($size)) 144 { 145 $this->chunkSize = (int)$size; 146 } 147 elseif(static::MODE == 'web') 205 * @throws \Exception 206 */ 207 public function setChunkSize(int $size): self 208 { 209 if(static::MODE == 'cli') 210 { 211 $this->chunkSize = $size; 212 } 213 else 148 214 { 149 215 throw new Exception('Chunk size is not supported on web mode'); 150 216 } 151 else152 {153 throw new Exception("$size is not a valid chunk size");154 }155 217 156 218 return $this; … … 159 221 /** 160 222 * Get the remote download flag 161 * 162 * @return bool 163 */ 164 public function getDownloadRemote() 223 */ 224 public function getDownloadRemote(): bool 165 225 { 166 226 return $this->downloadRemote; … … 169 229 /** 170 230 * Set the remote download flag 171 * 172 * @param bool $download 173 * @return $this 174 */ 175 public function setDownloadRemote($download) 231 */ 232 public function setDownloadRemote(bool $download): self 176 233 { 177 234 $this->downloadRemote = (bool) $download; … … 183 240 * Gets file metadata 184 241 * 185 * @param string $file 186 * @return \Vaites\ApacheTika\Metadata\Metadata 187 * @throws \Exception 188 */ 189 public function getMetadata($file) 190 { 191 return $this->request('meta', $file); 242 * @throws \Exception 243 */ 244 public function getMetadata(string $file): MetadataInterface 245 { 246 $response = $this->parseJsonResponse($this->request('meta', $file)); 247 248 if($response instanceof stdClass == false) 249 { 250 throw new Exception("Unexpected metadata response for $file"); 251 } 252 253 return Metadata::make($response, $file); 254 } 255 256 /** 257 * Gets recursive file metadata where the returned array indexes are the file name. 258 * 259 * Example: for a sample.zip with an example.doc file, the return array looks like if be defined as: 260 * 261 * [ 262 * 'sample.zip' => new Metadata() 263 * 'sample.zip/example.doc' => new DocumentMetadata() 264 * ] 265 * 266 * @link https://cwiki.apache.org/confluence/display/TIKA/TikaServer#TikaServer-RecursiveMetadataandContent 267 * @throws \Exception 268 */ 269 public function getRecursiveMetadata(string $file, ?string $format = 'ignore'): array 270 { 271 if(in_array($format, ['text', 'html', 'ignore']) == false) 272 { 273 throw new Exception("Unknown recursive type (must be text, html, ignore or null)"); 274 } 275 276 $response = $this->parseJsonResponse($this->request("rmeta/$format", $file)); 277 278 if(is_array($response) == false) 279 { 280 throw new Exception("Unexpected metadata response for $file"); 281 } 282 283 $metadata = []; 284 285 foreach($response as $item) 286 { 287 $name = basename($file); 288 if(isset($item->{'X-TIKA:embedded_resource_path'})) 289 { 290 $name .= $item->{'X-TIKA:embedded_resource_path'}; 291 } 292 293 $metadata[$name] = Metadata::make($item, $file); 294 } 295 296 return $metadata; 192 297 } 193 298 … … 195 300 * Detect language 196 301 * 197 * @param string $file 198 * @return string 199 * @throws \Exception 200 */ 201 public function getLanguage($file) 302 * @throws \Exception 303 */ 304 public function getLanguage(string $file): string 202 305 { 203 306 return $this->request('lang', $file); … … 207 310 * Detect MIME type 208 311 * 209 * @param string $file 210 * @return string 211 * @throws \Exception 212 */ 213 public function getMIME($file) 312 * @throws \Exception 313 */ 314 public function getMIME(string $file): string 214 315 { 215 316 return $this->request('mime', $file); … … 219 320 * Extracts HTML 220 321 * 221 * @param string $file 222 * @param mixed $callback 223 * @return string 224 * @throws \Exception 225 */ 226 public function getHTML($file, $callback = null) 322 * @throws \Exception 323 */ 324 public function getHTML(string $file, callable $callback = null, bool $append = true): string 227 325 { 228 326 if(!is_null($callback)) 229 327 { 230 $this->setCallback($callback );328 $this->setCallback($callback, $append); 231 329 } 232 330 … … 235 333 236 334 /** 335 * Extracts XHTML 336 * 337 * @throws \Exception 338 */ 339 public function getXHTML(string $file, callable $callback = null, bool $append = true): string 340 { 341 if(!is_null($callback)) 342 { 343 $this->setCallback($callback, $append); 344 } 345 346 return $this->request('xhtml', $file); 347 } 348 349 /** 237 350 * Extracts text 238 351 * 239 * @param string $file 240 * @param mixed $callback 241 * @return string 242 * @throws \Exception 243 */ 244 public function getText($file, $callback = null) 352 * @throws \Exception 353 */ 354 public function getText(string $file, callable $callback = null, bool $append = true): string 245 355 { 246 356 if(!is_null($callback)) 247 357 { 248 $this->setCallback($callback );358 $this->setCallback($callback, $append); 249 359 } 250 360 … … 255 365 * Extracts main text 256 366 * 257 * @param string $file 258 * @param mixed $callback 259 * @return string 260 * @throws \Exception 261 */ 262 public function getMainText($file, $callback = null) 367 * @throws \Exception 368 */ 369 public function getMainText(string $file, callable $callback = null, bool $append = true): string 263 370 { 264 371 if(!is_null($callback)) 265 372 { 266 $this->setCallback($callback );373 $this->setCallback($callback, $append); 267 374 } 268 375 … … 271 378 272 379 /** 273 * Returns the supported MIME types274 *275 * @return string276 * @throws \Exception277 */278 public function getSupportedMIMETypes()279 {280 return $this->request('mime-types');281 }282 283 /**284 * Returns the available detectors285 *286 * @return string287 * @throws \Exception288 */289 public function getAvailableDetectors()290 {291 return $this->request('detectors');292 }293 294 /**295 * Returns the available parsers296 *297 * @return string298 * @throws \Exception299 */300 public function getAvailableParsers()301 {302 return $this->request('parsers');303 }304 305 /**306 380 * Returns current Tika version 307 381 * 308 * @return string 309 * @throws \Exception 310 */ 311 public function getVersion() 382 * @throws \Exception 383 */ 384 public function getVersion(): string 312 385 { 313 386 return $this->request('version'); … … 317 390 * Return the list of Apache Tika supported versions 318 391 * 319 * @return array 320 */ 321 public static function getSupportedVersions() 322 { 323 return self::$supportedVersions; 392 * @throws \Exception 393 */ 394 public function getSupportedVersions(): array 395 { 396 static $versions = null; 397 398 if(is_null($versions)) 399 { 400 $composer = json_decode(file_get_contents(dirname(__DIR__) . '/composer.json'), true); 401 $versions = $composer['extra']['supported-versions'] ?? null; 402 403 if(empty($versions)) 404 { 405 throw new Exception("An error ocurred trying to read package's composer.json file"); 406 } 407 } 408 409 return $versions; 410 } 411 412 /** 413 * Sets the checked flag 414 */ 415 public function setChecked(bool $checked): self 416 { 417 $this->checked = (bool) $checked; 418 419 return $this; 420 } 421 422 /** 423 * Checks if instance is checked 424 */ 425 public function isChecked(): bool 426 { 427 return $this->checked; 428 } 429 430 /** 431 * Check if a response is cached 432 */ 433 protected function isCached(string $type, string $file): bool 434 { 435 return isset($this->cache[sha1($file)][$type]); 436 } 437 438 /** 439 * Get a cached response 440 */ 441 protected function getCachedResponse(string $type, string $file) 442 { 443 return $this->cache[sha1($file)][$type] ?? null; 444 } 445 446 /** 447 * Check if a request type must be cached 448 */ 449 protected function isCacheable(string $type): bool 450 { 451 return in_array($type, ['lang', 'meta']); 452 } 453 454 /** 455 * Caches a response 456 */ 457 protected function cacheResponse(string $type, $response, string $file): bool 458 { 459 $this->cache[sha1($file)][$type] = $response; 460 461 return true; 324 462 } 325 463 326 464 /** 327 465 * Checks if a specific version is supported 328 * 329 * @param string $version 330 * @return bool 331 */ 332 public static function isVersionSupported($version) 333 { 334 return in_array($version, self::getSupportedVersions()); 466 */ 467 public function isVersionSupported(string $version): bool 468 { 469 return in_array($version, $this->getSupportedVersions()); 470 } 471 472 /** 473 * Check if a mime type is supported 474 * 475 * @param string $mime 476 * @return bool 477 * @throws \Exception 478 */ 479 public function isMIMETypeSupported(string $mime): bool 480 { 481 return array_key_exists($mime, $this->getSupportedMIMETypes()); 335 482 } 336 483 … … 338 485 * Check the request before executing 339 486 * 340 * @param string $type 341 * @param string $file 342 * @return string 343 * @throws \Exception 344 */ 345 public function checkRequest($type, $file) 487 * @throws \Exception 488 */ 489 public function checkRequest(string $type, string $file = null): ?string 346 490 { 347 491 // no checks for getters … … 349 493 { 350 494 // 351 } 352 // invalid local file 495 } // invalid local file 353 496 elseif(!preg_match('/^http/', $file) && !file_exists($file)) 354 497 { 355 498 throw new Exception("File $file can't be opened"); 356 } 357 // invalid remote file 499 } // invalid remote file 358 500 elseif(preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0])) 359 501 { 360 502 throw new Exception("File $file can't be opened", 2); 361 } 362 // download remote file if required only for integrated downloader 503 } // download remote file if required only for integrated downloader 363 504 elseif(preg_match('/^http/', $file) && $this->downloadRemote) 364 505 { … … 370 511 371 512 /** 513 * Parse the response returned by Apache Tika 514 * 515 * @return mixed 516 * @throws \Exception 517 */ 518 protected function parseJsonResponse(string $response) 519 { 520 // an empty response throws an error 521 if(empty($response) || trim($response) == '') 522 { 523 throw new Exception('Empty response'); 524 } 525 526 // decode the JSON response 527 $json = json_decode($response); 528 529 // exceptions if metadata is not valid 530 if(json_last_error()) 531 { 532 $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Error parsing JSON response'; 533 534 throw new Exception($message, json_last_error()); 535 } 536 537 return $json; 538 } 539 540 /** 372 541 * Download file to a temporary folder 373 542 * 374 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 375 * @param string $file 376 * @return string 377 * @throws \Exception 378 */ 379 protected function downloadFile($file) 543 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 544 * @throws \Exception 545 */ 546 protected function downloadFile(string $file): string 380 547 { 381 548 $dest = tempnam(sys_get_temp_dir(), 'TIKA'); … … 411 578 412 579 /** 580 * Must return the supported MIME types 581 * 582 * @throws \Exception 583 */ 584 abstract public function getSupportedMIMETypes(): array; 585 586 /** 587 * Must return the available detectors 588 * 589 * @throws \Exception 590 */ 591 abstract public function getAvailableDetectors(): array; 592 593 /** 594 * Must return the available parsers 595 * 596 * @throws \Exception 597 */ 598 abstract public function getAvailableParsers(): array; 599 600 /** 601 * Check Java binary, JAR path or server connection 602 */ 603 abstract public function check(): void; 604 605 /** 413 606 * Configure and make a request and return its results. 414 607 * 415 * @param string $type 416 * @param string $file 417 * @return string 418 * @throws \Exception 419 */ 420 abstract public function request($type, $file); 608 * @throws \Exception 609 */ 610 abstract public function request(string $type, string $file = null): string; 421 611 } -
redisearch/trunk/vendor/vaites/php-apache-tika/src/Clients/CLIClient.php
r2002534 r2525480 6 6 7 7 use Vaites\ApacheTika\Client; 8 use Vaites\ApacheTika\Metadata\Metadata;9 8 10 9 /** … … 12 11 * 13 12 * @author David Martínez <contacto@davidmartinez.net> 14 * @link http://wiki.apache.org/tika/TikaJAXRS 15 * @link https://tika.apache.org/1.12/formats.html 13 * @link https://tika.apache.org/1.23/gettingstarted.html#Using_Tika_as_a_command_line_utility 16 14 */ 17 15 class CLIClient extends Client 18 16 { 19 const MODE = 'cli';17 protected const MODE = 'cli'; 20 18 21 19 /** … … 34 32 35 33 /** 34 * Java arguments 35 * 36 * @var string 37 */ 38 protected $javaArgs = null; 39 40 /** 36 41 * Configure client 37 42 * 38 * @param string $path 39 * @param string $java 40 * 41 * @throws Exception 42 */ 43 public function __construct($path = null, $java = null) 44 { 43 * @throws \Exception 44 */ 45 public function __construct(string $path = null, string $java = null, bool $check = true) 46 { 47 parent::__construct(); 48 45 49 if($path) 46 50 { … … 52 56 $this->setJava($java); 53 57 } 58 59 if($check === true) 60 { 61 $this->check(); 62 } 54 63 } 55 64 56 65 /** 57 66 * Get the path 58 * 59 * @return null|string 60 */ 61 public function getPath() 67 */ 68 public function getPath(): ?string 62 69 { 63 70 return $this->path; … … 66 73 /** 67 74 * Set the path 68 * 69 * @param string $path 70 * @return $this 71 */ 72 public function setPath($path) 75 */ 76 public function setPath($path): self 73 77 { 74 78 $this->path = $path; … … 79 83 /** 80 84 * Get the Java path 81 * 82 * @return null|int 83 */ 84 public function getJava() 85 */ 86 public function getJava(): ?string 85 87 { 86 88 return $this->java; … … 89 91 /** 90 92 * Set the Java path 91 * 92 * @param string $java 93 * @return $this 94 */ 95 public function setJava($java) 93 */ 94 public function setJava(string $java): self 96 95 { 97 96 $this->java = $java; … … 101 100 102 101 /** 102 * Get the Java arguments 103 */ 104 public function getJavaArgs(): ?string 105 { 106 return $this->javaArgs; 107 } 108 109 /** 110 * Set the Java arguments 111 * 112 * NOTE: to modify child process jvm args, prepend "J" to each argument (-JXmx4g) 113 */ 114 public function setJavaArgs(string $args): self 115 { 116 $this->javaArgs = $args; 117 118 return $this; 119 } 120 121 /** 122 * Returns the supported MIME types 123 * 124 * NOTE: the data provided by the CLI must be parsed: mime type has no spaces, aliases go next prefixed with spaces 125 * 126 * @throws \Exception 127 */ 128 public function getSupportedMIMETypes(): array 129 { 130 $mime = null; 131 $mimeTypes = []; 132 133 $response = preg_split("/\n/", $this->request('mime-types')); 134 135 foreach($response as $line) 136 { 137 if(preg_match('/^\w+/', $line)) 138 { 139 $mime = trim($line); 140 $mimeTypes[$mime] = ['alias' => []]; 141 } 142 else 143 { 144 [$key, $value] = preg_split('/:\s+/', trim($line)); 145 146 if($key == 'alias') 147 { 148 $mimeTypes[$mime]['alias'][] = $value; 149 } 150 else 151 { 152 $mimeTypes[$mime][$key] = $value; 153 } 154 } 155 } 156 157 158 return $mimeTypes; 159 } 160 161 /** 162 * Returns the available detectors 163 * 164 * @throws \Exception 165 */ 166 public function getAvailableDetectors(): array 167 { 168 $detectors = []; 169 170 $split = preg_split("/\n/", $this->request('detectors')); 171 172 $parent = null; 173 foreach($split as $line) 174 { 175 if(preg_match('/composite/i', $line)) 176 { 177 $parent = trim(preg_replace('/\(.+\):/', '', $line)); 178 $detectors[$parent] = ['children' => [], 'composite' => true, 'name' => $parent]; 179 } 180 else 181 { 182 $child = trim($line); 183 $detectors[$parent]['children'][$child] = ['composite' => false, 'name' => $child]; 184 } 185 } 186 187 return $detectors; 188 } 189 190 /** 191 * Returns the available parsers 192 * 193 * @throws \Exception 194 */ 195 public function getAvailableParsers(): array 196 { 197 $parsers = []; 198 199 $split = preg_split("/\n/", $this->request('parsers')); 200 array_shift($split); 201 202 $parent = null; 203 foreach($split as $line) 204 { 205 if(preg_match('/composite/i', $line)) 206 { 207 $parent = trim(preg_replace('/\(.+\):/', '', $line)); 208 209 $parsers[$parent] = ['children' => [], 'composite' => true, 'name' => $parent, 'decorated' => false]; 210 } 211 else 212 { 213 $child = trim($line); 214 215 $parsers[$parent]['children'][$child] = ['composite' => false, 'name' => $child, 'decorated' => false]; 216 } 217 } 218 219 return $parsers; 220 } 221 222 /** 223 * Check Java binary, JAR path or server connection 224 * 225 * @throws \Exception 226 */ 227 public function check(): void 228 { 229 if($this->isChecked() === false) 230 { 231 // Java command must not return an error 232 try 233 { 234 $this->exec(($this->java ?: 'java') . ' -version'); 235 } 236 catch(Exception $exception) 237 { 238 throw new Exception('Java command not found'); 239 } 240 241 // JAR path must exists 242 if(file_exists($this->path) === false) 243 { 244 throw new Exception('Apache Tika app JAR not found'); 245 } 246 247 $this->setChecked(true); 248 } 249 } 250 251 /** 103 252 * Configure and make a request and return its results 104 253 * 105 * @ param string $type106 * @param string $file107 * @returnstring108 * @throws \Exception109 */110 public function request($type, $file = null)111 { 254 * @throws \Exception 255 */ 256 public function request(string $type, string $file = null): string 257 { 258 // check if not checked 259 $this->check(); 260 112 261 // check if is cached 113 if( isset($this->cache[sha1($file)][$type]))114 { 115 return $this-> cache[sha1($file)][$type];262 if($file !== null && $this->isCached($type, $file)) 263 { 264 return $this->getCachedResponse($type, $file); 116 265 } 117 266 … … 120 269 121 270 // check the request 122 $file = parent::checkRequest($type, $file);271 $file = $this->checkRequest($type, $file); 123 272 124 273 // add last argument … … 130 279 // build command 131 280 $jar = escapeshellarg($this->path); 132 $command = ($this->java ?: 'java') . " -jar $jar " . implode(' ', $arguments);281 $command = trim(($this->java ?: 'java') . " -jar $jar " . implode(' ', $arguments) . " {$this->javaArgs}"); 133 282 134 283 // run command … … 136 285 137 286 // metadata response 138 if( $type == 'meta')287 if(in_array(preg_replace('/\/.+/', '', $type), ['meta', 'rmeta'])) 139 288 { 140 289 // fix for invalid? json returned only with images 141 290 $response = str_replace(basename($file) . '"}{', '", ', $response); 142 291 143 // on Windows, response comes in another charset 144 if(defined('PHP_WINDOWS_VERSION_MAJOR')) 145 { 146 $response = utf8_encode($response); 147 } 148 149 $response = Metadata::make($response, $file); 292 // on Windows, response must be encoded to UTF8 293 $response = $this->platform == 'win' ? utf8_encode($response) : $response; 150 294 } 151 295 152 296 // cache certain responses 153 if( in_array($type, ['lang', 'meta']))154 { 155 $this->cache [sha1($file)][$type] = $response;297 if($this->isCacheable($type)) 298 { 299 $this->cacheResponse($type, $response, $file); 156 300 } 157 301 … … 162 306 * Run the command and return its results 163 307 * 164 * @param string $command 165 * @return null|string 166 * @throws \Exception 167 */ 168 public function exec($command) 308 * @throws \Exception 309 */ 310 public function exec(string $command): ?string 169 311 { 170 312 // run command … … 187 329 } 188 330 189 $this->response .= $chunk; 331 if($this->callbackAppend === true) 332 { 333 $this->response .= $chunk; 334 } 190 335 } 191 336 fclose($pipes[1]); … … 205 350 * Get the arguments to run the command 206 351 * 207 * @param string $type208 * @param string $file209 * @return array210 352 * @throws Exception 211 353 */ 212 protected function getArguments( $type, $file = null)213 { 214 // parameters for command215 $arguments = []; 354 protected function getArguments(string $type, string $file = null): array 355 { 356 $arguments = $this->encoding ? ["--encoding={$this->encoding}"] : []; 357 216 358 switch($type) 217 359 { … … 256 398 break; 257 399 400 case 'rmeta/ignore': 401 $arguments[] = '--metadata --jsonRecursive'; 402 break; 403 404 case 'rmeta/html': 405 $arguments[] = '--html --jsonRecursive'; 406 break; 407 408 case 'rmeta/text': 409 $arguments[] = '--text --jsonRecursive'; 410 break; 411 412 case 'xhtml': 413 $arguments[] = '--xml'; 414 break; 415 258 416 default: 259 throw new Exception( "Unknown type $type");417 throw new Exception($file ? "Unknown type $type for $file" : "Unknown type $type"); 260 418 } 261 419 -
redisearch/trunk/vendor/vaites/php-apache-tika/src/Clients/WebClient.php
r2002534 r2525480 6 6 7 7 use Vaites\ApacheTika\Client; 8 use Vaites\ApacheTika\Metadata\Metadata;9 8 10 9 /** … … 12 11 * 13 12 * @author David Martínez <contacto@davidmartinez.net> 14 * @link http://wiki.apache.org/tika/TikaJAXRS 15 * @link https://tika.apache.org/1.12/formats.html 13 * @link https://cwiki.apache.org/confluence/display/TIKA/TikaServer 16 14 */ 17 15 class WebClient extends Client 18 16 { 19 const MODE = 'web';17 protected const MODE = 'web'; 20 18 21 19 /** … … 31 29 * @var string 32 30 */ 33 protected $host = '127.0.0.1';31 protected $host = null; 34 32 35 33 /** … … 38 36 * @var int 39 37 */ 40 protected $port = 9998;38 protected $port = null; 41 39 42 40 /** … … 54 52 protected $options = 55 53 [ 56 CURLINFO_HEADER_OUT => true,57 CURLOPT_HTTPHEADER => [],58 CURLOPT_PUT => true,59 CURLOPT_RETURNTRANSFER => true,60 CURLOPT_TIMEOUT => 5,54 CURLINFO_HEADER_OUT => true, 55 CURLOPT_HTTPHEADER => [], 56 CURLOPT_PUT => true, 57 CURLOPT_RETURNTRANSFER => true, 58 CURLOPT_TIMEOUT => 5 61 59 ]; 62 60 … … 64 62 * Configure class and test if server is running 65 63 * 66 * @param string $host 67 * @param int $port 68 * @param array $options 69 * @throws \Exception 70 */ 71 public function __construct($host = null, $port = null, $options = []) 72 { 73 if($host) 64 * @throws \Exception 65 */ 66 public function __construct(string $host = null, int $port = null, array $options = [], bool $check = true) 67 { 68 parent::__construct(); 69 70 if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL)) 71 { 72 $this->setUrl($host); 73 } 74 elseif($host) 74 75 { 75 76 $this->setHost($host); 76 77 } 77 78 78 if( $port)79 if(is_numeric($port)) 79 80 { 80 81 $this->setPort($port); … … 88 89 $this->setDownloadRemote(true); 89 90 90 $this->getVersion(); // exception if not running 91 if($check === true) 92 { 93 $this->check(); 94 } 95 } 96 97 /** 98 * Get the base URL 99 */ 100 public function getUrl(): string 101 { 102 return sprintf('http://%s:%d', $this->host, $this->port ?: 9998); 103 } 104 105 /** 106 * Set the host and port using an URL 107 */ 108 public function setUrl(string $url): self 109 { 110 $url = parse_url($url); 111 112 $this->setHost($url['host']); 113 114 if(isset($url['port'])) 115 { 116 $this->setPort($url['port']); 117 } 118 119 return $this; 91 120 } 92 121 93 122 /** 94 123 * Get the host 95 * 96 * @return null|string 97 */ 98 public function getHost() 124 */ 125 public function getHost(): ?string 99 126 { 100 127 return $this->host; … … 103 130 /** 104 131 * Set the host 105 * 106 * @param string $host 107 * @return $this 108 */ 109 public function setHost($host) 132 */ 133 public function setHost(string $host): self 110 134 { 111 135 $this->host = $host; … … 116 140 /** 117 141 * Get the port 118 * 119 * @return null|int 120 */ 121 public function getPort() 142 */ 143 public function getPort(): ?int 122 144 { 123 145 return $this->port; … … 126 148 /** 127 149 * Set the port 128 * 129 * @param int $port 130 * @return $this 131 */ 132 public function setPort($port) 150 */ 151 public function setPort(int $port): self 133 152 { 134 153 $this->port = $port; … … 139 158 /** 140 159 * Get the number of retries 141 * 142 * @return int 143 */ 144 public function getRetries() 160 */ 161 public function getRetries(): int 145 162 { 146 163 return $this->retries; … … 149 166 /** 150 167 * Set the number of retries 151 * 152 * @param int $retries 153 * @return $this 154 */ 155 public function setRetries($retries) 168 */ 169 public function setRetries(int $retries): self 156 170 { 157 171 $this->retries = $retries; … … 162 176 /** 163 177 * Get all the options 164 * 165 * @return null|array 166 */ 167 public function getOptions() 178 */ 179 public function getOptions(): array 168 180 { 169 181 return $this->options; … … 173 185 * Get an specified option 174 186 * 175 * @param string $key176 187 * @return mixed 177 188 */ 178 public function getOption( $key)179 { 180 return isset($this->options[$key]) ? $this->options[$key] :null;189 public function getOption(int $key) 190 { 191 return $this->options[$key] ?? null; 181 192 } 182 193 … … 184 195 * Set a cURL option to be set with curl_setopt() 185 196 * 186 * @link http://php.net/manual/en/curl.constants.php 187 * @link http://php.net/manual/en/function.curl-setopt.php 188 * @param string $key 189 * @param mixed $value 190 * @return $this 191 * @throws \Exception 192 */ 193 public function setOption($key, $value) 197 * @link http://php.net/manual/en/curl.constants.php 198 * @link http://php.net/manual/en/function.curl-setopt.php 199 * @throws \Exception 200 */ 201 public function setOption(int $key, $value): self 194 202 { 195 203 if(in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER])) … … 206 214 * Set the cURL options 207 215 * 208 * @param array $options 209 * @return $this 210 * @throws \Exception 211 */ 212 public function setOptions($options) 216 * @throws \Exception 217 */ 218 public function setOptions(array $options): self 213 219 { 214 220 foreach($options as $key => $value) … … 222 228 /** 223 229 * Get the timeout value for cURL 224 * 225 * @return int 226 */ 227 public function getTimeout() 230 */ 231 public function getTimeout(): int 228 232 { 229 233 return $this->getOption(CURLOPT_TIMEOUT); … … 233 237 * Set the timeout value for cURL 234 238 * 235 * @param int $value 236 * @return $this 237 * @throws \Exception 238 */ 239 public function setTimeout($value) 239 * @throws \Exception 240 */ 241 public function setTimeout(int $value): self 240 242 { 241 243 $this->setOption(CURLOPT_TIMEOUT, (int) $value); … … 245 247 246 248 /** 249 * Returns the supported MIME types 250 * 251 * @throws \Exception 252 */ 253 public function getSupportedMIMETypes(): array 254 { 255 $mimeTypes = json_decode($this->request('mime-types'), true); 256 257 ksort($mimeTypes); 258 259 return $mimeTypes; 260 } 261 262 /** 263 * Returns the available detectors 264 * 265 * @throws \Exception 266 */ 267 public function getAvailableDetectors(): array 268 { 269 $detectors = [json_decode($this->request('detectors'), true)]; 270 271 foreach($detectors as $index => $parent) 272 { 273 $detectors[$parent['name']] = $parent; 274 275 if(isset($parent['children'])) 276 { 277 foreach($parent['children'] as $subindex => $child) 278 { 279 $detectors[$parent['name']]['children'][$child['name']] = $child; 280 281 unset($detectors[$parent['name']]['children'][$subindex]); 282 } 283 } 284 285 unset($detectors[$index]); 286 } 287 288 return $detectors; 289 } 290 291 /** 292 * Returns the available parsers 293 * 294 * @throws \Exception 295 */ 296 public function getAvailableParsers(): array 297 { 298 $parsers = [json_decode($this->request('parsers'), true)]; 299 300 foreach($parsers as $index => $parent) 301 { 302 $parsers[$parent['name']] = $parent; 303 304 if(isset($parent['children'])) 305 { 306 foreach($parent['children'] as $subindex => $child) 307 { 308 $parsers[$parent['name']]['children'][$child['name']] = $child; 309 310 unset($parsers[$parent['name']]['children'][$subindex]); 311 } 312 } 313 314 unset($parsers[$index]); 315 } 316 317 return $parsers; 318 } 319 320 /** 321 * Check if server is running 322 * 323 * @throws \Exception 324 */ 325 public function check(): void 326 { 327 if($this->isChecked() === false) 328 { 329 $this->setChecked(true); 330 331 // throws an exception if server is unreachable or can't connect 332 $this->request('version'); 333 } 334 } 335 336 /** 247 337 * Configure, make a request and return its results 248 338 * 249 * @param string $type 250 * @param string $file 251 * @return string 252 * @throws \Exception 253 */ 254 public function request($type, $file = null) 339 * @throws \Exception 340 */ 341 public function request(string $type, string $file = null): string 255 342 { 256 343 static $retries = []; 257 344 345 // check if not checked 346 $this->check(); 347 258 348 // check if is cached 259 if( isset($this->cache[sha1($file)][$type]))260 { 261 return $this-> cache[sha1($file)][$type];349 if($file !== null && $this->isCached($type, $file)) 350 { 351 return $this->getCachedResponse($type, $file); 262 352 } 263 353 elseif(!isset($retries[sha1($file)])) … … 267 357 268 358 // parameters for cURL request 269 list($resource, $headers)= $this->getParameters($type, $file);359 [$resource, $headers] = $this->getParameters($type, $file); 270 360 271 361 // check the request 272 $file = parent::checkRequest($type, $file);362 $file = $this->checkRequest($type, $file); 273 363 274 364 // cURL options … … 282 372 283 373 // cURL init and options 284 $options[CURLOPT_URL] = "http://{$this->host}:{$this->port}". "/$resource";374 $options[CURLOPT_URL] = $this->getUrl() . "/$resource"; 285 375 286 376 // get the response and the HTTP status code 287 list($response, $status) = $this->exec($options); 377 [$response, $status] = $this->exec($options); 378 379 // reduce memory usage closing cURL resource 380 if(isset($options[CURLOPT_INFILE]) && is_resource($options[CURLOPT_INFILE])) 381 { 382 fclose($options[CURLOPT_INFILE]); 383 } 288 384 289 385 // request completed successfully 290 386 if($status == 200) 291 387 { 292 if($type == 'meta') 388 // cache certain responses 389 if($this->isCacheable($type)) 293 390 { 294 $ response = Metadata::make($response, $file);391 $this->cacheResponse($type, $response, $file); 295 392 } 296 297 // cache certain responses 298 if(in_array($type, ['lang', 'meta'])) 299 { 300 $this->cache[sha1($file)][$type] = $response; 301 } 302 } 303 // request completed successfully but result is empty 393 } // request completed successfully but result is empty 304 394 elseif($status == 204) 305 395 { 306 396 $response = null; 307 } 308 // retry on request failed with error 500 397 } // retry on request failed with error 500 309 398 elseif($status == 500 && $retries[sha1($file)]--) 310 399 { 311 400 $response = $this->request($type, $file); 312 } 313 // other status code is an error 401 } // other status code is an error 314 402 else 315 403 { 316 $this->error($status, $resource );404 $this->error($status, $resource, $file); 317 405 } 318 406 … … 323 411 * Make a request to Apache Tika Server 324 412 * 325 * @param array $options 326 * @return array 327 * @throws \Exception 328 */ 329 protected function exec(array $options = []) 413 * @throws \Exception 414 */ 415 protected function exec(array $options = []): array 330 416 { 331 417 // cURL init and options 332 418 $curl = curl_init(); 333 419 334 // we avoid curl_setopt_array($curl, $options) because extrange Windows behaviour (issue #8)420 // we avoid curl_setopt_array($curl, $options) because strange Windows behaviour (issue #8) 335 421 foreach($options as $option => $value) 336 422 { … … 338 424 } 339 425 340 // make the request 426 // make the request directly 341 427 if(is_null($this->callback)) 342 428 { 343 $this->response = curl_exec($curl) ;344 } 429 $this->response = curl_exec($curl) ?: ''; 430 } // with a callback, the response is appended on each block inside the callback 345 431 else 346 432 { … … 362 448 * Throws an exception for an error status code 363 449 * 364 * @codeCoverageIgnore 365 * 366 * @param int $status 367 * @param string $resource 368 * @throws \Exception 369 */ 370 protected function error($status, $resource) 450 * @throws \Exception 451 */ 452 protected function error(int $status, string $resource, string $file = null): void 371 453 { 372 454 switch($status) … … 374 456 // method not allowed 375 457 case 405: 376 throw new Exception('Method not allowed', 405);458 $message = 'Method not allowed'; 377 459 break; 378 460 379 461 // unsupported media type 380 462 case 415: 381 throw new Exception('Unsupported media type', 415);463 $message = 'Unsupported media type'; 382 464 break; 383 465 384 466 // unprocessable entity 385 467 case 422: 386 throw new Exception('Unprocessable document', 422); 468 $message = 'Unprocessable document'; 469 470 // using remote files require Tika server to be launched with specific options 471 if($this->downloadRemote == false && preg_match('/^http/', $file)) 472 { 473 $message .= ' (is server launched using "-enableUnsecureFeatures -enableFileUrl" arguments?)'; 474 } 475 387 476 break; 388 477 389 478 // server error 390 479 case 500: 391 throw new Exception('Error while processing document', 500);480 $message = 'Error while processing document'; 392 481 break; 393 482 394 483 // unexpected 395 484 default: 396 throw new Exception("Unexpected response for /$resource ($status)", 501); 397 } 485 $message = "Unexpected response for /$resource ($status)"; 486 $status = 501; 487 } 488 489 throw new Exception($message, $status); 398 490 } 399 491 … … 401 493 * Get the parameters to make the request 402 494 * 403 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 404 * @param string $type 405 * @param string file 406 * @return array 407 * @throws \Exception 408 */ 409 protected function getParameters($type, $file = null) 495 * @link https://wiki.apache.org/tika/TikaJAXRS#Specifying_a_URL_Instead_of_Putting_Bytes 496 * @throws \Exception 497 */ 498 protected function getParameters(string $type, string $file = null): array 410 499 { 411 500 $headers = []; 501 $callback = null; 412 502 413 503 if(!empty($file) && preg_match('/^http/', $file)) … … 433 523 break; 434 524 525 case 'detectors': 526 case 'parsers': 435 527 case 'meta': 436 $resource = 'meta'; 528 case 'mime-types': 529 case 'rmeta/html': 530 case 'rmeta/ignore': 531 case 'rmeta/text': 532 $resource = $type; 437 533 $headers[] = 'Accept: application/json'; 534 $callback = function($response) 535 { 536 return json_decode($response, true); 537 }; 438 538 break; 439 539 … … 448 548 break; 449 549 450 case 'detectors':451 case 'parsers':452 case 'mime-types':453 550 case 'version': 454 551 $resource = $type; 455 552 break; 456 553 554 case 'xhtml': 555 throw new Exception("Tika Server does not support XHTML output"); 556 break; 557 457 558 default: 458 559 throw new Exception("Unknown type $type"); 459 560 } 460 561 461 return [$resource, $headers ];562 return [$resource, $headers, $callback]; 462 563 } 463 564 … … 465 566 * Get the cURL options 466 567 * 467 * @param string $type 468 * @param string file 469 * @return array 470 * @throws \Exception 471 */ 472 protected function getCurlOptions($type, $file = null) 568 * @throws \Exception 569 */ 570 protected function getCurlOptions(string $type, string $file = null): array 473 571 { 474 572 // base options … … 480 578 $callback = $this->callback; 481 579 482 $options[CURLOPT_WRITEFUNCTION] = function($handler, $data) use ($callback)580 $options[CURLOPT_WRITEFUNCTION] = function($handler, $data) use ($callback) 483 581 { 484 $this->response .= $data; 582 if($this->callbackAppend === true) 583 { 584 $this->response .= $data; 585 } 485 586 486 587 $callback($data); … … 495 596 { 496 597 // 497 } 498 // local file options 598 } // local file options 499 599 elseif($file && file_exists($file) && is_readable($file)) 500 600 { 501 601 $options[CURLOPT_INFILE] = fopen($file, 'r'); 502 602 $options[CURLOPT_INFILESIZE] = filesize($file); 503 } 504 // other options for specific requests 505 elseif(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) 603 } // other options for specific requests 604 elseif(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) 506 605 { 507 606 $options[CURLOPT_PUT] = false; 508 } 509 // file not accesible 607 } // file not accesible 510 608 else 511 609 { -
redisearch/trunk/vendor/vaites/php-apache-tika/tests/BaseTest.php
r2002534 r2525480 3 3 namespace Vaites\ApacheTika\Tests; 4 4 5 use PHPUnit_Framework_TestCase; 5 use Exception; 6 7 use PHPUnit\Framework\TestCase; 6 8 7 9 /** 8 10 * Common test functionality 9 11 */ 10 abstract class BaseTest extends PHPUnit_Framework_TestCase12 abstract class BaseTest extends TestCase 11 13 { 12 14 /** … … 40 42 /** 41 43 * Get env variables 42 * 43 * @param null $name 44 * @param array $data 45 * @param string $dataName 46 */ 47 public function __construct($name = null, array $data = array(), $dataName = '') 44 * 45 * @throws \Exception 46 */ 47 public function __construct(string $name = null, array $data = array(), $dataName = '') 48 48 { 49 49 self::$version = getenv('APACHE_TIKA_VERSION'); 50 50 self::$binaries = getenv('APACHE_TIKA_BINARIES'); 51 51 52 if(empty(self::$version)) 53 { 54 throw new Exception('APACHE_TIKA_VERSION environment variable not defined'); 55 } 56 52 57 parent::__construct($name, $data, $dataName); 53 58 } … … 56 61 * Version test 57 62 */ 58 public function testVersion() 63 public function testVersion(): void 59 64 { 60 65 $this->assertEquals('Apache Tika ' . self::$version, self::$client->getVersion()); … … 64 69 * Metadata test 65 70 * 66 * @dataProvider documentProvider 67 * 68 * @param string $file 69 * @param string $class 70 * @throws \Exception 71 */ 72 public function testMetadata($file, $class = 'Metadata') 71 * @dataProvider documentProvider 72 */ 73 public function testMetadata(string $file, string $class = 'Metadata'): void 74 { 75 $this->assertInstanceOf("\\Vaites\\ApacheTika\\Metadata\\$class", self::$client->getMetadata($file)); 76 } 77 78 /** 79 * Metadata test 80 * 81 * @dataProvider documentProvider 82 */ 83 public function testDocumentMetadata(string $file, string $class = 'DocumentMetadata'): void 84 { 85 $this->testMetadata($file, $class); 86 } 87 88 /** 89 * Metadata title test 90 * 91 * @dataProvider documentProvider 92 */ 93 public function testDocumentMetadataTitle(string $file): void 94 { 95 $this->assertEquals('Lorem ipsum dolor sit amet', self::$client->getMetadata($file)->title); 96 } 97 98 /** 99 * Metadata author test 100 * 101 * @dataProvider documentProvider 102 */ 103 public function testDocumentMetadataAuthor(string $file): void 104 { 105 $this->assertEquals('David Martínez', self::$client->getMetadata($file)->author); 106 } 107 108 /** 109 * Metadata dates test 110 * 111 * @dataProvider documentProvider 112 */ 113 public function testDocumentMetadataCreated(string $file): void 114 { 115 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->created); 116 } 117 118 /** 119 * Metadata dates test 120 * 121 * @dataProvider documentProvider 122 */ 123 public function testDocumentMetadataUpdated(string $file): void 124 { 125 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->updated); 126 } 127 128 /** 129 * Metadata keywords test 130 * 131 * @dataProvider documentProvider 132 */ 133 public function testDocumentMetadataKeywords(string $file): void 134 { 135 $this->assertContains('ipsum', self::$client->getMetadata($file)->keywords); 136 } 137 138 /** 139 * Recursive text metadata test 140 * 141 * @dataProvider recursiveProvider 142 */ 143 public function testTextRecursiveMetadata(string $file): void 144 { 145 $nested = 'sample8.zip/sample1.doc'; 146 147 $metadata = self::$client->getRecursiveMetadata($file, 'text'); 148 149 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', $metadata[$nested]->content ?? 'ERROR'); 150 } 151 152 /** 153 * Recursive HTML metadata test 154 * 155 * @dataProvider recursiveProvider 156 */ 157 public function testHtmlRecursiveMetadata(string $file): void 158 { 159 $nested = 'sample8.zip/sample1.doc'; 160 161 $metadata = self::$client->getRecursiveMetadata($file, 'html'); 162 163 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', $metadata[$nested]->content ?? 'ERROR'); 164 } 165 166 /** 167 * Recursive ignore metadata test 168 * 169 * @dataProvider ocrProvider 170 */ 171 public function testIgnoreRecursiveMetadata(string $file): void 172 { 173 $metadata = self::$client->getRecursiveMetadata($file, 'ignore'); 174 175 $this->assertNull(array_shift($metadata)->content); 176 } 177 178 /** 179 * Language test 180 * 181 * @dataProvider documentProvider 182 */ 183 public function testDocumentLanguage(string $file): void 184 { 185 $this->assertRegExp('/^[a-z]{2}$/', self::$client->getLanguage($file)); 186 } 187 188 /** 189 * MIME test 190 * 191 * @dataProvider documentProvider 192 */ 193 public function testDocumentMIME(string $file): void 194 { 195 $this->assertNotEmpty(self::$client->getMIME($file)); 196 } 197 198 /** 199 * HTML test 200 * 201 * @dataProvider documentProvider 202 */ 203 public function testDocumentHTML(string $file): void 204 { 205 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', self::$client->getHTML($file)); 206 } 207 208 /** 209 * Text test 210 * 211 * @dataProvider documentProvider 212 */ 213 public function testDocumentText(string $file): void 214 { 215 $this->assertStringContainsString('Zenonis est, inquam, hoc Stoici', self::$client->getText($file)); 216 } 217 218 /** 219 * Main text test 220 * 221 * @dataProvider documentProvider 222 */ 223 public function testDocumentMainText(string $file): void 224 { 225 $this->assertStringContainsString('Lorem ipsum dolor sit amet', self::$client->getMainText($file)); 226 } 227 228 /** 229 * Metadata test 230 * 231 * @dataProvider imageProvider 232 */ 233 public function testImageMetadata(string $file, string $class = 'ImageMetadata'): void 234 { 235 $this->testMetadata($file, $class); 236 } 237 238 /** 239 * Metadata width test 240 * 241 * @dataProvider imageProvider 242 */ 243 public function testImageMetadataWidth(string $file): void 244 { 245 $meta = self::$client->getMetadata($file); 246 247 $this->assertEquals(1600, $meta->width, basename($file)); 248 } 249 250 /** 251 * Metadata height test 252 * 253 * @dataProvider imageProvider 254 */ 255 public function testImageMetadataHeight(string $file): void 256 { 257 $meta = self::$client->getMetadata($file); 258 259 $this->assertEquals(900, $meta->height, basename($file)); 260 } 261 262 /** 263 * OCR test 264 * 265 * @dataProvider ocrProvider 266 */ 267 public function testImageOCR(string $file): void 268 { 269 $text = self::$client->getText($file); 270 271 $this->assertRegExp('/voluptate/i', $text); 272 } 273 274 /** 275 * Text callback test 276 * 277 * @dataProvider callbackProvider 278 */ 279 public function testTextCallback(string $file): void 280 { 281 BaseTest::$shared = 0; 282 283 self::$client->getText($file, [$this, 'callableCallback']); 284 285 $this->assertGreaterThan(1, BaseTest::$shared); 286 } 287 288 /** 289 * Text callback test 290 * 291 * @dataProvider callbackProvider 292 */ 293 public function testTextCallbackWithoutAppend(string $file): void 294 { 295 BaseTest::$shared = 0; 296 297 $response = self::$client->getText($file, [$this, 'callableCallback'], false); 298 299 $this->assertEmpty($response); 300 } 301 302 /** 303 * Main text callback test 304 * 305 * @dataProvider callbackProvider 306 */ 307 public function testMainTextCallback(string $file): void 308 { 309 BaseTest::$shared = 0; 310 311 self::$client->getMainText($file, function() 312 { 313 BaseTest::$shared++; 314 }); 315 316 $this->assertGreaterThan(1, BaseTest::$shared); 317 } 318 319 /** 320 * Main text callback test 321 * 322 * @dataProvider callbackProvider 323 */ 324 public function testHtmlCallback(string $file): void 325 { 326 BaseTest::$shared = 0; 327 328 self::$client->getHtml($file, function() 329 { 330 BaseTest::$shared++; 331 }); 332 333 $this->assertGreaterThan(1, BaseTest::$shared); 334 } 335 336 /** 337 * Remote file test with integrated download 338 * 339 * @dataProvider remoteProvider 340 */ 341 public function testRemoteDocumentText(string $file): void 342 { 343 $this->assertStringContainsString('Rationis enim perfectio est virtus', self::$client->getText($file)); 344 } 345 346 /** 347 * Remote file test with internal downloader 348 * 349 * @dataProvider remoteProvider 350 */ 351 public function testDirectRemoteDocumentText(string $file): void 73 352 { 74 353 $client =& self::$client; 75 354 76 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 77 { 78 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 79 } 80 else 81 { 82 $this->assertInstanceOf("\\Vaites\\ApacheTika\\Metadata\\$class", self::$client->getMetadata($file)); 83 } 84 } 85 86 /** 87 * Metadata test 88 * 89 * @dataProvider documentProvider 90 * 91 * @param string $file 92 * @param string $class 93 * @throws \Exception 94 */ 95 public function testDocumentMetadata($file, $class = 'DocumentMetadata') 355 $client->setDownloadRemote(false); 356 357 $this->assertStringContainsString('Rationis enim perfectio est virtus', $client->getText($file)); 358 } 359 360 /** 361 * Encoding tests 362 * 363 * @dataProvider encodingProvider 364 */ 365 public function testEncodingDocumentText(string $file): void 96 366 { 97 367 $client =& self::$client; 98 368 99 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 100 { 101 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 102 } 103 else 104 { 105 $this->testMetadata($file, $class); 106 } 107 } 108 109 /** 110 * Metadata title test 111 * 112 * @dataProvider documentProvider 113 * 114 * @param string $file 115 * @throws \Exception 116 */ 117 public function testDocumentMetadataTitle($file) 118 { 119 $client =& self::$client; 120 121 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 122 { 123 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 124 } 125 else 126 { 127 $this->assertEquals('Lorem ipsum dolor sit amet', self::$client->getMetadata($file)->title); 128 } 129 } 130 131 /** 132 * Metadata author test 133 * 134 * @dataProvider documentProvider 135 * 136 * @param string $file 137 * @throws \Exception 138 */ 139 public function testDocumentMetadataAuthor($file) 140 { 141 $client =& self::$client; 142 143 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 144 { 145 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 146 } 147 else 148 { 149 $this->assertEquals('David Martínez', self::$client->getMetadata($file)->author); 150 } 151 } 152 153 /** 154 * Metadata dates test 155 * 156 * @dataProvider documentProvider 157 * 158 * @param string $file 159 * @throws \Exception 160 */ 161 public function testDocumentMetadataCreated($file) 162 { 163 $client =& self::$client; 164 165 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 166 { 167 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 168 } 169 else 170 { 171 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->created); 172 } 173 } 174 175 /** 176 * Metadata dates test 177 * 178 * @dataProvider documentProvider 179 * 180 * @param string $file 181 * @throws \Exception 182 */ 183 public function testDocumentMetadataUpdated($file) 184 { 185 $client =& self::$client; 186 187 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 188 { 189 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 190 } 191 else 192 { 193 $this->assertInstanceOf('DateTime', self::$client->getMetadata($file)->updated); 194 } 195 } 196 197 /** 198 * Metadata keywords test 199 * 200 * @dataProvider documentProvider 201 * 202 * @param string $file 203 * @throws \Exception 204 */ 205 public function testDocumentMetadataKeywords($file) 206 { 207 $client =& self::$client; 208 209 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 210 { 211 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 212 } 213 else 214 { 215 $this->assertContains('ipsum', self::$client->getMetadata($file)->keywords); 216 } 217 } 218 219 /** 220 * Language test 221 * 222 * @dataProvider documentProvider 223 * 224 * @param string $file 225 * @throws \Exception 226 */ 227 public function testDocumentLanguage($file) 228 { 229 $client =& self::$client; 230 231 if($client::MODE == 'web' && version_compare(self::$version, '1.9') < 0) 232 { 233 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks REST language identification'); 234 } 235 else 236 { 237 $this->assertRegExp('/^[a-z]{2}$/', self::$client->getLanguage($file)); 238 } 239 } 240 241 /** 242 * MIME test 243 * 244 * @dataProvider documentProvider 245 * 246 * @param string $file 247 * @throws \Exception 248 */ 249 public function testDocumentMIME($file) 250 { 251 $client =& self::$client; 252 253 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 254 { 255 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 256 } 257 else 258 { 259 $this->assertNotEmpty(self::$client->getMIME($file)); 260 } 261 } 262 263 /** 264 * HTML test 265 * 266 * @dataProvider documentProvider 267 * 268 * @param string $file 269 * @throws \Exception 270 */ 271 public function testDocumentHTML($file) 272 { 273 $client =& self::$client; 274 275 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 276 { 277 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 278 } 279 else 280 { 281 $this->assertContains('Zenonis est, inquam, hoc Stoici', self::$client->getHTML($file)); 282 } 283 } 284 285 /** 286 * Text test 287 * 288 * @dataProvider documentProvider 289 * 290 * @param string $file 291 * @throws \Exception 292 */ 293 public function testDocumentText($file) 294 { 295 $client =& self::$client; 296 297 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 298 { 299 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 300 } 301 else 302 { 303 $this->assertContains('Zenonis est, inquam, hoc Stoici', self::$client->getText($file)); 304 } 305 } 306 307 /** 308 * Main text test 309 * 310 * @dataProvider documentProvider 311 * 312 * @param string $file 313 * @throws \Exception 314 */ 315 public function testDocumentMainText($file) 316 { 317 $client =& self::$client; 318 319 if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 320 { 321 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction'); 322 } 323 else 324 { 325 $this->assertContains('Lorem ipsum dolor sit amet', self::$client->getMainText($file)); 326 } 327 } 328 329 /** 330 * Metadata test 331 * 332 * @dataProvider imageProvider 333 * 334 * @param string $file 335 * @param string $class 336 * @throws \Exception 337 */ 338 public function testImageMetadata($file, $class = 'ImageMetadata') 339 { 340 $client =& self::$client; 341 342 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 343 { 344 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 345 } 346 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 347 { 348 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 349 } 350 else 351 { 352 $this->testMetadata($file, $class); 353 } 354 } 355 356 /** 357 * Metadata width test 358 * 359 * @dataProvider imageProvider 360 * 361 * @param string $file 362 * @throws \Exception 363 */ 364 public function testImageMetadataWidth($file) 365 { 366 $client =& self::$client; 367 368 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 369 { 370 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 371 } 372 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 373 { 374 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 375 } 376 else 377 { 378 $meta = self::$client->getMetadata($file); 379 380 $this->assertEquals(1600, $meta->width, basename($file)); 381 } 382 } 383 384 /** 385 * Metadata height test 386 * 387 * @dataProvider imageProvider 388 * 389 * @param string $file 390 * @throws \Exception 391 */ 392 public function testImageMetadataHeight($file) 393 { 394 $client =& self::$client; 395 396 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 397 { 398 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 399 } 400 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 401 { 402 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 403 } 404 else 405 { 406 $meta = self::$client->getMetadata($file); 407 408 $this->assertEquals(900, $meta->height, basename($file)); 409 } 410 } 411 412 /** 413 * OCR test 414 * 415 * @dataProvider ocrProvider 416 * 417 * @param string $file 418 * @throws \Exception 419 */ 420 public function testImageOCR($file) 421 { 422 $client =& self::$client; 423 424 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 425 { 426 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 427 } 428 elseif($client::MODE == 'web' && version_compare(self::$version, '1.14') == 0) 429 { 430 $this->markTestSkipped('Apache Tika 1.14 throws "Expected \';\', got \',\'> when parsing some images'); 431 } 432 else 433 { 434 $text = self::$client->getText($file); 435 436 $this->assertRegExp('/voluptate/i', $text); 437 } 438 } 439 440 /** 441 * Text callback test 442 * 443 * @dataProvider callbackProvider 444 * 445 * @param string $file 446 * @throws \Exception 447 */ 448 public function testTextCallback($file) 449 { 450 $client =& self::$client; 451 452 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 453 { 454 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 455 } 456 else 457 { 458 BaseTest::$shared = 0; 459 460 self::$client->getText($file, [$this, 'callableCallback']); 461 462 $this->assertGreaterThan(1, BaseTest::$shared); 463 } 464 } 465 466 /** 467 * Main text callback test 468 * 469 * @dataProvider callbackProvider 470 * 471 * @param string $file 472 * @throws \Exception 473 */ 474 public function testMainTextCallback($file) 475 { 476 $client =& self::$client; 477 478 if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 479 { 480 $this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction'); 481 } 482 else 483 { 484 BaseTest::$shared = 0; 485 486 self::$client->getMainText($file, function ($chunk) { 487 BaseTest::$shared++; 488 }); 489 490 $this->assertGreaterThan(1, BaseTest::$shared); 491 } 492 } 493 494 /** 495 * Main text callback test 496 * 497 * @dataProvider callbackProvider 498 * 499 * @param string $file 500 * @throws \Exception 501 */ 502 public function testHtmlCallback($file) 503 { 504 $client =& self::$client; 505 506 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 507 { 508 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 509 } 510 else 511 { 512 BaseTest::$shared = 0; 513 514 self::$client->getHtml($file, function($chunk) 515 { 516 BaseTest::$shared++; 517 }); 518 519 $this->assertGreaterThan(1, BaseTest::$shared); 520 } 521 } 522 523 /** 524 * Remote file test with integrated download 525 * 526 * @dataProvider remoteProvider 527 * 528 * @param string $file 529 * @throws \Exception 530 */ 531 public function testRemoteDocumentText($file) 532 { 533 $client =& self::$client; 534 535 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 536 { 537 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 538 } 539 else 540 { 541 $this->assertContains('This is a small demonstration .pdf file', $client->getText($file)); 542 } 543 } 544 545 /** 546 * Remote file test with internal downloader 547 * 548 * @dataProvider remoteProvider 549 * 550 * @param string $file 551 * @throws \Exception 552 */ 553 public function testDirectRemoteDocumentText($file) 554 { 555 $client =& self::$client; 556 557 if($client::MODE == 'web' && version_compare(self::$version, '1.9') == 0) 558 { 559 $this->markTestSkipped('Apache Tika 1.9 throws random "Error while processing document" errors'); 560 } 561 elseif($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0) 562 { 563 $this->markTestSkipped('Apache Tika between 1.10 and 1.14 doesn\'t supports unsecure features'); 564 } 565 else 566 { 567 $client->setDownloadRemote(false); 568 569 $this->assertContains('This is a small demonstration .pdf file', $client->getText($file)); 570 } 369 $client->setEncoding('UTF-8'); 370 371 $this->assertThat($client->getText($file), $this->logicalAnd 372 ( 373 $this->stringContains('L’espéranto'), 374 $this->stringContains('世界語'), 375 $this->stringContains('Эспера́нто') 376 )); 571 377 } 572 378 573 379 /** 574 380 * Test available detectors 575 * 576 * @throws \Exception577 */578 public function testAvailableDetectors()579 { 580 $this->assert Contains('org.apache.tika.mime.MimeTypes', self::$client->getAvailableDetectors());381 */ 382 public function testAvailableDetectors(): void 383 { 384 $detectors = self::$client->getAvailableDetectors(); 385 386 $this->assertArrayHasKey('org.apache.tika.detect.DefaultDetector', $detectors); 581 387 } 582 388 583 389 /** 584 390 * Test available parsers 585 * 586 * @throws \Exception587 */588 public function testAvailableParsers()589 { 590 $this->assert Contains('org.apache.tika.parser.DefaultParser', self::$client->getAvailableParsers());391 */ 392 public function testAvailableParsers(): void 393 { 394 $parsers = self::$client->getAvailableParsers(); 395 396 $this->assertArrayHasKey('org.apache.tika.parser.DefaultParser', $parsers); 591 397 } 592 398 593 399 /** 594 400 * Test supported MIME types 595 * 596 * @throws \Exception 597 */ 598 public function testSupportedMIMETypes() 599 { 600 $this->assertContains('application/x-pdf', self::$client->getSupportedMIMETypes()); 401 */ 402 public function testSupportedMIMETypes(): void 403 { 404 $this->assertArrayHasKey('application/pdf', self::$client->getSupportedMIMETypes()); 405 } 406 407 408 /** 409 * Test supported MIME types 410 */ 411 public function testIsMIMETypeSupported(): void 412 { 413 $this->assertTrue(self::$client->isMIMETypeSupported('application/pdf')); 601 414 } 602 415 603 416 /** 604 417 * Static method to test callback 605 * 606 * @param string $chunk 607 */ 608 public static function callableCallback($chunk) 418 */ 419 public static function callableCallback(): void 609 420 { 610 421 BaseTest::$shared++; … … 613 424 /** 614 425 * Document file provider 615 * 616 * @return array 617 */ 618 public function documentProvider() 426 */ 427 public function documentProvider(): array 619 428 { 620 429 return $this->samples('sample1'); … … 623 432 /** 624 433 * Image file provider 625 * 626 * @return array 627 */ 628 public function imageProvider() 434 */ 435 public function imageProvider(): array 629 436 { 630 437 return $this->samples('sample2'); … … 633 440 /** 634 441 * File provider for OCR testing 635 * 636 * @return array 637 */ 638 public function ocrProvider() 442 */ 443 public function ocrProvider(): array 639 444 { 640 445 return $this->samples('sample3'); … … 643 448 /** 644 449 * File provider for callback testing 645 * 646 * @return array 647 */ 648 public function callbackProvider() 450 */ 451 public function callbackProvider(): array 649 452 { 650 453 return $this->samples('sample5'); … … 653 456 /** 654 457 * File provider for remote testing 655 * 656 * @return array 657 */ 658 public function remoteProvider() 458 */ 459 public function remoteProvider(): array 659 460 { 660 461 return 661 462 [ 662 463 [ 663 'http ://www.africau.edu/images/default/sample.pdf'464 'https://raw.githubusercontent.com/vaites/php-apache-tika/master/samples/sample6.pdf' 664 465 ] 665 466 ]; … … 667 468 668 469 /** 470 * File provider for encoding testing 471 */ 472 public function encodingProvider(): array 473 { 474 return $this->samples('sample7'); 475 } 476 477 /** 478 * File provider for recursive testing 479 */ 480 public function recursiveProvider(): array 481 { 482 return $this->samples('sample8'); 483 } 484 485 /** 669 486 * File provider using "samples" folder 670 * 671 * @param string $sample 672 * @return array 673 */ 674 protected function samples($sample) 487 */ 488 protected function samples(string $sample): array 675 489 { 676 490 $samples = []; -
redisearch/trunk/vendor/vaites/php-apache-tika/tests/CLITest.php
r2002534 r2525480 13 13 * Create shared instances of clients 14 14 */ 15 public static function setUpBeforeClass() 15 public static function setUpBeforeClass(): void 16 16 { 17 17 self::$client = Client::make(self::getPathForVersion(self::$version)); … … 19 19 20 20 /** 21 * XHTML test 22 * 23 * @dataProvider encodingProvider 24 */ 25 public function testDocumentHTML(string $file): void 26 { 27 $this->assertStringStartsWith('<?xml version="1.0"', self::$client->getXHTML($file)); 28 } 29 30 /** 21 31 * Set path test 22 32 */ 23 public function testSetPath() 33 public function testSetPath(): void 24 34 { 25 $ client = Client::make(self::getPathForVersion('1.0'));35 $path = self::getPathForVersion(self::$version); 26 36 27 $this->assertEquals(self::getPathForVersion('1.0'), $client->getPath()); 37 $client = Client::make($path); 38 39 $this->assertEquals($path, $client->getPath()); 28 40 } 29 41 … … 31 43 * Set Java test 32 44 */ 33 public function testSet Port()45 public function testSetBinary(): void 34 46 { 35 $ client = Client::make(self::getPathForVersion('1.0'), '/opt/jdk/bin/java');47 $path = self::getPathForVersion(self::$version); 36 48 37 $this->assertEquals('/opt/jdk/bin/java', $client->getJava()); 49 $client = Client::make($path, 'java'); 50 51 $this->assertEquals('java', $client->getJava()); 52 } 53 54 /** 55 * Set Java test 56 */ 57 public function testSetArguments(): void 58 { 59 $path = self::getPathForVersion(self::$version); 60 61 $client = Client::make($path); 62 $client->setJavaArgs('-JXmx4g'); 63 64 $this->assertEquals('-JXmx4g', $client->getJavaArgs()); 65 } 66 67 /** 68 * Test delayed check 69 */ 70 public function testDelayedCheck(): void 71 { 72 $path = self::getPathForVersion(self::$version); 73 74 $client = Client::prepare('/nonexistent/path/to/apache-tika.jar'); 75 $client->setPath($path); 76 77 $this->assertStringEndsWith(self::$version, $client->getVersion()); 38 78 } 39 79 40 80 /** 41 81 * Get the full path of Tika app for a specified version 42 *43 * @param string $version44 * @return string45 82 */ 46 private static function getPathForVersion( $version)83 private static function getPathForVersion(string $version): string 47 84 { 48 85 return self::$binaries . "/tika-app-{$version}.jar"; -
redisearch/trunk/vendor/vaites/php-apache-tika/tests/CommonTest.php
r2002534 r2525480 1 1 <?php namespace Vaites\ApacheTika\Tests; 2 2 3 use PHPUnit _Framework_TestCase;3 use PHPUnit\Framework\TestCase; 4 4 5 5 use Vaites\ApacheTika\Client; … … 8 8 * Common test functionality 9 9 */ 10 class CommonTest extends PHPUnit_Framework_TestCase10 class CommonTest extends TestCase 11 11 { 12 12 /** … … 33 33 /** 34 34 * Get env variables 35 *36 * @param null $name37 * @param array $data38 * @param string $dataName39 * @throws \Exception40 35 */ 41 public function __construct( $name = null, array $data = array(), $dataName = '')36 public function __construct(string $name = null, array $data = array(), $dataName = '') 42 37 { 43 38 self::$version = getenv('APACHE_TIKA_VERSION'); … … 51 46 * Set chunk size test 52 47 */ 53 public function testSetChunkSize() 48 public function testSetChunkSize(): void 54 49 { 55 50 self::$client->setChunkSize(42); … … 59 54 60 55 /** 56 * Set download remote 57 */ 58 public function testDownloadRemote(): void 59 { 60 self::$client->setDownloadRemote(true); 61 62 $this->assertTrue(self::$client->getDownloadRemote()); 63 } 64 65 /** 61 66 * Set callback (closure) test 62 67 */ 63 public function testSetClosureCallback() 68 public function testSetClosureCallback(): void 64 69 { 65 70 self::$client->setCallback(function($chunk) … … 74 79 * Set callback (callable) test 75 80 */ 76 public function testSetCallableCallback() 81 public function testSetCallableCallback(): void 77 82 { 78 83 self::$client->setCallback('trim'); … … 84 89 * Get supported versions test 85 90 */ 86 public function testGetSupportedVersions() 91 public function testGetSupportedVersions(): void 87 92 { 88 $this->assertTrue(in_array( '1.10', Client::getSupportedVersions()));93 $this->assertTrue(in_array(self::$version, self::$client->getSupportedVersions())); 89 94 } 90 95 … … 92 97 * Is version supported vtest 93 98 */ 94 public function testIsVersionSupported() 99 public function testIsVersionSupported(): void 95 100 { 96 $this->assertTrue( Client::isVersionSupported('1.10'));101 $this->assertTrue(self::$client->isVersionSupported(self::$version)); 97 102 } 98 103 } -
redisearch/trunk/vendor/vaites/php-apache-tika/tests/ErrorTest.php
r2002534 r2525480 2 2 3 3 use Exception; 4 use PHPUnit_Framework_TestCase; 4 5 use PHPUnit\Framework\TestCase; 5 6 6 7 use Vaites\ApacheTika\Client; … … 10 11 * Error tests 11 12 */ 12 class ErrorTest extends PHPUnit_Framework_TestCase13 class ErrorTest extends TestCase 13 14 { 14 15 /** … … 28 29 /** 29 30 * Get env variables 30 * 31 * @param null $name 32 * @param array $data 33 * @param string $dataName 34 */ 35 public function __construct($name = null, array $data = array(), $dataName = '') 31 */ 32 public function __construct(string $name = null, array $data = array(), $dataName = '') 36 33 { 37 34 self::$version = getenv('APACHE_TIKA_VERSION'); … … 44 41 * Test wrong command line mode path 45 42 */ 46 public function testAppPath() 47 { 48 try 49 { 50 $client = Client:: make('/nonexistent/path/to/apache-tika.jar');43 public function testAppPath(): void 44 { 45 try 46 { 47 $client = Client::prepare('/nonexistent/path/to/apache-tika.jar'); 51 48 $client->getVersion(); 52 49 } 53 50 catch(Exception $exception) 54 51 { 55 $this->assert Contains('Unexpected exit value', $exception->getMessage());52 $this->assertStringContainsString('Apache Tika app JAR not found', $exception->getMessage()); 56 53 } 57 54 } … … 60 57 * Test unexpected exit value for command line mode 61 58 */ 62 public function testAppExitValue() 59 public function testAppExitValue(): void 63 60 { 64 61 $path = self::getPathForVersion(self::$version); … … 76 73 rename($path . '.bak', $path); 77 74 78 $this->assert Contains('Unexpected exit value', $exception->getMessage());75 $this->assertStringContainsString('Unexpected exit value', $exception->getMessage()); 79 76 } 80 77 } … … 83 80 * Test invalid Java binary path for command line mode 84 81 */ 85 public function test AppJavaBinary()82 public function testJavaBinary(): void 86 83 { 87 84 $path = self::getPathForVersion(self::$version); … … 94 91 catch(Exception $exception) 95 92 { 96 $this->assert Contains('Unexpected exit value', $exception->getMessage());93 $this->assertStringContainsString('Java command not found', $exception->getMessage()); 97 94 } 98 95 } … … 101 98 * Test wrong server 102 99 */ 103 public function testServerConnection() 104 { 105 try 106 { 107 Client::make('localhost', 9997); 108 109 $this->fail(); 110 } 111 catch(Exception $exception) 112 { 113 $this->assertEquals(7, $exception->getCode()); 100 public function testServerConnection(): void 101 { 102 try 103 { 104 $client = Client::prepare('localhost', 9997); 105 $client->getVersion(); 106 107 $this->fail(); 108 } 109 catch(Exception $exception) 110 { 111 $this->assertThat($exception->getCode(), $this->logicalOr 112 ( 113 $this->equalTo(CURLE_COULDNT_CONNECT), 114 $this->equalTo(CURLE_OPERATION_TIMEDOUT) 115 )); 114 116 } 115 117 } … … 118 120 * Test wrong request options 119 121 */ 120 public function testRequestOptions() 121 { 122 try 123 { 124 $client = Client::make('localhost', 9998 , [CURLOPT_PROXY => 'localhost']);122 public function testRequestOptions(): void 123 { 124 try 125 { 126 $client = Client::make('localhost', 9998); 125 127 $client->request('bad'); 126 128 … … 129 131 catch(Exception $exception) 130 132 { 131 $this->assert Equals(7, $exception->getCode());133 $this->assertStringContainsString('Unknown type bad', $exception->getMessage()); 132 134 } 133 135 } … … 136 138 * Test invalidrequest options 137 139 */ 138 public function testRequestRestrictedOptions() 139 { 140 try 141 { 142 $client =Client::make('localhost', 9998, [CURLOPT_PUT => false]);140 public function testRequestRestrictedOptions(): void 141 { 142 try 143 { 144 Client::make('localhost', 9998, [CURLOPT_PUT => false]); 143 145 } 144 146 catch(Exception $exception) … … 149 151 150 152 /** 153 * Test wrong recursive metadata type 154 */ 155 public function testRequestMetadataType(): void 156 { 157 try 158 { 159 $client = Client::make('localhost', 9998); 160 $client->getRecursiveMetadata(dirname(__DIR__) . '/samples/sample3.png', 'bad'); 161 162 $this->fail(); 163 } 164 catch(Exception $exception) 165 { 166 $this->assertStringContainsString('Unknown recursive type', $exception->getMessage()); 167 } 168 } 169 170 /** 151 171 * Test unsupported media type 152 */ 153 public function testUnsupportedMedia() 172 * 173 * NOTE: return value was changed in version 1.23 174 * 175 * @link https://github.com/apache/tika/blob/master/CHANGES.txt 176 */ 177 public function testUnsupportedMedia(): void 154 178 { 155 179 try … … 162 186 catch(Exception $exception) 163 187 { 164 $this->assertEquals(415, $exception->getCode()); 165 } 166 } 167 168 /** 169 * Test invalid callback 170 */ 171 public function testInvalidCallback() 172 { 173 try 174 { 175 $client = Client::make(self::$binaries . '/tika-app-' . self::$version . '.jar'); 176 $client->setCallback('unknown_function'); 177 } 178 catch(Exception $exception) 179 { 180 $this->assertContains('Invalid callback', $exception->getMessage()); 188 if(version_compare(self::$version, '1.23') < 0) 189 { 190 $this->assertEquals(415, $exception->getCode()); 191 } 192 else 193 { 194 $this->assertEquals(0, $exception->getCode()); 195 } 196 } 197 } 198 199 /** 200 * Test unknown recursive metadata type 201 */ 202 public function testUnknownRecursiveMetadataType(): void 203 { 204 try 205 { 206 $client = Client::make('localhost', 9998); 207 $client->getRecursiveMetadata('example.doc', 'error'); 208 209 $this->fail(); 210 } 211 catch(Exception $exception) 212 { 213 $this->assertStringContainsString('Unknown recursive type', $exception->getMessage()); 181 214 } 182 215 } … … 185 218 * Test invalid chunk size 186 219 */ 187 public function testInvalidChunkSize() 188 { 189 try 190 { 191 $client = Client::make(self::$binaries . '/tika-app-' . self::$version . '.jar'); 192 $client->setChunkSize('string'); 193 } 194 catch(Exception $exception) 195 { 196 $this->assertContains('is not a valid chunk size', $exception->getMessage()); 197 } 198 } 199 200 /** 201 * Test invalid chunk size 202 */ 203 public function testUnsupportedChunkSize() 220 public function testUnsupportedChunkSize(): void 204 221 { 205 222 try … … 210 227 catch(Exception $exception) 211 228 { 212 $this->assertContains('Chunk size is not supported', $exception->getMessage()); 213 } 214 } 215 216 /** 217 * Test invalid metadata 218 */ 219 public function testInvalidMetadata() 220 { 221 try 222 { 223 $metadata = Metadata::make('InvalidJsonString', './samples/sample1.doc'); 224 } 225 catch(Exception $exception) 226 { 227 $this->assertEquals(JSON_ERROR_SYNTAX, $exception->getCode()); 228 } 229 } 230 231 /** 232 * Test empty metadata 233 */ 234 public function testEmptyMetadata() 235 { 236 try 237 { 238 $metadata = Metadata::make('', './samples/sample1.doc'); 239 } 240 catch(Exception $exception) 241 { 242 $this->assertContains('Empty response', $exception->getMessage()); 229 $this->assertStringContainsString('Chunk size is not supported', $exception->getMessage()); 243 230 } 244 231 } … … 248 235 * 249 236 * @dataProvider parameterProvider 250 * 251 * @param array $parameters 252 */ 253 public function testRequestType($parameters) 237 */ 238 public function testRequestType(array $parameters): void 254 239 { 255 240 try … … 262 247 catch(Exception $exception) 263 248 { 264 $this->assert Contains('Unknown type bad', $exception->getMessage());249 $this->assertStringContainsString('Unknown type bad', $exception->getMessage()); 265 250 } 266 251 } … … 270 255 * 271 256 * @dataProvider parameterProvider 272 * 273 * @param array $parameters 274 */ 275 public function testLocalFile($parameters) 257 */ 258 public function testLocalFile(array $parameters): void 276 259 { 277 260 try … … 292 275 * 293 276 * @dataProvider parameterProvider 294 * 295 * @param array $parameters 296 */ 297 public function testRemoteFile($parameters) 277 */ 278 public function testRemoteFile(array $parameters): void 298 279 { 299 280 try … … 312 293 /** 313 294 * Client parameters provider 314 * 315 * @return array 316 */ 317 public function parameterProvider() 295 */ 296 public function parameterProvider(): array 318 297 { 319 298 return … … 326 305 /** 327 306 * Get the full path of Tika app for a specified version 328 * 329 * @param string $version 330 * @return string 331 */ 332 private static function getPathForVersion($version) 307 */ 308 private static function getPathForVersion(string $version): string 333 309 { 334 310 return self::$binaries . "/tika-app-{$version}.jar"; -
redisearch/trunk/vendor/vaites/php-apache-tika/tests/WebTest.php
r2002534 r2525480 15 15 * Start Tika server and create shared instance of clients 16 16 */ 17 public static function setUpBeforeClass() 17 public static function setUpBeforeClass(): void 18 18 { 19 19 self::$client = Client::make('localhost', 9998, [CURLOPT_TIMEOUT => 30]); … … 23 23 * cURL multiple options test 24 24 */ 25 public function testCurlOptions() 25 public function testCurlOptions(): void 26 26 { 27 27 $client = Client::make('localhost', 9998, [CURLOPT_TIMEOUT => 3]); … … 34 34 * cURL single option test 35 35 */ 36 public function testCurlSingleOption() 36 public function testCurlSingleOption(): void 37 37 { 38 38 $client = Client::make('localhost', 9998)->setOption(CURLOPT_TIMEOUT, 3); … … 44 44 * cURL timeout option test 45 45 */ 46 public function testCurlTimeoutOption() 46 public function testCurlTimeoutOption(): void 47 47 { 48 48 $client = Client::make('localhost', 9998)->setTimeout(3); … … 54 54 * cURL headers test 55 55 */ 56 public function testCurlHeaders() 56 public function testCurlHeaders(): void 57 57 { 58 58 $header = 'Content-Type: image/jpeg'; … … 67 67 * Set host test 68 68 */ 69 public function testSetHost() 69 public function testSetHost(): void 70 70 { 71 71 $client = Client::make('localhost', 9998); … … 78 78 * Set port test 79 79 */ 80 public function testSetPort() 80 public function testSetPort(): void 81 81 { 82 82 $client = Client::make('localhost', 9998); … … 87 87 88 88 /** 89 * Set url host test 90 */ 91 public function testSetUrlHost(): void 92 { 93 $client = Client::make('http://localhost:9998'); 94 95 $this->assertEquals('localhost', $client->getHost()); 96 } 97 98 /** 99 * Set url port test 100 */ 101 public function testSetUrlPort(): void 102 { 103 $client = Client::make('http://localhost:9998'); 104 105 $this->assertEquals(9998, $client->getPort()); 106 } 107 108 /** 89 109 * Set retries test 90 110 */ 91 public function test RetriesPort()111 public function testSetRetries(): void 92 112 { 93 113 $client = Client::make('localhost', 9998); … … 96 116 $this->assertEquals(5, $client->getRetries()); 97 117 } 118 119 /** 120 * Test delayed check 121 */ 122 public function testDelayedCheck(): void 123 { 124 $client = Client::prepare('localhost', 9997); 125 $client->setPort(9998); 126 127 $this->assertStringEndsWith(self::$version, $client->getVersion()); 128 } 98 129 } -
redisearch/trunk/wp-redisearch.php
r2455651 r2525480 2 2 /* 3 3 Plugin Name: RediSearch 4 Version: 0.3. 24 Version: 0.3.3 5 5 Description: Replace Wordpress search by RediSearch. 6 6 Author: Foad Yousefi … … 29 29 // Plugin version . 30 30 if ( ! defined( 'WPRS_VERSION' ) ) { 31 define( 'WPRS_VERSION', '0.3. 2' );31 define( 'WPRS_VERSION', '0.3.3' ); 32 32 } 33 33
Note: See TracChangeset
for help on using the changeset viewer.