sofadesign / limonade Goto Github PK
View Code? Open in Web Editor NEWa PHP micro-framework
License: MIT License
a PHP micro-framework
License: MIT License
See : https://github.com/yesinteractive/fsl/blob/master/lib/fsl.php#L1136
Something like this…:
function request_uri($env=null)
{
static $uri = null;
if(is_null($env))
{
if(!is_null($uri)) return $uri;
$env = env();
}
// retrieve $uri depending env
$uri = rawurldecode(xss_filter($uri)); // store in static $uri variable
return $uri;
}
if(!defined('xss_filter'))
{
function xss_filter($str)
{
// minimal filtering like https://stackoverflow.com/a/1741568
}
}
The mime_type
function doesn’t check if an extension exists before getting its type. So if someone call this function with a non-existing extension (e.g. an empty string), he/she gets a warning:
Notice: Undefined index: in /…/sofadesign/limonade/lib/limonade.php on line 2417
I use limonade with idiorm ( orm )
i have this route :
dispatch('/**', function(){
$uid = params(0);
$data = appPloof::AntiSpam($_SERVER["REMOTE_ADDR"]);
return $data;
});
and this is the AntiSpam function
public static function AntiSpam($ip){
$ipM = ORM::for_table('antispam')->where_like("ip", $ip)->find_one();
if(!$ipM){
$ipM = ORM::for_table('antispam')->create();
$ipM->ip = $ip;
$ipM->nb = 0;
$ipM->save();
return true;
}
else {
if($ipM->nb < appPloof::$limiteAntiSpam){
$ipM->set_expr('nb', 'nb + 1');
$ipM->save();
return true;
}
}
return false;
}
in my bdd i can see the nb is incremeted two by two !
Cherry pick from goldeneagle@f08dbdf
Remember to add tests !
The issue is I can not send urls like redi-admin/post to the admin directory
function autoload_controller($callback)
{
$path = option('controllers_dir');
if(strpos($callback, "redi-admin") === 0) $path = file_path($path, 'redi-admin');
require_once_dir($path);
}
i have tried
function autoload_controller($callback)
{
$path = option('controllers_dir');
if(strpos($callback, "redi-admin/**") === 0) $path = file_path($path, 'redi-admin');
require_once_dir($path);
}
but that did not work
I'm running apache, and php in fcgid on a locahost (not sure if this is relavent, but there you go)
Chrome is sending a HEAD request immediately after each GET or POST
As flash messages are destroyed on the next request the HEAD request is wiping them before the next GET or POST
the flow goes a little like this
GET /step1:
flash("message","hello");
HEAD /step1
flash_sweep(); // destroys flash message
GET /step2
flash_now("message") // returns null
I can't do a pull request as I've quite substantially forked other parts, but the fix I've implement is in the stop_and_exit definition changing:
if($flash_sweep) flash_sweep();
to:
if($flash_sweep && !request_is_head()) flash_sweep();
option('views_dir', dirname(FILE).'/other/dir/for/views');
the above when executed works only for an instant,
but it(the set value) later gets updated to the default value, by the limonade framework.
try this,
The _method
POST parameter can be used to override the HTTP method. This means that DELETE
, PUT
routes can be triggered through CSRF. The documentation should warn that when using libmonade these routes should be CSRF-protected as well.
Additionaly it might be useful to be able to disable this feature.
I needed to match urls containing characters like "ñ" and this was not possible due to the urlencoding. I realized that this was done to secure in a way the values of the resulting params.
dispatch("^/test/(\d+)/{0,1}([a-zA-Zñ]*)", 'main');
Wouldn't match "/test/5/español" as it should (the actual url was more variable and complex, this is the simplified version). I don't know if its the best solution, but I solved it while mantining the previous behaviour for params in this commit: dresb/limonade@a54d79a419db71593d33d68fa6627cce0492aeb0
The majority of the changes in that commit are the text editor removing spaces at the end of the lines. The only two real changes are in the lines 1254 and 1272.
In section 7. Utils
, extends mime types supported by mime_type()
.
Could be useful to be able to add more include folder for controllers, views, lib, etc.
Use case: Multiple apps (with multiple frontend controller (index.php...)) could load only the code it need + generic code (like, an app with the same layout as an other).
With this, it could be more simpler to share code between apps, too.
by exemple:
option('views_dir', dirname(FILE).'/views');
can become:
option('views_dir', array(dirname(FILE).'/views', dirname(FILE).'/myapp/views'));
here, /views is my genereic views folder, and /myapp/views is my app folder.
Thanks.
Allow the templates to provide data to the layout. Extremely handy when you want to add stuff to header etc. See example at my fork github.com/dyve/limonade.
I also did a change to render that makes it somewhat smarter towards the $layout parameter.
Hi,
I'd first like to thank you for the work you've done with this framework!
Second, is there a way to capture content sent to partials? I have a "header" partial that I need to transform its content before returning the value to the view...
thoughts?
For example, it would be great to know the values similar to those route_build provides.
I need away to direct a URI that has been requested that starts with numbers must be a min of 3 numbers at start to go and load a different render
currently I use to do it by
dispatch_get("/*", array($redi, 'hello'));
and then get the home function to search the URI if it had numbers in it to then re-direct it somewhere else, however since I am re-ciding it all I thought I would ask if there is a better way to do such a function.
example
http://example.com/152A3
should go to
displatch_get("/:tagid",array($redi,"tagid"));
we use to use this function
public function hello(){
if(is_numeric(substr(params(0), 0, 5)))
{
include_once("./plugins/tagID/index.php");
return render("p_tag");
}
}
Since the routes are compiled into a pure REGEX manner, when reaching into the hundreds of routes the performance is severely degraded depending on where the route is. It has to run N regex patterns if the last route is hit. For large projects this is a severe stumbling block as I was reaching about 700-800ms with 1000 routes (testing) and that was just to figure out which route to run.
I toyed with the idea of storing the routes up to the first * or regex pattern to reduce the number of route lookups. For example:
route: /some/directory/*
$routes = array(
'some' => array(
'directory' => array(
'_routes' => array(
'ACTUAL REGEXP PATTERN' => $index_into_routes_array
)
)
)
);
This would allow you to do a couple quick lookups to possibly reduce the number of route lookups dramatically. Unfortunately I effed it up but something along these lines would help viability for using Limonade in large projects.
I could still make another attempt but perhaps there is a better way to handle this I'm not thinking of? Is there an existing methodology for handling a high number of directories with routes?
require_once 'vendors/limonade.php';
dispatch('/hello/:name', 'hello');
function hello($name) {
// automatic get $name from url.
return "Hello $name !“;
}
run();
I have using "ReflectionFunction" to handler this function in my little router library.
Hi!
Thank you for this very nice piece of software.
I happen to have to work with an extremely annoying php 4.4.2 installation on the development server at work, and there were a few minor incompatibilities I experienced (mostly missing functions). So here is what I needed to add, in order to make the error messaged disappear.
// prevent error message in php < 4.3.2
// somehow this function was missing in my php installation
if(!function_exists('memory_get_usage'))
{
function memory_get_usage()
{
return 0;
}
}
// prevent error message in php < 5.1
if( !function_exists('headers_list'))
{
function headers_list()
{
return array();
}
}
// "backport" of php5
// from: http://www.php.net/manual/de/function.array-combine.php#82244
if( !function_exists('array_combine') )
{
function array_combine($arr1, $arr2) {
$out = array();
$arr1 = array_values($arr1);
$arr2 = array_values($arr2);
foreach($arr1 as $key1 => $value1) {
$out[(string)$value1] = $arr2[$key1];
}
return $out;
}
}
Hi,
I wanted to implement SEO friendly URL's in my project and was wondering if there is a way using which I could create a middleware to map URL's to controllers dynamically.
TIA
The Limonade site refers to this downloads page for the stable release, but there are no download links there.
Could be useful to be able to add more include folder for controllers, views, lib, etc.
Use case: Multiple apps (with multiple frontend controller (index.php...)) could load only the code it need + generic code (like, an app with the same layout as an other).
With this, it could be more simpler to share code between apps, too.
by exemple:
option('views_dir', dirname(FILE).'/views');
can become:
option('views_dir', array(dirname(FILE).'/views', dirname(FILE).'/myapp/views'));
here, /views is my genereic views folder, and /myapp/views is my app folder.
The latest is the first to be search. Like that, it's possible to override generic template with an app template.
Thanks.
I apologise for asking this here but I didn't know where else to ask.
Can route patterns have an optional parameter for example a page number encoded as apart of the route?
For example to merge these two dispatches ..
dispatch('/blog/:slug','blog')
dispatch('/blog/:slug/:page', 'blog')
If so please can an example be added to the documentation regarding route patterns and parameters?
I'm wondering what is the minimum supported version of PHP supported by Limonade? It certainly works on 5.2.17, but I was interested in getting it working in a positively ancient 5.1. Is it likely to work or are major incompatibilities likely?
At any rate, it is probably worth putting the requirements in the readme.
Thanks again for making such an awesome framework.
I saw the improvement to redirect_to. Totally agree.
From my own experience, I'd say that whenever you expect a url, make the use decide if they need to call url_for. Else you'll end up with lots of different functions that accept a url parameter, and for consistency Limonade will have to accept all the parameters that url_for accepts in that place, and call it magically.
This will not improve code readability. Compare
#1 redirect_to('user', 'settings', array('status'=>HTTP_SEE_OTHER));
#2 redirect_to(url_for('user', 'settings'), array('status'=>HTTP_SEE_OTHER));
Someone that is new to Limonade will immediately understand #2, and need to think about #1.
http://limonade-php.github.com/ the github page is returning a 404.
I need to know how do I allow my script to send through with the GET commend the itunes URL for a song.
this is what I am currently doing http://site.com/limonade.php?uri=song/artist/http://itunes.com/song/artist and it keep saying not found
It seems to be the / in the url that i need to send. how can I fix this
When a template can't be found, the page renders the name of the view.
Is there a particular reason for this, or can we change it to throwing an error of some sort (at least in a development environment)
php short tags are not enabled on every server.
All dispatch_XXX functions create a route on the GET verb (eg. dispatch_post is the same a dispatch_get).
Hi,
First - thanks for making this great piece of code publicly available.
I've had some issues with the generated url from redirect_to(), which uses url_for().
The problem seems to be that & and not & is used as separator in the query string as per: https://github.com/sofadesign/limonade/blob/master/lib/limonade.php#L1651
When changing that row to use a plain & it seems to work just fine.
I guess there's a reason for this being & instead of &, and it's probably me that is doing something wrong - but I thought I should at least ask :)
Cheers,
Johan
The documentation says libraries are loaded before configure()
:
PHP files contained in the option('lib_dir') folder (lib/ by default) are loaded with require_once just before executing configure. So you can place in this folder all your PHP libraries and functions so that they will be loaded and available at application launch.
However the source code runs configure()
before loading libraries:
#2. Set user configuration
call_if_exists('configure');
[...]
#3. Loading libs
require_once_dir(option('lib_dir'));
This broke an app I was writing when I assumed that my ORM in lib/
would be loaded before configure()
was executed. Which is the intended behavior, please?
I wonder if I'm missing something as I can't be the first person to notice this, but I have a case where I need to use GET arguments, and they don't appear to be working. The best way to show the problem is by example:
http://www.example.com/login
. . . loads the route for /login fine. But when I use this URL:
http://www.example.com/login?return=/cart
I get a 404 for "(GET) /return".
I dug into it and I see where request_uri tries to get the intended URL from PATH_INFO first, then tries to parse it from the query string, then checks REQUEST_URI. So when there's a query string, it never gets to REQUEST_URI .
AFAIK under Linux/Apache, the URL is always available in REQUEST_URI. So the following fix worked for me (I don't know if it would break things on other servers). I replaced lines 1046-1069 with the following:
elseif(array_key_exists('REQUEST_URI', $env['SERVER']) && !empty($env['SERVER']['REQUEST_URI']))
{
$request_uri = preg_replace('/\?.+/' , '', rawurldecode($env['SERVER']['REQUEST_URI']));
$request_uri = rtrim($request_uri, '/') .'/';
$base_path = $env['SERVER']['SCRIPT_NAME'];
if($request_uri."index.php" == $base_path) $request_uri .= "index.php";
$uri = str_replace($base_path, '', $request_uri);
}
elseif (trim($query_string, '/') != '')
{
$uri = $query_string;
$get = $env['GET'];
if(count($get) > 0)
{
# exclude GET params
$keys = array_keys($get);
$first = array_shift($keys);
if(strpos($query_string, $first) === 0) $uri = $first;
}
}
Basically, I just switched the elseif blocks around and changed the way that $request_uri was being parsed.
I am having trouble using the flash().
I have a form, and in the POST route dispatch function, I validate the form. If it is invalid, I call flash() and render my view, but first the flash_now() is empty (as stated in the readme, I know).
But isn't it usefull to have it right away? Because now I need to set('error', 'some_message')
instead,
Hello Fabrice,
I wanted to ask if this awesome project is still maintained and being worked on. The last commit was in 2015. 2 years ago....
There are still lots of todos that are not done yet. The current version is 0.5.1 and there are todos until version 1.0!!!
If there is nobody who is currently working on new features, maybe I can overtake the project?
Short info about me: I'm 15 years old, from Austria, and have about two and a half years of experience in PHP. I have never maintained such a large project and am a bit unexperienced in it.
If you have any questions, just ask!
I would be very happy if I could overtake and maintain this awesome project!
Well... I hope that anyone replies!
~ Skayo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.