Subject.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace fphammerle\yii2\auth\clientcert;
  3. class Subject extends \yii\db\ActiveRecord
  4. {
  5. public static function tableName()
  6. {
  7. return 'identity_cert_subject';
  8. }
  9. public function __construct($dn = null)
  10. {
  11. $this->distinguished_name = $dn;
  12. }
  13. public function rules()
  14. {
  15. return [
  16. [['distinguished_name'], 'required'],
  17. [['distinguished_name'], 'string'],
  18. [['distinguished_name'], 'unique'],
  19. ];
  20. }
  21. // public function getIdentityId()
  22. // {
  23. // return $this->identity_id;
  24. // }
  25. public static function getIdentityClass()
  26. {
  27. return \Yii::$app->user->identityClass;
  28. }
  29. /**
  30. * @return \yii\db\TableSchema
  31. */
  32. public static function getIdentityTableSchema()
  33. {
  34. $cls = Subject::getIdentityClass();
  35. return (new $cls)->getTableSchema();
  36. }
  37. /**
  38. * @return \yii\db\ColumnSchema
  39. */
  40. public static function getIdentityIdSchema()
  41. {
  42. $keys = array_filter(
  43. self::getIdentityTableSchema()->columns,
  44. function($c) { return $c->isPrimaryKey; }
  45. );
  46. assert(sizeof($keys) == 1);
  47. return array_pop($keys);
  48. }
  49. // public function getIdentity()
  50. // {
  51. // return $this->hasOne(self::getIdentityClass(), ['id' => 'identity_id']);
  52. // }
  53. }