Giter Club home page Giter Club logo

troodon's Introduction

One more PHP framework

What is a troodon?

Troodon was one of the smartest dinosaurs ever to have walked the earth.

Motivation

  • Attempt to understand php better
  • Better understanding of MVC framework and other design patterns
  • Ultimately, make it a good framework for an e-commerce platform
  • Have some fun!

Framework components

Tentative list (subject to change):

  • Request and Response handling: Symphony HTTPFoundation
  • Routing: FastRoute (Nikic)
  • Controller Resolver: Symphony HTTPKernel
  • Templating: Twig
  • Handling configuration: Werx
  • Email: Swiftmailer
  • Validation: Particle

Task List

  • Create a git repository
  • Create a directory structure
  • Strictly follow PSR naming conventions
  • Implement MVC architecture
  • Use HTTPFoundation from Symphony
  • Use Swiftmailer (MIT license)
  • Port all framework related functions to a controller directory inside the framework sub-directory
  • Write a small app so that users can test it
  • Write a simple unit test to test the framework functions (before writing the functions themselves)
  • Use PHPMD (PHP Mess Detector) to analyze the project's cyclomatic complexity score

Design Pattern / Principles used (till now -subject to change anytime)

  • Front Design pattern (All requests are routed to only one file in the webroot)
  • MVC (Model View Controller) - Separation of concerns - Separate logic from data and view
  • To implement - Convention over configurations ()
  • Debating whether to use Active Record Pattern (Eloquent) or Data mapper (Doctrine2). Might go with a faster DBAL like PDO (cannot see the point of using the DBAL from doctrine).
  • Defining database class as abstract. The reasoning behind this is that database class itself not instantiated, but child classes like MySql are.
  • Might use interface for payment class, this would allow the users to define their own logic.

What I have till now

Directory structure

  • cache
    • empty directory at this point. Will be useful when using an ORM, like doctrine (data-mapper) or eloquent (active record)
  • config
    • config.php: This file returns the database info and other defined constants
  • framework
    • At this point empty. Core framework files will be put here.
    • Still need to figure out the sub-directory structure, I will leave that for the smarter me.
  • httpdocs
    • The web-root. The only web accessible directory. Contains only one file (index.php). We are following the front design pattern.
  • logs
    • The log files for php will be stored in this directory.
  • src
    • Place all your code in this directory.
  • tests
    • Place to put your unit tests
  • vendor
    • Composer installs the dependency in this directory.

Issues and fixes

  • Composer not working (connection issue) - remember to cite sources:

    • Edit the /etc/gai.conf file, and uncomment the following line
    precedence ::ffff:0:0/96  100
    
    
  • Setting up your localhost to enable mod_rewrite (ubuntu 16.04)

    • First install apache2 (sudo apt-get install apache2)

    • Then enable mod_rewrite module (sudo a2enmod rewrite)

    • Open this file using your favourite text editor (emacs or vim, if you do not use any of these, your cat might judge you) /etc/apache2/sites-enabled/000-default.conf

    • And add the following lines:

      <Directory /var/www/html>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           allow from all
      </Directory>
      
    • Restart apache2, and create your .htaccess file in the web accessible folder.

Some question in my mind, and their attempted answers

  • Why use front end design pattern?

Better security. Not possible for the end user to reach any other file.

  • Should I use ORM (Doctrine) or DBAL (PDO)

Initially, in the infancy of the framework, it makes sense to use PDOs. They are faster, and the author has some experience writing them. As the size of the database increases, an ORM like doctrine might be a better choice. With caching, the speed should be about the same as PDO, and it will help the user to write better complex queries (Is ORM an adapter pattern?)

  • How does Autoloading work?

To autoload files using composer, just add them to the composer.json file, and use the psr-4 key.

troodon's People

Watchers

James Cloos avatar  avatar  avatar

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.