Giter Club home page Giter Club logo

php-yafip's Introduction

YaFiP - (Y)et (a)nother (F)ramework (i)n (P)HP

What is this?

This is an attempt at creating a PHP based Framework for handling Websites in a more modern fashion. All the "Cool kids" use Node nowadays, so why not try something new for a change.

The Goal ...

... is to create something that lets the Programmer write PHP code in a similar way to lets say Svelte-Components or Smarty-Templates, but then also compile that code into a optimized, complete webpage that can be served quickly to clients.

Including the ability to update only parts of the served page on the client. (<-- this part is not yet implemented though)

How it works / Getting started:

Setup

The Environment:

Your Server needs to define 2 Environment Variables: This can be done in your Apache vhost config, via Apaches .htaccess or your any other means of your system.

These pathes need to be relative to your Servers $_SERVER['DOCUMENT_ROOT']

  • ROGOSS_YAFIP_PAGESROOT = 'src/pages'
  • ROGOSS_YAFIP_COMPONENTSROOT = 'src/components'

Submodules

This project requires 2 Submodule to be loaded.

Initialize them via

git submodule init && git submodule update

The project also contain a 3rd Submodule, that proviedes a way set up a quick autoloader.

Feel free to replace it, with what ever autoloading method you prefere. Just make sure, the two submodules above are covered by your new method.

Creating your first Page.

In your pages folder (the you you set up with the ROGOSS_YAFIP_PAGESROOT Environment var) create a new subfolder called index. Now you should have src/pages/index in your project.

the HTML side of things

Next in this folder (src/pages/index) create a new file called layout.html.

You should now have src/pages/index/layout.html. Open it in your Editor of choice and paste the following into it:

<!DOCTYPE html>
<html>
    <body>
        <h1> Hello World !!! </h1>
        <p>
            it has been [[--time--]] seconds since the 01. Jan. 1970.
        </p>
    </body>
</html>

Notice the [[--time--]] part. This is a Placeholder and can either lead to a component or data to be rendered For the sake of this intro, this one is used as data.

the Data side of things

next to your src/pages/index/layout.html create a new file data.php. This one will be responsible for, you guessed it, filling in the data fields defined in the layout.html

So open your newly created src/pages/index/data.php and paste the following.

<?php 
    return [
        'time' => time()
    ]

Noticed the return? PHPs include can return a value, $var = include "filename.php"

YaFiP makes use of that behavior to avoid having to introduce new variables into the scope and keeping data.php isolated.

At the same time, what is defined in data.php will stay in data.php. The only way of getting access to global ressources being the Super-Globals and using global $varname.

The Route

while this framework does not privide routing. It should integrat well with existing routing methods.

Lets say we use Apache.

create an index.php in your servers DOCUMENT_ROOT and paste the following into it:

<?php require_once __DIR__ . "/loader.php";  //<-- if you use the loading methods 
                                             // of this project this is the autoloader

use rogoss\yafip\Page;

Page::load('index')->render();

on Page::load( all we need to provide is the name of the subfolder containing our layout. The rest will be handled by the environment var we set up earlier.

Roadmap:

  • ⬜ function to let components add CSS and JS defintiions to the Pages head
  • ⬜ Figure out, how to do Wikis on GitHub
  • ⬜ Explain Components
  • ✔️ Finish example
  • ✔️ set everything up to be cloned

Misc:

Motivation:

I love PHP. You can just install it and be done. Each script works on every system, that supports PHP.

No depencys no, Package managers, nothing. That does not mean, there are no packages. Tools like Smarty and Laravel for example are excelent, but also come with some 3rd party dependecys and some function overhead.

So I trie to create my own kind of Framework / Engine for handling Websites. Will it be as capable as any of the two mentioned above. Of course not, but it will be an interessting experiement.

php-yafip's People

Contributors

rocco-gossmann avatar

Watchers

 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.