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

Add missing read only properties to role structs #2

Merged
merged 5 commits into from
Feb 14, 2012
Merged

Add missing read only properties to role structs #2

merged 5 commits into from
Feb 14, 2012

Conversation

emodric
Copy link
Contributor

@emodric emodric commented Feb 7, 2012

These should be readable. As far as I can see, there's no way to access limitations and policies once added to structs, there's no abstract methods to implement like, for example, eZ\Publish\API\Repository\Values\User\Role::getPolicies

@andrerom
Copy link
Contributor

One minor mistake with the protected stuff I have been made aware of during the conference is that you can not change the array, as it is returned by value and not by reference.

Code:

class Test
{
    protected $test = array( 'one' );
    function __get( $name ){ return $this->$name; }
    function __set( $name, $value ){ $this->$name = $value; }
}

$obj = new Test();

var_dump( $obj->test );

$obj->test[] = 'two';

var_dump( $obj->test );

$obj->test[0] = 'oneTwo';

var_dump( $obj->test );

Output:

array(1) {
  [0]=>
  string(3) "one"
}

Notice: Indirect modification of overloaded property Test::$test has no effect in /Users/andrerom/Sites/www/next/index.php on line 63

Call Stack:
    0.0019     653336   1. {main}() /Users/andrerom/Sites/www/next/index.php:0

array(1) {
  [0]=>
  string(3) "one"
}

Notice: Indirect modification of overloaded property Test::$test has no effect in /Users/andrerom/Sites/www/next/index.php on line 67

Call Stack:
    0.0019     653336   1. {main}() /Users/andrerom/Sites/www/next/index.php:0

array(1) {
  [0]=>
  string(3) "one"
}

If this is annoying enough to need methods, I don't know. As they are readonly they are not supposed to be manipulated like this anyway.

@emodric
Copy link
Contributor Author

emodric commented Feb 13, 2012

Sounds good to me. I'll make another commit to add methods. But, how should we stop exposing arrays? Throwing exceptions in __get in case is_array returns true?

@andrerom
Copy link
Contributor

Throwing exceptions in __get in case is_array returns true?

No, I think the possible outcome is to either remove all magic and instead have clear methods in the interface for readonly properties. Or let it be like it is.

@emodric
Copy link
Contributor Author

emodric commented Feb 13, 2012

It seems kinda too much to have methods for each and every readonly property, some value objects have 5 and more of those.

@andrerom
Copy link
Contributor

Yes, and that is why we ended up with these magic methods instead.

@andrerom
Copy link
Contributor

The diff looks good now, so good that I can start to nitpick :)

  1. 3 x remaining unneeded new lines in class php doc headers
  2. 3 x "public abstract function getLimitations();" should be "abstract public function getLimitations();"

@emodric
Copy link
Contributor Author

emodric commented Feb 13, 2012

The diff looks good now, so good that I can start to nitpick :)

:))

  1. 3 x remaining unneeded new lines in class php doc headers

Removed the lines in PHPDoc comments.

  1. 3 x "public abstract function getLimitations();" should be "abstract public function getLimitations();"

I wrote those exactly as existing methods addLimitation / addPolicy :)

@emodric
Copy link
Contributor Author

emodric commented Feb 13, 2012

Rebased the pull request with current master for "abstract public"

andrerom added a commit that referenced this pull request Feb 14, 2012
Add missing read only properties to role structs
@andrerom andrerom merged commit f5236e6 into ezsystems:master Feb 14, 2012
patrickallaert referenced this pull request in patrickallaert/ezpublish-kernel Oct 4, 2012
patrickallaert referenced this pull request in patrickallaert/ezpublish-kernel Oct 4, 2012
lolautruche added a commit that referenced this pull request May 16, 2013
@glye glye mentioned this pull request Sep 2, 2015
5 tasks
andrerom pushed a commit that referenced this pull request Oct 31, 2017
* Added class constants in SudoMainLocationLoaderTest

* getMock to createMock and class constants in ArrayTranslatorFieldsGroupsListTest

* getMock to createMock and class constants in RepositoryConfigFieldsGroupsListFactoryTest

* getMock to createMock and class constants in ContentPreviewHelperTest

* getMock to createMock and class constants in FieldHelperTest

* getMock to createMock and class constants in PreviewLocationProviderTest

* getMock to createMock and class constants in TranslationHelperTest

* getMock to createMock and class constants in AssignedLocationsListenerTest

* getMock to createMock and class constants in ParentLocationsListenerTest

* getMock to createMock and class constants in RelatedLocationsListenerTest

* MVC/Symfony/Cache/Tests/Http/SignalSlot tests added class constants

* Class constants and createMock added to POSPurgeClientTest

* Class constants and createMock in InstantCachePurgerTest, LocalPurgeClientTest and LocationAwareStoreTest

* Class constants and createMock added to Core/MVC/Symfony/Controller/Tests

* Class constants and createMock added to Core/MVC/Symfony/Event/Tests

* Class constants and createMock added to Core/MVC/Symfony/EventListener/Tests

* Removed mock of unexistent methods, added class constants and createMock to Core/MVC/Symfony/FieldType/Tests

* Added class constants and createMock to Core/MVC/Symfony/Locale/Tests

* Added class constants and createMock to Core/MVC/Symfony/Matcher/Tests

* Added class constants and createMock to Core/MVC/Symfony/Routing/Tests

* Added class constants and createMock to Core/MVC/Symfony/Security/Tests

* Added class constants and createMock to Core/MVC/Symfony/SiteAccess/Tests

* Added class constants and createMock to Core/MVC/Symfony/Templating/Tests

* Added class constants and createMock to Core/MVC/Symfony/View/Tests

* Class constants and createMock added to Core/Limitation/Tests

* Class constants and createMock added to Core/Pagination/Tests

* Class constants added to Core/Base/Tests

* Class constants and createMock added to Core/FieldType/Tests part #1

* Class constants and createMock added to Core/FieldType/Tests part #2

* Class constants and createMock added to Core/IO/Tests

* Class constants and createMock added to Core/SignalSlot/Tests

* Class constants and createMock added to Core/Search/Tests

* Fixed CS issue

* Class constants and createMock in Core/Persistence/Tests

* Class constants and createMock in Core/REST/Tests

* Use PHPUnit v57

* Remove mockery

* Added createMock() to Core/Repository/Tests

* Now we can use symfony-dependency-injection-test v1

* Added createMock() to SPI

* Updated Bundle tests

* Use namespaced TestCase

* Hopefully fixed CS

* Now I really think that CS if fixed

* Trigger travis build

* This was removed in rebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants