Git Product home page Git Product logo

Comments (17)

samdark avatar samdark commented on June 20, 2024

@dynasource, @cebe, @klimov-paul, @SilverFire thoughts?

from yii-core.

klimov-paul avatar klimov-paul commented on June 20, 2024

Such change seems to be logical, but it make implementation more complicated.

Keep in mind that identity is bound to yii\web\User. There is a single property yii\web\User::$identityClass at the moment. Spliting IdentityInterface into several ones will also make yii\web\User to be more complex.

Current Identity finding methods findIdentity() and findIdentityByAccessToken() are static. Thier notation was inspired by ActiveRecord paradigm.
Extracting IndentityRepositoryInterface with static methods looks odd - those methods should not be static then: identity repository should be an instance, which finds instances of identity. Such change eliminates the ability of usage same ActiveRecord class for IdentityInterface and IndentityRepositoryInterface.

Keeping 'find' methods as static already allows you to create separated implementation for finding - it just need to be encapsulated in those static methods of Identity class.

I am against such change.

from yii-core.

samdark avatar samdark commented on June 20, 2024

Keeping 'find' methods as static already allows you to create separated implementation for finding - it just need to be encapsulated in those static methods of Identity class.

It will be in the same class. Thus not separate.

from yii-core.

klimov-paul avatar klimov-paul commented on June 20, 2024

It will be in the same class. Thus not separate.

class MyIdentity implements IdentityInterface
{
    // ....

    public static function findIdentity($id)
    {
        return Yii::$app->identityRepository->find($id);
    }
}

from yii-core.

dynasource avatar dynasource commented on June 20, 2024

I'm positive applying the interface-segregation principle. In the end this will result to less complex code which is more flexible and easier to extend.

from yii-core.

samdark avatar samdark commented on June 20, 2024

@klimov-paul right but that's adding intermediate class. Feels hacky. I understand your concerns about complicating yii\web\User though...

from yii-core.

samdark avatar samdark commented on June 20, 2024

I need to actually attempt it to say if it's possible to do it w/o much hassle.

from yii-core.

SilverFire avatar SilverFire commented on June 20, 2024

I'm all for it.

from yii-core.

lynicidn avatar lynicidn commented on June 20, 2024

Разделять надо, т.к. IdentityInterface не должен уметь и находить и быть идентификацией, но репозитори интерфейс не нужен со статикой, его надо вынести в yii\web\User::findIdentity (там есть identityClass)

from yii-core.

lynicidn avatar lynicidn commented on June 20, 2024

http://slides.rmcreative.ru/2016/yii2-architecture/#/26 =)

from yii-core.

samdark avatar samdark commented on June 20, 2024

@lynicidn please use English in discussions which are conducted using English. Thanks.

from yii-core.

lynicidn avatar lynicidn commented on June 20, 2024

@samdark ok, sorry, no problem, wait pr, may be i have wrong opinion

from yii-core.

SamMousa avatar SamMousa commented on June 20, 2024

This makes sense to me as well.
Note that yii\web\User::$identityClass would then become yii\web\User::$identityRepository.
It no longer needs to know the class for an identity.

The parameter would accept an object or a configuration array or closure (as normal for Yii).
A basic ActiveRecordUserRepository could be implemented and provided with core, configuration would then become:

'components' => [
    'user' => [
        'identityRepository' => [
            'modelClass' => 'app\models\User'
        ]

Note that the user component would have a default configuration for its repository which contains:

['class' => 'yii\db\ActiveRecordUserRepository']

from yii-core.

vercotux avatar vercotux commented on June 20, 2024

While at it, would it be possible to add another method to the new IdentityInterface: something that produces a human-readable string of the underlying identity (such as getName(), getUsername() or getLabel())? It makes sense to me at least. What else is an identity if not an abstraction of a person, and as far as I know all humans come with a name.

I guess the reason why it was originally omitted is things like oauth where you don't necessarily obtain a string name? Maybe introduce as separate identity (e.g. HumanIdentityInterface) instead? Just something to consider.

from yii-core.

samdark avatar samdark commented on June 20, 2024

Identity doesn't necessary represent a human. It could be API client or another project or a service.

from yii-core.

samdark avatar samdark commented on June 20, 2024

yiisoft/yii-web#101

from yii-core.

samdark avatar samdark commented on June 20, 2024

Closing since the implementation has it split.

from yii-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.