kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.23k stars 426 forks source link

Setting the badge account with $message->withApnsConfig(ApnsConfig::new()->withBadge(123)) does not work #899

Closed ptmkenny closed 3 months ago

ptmkenny commented 3 months ago

Describe the bug

I'm trying to set the badge count on iOS using the code example shown in the documentation for Notification Sounds. (code shown below)

The problem is that using ->withApnsConfg() is not actually changing the payload; when I check the value of $messages in XDebug, the payload isn't modified.

Installed packages

asm89/stack-cors                         2.2.0             Cross-origin resource sharing library and stack middleware
beste/clock                              3.0.0             A collection of Clock implementations
beste/in-memory-cache                    1.1.0             A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.
beste/json                               1.4.0             A simple JSON helper to decode and encode JSON
brick/math                               0.12.1            Arbitrary-precision arithmetic library
chi-teck/drupal-code-generator           3.6.0             Drupal code generator
chillerlan/php-qrcode                    4.4.1             A QR code generator with a user friendly API. PHP 7.4+
chillerlan/php-settings-container        3.2.0             A container class for immutable settings objects. Not a DI container.
christian-riesen/otp                     2.7.0             One Time Passwords, hotp and totp according to RFC4226 and RFC6238
composer/installers                      2.2.0             A multi-framework Composer library installer
composer/semver                          3.4.0             Semver library that offers utilities, version constraint parsing and validation.
consolidation/annotated-command          4.10.0            Initialize Symfony Console commands from annotated command class methods.
consolidation/config                     2.1.2             Provide configuration services for a commandline tool.
consolidation/filter-via-dot-access-data 2.0.2             This project uses dflydev/dot-access-data to provide simple output filtering for applicati...
consolidation/log                        3.1.0             Improved Psr-3 / Psr\Log logger based on Symfony Console components.
consolidation/output-formatters          4.5.0             Format text by applying transformations provided by plug-in formatters.
consolidation/robo                       4.0.6             Modern task runner
consolidation/self-update                2.2.0             Provides a self:update command for Symfony Console applications.
consolidation/site-alias                 4.1.0             Manage alias records for local and remote sites.
consolidation/site-process               5.4.0             A thin wrapper around the Symfony Process Component that allows applications to use the Si...
cweagans/composer-configurable-plugin    2.0.0             Provides a lightweight configuration system for Composer plugins.
cweagans/composer-patches                2.0.0-beta2       Provides a way to patch Composer packages.
defuse/php-encryption                    2.4.0             Secure PHP Encryption Library
dflydev/dot-access-data                  3.0.2             Given a deep data structure, access data by dot notation.
doctrine/annotations                     1.14.3            Docblock Annotations Parser
doctrine/deprecations                    1.1.3             A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to ...
doctrine/lexer                           2.1.1             PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
drupal/alternative_user_emails           1.0.0-alpha4      Store alternative email addresses for users.
drupal/core                              10.2.6            Drupal is an open source content management platform powering millions of websites and app...
drupal/core-composer-scaffold            10.2.6            A flexible Composer project scaffold builder.
drupal/core-vendor-hardening             10.2.6            Hardens the vendor directory for when it's in the docroot.
drush/drush                              12.5.2            Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army k...
e0ipso/shaper                            1.2.4             Lightweight library to handle in and out transformations in PHP.
egulias/email-validator                  4.0.2             A library for validating emails against several RFCs
fig/http-message-util                    1.1.5             Utility classes and constants for use with PSR-7 (psr/http-message)
firebase/php-jwt                         6.10.1            A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the ...
gapple/structured-fields                 2.1.1             Library for Structured Field Values for HTTP 
google/auth                              1.39.0            Google Auth Library for PHP
google/cloud-core                        1.58.1            Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-storage                     1.42.0            Cloud Storage Client for PHP
google/common-protos                     4.6.0             Google API Common Protos for PHP
google/gax                               1.33.0            Google API Core for PHP
google/grpc-gcp                          0.4.0             gRPC GCP library for channel management
google/longrunning                       0.4.2             Google LongRunning Client for PHP
google/protobuf                          4.27.0            proto library for PHP
grasmash/expander                        3.0.0             Expands internal property references in PHP arrays file.
grasmash/yaml-cli                        3.2.1             A command line tool for reading and manipulating yaml files.
gravitypdf/querypath                     3.2.3             PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PH...
grpc/grpc                                1.57.0            gRPC library for PHP
guzzlehttp/guzzle                        7.8.1             Guzzle is a PHP HTTP client library
guzzlehttp/promises                      2.0.2             Guzzle promises library
guzzlehttp/psr7                          2.6.2             PSR-7 message implementation that also provides common utility methods
html2text/html2text                      4.3.1             Converts HTML to formatted plain text
justinrainbow/json-schema                5.2.13            A library to validate a json schema.
kreait/firebase-php                      7.11.0            Firebase Admin SDK
kreait/firebase-tokens                   5.1.0             A library to work with Firebase tokens
laminas/laminas-escaper                  2.13.0            Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs
laminas/laminas-feed                     2.22.0            provides functionality for creating and consuming RSS and Atom feeds
laminas/laminas-stdlib                   3.19.0            SPL extensions, array utilities, error handlers, and more
lcobucci/clock                           3.2.0             Yet another clock abstraction
lcobucci/jwt                             5.3.0             A simple library to work with JSON Web Token and JSON Web Signature
league/commonmark                        2.4.2             Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-...
league/config                            1.2.0             Define configuration arrays with strict schemas and access values with dot notation
league/container                         4.2.2             A fast and intuitive dependency injection container.
masterminds/html5                        2.9.0             An HTML5 parser and serializer.
matomo/device-detector                   6.3.1             The Universal Device Detection library, that parses User Agents and detects devices (deskt...
mck89/peast                              1.16.2            Peast is PHP library that generates AST for JavaScript code
monolog/monolog                          3.6.0             Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/jmespath.php                   2.7.0             Declaratively specify how to extract elements from a JSON document
mustangostang/spyc                       0.6.3             A simple YAML loader/dumper class for PHP
nette/schema                             1.3.0             📐 Nette Schema: validating data structures against a given Schema.
nette/utils                              4.0.4             🛠  Nette Utils: lightweight utilities for string & array manipulation, image handling, ...
nikic/php-parser                         5.0.2             A PHP parser written in PHP
oomphinc/composer-installers-extender    2.0.1             Extend the composer/installers plugin to accept any arbitrary package type.
opis/json-schema                         2.3.0             Json Schema Validator for PHP
opis/string                              2.0.1             Multibyte strings as objects
opis/uri                                 1.1.0             Build, parse and validate URIs and URI-templates
paragonie/constant_time_encoding         2.7.0             Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
paragonie/halite                         5.1.2             High-level cryptography interface powered by libsodium
paragonie/hidden-string                  2.2.0             Encapsulate strings in an object to hide them from stack traces
paragonie/random_compat                  9.99.100          PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
paragonie/sodium_compat                  2.0.1             Pure PHP implementation of libsodium; uses the PHP extension if it exists
pear/archive_tar                         1.5.0             Tar file management class with compression support (gzip, bzip2, lzma2)
pear/console_getopt                      1.4.3             More info available on: http://pear.php.net/package/Console_Getopt
pear/pear-core-minimal                   1.10.15           Minimal set of PEAR core files to be used as composer dependency
pear/pear_exception                      1.0.2             The PEAR Exception base class.
phootwork/collection                     3.2.2             The phootwork library fills gaps in the php language and provides better solutions than th...
phootwork/lang                           3.2.2             Missing PHP language constructs
phpdocumentor/reflection-common          2.2.0             Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock        5.4.1             With this component, a library can provide support for annotations via DocBlocks or otherw...
phpdocumentor/type-resolver              1.8.2             A PSR-5 based resolver of Class names, Types and Structural Element Names
phpowermove/docblock                     4.0               PHP Docblock parser and generator. An API to read and write Docblocks.
phpstan/phpdoc-parser                    1.29.0            PHPDoc parser with support for nullable, intersection and generic types
platformsh/config-reader                 2.4.1             Small helper to access Platform.sh environment variables
psr/cache                                3.0.0             Common interface for caching libraries
psr/clock                                1.0.0             Common interface for reading the clock.
psr/container                            2.0.2             Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                     1.0.0             Standard interfaces for event handling.
psr/http-client                          1.0.3             Common interface for HTTP clients
psr/http-factory                         1.1.0             PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message                         2.0               Common interface for HTTP messages
psr/log                                  3.0.0             Common interface for logging libraries
psy/psysh                                0.12.3            An interactive shell for modern PHP.
ralouphie/getallheaders                  3.0.3             A polyfill for getallheaders.
ramsey/collection                        2.0.0             A PHP library for representing and manipulating collections.
ramsey/uuid                              4.7.6             A PHP library for generating and working with universally unique identifiers (UUIDs).
rize/uri-template                        0.3.6             PHP URI Template (RFC 6570) supports both expansion & extraction
rrssb/rrssb-plus                         0.5.5             Ridiculously Responsive Social Sharing Buttons Plus
sebastian/diff                           4.0.6             Diff implementation
softcreatr/jsonpath                      0.9.0             JSONPath implementation for parsing, searching and flattening arrays
spomky-labs/cbor-php                     3.0.4             CBOR Encoder/Decoder for PHP
spomky-labs/pki-framework                1.2.1             A PHP framework for managing Public Key Infrastructures. It comprises X.509 public key cer...
stripe/stripe-php                        14.8.0            Stripe PHP Library
symfony/console                          6.4.7             Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                     6.4.7             Converts CSS selectors to XPath expressions
symfony/dependency-injection             6.4.7             Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts            3.5.0             A generic function and convention to trigger deprecation notices
symfony/error-handler                    6.4.7             Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher                 6.4.7             Provides tools that allow your application components to communicate with each other by di...
symfony/event-dispatcher-contracts       3.5.0             Generic abstractions related to dispatching event
symfony/filesystem                       6.4.7             Provides basic utilities for the filesystem
symfony/finder                           6.4.7             Finds files and directories via an intuitive fluent interface
symfony/http-foundation                  6.4.7             Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                      6.4.7             Provides a structured process for converting a Request into a Response
symfony/mailer                           6.4.7             Helps sending emails
symfony/mime                             6.4.7             Allows manipulating MIME messages
symfony/polyfill-ctype                   1.29.0            Symfony polyfill for ctype functions
symfony/polyfill-iconv                   1.29.0            Symfony polyfill for the Iconv extension
symfony/polyfill-intl-grapheme           1.29.0            Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn                1.29.0            Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer         1.29.0            Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                1.29.0            Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                   1.20.0            Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php72                   1.29.0            Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80                   1.29.0            Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81                   1.29.0            Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/polyfill-php83                   1.29.0            Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/polyfill-uuid                    1.29.0            Symfony polyfill for uuid functions
symfony/process                          6.4.7             Executes commands in sub-processes
symfony/property-access                  7.0.7             Provides functions to read and write from/to an object or array using a simple string nota...
symfony/property-info                    7.0.7             Extracts information about PHP class' properties using metadata of popular sources
symfony/psr-http-message-bridge          6.4.7             PSR HTTP message bridge
symfony/routing                          6.4.7             Maps an HTTP request to a set of configuration variables
symfony/serializer                       6.4.7             Handles serializing and deserializing data structures, including object graphs, into array...
symfony/service-contracts                3.5.0             Generic abstractions related to writing services
symfony/string                           6.4.7             Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and gra...
symfony/translation-contracts            3.5.0             Generic abstractions related to translation
symfony/uid                              7.0.7             Provides an object-oriented API to generate and represent UIDs
symfony/validator                        6.4.7             Provides tools to validate values
symfony/var-dumper                       6.4.7             Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                     7.0.7             Allows exporting any serializable PHP data structure to plain PHP code
symfony/yaml                             6.4.7             Loads and dumps YAML files
tijsverkoyen/css-to-inline-styles        2.2.7             CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/...
twig/twig                                3.10.3            Twig, the flexible, fast, and secure template language for PHP
web-auth/cose-lib                        4.3.0             CBOR Object Signing and Encryption (COSE) For PHP
web-auth/metadata-service                4.8.6             Metadata Service for FIDO2/Webauthn
web-auth/webauthn-lib                    4.8.6             FIDO2/Webauthn Support For PHP
webflo/drupal-finder                     1.3.0             Helper class to locate a Drupal installation.
webmozart/assert                         1.11.0            Assertions to validate method input/output with nice error messages.

### PHP version and extensions

```shell
composer                 2.7.6    Composer package
composer-plugin-api      2.6.0    The Composer Plugin API
composer-runtime-api     2.2.2    The Composer Runtime API
ext-bcmath               8.3.7    The bcmath PHP extension
ext-bz2                  8.3.7    The bz2 PHP extension
ext-calendar             8.3.7    The calendar PHP extension
ext-ctype                8.3.7    The ctype PHP extension
ext-curl                 8.3.7    The curl PHP extension
ext-date                 8.3.7    The date PHP extension
ext-dba                  8.3.7    The dba PHP extension
ext-dom                  20031129 The dom PHP extension
ext-exif                 8.3.7    The exif PHP extension
ext-ffi                  8.3.7    The FFI PHP extension
ext-fileinfo             8.3.7    The fileinfo PHP extension
ext-filter               8.3.7    The filter PHP extension
ext-ftp                  8.3.7    The ftp PHP extension
ext-gd                   8.3.7    The gd PHP extension
ext-gettext              8.3.7    The gettext PHP extension
ext-gmp                  8.3.7    The gmp PHP extension
ext-hash                 8.3.7    The hash PHP extension
ext-iconv                8.3.7    The iconv PHP extension
ext-intl                 8.3.7    The intl PHP extension
ext-json                 8.3.7    The json PHP extension
ext-ldap                 8.3.7    The ldap PHP extension
ext-libxml               8.3.7    The libxml PHP extension
ext-mbstring             8.3.7    The mbstring PHP extension
ext-mysqli               8.3.7    The mysqli PHP extension
ext-mysqlnd              0        The mysqlnd PHP extension (actual version: mysqlnd 8.3.7)
ext-odbc                 8.3.7    The odbc PHP extension
ext-openssl              8.3.7    The openssl PHP extension
ext-pcntl                8.3.7    The pcntl PHP extension
ext-pcre                 8.3.7    The pcre PHP extension
ext-pdo                  8.3.7    The PDO PHP extension
ext-pdo_dblib            8.3.7    The pdo_dblib PHP extension
ext-pdo_mysql            8.3.7    The pdo_mysql PHP extension
ext-pdo_odbc             8.3.7    The PDO_ODBC PHP extension
ext-pdo_pgsql            8.3.7    The pdo_pgsql PHP extension
ext-pdo_sqlite           8.3.7    The pdo_sqlite PHP extension
ext-pgsql                8.3.7    The pgsql PHP extension
ext-phar                 8.3.7    The Phar PHP extension
ext-posix                8.3.7    The posix PHP extension
ext-pspell               8.3.7    The pspell PHP extension
ext-random               8.3.7    The random PHP extension
ext-readline             8.3.7    The readline PHP extension
ext-reflection           8.3.7    The Reflection PHP extension
ext-session              8.3.7    The session PHP extension
ext-shmop                8.3.7    The shmop PHP extension
ext-simplexml            8.3.7    The SimpleXML PHP extension
ext-soap                 8.3.7    The soap PHP extension
ext-sockets              8.3.7    The sockets PHP extension
ext-sodium               8.3.7    The sodium PHP extension
ext-spl                  8.3.7    The SPL PHP extension
ext-sqlite3              8.3.7    The sqlite3 PHP extension
ext-sysvmsg              8.3.7    The sysvmsg PHP extension
ext-sysvsem              8.3.7    The sysvsem PHP extension
ext-sysvshm              8.3.7    The sysvshm PHP extension
ext-tidy                 8.3.7    The tidy PHP extension
ext-tokenizer            8.3.7    The tokenizer PHP extension
ext-xml                  8.3.7    The xml PHP extension
ext-xmlreader            8.3.7    The xmlreader PHP extension
ext-xmlwriter            8.3.7    The xmlwriter PHP extension
ext-xsl                  8.3.7    The xsl PHP extension
ext-zend-opcache         8.3.7    The Zend OPcache PHP extension
ext-zip                  1.22.3   The zip PHP extension
ext-zlib                 8.3.7    The zlib PHP extension
lib-bz2                  1.0.8    The bz2 library
lib-curl                 8.8.0    The curl library
lib-curl-libssh2         1.11.0   curl libssh2 version
lib-curl-securetransport 3.3.0    curl (securetransport) openssl version (3.3.0)
lib-curl-zlib            1.2.12   curl zlib version
lib-date-timelib         2022.10  date timelib version
lib-date-zoneinfo        2024.1   zoneinfo ("Olson") database for date
lib-fileinfo-libmagic    543      fileinfo libmagic version
lib-gd                   2.3.3    The gd library
lib-gmp                  6.3.0    The gmp library
lib-iconv                1.11     The iconv library
lib-icu                  74.2     The ICU unicode and globalization support library
lib-icu-cldr             44.1     ICU CLDR project version
lib-icu-unicode          15.1.0   ICU unicode version
lib-icu-zoneinfo         2023.3   zoneinfo ("Olson") database for icu
lib-ldap-openldap        2.6.7    OpenLDAP version of ldap
lib-libsodium            1.0.19   The libsodium library
lib-libxml               2.9.13   libxml library version
lib-libxslt              1.1.35   The libxslt library
lib-libxslt-libxml       2.9.13   libxml version libxslt is compiled against
lib-mbstring-libmbfl     1.3.2    mbstring libmbfl version
lib-mbstring-oniguruma   6.9.9    mbstring oniguruma version
lib-openssl              3.3.0    OpenSSL 3.3.0 9 Apr 2024
lib-pcre                 10.43    The pcre library
lib-pcre-unicode         15.0.0   PCRE Unicode version support
lib-pdo_pgsql-libpq      16.3     libpq for pdo_pgsql
lib-pdo_sqlite-sqlite    3.45.3   The pdo_sqlite-sqlite library
lib-pgsql-libpq          16.3     libpq for pgsql
lib-sqlite3-sqlite       3.45.3   The sqlite3-sqlite library
lib-zip-libzip           1.10.0   The zip-libzip library
lib-zlib                 1.2.12   The zlib library
php                      8.3.7    The PHP interpreter
php-64bit                8.3.7    The PHP interpreter, 64bit
php-ipv6                 8.3.7    The PHP interpreter, with IPv6 support

### Steps to reproduce the issue.

```shell
# Insert the commands issued in the terminal if they are needed
# to reproduce the issue. Otherwise, delete this code block.
// Insert the PHP code to reproduce the issue. Please ensure that it is code that
// can be copy pasted to reproduce it.
    $notification = Notification::create('Test Title', 'This is a test message.');
    $message_array = ['notification' => $notification, 'token' => 'valid-ios-token' ];
    $badge_count = 25;
    $message = CloudMessage::fromArray($message_inputs);

    $badge_apns_config = ApnsConfig::new()->withBadge($badge_count);
    // When I check $badge_apns_config in Xdebug, the ApnsConfig has a badge count of 25.
    $message->withApnsConfig($badge_apns_config);
    // When I view $message, apparently the payload has not been modified to include the badge count.

Error message/Stack trace

-

Additional information

No response

jeromegamez commented 3 months ago

$message is an immutable object and returns a new instance of itself; the original message remains unchanged

$message = $message->withApnsConfig($badge_apns_config);

should work.

ptmkenny commented 3 months ago

Thank you so much! That did the trick.