-
Notifications
You must be signed in to change notification settings - Fork 393
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 request detectors for mobile and tablet. #38
Conversation
👍 |
Library MobileDetect has been added as a dependency.
|
||
Request::addDetector('tablet', ['callback' => function($request) { | ||
return (new \Detection\MobileDetect())->isTablet(); | ||
}]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this code makes me which we didn't need that wrapping array. Totally tangential though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we skip BC we can just replace all that options keys juggling and only use closures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detecting with is_callable() is also an option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, but i find the current code for Request::is()
with almost a dozen isset
checks pretty ugly :)
Looks good to me 👍 |
Several things:
|
Uh. I just noticed #3031 and several already mentioned "suggest" is preferred. I see @lorenzo's point, but I still think that we should ship with as little dependencies as possible. |
Composer just lists the suggested packages after installation. There's no switch to actually install suggested packages, you have to explicitly install them separately. So that's not good enough.
How would that be better? If you don't need those detectors remove the lib from your composer.json and strip out relevant code from bootstrap. In majority of the cases you will use the app template just as a starting point and modify bootstrap and other files as per your needs.
I could create an instance and then pass it into closures for both detectors using
This is the first external dependency we have added that too for app template not core. |
That's the point, I would not want
I see it in the opposite side, why would we 'hardwire' things when it can be optional and automated? And people who really need these, would have the
Ok. I'm just asking because I don't really know the internals. Good to know that we can have an lighter method of setup anyway.
Not specifically related to this pull request, but where would we draw a line? One thing that draws me to cake in early days was that it was a full stack framework. Granted, with 3.0 and I'm okay with that, but we should make them a "suggest" and not "required". Another question, how should we handle library change if a better lib is available? The way i see this is that if this was released in 3.0.0, we're tied to mobiledetectlib for the rest of 3.x lifecycle. |
I think we should include/require as much as possible from the community we possible can. Cake 3 is a good opportunity to kill the full monolithic "not invented here" framework and embrace what the community in general is doing, working with composer and having dependencies where it make sense. I don't see a problem at all to include 5-10 composer dependencies, if the components included is well maintained, and they make sense for the framework. I think we should just ignore people who are afraid of composer and continue on the path of being a composed framework like everyone else in the community is doing :) If a library don't suit us or the user later, it's trivial to update, people can change their composer file back or chose to follow the framework. I think thats a missed point of composer :) Also, it's not CakePHP that depends on it, but the App version, so CakePHP internally don't care, it's only the actual application, and thus something people can remove, change or switch as they see fit. |
I'm sorry Jippi, that's just a low blow and lame argument. |
The app template should just work out of the box. You shouldn't need to install anything separately. This is very essential for attracting newbies.
No where. We consider it case by case and keep pushing it as further as we want.
We will have to just agree to disagree on that.
I see no harm if 3.0 is tied to mobiledetectlib (which btw is the app template not the core). Even if the original authors stop supporting it would be way more up to date than that mobile detection we had in the core. In general I believe the days of developing and maintaining everything ourselves are gone. We don't have the man power to do that. If there are existing libs which do a particular job nicely than we should use them instead of trying to reinvent the wheel, albeit a broken one. |
@rchavik low how? there is always people opposing progress, and considering how cake 3 already depends on composer, I do not see any problem in requiring 3rd party modules. |
@rchavik How do you currently manage application dependencies? Do you not use plugins? Are they committed to your repository, or do you use submodules? Just curious, as your advocacy against composer appears to be advocacy in general against application dependencies. |
Add request detectors for mobile and tablet.
While I think composer is great it is not the only way to manage dependencies. I know many people use git submodules, which the new MobileDetect dependency is amenable to. Keep in mind that the mobile detectors can be removed by anyone not needing them, and that the code will be rolled into the zip file we generate in future releases. |
Library Mobile_Detect has been added as a dependency.