Skip to content

Commit a48d9bb

Browse files
committed
Multiple issues fixed in this commit
- Refactor 'Collections' Namespace to 'Support' (#10) - Move all service-related tasks to CommonPHP/ServiceManager library (#9, #8, #4) - Implement and pass tests (#6) - Create CONTRIBUTING.md (#5) - Close #3 and #1 as they are now applicable to ServiceManager library - Modified version to 0.1 to create Packagist package for composer
1 parent 07da0a4 commit a48d9bb

22 files changed

Lines changed: 831 additions & 31 deletions

CODE_OF_CONDUCT.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at timothy@commonphp.org. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.4, available at http://contributor-covenant.org/version/1/4.

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contributing to CommonPHP\DependencyInjection
2+
3+
First of all, thank you for your interest in contributing to CommonPHP\DependencyInjection! This project welcomes any kind of contribution, whether it's reporting bugs, suggesting improvements, or opening pull requests.
4+
5+
Here are some guidelines on how to contribute.
6+
7+
## Reporting Bugs
8+
9+
1. Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/commonphp/di/issues).
10+
11+
2. If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/commonphp/di/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
12+
13+
## Suggesting Enhancements
14+
15+
1. First, read the [documentation](https://github.com/commonphp/di/wiki) carefully to make sure the behavior you are suggesting doesn't already exist.
16+
17+
2. Check the [issues list](https://github.com/commonphp/di/issues) on GitHub to see if there has been any discussion on the matter.
18+
19+
3. If it hasn't been suggested before, you can [create a new issue](https://github.com/commonphp/di/issues/new). Provide as much context as you can about why the feature would be useful.
20+
21+
## Pull Requests
22+
23+
1. Fork the project on GitHub.
24+
25+
2. Clone the forked project to your machine.
26+
27+
3. Create a new branch from `master` for your changes.
28+
29+
4. Make your changes in your new branch. If you're adding a feature or fixing a bug, please add tests!
30+
31+
5. Push your changes to your fork.
32+
33+
6. Submit a pull request to the `master` branch of the CommonPHP\DependencyInjection repository.
34+
35+
7. Be sure to include a description of your changes.
36+
37+
8. The maintainers of the project will review your pull request as soon as possible.
38+
39+
## Code of Conduct
40+
41+
We enforce a Code of Conduct for all maintainers and contributors of this project. Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md).
42+
43+
Again, thank you for your contribution, and we look forward to your suggestions, bug reports, and pull requests!

examples/call.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
use CommonPHP\DependencyInjection\DependencyInjector;
6+
7+
function exampleFunction(string $message)
8+
{
9+
echo "The message is: " . $message;
10+
}
11+
12+
$injector = new DependencyInjector();
13+
14+
try {
15+
// Call the function 'exampleFunction' with 'Hello, world!' as the parameter
16+
$injector->call('exampleFunction', ['message' => 'Hello, world!']);
17+
} catch (Exception $e) {
18+
// Handle exceptions
19+
echo "An error occurred: " . $e->getMessage();
20+
}

examples/instantiate.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
use CommonPHP\DependencyInjection\DependencyInjector;
6+
7+
class ExampleClass
8+
{
9+
public function __construct(private string $property)
10+
{
11+
}
12+
13+
public function getProperty(): string
14+
{
15+
return $this->property;
16+
}
17+
}
18+
19+
$injector = new DependencyInjector();
20+
21+
try {
22+
// Instantiate ExampleClass with a provided constructor parameter
23+
$instance = $injector->instantiate(ExampleClass::class, ['property' => 'exampleValue']);
24+
25+
// Use the instantiated object
26+
echo $instance->getProperty(); // Outputs: exampleValue
27+
} catch (Exception $e) {
28+
// Handle exceptions
29+
echo "An error occurred: " . $e->getMessage();
30+
}

examples/invoke.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
use CommonPHP\DependencyInjection\DependencyInjector;
6+
7+
class ExampleClass
8+
{
9+
private string $property;
10+
11+
public function __construct()
12+
{
13+
$this->property = 'Initial value';
14+
}
15+
16+
public function setProperty(string $newValue): void
17+
{
18+
$this->property = $newValue;
19+
}
20+
21+
public function getProperty(): string
22+
{
23+
return $this->property;
24+
}
25+
}
26+
27+
$injector = new DependencyInjector();
28+
29+
try {
30+
// Instantiate ExampleClass without any constructor parameters
31+
$instance = $injector->instantiate(ExampleClass::class, []);
32+
33+
// Invoke setProperty method on the instantiated object
34+
$injector->invoke($instance, 'setProperty', ['newValue' => 'Updated value']);
35+
36+
// Use the updated object
37+
echo $instance->getProperty(); // Outputs: Updated value
38+
} catch (Exception $e) {
39+
// Handle exceptions
40+
echo "An error occurred: " . $e->getMessage();
41+
}

examples/lookup-hooks.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
use CommonPHP\DependencyInjection\DependencyInjector;
6+
use CommonPHP\DependencyInjection\Support\ValueFinder;
7+
8+
class ExampleClass
9+
{
10+
public function __construct(public string $message)
11+
{
12+
}
13+
}
14+
15+
$injector = new DependencyInjector();
16+
17+
// Add a custom lookup hook to the ValueFinder
18+
$injector->valueFinder->onLookup(function (string $name, string $typeName, bool &$found): mixed {
19+
if ($name === 'message' && $typeName === 'string') {
20+
$found = true;
21+
return 'Hello from custom lookup hook!';
22+
}
23+
24+
return null;
25+
});
26+
27+
try {
28+
// Create a new instance of ExampleClass using the custom lookup hook
29+
$instance = $injector->instantiate(ExampleClass::class, []);
30+
} catch (Exception $e) {
31+
// Handle exceptions
32+
echo "An error occurred: " . $e->getMessage();
33+
}
34+
35+
echo $instance->message; // Outputs: "Hello from custom lookup hook!"

examples/populate.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
use CommonPHP\DependencyInjection\DependencyInjector;
6+
7+
class ExampleClass
8+
{
9+
public string $message;
10+
}
11+
12+
$injector = new DependencyInjector();
13+
14+
// Create a new instance of ExampleClass
15+
$instance = new ExampleClass();
16+
17+
try {
18+
// Populate the properties of the instance
19+
$injector->populate($instance, ['message' => 'Hello, world!']);
20+
} catch (Exception $e) {
21+
// Handle exceptions
22+
echo "An error occurred: " . $e->getMessage();
23+
}
24+
25+
echo $instance->message; // Outputs: "Hello, world!"

examples/usage.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)