Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Richard Weinhold
PushNotifications
Commits
eceb384f
Verified
Commit
eceb384f
authored
Sep 29, 2020
by
Richard Weinhold
🔨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds support for composer/ca-bundle to FCM-Handler
parent
81969ae7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
22 deletions
+44
-22
src/Handler.php
src/Handler.php
+32
-0
src/Handler/APNS.php
src/Handler/APNS.php
+3
-17
src/Handler/APNSBinary.php
src/Handler/APNSBinary.php
+2
-4
src/Handler/FCM.php
src/Handler/FCM.php
+7
-1
No files found.
src/Handler.php
View file @
eceb384f
...
...
@@ -13,10 +13,42 @@ use RuntimeException;
*/
abstract
class
Handler
{
/**
* @var string[]
*/
protected
array
$devices
=
[];
protected
?string
$caCertPath
;
protected
function
setCaCertPath
(
?string
$caCertPath
):
void
{
if
(
$caCertPath
!==
null
)
{
$this
->
caCertPath
=
$caCertPath
;
}
elseif
(
class_exists
(
'\Composer\CaBundle\CaBundle'
))
{
$this
->
caCertPath
=
\
Composer\CaBundle\CaBundle
::
getSystemCaRootBundlePath
();
}
}
/**
* @return array|null
*/
protected
function
getCurlCAPathOptions
():
?array
{
if
(
$this
->
caCertPath
===
null
)
{
return
null
;
}
$caCertPath
=
realpath
(
$this
->
caCertPath
);
if
(
$caCertPath
===
null
||
!
file_exists
(
$caCertPath
)
||
!
is_readable
(
$caCertPath
))
{
throw
new
RuntimeException
(
"CA not found or not readable for path:
{
$this
->
caCertPath
}
"
,
404
);
}
if
(
is_dir
(
$caCertPath
))
{
return
[
CURLOPT_CAPATH
=>
$caCertPath
];
}
return
[
CURLOPT_CAINFO
=>
$caCertPath
];
}
public
function
addDevice
(
string
$token
):
void
{
...
...
src/Handler/APNS.php
View file @
eceb384f
...
...
@@ -23,7 +23,6 @@ class APNS extends Handler
private
int
$port
;
private
string
$certPath
;
private
?string
$certPassphrase
;
private
?string
$caCertPath
;
private
int
$timeout
;
public
function
__construct
(
string
$environment
,
string
$appBundleID
,
string
$certPath
,
?string
$certPassphrase
=
null
,
?string
$caCertPath
=
null
,
?string
$url
=
null
,
int
$timeout
=
10
)
...
...
@@ -54,11 +53,7 @@ class APNS extends Handler
$this
->
certPassphrase
=
$certPassphrase
;
$this
->
timeout
=
$timeout
;
if
(
$caCertPath
!==
null
)
{
$this
->
caCertPath
=
$caCertPath
;
}
elseif
(
class_exists
(
'\Composer\CaBundle\CaBundle'
))
{
$this
->
caCertPath
=
\
Composer\CaBundle\CaBundle
::
getSystemCaRootBundlePath
();
}
$this
->
setCaCertPath
(
$caCertPath
);
}
public
function
addDevice
(
string
$token
):
void
...
...
@@ -128,17 +123,8 @@ class APNS extends Handler
$options
[
CURLOPT_KEYPASSWD
]
=
$this
->
certPassphrase
;
}
if
(
$this
->
caCertPath
!==
null
)
{
$caCertPath
=
realpath
(
$this
->
caCertPath
);
if
(
$caCertPath
===
null
||
!
file_exists
(
$caCertPath
)
||
!
is_readable
(
$caCertPath
))
{
throw
new
RuntimeException
(
"[APNS] CA not found or not readable for path:
{
$this
->
caCertPath
}
"
,
404
);
}
if
(
is_dir
(
$caCertPath
))
{
$options
[
CURLOPT_CAPATH
]
=
$caCertPath
;
}
else
{
$options
[
CURLOPT_CAINFO
]
=
$caCertPath
;
}
if
(
null
!==
$caCertOptions
=
$this
->
getCurlCAPathOptions
())
{
$options
=
array_merge
(
$options
,
$caCertOptions
);
}
$curl
=
curl_init
();
...
...
src/Handler/APNSBinary.php
View file @
eceb384f
...
...
@@ -10,8 +10,6 @@ use ricwein\PushNotification\Message;
use
RuntimeException
;
/**
* Class APNSBinary
* @package ricwein\PushNotification\Handler
* @deprecated
*/
class
APNSBinary
extends
Handler
...
...
@@ -24,7 +22,6 @@ class APNSBinary extends Handler
private
string
$endpoint
;
private
string
$certPath
;
private
?string
$certPassphrase
;
private
?string
$caCertPath
;
private
int
$timeout
;
public
function
__construct
(
string
$environment
,
string
$certPath
,
?string
$certPassphrase
=
null
,
?string
$caCertPath
=
null
,
?string
$url
=
null
,
int
$timeout
=
10
)
...
...
@@ -44,7 +41,8 @@ class APNSBinary extends Handler
$this
->
certPath
=
$certPath
;
$this
->
certPassphrase
=
$certPassphrase
;
$this
->
timeout
=
$timeout
;
$this
->
caCertPath
=
$caCertPath
;
$this
->
setCaCertPath
(
$caCertPath
);
}
public
function
addDevice
(
string
$token
):
void
...
...
src/Handler/FCM.php
View file @
eceb384f
...
...
@@ -18,11 +18,13 @@ class FCM extends Handler
private
string
$token
;
private
int
$timeout
;
public
function
__construct
(
string
$token
,
string
$url
=
self
::
FCM_ENDPOINT
,
int
$timeout
=
30
)
public
function
__construct
(
string
$token
,
string
$url
=
self
::
FCM_ENDPOINT
,
?string
$caCertPath
=
null
,
int
$timeout
=
30
)
{
$this
->
endpoint
=
$url
;
$this
->
token
=
$token
;
$this
->
timeout
=
$timeout
;
$this
->
setCaCertPath
(
$caCertPath
);
}
/**
...
...
@@ -94,6 +96,10 @@ class FCM extends Handler
CURLOPT_TIMEOUT
=>
$this
->
timeout
,
];
if
(
null
!==
$caCertOptions
=
$this
->
getCurlCAPathOptions
())
{
$options
=
array_merge
(
$options
,
$caCertOptions
);
}
$curl
=
curl_init
();
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment