A very slight PHP framework, very easy to use and integrate.

Related tags

Frameworks api php
Overview

Nervsys

README: English | 简体中文

release issues contributors last-commit license

About Nervsys

  • What is "Nervsys"?
    A very slight PHP framework, very easy to use and integrate.

  • Why called "Nervsys"?
    At the very beginning, as we hoped. The unit could process more like a nerve cell, and build together as a pure data-based calling system. Exact commands would be unnecessary to tell the system what to do.

  • Any short name?
    NS, that's what most of us call it, but, don't mix it up with Nintendo Switch.

  • Requirements:
    PHP 7.4+ and above. Any kind of web server or running under CLI mode.

  • Usage example:

    1. Ordinary framework for Web-backend-developing
    2. API controller for all types of Apps
    3. Client for program communication
    4. More...

Installation

  1. Clone or download source code to anywhere on your machine. Only one copy is required on the same machine even multiple projects exist.
  2. Include "NS.php" in the main entry script of the project, and call it with using "NS::new();".
  3. If needed, using "/Ext/libCoreApi" to register your own modules and functions before calling "NS::new();".
  4. Write your API code classes under "/api", application code classes under "/app", if not changed, and there you go.
  5. In "/Ext", there are common useful extensions for normal project development, so, please do review them when coding. They can be helpful.

Usage

All demo usage is under default system settings.

1. Suggested project structure

Notice: App root path will be set to the parent directory of the entry php script.
Root/
    ├─api/                            default api entry code path
    │    └─DemoApiClass.php           demo api php class file
    ├─app/                            default application code path
    │    └─DemoAppClass.php           demo application php class file
    ├─config/                         suggested conf file path (use "Ext/libConfGet.php" to process)
    │       ├─dev.conf                conf file for dev
    │       ├─prod.conf               conf file for prod
    │       └─...                     other conf files
    ├─message/                        suggested message file path (use "Ext/libErrno.php" to process)
    │        └─msg.ini                custom message ini file
    └─www/                            default home path
         └─index.php                  main entry script

2. NS integration

Follow "Installation" steps to integrate NS into your entry script. Demo code is as follows.

setCoreDebug(true) //open CORS to all with default headers ->addCorsRecord('*') //set output content type to "application/json; charset=utf-8" ->setContentType('application/json'); NS::new(); ">
require __DIR__ . '/../../NervSys/NS.php';

//optional, if needed, please review "Ext/libCoreApi.php"
\Ext\libCoreApi::new()
    //open core debug mode (error display with results)
    ->setCoreDebug(true)
    //open CORS to all with default headers
    ->addCorsRecord('*')
    //set output content type to "application/json; charset=utf-8"
    ->setContentType('application/json');

NS::new();

3. Request data format

NS can parse data from both FormData and request Payload via GET or POST.
When data is sending as request Payload, both JSON and XML are supported.
Data fetcher and parser library in NS is "/Core/Lib/IOUnit.php".

In HTTP request, NS fetch and parse data in the following steps:

POST -> GET. 4. fetch request Payload, and try to decode in JSON/XML format, add to data from above. 5. read HTTP Header and Cookie data by specific keys defined in entry script, add to data from above. 6. find and isolate "c" data from data source, and pass it to Router library as request command. ">
1. read Accept from HTTP request header, decide return type if not defined in entry.
2. read URl, try to fetch "c" from "PATH_INFO" or "REQUEST_URI" if found.
3. fetch HTTP FormData in non-overwrite mode in following order: FILES -> POST -> GET.
4. fetch request Payload, and try to decode in JSON/XML format, add to data from above.
5. read HTTP Header and Cookie data by specific keys defined in entry script, add to data from above.
6. find and isolate "c" data from data source, and pass it to Router library as request command.

In CLI mode, NS takes "c" from "-c" parameter, or the first argument if not found. String parameter "-d" will be taken to decode to get CGI data source. "-r" forces output returned data format. Other arguments will be considered as CLI argv.

4. About key "c"

"c" in request data will be taken as request command, and will lead system to go continue.
"c" can be passed in any ways, URL, GET, POST, all is OK, no matter FormData or request Payload.

In CGI mode, normally known as HTTP request, "c" is always redirected to api path for some security reasons, but, CLI mode allows calling from root by adding "/" in the beginning of "c" using full class namespace path.

Valid "c" format should be as follows:

calling "byId" method in "\api\user\info" class. GET: http://your_domain/index.php?c=user/login POST: pass directly "user/login" in "c" parameter, both support FormData or request Payload. ">
API path based: innerpath_in_api_path/class_name/public_method_name

examples:
URL: http://your_domain/index.php/user/login => calling "login" method in "\api\user" class.
URL: http://your_domain/index.php/user/info/byId => calling "byId" method in "\api\user\info" class.

GET: http://your_domain/index.php?c=user/login
POST: pass directly "user/login" in "c" parameter, both support FormData or request Payload.
calling "login" method in "\app\user" class. GET: http://your_domain/index.php?c=/app/user/login POST: pass directly "/app/user/login" in "c" parameter, both support FormData or request Payload. ">
ROOT path based: /namespace/class_name/public_method_name

examples:
URL: NOT support.

CLI: php index.php /app/user/login => calling "login" method in "\app\user" class.
CLI: php index.php -c"/app/user/login" => calling "login" method in "\app\user" class.

GET: http://your_domain/index.php?c=/app/user/login
POST: pass directly "/app/user/login" in "c" parameter, both support FormData or request Payload.

5. Data autofill

Once "c" and data source are taken by system, Router library and Execute library will be woken up to run exact method. Key matched parameters will be taken out of data source, and pass in the right order automatically into target method when calling. Watch out of all data passed to NS, keys are case-sensitive, and data values are type-strict. All returned results will be captured and output.

example:

parameters in any order:
URL: http://your_domain/index.php/user/login?name=admin&passwd=admin&age=30&type=client
URL: http://your_domain/index.php/user/login?passwd=admin&age=30&name=admin&type=client
  • API 1
namespace api;

class user
{
    public function login($name, $passwd)
    {
        //your code

        return $name . ' is online!';
    }
}
  • API 2
namespace api;

class user
{
    public function login($name, $passwd, int $age)
    {
        //your code

        return $name . ' is ' . $age . ' years old.';
    }
}

6. Exposed Core libraries

NS leaves some important core libraries exposed to developers since 8.0 and on.
Thanks to douglas99, all changeable core related APIs are merged into " Ext/libCoreApi.php".
With this, developers can register own libraries instead of default ones, such as custom Router, outputHandler, ApiPath, hook related functions, etc...

Todo

  • Basic Core and Ext logic
  • Automatic argument mapping
  • App code env detection logic
  • Custom router module support
  • Custom error handler module support
  • Custom data reader/output module support
  • Path based hook registration function support
  • Socket related functions
  • ML/AI based internal router
  • More detailed documents and demos

Except functions listed above, NS still has a long way to go.
Thanks for issues & pull requests if you found bugs or make it better, or just need help. Contact us.

Supporters

Thanks to JetBrains for supporting the project, within the Open Source Support Program.

License

This software is licensed under the terms of the Apache 2.0 License.
You can find a copy of the license in the LICENSE.md file.

You might also like...
Lite & fast micro PHP framework that is **easy to learn**.
Lite & fast micro PHP framework that is **easy to learn**.

Utopia Framework is a PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development.

a framework for WebDevelop based on the mvc structure. The name of this project for Fun because everyone can use it. Completely simple and powerful structure for all your projects

A_A (-.-) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ |-| █▄─▄▄─█▄─██─▄█─▄▄▄▄█─▄▄▄▄█▄─█─▄█─▄▄▄─██▀▄─██─▄

Tarantool connector for yii2 framework. Allow to use activerecord, schemas, widgets and more.

Tarantool connector for yii2 framework Tarantool connector for yii2 framework. Allow to use framework abstractions such as ActiveRecord, Schema, Table

Quite possibly the smallest MVC framework you'll ever use.

Swiftlet Swiftlet is quite possibly the smallest MVC framework you'll ever use. And it's swift. Licensed under the MIT license. Buzzword compliance ✔

PIP is a tiny application framework built for people who use a LAMP stack.

PIP is a tiny application framework built for people who use a LAMP stack. PIP aims to be as simple as possible to set up and use.

The easiest to use WordPress option framework.

Titan Framework allows theme and plugin developers to create admin pages, options, meta boxes, and theme customizer options with just a few simple lines of code.

A easy way to install your basic yii projetc, we have encrypt database password in phpfile, my class with alot funtions to help you encrypt and decrypt and our swoole server install just run ./yii swoole/start and be happy!

Yii 2 Basic Project Template with swoole and Modules Yii 2 Basic Project Template is a skeleton Yii 2 application best for rapidly creating small proj

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework. It is free, Open Source and is distributed under Free Public Lice

Framework X is a simple and fast micro framework based on PHP
Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP. I've created a simple CRUD application to understand how it works. I used twig and I created a custom middleware to handle PUT, DELETE methods.

Releases(8.1.0)
  • 8.1.0(Sep 10, 2022)

    Hello all.

    This is NS 8.1.0 stable release version. Lots of new below:

    1. Totally incompatible with old version of 7+
    2. Add new Mgr classes in Core
    3. Add ProcMgr, FiberMgr, SocketMgr support
    4. Add trait System for controlling NS Core releated functions and properties
    5. Add Security library in Core/Lib for CGI, opened for CLI
    6. Main logic improved compare with ver 7+ and 8.0+
    7. Change required PHP version up to 8.1+
    8. Many code changes and performance improvements
    9. Removed some useless library from Ext

    Happy Mid-Autumn Day!

    Source code(tar.gz)
    Source code(zip)
  • v8.0.3(Jan 6, 2022)

    1. Finish five common algorithm classes;
    2. Add libZip for simple compression;
    3. Add libExeC to fully control and communicate with other programs;
    4. Improve libMPC and libSockOnRedis;
    5. Other core improvements and bug fixes.

    All users who use version 8.0.x are encouraged to update to this version.

    Source code(tar.gz)
    Source code(zip)
  • v8.0.2(Oct 27, 2021)

    First release of v8.0 A brand new version based on new structure.

    1. NOT compatible with old versions (NS_VER>8.0).
    2. File naming and function naming change to camel cased.
    3. Core re-coded. All logic improved for performance.
    4. All extensions re-coded and named as lib* for better identification.
    5. Add some algorithm class for future plans.
    6. Compatible under PHP 7.4+
    Source code(tar.gz)
    Source code(zip)
  • v7.4.5(Nov 26, 2020)

    1. Core preload in OPCache
    2. Make core as a global module
    3. Change "ns.php" to "sys.php"
    4. Support entry script including from anywhere
    5. Fix some errors under PHP 8.0

    This is the last version of NS 7.4.x branch. NS.NG will try to catch up using PHP 8.0

    Source code(tar.gz)
    Source code(zip)
  • v7.4.0(Feb 13, 2020)

    Change log:

    1. main script renamed to "ns.php" under "/core/";
    2. better core structure;
    3. ROOT, SYS_ROOT auto detect, no need to set now;
    4. make directory "app" as the default application dir;
    5. simple stand-alone entry script and main configuration file;
    6. better error track logic;
    7. remove lots of useless function codes, not fully compatible with versions before;
    8. extensions updated (not compatible with before, but easy to make it going)
    9. new features and new document (under going)
    Source code(tar.gz)
    Source code(zip)
  • 7.3.2(Mar 8, 2020)

  • 7.2.20(Jul 2, 2019)

  • 7.2.18(Feb 27, 2019)

  • 5.2.10(May 25, 2018)

  • 5.1.6(Mar 28, 2018)

  • 5.0.0(Feb 15, 2018)

    Happy Chinese Spring Festival. This is new, ready for use.

    1. New structure.
    2. Simpler core scripts.
    3. Separated extensions.
    4. Better performance.
    5. A good readme.md, thanks for translation.

    More useful extensions will be added soon, thanks for all developers.

    Source code(tar.gz)
    Source code(zip)
  • 3.2.2(Nov 17, 2017)

  • 3.2.0(Aug 19, 2017)

    1. New code style
    2. Better file structure
    3. Namespace/Non-Namespace support
    4. More useful functions & methods
    5. Some changes on API
    6. Better performance
    7. Bug fixing
    8. (∩ ͡° ͜ʖ ͡°)⊃━☆゚
    Source code(tar.gz)
    Source code(zip)
  • 2.9.6(Jul 28, 2017)

  • 2.9.0(May 11, 2017)

  • 2.8.6(Apr 4, 2017)

    1. Common kernel modules (database, session, file i/o, upload, language, error, a lot of functions, etc.)
    2. HTTP access key controlling module with cross-domain support
    3. A simple encrypt/decrypt module (you should rewrite it yourself)
    4. HTTP request data pool transferring module (works like neuronal cell, supports multiple modules/methods calling with/without data structure comparing and chain-calling with even one result from other modules/methods, etc...)
    5. Based on HTTP request data pool transferring module, now, we can simply do our coding job on the class. All the methods in the class can now be divided into very simple and short ones and could be chain-called by the HTTP request data pool transferring module.
    6. Language crossing supported by CLI module using PIPE to communicate
    7. One API entry supports both CGI and CLI

    We need people to do the job together. A lot of things undone yet. Document is the next thing we need to do.

    Source code(tar.gz)
    Source code(zip)
Owner
Jerry
Love to make friends
Jerry
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast! Condensed in a single ~65KB file

Bong Cosca 2.6k Dec 30, 2022
TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

TrailLamp Introduction TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs. Installatio

Etorojah Okon 14 Jun 10, 2022
Easy to use, fast extendable small PHP Framework, like the one you ever missed. The skeleton-APP

About Tufu-Framework Easy to use, fast extendable PHP Framework, like the one you ever missed. Features included such as: Twig and extensions. Fast ro

Giacomo Barbalinardo 0 Jul 2, 2022
Fast PHP framework made with very loose optional components.

Nimble is a super fast mini-framework for PHP built on top of optional loose components. Installation Clone the repository $ git clone [email protected]:

Neo 53 Dec 22, 2022
Lite & fast micro PHP abuse library that is **easy to use**.

Utopia Abuse Utopia framework abuse library is simple and lite library for managing application usage limits. This library is aiming to be as simple a

utopia 23 Dec 17, 2022
Fast and easy PHP framework

Español | English Fácil, rápido y en español (Or should I say fast and easy?) Bienvenidos a KumbiaPHP Framework Versión 1 Manual en construcción de la

KumbiaPHP Framework 281 Jan 2, 2023
PhpBoot is an easy and powerful PHP framework for building RESTful/Microservices APIs.

?? tiny & fast PHP framework for building Microservices/RESTful APIs, with useful features: IOC, Hook, ORM, RPC, Swagger, Annotation, Parameters binding, Validation, etc.

tknet 656 Jan 4, 2023
Simple, fast and secure PHP Framework with easy integration.

simple-php-framework Simple, fast and secure PHP Framework with easy integration.

winact 2 Nov 23, 2021
Fast and easy PHP framework

Español | English Fácil, rápido y en español (Or should I say fast and easy?) Bienvenidos a KumbiaPHP Framework Versión 1 Manual en construcción de la

KumbiaPHP Framework 280 Dec 26, 2022
LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way

LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way. You can see several applications created using LODSPeaKr.

Alvaro Graves 31 Jun 23, 2020