Skip to content

Commit

Permalink
fix: reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
byawitz committed Sep 6, 2024
1 parent 17d87f2 commit 5669f39
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,15 @@ use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

class User {
public string $name;

public function __construct(string $name)
{
$this->name = $name;
}
}
// Creating the dependency injection container
$container = new Container();

// Adding a user dependency to the container
$user = new Dependency();
$user
->setName('user')
->setCallback(fn () => new User('John Doe'));
->inject('request') // We can insert and use other injections as well
->setCallback(fn (Request $request) => $request->getHeader('x-user-id', 'John Doe'));

$container->add($user);

Expand All @@ -56,12 +49,12 @@ Http::get('/hello-world')
->inject('response') // Auto-injected each request
->inject('user')
->action(
function(Request $request, Response $response, User $user) {
function(Request $request, Response $response, string $user) {
$response
->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
->addHeader('Expires', '0')
->addHeader('Pragma', 'no-cache')
->json(['Hello' => 'World', 'User is' => $user->name]);
->json(['message' => 'Hello World', 'user' => $user]);
}
);

Expand Down

0 comments on commit 5669f39

Please sign in to comment.