Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:20:26+00:00 2026-06-15T02:20:26+00:00

I am currently looking a this piece of code from a module called ZfcUser

  • 0

I am currently looking a this piece of code from a module called ZfcUser for Zend 2:

namespace ZfcUser\Controller;

use Zend\Form\Form;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\ResponseInterface as Response;
use Zend\Stdlib\Parameters;
use Zend\View\Model\ViewModel;
use ZfcUser\Service\User as UserService;
use ZfcUser\Options\UserControllerOptionsInterface;

class UserController extends AbstractActionController
{
/**
 * @var UserService
 */
protected $userService;
     .
     .

public function indexAction()
{
    if (!$this->zfcUserAuthentication()->hasIdentity()) {
        return $this->redirect()->toRoute('zfcuser/login');
    }
    return new ViewModel();
}
    .
    .
}

In the namespace ZfcUser\Controller\Plugin:

namespace ZfcUser\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
use ZfcUser\Authentication\Adapter\AdapterChain as AuthAdapter;

class ZfcUserAuthentication extends AbstractPlugin implements ServiceManagerAwareInterface
{
/**
 * @var AuthAdapter
 */
protected $authAdapter;
    .
    .
/**
 * Proxy convenience method
 *
 * @return mixed
 */
public function hasIdentity()
{
    return $this->getAuthService()->hasIdentity();
}
/**
 * Get authService.
 *
 * @return AuthenticationService
 */
public function getAuthService()
{
    if (null === $this->authService) {
        $this->authService = $this->getServiceManager()->get('zfcuser_auth_service');
    }
    return $this->authService;
}

My Questions:

  • From indexAction(), the controller plugin is called without being instantiated ($this->zfcUserAuthentication()->hasIdentity()), do controller plugins always work like this?.
  • What really happens in the hasIdentity()? I see getAuthService() returning something but not hasIdentity().I am not familiar with this type of advanced class implementation of function calling so I would truly appreciate any explanation here or topic I should look into.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:20:27+00:00Added an answer on June 15, 2026 at 2:20 am

    I can’t answer your first question, but regarding your second question:

    The getAuthService() method in your code returns an AuthenticationService object, which has a hasIdentity() method.

    So there are two different hasIdentity() methods:

    • In the AuthenticationService class (source code here).
    • In the ZfcUserAuthentication class which you’re looking at.

    This line of code in the ZfcUserAuthentication class:

    return $this->getAuthService()->hasIdentity();
    

    does three things:

    • $this->getAuthService() returns an AuthenticationService object.
    • The hasIdentity() method of that AuthenticationService object is then called, and it returns a boolean.
    • That boolean is then returned.

    Imagine splitting the code into two parts:

    // Get AuthenticationService object     Call a method of that object
    $this->getAuthService()                 ->hasIdentity();
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to speed up this Magento code? Currently it is looking
This piece of code takes a row from 1.txt and splits it into columns.
There's a piece of code I'm currently looking like which serialises/deserialises data. The class
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Okay I'm looking for some input, I'm pretty sure this is not currently supported
I am currently looking for a way to remove fullstops from a string in
I'm currently creating a plugin system (My first attempt), looking at other peoples code
I am currently working on the maintenance of a piece of code that is
I have this model called Post, idaelly I would love to use just ONE
I currently have a Python 2.6 piece of code that runs two loops simultaneously.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.