當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Document::addFile方法代碼示例

本文整理匯總了PHP中Elastica\Document::addFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP Document::addFile方法的具體用法?PHP Document::addFile怎麽用?PHP Document::addFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Elastica\Document的用法示例。


在下文中一共展示了Document::addFile方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: transform

 /**
  * Transforms an object into an elastica object having the required keys
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  *
  * @return Document
  **/
 public function transform($object, array $fields)
 {
     $identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $key);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     return $document;
 }
開發者ID:benstinton,項目名稱:FOSElasticaBundle,代碼行數:40,代碼來源:ModelToElasticaAutoTransformer.php

示例2: testAddFile

 /**
  * @group unit
  */
 public function testAddFile()
 {
     $fileName = '/dev/null';
     if (!file_exists($fileName)) {
         $this->markTestSkipped("File {$fileName} does not exist.");
     }
     $doc = new Document();
     $returnValue = $doc->addFile('key', $fileName);
     $this->assertInstanceOf('Elastica\\Document', $returnValue);
 }
開發者ID:MediaWiki-stable,項目名稱:1.26.1,代碼行數:13,代碼來源:DocumentTest.php

示例3: testExcludeFileSource

 public function testExcludeFileSource()
 {
     $indexMapping = array('file' => array('type' => 'attachment', 'store' => 'yes'), 'text' => array('type' => 'string', 'store' => 'yes'), 'title' => array('type' => 'string', 'store' => 'yes'));
     $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0));
     $index = $this->_createIndex();
     $type = new Type($index, 'content');
     $mapping = Mapping::create($indexMapping);
     $mapping->setSource(array('excludes' => array('file')));
     $mapping->setType($type);
     $index->create($indexParams, true);
     $type->setMapping($mapping);
     $docId = 1;
     $text = 'Basel World';
     $title = 'No Title';
     $doc1 = new Document($docId);
     $doc1->addFile('file', BASE_PATH . '/data/test.docx');
     $doc1->set('text', $text);
     $doc1->set('title', $title);
     $type->addDocument($doc1);
     // Optimization necessary, as otherwise source still in realtime get
     $index->optimize();
     $data = $type->getDocument($docId)->getData();
     $this->assertEquals($data['title'], $title);
     $this->assertEquals($data['text'], $text);
     $this->assertFalse(isset($data['file']));
 }
開發者ID:kskod,項目名稱:Elastica,代碼行數:26,代碼來源:IndexTest.php

示例4: testAddFile

 public function testAddFile()
 {
     $doc = new Document();
     $returnValue = $doc->addFile('key', '/dev/null');
     $this->assertInstanceOf('Elastica\\Document', $returnValue);
 }
開發者ID:kskod,項目名稱:Elastica,代碼行數:6,代碼來源:DocumentTest.php

示例5: transformObjectToDocument

 /**
  * Transforms the given object to an elastica document
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  * @param string $identifier the identifier for the new document
  * @return Document
  */
 protected function transformObjectToDocument($object, array $fields, $identifier = '')
 {
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $path = isset($mapping['property_path']) ? $mapping['property_path'] : $key;
         if (false === $path) {
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $path);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     if ($this->dispatcher) {
         $event = new TransformEvent($document, $fields, $object);
         $this->dispatcher->dispatch(TransformEvent::POST_TRANSFORM, $event);
         $document = $event->getDocument();
     }
     return $document;
 }
開發者ID:anteros,項目名稱:FOSElasticaBundle,代碼行數:48,代碼來源:ModelToElasticaAutoTransformer.php


注:本文中的Elastica\Document::addFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。