Download the PHP package messagebooster/uflex without Composer
On this page you can find all versions of the php package messagebooster/uflex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download messagebooster/uflex
More information about messagebooster/uflex
Files in messagebooster/uflex
Package uflex
Short Description All in one PHP user authentication class
License MIT
Homepage http://ptejada.com/projects/uFlex
Informations about the package uflex
uFlex 1.0.0
A simple all-in-one PHP user Authentication library. This library is developed, maintained and tested in a PHP 5.3.x environment. The UnitTest also runs on Travis-CI for PHP 5.4.x and PHP 5.5.x.
The single class file class.uFlex.php
code can be found on the Legacy Branch
For more information:
- Check the examples here http://ptejada.com/projects/uFlex/examples/
- Try the demo in this package and review its source
- See the methods documentation here http://ptejada.com/projects/uFlex/documentation/
- For more detailed documentation check generated PHPDoc http://ptejada.com/docs/uFlex/namespaces/ptejada.uFlex.html
Upgrading from previous version...
Before updating you will need to run a SQL upgrade script. Make sure you backup your database before running the upgrade script. Refer to the DB directory https://github.com/ptejada/uFlex/tree/master/db
If not using Composer instead of including a PHP class you will include the autoload.php
script in
your application which will auto include the library classes as required.
If using composer then the just include the vendor/autoload.php
in your application if is not already
been included.
Overall version 1.0 takes a more object oriented approach and follows conventions more closely. For more information check out the API Changes
Getting Started
- Including it in your project
- Configuring the User object
- Understanding Collections
- Using the Session
- Extending the User class
Including it in your project
If using Composer just add ptejada/uflex
as a dependency. Note the casing on uflex
,
all lowercase. Ex:
When using Composer use the vendor/autoload.php
script to include the library in your
project.
If not using Composer then clone this repository in your project. Use the autoload.php
script to include the library
in your project.
Configuring the User object
When the User
class is instantiated not much happens, the session is not initialized nor a DB connection is established.
This is to allow the class to be configured. Once the configured the start()
method must be call in order for the user
authentication process
to start. For Example:
It is preferable that a configuration file like the one above is created per project. This way you can use the configuration file to provide a pre-configured User instance to any PHP script in your project.
Alternatively you could create your own class which configures and start the the User
object for you. Ex:
Below is an excerpt from the PHP class file which lists the customizable config
properties you could change prior to calling
start()
on a User
instance. Note: the config
property is a Collection
instance:
Understanding Collections
A Collection
is an object representation of an array. Collection
s have many uses throughout this project and are
easy to use. What a Collection
does for us is handle the errors for undefined indexes and streamline our code.
Consider this example working with plain arrays:
Here is the same code using a Collection
:
For more information check the API Documentation for the Collection
class.
Using the Session
The User
object provides easy management of the PHP session through its session
property which is an instance of
the Session
class. By default the User
class manages the userData
namespace in PHP super global $_SESSION but this
is configurable by setting config->userSession
before the User
object is started. This is very powerful since it lets
the User
class use the PHP session without interfering with other software the their session usage.
The Session
class is just an extended Collection
so it works like any other collection. The only difference is a few
additional methods and the fact that it is a linked collection meaning that any changes made in the object will be
reflected on $_SESSION
and thus automatically saved on the PHP session.
Consider the following code and its output to give you a better idea of how everything works together:
Here is the output of the previous code:
The Session
class can be use for other aspects of your application as well. For example to manage the entire PHP
session you could do so by instantiating the Session class without arguments: new ptejada\uFlex\Session()
For more information on the Session
class refer to the API Documentation
Extending the User class
In PHP you area able extend classes just like in any object oriented programming language. Therefore you could extend
the User
class functionality by adding your methods or modifications without having to modify the class file itself. You
just have create a new PHP class that extends the User
class: