sebbmeyer / php-microsoft-teams-connector

PHP Microsoft Teams Connector
MIT License
111 stars 22 forks source link

Fatal error: Uncaught Error: Class 'Sebbmyr\Teams\TeamsConnector' not found #17

Closed kevshah1 closed 4 years ago

kevshah1 commented 4 years ago

Following the simple card example, getting Fatal error: Uncaught Error: Class 'Sebbmyr\Teams\TeamsConnector' not found

Have also tried to include the teams connector by doing 'use Sebbmyr\Teams\TeamsConnector;' however still does not work.

Environment uses PHP v7.4.

sebbmeyer commented 4 years ago

@kevshah1 How did you include the package in you project? Is the TeamsConnector.php located in vendor\sebbmeyer\php-microsoft-teams-connector\src?

kevshah1 commented 4 years ago

Hi Done the below: require 'vendor\sebbmeyer\php-microsoft-teams-connector\src\TeamsConnector.php'; require 'vendor\sebbmeyer\php-microsoft-teams-connector\src\AbstractCard.php'; require 'vendor\sebbmeyer\php-microsoft-teams-connector\src\Cards\SimpleCard.php'; require 'vendor\sebbmeyer\php-microsoft-teams-connector\src\Cards\CustomCard.php';

and

use Sebbmyr\Teams\TeamsConnector; use Sebbmyr\Teams\SimpleCard; use Sebbmyr\Teams\TeamsConnectorInterface;

TeamsConnector.php is located in the correct folder

sebbmeyer commented 4 years ago

You are trying to include it in a plain php script, correct? If yes, you don't need use. So the following should work:

require_once 'vendor/autoload.php';

$connector = new TeamsConnector('<WEBHOOK_URL>');
$card = new SimpleCard(['title' => 'Simple Card', 'text' => 'Hello World']);
$connector->send($card);

I used the answer from here and modified it, but I didn't test it

kevshah1 commented 4 years ago

Changed as per your suggestion but now getting a Fatal error: Uncaught Error: Class 'TeamsConnector' not found.

Yes, using a plain PHP script.

sebbmeyer commented 4 years ago

Ok, I tried it and this worked for me:

<?php

require __DIR__ . '/vendor/autoload.php';

$connector = new Sebbmyr\Teams\TeamsConnector('<WEBHOOK_URL>');
// create card
$card  = new Sebbmyr\Teams\Cards\SimpleCard(['title' => 'Simple card title', 'text' => 'Simple card text']);
// send card via connector
$connector->send($card);
kevshah1 commented 4 years ago

Thank you so much works now!

Useful for anyone that may be using it with plain PHP.