Download the PHP package kengoldfarb/underscore_libs without Composer
On this page you can find all versions of the php package kengoldfarb/underscore_libs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kengoldfarb/underscore_libs
More information about kengoldfarb/underscore_libs
Files in kengoldfarb/underscore_libs
Package underscore_libs
Short Description _php libraries
License MIT
Homepage http://underscorephp.com
Informations about the package underscore_libs
UnderscorePHP _Libs
A set of useful, framework-agnostic PHP libraries to make life easier
Goal: A set of libraries that are useful, flexible, and can be used within any framework.
Installation
Composer
Using the composer package manager, In your composer.json file add:
Then install it (from the same directory as composer.json): php composer.phar install
Manual Installation
You can either download the latest release or you can just grab the source of an individual library and plug it in to your project.
Usage
Here you'll find information and examples about each of the libraries. These examples may not cover all permutations of how a library may be used. For more advanced details please view the source code...hopefully you'll find that the comments are very verbose and easy to understand.
- Logging: A logging class that also logs objects!
- Encryption: Simple AES or RSA (pub/private key) encryption
- UUID: Generate and work with uuids
- Database (MySQL): MySQL database wrapper class with some nicities
- File: Makes working with files easier
- Random: Generate random numbers, strings.
- ServiceResponse: For API responses to generate consistent json or xml responses
- Session: A session wrapper to provide additional error checking
- SSL: Methods to check if SSL is active or require SSL
- Web Response: Some nice utility stuff like setting P3P headers, sending http status codes, etc.
- Info: Extract information about a web request
Tests
Tests can be found in the 'tests' directory and can be run with phpunit. If you've cloned this repository, you can run the tests...
Logging
The logging library provides are log levels and the ability to log complex objects.
Logs are written via php's native function. The location of the log message may appear in a file, webserver log, syslog, etc. depending on your settings.
Change the error_log setting in your php.ini file to adjust the location.
Options
You can set the following options on the logger:
- Default: DEBUG
The log level may be set to one of:
Once set, any logs at or above that level will be logged. For example, if I set the level to INFO, any 'debug' logs will not be written but a 'warn' log would be written.
- Default: TRUE
Boolean. Whether or not to log complex objects.
- Default: FALSE
Boolean. Whether to use php's for log messages. Can be handy for CLI scripts.
- Default: FALSE
Boolean. Whether to throw an exception if an error log can't be written. In most cases you probably want to leave this FALSE
Examples
Encryption
The Crypt class provides AES and RSA encryption and decryption methods.
AES encryption with PKCS7 padding
Options
$textToEncrypt Required
$key Required
$cipher Optional
Default: MCRYPT_RIJNDAEL_256 Allowed values are: MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_192, MCRYPT_RIJNDAEL_256
$mode Optional
Default: MCRYPT_MODE_CBC Allowed values are: MCRYPT_MODE_CBC, MCRYPT_MODE_ECB, MCRYPT_MODE_CFB, MCRYPT_MODE_OFB, MCRYPT_MODE_NOFB, MCRYPT_MODE_STREAM
Basic Example
RSA encryption (public/private keys)
This type of encryption is perfect for situations where you need to encrypt something within an application that doesn't need to be decrypted within the application. In that case you could keep the decryption (private) key off your application server for added security.
Generate RSA Public/Private keypair
Generate a keypair. You can optionally pass in $keybits which may be one of: 1024, 2048, 4096
RSA Encrypt/Decrypt
UUID
This library provides functions for working with a UUID or "Universally Unique Identifier".
Generate a UUID
Options
$withHyphens Default: TRUE This single option can be passed to the function that controls over whether or not the UUID will contain hyphens.
Example
Convert UUID string to binary representation
Example
Convert UUID in binary to string representation
Options
$withHyphens Default: TRUE This single option can be passed to the function that controls over whether or not the UUID will contain hyphens.
Example
Database
Wrapper for the mysqli library. Provides both regular and static class interfaces. In most cases you'll want to use the static interface which will share the DB connection within your application. This helps prevent the opening of uncessary connections.
Public variables
$mysqli For non-static interfaces, you can access the 'mysqli' object directly.
Note: the below examples assume you're using the static version of the DB class. The non-static versions of the functions have the same name without the beginning underscore. I.e. _Log::_query($sql) corresponds to $db->query($sql)
Examples
Create a connection
Create a query, escape it, get the number of rows and process the rows
Insert a new row into the db and get the resulting id
File
Simplifies the task of writing and reading from files
Regular Methods
- writeToFile($textToWrite, $filename = NULL)
- getFilePermissions($filename = NULL)
- readAllFromFile($filename = NULL)
- readByLineFromFile($filename = NULL)
- deleteFile($filename)
- getTemporaryFileDirectory()
Static Methods
- _writeToFile($textToWrite, $filename, $permissions = _FileConstants::READ_WRITE_END_OF_FILE_CREATE)
- _readAllFromFile($filename, $permission = _FileConstants::READ_ONLY)
Options
Some of the methods will allow you to pass a constant specifying which permissions the file should be opened with. The available (self explanitory) options are: _FileConstants::READ_ONLY _FileConstants::READ_WRITE _FileConstants::WRITING_ONLY_CREATE _FileConstants::READ_WRITE_TRUNCATE_CREATE _FileConstants::WRITE_ONLY_END_OF_FILE_CREATE _FileConstants::READ_WRITE_END_OF_FILE_CREATE _FileConstants::WRITE_ONLY_BEGIN_OF_FILE _FileConstants::READ_WRITE_BEGIN_OF_FILE _FileConstants::WRITE_ONLY_NO_TRUNCATE_BEGIN_OF_FILE _FileConstants::READ_WRITE_NO_TRUNCATE_BEGIN_OF_FILE
Examples
Read from file
Write to file
Info
General info and helper class.
Get the user's IP address
Gets the user's ip. This should work behind load balancers. It will first check for the header for the ip address. If that isn't set it will use .
Get the current datetime in a mysql friendly format
Random
Get Random Number
_getRand($min, $max)
Get Random String
_randString($length, $lettersNumbersOnly = false)
Get Random Character
_randCharacter($start = 32, $end = 126)
Parameters
$start The ascii character code to start from $end The ascii character code to end at
See http://www.asciitable.com for a list of character codes
Service Response
This library generates json or xml responses in a consistent format.
Parameters
$objects Any object to be serialized. String, number, object, array, etc. $echoResponse optional Whether or not to echo the response $format optional 'json' or 'xml'
Success
_success($objects, $echoResponse = TRUE, $format = 'json')
Failure
_failure($objects, $echoResponse = TRUE, $format = 'json')
SSL
TODO
Session
TODO
Web Response
TODO
Versioning
This project will follow the guidelines set forth in Semantic Versioning;
Contact
Author: Ken Goldfarb
License
MIT