Download the PHP package kajna/k-framework without Composer

On this page you can find all versions of the php package kajna/k-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package k-framework

K

Version DUB

Introduction

K is simple mini framework, made with simplicity and performance in mind. This is template app repository, if you want to explore how internals work or contribute core files can be found here

Getting started

Install

K requires PHP >=7.0 and Composer dependency manager to run.

So, before using K, you will need to make sure you have Composer installed on your machine

To install K using composer run following command:

Setup web server

Apache

K uses front end controller pattern so ensure the .htaccess and index.php files are in the same public-accessible directory. The .htaccess file should contain at least this code (K ships with example .htaccess file that can be used):

Additionally, make sure virtual host is configured with the AllowOverride option so that the .htaccess rewrite rules can be used:

AllowOverride All

Nginx

The nginx configuration file should contain at least this code in your location block:

try_files $uri $uri/ /index.php?$args;

This assumes that index.php is in the root folder of your project (www root).

Architecture Foundations

Application structure

Application consists of bootstrap index.php file and App folder. App folder will usually hold all user files as configuration, controllers, models, views, middleware, hooks etc. Althought not required App folder will come with predefined folder structure:

Application lifecycle

The entry point for all requests to a K application is the index.php file. All requests are directed to this file by your web server (Apache / Nginx) configuration. The index.php file doesn't contain much code. Rather, it is simply a starting point for loading the rest of the framework.

The index.php file loads the Composer generated auto loader definition, and then retrieves an instance of the K application Core class. When Core class is instantiated optionally midlewares and hooks are added and then execute method is called to start generating response.

K has middleware based architecture that means that each added middleware is executed before calling routing process which is itself middleware also.

After all middleware are executed and targeted route is found (or not), application generated response is displayed back to user.

The Basics

Routing

Basic routes

All routes are declared in file App/routes.php file. The most basic K route simply accepts a URI and two strings representing name of class and name of class method to execute:

Routes with parameters

Sometimes you will need to capture segments of the URI within your route. For example, when article ID is passed in the URL you may capture it by defining route parameters:

Captured ID will be appended to Request object get array

Available Router Methods

The router allows you to register routes that respond to any HTTP verb:

Middleware

What is middleware?

Middleware is a anything that is callable and accepts another callable as parameter (next middleware on stack):

Middleware can do any task like start session, filter request, connect to database, etc. The only hard requirement is that a middleware MUST return an instance of Response. Each middleware SHOULD invoke the next middleware.

How does middleware work?

Different frameworks use middleware differently. K implements middleware as stack. Each new middleware will be put on top of existing middleware. The structure expands as additional middleware layers are added. The last middleware layer added is the first to be executed. By default application core routing process will be automatically added as middleware.

When K application is executed middleware stack is popped and first element is invoked which will either return Response or invoke next middleware and so on. When middleware stack is executed application will render returned response and will display it back to user.

How to write middleware?

Closure middleware example
Invokable class middleware example

This example middleware is an invokable class that implements the magic __invoke() method.

How do I add middleware?

You may add middleware to a K application or to an individual K application route. All scenarios accept the same middleware and implement the same middleware interface.

Application middleware

Application (global) middleware will be executed on any request.

Route middleware

You can also attach middleware to any route and it will be invoked only when route is matched.

Route group middleware

Middleware can be attached to group of routes as well:

Hooks

What is a hook?

A "hook" is a moment in the K application lifecycle at which a callable assigned to the hook will be invoked if present. A hook is identified by a string name.

Although middleware can be used in most cases, some specific events will require hooks, currently K supports hooks for following events:

Example for setting hook which will be invoked when exception is thrown.

Controllers

K's Controller class provides many useful methods for accessing container objects and extending route target classes by Controller class is preferred way of doing things.

Container access

K injects container object to every class route that extends ContainerAware class (which Controller class does). Content of container can be accesed in different ways:

Render/Buffer template:

Though not a requirement, most controllers will ult imately render a template that's responsible for generating the HTML (or other format). Templates are usually stored in App/Views folder.

Note that render method will return Response object

Controller example

Request

Request object is created in K boot process and can be obtained from application container as described in controllers section.

Examples of commonly used request methods:

Response

Every middleware or route callback is expected to return Response object, by default K will not create any response and it expected that response is created during application runtime and passed back.

Examples of commonly used response methods:

Licence

The K Framework is released under the MIT public license.


All versions of k-framework with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
kajna/core Version 3.5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kajna/k-framework contains the following files

Loading the files please wait ....