Skip to content

Commit dddfca2

Browse files
authored
Merge pull request #121 from netolicak/master
Added PKPass::addFileContent and PKPass::addLocaleFileContent methods…
2 parents 8981689 + b2434bc commit dddfca2

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/PKPass.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class PKPass
4747
*/
4848
protected $remote_file_urls = [];
4949

50+
/**
51+
* Holds the files content to include in the pass.
52+
* @var string[]
53+
*/
54+
protected $files_content = [];
55+
5056
/**
5157
* Holds the JSON payload.
5258
* @var object|array
@@ -250,7 +256,7 @@ public function addRemoteFile($url, $name = null)
250256
* Add a locale file from a url to the remote file urls array.
251257
*
252258
* @param string $language language for which file to be added
253-
* @param string $url URL to file
259+
* @param string $content Content of file
254260
* @param string $name Filename to use in pass archive (default is equal to $url)
255261
*/
256262
public function addLocaleRemoteFile($language, $url, $name = null)
@@ -259,6 +265,29 @@ public function addLocaleRemoteFile($language, $url, $name = null)
259265
$this->remote_file_urls[$language . '.lproj/' . $name] = $url;
260266
}
261267

268+
/**
269+
* Add a file from a string to the string files array.
270+
*
271+
* @param string $content Content of file
272+
* @param string $name Filename to use in pass archive (default is equal to $url)
273+
*/
274+
public function addFileContent($content, $name)
275+
{
276+
$this->files_content[$name] = $content;
277+
}
278+
279+
/**
280+
* Add a locale file from a string to the string files array.
281+
*
282+
* @param string $language language for which file to be added
283+
* @param string $content Content of file
284+
* @param string $name Filename to use in pass archive (default is equal to $url)
285+
*/
286+
public function addLocaleFileContent($language, $content, $name)
287+
{
288+
$this->files_content[$language . '.lproj/' . $name] = $content;
289+
}
290+
262291
/**
263292
* Create the actual .pkpass file.
264293
*
@@ -353,6 +382,13 @@ protected function createManifest()
353382
$sha[$name] = sha1(file_get_contents($url));
354383
}
355384

385+
foreach ($this->files_content as $name => $content) {
386+
if (strtolower($name) == 'icon.png') {
387+
$has_icon = true;
388+
}
389+
$sha[$name] = sha1($content);
390+
}
391+
356392
if (!$has_icon) {
357393
throw new PKPassException('Missing required icon.png file.');
358394
}
@@ -470,6 +506,11 @@ protected function createZip($manifest, $signature)
470506
$download_file = file_get_contents($url);
471507
$zip->addFromString($name, $download_file);
472508
}
509+
510+
foreach ($this->files_content as $name => $content) {
511+
$zip->addFromString($name, $content);
512+
}
513+
473514
$zip->close();
474515

475516
if (!file_exists($filename) || filesize($filename) < 1) {

0 commit comments

Comments
 (0)