-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLine.php
39 lines (32 loc) · 912 Bytes
/
Line.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* Created by PhpStorm.
* User: jderay
* Date: 9/3/14
* Time: 9:09 PM
*/
namespace Giftcards\FixedWidth;
class Line extends AbstractLine
{
protected $data;
public function __construct($dataOrLength)
{
$this->data = is_int($dataOrLength) ? str_repeat(' ', $dataOrLength) : $dataOrLength;
}
public function getLength()
{
return strlen($this->data);
}
protected function loadSlice(Slice $slice)
{
$this->checkSlice($slice);
return substr($this->data, $slice->getStart(), $slice->getWidth());
}
protected function setSlice(Slice $slice, $value)
{
$this->checkSlice($slice);
$value = str_pad(substr($value, 0, $slice->getWidth()), $slice->getWidth(), ' ', STR_PAD_RIGHT);
$this->data = substr_replace($this->data, $value, $slice->getStart(), $slice->getWidth());
return $this;
}
}