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

Feature: disallow serialization #1

Merged
merged 47 commits into from
Oct 11, 2016
Merged

Feature: disallow serialization #1

merged 47 commits into from
Oct 11, 2016

Conversation

Ocramius
Copy link
Member

@Ocramius Ocramius commented Oct 11, 2016

This PR introduces:

  • Dont\Serialize
  • Dont\DeSerialize

TODOs:

  • code review
  • do Serialize and DeSerialize imply each other? not for now, maybe in 2.x.
  • introduce humbug testing (mandatory)
  • documentation
  • repository description

* @throws NonDeSerializableObject
* @throws TypeError
*/
final public function __wakeup()
Copy link
Collaborator

Choose a reason for hiding this comment

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

return type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't: void is only 7.1, although we could make the lib 7.1 only.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 for 7.1

Copy link
Member

Choose a reason for hiding this comment

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

Another 👍 to allow : void return decl

Copy link
Member Author

Choose a reason for hiding this comment

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

Done with 7.1 bump

*
* @return self
*/
public static function fromNonObject($object) : self
Copy link
Collaborator

Choose a reason for hiding this comment

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

currently $object is not an object

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, will fix!

* @throws NonSerializableObject
* @throws TypeError
*/
final public function __sleep()
Copy link
Collaborator

Choose a reason for hiding this comment

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

return type void?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't unless we force 7.1

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to 7.1

use Dont\Exception\NonDeSerializableObject;
use Dont\Exception\TypeError;

trait DeSerialize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be unserialize instead

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed, deserialize would be proper English, while PHP has its own unserialize wording. Unsure about the wording to adopt for now. @asgrim, can you give us an opinion?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Better preserve php strangeness as it's more intuitive for php developers IMHO

Choose a reason for hiding this comment

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

We could always create an alias ? But i'm going to agree with @Ocramius for the simple reason I would be annoyed with phpstorm including the wrong thing.

Copy link

Choose a reason for hiding this comment

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

Deserialise is the correct word. However you can have the version with the z if you must…

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 could fancy a British lib...

Copy link
Member

Choose a reason for hiding this comment

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

Acceptable to me in selfish preference order: Deserialise Deserialize Unserialise Unserialize (note, no capital S in any)

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with Deserialise, to be non-brexit-compliant

Copy link
Member

Choose a reason for hiding this comment

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

Deserialise is UK English btw, Deserialize is American, so technically, it's now Brexit-compliant 👍 🇬🇧

The given object %s#%s is not designed to be de-serialized, yet de-serialization was attempted.

This error is raised because the author of %s didn't design it to be de-serializable, nor can
guarantee that it will function correctly after de-serialization, nor can guarantee that all
Copy link
Collaborator

@malukenho malukenho Oct 11, 2016

Choose a reason for hiding this comment

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

function mean work?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it will function and it will work are synonyms

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 😄

@macnibblet
Copy link

Whats the general purpose of this library ? Apart from the obvious :)

@Ocramius
Copy link
Member Author

Ocramius commented Oct 11, 2016

@macnibblet the idea is to:

final class MyFantasticService implements TheService
{
    use \Dont\Serialize;
    use \Dont\DeSerialize;
    use \Dont\Clone;

    public function __construct(Db $theDb) { /* ... */ }
    // ...
}

@macnibblet
Copy link

@Ocramius Copy from what I wrote in IRC, if you import the classes you end up with Serialize; Deserialize; Clone; I suggest you retain the Dont prefix in the trait names

@@ -0,0 +1,35 @@
{
"name": "roave/don-t",
Copy link
Member

Choose a reason for hiding this comment

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

grammar is hard, but IMO roave/dont is easier to remember package name

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 can live with roave/dont

],
"authors": [
{
"name": "Marco Pivetta",
Copy link
Member

Choose a reason for hiding this comment

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

Typo in your surname there, should be Pivetti :trollface:

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

}
],
"require": {
"php": "7.*"
Copy link
Member

@asgrim asgrim Oct 11, 2016

Choose a reason for hiding this comment

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

^7.0|^7.1 maybe, adding future versions as they appear?

Copy link
Member

Choose a reason for hiding this comment

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

In fact, mandating just ^7.1 could mean using void return type further down?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can probably push to 7.1. This package is initially to be deployed as part of ocramius/proxy-manager for a version that only supports PHP 7.1+

use Dont\Exception\NonDeSerializableObject;
use Dont\Exception\TypeError;

trait DeSerialize
Copy link
Member

Choose a reason for hiding this comment

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

Acceptable to me in selfish preference order: Deserialise Deserialize Unserialise Unserialize (note, no capital S in any)

* @throws NonDeSerializableObject
* @throws TypeError
*/
final public function __wakeup()
Copy link
Member

Choose a reason for hiding this comment

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

Another 👍 to allow : void return decl


use LogicException;

class NonDeSerializableObject extends LogicException implements ExceptionInterface
Copy link
Member

Choose a reason for hiding this comment

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

Amend naming as discussed above (especially removing capital S)

{
public function testWillThrowOnSerializationAttempt()
{
$object = new NotSerializable();
Copy link
Member

@asgrim asgrim Oct 11, 2016

Choose a reason for hiding this comment

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

Do we need the assignment? just serialize(new NotSerializable()); on L22 should suffice

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't want to make it seem like the constructor caused the exception

throw TypeError::fromNonObject($object);
}

$template = <<<'ERROR'
Copy link
Member

Choose a reason for hiding this comment

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

I get the purpose, but these messages are really verbose... Surely a simple %s objects should not be (de)serialized would suffice? Make the point, but in less characters basically...

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea of the lengthy message is to make this REALLY obnoxiously clear to the reader. There must be no issue opened by people asking why this kind of thing is being thrown (which is the reason why I started working on the package in first place)

/**
* Marker interface for exceptions thrown by the Dont package
*/
interface ExceptionInterface extends Throwable
Copy link
Member

Choose a reason for hiding this comment

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

What advantage does this interface give?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a marker interface - provides generic "group by" and catch-all for the package, should anybody want to do that.

@asgrim asgrim removed their assignment Oct 11, 2016
use Dont\Exception\NonDeSerializableObject;
use Dont\Exception\TypeError;

trait DontDeSerialize
Copy link
Member

@asgrim asgrim Oct 11, 2016

Choose a reason for hiding this comment

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

Should be DontDeserialize imo (no cap on Serialize), the word is "deserialize" not "de-serialize" afaik


use Dont\DontSerialise;

final class NotSerialisable

Choose a reason for hiding this comment

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

Serialisable => Serializable (https://en.wiktionary.org/wiki/serializable)

Copy link
Member Author

@Ocramius Ocramius Oct 11, 2016

Choose a reason for hiding this comment

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

Just moved to Serialisable as per @asgrim and @akrabat review.

Copy link
Member

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

I guess the s spelling is British, but PHP uses the z spelling.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, we discussed already :) #1 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we just went with the brit approach:
bd4567

@Ocramius Ocramius merged commit f969755 into master Oct 11, 2016
@Ocramius Ocramius deleted the feature/dont-serialize branch October 11, 2016 11:23
@Ocramius Ocramius assigned Ocramius and unassigned malukenho Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants