iso icon indicating copy to clipboard operation
iso copied to clipboard

Use objects

Open jasny opened this issue 11 years ago • 0 comments

Breaks backwards compatibility

Instead of using the static classes, you should be able to instantiate. Creating the object should be done with a factory method fromSomething(). The general from() should accept anything and work out what the input is (for example based on string length). Output is done with a toSomething() method.

The static classes should still exist and be used by the objects. However they should be moved to namespace Jasny\ISO\Data.

Some examples:

use Jasny\ISO\Country, Jasny\ISO\Color;

Country::fromName("United States")->toCode();
Country::fromCode("US")->toName();
Country::from("USA")->toCode();

$country = new Country("Germany"); // Same as Country::from("Germany");
$country = new Country("DE", "code"); // Same as Country::fromCode("DE");

Color::fromName("black")->toHex();
Color::fromRGB([0, 0, 0])->toHex();
Color::fromHSL([0, "0%", "0%"])->toRGB();
Color::from("#000")->toHSL();

$color = new Color("white"); // Same as Color::from("white");
$color = new Color([255, 255, 255], "rgb"); // Same as Color::fromRGB([255, 255, 255]);

jasny avatar Sep 04 '14 00:09 jasny