roydejong / enlighten Goto Github PK
View Code? Open in Web Editor NEWEnlighten is a PHP micro framework that is simple, lean, high-performance and future proof.
License: MIT License
Enlighten is a PHP micro framework that is simple, lean, high-performance and future proof.
License: MIT License
In addition to the Request docs (#33), we need its counterpart - the Response object:
Enlighten
Introduction to the framework and basic documentation setup.
Example use case:
I created a custom session implementation. I initialize this session manager in a global before()
filter. I want to expose my session manager to controllers, but I currently do not have the option to access the application Context
, so I can't add custom objects to it.
Proposed solution:
Expose the Context via the Context dependency injection itself.
In the current build, only dependency-injected objects work.
Support for route-based variable injection (via mapPathVariables()
) is gone. Woops.
Need to add docs on the Filters system:
Enlighten
Shit is a mess right now:
https://travis-ci.org/roydejong/Enlighten/jobs/72916403
The request docs are a work in progress:
https://enlighten.readthedocs.org/en/latest/request.html
Still need a bit more info on the various public methods and utilites it has to offer:
$_POST
/ $_GET
$_SERVER
)Controllers are an optional extension to the framework that act as a useful building block for MVC applications.
Requirements:
my\ns\ControllerClass@invokeFunction
)Need documentation and with info, API and best practices for handling file uploads, with a particular focus on validating and handling image uploads.
At the moment when a routing function / closure is invoked, it is being passed a Request object as a first parameter and any dynamic routing variables after that.
This also means that these closures currently cannot access the Response object or any other useful context data.
Using the bindTo
function, we should bind a context object to these anonymous functions that allows them to freely access such objects without polluting their parameter list. This should allow for more reasonable and readable code.
It is important that any context object design can be used for MVC barbones later as well.
The Http\Request
class should have utilities that make it easy to read headers sent in the request, in addition to the information available in the environment data.
Proposed API:
getHeader($key)
getHeaders()
Documentation is needed for the routing configuration, both via the Enlighten::route()
API and direct / custom Router configuration.
Should encompass all routing features including:
Can only be started once milestone v0.1 is complete (depends on #4, #5, etc).
Before v0.1 is released, there is a bunch of code that needs to be checked and refactored.
This ticket simply represents all the actions that need to be performed to achieve that and should act as a registry for those commits.
Goals:
::getPostValue()
should probably just be called ::post()
).This is a blocking issue before v0.1 can be released.
This is slightly inconsistent behavior compared to Enlighten
, Response
, etc.
I think the Request
class needs a few utility / helper functions that extend past the basic functionality provided by #9 (i.e. getHeader()
).
isAjax(): bool
)isHttps(): bool
, getProtocol(): string
)getIp(): bool
) - with IPv6 and proxy considerationsExample use case:
I am creating a before() filter that checks user authentication. Currently I have to redirect the user away and throw exit
to stop execution. This is a bit dirty, and I can't reliably use the Request class either.
It would be nice if the framework provided a cleaner way to do this, for example halting execution when the "before" function returns false
.
Example use case:
I created a custom session implementation. I initialize this session manager in a global before()
filter. I have exposed my session manager to the Context thanks to the enhancement in #35. But I also have a custom View implementation I want to pass my session manager to. I would like to rely on the Context here, rather than having to pass it over manually. But there is no way to do that currently.
The framework should provide a way for applications to quickly and easily validate and extract form-submitted data.
Requirements:
Possible extensions for the future:
It would be useful to be able to configure simple redirects:
$router->redirect('/sourceuri', '/targeturi');
This should result in a simple, static 302 redirect. A redirectPermanently
might be cool too.
When a HEAD request is sent, the Enlighten
class strips the response body.
This results in an incorrect Content-Length header.
Because there is a hint of doubt on the internet as to whether web servers always strip the response body correctly, I think it is still important that the framework forces a consistent response.
Proposed fix: set the Content-Length before stripping the response body OR determine that both apache and nginx handle this appropriately.
When we define a routing target function, we have some potential problems:
$app->get('/user/$name/$action', function ($action, $name) {
// $action contains our $name and $name contains our $action :(
$this->request->getPost(/* ... */); // IDE does not understand this
});
We have a fixed order for the function parameters. The name of the variables does not matter, only the order does - this is not ideal.
In the background we currently pass some secret variables (e.g. $this->getRequest()
). Our IDE does not know this, cannot hint it, and will not understand it.
I propose a solution that fixes all of these problems and opens up a few nice future oppertunities: dependency injection:
Example usage, desired situation:
$app->get('/user/$name/$action', function ($action, Request $request, $name) {
// Our system has filled $action and $name with the appropriate route variables
// Because we type-hinted the "Request" class, we injected that dependency, on demand
// & no more need for dirty $this-> hacks.
});
It should be possible to read uploaded files from the Request class in a safe and intelligent way.
Need good way to handle 404 errors when a route cannot be resolved.
Current situation for unmatched requests: HTTP 404 Not Found
status code is returned to the client, with a blank screen (no content). There is no way to control this behavior right now.
Proposed solution: throw a specific Exception that can then be caught in the appropriate filters (see #1). Or perhaps add a custom global filter event type (e.g. notFound
).
It should be possible to read a user's cookies via the Http\Request
class.
Proposed API:
Request::getCookies()
: Return all cookies as a key/value arrayRequest::getCookie($key, $default)
: Return a specific cookie or a default value if it is not foundRequest::setCookies(array $cookies)
It should be possible to send cookies using the Http\Response
class.
Proposed API:
Request::sendCookie($key, $value, $ttl, [..])
Request::deleteCookie($key)
According to the RFC, HTTP HEAD requests are really just aliasses for GET.
Currently, the framework would reject a HEAD request and reply with a 404 if only a GET route matched. That does not conform to HTTP standards.
Proposed fix: Remove HEAD as a configurable routing option. When GET routes are configured, the constraint should both allow for GET and HEAD methods.
It would be nice if Enlighten routing could support a fixed subdirectory.
For example, a simple $router->setSubdirectory('/projects/bla');
could automatically expect that part to be in each route / request URI.
It should be possible to apply filters to the routing system.
A filter is a piece of code that is executed during different stages of routing. This is useful for performing a variety of operations, like checking a user's authorization before granting them access to a specific page.
Some frameworks such as Slim, Laravel, etc describe this concept as middleware because it sounds fancy. ASP.NET uses the term filters, which I think is a bit easier to communicate.
Overall requirements:
Enlighten::get($pattern, $target)
), without resorting to array-based configuration.Filter event types:
Proposed configuration API:
$app = new Enlighten();
// Fluent API using the returned Route of ::get, ::post, etc
// For setting up route-specific filters
$app->get('/page.html', function () {
echo 'Hi there!';
})
->after(function () {
echo "Thanks for stopping by!";
})
->onException(function (Exception $ex) {
echo "Oh dear!"
});
// For setting up global filters
$app->before(function () {
// ..
});
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.