Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace object-like array with class #79

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 28, 2022

The new class is templatable, which should enable us to specify that the
ORM Lexer is an Lexer<self::T_*>, and in the future, define an enum
called TokenType in the ORM, and switch to Lexer<TokenType>.

@greg0ire greg0ire added this to the 2.0.0 milestone Nov 28, 2022
* @template T of string|int
* @implements ArrayAccess<string,mixed>
*/
final class Token implements ArrayAccess, Countable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I will remove Countable, as ArrayAccess should be enough to easily implement a forward-compatibility layer.

@greg0ire greg0ire force-pushed the token-class branch 2 times, most recently from e99786b to 65f3cdc Compare November 28, 2022 21:57
* @template T of string|int
* @implements ArrayAccess<string,mixed>
*/
final class Token implements ArrayAccess
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although no BC-layer will be provided, implementing ArrayAccess should allow to easily make dependent packages compatible with lexer 1 and 2 at the same time.

@derrabus
Copy link
Member

We should try to ship this change in 1.x. It would be unfortunate if we needed to ship 2.x with a BC layer.

@greg0ire
Copy link
Member Author

We should try to ship this change in 1.x. It would be unfortunate if we needed to ship 2.x with a BC layer.

I think we are going to need a 3.x very soon, because inheritance is involved: the ORM lexer extends the AbstractLexer, which means that if we add return type hints on 3.x, we will make it impossible for doctrine/orm to be compatible with both v1 and v2 at the same time, just like here: doctrine/collections#331

For that reason, I think it's not that big of a deal to have that BC layer on 2.x, since that series is supposed to be short-lived.

If you can think of a way to ship this change in 1.x, I'm still interested though.

@greg0ire greg0ire marked this pull request as draft November 29, 2022 20:19
@greg0ire
Copy link
Member Author

I'm working on a solution to ship this in 1.x

@greg0ire greg0ire marked this pull request as ready for review November 30, 2022 20:09
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that one. Having 2.x as an interim version sounds reasonable.

tests/Doctrine/Common/Lexer/TokenTest.php Outdated Show resolved Hide resolved
The new class is templatable, which should enable us to specify that the
ORM Lexer is an Lexer<self::T_*>, and in the future, define an enum
called TokenType in the ORM, and switch to Lexer<TokenType>.
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to hear what other reviewers have to add.

@greg0ire
Copy link
Member Author

greg0ire commented Dec 8, 2022

ping @derrabus are you fine with this?

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better idea right now. 🙂

@greg0ire greg0ire merged commit c63c80d into doctrine:2.0.x Dec 9, 2022
@greg0ire greg0ire deleted the token-class branch December 9, 2022 12:53
}

/** @param T ...$types */
public function isA(...$types): bool

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this be inA() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi mate! No it's isA, just like https://www.php.net/manual/en/function.is-a.php (but with several types) 🙂

ruudk added a commit to ruudk/serializer that referenced this pull request Jun 2, 2023
By requiring `doctrine/lexer` v2 we can solve the following deprecation:
```
Accessing Doctrine\Common\Lexer\Token properties via ArrayAccess is deprecated, use the value, type or position property instead (Token.php:104 called by Parser.php:46, doctrine/lexer#79, package doctrine/lexer)
```
ruudk added a commit to ruudk/serializer that referenced this pull request Jun 2, 2023
By requiring `doctrine/lexer` v2 we can solve the following deprecation:
```
Accessing Doctrine\Common\Lexer\Token properties via ArrayAccess is deprecated, use the value, type or position property instead (Token.php:104 called by Parser.php:46, doctrine/lexer#79, package doctrine/lexer)
```
ruudk added a commit to ruudk/serializer that referenced this pull request Jun 6, 2023
By requiring `doctrine/lexer` v2 we can solve the following deprecation:
```
Accessing Doctrine\Common\Lexer\Token properties via ArrayAccess is deprecated, use the value, type or position property instead (Token.php:104 called by Parser.php:46, doctrine/lexer#79, package doctrine/lexer)
```
ruudk added a commit to ruudk/serializer that referenced this pull request Jun 7, 2023
By requiring `doctrine/lexer` v2 we can solve the following deprecation:
```
Accessing Doctrine\Common\Lexer\Token properties via ArrayAccess is deprecated, use the value, type or position property instead (Token.php:104 called by Parser.php:46, doctrine/lexer#79, package doctrine/lexer)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants