Skip to content

jstewmc/gravity

Repository files navigation

Gravity

Gravity lets other developers define settings and services in your dependency injection container using files in their packages. By pulling everything together, Gravity makes it easy to build and share small, configurable services.

Build Status codecov

Usage

As a package author, you'll define services and settings in your repository using the set() method:

# /path/to/package/.gravity/foo.php

$g->set('foo.bar.baz', true);            // defines a setting
$g->set('Foo\Bar\Baz', new StdClass());  // defines a service

As a package consumer, you'll request services and settings in your project using the get() method:

# /path/to/project/file.php

$g = (new \Jstewmc\Gravity\Gravity())->pull();  // returns Gravity's manager

$g->get('foo.bar.baz');  // returns true
$g->get('Foo\Bar\Baz');  // returns the StdClass instance

Gravity works entirely within your local filesystem. When you call the pull() method, Gravity will find the current project's root directory; search it, as well as your vendor directory, for Gravity files; load each file's service and setting definitions into the manager; and, return the manager to you. That's it!

Documentation

Gravity's documentation is available online or in the docs directory.

We strive to maintain great documentation. If you see a mistake or have a suggestion, feel free to fork and fix it!

Installation

Gravity requires PHP 7.2+.

Gravity is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX.

Gravity must be installed via Composer. To do so, add the following line to the require section of your composer.json file (where x is the latest major version), and run composer update:

{
   "require": {
       "jstewmc/gravity": "^x"
   }
}

Examples

You can run most examples in the documentation by cloning the repository to your computer, navigating to it on your filesystem, and using the PHP command line.

# navigate to a directory on your computer
$ cd ~/projects

# clone the repository to your computer
~/projects $ git clone https://github.com/jstewmc/gravity.git

# navigate to the repository
~/projects $ cd gravity

# run the first example
~/projects/gravity $ php examples/first.php

Most examples use assert() statements, and will output nothing when successful, unless stated otherwise.

Compliance

This library strives to adhere to the following standards:

  1. Keep a Changelog 1.0
  2. PSR-2
  3. PSR-11
  4. PSR-16
  5. Semantic Versioning 2.0
  6. SODO Design Pattern 0.1.0

If you spot an error, please let us know!

License

This library is licensed under the MIT license.

Credits

This library was originally developed by Jack Clayton with input from good friends like Andy O'brien and Harry Wallin.

We hope you enjoy it!

About

Like Composer for services and settings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages