PeServer

Stream extends ResourceBase
in package

ストリーム。

Tags
phpstan-extends

ResourceBase

Table of Contents

Constants

MODE_EDIT  = 3
読み書きモード。
MODE_READ  = 1
読み込みモード。
MODE_WRITE  = 2
書き込みモード。
WHENCE_CURRENT  = SEEK_CUR
シーク位置: 現在位置。
WHENCE_SET  = SEEK_SET
シーク位置: 絶対値。
WHENCE_TAIL  = SEEK_END
シーク位置: 末尾(設定値は負数となる)。

Properties

$newLine  : string
改行文字。
$raw  : TResource
$resource  : mixed
$resourceType  : string
$encoding  : Encoding
文字列として扱うエンコーディング。(バイナリデータは気にしなくてよい)
$isDisposed  : bool
解放済みか。

Methods

__construct()  : mixed
生成。
__destruct()  : mixed
__get()  : mixed
create()  : self
新規ファイルのファイルストリームを生成。
dispose()  : void
解放処理。
empty()  : IDisposable
何もしない解放処理オブジェクトを生成。
flush()  : void
フラッシュ。
getMetaData()  : StreamMetaData
getOffset()  : int
現在位置を取得。
getState()  : IOState
isDisposed()  : bool
解放済みか。
isEnd()  : bool
EOFか。
new()  : self
`fopen` を使用してファイルストリームを生成。
open()  : self
既存ファイルからファイルストリームを生成。
openMemory()  : self
メモリストリームを開く。
openOrCreate()  : self
既存ファイルからファイルストリームを生成、既存ファイルが存在しない場合新規ファイルを作成してファイルストリームを生成。
openStandardError()  : self
標準エラーストリームを開く。
openStandardInput()  : self
標準エラーストリームを開く。
openStandardOutput()  : self
標準出力ストリームを開く。
openTemporary()  : self
一時メモリストリームを開く。
readBinary()  : Binary
バイナリ読み込み。
readBinaryContents()  : Binary
残りのストリームを全てバイナリとして読み込み。
readBom()  : bool
現在のエンコーディングを使用してBOMを読み取る。
readLine()  : string
現在のストリーム位置から1行分のデータを取得。
readStringContents()  : string
残りのストリームを全て文字列として読み込み。
seek()  : bool
現在位置をシーク。
seekHead()  : bool
先頭へシーク。
seekTail()  : bool
末尾へシーク。
writeBinary()  : int
バイナリ書き込み。
writeBom()  : int
現在のエンコーディングを使用してBOMを書き込み。
writeLine()  : int
文字列を改行付きで書き込み。
writeString()  : int
文字列書き込み。
disposeImpl()  : void
解放処理内部実装。
isValidType()  : bool
リソース型は自身の扱えるものか。
release()  : void
リソース型を解放する。
throwIfDisposed()  : void
解放済みの場合、例外を投げる。

Constants

MODE_EDIT

読み書きモード。

public mixed MODE_EDIT = 3

MODE_READ

読み込みモード。

public mixed MODE_READ = 1

MODE_WRITE

書き込みモード。

public mixed MODE_WRITE = 2

WHENCE_CURRENT

シーク位置: 現在位置。

public mixed WHENCE_CURRENT = SEEK_CUR

WHENCE_SET

シーク位置: 絶対値。

public mixed WHENCE_SET = SEEK_SET

WHENCE_TAIL

シーク位置: 末尾(設定値は負数となる)。

public mixed WHENCE_TAIL = SEEK_END

Properties

$newLine

改行文字。

public string $newLine = PHP_EOL

書き込み時に使用される(読み込み時は頑張る)

$encoding

文字列として扱うエンコーディング。(バイナリデータは気にしなくてよい)

private Encoding $encoding

$isDisposed

解放済みか。

private bool $isDisposed = false

Methods

__construct()

生成。

public __construct(mixed $resource[, Encoding|null $encoding = null ]) : mixed

内部的にしか使わない。

Parameters
$resource : mixed

ファイルリソース。

$encoding : Encoding|null = null

__get()

public __get(string $name) : mixed
Parameters
$name : string

create()

新規ファイルのファイルストリームを生成。

public static create(string $path[, Encoding|null $encoding = null ]) : self
Parameters
$path : string

ファイルパス。

$encoding : Encoding|null = null
Tags
throws
IOException

既にファイルが存在する。

Return values
self

isDisposed()

解放済みか。

public isDisposed() : bool
Return values
bool

new()

`fopen` を使用してファイルストリームを生成。

public static new(string $path, string $mode[, Encoding|null $encoding = null ]) : self

原則以下の処理を使ってればよい。

  • self::create
  • self::open
  • self::openOrCreate
  • self::openStandardInput
  • self::openStandardOutput
  • self::openStandardError
  • self::openMemory
  • self::openTemporary
Parameters
$path : string

ファイルパス。

$mode : string

fopen:mode を参照。

$encoding : Encoding|null = null
Tags
throws
IOException
see
https://www.php.net/manual/function.fopen.php
Return values
self

open()

既存ファイルからファイルストリームを生成。

public static open(string $path, self::MODE_* $mode[, Encoding|null $encoding = null ]) : self
Parameters
$path : string

ファイルパス。

$mode : self::MODE_*

self::MODE_* を指定。 self::MODE_CRETE: ファイルが存在しない場合失敗する。

$encoding : Encoding|null = null
Tags
throws
IOException
Return values
self

openMemory()

メモリストリームを開く。

public static openMemory([Encoding|null $encoding = null ]) : self
Parameters
$encoding : Encoding|null = null
Return values
self

openOrCreate()

既存ファイルからファイルストリームを生成、既存ファイルが存在しない場合新規ファイルを作成してファイルストリームを生成。

public static openOrCreate(string $path, int $mode[, Encoding|null $encoding = null ]) : self
Parameters
$path : string

ファイルパス。

$mode : int

self::MODE_* を指定。 self::MODE_CRETE: ファイルが存在しない場合に空ファイルが作成される(読むしかできないけど開ける。意味があるかは知らん)。

$encoding : Encoding|null = null
Tags
phpstan-param

self::MODE_* $mode

throws
IOException
Return values
self

openStandardError()

標準エラーストリームを開く。

public static openStandardError([Encoding|null $encoding = null ]) : self
Parameters
$encoding : Encoding|null = null
Return values
self

openStandardInput()

標準エラーストリームを開く。

public static openStandardInput([Encoding|null $encoding = null ]) : self
Parameters
$encoding : Encoding|null = null
Return values
self

openStandardOutput()

標準出力ストリームを開く。

public static openStandardOutput([Encoding|null $encoding = null ]) : self
Parameters
$encoding : Encoding|null = null
Return values
self

openTemporary()

一時メモリストリームを開く。

public static openTemporary([int|null $memoryByteSize = null ][, Encoding|null $encoding = null ]) : self
Parameters
$memoryByteSize : int|null = null

指定した値を超過した際に一時ファイルに置き換わる。nullの場合は 2MB(php://temp 参照のこと)。

$encoding : Encoding|null = null
Return values
self

readBinaryContents()

残りのストリームを全てバイナリとして読み込み。

public readBinaryContents([int|null $byteSize = null ][, int $offset = -1 ]) : Binary
Parameters
$byteSize : int|null = null

読み込む最大バイト数。nullで全て。

$offset : int = -1

読み込みを開始する前に移動する位置。

Tags
phpstan-param

non-negative-int|null $byteSize

throws
StreamException
see
https://www.php.net/manual/function.stream-get-contents.php
Return values
Binary

readBom()

現在のエンコーディングを使用してBOMを読み取る。

public readBom() : bool
  • 現在位置から読み込む点に注意(シーク位置が先頭以外であれば無視される)。
  • 読み込まれた場合(エンコーディングがBOMを持っていて合致した場合)はその分読み進められる。
Return values
bool

BOMが読み込まれたか。

readLine()

現在のストリーム位置から1行分のデータを取得。

public readLine([int $bufferByteSize = 1024 ]) : string
  • 位置を進めたり戻したりするので操作可能なストリームで処理すること。
  • エンコーディングにより復元不可の可能性あり。
Parameters
$bufferByteSize : int = 1024

1回読み進めるにあたり予め取得するサイズ。このサイズが改行(CR,LF)のサイズより小さい場合は改行(CR,LF)のサイズが設定される(1指定のutf16とか)

Tags
phpstan-param

positive-int $bufferByteSize

Return values
string

readStringContents()

残りのストリームを全て文字列として読み込み。

public readStringContents() : string

エンコーディングにより復元不可の可能性あり。

Tags
throws
StreamException
Return values
string

seekTail()

末尾へシーク。

public seekTail() : bool
Return values
bool

writeBinary()

バイナリ書き込み。

public writeBinary(Binary $data[, int|null $byteSize = null ]) : int
Parameters
$data : Binary

データ。

$byteSize : int|null = null

書き込みサイズ。

Tags
phpstan-param

non-negative-int|null $byteSize

phpstan-return

non-negative-int

throws
StreamException
see
https://www.php.net/manual/function.fwrite.php
Return values
int

書き込んだバイトサイズ。

writeBom()

現在のエンコーディングを使用してBOMを書き込み。

public writeBom() : int
  • 現在位置に書き込む点に注意(シーク位置が先頭以外であれば無視される)。
  • エンコーディングがBOM情報を持っていれば出力されるためBOM不要な場合は使用しないこと。
Tags
phpstan-return

non-negative-int

Return values
int

書き込まれたバイトサイズ。

writeLine()

文字列を改行付きで書き込み。

public writeLine(string $data) : int
Parameters
$data : string
Tags
phpstan-return

non-negative-int

Return values
int

書き込まれたバイト数。

writeString()

文字列書き込み。

public writeString(string $data[, int|null $count = null ]) : int
Parameters
$data : string

データ。

$count : int|null = null

文字数。

Tags
phpstan-param

non-negative-int|null $count

phpstan-return

non-negative-int

Return values
int

書き込まれたバイト数。

disposeImpl()

解放処理内部実装。

protected disposeImpl() : void

継承先で継承元を呼び出すこと。

isValidType()

リソース型は自身の扱えるものか。

protected isValidType(string $resourceType) : bool
Parameters
$resourceType : string
Return values
bool

release()

リソース型を解放する。

protected release() : void

        
On this page

Search results