taniarascia / laconia Goto Github PK
View Code? Open in Web Editor NEW🏺 A minimalist MVC framework.
License: MIT License
🏺 A minimalist MVC framework.
License: MIT License
Can't access the demo site, maybe the server is down?
I think is would be interesting to update code with typehint in arguments function https://www.php.net/manual/en/functions.arguments.php
I tried install Laconia using Apache, I set up the server and others (composer, npm, node.js, etc). When I type the root url (http://laconia.local) it works fine but when try to enter to register the server send: "404 - The requested URL was not found on this server."
However, when I run Laconia from php -S localhost:8888 Laconia's all pages works fine!
Debian 10, PHP 7.3, Apache/2.4.38
This is similar to #2, but may need a bit of experimentation to get right.
I would start off with adding something similar to GET/POST:
protected $sessionValues = [];
public function setSessionValues(array $sessionValues) {
$this->sessionValues = $sessionValues;
}
protected function getSessionValue($key) {
return isset($this->getSessionValue[$key]) ? $this->getSessionValue[$key] : null;
}
You will also want to modify keys separately:
public function setSessionValue($key, $value) {
$this->sessionValues[$key] = $value;
}
However, this array is unusual in that when you reset it, you want it to modify the $SESSION
PHP var. To do that, I believe you can use "pass by reference" on the original setter, like so:
// The ampersand indicates pass by ref
// See https://stackoverflow.com/a/885
public function setSessionValues(array &$sessionValues) {
This will allow you to disconnect your controllers $SESSION
too, again helping future testing. Of course, check your web app still works after making any sweeping changes.
This is pretty much one of the most minor issues but nevertheless an important one to the eye of some viewers. 😇
I think laconia should use new feature of php like type for function parameters https://www.php.net/manual/en/migration72.new-features.php
The link to "Project Directory" is broken or may be no longer existe.
I think is will be interesting to integrate docker compose file, for easy install and upgrade environment.
I am new for the PHP if you have any sample code for Pos system or I need to know how to write a code adding a item in php with checking existing product and items and sell the items please help me
Thank you,
Vijay
Hi Tania! only i what to ask you how to install Laconia in ubunutu. Im staring with php and your project it seems very interesting and i would like to look inside it. Please if you could guide me I would appreciate it.
Continuing on my theme of testability, another item to think about and possibly implement. Your controllers will do one of two things:
header()
to perform a redirect and exitI would suggest that instead you:
Laconia\WebResponse
objectYou can call this whatever you like, but to wire it in, I'd do this in your controller:
public function setWebResponse(Laconia\WebResponse $webResponse) {
$this->webResponse = $webResponse;
}
I'd then modify view
to inject the HTML it generates into the WebResponse
(to capture HTML in a variable rather than printing it immediately, use output buffering).
The web response could look a bit like this:
namespace Laconia;
class WebResponse {
protected $isOutput = false;
protected $isRedirect = false;
protected $output;
protected $redirect;
public function setOutput($output) {
$this->isOutput = true;
$this->output = $output;
}
public function setRedirect($redirect) {
$this->isRedirect = true;
$this->redirect = $redirect;
}
public function execute() {
if ($this->isOutput) {
echo $this->output;
} elseif ($this->isRedirect) {
header($this->redirect);
}
}
}
Woop! That is much better for testing. It is, specifically, better for mocking, so we can pass a fake object during testing, to see what things get called on it.
The password reset link does not seem to be working. I don't receive any e-mail when I click on the forgot password link.
Hi!
I can see that you have a partials
dit in your views
. I suggest that we refactor the viens in a way that it can support a basic templating system as you can see here.
There's an .htaccess
file that does some interesting routing. In order to get laconia.dev/user
to work, I made a rule that looks for username-router
in the URL and redirects to the profile if it exists. I couldn't find any way to get nginx working with this setup, so maybe someone knows a better way to handle those URLs.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f
# Do not route static files in the public directory
RewriteRule \.(js|css|svg|gif|jpg|jpeg|png)$ - [L]
# Route /edit/$ to /edit?list_id=$
RewriteRule ^/?edit/(.*?)/?$ /edit?list_id=$1 [L]
# Route everything else to index.php in the public directory
# Note: username-router get variable used for public user profiles
RewriteRule ^(.*)$ index.php?username-router=$1 [QSA,L]
OK, what you have so far is great work. I'm adding suggestions here as they're more editable than Reddit PMs. Feel free to do, or not do, any of these as you wish - all just food for thought.
Your controllers rely on $_GET
and $_POST
, which don't work in test environments, and they're global variables, so they are not very clean to work with. I would suggest something like this in your Controller
:
protected $getValues = [];
protected $postValues = [];
public function setGetValues(array $getValues) {
$this->getValues = $getValues;
}
public function setPostValues(array $postValues) {
$this->postValues = $postValues;
}
protected function getGetValue($key) {
return isset($this->getValues[$key]) ? $this->getValues[$key] : null;
}
protected function getPostValue($key) {
// TODO
}
Then before you execute the controller in the index.php
, you can do:
$controller->setGetValues($_GET);
$controller->setGetValues($_POST);
Of course you'll need to scan your controllers for the old global arrays and swap them for the new getters. Feel free to rename things as you wish.
When you come to unit testing, your controllers will now have nice entry points for you to inject test values.
I can expand on this once the existing tickets are done - it's a "level up" target for now! 😸
I tend to install PHPUnit and Mockery together for this purpose. Mockery has a fluent interface to create different kinds of class mocks i.e. fake secondary classes that we can rely upon when testing a class in isolation. I believe PHPUnit has its own mocking system, but I've learned Mockery instead, and this route seems to be popular with other PHP devs.
This really isn't an "issue" since laconia was developed for PHP 7.2, but this might help anyone considering a PHP update.
In controller.php, function validateUsername, the preg_match fails with error “Compilation failed: invalid range in character class at offset 10” after upgrading to PHP 7.4. This appears to be caused by the update made in PHP’s implementation of PRCE2 (introduced in 7.3) that assumes the use of a dash in a character class defines a range. For the regex in controller.php, the 3rd dash isn’t a range, it’s a literal, so I believe the simple, backwards compatible solution is to simply escape it. I.e., instead of
if (!preg_match("/^[a-zA-Z\d-_]+$/i", $username)) {
change it to:
if (!preg_match("/^[a-zA-Z\d\-_]+$/i", $username)) {
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.