Skip to content

Simplified Data Transport Between Components

William Tempest Wright Ferrer edited this page Aug 17, 2018 · 2 revisions

Very often in complex projects, I find that an awful lot of time is spent changing the signatures, and return values from methods in your application. These signature changes and return values often have to be modified in deep chains of logic, and one simple mess up can break your whole application.

This problem arises because the data a method of a class needs to function today, may not be the same data it needs in a future version of your application.

Having too many arguments in methods is messy, and deeper refractors to address problems like these as your application evolves, can be time-consuming and inconsistently applied.

To get around these hassles, and keep your code clean and readable, Tempest Tools uses an array helper object which is injected in your Tempest Tools components. This object is a helper class with many features built into it to help you manage and access the data it holds. The data itself is stored as an ArrayObject inside the helper class.

You can think of this as a place where information about the state of your application is stored, and easily accessed/shared by multiple components.

The custom ArrayObject class used has custom functionality added to protect values stored within it that should remain static and ensure that the primary keys are populated.

The object is first populated via Middleware with the pertinent info your application needs to know about the current request (such as what user is the current sessions associated with, and info about that user). This Middleware allows Closures to be added to do custom retrieval more data as needed by your application.

As the code continues to run different pieces of Scribe will add additional data to the helper that can be used for reference inside your code. For instance, any entities that Scribe automatically retrieves for you it will store on the array object in this helper so you can reference those entities when making decisions within your application (this is also used automatically as a feature that optimizes the speed of your application).

Tempest Tools allows you to build functionality into your classes which lets them extract relevant data about them and add them to their own array keys within this helper.

This helper object is handled via dependency injection, stores information specifically related functionality to the users your current request, and does not use global namespaces, allowing for a convenient communication layer between related classes in your application without falling into many of the pitfalls that global namespaces present.

Additionally, this allows code that relates to your ORM to be agnostic of the framework it runs in.