Log message #4197717

# At Username Text
# Aug 13th 2019, 10:28 challgren Why not like this?
# Aug 13th 2019, 10:26 slackebot1 string { return TableRegistry::getTableLocator()->get($this->getSource())->types[$this->type]; } ```
# Aug 13th 2019, 10:26 vossen.steven Not sure if I follow but here's a crude example Table ``` const TYPE_USER = 0; const TYPE_ADMIN = 1; /** @var array */ public $types; public function initialize(array $config) { $this->types = [ self::TYPE_USER => __('User'), self::TYPE_ADMIN => __('Administrator'), ]; } ``` Entity ``` /** * @return string */ protected function _getTypeValue():
# Aug 13th 2019, 10:21 challgren Why not an association if you already have the tables
# Aug 13th 2019, 10:19 vossen.steven I only use it for const values, for populating selects/radios and instances where I use a variable table name
# Aug 13th 2019, 10:19 vossen.steven @challgren
# Aug 13th 2019, 10:16 dereuromark A rector task for it would make it a super trivial change. For free.
# Aug 13th 2019, 10:16 neothermic and then I can run the fixer to add the return to all of my $this->redirect calls
# Aug 13th 2019, 10:16 neothermic a lot of my controller testing can't happen until another branch is merged in
# Aug 13th 2019, 10:15 challgren Ahh ok
# Aug 13th 2019, 10:15 neothermic 433 test cases
# Aug 13th 2019, 10:15 challgren Weak sauce!
# Aug 13th 2019, 10:14 neothermic @challgren Currently 764
# Aug 13th 2019, 10:12 challgren Looking in my major project I only use it twice, 1 in an entity because ModelAwareTrait screwed up json encoding it. And the other in a table class afterSave event
# Aug 13th 2019, 10:09 neon1024 Here it is if anyone is interested https://github.com/cakephp/cakephp/pull/10933
# Aug 13th 2019, 10:06 challgren https://github.com/dereuromark/cakephp-queue/blame/master/docs/README.md#L320
# Aug 13th 2019, 10:05 challgren I think dereuromark ’s code taught me to use it honestly
# Aug 13th 2019, 10:04 neon1024 ..and to rename some of the api
# Aug 13th 2019, 10:04 neon1024 It got refactored a while ago to try and remove the static interface
# Aug 13th 2019, 10:04 vossen.steven Yea was just thinking getTableLocator probly uses the same obj
# Aug 13th 2019, 10:04 neon1024 @challgren Well that method will be pulling the instance from the registry if one already exists
# Aug 13th 2019, 10:03 challgren Doesn’t make sense to make a new object when sometimes I use getTableLocator() multiple times
# Aug 13th 2019, 10:02 neon1024 @val Good luck! 8)
# Aug 13th 2019, 10:02 challgren IDK honestly, I always coded `TableRegistry::getTableLocator()->get()` well `TableRegistry::get()`
# Aug 13th 2019, 10:02 racmiroslav there is. `TableRegistry::getTableLocator()` is Singleton
# Aug 13th 2019, 10:00 vossen.steven @challgren maybe a dumb question but is there a difference between `TableRegistry::getTableLocator()->get('Table')` and `(new TableLocator())->get('Table')` ?
# Aug 13th 2019, 09:57 val @neon1024 nope, that's not what I asked. In 2.x there is an option to set table alias in data source object. It seems such option is missing in 3.x
# Aug 13th 2019, 09:56 jotpe But skipAuthorization() has no parameter for actions. So how can i allow an action from one Controller?
# Aug 13th 2019, 09:55 jotpe As mentioned over here Authorization can skipped for actions: https://book.cakephp.org/authorization/1.1/en/component.html#automatic-authorization-checks
# Aug 13th 2019, 09:50 challgren Ahhh, how many assertions so far?
# Aug 13th 2019, 09:50 neothermic @challgren also I've had to do other work inbetween writing tests :S
# Aug 13th 2019, 09:49 neon1024 https://github.com/cakephp/cakephp/blob/master/src/Core/ObjectRegistry.php
# Aug 13th 2019, 09:49 neon1024 @val Have a look at the ObjectRegistry class if you’re interested, it’s one of the key patterns for the whole framework, even in Cake 2
# Aug 13th 2019, 09:48 challgren @val maybe someone else knows a better answer, I by no means am a ORM expert
# Aug 13th 2019, 09:48 neon1024 @val That’s exactly what you asked for
# Aug 13th 2019, 09:47 neothermic it gets fun when you have a function with an npath of 442.. :)
# Aug 13th 2019, 09:46 val omg. new table instance for each subquery?! that's insane
# Aug 13th 2019, 09:45 neon1024 It can lead to sub-standard test-cases
# Aug 13th 2019, 09:45 neon1024 Chasing coverage is dangerous
# Aug 13th 2019, 09:44 challgren I had 100% at one time but it dropped to 80% and Im sad about it, but need to focus on getting it back up to 100%
# Aug 13th 2019, 09:43 neon1024 So you can use it later again if needed