Skip to content

Commit

Permalink
Merge pull request #106 from tufanbarisyildirim/php-8
Browse files Browse the repository at this point in the history
Migrating to PHP 8.0+
  • Loading branch information
tufanbarisyildirim authored Nov 19, 2022
2 parents 0dcb20a + 5e82447 commit b7d008c
Show file tree
Hide file tree
Showing 8 changed files with 660 additions and 645 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobs:
strategy:
matrix:
php-version:
- '7.3'
- '7.4'
- '8.0'
- '8.1'

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PHP = php
COMPOSER = composer
M = $(shell printf "\033[34;1m>>\033[0m")

.PHONY: test
test:
$(info $(M) runing tests...)
$(COMPOSER) tests
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ files contained in the APK file to a given directory.

### Requirements

PHP 7.3+
PHP 8.0+
PHP 7.3+ is in [2.x.x](https://github.com/tufanbarisyildirim/php-apk-parser/tree/v2.x.x) branch

### Installation

Expand All @@ -34,10 +35,9 @@ your changes. That's all!
Thanks JetBrains for the free open source license

<a href="https://www.jetbrains.com/?from=tufanbarisyildirim" target="_blank">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width = "260" align=center />
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width = "260" align=center alt="Jetbrains"/>
</a>


### License

Apk Parser is [MIT licensed](./LICENSE.md).
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
}
],
"require": {
"php": ">=7.3",
"php": ">=8.0",
"ext-simplexml": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*"
"ext-mbstring": "*",
"ext-zip": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.5"
Expand Down
42 changes: 25 additions & 17 deletions lib/ApkParser/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Archive extends \ZipArchive


/**
* @param bool $file
* @param bool|string $file
* @throws \Exception
*/
public function __construct($file = false)
public function __construct(string|bool $file = false)
{
if ($file && is_file($file)) {
$this->open($file);
Expand All @@ -41,11 +41,12 @@ public function __construct($file = false)
* Get a file from apk Archive by name.
*
* @param string $name
* @param int $length
* @param int $flags
* @return mixed
* @param int|null $length
* @param int|null $flags
* @return string|false
* @throws \Exception
*/
public function getFromName($name, $length = null, $flags = null)
public function getFromName(string $name, int $length = null, int $flags = null): string|false
{
if (strtolower(substr($name, -4)) == '.xml') {
$xmlParser = new XmlParser(new Stream($this->getStream($name)));
Expand All @@ -59,33 +60,34 @@ public function getFromName($name, $length = null, $flags = null)
* Returns an ApkStream which contains AndroidManifest.xml
* @return Stream
*/
public function getManifestStream()
public function getManifestStream(): Stream
{
return new Stream($this->getStream('AndroidManifest.xml'));
}

/**
* @return SeekableStream
*/
public function getResourcesStream()
public function getResourcesStream(): SeekableStream
{
return new SeekableStream($this->getStream('resources.arsc'));
}

/**
* Returns an \ApkParser\Stream instance which contains classes.dex file
* @returns \ApkParser\Stream
* @returns Stream
* @throws \Exception
*/
public function getClassesDexStream()
public function getClassesDexStream(): Stream
{
return new Stream($this->getStream('classes.dex'));
}

/**
* Apk file path.
* @return string
* @return bool|string
*/
public function getApkPath()
public function getApkPath(): bool|string
{
return $this->filePath;
}
Expand All @@ -94,19 +96,25 @@ public function getApkPath()
* Apk file name
* @return string
*/
public function getApkName()
public function getApkName(): string
{
return $this->fileName;
}


public function extractTo($destination, $entries = null)
/**
* @param string $pathto
* @param array|string|null $files
* @return bool
* @throws \Exception
*/
public function extractTo(string $pathto, array|string|null $files = null): bool
{
if ($extResult = parent::extractTo($destination, $entries)) {
$xmlFiles = Utils::globRecursive($destination . '/*.xml');
if ($extResult = parent::extractTo($pathto, $files)) {
$xmlFiles = Utils::globRecursive($pathto . '/*.xml');

foreach ($xmlFiles as $xmlFile) {
if ($xmlFile == ($destination . "/AndroidManifest.xml")) {
if ($xmlFile == ($pathto . "/AndroidManifest.xml")) {
XmlParser::decompressFile($xmlFile);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ApkParser/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct(array $config = [])
{
$this->config = array_merge(
[
'tmp_path' => sys_get_temp_dir(),
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
'tmp_path' => sys_get_temp_dir(),
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
'manifest_only' => true
],
$config
Expand Down
Loading

0 comments on commit b7d008c

Please sign in to comment.