2017 © Pedro Peláez
 

library nexus

It manages object's dependencies for internal builders collaborators.

image

ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  • Wednesday, September 14, 2016
  • by ix
  • Repository
  • 1 Watchers
  • 0 Stars
  • 44 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Mapping dependencies at construction time

This registers collaborators (dependencies) in the constructors in order to decouple the object creation in methods., (*2)

Keywords

inversion control, dependency injection, builder, (*3)

Goal

Testable, reusable and maintainable code by avoiding hard-coded references in methods., (*4)

Benefits

  • Creating collaborators (a.k.a. dependencies) only in constructors.
  • Avoiding a global dependency injection container.
  • Switching default implementations with alternatives and test's objects.

Advantages of the language

  • Referencing of classes and interfaces with its namespace.

Alternatives

  • Usage of mapping.
  • Anonymous classes.
  • Passing empty objects that create those which are fully identifiable.
  • Defining and implementing an interface for each collaboration.

Here is an example that reconstitutes an entity from a data store.

You just need to pass the interface and its implementation.
    // It reconstitutes a person from a data store: PersonID is a kind 
    // of Identity as much as an AboutMe is a kind of About and both
    // of them are collaborators. Take note that the creation is
    // delayed until need it, but it is not a Singleton.

    // Testing purposes.
    $person = new PersonFromStore(
        new FetchedPerson($id), TestPersonID::class, AboutMe::class
    );   

    // Application.
    $person = new PersonFromStore(
        new FetchedPerson($id), PersonID::class, AboutMe::class
    );  

    // Description
    final class PersonFromStore implements Party
    {
        private $record;
        private $identity;
        private $about;

        public function __construct(IdentityRecord $record, string $identity, string $about)
        {
            $this->record = $record;        

            $this->identity = new Assignment(Identity::class, $identity);

            $this->about = new Assignment(About::class, $about);
        }

        // Please, your ID?
        public function identity() : Identity
        {
            // It calls the main constructor or the operator "new" in the ID class.
            // Same as: new PersonID(...)
            return $this->identity->new($this->record->key());
        }

        // Tell me something about you.
        public function about() : About
        {
            // It calls a convenience constructor in the AboutMe class.
            // Same as: AboutMe::withID(...)
            return $this->about->withID($this->identity());
        }
    }  

A proposal for the php community.

    // Definition
    final class PersonFromStore implements Party 
    {
        // It can use another word, such as join, to avoid conflicts with traits.
        use (Identity, About);

        public function identity() : Identity
        {
            return new Identity($record->key());
        }

        ...               
    }

    // Client
    $person = new PersonFromStore($fetchedPerson) use (PersonID, AboutMe);
    // Test
    $person = new PersonFromStore($fetchedPerson) use (TestPersonID, AboutMe);

Now, we can create objects from their interfaces and thus, we have no more hard-coded dependencies in the methods., (*5)

The Versions

14/09 2016

dev-master

9999999-dev https://github.com/ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method

13/08 2016

1.0.0

1.0.0.0 https://github.com/ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method

30/04 2016

1.0.0-beta.1

1.0.0.0-beta1 https://github.com/ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method

11/04 2016

1.0.0-alpha.1

1.0.0.0-alpha1 https://github.com/ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method

10/04 2016

1.0.0-alpha

1.0.0.0-alpha https://github.com/ixmanuel/nexus

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method

10/04 2016

0.3.0

0.3.0.0 https://github.com/ixmanuel/creation-pods

It manages object's dependencies for internal builders collaborators.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by ixmanuel

dependency injection dependencies ix inversion control factory method