public function addContacts($contacts_json) { error_log("ContactsRepo->addContacts"); error_log($contacts_json); $contacts = []; foreach (json_decode($contacts_json, true) as $contact_array) { $contacts[] = new Contact($contact_array); } $phone_book = PhoneBook::from_array(array('retrieved_date' => date("c"), 'remote_addr' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'contacts' => $contacts)); $this->open_file('a'); fwrite($this->file_ptr, $phone_book->toJSON() . PHP_EOL); $this->close_file(); }