Skip to content

Commit

Permalink
get namespace properly
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom committed Oct 29, 2023
1 parent e78ffa3 commit 5918edb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Proxy/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ public function __construct(protected string|null $cacheDir = null)

public function define(string $interface): string
{
$name = $this->getName(new \ReflectionClass($interface));
$name = $this->getName($class = new \ReflectionClass($interface));
$namespace = $this->getInterfaceNamespace($class);
$cacheFile = null;
if ($this->cacheDir) {
$cacheFile = $this->cacheDir . DIRECTORY_SEPARATOR . $name . '.php';
if (file_exists($cacheFile)) {
require_once $cacheFile;
return '\Monitoring\Models\Actors\\' . $name;
return '\\' . $namespace . '\\' . $name;
}
}

Expand All @@ -50,7 +51,11 @@ public function define(string $interface): string
}
}

return '\Monitoring\Models\Actors\\' . $name;
return '\\' . $namespace . '\\' . $name;
}

protected function getInterfaceNamespace(\ReflectionClass $class): string {
return $class->getNamespaceName();
}

abstract protected function getName(\ReflectionClass $class): string;
Expand Down

0 comments on commit 5918edb

Please sign in to comment.