Skip to content

Commit b7d008c

Browse files
Merge pull request #106 from tufanbarisyildirim/php-8
Migrating to PHP 8.0+
2 parents 0dcb20a + 5e82447 commit b7d008c

File tree

8 files changed

+660
-645
lines changed

8 files changed

+660
-645
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ jobs:
77
strategy:
88
matrix:
99
php-version:
10-
- '7.3'
11-
- '7.4'
1210
- '8.0'
1311
- '8.1'
1412

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PHP = php
2+
COMPOSER = composer
3+
M = $(shell printf "\033[34;1m>>\033[0m")
4+
5+
.PHONY: test
6+
test:
7+
$(info $(M) runing tests...)
8+
$(COMPOSER) tests

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ files contained in the APK file to a given directory.
77

88
### Requirements
99

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

1213
### Installation
1314

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

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

40-
4141
### License
4242

4343
Apk Parser is [MIT licensed](./LICENSE.md).

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.3",
21+
"php": ">=8.0",
2222
"ext-simplexml": "*",
2323
"ext-json": "*",
2424
"ext-libxml": "*",
25-
"ext-mbstring": "*"
25+
"ext-mbstring": "*",
26+
"ext-zip": "*"
2627
},
2728
"require-dev": {
2829
"phpunit/phpunit": "^8.5"

lib/ApkParser/Archive.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class Archive extends \ZipArchive
2424

2525

2626
/**
27-
* @param bool $file
27+
* @param bool|string $file
2828
* @throws \Exception
2929
*/
30-
public function __construct($file = false)
30+
public function __construct(string|bool $file = false)
3131
{
3232
if ($file && is_file($file)) {
3333
$this->open($file);
@@ -41,11 +41,12 @@ public function __construct($file = false)
4141
* Get a file from apk Archive by name.
4242
*
4343
* @param string $name
44-
* @param int $length
45-
* @param int $flags
46-
* @return mixed
44+
* @param int|null $length
45+
* @param int|null $flags
46+
* @return string|false
47+
* @throws \Exception
4748
*/
48-
public function getFromName($name, $length = null, $flags = null)
49+
public function getFromName(string $name, int $length = null, int $flags = null): string|false
4950
{
5051
if (strtolower(substr($name, -4)) == '.xml') {
5152
$xmlParser = new XmlParser(new Stream($this->getStream($name)));
@@ -59,33 +60,34 @@ public function getFromName($name, $length = null, $flags = null)
5960
* Returns an ApkStream which contains AndroidManifest.xml
6061
* @return Stream
6162
*/
62-
public function getManifestStream()
63+
public function getManifestStream(): Stream
6364
{
6465
return new Stream($this->getStream('AndroidManifest.xml'));
6566
}
6667

6768
/**
6869
* @return SeekableStream
6970
*/
70-
public function getResourcesStream()
71+
public function getResourcesStream(): SeekableStream
7172
{
7273
return new SeekableStream($this->getStream('resources.arsc'));
7374
}
7475

7576
/**
7677
* Returns an \ApkParser\Stream instance which contains classes.dex file
77-
* @returns \ApkParser\Stream
78+
* @returns Stream
79+
* @throws \Exception
7880
*/
79-
public function getClassesDexStream()
81+
public function getClassesDexStream(): Stream
8082
{
8183
return new Stream($this->getStream('classes.dex'));
8284
}
8385

8486
/**
8587
* Apk file path.
86-
* @return string
88+
* @return bool|string
8789
*/
88-
public function getApkPath()
90+
public function getApkPath(): bool|string
8991
{
9092
return $this->filePath;
9193
}
@@ -94,19 +96,25 @@ public function getApkPath()
9496
* Apk file name
9597
* @return string
9698
*/
97-
public function getApkName()
99+
public function getApkName(): string
98100
{
99101
return $this->fileName;
100102
}
101103

102104

103-
public function extractTo($destination, $entries = null)
105+
/**
106+
* @param string $pathto
107+
* @param array|string|null $files
108+
* @return bool
109+
* @throws \Exception
110+
*/
111+
public function extractTo(string $pathto, array|string|null $files = null): bool
104112
{
105-
if ($extResult = parent::extractTo($destination, $entries)) {
106-
$xmlFiles = Utils::globRecursive($destination . '/*.xml');
113+
if ($extResult = parent::extractTo($pathto, $files)) {
114+
$xmlFiles = Utils::globRecursive($pathto . '/*.xml');
107115

108116
foreach ($xmlFiles as $xmlFile) {
109-
if ($xmlFile == ($destination . "/AndroidManifest.xml")) {
117+
if ($xmlFile == ($pathto . "/AndroidManifest.xml")) {
110118
XmlParser::decompressFile($xmlFile);
111119
}
112120
}

lib/ApkParser/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function __construct(array $config = [])
3131
{
3232
$this->config = array_merge(
3333
[
34-
'tmp_path' => sys_get_temp_dir(),
35-
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
34+
'tmp_path' => sys_get_temp_dir(),
35+
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
3636
'manifest_only' => true
3737
],
3838
$config

0 commit comments

Comments
 (0)