Skip to content

Commit

Permalink
Added a alternative random service class to be able to demonstrate th…
Browse files Browse the repository at this point in the history
…e service swap within the same interface.
  • Loading branch information
michaelkeiluweit committed Jun 14, 2020
1 parent 22ff833 commit ba434f0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
27 changes: 21 additions & 6 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# random-integer-number
Example component for OXID eShop 6.2 Services
# random-number
Example component service for OXID eShop 6.2

### Install as package
`composer require michaelkeiluweit/random-number`
Expand All @@ -13,13 +13,28 @@ use MichaelKeiluweit\RandomNumber\RandomNumberInterface;

require_once 'bootstrap.php';

/** @var RandomIntegerNumberInterface $randomIntegerNumber */
/** @var RandomNumberInterface $randomNumber */
$randomNumber = ContainerFactory::getInstance()->getContainer()->get(RandomNumberInterface::class);

$number = $randomNumber->shuffle();
echo 'random_number: ' . $number;
echo PHP_EOL;
echo 'type: ' . gettype($number);
echo PHP_EOL;
echo 'random number: ' . $number . PHP_EOL;
echo 'number type: ' . gettype($number) . PHP_EOL;
echo 'object type: ' . get_class($randomNumber) . PHP_EOL . PHP_EOL;
```

### Switch from integer to float

To get a random float number, open the file `random-number/src/services.yaml` and replace the line
```yaml
class: MichaelKeiluweit\RandomNumber\RandomIntegerNumber
```
with
```yaml
class: MichaelKeiluweit\RandomNumber\RandomFloatNumber
```
After that, execute the command `composer update`.
Now the service will provide a random float number.


Empty file modified composer.json
100644 → 100755
Empty file.
Empty file modified services.yaml
100644 → 100755
Empty file.
13 changes: 13 additions & 0 deletions src/RandomFloatNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php


namespace MichaelKeiluweit\RandomNumber;


class RandomFloatNumber implements RandomNumberInterface
{
public function shuffle()
{
return mt_rand() / mt_getrandmax();
}
}
Empty file modified src/RandomIntegerNumber.php
100644 → 100755
Empty file.
Empty file modified src/RandomNumberInterface.php
100644 → 100755
Empty file.

0 comments on commit ba434f0

Please sign in to comment.