-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathPackagesTable.php
More file actions
96 lines (83 loc) · 3.83 KB
/
PackagesTable.php
File metadata and controls
96 lines (83 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
namespace App\Model\Table;
use App\Model\Filter\PackagesCollection;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Packages Model
*
* @method \App\Model\Entity\Package newEmptyEntity()
* @method \App\Model\Entity\Package newEntity(array $data, array $options = [])
* @method array<\App\Model\Entity\Package> newEntities(array $data, array $options = [])
* @method \App\Model\Entity\Package get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\Package findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \App\Model\Entity\Package patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\App\Model\Entity\Package> patchEntities(iterable $entities, array $data, array $options = [])
* @method \App\Model\Entity\Package|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\Package saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\App\Model\Entity\Package>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Package>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\Package>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Package> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\Package>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Package>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\Package>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Package> deleteManyOrFail(iterable $entities, array $options = [])
*/
class PackagesTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('packages');
$this->setDisplayField('package');
$this->setPrimaryKey('id');
$this->addBehavior('Search.Search', [
'collectionClass' => PackagesCollection::class,
]);
$this->addBehavior('Tags.Tag', ['taggedCounter' => false]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('package')
->maxLength('package', 255)
->requirePresence('package', 'create')
->notEmptyString('package');
$validator
->scalar('description')
->requirePresence('description', 'create')
->allowEmptyString('description');
$validator
->scalar('repo_url')
->maxLength('repo_url', 255)
->requirePresence('repo_url', 'create')
->notEmptyString('repo_url');
$validator
->integer('downloads')
->requirePresence('downloads', 'create')
->notEmptyString('downloads');
$validator
->integer('stars')
->requirePresence('stars', 'create')
->notEmptyString('stars');
$validator
->scalar('latest_stable_version')
->requirePresence('latest_stable_version', 'create')
->allowEmptyString('latest_stable_version');
$validator
->date('latest_stable_release_date')
->requirePresence('latest_stable_release_date', 'create')
->allowEmptyDate('latest_stable_release_date');
return $validator;
}
}