Installation
composer require bcedric/uca-office365:dev-main
Register the bundle in config/bundle.php:
BCedric\UCAOffice365\BCedricUCAOffice365Bundle::class => ['all' => true],
Environment Configuration
Add these to your .env (choose one service):
GRAPH_TENANT=your_tenant_id
GRAPH_CLIENT=your_client_id
GRAPH_CLIENT_SECRET=your_client_secret
PROXY_URL=http://your_proxy_url
APIO365_URL=https://your-api-url
APIO365_LOGIN=your_login
APIO365_PASSWORD=your_password
First Use Case Inject the service in a controller/service and call a method:
use BCedric\UCAOffice365\Service\UCAOffice365;
public function __construct(private UCAOffice365 $ucaOffice365) {}
public function fetchUserData(string $uid) {
return $this->ucaOffice365->getUser($uid);
}
User Management
getUser(), createUser(), and deleteUser() for basic user lifecycle.addBooking() and removeBooking().$user = $this->ucaOffice365->getUser('user123');
$this->ucaOffice365->addBooking('user123'); // Enable booking
Calendar Integration
$calendarUrl = $this->ucaOffice365->getCalendarURL($uid, $startDate, $endDate);
Proxy Handling
PROXY_URL in .env if your app routes through a proxy for Office365 API calls.Error Handling
try {
$user = $this->ucaOffice365->getUser($uid);
} catch (\Exception $e) {
// Log or notify (e.g., Slack/email)
throw new \RuntimeException("Failed to fetch user: " . $e->getMessage());
}
Dependency Injection
public function __construct(
private UCAOffice365 $ucaOffice365,
private GraphAPI $graphApi // If using Microsoft Graph
) {}
Command Bus Pattern
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncUsersCommand extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$users = $this->ucaOffice365->getAllUsers(); // Hypothetical method
foreach ($users as $user) {
$this->ucaOffice365->addBooking($user['uid']);
}
$output->writeln('Booking enabled for all users.');
}
}
Event-Driven Extensions
UserCreated) to trigger Office365 actions:
// In a subscriber or event listener
public function onUserCreated(UserCreatedEvent $event) {
$this->ucaOffice365->createUser($event->getUser()->getId());
}
Caching
$user = Cache::remember("user_{$uid}", now()->addHours(1), function() use ($uid) {
return $this->ucaOffice365->getUser($uid);
});
Authentication Failures
.env variables cause silent failures.Route::get('/health', function () {
try {
$this->ucaOffice365->getUser('test123');
return response()->json(['status' => 'healthy']);
} catch (\Exception $e) {
return response()->json(['status' => 'unhealthy', 'error' => $e->getMessage()], 500);
}
});
Rate Limiting
use Symfony\Component\Process\Exception\TimeoutException;
try {
$user = $this->ucaOffice365->getUser($uid);
} catch (TimeoutException $e) {
sleep(2); // Wait before retry
$user = $this->ucaOffice365->getUser($uid);
}
Proxy Dependencies
PROXY_URL may break if the proxy is down.if (env('USE_PROXY') && !filter_var(env('PROXY_URL'), FILTER_VALIDATE_URL)) {
throw new \RuntimeException('Proxy URL is invalid. Disabling proxy.');
}
Data Mismatches
$userData = $this->ucaOffice365->getUser($uid);
$normalizedUser = [
'id' => strtolower($userData['uid']),
'email' => strtolower($userData['email'] ?? ''),
];
Enable Verbose Logging
config/services.php to log API requests:
'uca_office365' => [
'debug' => env('APP_DEBUG', false),
],
storage/logs/laravel.log for raw API responses.Mocking for Tests
$this->mock(UCAOffice365::class)
->shouldReceive('getUser')
->once()
->andReturn(['uid' => 'test123', 'name' => 'Test User']);
API Response Inspection
$response = $this->ucaOffice365->getUser($uid);
\Log::debug('Raw API Response:', ['response' => $response]);
Custom API Endpoints
UCAOffice365 service by creating a decorator:
class ExtendedUCAOffice365 extends UCAOffice365 {
public function getCustomUserData($uid) {
$user = parent::getUser($uid);
return array_merge($user, ['custom_field' => 'value']);
}
}
config/services.php:
'uca_office365' => [
'class' => \App\Services\ExtendedUCAOffice365::class,
],
GraphAPI Integration
$events = $this->graphApi->getEvents($user['mail'], new \DateTime());
Webhook Listeners
public function handle(Office365Webhook $event) {
$this->ucaOffice365->syncUser($event->getUserId());
}
Batch Processing
$users = $this->ucaOffice365->getAllUsers();
foreach (array_chunk($users, 50) as $chunk) {
foreach ($chunk as $user) {
$this->ucaOffice365->addBooking($user['uid']);
}
}
How can I help you explore Laravel packages today?