Author: pmacadden
Date: 2010-05-21 17:01:52 +0200 (Fri, 21 May 2010)
New Revision: 29571

Modified:
   plugins/pmMigratorPlugin/trunk/lib/pmMigratorCSV.class.php
Log:
new feature: now you can pass an array of parameters to fgetscsv (pmMigratorCSV)

Modified: plugins/pmMigratorPlugin/trunk/lib/pmMigratorCSV.class.php
===================================================================
--- plugins/pmMigratorPlugin/trunk/lib/pmMigratorCSV.class.php  2010-05-21 
14:49:47 UTC (rev 29570)
+++ plugins/pmMigratorPlugin/trunk/lib/pmMigratorCSV.class.php  2010-05-21 
15:01:52 UTC (rev 29571)
@@ -12,6 +12,11 @@
   protected $file;
 
   /**
+   * @var array parameters for fgetscsv function.
+   */
+  protected $fgetscsv_options;
+
+  /**
    * Create an instance of pmMigratorCSV.
    * @param string $file The path to the CSV file
    * @param string $class_name The class name
@@ -19,12 +24,13 @@
    *
    * @return pmMigratorCSV
    */
-  public static function create($file, $class_name, $class_fields)
+  public static function create($file, $class_name, $class_fields, 
$fgetscsv_options = array())
   {
     $class = __CLASS__;
     $migrator = new $class();
     $migrator->init($class_name, $class_fields);
     $migrator->setFile($file);
+    $migrator->setFgetscsvOptions($fgetscsv_options);
 
     return $migrator;
   }
@@ -52,6 +58,34 @@
   }
 
   /**
+   * Setter for $fgetscsv_options attribute.
+   * @param array parameters for fgetscsv function.
+   *
+   * @return pmMigratorCSV
+   */
+  public function setFgetscsvOptions($fgetscsv_options)
+  {
+    $options = array();
+    $options['lenght'] = isset($fgetscsv_options['lenght']) ? 
$fgetscsv_options['lenght'] : 4096;
+    $options['delimiter'] = isset($fgetscsv_options['delimiter']) ? 
$fgetscsv_options['delimiter'] : ',';
+    $options['enclosure'] = isset($fgetscsv_options['enclosure']) ? 
$fgetscsv_options['enclosure'] : '"';
+    $options['escape'] = isset($fgetscsv_options['escape']) ? 
$fgetscsv_options['escape'] : '\\';
+
+    $this->fgetscsv_options = $options;
+    return $this;
+  }
+
+  /**
+   * Getter for $fgetscsv_options attribute.
+   *
+   * @return string
+   */
+  public function getFgetscsvOptions()
+  {
+    return $this->fgetscsv_options;
+  }
+
+  /**
    * Perform the migration.
    * @param boolean $dry Run in dry mode
    * @param boolean $debug Run in debug mode
@@ -60,9 +94,11 @@
   {
     $handle = fopen($this->getFile(), "r");
 
+    $opts = $this->getFgetscsvOptions();
+
     if ($handle)
     {
-      while($data = fgetcsv($handle))
+      while($data = fgetcsv($handle, $opts['lenght'], $opts['delimiter'], 
$opts['enclosure'], $opts['escape']))
       {
         $object = $this->createObject($debug);
 

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to