Skip to content

Commit

Permalink
Remove deprecated usage of functions calling $it->next()
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jul 7, 2024
1 parent 6a52ec0 commit e252a80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 67 deletions.
21 changes: 6 additions & 15 deletions src/main/php/util/address/ByAddresses.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace util\address;

use ReflectionFunction;
use Generator;

/** Base class for ValueOf, ObjectOf and RecordOf */
abstract class ByAddresses implements Definition {
Expand All @@ -9,30 +9,19 @@ abstract class ByAddresses implements Definition {
/** @param [:function(var, ?string): Generator] */
public function __construct($addresses) {
foreach ($addresses as $path => $address) {
$this->add($path, new ReflectionFunction($address), $address);
$this->add($path, $address);
}
}

/**
* Add a given address function for a given path or a list of paths.
*
* @param string $path
* @param ReflectionFunction $reflect
* @param function(var, ?string): Generator $address
*/
protected function add($path, $reflect, $address) {
if ($reflect->isGenerator()) {
$handler= $address;
} else {
'/' === $path || trigger_error('Use function(var, string) instead!', E_USER_DEPRECATED);
$handler= function(&$result, $path, $iteration) use($address) {
$address($result, $iteration, $path);
return [];
};
}

protected function add($path, $address) {
foreach (explode('|', $path) as $match) {
$this->addresses[$match]= $handler;
$this->addresses[$match]= $address;
}
}

Expand All @@ -47,6 +36,8 @@ protected function add($path, $reflect, $address) {
*/
protected function invoke($address, &$result, $iteration, $path) {
$r= $address($result, $path, $iteration);
if (!($r instanceof Generator)) return;

foreach ($r as $definition) {
$r->send($iteration->next($definition));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/util/address/ObjectOf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($type, array $addresses) {
$class= $this->type->literal();
foreach ($addresses as $path => $address) {
$reflect= new ReflectionFunction($address);
$this->add($path, $reflect, $address->bindTo($reflect->getClosureThis(), $class));
$this->add($path, $address->bindTo($reflect->getClosureThis(), $class));
}
}

Expand Down
51 changes: 0 additions & 51 deletions src/test/php/util/address/unittest/UsingNextTest.class.php

This file was deleted.

0 comments on commit e252a80

Please sign in to comment.