Coder Social home page Coder Social logo

Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given about pushok HOT 13 CLOSED

edamov avatar edamov commented on June 3, 2024
Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given

from pushok.

Comments (13)

edamov avatar edamov commented on June 3, 2024

Hi,
Can you provide code how do you use Client ?

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

Here's my whole code :

<?php

require ROOTPATH . 'vendor/autoload.php';

use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;

class PushiOS {

	private $key_id;
	private $team_id;
	private $app_bundle_id;
	private $private_key_path;
	private $private_key_secret;

	private $authProvider;

	public function __construct() {
		// Load iOS options
		$this->loadOptions();

		// Init auth provider
		$this->initAuthProvider();
	}

	private function loadOptions() {
		$key_id = get_option('freenews_ios_key_id', array('text_string' => null));
		$this->key_id = $key_id['text_string'];

		$team_id = get_option('freenews_ios_team_id', array('text_string' => null));
		$this->team_id = $team_id['text_string'];

		$app_bundle_id = get_option('freenews_ios_app_bundle_id', array('text_string' => null));
		$this->app_bundle_id = $app_bundle_id['text_string'];

		$private_key_path = get_option('freenews_ios_private_key_path', array('text_string' => null));
		$this->private_key_path = $private_key_path['text_string'];

		$private_key_secret = get_option('freenews_ios_private_key_secret', array('text_string' => null));
		$this->private_key_secret = $private_key_secret['text_string'];
	}

	private function initAuthProvider() {
		$options = [
			'key_id' => $this->key_id,
			'team_id' => $this->team_id,
			'app_bundle_id' => $this->app_bundle_id,
			'private_key_path' => $this->private_key_path,
			'private_key_secret' => $this->private_key_secret
		];

		$this->authProvider = AuthProvider\Token::create($options);
	}

	private function generatePayload($title, $body, $sound = 'default', $customValues = array()): Payload {
		$alert = Alert::create()->setTitle($title);
		$alert = $alert->setBody($body);

		$payload = Payload::create()->setAlert($alert);
		$payload = $payload->setSound($sound);

		foreach ($customValues as $key => $value) {
			$payload = $payload->setCustomValue($key, $value);
		}

		return $payload;
	}

	public function notify($devices, $data) {
		$payload = $this->generatePayload($data['mtitle'], $data['mdesc']);

		$notifications = [];
		foreach ($devices as $device) {
			$notifications[] = new Notification($payload, $device['token']);
		}

		$client = new Client($this->authProvider, $production = !WP_LOCAL_DEV);
		$client->addNotifications($notifications);

		$responses = $client->push();

		foreach ($responses as $response) {
			var_dump($response->getApnsId());
			var_dump($response->getStatusCode());
			var_dump($response->getReasonPhrase());
			var_dump($response->getErrorReason());
			var_dump($response->getErrorDescription());
		}
	}
}
?>

And I'm doing this when publishing a post :

$pushiOS = new PushiOS();
$pushiOS->notify($ios_devices, $data);

It's more or less your exemple in the readme.

from pushok.

edamov avatar edamov commented on June 3, 2024

I think it is the same bug as here #7.
Please read my answer

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

Indeed, it looks like my version of curl wasn't compatible with HTTP/2, now it seems good for that part, but it seems like I still need to find how to update openssl to v1.0.2 on Jessie.

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

All right, I managed to correctly install everything needed (I think).

Here's a curl request showing that it's working :

# curl --http2 -I https://nghttp2.org/
HTTP/2.0 200
date:Wed, 15 Feb 2017 21:15:53 GMT
content-type:text/html
last-modified:Wed, 25 Jan 2017 12:22:17 GMT
etag:"58889879-19e1"
accept-ranges:bytes
content-length:6625
x-backend-header-rtt:0.001475
strict-transport-security:max-age=31536000
server:nghttpx nghttp2/1.20.0-DEV
via:2 nghttpx
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
x-content-type-options:nosniff

I have OpenSSL 1.0.2k:

OpenSSL Header Version => OpenSSL 1.0.2j  26 Sep 2016```

But I still have the same error, but now with two more notices :

Notice: Use of undefined constant CURLPIPE_MULTIPLEX - assumed 'CURLPIPE_MULTIPLEX' in .../vendor/edamov/pushok/src/Client.php on line 62

Notice: Use of undefined constant CURL_HTTP_VERSION_2 - assumed 'CURL_HTTP_VERSION_2' in .../vendor/edamov/pushok/src/Request.php on line 67

Notice: Undefined offset: 1 in .../vendor/edamov/pushok/src/Client.php on line 95

Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in .../vendor/edamov/pushok/src/Client.php on line 97 and defined in .../vendor/edamov/pushok/src/Response.php:136

from pushok.

edamov avatar edamov commented on June 3, 2024

@ThibaultVlacich What version of PHP do you have?

from pushok.

edamov avatar edamov commented on June 3, 2024

I've just find CURL_HTTP_VERSION_2 constant is available only from PHP 7.0.7

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

I have PHP 7.0.15

# php -v
PHP 7.0.15-1+0~20170120094752.20+jessie~1.gbpe03972 (cli) (built: Jan 20 2017 11:15:00) ( NTS )

from pushok.

edamov avatar edamov commented on June 3, 2024

It's the version of php-cli. It can be different with php-fpm version. Can you look in phpinfo(); ?

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

Yep, I looked in phpinfo(); and it's the exact same version PHP Version 7.0.15-1+0~20170120094752.20+jessie~1.gbpe03972.

Here's other interesting info I have in the phpinfo :

curl

cURL support	enabled
cURL Information	7.46.0
HTTP2	Yes
SSL Version	OpenSSL/1.0.2k

from pushok.

edamov avatar edamov commented on June 3, 2024

Hmm. I just have no idea. When I have time I'll try to investigate this issue.

CURL_HTTP_VERSION_2 is available since PHP 7.0.7 and cURL 7.43.0
CURLPIPE_MULTIPLEX is available since PHP 7.0.0 and cURL 7.43.0
http://php.net/manual/en/curl.constants.php

from pushok.

ThibaultVlacich avatar ThibaultVlacich commented on June 3, 2024

It seems like PHP doesn't just need Curl 7.43+ to be available at runtime, but it needs to be compiled against Curl 7.43+ to be working.

https://bugs.php.net/bug.php?id=74050

from pushok.

edamov avatar edamov commented on June 3, 2024

I added this constants in library if they don't exist in php dist

from pushok.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.