当前位置: 首页>>代码示例>>PHP>>正文


PHP Parameters::count方法代码示例

本文整理汇总了PHP中Zend\Stdlib\Parameters::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Parameters::count方法的具体用法?PHP Parameters::count怎么用?PHP Parameters::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Stdlib\Parameters的用法示例。


在下文中一共展示了Parameters::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveItemFilePhisically

 /**
  * @param Parameters|array|bool $file
  * @param int $itemId
  * @param \DDD\Domain\Finance\Expense\Expenses $expenseData
  * @return array
  * @throws \Exception
  */
 private function saveItemFilePhisically(Parameters $file, $itemId, $expenseData)
 {
     $fileReport = [];
     if ($file->count()) {
         $file = $file->get('file');
         $expenseItemDao = new ExpenseItem($this->getServiceLocator(), '\\ArrayObject');
         $expenseId = $expenseItemDao->fetchOne(['id' => $itemId], ['expense_id'])['expense_id'];
         $expenseItemAttachmentsDao = $this->getServiceLocator()->get('dao_finance_expense_expense_item_attachments');
         $isTempItem = empty($expenseData) ? true : false;
         if ($isTempItem) {
             $path = "/ginosi/uploads/expense/items_tmp/{$itemId}/";
         } else {
             list($date, ) = explode(' ', $expenseData->getDateCreated());
             list($y, $m, $d) = explode('-', $date);
             $path = "/ginosi/uploads/expense/items/{$y}/{$m}/{$d}/{$expenseData->getId()}/{$itemId}/";
         }
         if (!is_readable($path)) {
             if (!mkdir($path, 0755, true)) {
                 throw new \Exception('Cannot create directories.');
             }
         }
         $fileName = $this->generateItemFileName($file['name'], $itemId);
         $oldInfo = $expenseItemAttachmentsDao->fetchOne(['item_id' => $itemId], ['id']);
         if ($this->isValidFile($file)) {
             if (!$isTempItem) {
                 array_map('unlink', glob($path . '*'));
             }
             if (move_uploaded_file($file['tmp_name'], $path . $fileName)) {
                 if ($oldInfo) {
                     $expenseItemAttachmentsDao->save(['filename' => $fileName, 'expense_id' => $expenseId], ['item_id' => $itemId]);
                 } else {
                     $expenseItemAttachmentsDao->save(['item_id' => $itemId, 'filename' => $fileName, 'expense_id' => $expenseId]);
                 }
                 array_push($fileReport, ['value' => $fileName, 'status' => 'success']);
             } else {
                 array_push($fileReport, ['value' => 'Cannot upload a file ' . $file['name'], 'status' => 'fail']);
             }
         } else {
             array_push($fileReport, ['value' => 'Unsupported file ' . $file['name'], 'status' => 'fail']);
         }
     }
     return $fileReport;
 }
开发者ID:arbi,项目名称:MyCode,代码行数:50,代码来源:ExpenseTicket.php

示例2: parseFromStream


//.........这里部分代码省略.........
                     }
                 }
                 if ($filename) {
                     // At this point, we can add the file entry, regardless of error condition
                     $files->set($name, $file);
                 }
             }
             // Is this a boundary end? If so, we're done
             if (preg_match($partBoundaryPatternEnd, $trimmedLine)) {
                 // Met the "end" boundary; time to stop!
                 break;
             }
             // New part to parse!
             $partInProgress = true;
             $inHeader = true;
             $headers = [];
             $header = '';
             continue;
         }
         if (!$partInProgress) {
             // We're not inside a part, so do nothing.
             continue;
         }
         if ($inHeader) {
             if (preg_match('/^\\s*$/s', $line)) {
                 // Headers are done; cleanup
                 $inHeader = false;
                 $content = '';
                 $file = ['error' => UPLOAD_ERR_OK];
                 $tmpFile = false;
                 $lastline = null;
                 // Parse headers
                 $name = $this->getNameFromHeaders($headers);
                 if (!$name) {
                     throw new Exception\InvalidMultipartContentException('Missing Content-Disposition header, or Content-Disposition header does not ' . 'contain a "name" field');
                 }
                 $filename = $this->getFilenameFromHeaders($headers);
                 $mimeType = $this->getMimeTypeFromHeaders($headers);
                 continue;
             }
             if (preg_match('/^(?P<header>[a-z]+[a-z0-9_-]+):\\s*(?P<value>.*)$/i', $trimmedLine, $matches)) {
                 $header = strtoupper($matches['header']);
                 $headers[$header] = $matches['value'];
                 continue;
             }
             if (!$header) {
                 throw new Exception\InvalidMultipartContentException('Malformed or missing MIME part header for multipart content');
             }
             $headers[$header] .= $trimmedLine;
             continue;
         }
         // In the body content...
         // Data only; aggregate.
         if (!$filename) {
             $content .= $line;
             continue;
         }
         // If we've had an error already with the upload, continue parsing
         // to the end of the MIME part
         if ($file['error'] !== UPLOAD_ERR_OK) {
             continue;
         }
         // Create a temporary file handle if we haven't already
         if (!$tmpFile) {
             // Sets the file entry
             $file['name'] = $filename;
             $file['type'] = $mimeType;
             $tmpDir = $this->getUploadTempDir();
             if (empty($tmpDir)) {
                 // Cannot ascertain temporary directory; this is an error
                 $file['error'] = UPLOAD_ERR_NO_TMP_DIR;
                 continue;
             }
             $file['tmp_name'] = tempnam($tmpDir, 'zfc');
             $tmpFile = fopen($file['tmp_name'], 'wb');
             if (false === $tmpFile) {
                 // Cannot open the temporary file for writing; this is an error
                 $file['error'] = UPLOAD_ERR_CANT_WRITE;
                 continue;
             }
         }
         // Off-by-one operation. Last line must be trimmed, so we'll write
         // the lines one iteration behind.
         if (null === $lastline) {
             $lastline = $line;
             continue;
         }
         if (false === fwrite($tmpFile, $lastline)) {
             $file['error'] = UPLOAD_ERR_CANT_WRITE;
             fclose($tmpFile);
             continue;
         }
         $lastline = $line;
     }
     fclose($stream);
     if ($files->count()) {
         $this->request->setFiles($files);
     }
     return $data->toArray();
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:101,代码来源:MultipartContentParser.php


注:本文中的Zend\Stdlib\Parameters::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。