PHP code example of k3progetti / microsoft-bundle

1. Go to this page and download the library: Download k3progetti/microsoft-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

k3progetti / microsoft-bundle example snippets


return [
    // ...
    K3Progetti\MicrosoftBundle\MicrosoftBundle::class => ['all' => true],
];

use K3Progetti\MicrosoftBundle\Contract\UserInterface as MicrosoftUserInterface;

class User implements MicrosoftUserInterface
{
    public function getId(): mixed { ... }
    public function setUsername(string $username): static { ... }
    public function setEmail(string $email): static { ... }
    public function setActive(bool $active): static { ... }
    public function setPassword(string $password): static { ... }
    public function setSurname(?string $surname): static { ... }
    public function setName(?string $name): static { ... }
    public function setPhone(?string $phone): static { ... }
    public function setRoles(array $roles): static { ... }
}

use K3Progetti\MicrosoftBundle\Service\MicrosoftService;

class MyService
{
    public function __construct(private MicrosoftService $microsoftService) {}

    public function example(): void
    {
        // Recupera tutti gli utenti
        $users = $this->microsoftService->getAllUsers();

        // Recupera i membri di un gruppo
        $members = $this->microsoftService->getUsersByGroupId('group-id');

        // Recupera tutti i gruppi di sicurezza
        $groups = $this->microsoftService->getAllGroups(security: true);

        // Recupera le email di un utente (di default le prime 50)
        $messages = $this->microsoftService->getMessages('[email protected]', top: 50);

        // Lista degli allegati di un messaggio (senza contenuto)
        $attachments = $this->microsoftService->getMessageAttachments('[email protected]', $messageId);

        // Scarica un singolo allegato (contenuto in base64 nel campo contentBytes)
        $attachment = $this->microsoftService->getMessageAttachment('[email protected]', $messageId, $attachmentId);

        // Scarica il messaggio completo in formato MIME (.eml)
        $eml = $this->microsoftService->getMessageMime('[email protected]', $messageId);

        // Segna un messaggio come letto / non letto
        $this->microsoftService->updateMessageStatusRead('[email protected]', $messageId, true);

        // Imposta le categorie di un messaggio (null o [] per rimuoverle)
        $this->microsoftService->updateMessageCategory('[email protected]', $messageId, ['Fatture', 'Urgente']);

        // Elimina un'email
        $this->microsoftService->deleteEmail('[email protected]', $messageId);

        // Credenziali dinamiche (override della configurazione globale)
        $this->microsoftService
            ->withCredentials($clientId, $tenantId, $clientSecret)
            ->getAllUsers();
    }
}

MicrosoftBundle/
├── src/
│   ├── MicrosoftBundle.php
│   ├── Command/
│   │   ├── GetAllUsersCommand.php
│   │   ├── GetAllDisabledUsersCommand.php
│   │   └── GetAllGroupsCommand.php
│   ├── Contract/
│   │   └── UserInterface.php
│   ├── Controller/
│   │   └── AuthController.php
│   ├── DependencyInjection/
│   │   ├── MicrosoftConfiguration.php
│   │   └── MicrosoftExtension.php
│   ├── Entity/
│   │   ├── MicrosoftUser.php
│   │   ├── MicrosoftGroup.php
│   │   └── MicrosoftGroupUser.php
│   ├── Repository/
│   │   ├── MicrosoftUserRepository.php
│   │   ├── MicrosoftGroupRepository.php
│   │   └── MicrosoftGroupUserRepository.php
│   └── Service/
│       └── MicrosoftService.php