/**
  * @param \AGmakonts\DddBricks\Service\ServiceInterface $target
  * @param array                                         $params
  */
 public function __construct(ServiceInterface $target, array $params = [])
 {
     $this->target = $target;
     $this->occurrenceTime = DateTime::get();
     $this->identifier = Text::get(Uuid::uuid4()->toString());
     $this->params = $params;
 }
Ejemplo n.º 2
0
 /**
  * @return \AGmakonts\STL\Identity\AutoNumeric
  */
 public static function generate()
 {
     $server = hexdec(basename(__FILE__)) ^ hexdec(gethostname()) % 99;
     $pid = str_pad(substr(getmypid(), -2), 2, '0', STR_PAD_LEFT);
     $time = substr(str_pad(str_replace('.', '', microtime(TRUE)), 14, '0'), 2);
     return self::get(Text::get($time . str_pad($server . $pid . mt_rand(0, 9), 5, '0', STR_PAD_LEFT)));
 }
Ejemplo n.º 3
0
 /**
  * @param \AGmakonts\STL\Number\Integer $stringLength
  *
  * @return \AGmakonts\STL\String\Text
  */
 public static function generate(Integer $stringLength)
 {
     if ($stringLength->isZero() === TRUE || $stringLength->isNegative() === TRUE) {
         throw new InvalidStringLengthException("String length must be grater than zero");
     }
     $randString = bin2hex(openssl_random_pseudo_bytes(ceil($stringLength->value() / 2)));
     if ($stringLength->value() % 2 !== 0) {
         $randString = substr($randString, 0, -1);
     }
     return Text::get($randString);
 }
Ejemplo n.º 4
0
 /**
  * @param \AGmakonts\STL\String\Text $date
  * @param \AGmakonts\STL\String\Text $format
  *
  * @return DateTime
  */
 public static function getFromFormat(Text $date, Text $format)
 {
     $dateTime = \DateTime::createFromFormat($format->value(), $date->value());
     if (FALSE === $dateTime) {
         throw new \InvalidArgumentException("Wrong format or date provided");
     }
     $timestamp = Integer::get($dateTime->getTimestamp());
     return self::getInstanceForValue($timestamp);
 }
Ejemplo n.º 5
0
 /**
  * @param $string
  * @param $length
  * @param $fill
  * @param $mode
  * @param $expected
  *
  * @covers ::padded
  * @dataProvider paddedProvider
  */
 public function testPadded($string, $length, $fill, $mode, $expected)
 {
     $string = Text::get($string);
     $length = Integer::get($length);
     if (NULL !== $fill) {
         $fill = Text::get($fill);
     }
     $mode = \AGmakonts\STL\String\Padding::get($mode);
     self::assertEquals($expected, $string->padded($length, $mode, $fill)->value());
 }
Ejemplo n.º 6
0
 /**
  * @return \AGmakonts\STL\Number\Integer
  */
 public function digitCount()
 {
     return self::get(Text::get((string) $this->value())->length());
 }
Ejemplo n.º 7
0
 /**
  * @covers ::getFromFormat()
  */
 public function testGetFromFormat()
 {
     $testClass1 = \AGmakonts\STL\DateTime\DateTime::getFromFormat(\AGmakonts\STL\String\Text::get("2005-08-15T15:52:01+0000"), \AGmakonts\STL\String\Text::get('Y-m-d\\TH:i:sO'));
     $this->assertInstanceOf(\AGmakonts\STL\DateTime\DateTime::class, $testClass1);
     $this->assertSame(1124121121, $testClass1->getTimestamp()->value());
 }
 /**
  * @param \AGmakonts\DddBricks\Entity\EntityInterface $target
  */
 public function __construct(EntityInterface $target)
 {
     $this->target = $target;
     $this->occurrenceTime = DateTime::get();
     $this->identifier = Text::get(Uuid::uuid4()->toString());
 }
Ejemplo n.º 9
0
 /**
  * @return \AGmakonts\STL\Number\NumberInterface
  */
 public function digitCount()
 {
     $string = str_replace('.', '', (string) $this->value());
     return self::get(Text::get($string)->length());
 }