Download the PHP package laszlovl/yii2-staticactiverecord without Composer

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

yii2-staticactiverecord

A faster but slightly less flexible version of Yii2's ActiveRecord.

Build Status

DESCRIPTION

Yii2 is a great framework, and its flexibility is a big part of that. As usual though, flexibility comes at the cost of performance, and sometimes the performance impact might not be worth the tradeoff.

This code focusses specifically on Yii2's ActiveRecord. Because of ActiveRecord's flexibility, a lot of calculations have to be done at runtime: look up the corresponding database schema, derive the list of attributes from that, determine the list of safe attribute for each scenario based on the model's rules(), etcetera.

In Yii2's architecture, most of these calculations are not only done once (per request) for every one of your ActiveRecord classes, but for every one of your ActiveRecord instances.

Take this code as example:

The call to ->owner will be forwarded to __get(), which will call hasAttribute(), which will call attributes(), which will call getTableSchema(), which will use the DI container to retrieve a reference to the db component, and so on. All of this just to determine whether your Cat class has a native property $owner or that it should be resolved as ActiveRecord property, or perhaps as a relation. This is done not just once, but 100 times: again for every one of your Cat instances.

Is all this necessary? This of course depends on the way your application is designed. For example, it's very possible to attach behaviors to objects at runtime, causing one of your cats to have a owner relation, while another one doesn't. Or to override attributes() to completely hide the owner property based on the value of one of the other properties of the instance.

But in a lot of applications this isn't the case: while different instances of a class would of course have different values, their metadata would be static: either all of your Cats have a property owner, or none of them do. If one of your cat instances is found to have the MiowBehavior, all other cats would have it as well.

If this is indeed the case for your application, we can cache this metadata on the class level: once it's calculated for one instance of a class, for all other instances it can be looked up instantly. This extension's ActiveRecord does just that, by using a static class variable to cache the result of a function between all instances of the containing class.

This can enormously benefit your application's performance, especially for requests that handle a lot of instances of the same class, like a GridView or ListView with a large pagination size, or an API call on a resource collection.

BENCHMARKS

The extension comes with a benchmark tool to measure the performance improvements for a few very simple scenarios. In all cases, 1000 instances of the same class are created.

The sum of the performance improvements in a single request of course highly depends on your specific application, but I've been able to reduce the response time for one of my application's heavy requests by more than 50%.

TESTS

The extension re-uses Yii's existing ActiveRecordTest suite, overriding the default ActiveRecord implementation with the one in this extension. This shows that none of the testcases included in Yii are broken by this extension's behavior.

CAVEATS

As was said, this extension is not for everyone. Some signs that it might not be suitable for a specific class:

INSTALLATION

Via composer: composer require laszlovl/yii2-staticactiverecord

After that, simply extend your ActiveRecord classes from lvl\staticactiverecord\db\ActiveRecord instead of yii\db\ActiveRecord.


All versions of yii2-staticactiverecord with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.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 laszlovl/yii2-staticactiverecord contains the following files

Loading the files please wait ....