SluggableBehavior.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Behavior for binding management.
  5. *
  6. * Behavior to simplify manipulating a model's bindings when doing a find operation
  7. *
  8. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  9. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. *
  11. * Licensed under The MIT License
  12. * For full copyright and license information, please see the LICENSE.txt
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  16. * @link https://cakephp.org CakePHP(tm) Project
  17. * @since 1.2.0
  18. * @license https://opensource.org/licenses/mit-license.php MIT License
  19. */
  20. namespace TestApp\Model\Behavior;
  21. use Cake\Event\EventInterface;
  22. use Cake\ORM\Behavior;
  23. use Cake\ORM\Query;
  24. use Cake\Utility\Text;
  25. class SluggableBehavior extends Behavior
  26. {
  27. public function beforeFind(EventInterface $event, Query $query, $options = []): Query
  28. {
  29. $query->where(['slug' => 'test']);
  30. return $query;
  31. }
  32. public function findNoSlug(Query $query, array $options = []): Query
  33. {
  34. $query->where(['slug IS' => null]);
  35. return $query;
  36. }
  37. public function slugify(string $value): string
  38. {
  39. return Text::slug($value);
  40. }
  41. public function camelCase(): string
  42. {
  43. return 'camelCase';
  44. }
  45. }