vendor/pec-platform/search-bundle/Entity/SolrDocument.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  *
  5.  * This file is part of the PEC Platform SearchBundle.
  6.  *
  7.  * (c) PEC project engineers & consultants
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Pec\Bundle\SearchBundle\Entity;
  13. @trigger_error('Please use \StingerSoft\EntitySearchBundle\Model\Document'E_USER_DEPRECATED);
  14. /**
  15.  * POPO to encapsulated properties and fields to be indexed
  16.  * @deprecated
  17.  */
  18. class SolrDocument {
  19.     /**
  20.      * Key of the solr field <em>title</em>
  21.      * @var string
  22.      */
  23.     const FIELD_TITLE 'title';
  24.     /**
  25.      * Key of the solr field <em>content</em>
  26.      * @var string
  27.      */
  28.     const FIELD_CONTENT 'content';
  29.     /**
  30.      * Key of the solr field <em>last_modified</em>
  31.      * @var string
  32.      */
  33.     const FIELD_LAST_MODIFIED 'last_modified';
  34.     /**
  35.      * Key of the solr field <em>author</em>
  36.      * @var string
  37.      */
  38.     const FIELD_AUTHOR 'author';
  39.     /**
  40.      * Key of the solr field <em>keywords</em>
  41.      * @var string
  42.      */
  43.     const FIELD_KEYWORDS 'keywords';
  44.     /**
  45.      * Key of the solr field <em>roles</em>
  46.      * @var string
  47.      */
  48.     const FIELD_ROLES 'roles';
  49.     /**
  50.      * Key of the solr field <em>editors</em>
  51.      * @var string
  52.      */
  53.     const FIELD_EDITORS 'editors';
  54.     /**
  55.      * Key of the solr field <em>deleted_at</em>
  56.      * @var string
  57.      */
  58.     const FIELD_DELETED_AT 'deleted_at';
  59.     /**
  60.      * Stores are fields with their values which should be stored in the solr index
  61.      * @var array
  62.      */
  63.     protected $fields = array();
  64.     /**
  65.      * Adds a field and its value to the index
  66.      * @param string $fieldname
  67.      * @param mixed $value
  68.      */
  69.     public function addField($fieldname$value) {
  70.         $this->fields[$fieldname] = $this->failSafeValue($value);
  71.     }
  72.     /**
  73.      * Returns all fields and values which should be stored in the solr index
  74.      */
  75.     public function getFields() {
  76.         return $this->fields;
  77.     }
  78.     /**
  79.      * Adds an editor to the field set
  80.      * @param string $editor
  81.      */
  82.     public function addEditor($editor) {
  83.         $this->addMultiValueField(self::FIELD_EDITORS$editor);
  84.     }
  85.     /**
  86.      * Adds a role to the field set
  87.      * @param string $role
  88.      */
  89.     public function addRole($role) {
  90.         $this->addMultiValueField(self::FIELD_ROLES$role);
  91.     }
  92.     /**
  93.      * Adds a value to a field without deleting the already existing values
  94.      * @param string $field
  95.      * @param string $value
  96.      */
  97.     public function addMultiValueField($field$value) {
  98.         if(!array_key_exists($field$this->fields)) {
  99.             $this->fields[$field] = array(
  100.                 $this->failSafeValue($value)
  101.             );
  102.         } else if(!in_array($value$this->fields[$field])) {
  103.             $this->fields[$field][] = $this->failSafeValue($value);
  104.         }
  105.     }
  106.     protected function failSafeValue($value) {
  107.         if(is_string($value)) {
  108.             return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@'' '$value);
  109.         }
  110.         return $value;
  111.     }
  112. }