@@ -47,6 +47,12 @@ class PKPass
47
47
*/
48
48
protected $ remote_file_urls = [];
49
49
50
+ /**
51
+ * Holds the files content to include in the pass.
52
+ * @var string[]
53
+ */
54
+ protected $ files_content = [];
55
+
50
56
/**
51
57
* Holds the JSON payload.
52
58
* @var object|array
@@ -250,7 +256,7 @@ public function addRemoteFile($url, $name = null)
250
256
* Add a locale file from a url to the remote file urls array.
251
257
*
252
258
* @param string $language language for which file to be added
253
- * @param string $url URL to file
259
+ * @param string $content Content of file
254
260
* @param string $name Filename to use in pass archive (default is equal to $url)
255
261
*/
256
262
public function addLocaleRemoteFile ($ language , $ url , $ name = null )
@@ -259,6 +265,29 @@ public function addLocaleRemoteFile($language, $url, $name = null)
259
265
$ this ->remote_file_urls [$ language . '.lproj/ ' . $ name ] = $ url ;
260
266
}
261
267
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
+
262
291
/**
263
292
* Create the actual .pkpass file.
264
293
*
@@ -353,6 +382,13 @@ protected function createManifest()
353
382
$ sha [$ name ] = sha1 (file_get_contents ($ url ));
354
383
}
355
384
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
+
356
392
if (!$ has_icon ) {
357
393
throw new PKPassException ('Missing required icon.png file. ' );
358
394
}
@@ -470,6 +506,11 @@ protected function createZip($manifest, $signature)
470
506
$ download_file = file_get_contents ($ url );
471
507
$ zip ->addFromString ($ name , $ download_file );
472
508
}
509
+
510
+ foreach ($ this ->files_content as $ name => $ content ) {
511
+ $ zip ->addFromString ($ name , $ content );
512
+ }
513
+
473
514
$ zip ->close ();
474
515
475
516
if (!file_exists ($ filename ) || filesize ($ filename ) < 1 ) {
0 commit comments