Giter Club home page Giter Club logo

laconia's People

Contributors

kevin-mycos avatar kevin-schmitt avatar taniarascia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laconia's Issues

[Bug] Routing issues with nginx on Docker compose

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]

how to run laconia in ubuntu

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.

Separate GET/POST array from controllers

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.

Separate SESSION array from controllers

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.

URL not found with Apache?

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

Create a basic templating system

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.

Hi Tania

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

Broken link

The link to "Project Directory" is broken or may be no longer existe.

Integrate docker compose

I think is will be interesting to integrate docker compose file, for easy install and upgrade environment.

Write some unit tests using PHPUnit

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.

Password Reset is not working!

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.

Separate server response from controllers

Continuing on my theme of testability, another item to think about and possibly implement. Your controllers will do one of two things:

  • Echo HTML to standard output
  • Use header() to perform a redirect and exit

I would suggest that instead you:

  • Return a Laconia\WebResponse object

You 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.

Regex in controller.php causes an error with PHP 7.4

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)) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.