PHPackages                             uxie/uxie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. uxie/uxie

ActiveFramework[Framework](/categories/framework)

uxie/uxie
=========

Uxie a light MVC Framework

v0.9.1beta8(3y ago)6363[1 issues](https://github.com/Uxie-Framework/Uxie/issues)MITPHPPHP ^8.0CI passing

Since Jun 23Pushed 3w ago2 watchersCompare

[ Source](https://github.com/Uxie-Framework/Uxie)[ Packagist](https://packagist.org/packages/uxie/uxie)[ RSS](/packages/uxie-uxie/feed)WikiDiscussions v0.9beta Synced today

READMEChangelog (10)Dependencies (9)Versions (37)Used By (0)

What is Uxie:
=============

[](#what-is-uxie)

Uxie is a PHP MVC Framework.

Features:
=========

[](#features)

#### - Perfect MVC environment.

[](#--perfect-mvc-environment)

#### - Box (Command Line Tool).

[](#--box-command-line-tool)

#### - DataBase Migration (phinx).

[](#--database-migration-phinx)

#### - Security (secured against SQL injection, XSS, CSRF).

[](#--security-secured-against-sql-injection-xss-csrf)

#### - IOC (Inversion of control) Container.

[](#--ioc-inversion-of-control-container)

#### - Router (REST).

[](#--router-rest)

#### - Authentication.

[](#--authentication)

#### - Middlewares.

[](#--middlewares)

#### - Templating Engine (Blade):

[](#--templating-engine-blade)

#### - ORM Model.

[](#--orm-model)

#### - Visitors Data Recorder.

[](#--visitors-data-recorder)

#### - Request &amp; Response Handlers.

[](#--request--response-handlers)

#### - Automatic Exception handling.

[](#--automatic-exception-handling)

#### - Errors / Exceptions logger.

[](#--errors--exceptions-logger)

#### - Built-in functions (Helpers).

[](#--built-in-functions-helpers)

Documentation:
==============

[](#documentation)

Installing:
-----------

[](#installing)

Using Composer:

```
  composer create-project uxie/uxie

```

Routing:
--------

[](#routing)

All routes are defined in : `App/Routes.php`

#### Available Methods:

[](#available-methods)

GET, POST, PUT, PATCH, DELETE

To use PUT, PATCH, DELETE methods your HTML

 method must be 'POST' inside the form you must put `csrf_method(string $method)`, csrf\_method('PUT') will echo this automatically:```
write('this is a middleware');
    }
}
```

#### Middlewares locators:

[](#middlewares-locators)

To use Middlewares and short names you must first register the shortname in App/MiddlewaresLocator.php:

```
return [
    'statistics' => \Middleware\Statistics::class,
];
```

#### How To assign a middleware to a route

[](#how-to-assign-a-middleware-to-a-route)

```
// 'statistics' short name example:
$route->get('user', 'controller@method')->middleware('statistics');
```

Security ( against SQL injection, XSS, CSRF):
---------------------------------------------

[](#security--against-sql-injection-xss-csrf)

#### SQL injection:

[](#sql-injection)

Uxie is secured against both first and second order sql injection attacks.

#### XSS:

[](#xss)

Uxie templating engine (Blade) escape html+js when printing data.

#### CSRF:

[](#csrf)

Uxie comes with built in feature that protect against CSRF when using ('POST','PATCH','PUT','DELETE') methods, So every HTML form should contain: csrf\_field()

```

        csrf_field();

```

IOC Container:
--------------

[](#ioc-container)

uxie comes with a IOC container that resolves all of your classes dependencies and their dependencies and so on to use it :

```
// instead of this:
$myClass = new \Namespace\MyClass( new Class1(), new Class2( new Class3()));

// you can use this:
$myClass = container()->build('\Namespace\MyClass');

// if you have some arguments
// instead of this:
$myClass = new \Namespace\MyClass('argument1', 'argument2');

// use this
container()->build('\Namespace\Myclass', ['argument1', 'argument2']);

container()->get('MyClass')->someMethod();
// or this:
contaienr()->MyClass->someMethod();
```

#### IOC Service Provider:

[](#ioc-service-provider)

Service provider located in `App/Services.php`It contains aliases and sevices that should be loaded when the application start:

```
        'ServiceLocators' => [
            'Router'     => \Router\Router::class,
            'Kernel'     => \Kernel\Kernel::class,
            'Compiler'   => \Kernel\Compiler\Compiler::class,
            'Middleware' => \App\Middleware\Middleware::class,
            'Dotenv'     => \Dotenv\Dotenv::class,
            'Auth'       => \Authenticator\Auth::class,
        ],

        'ServiceProviders' => [
            Jenssegers\Blade\Blade::class,
        ],
```

#### The global $container:

[](#the-global-container)

the `container()`function is global in the framework (can be used everywhere, it contains all the objects created by the IOC container),

```
// create an instance
container()->build('someclass');

// access created instance
container()->someClass->someMethod();
```

Uxie Model:
-----------

[](#uxie-model)

how to use it:

```
use Model/Model;
```

Insert data:

```
Model\MyModel::insert([
  'value1' => $value1,
  'value2' => $value2,
])->save();
```

Update data:

```
Model\MyModel::update([
  'value1' => $newValue1,
  'value2' => $newValue2,
])->save();
```

Retrieve data:

```
$data = Model\MyModel::select()->where('name', '=', 'user')->limit(10)->get();
```

Retrieve single row:

```
$user = Model\MyModel::find('name', 'MyName');
```

Soft delete : by default uxie migration add a softdelete column to the table softdelete method will change the value of softdelete column NOTE: select won't return any soft deleted rows

```
  Model\MyModel::delete()->where('id' , '=', $id)->save();
```

to hard delete a row use hardDelete method:

```
  Model\MyModel::hardDelete()->where('id' , '=', $id)->save();
```

There is also plenty of other methods such as limit(), orderBy(), groupBy(), count(), join, update and delete. simple example:

```
Model\MyModel::select()->where('name', '=', 'user')->or('name', '=', 'other-user')->orderBy('date')->get();
```

Visitors Statistics:
--------------------

[](#visitors-statistics)

It's a built-in middleware that record each user data and store it in a database table, Data such as ip, browser, os, PreviousUrl, CurrentUrl, date, and memory usage

Validation:
-----------

[](#validation)

How to use it:

```
use Validator\Validator as Validator;

Validator::start();
```

Available validation methods :

```
$validator = Validator::start();
$validator->setInput(string $input); // optional
$validator->required([string $input], string $errorMsg)
$validator->length([string $input], int $min, int $max, string $errorMsg)
$validator->email([string $input], string $errorMsg)
$validator->isip([string $input], string $errorMsg)
$validator->isint([string $input], string $errorMsg)
$validator->isfloat([string $input], string $errorMsg)
$validator->url([string $input], string $errorMsg)
$validator->unique([string $input], string $model, string $column, string $errorMsg)
$validator->equals([string $input],mixed $value, string $errorMsg)
```

To validate POST inputs:

```
use Validator\Validator as Validator;

public function someMethod(Request $request, Response $response)
{
    $validator = Validator::start()
    ->length($request->body->name, 4, 10, 'Failed validation Msg')
    ->required($request->body->name, 'Failed validation Msg')
    ->unique($request->body->name, 'User', 'name', 'Failed validation Msg')
    ->validate();

    // Or using setInput method

    $validator = Validator::start()->setInput($request->body->name)
    ->length(4, 10, 'Failed validation Msg')
    ->required('Failed validation Msg')
    ->unique('User', 'name', 'Failed validation Msg')
    ->validate();

    var_dump($validator->getErrors());
}
```

the above example will return error messages in this form:

```
    [
        'Failed validation Msg',
        'Failed validation Msg',
        'Failed validation Msg',
    ]
```

Filters:
--------

[](#filters)

Filters are meant to validate input from user. To create a new filter use Box :

```
php box filter LoginForm

```

this will create a new file in App/Filters something like :

```
class LoginForm extends Validator implements Filterable
{

    public function __construct(Request $request)
    {
        //
    }

    public function check(): bool
    {
        if ($this->isValide()) {
            return true;
        }

        return false;
    }
}
```

Notice that: filters extends validators so we can use all validators inside the class filters must have a check method which return if the validation is true (passed) or false (didn't pass).

Let's validate login form by adding validations to the constructor :

```
  public function __construct(Request $request)
    {
        $this->setInput($request->body->email)
        ->required('E-mail is required')
        ->email('Your e-mail is not a valide e-mail)
        ->setInput($request->body->password)
        ->required('password is required')
        ->validate();
    }
```

Exception handler:
------------------

[](#exception-handler)

`Uxie` comes with a built-in exceptions handler that will handle thrown exceptions / errors automatically.

Errors logger:
--------------

[](#errors-logger)

All errors/exceptions thrown during runtime will be logged in `log/All_errors.log` with information about error such as file, line, code and error-Message.

Helpers:
--------

[](#helpers)

Helpers are functions available to use everywhere inside the framework such as `csrf_field()`, `csrf_token()`, `container()`.
All function are listed in `framework/helpers/helpers.php`.

examples:

```
csrf_field();
// echo something like this

csrf_token();
// returns csrf token value

method_field(string $method);
// echo something like
