Download the PHP package jasonmccreary/orfail without Composer

On this page you can find all versions of the php package jasonmccreary/orfail. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package orfail

PHP OrFail Trait

OrFail is a simple trait which makes it easier to practice exceptional programming and write cleaner code.

Through magic, OrFail allows you to append OrFail to any method name and force it to fail (throw an exception) if that method returns a falsey value.

Code without OrFail:

public function someMethod() {
    $value = $this->getValue();

    if ($value === null) {
        // failure code
    }

    return $value;
}

The same code using OrFail:

public function someMethod() {
    return $this->getValueOrFail();
}

Requirements

Installation

The recommended way to install OrFail is with Composer:

composer require "jasonmccreary/orfail"

Alternatively you can download the src directory of this project and include it in your project.

Usage

Once OrFail is included in your project you may add it to any class by simply using the trait.

For example:

class Example {
    use OrFail\Traits\OrFail;

    public function someMethod() {
        // code
    }
}

Now you can call any method with OrFail appended. If the method returns a falsey value a FailingReturnValue exception will be thrown.

Configuration

OrFail has two methods you may optionally override: orFailTest() and allowedOrFailMethods().

bool orFailTest ( mixed $value )

By default orFailTest() simply tests if $value is falsey. You can override this method to perform your own failure test.

array allowedOrFailMethods ( void )

By default orFailMethods() returns an empty array which allows all methods. You can restrict which methods allow being called with OrFail appended by overriding this method and returning an array of the allowed method names.

Troubleshooting

Since OrFail uses magic methods, it is easy to create an infinite call loop if you are not careful. This most commonly results in PHP exhausting its memory or a Segmentation Fault 11.

If you wish to use the OrFail trait in a class that implements __call() you will need to resolve the conflict manually.

For example:

class YourClass {
    use OrFail\Traits\OrFail {
        OrFail::__call as __callOrFail;
    }

    public function __call($name, $parameters) {
        // your code
        $this->__callOrFail($name, $parameters);
        // your code
    }
}

Note: this is only an example of how to resolve the conflict. How you call OrFail will depend on your code.

Contributing

OrFail is a new package and needs more integration testing with other packages and codebases using __call(). Please report any problems by creating an Issue.

If you plan to submit a Pull Request, please ensure you follow the PSR-2 Style Guide.

Thanks.


All versions of orfail with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jasonmccreary/orfail contains the following files

Loading the files please wait ...