-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Refactoring Sprunje Class #835
Comments
What do you propose? In my Sprunjes, I've been creating a new method that allows me to access the underlying
That being said, I've run into other issues with the |
Your solution could also work in my case. But doesn't it makes the Also, if you need to inject another service (Router, cache, etc.) to use with Transform for example, it won't be much of help. And speaking of refactoring, caching is another issue when dealing with Sprunje... |
Yes, I agree, I'm starting to see a lot of structural issues with
This allows you to specify which relationships (and even direct properties) of a model to load. Maybe every Sprunje could have a set of default properties to load, and then additional properties could be specified in the parameters. It would have to be integrated with our access control system somehow, I suppose. |
Ok. Let's make this issue the |
Reference: userfrosting/UserFrosting#835
I've done part of the refactor in userfrosting/sprinkle-core@526bb8e. The constructor have been simplified and an alternative to the option in the contractor have been added (
public function getList(Request $request, Response $response)
{
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = $this->ci->classMapper;
$sprunje = $classMapper->createInstance('activity_sprunje', $classMapper, $params);
return $sprunje->toResponse($response);
}
public function getList(Request $request, Response $response, ActivitySprunje $sprunje)
{
$sprunje->setOptions($params);
return $sprunje->toResponse($response);
} |
Done in userfrosting/sprinkle-core@7ce3e03 ! List of columns to show added as property (and not options; as theses proves difficult to default, and array are bad at type check). |
As far as further rewrite goes, I propose to separate Sprunje between data definition (what we want to get) and what return the data : class Sprunjer implement Sprunjer {
public function __construct(SprunjeInterface $sprunje) { ... }
public function toArray() { ... }
public function getListable() { ... }
// etc.
} class Sprunje implement SprunjeInterface, SortableSprunjeInterface, ListableSprunjeInterface, FilterableSprunjeInterface {
protected array $filterable = [];
protected array $listable = [];
protected array $sortable = [];
protected function baseQuery()
// etc.
} Big pro is Sprunjer can be extended : Sprunje (another name could be used to avoid confusion) itself could implement variable feature thought implemented interface. Sprunjer could check if Sprunje implement Finally the array of 'options' should be replaced with specific property (because array based options are bad at type check). I'll probably target 5.1 for this fix, therefor create a new issue and move caching feature there. |
Tasks
properties
featureCurrent Sprunje Constructor is too complex. The problem is the query method is called inside the constructor. So if the query requires more info (eg.
$foo
relation model), you can't do this :Instead the ctor needs to be extended (
$sprunje = new BarSprunje($classMapper, $params, $foo);
), which in the long term can create issue if a new argument needs to be added to the core class.Same goes if any additional services are required by the Sprunje and/or
transform
method.The text was updated successfully, but these errors were encountered: