1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-04 02:14:06 +02:00

Add php-cs-fixer

This commit is contained in:
Robin Appelman 2017-07-30 14:51:54 +02:00
commit 309ae17036
54 changed files with 4900 additions and 4106 deletions

View file

@ -3,44 +3,46 @@
namespace Demostf\API\Demo;
class HeaderParser {
/**
* @param string $head string containing the demo header binary data
* @return Header
* @throws \InvalidArgumentException
*/
public function parseString(string $head): Header {
$info = @unpack('A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
$head);
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
throw new \InvalidArgumentException('Not an HL2 demo');
}
return Header::fromArray($info);
}
/**
* @param string $head string containing the demo header binary data
* @return Header
* @throws \InvalidArgumentException
*/
public function parseString(string $head): Header {
$info = @unpack(
'A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
$head
);
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
throw new \InvalidArgumentException('Not an HL2 demo');
}
return Header::fromArray($info);
}
/**
* Parse demo info from a stream
*
* @param resource $stream
* @return Header
* @throws \InvalidArgumentException
*/
public function parseStream($stream): Header {
$head = fread($stream, 2048);
return $this->parseString($head);
}
/**
* Parse demo info from a stream
*
* @param resource $stream
* @return Header
* @throws \InvalidArgumentException
*/
public function parseStream($stream): Header {
$head = fread($stream, 2048);
return $this->parseString($head);
}
/**
* Parse demo info from a local file
*
* @param string $path
* @return Header
* @throws \InvalidArgumentException
*/
public function parseHeader(string $path): Header {
if (!is_readable($path)) {
throw new \InvalidArgumentException('Unable to open demo: ' . $path);
}
$fh = fopen($path, 'rb');
return $this->parseStream($fh);
}
/**
* Parse demo info from a local file
*
* @param string $path
* @return Header
* @throws \InvalidArgumentException
*/
public function parseHeader(string $path): Header {
if (!is_readable($path)) {
throw new \InvalidArgumentException('Unable to open demo: ' . $path);
}
$fh = fopen($path, 'rb');
return $this->parseStream($fh);
}
}