Advertisement
Guest User

Untitled

a guest
Apr 19th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. namespace App\Model\Table;
  5.  
  6. use Cake\ORM\Query;
  7. use Cake\ORM\RulesChecker;
  8. use Cake\ORM\Table;
  9. use Cake\Validation\Validator;
  10.  
  11. /**
  12. * Users Model
  13. *
  14. * @method \App\Model\Entity\User newEmptyEntity()
  15. * @method \App\Model\Entity\User newEntity(array $data, array $options = [])
  16. * @method \App\Model\Entity\User[] newEntities(array $data, array $options = [])
  17. * @method \App\Model\Entity\User get($primaryKey, $options = [])
  18. * @method \App\Model\Entity\User findOrCreate($search, ?callable $callback = null, $options = [])
  19. * @method \App\Model\Entity\User patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
  20. * @method \App\Model\Entity\User[] patchEntities(iterable $entities, array $data, array $options = [])
  21. * @method \App\Model\Entity\User|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
  22. * @method \App\Model\Entity\User saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
  23. * @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = [])
  24. * @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = [])
  25. * @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = [])
  26. * @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = [])
  27. *
  28. * @mixin \Cake\ORM\Behavior\TimestampBehavior
  29. */
  30. class UsersTable extends Table
  31. {
  32. /**
  33. * Initialize method
  34. *
  35. * @param array $config The configuration for the Table.
  36. * @return void
  37. */
  38. public function initialize(array $config): void
  39. {
  40. parent::initialize($config);
  41.  
  42. $this->setTable('users');
  43. $this->setDisplayField('id');
  44. $this->setPrimaryKey('id');
  45.  
  46. $this->addBehavior('Timestamp');
  47. }
  48.  
  49. /**
  50. * Default validation rules.
  51. *
  52. * @param \Cake\Validation\Validator $validator Validator instance.
  53. * @return \Cake\Validation\Validator
  54. */
  55. public function validationDefault(Validator $validator): Validator
  56. {
  57. $validator
  58. ->integer('id')
  59. ->allowEmptyString('id', null, 'create');
  60.  
  61. $validator
  62. ->email('email')
  63. ->requirePresence('email', 'create')
  64. ->notEmptyString('email');
  65.  
  66. $validator
  67. ->scalar('password')
  68. ->maxLength('password', 255)
  69. ->requirePresence('password', 'create')
  70. ->notEmptyString('password');
  71.  
  72. return $validator;
  73. }
  74.  
  75. /**
  76. * Returns a rules checker object that will be used for validating
  77. * application integrity.
  78. *
  79. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
  80. * @return \Cake\ORM\RulesChecker
  81. */
  82. public function buildRules(RulesChecker $rules): RulesChecker
  83. {
  84. $rules->add($rules->isUnique(['email']));
  85. return $rules;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement