GithubHelp home page GithubHelp logo

Comments (8)

chanmix51 avatar chanmix51 commented on August 20, 2024

AFAIU, the entity is persisted and has been modified in memory so

$entity->getStatus() & FlexibleEntityInterface::STATUS_EXIST; // return true
$entity->getStatus() & FlexibleEntityInterface::STATUS_MODIFIED; // return true as well

So status is a linear combination of 1×1 + 1×2 = 3 (both modified and persisted).

Is there something I am missing ?

from modelmanager.

ishenkoyv avatar ishenkoyv commented on August 20, 2024

There is no such status as 3 and if I call get method I want to get current status without bitwise operations. Check your phpdoc for FlexibleEntityInterface::status(). Also StatefulEntityTrait::status() method should check for available statuses before assign new value.

from modelmanager.

chanmix51 avatar chanmix51 commented on August 20, 2024

That's true, the doc block doesn't state it can also be a combination of 4 different possible states:
0 = none
1 = persisted
2 = modified
3 = persisted + modified

If a new state is needed (let's say TAINTED) it would be 4 and this will give 8 possible states for the FlexibleEntity. I am going to make the doc block more meaningful about that.

There used to be isModified() and isPersisted() methods in Pomm 1 but they are not present in Pomm2 since using bitwise operations with named constants makes the code self explained and more flexible.

True, the status($status) method does not validate the status. Since the status mechanism is extensible I think it would be a problem to limit the status system. Any ideas ?

from modelmanager.

ishenkoyv avatar ishenkoyv commented on August 20, 2024

https://github.com/pomm-project/ModelManager/blob/master/sources/lib/Model/FlexibleEntity/StatefulEntityTrait.php#L34
Is it ok that we can assign any value to state?

from modelmanager.

chanmix51 avatar chanmix51 commented on August 20, 2024

I have updated my previous post on that topic. From my point of view, yes it is ok since developers can declare new netmask constants(4, 8, 16 etc.) so I feel like setting unknown value to status (let's say 255) will still be at least PERSISTED and MODIFIED with unknown other states so it doesn't break the actual status mechanism.

Any other opinions welcome.

from modelmanager.

chanmix51 avatar chanmix51 commented on August 20, 2024

You mean it would be nice to cast the parameter as an int to compensate for PHP lack of type check ?

from modelmanager.

ishenkoyv avatar ishenkoyv commented on August 20, 2024

Yes, at least. It would be great to have code like this too

if (!in_array($status, FlexibleEntityInterface::getStatuses())) {
  throw new FoundationException(...);
}

from modelmanager.

chanmix51 avatar chanmix51 commented on August 20, 2024

👍 to cast the status as integer.

Testing the available status is not that simple because status is a bitmask of possible states. getStatuses() would have to return all possible combinations of available statuses (given they are registered). Furthermore, this method getStatuses() would collide with an entity field named statuses (likely to happen).

from modelmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.