Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 1fa6a43

Browse files
authored
Create ArrBuffer.php
1 parent b6eb003 commit 1fa6a43

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

‎src/ArrBuffer.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017年10月24日
6+
* Time: 9:17
7+
*/
8+
9+
namespace MyLib\ArrUtil;
10+
11+
/**
12+
* Class ArrBuffer
13+
* @package MyLib\ArrUtil
14+
*/
15+
final class AryBuffer
16+
{
17+
/**
18+
* @var string[]
19+
*/
20+
private $body = [];
21+
22+
/** @var string */
23+
private $delimiter = ''; // '/' ':'
24+
25+
/**
26+
* constructor.
27+
* @param string $content
28+
*/
29+
public function __construct(string $content = '')
30+
{
31+
if ($content) {
32+
$this->body[] = $content;
33+
}
34+
}
35+
36+
/**
37+
* @param string $content
38+
*/
39+
public function write(string $content)
40+
{
41+
$this->body[] = $content;
42+
}
43+
44+
/**
45+
* @param string $content
46+
*/
47+
public function append(string $content)
48+
{
49+
$this->write($content);
50+
}
51+
52+
/**
53+
* @param string $content
54+
*/
55+
public function prepend(string $content)
56+
{
57+
array_unshift($this->body, $content);
58+
}
59+
60+
/**
61+
* clear
62+
*/
63+
public function clear()
64+
{
65+
$this->body = [];
66+
}
67+
68+
/**
69+
* @return string[]
70+
*/
71+
public function getBody(): array
72+
{
73+
return $this->body;
74+
}
75+
76+
/**
77+
* @param string[] $body
78+
*/
79+
public function setBody(array $body)
80+
{
81+
$this->body = $body;
82+
}
83+
84+
/**
85+
* @return string
86+
*/
87+
public function toString(): string
88+
{
89+
return implode($this->delimiter, $this->body);
90+
}
91+
92+
/**
93+
* @return string
94+
*/
95+
public function __toString()
96+
{
97+
return $this->toString();
98+
}
99+
100+
/**
101+
* @return string
102+
*/
103+
public function getDelimiter(): string
104+
{
105+
return $this->delimiter;
106+
}
107+
108+
/**
109+
* @param string $delimiter
110+
*/
111+
public function setDelimiter(string $delimiter)
112+
{
113+
$this->delimiter = $delimiter;
114+
}
115+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /