Open merumelu opened 8 years ago
Ok, here are some things that are (I think) already most-used:
composer.json
and bower.json
)<?php if(stuff) { ?> <?php } ?>
(full tags and braces)&$response
), and should not be modified if there were no errorstrue
, and change the response to include the messagefalse
All of this allows us to call utility functions as:
$error = $this->utils->error_reponse_if_missing_or_not_string(false, $response, $body, 'username');
$error = $this->utils->error_reponse_if_missing_or_not_string($error, $response, $body, 'email');
$error = $this->utils->error_reponse_if_missing_or_not_string($error, $response, $body, 'password');
if($error) return $response;
I'd strongly suggest going with PSR-1 & PSR-2. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
Some important points:
PSR-2
PSR-1
So it should be e.g.
$error = $this->utils->errorReponseIfMissingOrNotString(false, $response, $body, 'username');
I'd also recommend using editorconfig.org to easily set editor preferences to those styles. Added a pull request for a basic editorconfig file #87.
It might be related, so I'm posting this here: After browsing the code a bit I noticed a couple of odd design decisions.
The database handling stands on really slippery ground IMO; I don't necessarily recommend using Doctrine or another heavy weight ORM solution, but an object based wrapper would work wonders:
$asset = new \GodotAssetLibrary\Asset();
$asset->title = 'PoolManager';
$asset->save();
I agree for all except the last point -- I'm not switching away from any technology since people found it "uncool" (also, bower has pretty nice decentralization I personally like). If we would switch away from uncool technologies, we are going to have to run assetlib on a Go/Rust server (which is obviously not on tuxfamily..).
@bojidar-bg I completely get this - I also stay with some older technologies, because I'm more productive in them; and a project maintainer / main dev should always feel comfortable with the tech stack they are using. I guess I made a bad argument for chosing NPM over bower. Let's see if I might convince you further down the road for a better reason. ;)
btw.: What about using a template engine? (Smarty/Twig) I know all the arguments around it (and been through the holy wars) - but I'm generally in favor of template engines, because they add a distinct interface between logic and presentation and make writing view helpers very modular.
(I'm also more of a frontend guy and thought I might be of use there a bit down the road)
There is a template engine used, PHPView. However, it's pretty bare-bones.
If we want to keep templates as PHP instead of some custom templating language, there's also Plates.
Ok... seems like we are deploying beta soon, so, we should start thinking about this issue, before 1.0 is started.
In other words, I would like if everyone agrees on some plan of refactoring action, and then we (or I) might do it. :smiley: (not implying that we aren't agreeing on something in any way)
So does the merging of #87 mean ok to four spaces or PSR1/2 as a whole? If it's the latter, let's do that first, might be enough to just run everything through php-cs-fixer. :smile:
If we are going to replace PHP-View with something else, I'd vote for Twig. It has nice stuff like template inheritance, and unlike templates written in vanilla PHP, there's also autoescaping available as well as specific escaping strategies for JavaScript or HTML attributes which lessens the chance for accidental XSS quite a bit. Smarty might have this as well but I've never used it.
For auth stuff, I'd suggest adding a middleware which adds a user
to $request
using $requst->addAttribute()
, which can then be checked in route middleware and is also accessible in routes themself if needed. Maybe add a "guest" level, so is_logged_in
+ has_level_higher_than(x)
can be combined.
Regarding applying PSR1/2, please do it in two commits:
Hm, PSR-1 states:
Code written for PHP 5.3 and after MUST use formal namespaces.
What namespace should we use? Godot\AssetLibrary
?
@merumelu sounds good... :smile:
I'd volunteer for integrating the template engine if you like. I'm a bit more in favor of Smarty, because I've used it extensively in the past, it's said to be faster, and extending it with custom functions is more straightforward IMO.
Just check the docs: http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension vs. http://www.smarty.net/docs/en/plugins.tpl
I know and recognize that Twig has (for some reason unknown to me) more momentum right now, so if you like to use that, I can do that.
Plates looks also nice I gotta say, but never used it.
I also have a bit of experience with Slim middleware, so if I should look into that, just ask.
Ok, I'll try to summarise everything decided on, plus some things that are under consideration:
Godot\AssetLibrary
namespace for all classes<?=
syntax, and it might be "rude" to ask developers to change configs just so they can run a local version. So, maybe yes, maybe no, even though they should be very fast in general.{
might collide with normal text at times (though that's probably not a big issue). Doesn't allow php in templates directly, which is probably nice.{{
. Also, doesn't allow for php in templates. Probably, being a bit slower than Smarty is the only problem with it.{{
like Twig and Smarty, also used in a pretty sweet PHP framework (which I used once). Uses a pretty strange syntax for functions though (@..
), so it should be considered carefully. This link might be useful for browsing through the options for provider.5.6.27-0
with some zend cache.The PHP short tag syntax <?= is not related to PHP being old, it's been around for awhile, but it might be disabled on the host as you say - have you tested it? And yes, without it, it's really no fun to use a PHP based template language and would be an argument for one of the other solutions.
@TomWor Ups, my bad, it is my configuration that's wrong, not theirs :laughing: But, that being said, php-based templating might lead to putting too much things in the templates, which shouldn't be there (as mentioned by the Smarty site).
I remember having performance issues with Twig in the past, though it was a distant past and the problems went away once I rewrote my code to better use the caching it offers. Syntax-wise it is my favorite.
As I'm said I'm rather agnostic about it, but I prefer Smarty syntax. Small example:
{% for color in myColors %}
<li>{{ color }}</li>
{% endfor %}
{foreach $myColors as $color}
<li>{$color}</li>
{/foreach}
And writing plugins, filters, etc. is more straightforward IMO, linked it above. Anyway, let's just decide and move on, the template migration would be a good issue to move out of this thread and just implement it, it's very straightforward.
@TomWor Ok, I'm for Smarty in this case, since it is really troublesome to write all those %
signs (though I dislike the ancient look of their doc :laughing: )
@bojidar-bg Yeah, those % signs make my eyes bleed and I don't like them for readability. As for Smarty Docs: Yes, we are definitely not in cool-town here, but to their defense: The documentation is really good and clear. :)
I might have a bit of time next week to work on the template engine integration. Can I proceed on this and start creating a template branch on my fork?
Well, would be nice if @merumelu's PSR PR is merged first, but it has some conflicts... So, I guess, go for it, then if some merge conflicts occur, we would fix them by hand :smiley:
@TomWor How is it the template engine integration going along? I would be glad to help somehow...
Just an update:
That is great news! I would be willing to integrate the Doctrine ORM, if you like.
@cmfcmf Well, I checked various ORMs available, and I am not sure about using Doctrine (feel free to correct me on any of the points, as I haven't used PHP much).
Here are the various points I think are important to have (in no particular order):
Taking a list of ORMs from awesome-php:
You are right, I should've looked at other options before suggesting Doctrine (I suggested it because it is the only ORM I have used so far). Thank you for your comprehensive list of requirements and alternatives! I've looked into the different options myself now. Here are my two cents in addition to your own evaluation:
š
š
To me it seems like Doctrine, Spot2 or Eloquent may be the way to go.
I would personally go for Doctrine as I'm most familiar with that ORM.
Great! Let me point here something.
Actually the Godot's website is using OctoberCMS that is developed over the Laravel Framework. That is amazing. In fact, the big discussion, IMHO, should be if the Asset's Library desires to be close to the technology adopt on the website, allowing both to get easily connected.
So, my suggestion is to migrate the application to Laravel, using Eloquent and Blade/Twig (I really don't care about the template engine at this point) and Bulma CSS.
I started something on my fork, just for testing. Can be cloned from here: https://github.com/rluders/godot-asset-library/tree/feature/laravel
@rluders Sorry, I think I will have to stop your enthusiasm a bit.
My main concern, as discussed on other channels, is that there is little point in switching the whole codebase unless there are unsolveable problems with the current one. This is commonly known as "don't fix what's not broken."
About the big discussion of whether the Asset Library should become an OctoberCMS plugin, we have never planned for such an inclusion. Actually, part of the original plan was to provide code which would be used to create other asset libraries easily.
A final concern is that the changes when switching to another framework are huge, and learning to maintain the new code would take some time.
I think a change to Laravel would make a lot of sense.
Sadly I never came around to contribute much to the project since my first involvement 2 years ago (!), and looking at the commit graph, there was really not much happening here by other actors as well. (no offense) Part of the reason I think might actually be the non-inclusive nature of the codebase, which is a bit of a hack based on the Slim Framework without any regards to current PHP code styleguides and best practices. What Laravel would provide is a stringent framework philosophy that a lot more developers are already familiar with and would provide a codebase that could be more easily picked up and worked on in peoples spare time. Please don't discard the idea for a framework switch and effective rewrite so easily. I think the whole asset library could be rewritten by someone with Laravel experience in about a day or two, that's how efficient the Laravel workflow is (I'm getting into it right now too, work-related). Also want to point out @rluders didn't propose making the asset library an October CMS plugin, just aligning the technologies with another, which would be another slam-dunk strategy-wise in my books. Just my 2 cents.
@bojidar-bg so, I totally disagree with the ādonāt fix whatās not brokenā principle. And Iāll explain the main reason for that in one second.
@TomWor you came with a lot of points that is the reason to move to Laravel. And when you said that non-inclusive nature of the code is reducing the number of contribution, I canāt agree more. And this was one of the main reasons for me to propose the Laravel.
My first idea was exactly to help the project has it is right now, but It was so confusing and difficult to find out where to start. And I consider myself an experienced PHP Developer and Software Engineer (you can check my LinkedIn if you want to). And at the first moment I was just reading the code and trying to find something to improve, and my second thought was: OK, maybe the way that I can help is to make it an familiar codebase and some design principles, that could make it grows SOLID.
The code right now is pretty small, and most part of then could be easily moved out to Laravel. Iām working with the rewrite right now, on my fork, and Iāll probably work hard this weekend to see how much of the concepts can I delivery.
I know, Slim is great, in fact, thereās a lot of nice frameworks that could be used. But, my big concert about using micro-frameworks is that you need to spend too much time focus in ādesigning principlesā that an Laravel already provides, you donāt need to research libraries, see how they work together, design your abstracts, your folder structure, and more. You already have the basic job done, you could just keep the focus in your code business.
I know that we already have some work going out, to using some ORM and also moving the template engine to Twig. And I feel like we donāt need to discard this jobs, ācause we could use Twig instead of Blade with Laravel, and also using Repository Pattern to embrace the non-eloquent ORM for know, or even move it to Eloquent will be not be THAT painful.
And yes, @TomWor, align the technologies will give us a lot of benefits, ācause we could have people working on the website that will also be able to help on the asset store. So, instead having two teams, we will have ONE big and integrated team. So we could easily integrate system and contributors.
So... Here... As I said before, I'm working in an complete (?) rewrite of the asset store using Laravel. You can check an preview here: http://godot.luders.com.br/
@rluders Your ui seems clean. What is status of project?
Hi, @menip. I just didn't have time to work on it right now (too many things happening). I'll get it back after August. Any help to work on it will be appreciated. Feel free to ping me on IRC (at freenode: rluders) or even on Godot official Discord (rluders#5401).
Okay, now for something important :D
At the moment, the code uses a mixture of different styles. For example, while most of the files use two spaces for indentation, some use four and others go a different way altogether and use tabs.
Another example: in templates there are a few occasions where alternate sytax is used for control structures (like
if (foo): ... endif;
) which do not appear in the majority of the code.It might be good to decide on some standards while the codebase is still smallish, so changing it doesn't become such a behemoth as godotengine/godot#3916 :stuck_out_tongue: