-
Notifications
You must be signed in to change notification settings - Fork 6
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
Potential Features: Controllers and Validators #8
Comments
Could you give any more concrete examples of what you're trying to do or how these additional components would be helping you? Where do you know this from? Are there any implementations that you like? |
Basically just providing general CRUD user flow for various objects stored in the db. Examples: create/edit/delete profile/blog post/etc... Perhaps some of the logic in these controllers can be reused and base-classed. Ex. validating the posted data matches the db schema and then redirecting to the appropriate error routes. However, I would not be surprised if each application is much too specialized for there to be useful framework to handle these tasks. As for an example implementation, I am aware of Ruby on Rails. However, I believe that Rails is quite complicated and bloated and doesn't match this framework. So I am curious if there is something useful out there that might be good to learn from? I've taken a very quick look at silex and lumen, but neither fx seems particularly useful in this area. Perhaps these features are much too complex to fit with this very simple and elegant framework... If this is the case, I am quite content to write my own specialized code, but I am forced to wonder if there is an ideal and reusable solution. |
Well, yes, writing your own classes to do this would still allow you to re-use much of your code. It's just a different level of abstraction. But if we could really make this fit in here, we should do that, of course. Perhaps we should indeed look at the solution in Rails. In general, I'm definitely open to such a feature, if we can implement it in a good way. Otherwise, as we agreed, you writing that layer for a specific application yourself is still a good solution and will allow for a good amount of code re-use, though it's not optimal because sharing that layer across applications would be the ideal solution. |
There are hundreds of php frameworks, and perhaps it was a long shot to think there was already a highly-modular and elegant component. I will keep my eyes open and if I spot something worthy (or make something), will share. Thx |
That layer will definitely depend on the front-end framework that you use, right? For example, outputs for Bootstrap 2, 3 or 4, other frameworks, or plain HTML could be supported. Though plain HTML is a bit difficult because you also need the correct CSS classes that have adequate styles. In the end, it might not be too hard to build a custom solution for this. But we should discuss this so that we can agree on the overall concept of how to do this, I guess. |
Actually, I thought the view could be excluded from this layer. For example, imagine a controller with only these policy requirements:
But maybe the layer could be even thinner. A base controller could have overridable properties for success route, validation error route, validation function, etc... Although, perhaps I am thinking too eagerly... I will look at a "Hello World" CRUD Rails app and see if there is anything to learn. |
That sounds good. I like the idea of excluding the view layer. But indeed, there are many solutions possible, some more efficient, some less. Looking forward to hear about your experience with Rails! |
Hello I have done some research on Rails, Laravel, and a couple other frameworks and unfortunately don't have too much to recommend. Many of these "full-service" frameworks use tight-coupling between model classes, database schema, and other components. This is particularly true for Rails which automatically generates consistent database migrations, model class definitions, and more. Clearly, features like these are too much and too complicated... One thing I love about this framework is how the DB component uses "plain old php arrays" as the basis for its data exchange. It seems natural to use the plain old php arrays as Value Objects (VO) in a Data Access Object (DAO) design pattern. The DB component handles much of the boilerplate DAO pattern. Basically the only work a DAO wrapper needs to do is:
There isn't much overhead for developer users to implement these. The only possible enhancements to DB I can think of to ease this are: Another area I looked at was the role of the controller. It turns out that most useful and reusable controller methods already appear in One task that controllers do is validation, and this is an interesting area to consider. A Validation component seems like a good candidate for an enhancement. It can exist as a separate and decoupled component. Laravel has an interesting implementation (https://laravel.com/docs/5.4/validation#quick-writing-the-validation-logic). I am building such a component. It is designed to apply various rules to values received from |
Thanks for your research! You say that one would have to switch between For those "merge" or "upsert" operations, there are some slight variations, however, so I could even imagine separate methods Most importantly, what the In general, what a "merge" or "upsert" method needs in addition to the data from the The validators sound interesting as well. So you want not just the enforcement of specific data types, as provided by the After all, maybe you don't actually have to prevent any tight coupling between the framework and your base controller. If only the base controller is tightly coupled to the framework, you could simply regard it as an extension of the framework. If something changes later, you'll have to adjust calls, but only in one place. Sometimes convenience (of development) and flexibility don't go together that well. |
Thanks for your consideration! For a "merge" or "upsert", the only other insight that I can offer is that What I like best about this framework is that it is plain old php! There are no new pseudo-languages to learn. There are no "magical" command line utilities to generate boilerplate code. It is simple and efficient. Perhaps enforcing primary keys can be done the same way. Consider this example:
(Reference: http://www.odi.ch/prog/design/php/guide.php - it's old but still valid) Regarding validation, I totally agree that Laravel's plain string parameters are messy. Also, validation tends to occur within a single method call, which seems to be unnecessary. I like the chained method call approach, Each rule is its own method call, and each call takes parameters which determine the error severity and message. These errors are collected and could be passed to
I had also considered extending Perhaps also the developer user can subclass the validator for reuse:
Of course each developer is free to implement these solutions independent of this framework (which is exactly what I have done). However, I think these two solutions fit very nicely with this framework and provide useful, reusable features. I am happy to contribute if they're good enough :) |
Thank you! I agree with everything you said and your The
By the way:
Good point, I should add that to the project description :) |
Hello
I am curious if potential features for this framework might include base class Controllers and/or Validators. I find that much of the code that I have to write falls in to either of these categories. So far I've just coded brutishly without much regard for scalable design patterns or clear semantics. When the project stabilizes I'd like to rewrite my core business logic (i.e. user driven CRUD) in a more maintainable way. Therefore, I am curious if well-designed base Controllers/Valdiators are appropriate for this project. I totally understand if they are not since these might need to be too specialized and/or complex... If that's the case, are you aware of any other frameworks that handle these tasks particularly well?
Thx
The text was updated successfully, but these errors were encountered: