Skip to content

Commit fad7f0a

Browse files
committed
support use of "-" in arg names
php-vips 1.x used to allow "-" as a component separator in arg names, but we forgot to implement this in v2. Thanks andrews05 See #153
1 parent e2874ce commit fad7f0a

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `:vips` will be documented in this file.
44

5+
## master
6+
7+
- allow "-" as a name component separator [andrews05]
8+
59
## 2.0.3 - 2022-07-04
610

711
- Fix on Windows [kleisauke]

install-vips.sh

-25
This file was deleted.

src/Introspect.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public function __construct($operation_name)
121121
$argumentFlags = [];
122122
for ($i = 0; $i < $n_args; $i++) {
123123
if (($p_flags[$i] & ArgumentFlags::CONSTRUCT) != 0) {
124-
# libvips uses '-' to separate parts of arg names, but we
125-
# need '_' for php
124+
# make sure we're using "_" to separate arg components, though
125+
# I think libvips is "_" everywhere now
126126
$name = \FFI::string($p_names[$i]);
127127
$name = str_replace("-", "_", $name);
128128
$argumentFlags[$name] = $p_flags[$i];

src/VipsObject.php

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function getDescription(): string
9191
// FIXME add a cache for this thing
9292
public function getPspec(string $name): ?\FFI\CData
9393
{
94+
$name = str_replace("-", "_", $name);
9495
$pspec = Config::gobject()->new("GParamSpec*[1]");
9596
$argument_class = Config::vips()->new("VipsArgumentClass*[1]");
9697
$argument_instance = Config::vips()->new("VipsArgumentInstance*[1]");
@@ -140,6 +141,7 @@ public function getArgumentDescription(string $name): string
140141
*/
141142
public function get(string $name)
142143
{
144+
$name = str_replace("-", "_", $name);
143145
$gvalue = new GValue();
144146
$gvalue->setType($this->getType($name));
145147

@@ -159,6 +161,7 @@ public function set(string $name, $value): void
159161
{
160162
Utils::debugLog("set", [$name => $value]);
161163

164+
$name = str_replace("-", "_", $name);
162165
$gvalue = new GValue();
163166
$gvalue->setType($this->getType($name));
164167
$gvalue->set($value);

src/VipsOperation.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public static function callBase(
290290
/* Set optional.
291291
*/
292292
foreach ($options as $name => $value) {
293+
$name = str_replace("-", "_", $name);
293294
if (!in_array($name, $operation->introspect->optional_input) &&
294295
!in_array($name, $operation->introspect->optional_output)) {
295296
$operation->unrefOutputs();
@@ -324,6 +325,7 @@ public static function callBase(
324325
*/
325326
$option_keys = array_keys($options);
326327
foreach ($operation->introspect->optional_output as $name) {
328+
$name = str_replace("-", "_", $name);
327329
if (in_array($name, $option_keys)) {
328330
$result[$name] = $operation->get($name);
329331
}
@@ -335,7 +337,9 @@ public static function callBase(
335337

336338
$result = self::wrapResult($result);
337339

338-
Utils::debugLog($operation_name, ['result' => var_export($result, true)]);
340+
Utils::debugLog($operation_name, [
341+
'result' => var_export($result, true)
342+
]);
339343

340344
return $result;
341345
}

tests/CallTest.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ class CallTest extends TestCase
1010
public function testVipsCall()
1111
{
1212
$image = Vips\Image::newFromArray([1, 2, 3]);
13-
$image = $image->embed(10, 20, 3000, 2000, ['extend' => Vips\Extend::COPY]);
13+
$image = $image->embed(10, 20, 3000, 2000, [
14+
'extend' => Vips\Extend::COPY
15+
]);
1416

1517
$this->assertEquals($image->width, 3000);
1618
$this->assertEquals($image->height, 2000);
1719
$this->assertEquals($image->bands, 1);
1820
}
1921

22+
public function testVipsCallHyphen()
23+
{
24+
# should work with "-" as well as "_"
25+
$image = Vips\Image::worley(64, 64, [
26+
"cell-size" => 8
27+
]);
28+
29+
$this->assertEquals($image->width, 64);
30+
$this->assertEquals($image->height, 64);
31+
$this->assertEquals($image->bands, 1);
32+
}
33+
2034
public function testVipsCallStatic()
2135
{
2236
$image = Vips\Image::black(1, 4, ['bands' => 3]);

0 commit comments

Comments
 (0)