Download the PHP package maarky/lazy without Composer

On this page you can find all versions of the php package maarky/lazy. 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 lazy

Lazy Loading

This library provides a basic means of lazy loading. If you are sick of writing code like the following then you can benefit from this class.

class Whatever
{
    public $something;

    public function getSomething()
    {
        if(!$something) {
            $this->something = 'something';
        }
        return $this->something;
    }
}

There are a number of issues with this approach:

Usage

Imagine you have an Author object and a getArticles() metod that returns an array of all articles by this author. If you use this object in 100 places throughout your code but you only need the list of their articles in half of those places you aren't going to want to load the articles every time you create an Author object since the time spent will often be wasted.

The Lazy\Container class constructor takes a callback that accepts no arguments and returns any value. The get() method calls the function, stores the returned value and returns it. If you ever call the get() method again it will not call your function but will instead just return the previously generated value.

Here's an example where a repository class creates your Author instances:

class AuthorRepository
{
    public function find($id)
    {
        //query db for author with the given id
        //resulting an an array called $row

        $function = function() use($id) {
            return $this->articleRepository->findByAuthor($id)
        };
        $row['articles'] = new \maarky\Lazy\Container($function);
        return new Author($row);
    }
}

class Author
{
    public function getArticles()
    {
        return $this->articles->get();
    }
}

As you can see, the getArticles() method doesn't need to know anything about how the articles are retrieved or whether or not they have already been retrieved. It just needs to get the value from the Lazy\Container object and leaves it to that object to worry about the details.

Warning

It is important to know that this value will only be generated once. This means that it is intended to be immutable. If any change in the application or the object containing the Lazy\Container object changes and requires a new value for that Lazy\Container object then you should not use this class for that.

This behavior is intentional and it is a feature, not a bug.


All versions of lazy with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 maarky/lazy contains the following files

Loading the files please wait ....