user9099802
user9099802

Reputation: 253

Symfony The autoloader expected class

I start in symfony and php, and I try to call a function like this :

$login = Piwik::getCurrentUserLogin();

For that, I have to call a namespace I think.

When I do that Symfony it puts me this error:

The autoloader expected class "Etiam\Nexus\Communication\ChatBundle\Controller\AuthenticationController" to be defined in file "/home/star/workspace/nexus/trunk/production/symfony/vendor/composer/../../src/Etiam/Nexus/Communication/ChatBundle/Controller/AuthenticationController.php". The file was found but the class was not in it, the class name or namespace probably has a typo. (500 Internal Server Error)

Here is my class:

<?php

namespace Etiam\Nexus\Communication\ChatBundle\Controller;
namespace Piwik\Piwik;

use Etiam\Nexus\UserBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Piwik\Piwik;

class AuthenticationController extends Controller
{
  public function postCheckCredentialsAction(Request $request)
  {
    $arAuthRequest = json_decode($request->getContent(), true);

    $userUid = $arAuthRequest['user']['id'];
    $userPwd = $arAuthRequest['user']['password'];

    $directoryService = $this->get('etiam_nexus_directory.service.directory');

    $loginPattern = '/^@(.*):.*$/';
    preg_match_all($loginPattern, $userUid, $arUserIds);

    $user = $directoryService->getUser(
        $directoryService->getLocalEstablishment(),
        $arUserIds[1]
    );

    $login = Piwik::getCurrentUserLogin();
  }

////////////////UPDATE//////////////////:

The new error :

Attempted to load class "Piwik" from namespace "Piwik". Did you forget a "use" statement for another namespace? (500 Internal Server Error)

My class :

<?php
/**
* Created by PhpStorm.
* User: floriane
* Date: 26/12/17
* Time: 15:49
*/

namespace Etiam\Nexus\Communication\ChatBundle\Controller;

use Etiam\Nexus\UserBundle\Entity\User;
use Piwik\Piwik; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class AuthenticationController extends Controller
{
   public function postCheckCredentialsAction(Request $request)
   {
    $arAuthRequest = json_decode($request->getContent(), true);

    $userUid = $arAuthRequest['user']['id'];
    $userPwd = $arAuthRequest['user']['password'];

    $directoryService = $this->get('etiam_nexus_directory.service.directory');

    $loginPattern = '/^@(.*):.*$/';
    preg_match_all($loginPattern, $userUid, $arUserIds);

    $user = $directoryService->getUser(
        $directoryService->getLocalEstablishment(),
        $arUserIds[1]
    );

      $login = Piwik::getCurrentUserLogin();

    if (!$user instanceof User) {
        return JsonResponse::create(
            array(
                'auth' => array(
                    'success' => false,
                    'mxid' => $userUid
                )
            )
        );
    }

    return JsonResponse::create(
        array(
            'auth' => array(
                'success' => true,
                'mxid' => $userUid,
                'profile' => array(
                    'display_name' => $user->getUserFullName(),
                    'three_pids' => array(
                        array(
                            'medium' => 'email',
                            'address' =>$user->getUseruniqname()
                        ),
                        array(
                            'medium' => 'msisdn',
                            'address' => $user->getPhonenumber()
                        )
                    )
                )
            )
        )
    );
}
}

Upvotes: 1

Views: 871

Answers (1)

svgrafov
svgrafov

Reputation: 2014

You should pick correct namespace for your class.
Remove namespace Piwik\Piwik;

That line basically means that you put your class in Piwik\Piwik namespace, which is not what you want.

Upvotes: 2

Related Questions