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


PHP SplFileObject::setFlags方法代码示例

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


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

示例1: __construct

 /**
  * @param \SplFileObject $file
  * @param string         $delimiter
  * @param string         $enclosure
  * @param string         $escape
  */
 public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = '"', $escape = '\\')
 {
     ini_set('auto_detect_line_endings', true);
     $this->file = $file;
     $this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE);
     $this->file->setCsvControl($delimiter, $enclosure, $escape);
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:13,代码来源:CsvReader.php

示例2: insert

 public function insert($file, array $callback, $scan_info)
 {
     $class = $callback[0];
     $method = $callback[1];
     $class = Model::factory($class);
     $this->_handle = fopen($file, 'r');
     $headers = fgetcsv($this->_handle, $file);
     $scan_data = array();
     $file = new SplFileObject($file);
     $file->setFlags(SplFileObject::SKIP_EMPTY);
     $file->setFlags(SplFileObject::READ_AHEAD);
     $file->setFlags(SplFileObject::READ_CSV);
     $file->setCsvControl(",", '"', "\"");
     $c = 0;
     foreach ($file as $row) {
         $c++;
         if (count($row) === count($headers)) {
             $scan_data[] = array_combine($headers, $row);
             $row = array();
         }
         if ($c % $this->insert_threshold == 0) {
             Logger::msg('info', array('message' => 'flushing ' . $this->insert_threshold . ' rows', "class" => $callback[0], "method" => $callback[1], 'rows_inserted' => $c));
             Logger::msg('info', array('memory_usage' => $this->file_size(memory_get_usage())));
             $flush = $class->{$method}($scan_data, $scan_info);
             $scan_data = array();
         }
     }
     $flush = $class->{$method}($scan_data, $scan_info);
     $scan_data = array();
     Logger::msg('info', array('memory_usage' => $this->file_size(memory_get_usage())));
     return $c;
 }
开发者ID:pombredanne,项目名称:vulnDB,代码行数:32,代码来源:csv.php

示例3: openFile

 /**
  * @inheritDoc
  */
 public function openFile($filePath = "/", $openMode = "a+")
 {
     try {
         $this->file = new \SplFileObject($filePath, $openMode);
         $this->file->setFlags(\SplFileObject::READ_AHEAD);
         $this->file->setFlags(\SplFileObject::SKIP_EMPTY);
     } catch (\Exception $e) {
         throw new FileException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:stedop,项目名称:playground-framework,代码行数:13,代码来源:BasicFileHandler.php

示例4: getFile

 /**
  * @return \SplFileObject
  */
 protected function getFile()
 {
     if (!$this->file instanceof \SplFileObject) {
         $this->file = $this->fileInfo->openFile();
         $this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE);
         $this->file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
         if ($this->firstLineIsHeader && !$this->header) {
             $this->header = $this->file->fgetcsv();
         }
     }
     return $this->file;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:15,代码来源:CsvFileReader.php

示例5: __construct

 public function __construct($fileName)
 {
     parent::__construct();
     $this->fileName = $fileName;
     try {
         $this->fileHandle = new \SplFileObject($fileName, 'c+');
         $this->fileHandle->setFlags(\SplFileObject::READ_CSV);
         $this->fileHandle->setCsvControl(self::CSV_DELIMITER, self::CSV_SEPARATOR);
     } catch (\Exception $exception) {
         throw new PinqException('Invalid cache file: %s is not readable with the message, "%s"', $fileName, $exception->getMessage());
     }
     $this->fileName = $fileName;
 }
开发者ID:timetoogo,项目名称:pinq,代码行数:13,代码来源:CSVFileCache.php

示例6: readRecords

 /**
  * Reads csv records
  *
  * @param string $fileName
  * @param int $position
  * @param int $step
  * @return array
  * @throws \Exception
  */
 public function readRecords($fileName, $position, $step)
 {
     $tempFileName = '';
     if (file_exists($fileName)) {
         $tempFileName = $this->uploadPathProvider->getRealPath(md5(microtime() . '.csv'));
         file_put_contents($tempFileName, file_get_contents($fileName));
         $fileName = $tempFileName;
     }
     $file = new \SplFileObject($fileName);
     $file->setCsvControl(";", '"');
     $file->setFlags(\SplFileObject::READ_CSV);
     $columnNames = $this->getColumnNames($file);
     //moves the file pointer to a certain line
     // +1 to ignore the first line of the file
     $file->seek($position + 1);
     $readRows = [];
     $data = [];
     for ($i = 1; $i <= $step; $i++) {
         $row = $file->current();
         if ($this->isInvalidRecord($row)) {
             break;
         }
         foreach ($columnNames as $key => $name) {
             $data[$name] = isset($row[$key]) ? $row[$key] : '';
         }
         $readRows[] = $data;
         // Move the pointer to the next line
         $file->next();
     }
     unlink($tempFileName);
     return $this->toUtf8($readRows);
 }
开发者ID:shopwareLabs,项目名称:SwagImportExport,代码行数:41,代码来源:CsvFileReader.php

示例7: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             continue;
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:32,代码来源:CsvFileLoader.php

示例8: buildQuadTree

function buildQuadTree($filename)
{
    //  Set the centrepoint of our QuadTree at 0.0 Longitude, 0.0 Latitude
    $centrePoint = new \QuadTrees\QuadTreeXYPoint(0.0, 0.0);
    //  Set the bounding box to the entire globe
    $quadTreeBoundingBox = new \QuadTrees\QuadTreeBoundingBox($centrePoint, 360, 180);
    //  Create our QuadTree
    $quadTree = new \QuadTrees\QuadTree($quadTreeBoundingBox);
    echo "Loading cities: ";
    $cityFile = new \SplFileObject($filename);
    $cityFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
    //  Populate our new QuadTree with cities from around the world
    $cityCount = 0;
    foreach ($cityFile as $cityData) {
        if (!empty($cityData[0])) {
            if ($cityCount % 1000 == 0) {
                echo '.';
            }
            $city = new cityPoint($cityData[0], $cityData[1], $cityData[3], $cityData[2]);
            $quadTree->insert($city);
            ++$cityCount;
        }
    }
    echo PHP_EOL, "Added {$cityCount} cities to QuadTree", PHP_EOL;
    return $quadTree;
}
开发者ID:markbaker,项目名称:quadtrees,代码行数:26,代码来源:citySearch.php

示例9: loadResource

 /**
  * {@inheritdoc}
  */
 protected function loadResource($resource)
 {
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if (substr($data[0], 0, 1) === '#') {
             continue;
         }
         if (!isset($data[1])) {
             continue;
         }
         if (count($data) == 2) {
             $messages[$data[0]] = $data[1];
         } else {
             continue;
         }
     }
     return $messages;
 }
开发者ID:niyomja,项目名称:laravel_redis,代码行数:28,代码来源:CsvFileLoader.php

示例10: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $messages = array();
     try {
         $file = new \SplFileObject($resource, 'rb');
     } catch (\RuntimeException $e) {
         throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
     }
     $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     foreach ($file as $data) {
         if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
             $messages[$data[0]] = $data[1];
         }
     }
     $catalogue = parent::load($messages, $locale, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:30,代码来源:CsvFileLoader.php

示例11: read

 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->csv) {
         if (mime_content_type($this->filePath) === 'application/zip') {
             $this->extractZipArchive();
         }
         $this->csv = new \SplFileObject($this->filePath);
         $this->csv->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
         $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
         $this->fieldNames = $this->csv->fgetcsv();
     }
     $data = $this->csv->fgetcsv();
     if (false !== $data) {
         if ($data === array(null) || $data === null) {
             return null;
         }
         if ($this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read');
         }
         if (count($this->fieldNames) !== count($data)) {
             throw new InvalidItemException('pim_base_connector.steps.csv_reader.invalid_item_columns_count', $data, array('%totalColumnsCount%' => count($this->fieldNames), '%itemColumnsCount%' => count($data), '%csvPath%' => $this->csv->getRealPath(), '%lineno%' => $this->csv->key()));
         }
         $data = array_combine($this->fieldNames, $data);
     } else {
         throw new \RuntimeException('An error occured while reading the csv.');
     }
     return $data;
 }
开发者ID:NoelCamille,项目名称:pim-community-dev,代码行数:31,代码来源:CsvReader.php

示例12: exportedFileOfShouldContain

 /**
  * @param string       $code
  * @param PyStringNode $csv
  *
  * @Then /^exported file of "([^"]*)" should contain:$/
  *
  * @throws ExpectationException
  * @throws \Exception
  */
 public function exportedFileOfShouldContain($code, PyStringNode $csv)
 {
     $config = $this->getFixturesContext()->getJobInstance($code)->getRawConfiguration();
     $path = $this->getMainContext()->getSubcontext('job')->getJobInstancePath($code);
     if (!is_file($path)) {
         throw $this->getMainContext()->createExpectationException(sprintf('File "%s" doesn\'t exist', $path));
     }
     $delimiter = isset($config['delimiter']) ? $config['delimiter'] : ';';
     $enclosure = isset($config['enclosure']) ? $config['enclosure'] : '"';
     $escape = isset($config['escape']) ? $config['escape'] : '\\';
     $csvFile = new \SplFileObject($path);
     $csvFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
     $csvFile->setCsvControl($delimiter, $enclosure, $escape);
     $expectedLines = [];
     foreach ($csv->getLines() as $line) {
         if (!empty($line)) {
             $expectedLines[] = explode($delimiter, str_replace($enclosure, '', $line));
         }
     }
     $actualLines = [];
     while ($data = $csvFile->fgetcsv()) {
         if (!empty($data)) {
             $actualLines[] = array_map(function ($item) use($enclosure) {
                 return str_replace($enclosure, '', $item);
             }, $data);
         }
     }
     $expectedCount = count($expectedLines);
     $actualCount = count($actualLines);
     assertSame($expectedCount, $actualCount, sprintf('Expecting to see %d rows, found %d', $expectedCount, $actualCount));
     if (md5(json_encode($actualLines[0])) !== md5(json_encode($expectedLines[0]))) {
         throw new \Exception(sprintf('Header in the file %s does not match expected one: %s', $path, implode(' | ', $actualLines[0])));
     }
     unset($actualLines[0]);
     unset($expectedLines[0]);
     foreach ($expectedLines as $expectedLine) {
         $originalExpectedLine = $expectedLine;
         $found = false;
         foreach ($actualLines as $index => $actualLine) {
             // Order of columns is not ensured
             // Sorting the line values allows to have two identical lines
             // with values in different orders
             sort($expectedLine);
             sort($actualLine);
             // Same thing for the rows
             // Order of the rows is not reliable
             // So we generate a hash for the current line and ensured that
             // the generated file contains a line with the same hash
             if (md5(json_encode($actualLine)) === md5(json_encode($expectedLine))) {
                 $found = true;
                 // Unset line to prevent comparing it twice
                 unset($actualLines[$index]);
                 break;
             }
         }
         if (!$found) {
             throw new \Exception(sprintf('Could not find a line containing "%s" in %s', implode(' | ', $originalExpectedLine), $path));
         }
     }
 }
开发者ID:SamirBoulil,项目名称:pim-community-dev,代码行数:69,代码来源:ExportProfilesContext.php

示例13: buildQuadTree

function buildQuadTree($filename)
{
    //  Set the centrepoint of our QuadTree at 0.0 Longitude, 0.0 Latitude
    $centrePoint = new \QuadTrees\QuadTreeXYPoint(0.0, 0.0);
    //  Set the bounding box to the entire globe
    $quadTreeBoundingBox = new \QuadTrees\QuadTreeBoundingBox($centrePoint, 360, 180);
    //  Create our QuadTree
    $quadTree = new \QuadTrees\QuadTree($quadTreeBoundingBox);
    echo "Loading lunarLandings: ";
    $landingFile = new \SplFileObject($filename);
    $landingFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
    //  Populate our new QuadTree with lunarLandings from around the world
    $lunarLandingCount = 0;
    foreach ($landingFile as $lunarLandingData) {
        if (!empty($lunarLandingData[0])) {
            if ($lunarLandingCount % 10 == 0) {
                echo '.';
            }
            $lunarLanding = new lunarLandingPoint(trim($lunarLandingData[0]), trim($lunarLandingData[1]), trim($lunarLandingData[2]), trim($lunarLandingData[4]), trim($lunarLandingData[3]));
            $quadTree->insert($lunarLanding);
            ++$lunarLandingCount;
        }
    }
    echo PHP_EOL, "Added {$lunarLandingCount} lunar landing details to QuadTree", PHP_EOL;
    return $quadTree;
}
开发者ID:markbaker,项目名称:quadtrees,代码行数:26,代码来源:lunarLandingSearch.php

示例14: importAction

 /**
  * Import action
  *
  * @return Response
  *
  * @throws AccessDeniedException If access is not granted
  */
 public function importAction(Request $request)
 {
     if (false === $this->admin->isGranted('IMPORT')) {
         throw new AccessDeniedException();
     }
     $defaultData = array();
     $form = $this->createFormBuilder($defaultData)->add('file', 'file')->getForm();
     $form->handleRequest($request);
     $data = array();
     if ($form->isValid()) {
         $fs = new Filesystem();
         try {
             $fs->mkdir('/tmp/import');
         } catch (IOExceptionInterface $e) {
             echo "An error occurred while creating your directory at " . $e->getPath();
         }
         $form['file']->getData()->move('/tmp/import', 'data.csv');
         $file = new \SplFileObject('/tmp/import/data.csv');
         // this must be done to import CSVs where one of the data-field has CRs within!
         $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD);
         $reader = new Reader\CsvReader($file, ';');
         $reader->setHeaderRowNumber(0);
         if ($request->request->has('btn_preview')) {
             foreach ($reader as $row) {
                 $data[] = $row;
             }
         } else {
             // Set Database into "nonchecking Foreign Keys"
             $em = $this->getDoctrine()->getManager();
             $em->getConnection()->exec("SET FOREIGN_KEY_CHECKS=0;");
             $writer = new DoctrineWriter($em, "AppBundle:Partner");
             $writer->setTruncate(false);
             $metadata = $em->getClassMetaData("AppBundle:Partner");
             $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
             $mapping = new Step\MappingStep();
             $mapping->map('[country_code]', '[country]');
             $mapping->map('[category]', '[partnerCategory]');
             $converter = new StringToObjectConverter($em->getRepository("AppBundle:PartnerCategory"), 'name');
             $valueConverterStep = new Step\ValueConverterStep();
             $valueConverterStep->add('[partnerCategory]', $converter);
             //                $converter = new CustomValueConverter();
             //                $converterStep = new Step\ConverterStep();
             //                $converterStep->add($converter);
             $workflow = new Workflow\StepAggregator($reader);
             $workflow->addStep($mapping);
             $workflow->addStep($valueConverterStep);
             //                $workflow->addStep($converterStep);
             $workflow->addWriter($writer);
             $workflow->process();
             // Resetting Database Check Status
             $em->getConnection()->exec("SET FOREIGN_KEY_CHECKS=1;");
         }
     }
     $formView = $form->createView();
     // set the theme for the current Admin Form
     $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
     return $this->render('CRUD/import_partner.html.twig', array('action' => 'import', 'form' => $formView, 'data' => $data));
 }
开发者ID:Nexotap,项目名称:Ivory,代码行数:65,代码来源:PartnerController.php

示例15: getFileObject

 /**
  * @param $tmp_file
  * @return \SplFileObject
  */
 public function getFileObject($tmp_file)
 {
     if (!$tmp_file) {
         return array();
     }
     $file = new \SplFileObject($tmp_file);
     $file->setFlags(\SplFileObject::READ_CSV);
     return $file;
 }
开发者ID:sumiyoshi,项目名称:BokunoSlim3,代码行数:13,代码来源:FileObject.php


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