I've got 4 classes responsive for:
1st - getting input as JSON string from url, decode it into an array and create 2 variables: $user_id, $user_text (like here below):
class Get_message{
public $user_id, $user_text;
public function get_input(){
$input = json_decode(file_get_contents('myURL'), true);
$user_id = $input['getting value from an array'];
$user_text = $input['getting value from an array'];
//how to return it?
//return $input, $user_id, $user_text? it won't work I guess
}
}
and there is my first question: how to return that 2 values so that I can use it in another classes?
2nd - check if that string contains keywords, if it contains a keyword I want to create another JSON,
so far I've got this:
class input_recognize{
const KEYWORD_HELP = 'help';
//...some more constants...
const KEYWORD_REPORT = 'report';
public function msg_recognize($user_text)
{
switch ($user_text) {
case self::KEYWORD_HELP:
return new Output_msg(Output_msg::MESS_HELP);
break;
//... some more cases
case self::KEYWORD_REPORT:
return new Output_message(Output_msg::MESS_REPORT);
break;
}
}
}
3rd - based on that what case in class above was true create appropriate JSON, my code looks like:
class Output_message{
const MESS_REPORT = 1;
const MESS_HELP = 2;
public function __construct($user_id, $user_text){
//I guess I should use $this here, dunno how
$json_output = array(
"first_title" => array(
"id" => $user_id
),
"second_title" => array(
"text" => "text to send"
),
);
$output = json_encode($json_ouput);
}
}
4th - and I want to be able to take $output into that function and POST it to url.
I'm beginner in php, object oriented programming as well, I'll appreciate any help, and criticism. Thanks in advice.