PHPackages                             getpop/component-model-configuration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. getpop/component-model-configuration

ActiveLibrary[API Development](/categories/api)

getpop/component-model-configuration
====================================

Adds the configuration layer to the component model

1.0.6(2y ago)11.2k3GPL-2.0-or-laterPHPPHP ^8.1

Since Jan 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/getpop/component-model-configuration)[ Packagist](https://packagist.org/packages/getpop/component-model-configuration)[ Docs](https://github.com/getpop/component-model-configuration)[ RSS](/packages/getpop-component-model-configuration/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (39)Used By (3)

Component Model Configuration
=============================

[](#component-model-configuration)

Adds the configuration level to the component hierarchy, through which the data API can be extended into an application

Install
-------

[](#install)

Via Composer

```
composer require getpop/component-model-configuration
```

Development
-----------

[](#development)

The source code is hosted on the [GatoGraphQL monorepo](https://github.com/GatoGraphQL/GatoGraphQL), under [`SiteBuilder/packages/component-model-configuration`](https://github.com/GatoGraphQL/GatoGraphQL/tree/master/layers/SiteBuilder/packages/component-model-configuration).

Usage
-----

[](#usage)

Initialize the component:

```
\PoP\Root\App::stockAndInitializeModuleClasses([([
    \PoP\ConfigurationComponentModel\Module::class,
]);
```

Architecture Design and Implementation
--------------------------------------

[](#architecture-design-and-implementation)

### Configuration

[](#configuration)

Configuration values are added under functions:

- `function getImmutableConfiguration($component, &$props)`
- `function getMutableonmodelConfiguration($component, &$props)`
- `function getMutableonrequestConfiguration($component, &$props)`

For instance:

```
// Implement the components properties ...
function getImmutableConfiguration($component, &$props)
{
  $ret = parent::getImmutableConfiguration($component, $props);

  switch ($component->name) {
    case self::COMPONENT_SOMENAME:
      $ret['description'] = __('Some description');
      $ret['classes']['description'] = 'jumbotron';
      break;
  }

  return $ret;
}
```

Please notice that the configuration receives the `$props` parameter, hence it can print configuration values set through props. `immutable` and `mutable on model` configuration values are initialized through `initModelProps`, and `mutable on request` ones are initialized through `initRequestProps`:

```
// Implement the components properties ...
function getImmutableConfiguration($component, &$props)
{
  $ret = parent::getImmutableConfiguration($component, $props);

  switch ($component->name) {
    case self::COMPONENT_SOMENAME:
      $ret['showmore'] = $this->getProp($component, $props, 'showmore');
      $ret['class'] = $this->getProp($component, $props, 'class');
      break;
  }

  return $ret;
}

function initModelProps($component, &$props)
{
  switch ($component->name) {
    case self::COMPONENT_SOMENAME:
      $this->setProp($component, $props, 'showmore', false);
      $this->appendProp($component, $props, 'class', 'text-center');
      break;
  }

  parent::initModelProps($component, $props);
}
```

### Client-Side Caching

[](#client-side-caching)

To cache the configuration for all components in the client, and keep them available to be reused, we simply deep merge all the responses together. For instance, if the first request brings this response:

```
{
  "component1": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      }
    }
  }
}
```

And the second response brings this response:

```
{
  "component3": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component4": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

Then deep merging the responses together will result in:

```
{
  "component1": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      }
    }
  },
  "component3": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component4": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

And we can perfectly reuse the configuration starting from "component1" to reprint the first request, and the configuration starting from "component3" to reprint the second request.

That was easy, however from now on it gets more complicated. What happens if the component's descendants are not static, but can change depending on the context, such as the requested URL or other inputs? For instance, we could have a component "single-post" which changes its descendant component based on the post type of the requested object, choosing between components "layout-post" or "layout-event", so that the component hierarchy alternates from this:

```
"single-post"
  components
    "layout-post"
```

to this:

```
"single-post"
  components
    "layout-event"
```

Similarly, even within the same component hierarchy, a component could have a property value change for different URLs. For instance, a component "post-layout" can have a property "class" with value "post-{id}", where "{id}" is the id of the requested post, so that we can add styles for specific posts such as `.post-37 { background-color: red; }` and `.post-224 { background-color: green; }`. Then, posts with ids 37 and 224, even though they have the same component hierarchy, their configurations will alternate from this:

```
"single-post"
  components
    "layout-post"
      configuration
        class: "post-37"
```

to this:

```
"single-post"
  components
    "layout-post"
      configuration
        class: "post-224"
```

Let's explore what happens in these two situations described above when deep merging the results. In the first case, for instance, if the first request brings this response:

```
{
  "component1": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      }
    }
  }
}
```

And the second response brings this response:

```
{
  "component1": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component3": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

Then deep merging the responses together will result in:

```
{
  "component1": {
    configuration: {
      class: "topcomponent"
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      },
      "component3": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

As it can be seen, after merging the response from the second request, the data that was the same (`class: "topcomponent"`) didn't affect the merged object, and the new information was appended to the existing object but without overriding any data. However, originally the first response has "component1" with only "component2" as a descendant, but after the merge, "component1" has two descendants, "component2" and "component3". Then, if loading again the URL for the first response and reusing the cached configuration, below "component1" it will print "component2" and "component3" instead of only "component2" as it should be.

To address this issue, the configuration can add a property "descendants" explicitly declaring which are its subcomponents, to know which components must be rendered and ignore the rest, even though their data is still part of the merged JSON object. Then, the first and second response will look like this:

```
{
  "component1": {
    configuration: {
      class: "topcomponent",
      descendants: ["component2"]
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      }
    }
  }
}

{
  "component1": {
    configuration: {
      class: "topcomponent",
      descendants: ["component3"]
    },
    components: {
      "component3": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

And the merged configuration will look like this:

```
{
  "component1": {
    configuration: {
      class: "topcomponent",
      descendants: ["component3"]
    },
    components: {
      "component2": {
        configuration: {
          class: "some-class"
        }
      },
      "component3": {
        configuration: {
          class: "another-class"
        }
      }
    }
  }
}
```

But now, the value for property "descendants" in the cached object has been overriden with the value from the second response, bringing us to the second issue stated earlier on about differing property values. Then, if loading again the URL for the first response and reusing the cached configuration, below "component1" it will print "component3" instead of "component2" as it should be.

The issue about differing properties arises from the fact that configuration values are set not only according to the component hierarchy, but also to the requested URL. For instance, the following component hierarchy:

```
"single-post"
  components
    "layout-post"
```

Can produce the following two different configuration outputs:

```
"single-post"
  components
    "layout-post"
      configuration
        class: "post-37"
```

and

```
"single-post"
  components
    "layout-post"
      configuration
        class: "post-224"
```

The solution is to deep merge the configurations from different requests without overriding differing properties, either at the component hierarchy or URL levels, is to have the configuration split into 3 separate subsections: "immutable", "mutableonmodel" (where "model" is equivalent to "component hierarchy") and "mutableonrequest". Every property in the configuration must be placed under exactly 1 of the 3 sections, like this:

- **immutable:** Contains properties which never change, such as `class: "topcomponent"`
- **mutableonmodel:** Contains properties which can change based on the component hierarchy, such as `descendants: ["component2"]`
- **mutableonrequest:** Contains properties which can change based on the requested URL, such as `class: "post-37"`

Following this scheme, a first request may produce the following response:

```
{
  immutable: {
    "single-post": {
      configuration: {
        class: "topcomponent"
      }
    }
  },
  mutableonmodel: {
    "single-post": {
      configuration: {
        descendants: ["layout-post"]
      }
    }
  },
  mutableonrequest: {
    "single-post": {
      components: {
        "layout-post": {
          configuration: {
            class: "post-37"
          }
        }
      }
    }
  }
}
```

As it can be observed, because the properties from the 3 sections do not overlap, then merging the 3 sections for the request produces the whole configuration once again:

```
{
  "single-post": {
    configuration: {
      class: "topcomponent",
      descendants: ["layout-post"]
    },
    components: {
      "layout-post": {
        configuration: {
          class: "post-37"
        }
      }
    }
  }
}
```

Next, the cache in the client is kept in 3 separate objects, one for each of the subsections, with sections "mutableonmodel" and "mutableonrequest" storing their data under appropriate keys: "mutableonmodel" under a key called "modelInstanceId", which represents a hash of the component hierarchy, and "mutableonrequest" under the requested URL. The request above will then be cached like this (assuming a "modelInstanceId" with value "bwKtq\*8H" and URL "/posts/some-post/"):

```
immutable =>
  {
    "single-post": {
      configuration: {
        class: "topcomponent"
      }
    }
  }

mutableonmodel =>
  {
    "bwKtq*8H": {
      "single-post": {
        configuration: {
          descendants: ["layout-post"]
        }
      }
    }
  }

mutableonrequest =>
  {
    "/posts/some-post/": {
      "single-post": {
        components: {
          "layout-post": {
            configuration: {
              class: "post-37"
            }
          }
        }
      }
    }
  }
```

If then we obtain the response for a second request, the cache is updated like this (assuming a "modelInstanceId" with value "6C7Lu$\\3" and URL "/posts/some-event/"):

```
immutable =>
  {
    "single-post": {
      configuration: {
        class: "topcomponent"
      }
    }
  }

mutableonmodel =>
  {
    "bwKtq*8H": {
      "single-post": {
        configuration: {
          descendants: ["layout-post"]
        }
      }
    },
    "6C7Lu$\3": {
      "single-post": {
        configuration: {
          descendants: ["layout-event"]
        }
      }
    }
  }

mutableonrequest =>
  {
    "/posts/some-post/": {
      "single-post": {
        components: {
          "layout-post": {
            configuration: {
              class: "post-37"
            }
          }
        }
      }
    },
    "/posts/some-event/": {
      "single-post": {
        components: {
          "layout-event": {
            configuration: {
              class: "post-45"
            }
          }
        }
      }
    }
  }
```

As it can be observed, "immutable" holds the common parts of the structure, while "mutableonmodel" and "mutableonrequest" hold the deltas. Hence, this scheme identifies common data and stores it only once, and all dissimilar entries are stored and accessible on their own. If most of the configuration doesn't change within the component hierarchy, then the information stored under "immutable" will make the bulk of the stored information, succeeding in minimizing the amount of data that is cached.

Finally, given the "modelInstanceId" and URL for any request we can obtain the 3 separate branches from the 3 sections, and merge them all together to recreate the whole configuration from the cache.

The merging can be done in the server-side too: If there is no need to cache the configuration on the client, then we can avoid the added complexity of dealing with the three subsections by adding parameter `dataoutputmode=combined` to the URL.

PHP versions
------------

[](#php-versions)

Requirements:

- PHP 8.1+ for development
- PHP 7.2+ for production

### Supported PHP features

[](#supported-php-features)

Check the list of [Supported PHP features in `GatoGraphQL/GatoGraphQL`](https://github.com/GatoGraphQL/GatoGraphQL/blob/master/docs/supported-php-features.md)

### Preview downgrade to PHP 7.2

[](#preview-downgrade-to-php-72)

Via [Rector](https://github.com/rectorphp/rector) (dry-run mode):

```
composer preview-code-downgrade
```

Standards
---------

[](#standards)

[PSR-1](https://www.php-fig.org/psr/psr-1), [PSR-4](https://www.php-fig.org/psr/psr-4) and [PSR-12](https://www.php-fig.org/psr/psr-12).

To check the coding standards via [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), run:

```
composer check-style
```

To automatically fix issues, run:

```
composer fix-style
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

To execute [PHPUnit](https://phpunit.de/), run:

```
composer test
```

Static Analysis
---------------

[](#static-analysis)

To execute [PHPStan](https://github.com/phpstan/phpstan), run:

```
composer analyse
```

Report issues
-------------

[](#report-issues)

To report a bug or request a new feature please do it on the [GatoGraphQL monorepo issue tracker](https://github.com/GatoGraphQL/GatoGraphQL/issues).

Contributing
------------

[](#contributing)

We welcome contributions for this package on the [GatoGraphQL monorepo](https://github.com/GatoGraphQL/GatoGraphQL) (where the source code for this package is hosted).

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Leonardo Losoviz](https://github.com/leoloso)
- [All Contributors](../../../../../../contributors)

License
-------

[](#license)

GNU General Public License v2 (or later). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~0 days

Total

38

Last Release

981d ago

Major Versions

0.10.2 → 1.0.02023-09-06

PHP version history (3 changes)0.7.6PHP ^7.4|^8.0

0.8.1PHP ^8.0

0.9.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1981996?v=4)[Leonardo Losoviz](/maintainers/leoloso)[@leoloso](https://github.com/leoloso)

![](https://www.gravatar.com/avatar/d5a0a064bae63a335ddd796bb69ab38e1d01420d14bfcc8e3d4e1550922ac60b?d=identicon)[getpop](/maintainers/getpop)

---

Top Contributors

[![leoloso](https://avatars.githubusercontent.com/u/1981996?v=4)](https://github.com/leoloso "leoloso (340 commits)")

---

Tags

componentcomponent-modelconfigurationmodelpopphpgraphqlGatoGatoGraphQLcomponent-model-configuration

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/getpop-component-model-configuration/health.svg)

```
[![Health](https://phpackages.com/badges/getpop-component-model-configuration/health.svg)](https://phpackages.com/packages/getpop-component-model-configuration)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
