Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using UnitMap to add a unit HeadCount can't find unit #13

Open
slavensaka opened this issue Feb 13, 2020 · 1 comment
Open

Using UnitMap to add a unit HeadCount can't find unit #13

slavensaka opened this issue Feb 13, 2020 · 1 comment
Labels

Comments

@slavensaka
Copy link

slavensaka commented Feb 13, 2020

Hi im having a hard time figuring out why i get a not found.
I'm trying to add a Headcount.php unit within Amount unit type.
But i get this
Class 'PhpUnitConversion\Unit\Amount\HeadCount' not found

I'm using the UnitMap::add

UnitMap::add(
dirname(__DIR__, 2) .'/helpers/unitconversion/Fixtures/Amount/HeadCount.php',
 "PhpUnitConversion\\Unit",
\PhpUnitConversion\Unit\Amount::class
);

First parameter is the server path that's the correct path to my HeadCount.php
Second im not sure what to use
Third the class of the unit type I want to add it to

This is my HeadCount.php unit

 namespace PhpUnitConversion\Unit\Amount;
 use PhpUnitConversion\Unit\Amount;
 class HeadCount extends Amount
 {
   const FACTOR = 1;
  const SYMBOL = 'hc';
  const LABEL = 'head count';
}

Initlization:

$hd = new  \PhpUnitConversion\Unit\Amount\HeadCount(343);

I need to initilize it like above reason i have dynamic way of calling it

$convertFromClass = "\PhpUnitConversion\Unit\\". $type . "\\" .  $from;
$convertFrom = new $convertFromClass($formattedNumber);

Looking in Map.php source code the static load() adds it to self:$paths like this

"[["/var/www/vhost/biome/vendor/php-unit-conversion/php-unit-conversion/src/Unit/"
"PhpUnitConversion\Unit"
true
null]

["/var/www/vhost/biome/app/helpers/unitconversion/Fixtures/Amount/HeadCount.php"
"PhpUnitConversion\Unit"
true
"PhpUnitConversion\Unit\Amount"]]"

@pimlie
Copy link
Owner

pimlie commented Feb 23, 2020

I dont think its possible to re-use the same namespace? It shouldnt be necessary at least.

Namespaces are linked to a folder on disk, the PhpUnitConversion\Unit\Amount namespace should be pointing to a folder in vendor but your HeadCount file isnt located in vendor right? Did you try using a custom namespace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants