Download the PHP package yii2tech/embedded without Composer

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

Embedded (Nested) Models Extension for Yii 2


This extension provides support for embedded (nested) models usage in Yii2. In particular it allows working with sub-documents in MongoDB and ElasticSearch as well as processing complex JSON attributes at relational databases.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Usage

This extension grants the ability to work with complex model attributes, represented as arrays, as nested models, represented as objects. To use this feature the target class should implement [[\yii2tech\embedded\ContainerInterface]] interface. This can be easily achieved using [[\yii2tech\embedded\ContainerTrait]].

For each embedded entity a mapping declaration should be provided. In order to do so you need to declare method, which name is prefixed with 'embedded', which should return the [[Mapping]] instance. You may use [[hasEmbedded()]] and [[hasEmbeddedList()]] for this.

Per each of source field or property a new virtual property will be declared, which name will be composed by removing 'embedded' prefix from the declaration method name.

Note: watch for the naming collisions: if you have a source property named 'profile' the mapping declaration for it should have different name, like 'profileModel'.

Example:

Each embedded mapping may have additional options specified. Please refer to [[\yii2tech\embedded\Mapping]] for more details.

Processing embedded objects

Embedded feature is similar to regular ActiveRecord relation feature. Their declaration and processing are similar and have similar specifics and limitations. All embedded objects are lazy loaded. This means they will not be created until first demand. This saves memory but may produce unexpected results at some point. By default, once embedded object is instantiated its source attribute will be unset in order to save memory usage. You can control this behavior via [[\yii2tech\embedded\Mapping::$unsetSource]].

Embedded objects allow simplification of nested data processing, but usually they know nothing about their source data meaning and global processing. For example: nested object is not aware if its source data comes from database and it does not know how this data should be saved. Such functionality usually is handled by container object. Thus at some point you will need to convert data from embedded objects back to its raw format, which allows its native processing like saving. This can be done using method refreshFromEmbedded():

While embedding list of objects (using [[\yii2tech\embedded\ContainerTrait::mapEmbeddedList()]]) the produced virtual field will be not an array, but an object, which satisfies [[\ArrayAccess]] interface. Thus all manipulations with such property (even if it may look like using array) will affect container object. For example:

Validating embedded models

Each embedded model should declare its own validation rules and, in general, should be validated separately. However, you may simplify complex model validation using [[\yii2tech\embedded\Validator]]. For example:

Note: pay attention that [[\yii2tech\embedded\Validator]] must be set for the embedded model name - not for its source attribute. Do not mix them up!

You can enable [[\yii2tech\embedded\Validator::$initializedOnly]], allowing to skip validation for the embedded model, if it has not been initialized, e.g. requested at least once. This will save the performance in case source model can be used in different scenarios, some of which may not require embedded model manipulations. However, in this case embedded source attribute value will not be validated. You should ensure it validated in other way or it is 'unsafe' for population via [[\yii\base\Model::load()]] method.

Saving embedded models

Keep in mind that embedded models are stored separately from the source model attributes. You will need to use [[\yii2tech\embedded\ContainerInterface::refreshFromEmbedded()]] method in order to populate source model attributes with the data from embedded models.

Also note, that attempt to get 'dirty' value for embedded source attribute will also fail until you use refreshFromEmbedded() even, if embedded model has changed:

In case you are applying 'embedded' functionality to an ActiveRecord class, the best place for the data synchronization is [[\yii\db\BaseActiveRecord::beforeSave()]] method. For example, application of this extension to the [[\yii\mongodb\ActiveRecord]] class may look like following:

Predefined model classes

This extension is generic and may be applied to any model with complex attributes. However, to simplify integration with common solutions several base classes are provided by this extension:

Provided ActiveRecord classes already implement [[\yii2tech\embedded\ContainerInterface]] and invoke refreshFromEmbedded() on beforeSave() stage. For example, if you are using MongoDB and wish to work with sub-documents, you may simply switch extending from regular [[\yii\mongodb\ActiveRecord]] to [[\yii2tech\embedded\mongodb\ActiveRecord]]:


All versions of embedded with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.14
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 yii2tech/embedded contains the following files

Loading the files please wait ....