Rinvex Support Package: Basic controller with foundations out-of-the-box
Rinvex Repository Package: Clean & Intuitive API Rinvex Repository Package: Basic Functionality Rinvex Repository Package: Config Options

Rinvex Support

FREE & Open source $0.00

Rinvex Support support helpers, contracts, and traits required by various Rinvex packages. Validator functionality, and basic controller included out-of-the-box.

Rinvex Support

Rinvex common support helpers, contracts, and traits required by various Rinvex packages. Validator functionality, and basic controller included out-of-the-box.

Packagist License VersionEye Dependencies Scrutinizer Code Quality Code Climate StyleCI SensioLabs Insight

Table Of Contents

Installation

The best and easiest way to install this package is through Composer.

Compatibility

This package fully compatible with Laravel 5.1.*, 5.2.*, and 5.3.*.

While this package tends to be framework-agnostic, it embraces Laravel culture and best practices to some extent. It's tested mainly with Laravel but you still can use it with other frameworks or even without any framework if you want.

Prerequisites

"php": ">=5.5.9",
"illuminate/bus": "5.1.*|5.2.*|5.3.*",
"illuminate/http": "5.1.*|5.2.*|5.3.*",
"illuminate/support": "5.1.*|5.2.*|5.3.*",
"illuminate/contracts": "5.1.*|5.2.*|5.3.*",
"illuminate/validation": "5.1.*|5.2.*|5.3.*",
"illuminate/routing": "5.1.*|5.2.*|5.3.*",
"illuminate/auth": "5.1.*|5.2.*|5.3.*"

Require Package

Open your application's composer.json file and add the following line to the require array:

"rinvex/support": "1.0.*"

Note: Make sure that after the required changes your composer.json file is valid by running composer validate.

Install Dependencies

On your terminal run composer install or composer update command according to your application's status to install the new requirements.

Note: Checkout Composer's Basic Usage documentation for further details.

Integration

Rinvex Support package is framework-agnostic and as such can be integrated easily natively or with your favorite framework.

Native Integration

Integrating the package outside of a framework is incredibly easy, just require the vendor/autoload.php file to autoload the package.

Note: Checkout Composer's Autoloading documentation for further details.

Laravel Integration

Integrating the package inside Laravel framework takes much less work, actually it doesn't require any integration steps after installation. Just jump directly to the Usage section. Awesome, huh?

Usage

Redirectable Trait

The Rinvex\Support\Traits\Redirectable provides an easy way to redirect users efficiently and get appropriate response depending on wether it's ajax or normal request. First, your class MUST implement the appropriate interface and use the corresponding trait:

use Rinvex\Support\Traits\Redirectable;
use Rinvex\Support\Contracts\RedirectionContract;

class FooController implements RedirectionContract
{
    use Redirectable;
}

Redirect users to the previous page with flash message:

return $this->redirect([
    'back' => true,
    'with' => ['status' => 'Action failed!'],
]);

Redirect users to the home page with flash error message:

return $this->redirect([
    'home'       => true,
    'withErrors' => ['no_permission' => 'Sorry, you do not have appropriate permissions!'],
]);

Note: The Rinvex\Support\Traits\Redirectable trait works intuitively like Laravel's standard redirect helper redirect(), so it takes same default arguments. It's just a wrapper around Laravel's redirect() helper with some extra functionality like checking request type (ajax/normal) and return response accordingly.

Validateable Trait

The Rinvex\Support\Traits\Validateable trait provides a fluent, convenient wrapper for working with data validation. First, your class MUST implement the appropriate interface and use the corresponding trait:

use Rinvex\Support\Traits\Validateable;
use Rinvex\Support\Contracts\ValidationContract;

class FooController implements ValidationContract
{
    use Validateable;
}

setValidationFactory(), getValidationFactory()

The setValidationFactory method sets the validation factory instance, while getValidationFactory returns it:

// Require validation contract
use Illuminate\Contracts\Validation\Factory as ValidationFactory;

// Instantiate validator instance
$validator = app(ValidationFactory::class);

// Set the validation factory instance
$validator->setValidationFactory($validator);

// Get the validation factory instance
$validator->getValidationFactory();

setValidationRules(), getValidationRules()

The setValidationRules method sets the validation rules, while getValidationRules returns it:

// Set validation rules
$this->setValidationRules(['name' => 'required', 'email' => 'required|email|{{foo}}']);

// Get validation rules
$this->getValidationRules();

Note: The {{foo}} variable is NOT native validation rule, it's a placeholder that will be bound and resolved later, see the following section setValidationBindings(), getValidationBindings() for more details.

setValidationMessages(), getValidationMessages()

The setValidationMessages method sets the validation messages, while getValidationMessages returns it:

// Set validation messages
$this->setValidationMessages(['name' => 'name is required', 'email' => 'email is required']);

// Get validation messages
$this->getValidationMessages();

setValidationCustomAttributes(), getValidationCustomAttributes()

The setValidationCustomAttributes method sets the validation custom attributes, while getValidationCustomAttributes returns it:

// Set custom validation attributes
$this->setValidationCustomAttributes(['first_name' => 'First Name', 'last_name'  => 'Last Name']);

// Get custom validation attributes
$this->getValidationCustomAttributes();

setValidationBindings(), getValidationBindings()

The setValidationBindings method sets the validation bindings, while getValidationBindings returns it:

// Set the validation bindings
$this->setValidationBindings(['foo' => 'alpha']);

// Get the validation bindings
$this->getValidationBindings();

Note: The {{foo}} variable was mentioned before in the previous section setValidationRules(), getValidationRules(), and it's time now to bind and resolve it. The validation rule now is processed as required|email|alpha through the protected method getBoundValidationRules. It's useful for some scenarios like verifying uniqueness and dynamic validation rules.

validate()

The validate method validates passed data, it's where the real validation work happen and it returns a validator instance:

// Validate passed data
$validator = $this->validate(['name' => 'Somebody', 'email' => 'test@example.com']);

// Check if validation fails
if ($validator->fails()) {
    // Do something
}

Support Helpers

lower_case()

The lower_case method converts the given string to lower-case:

$lowercaseStr = upper_case('THIS UPPER CASE TEXT WILL BE LOWER CASED');

upper_case()

The upper_case method converts the given string to upper-case:

$uppercaseStr = upper_case('this lower case text will be capitalized');

mimetypes()

The mimetypes method gets valid mime types:

$mimetypes = mimetypes();

timezones()

The timezones method gets valid timezones:

$timezones = timezones();

Note: This package follows the FIG PHP Standards Recommendations compliant with the PSR-1: Basic Coding Standard, PSR-2: Coding Style Guide and PSR-4: Autoloader to ensure a high level of interoperability between shared PHP code.

Support

The following support channels are available at your fingertips:

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to help@rinvex.com. All security vulnerabilities will be promptly addressed.

Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

Our Standards

Examples of behavior that contributes to creating a positive environment include:

  • Using welcoming and inclusive language
  • Being respectful of differing viewpoints and experiences
  • Gracefully accepting constructive criticism
  • Focusing on what is best for the community
  • Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

  • The use of sexualized language or imagery and unwelcome sexual attention or advances
  • Trolling, insulting/derogatory comments, and personal or political attacks
  • Public or private harassment
  • Publishing others' private information, such as a physical or electronic address, without explicit permission
  • Other conduct which could reasonably be considered inappropriate in a professional setting

Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at help@rinvex.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4

This project adheres to the following standards and practices.

Versioning

This project is versioned under the Semantic Versioning guidelines as much as possible.

Releases will be numbered with the following format:

  • <major>.<minor>.<patch>
  • <breaking>.<feature>.<fix>

And constructed with the following guidelines:

  • Breaking backward compatibility bumps the major and resets the minor and patch.
  • New additions without breaking backward compatibility bumps the minor and resets the patch.
  • Bug fixes and misc changes bumps the patch.

Support Policy

  • This package adheres to the following release cycle:
    • LTS Releases:
      • Released Every 2 years
      • Gets 2 years bug fixes
      • Gets 3 years security fixes
    • General Releases:
      • Released Every 6 months
      • Gets 6 months bug fixes
      • Gets 12 months security fixes
  • As of next Laravel LTS release, long term support (LTS) will be provided for this package. This support and maintenance window is the largest ever provided for Rinvex packages and provides stability and peace of mind for larger, enterprise clients and customers.

Coding Standards

This project follows the FIG PHP Standards Recommendations compliant with the PSR-1: Basic Coding Standard, PSR-2: Coding Style Guide and PSR-4: Autoloader to ensure a high level of interoperability between shared PHP code. If you notice any compliance oversights, please send a patch via pull request.

Pull Requests

The pull request process differs for new features and bugs.

Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed, please leave a comment detailing your proposed fix or create a pull request with the fix mentioning that issue id.

Proposal / Feature Requests

If you have a proposal or a feature request, you may create an issue with [Proposal] in the title.

The proposal should also describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature.

Which Branch?

This project follows Git-Flow, and as such has master (latest stable releases), develop (latest WIP development) and X.Y support branches.

Note: Pull requests which do not follow these guidelines will be closed without any further notice.

The MIT License (MIT)

Copyright (c) 2016, Rinvex LLC,

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

v1.0.0 - 2016-06-22

  • Commit first draft