/**
  * Find path
  *
  * Most files will require the $module parameter to
  * make search more specific.  The only files that
  * are currently module-independent are list CSVs.
  *
  * @param string $module Module to look for files in
  * @param string $path     Path to look for
  * @return null|string|array Null for not found, string for single path, array for multiple paths
  */
 public function find($module = null, $path = null)
 {
     if ($this->requireModule) {
         if (empty($module)) {
             throw new \InvalidArgumentException("Module is not specified");
         }
         if (!is_string($module)) {
             throw new \InvalidArgumentException("Module name is not a string");
         }
     }
     if (empty($path)) {
         $path = $this->fileName;
     }
     if (!is_string($path)) {
         throw new \InvalidArgumentException("Path is not a string");
     }
     if (empty($this->pathConfigKey)) {
         throw new \InvalidArgumentException("pathConfigKey is empty");
     }
     $result = Configure::readOrFail($this->pathConfigKey);
     if ($this->requireModule) {
         $result .= $module . DIRECTORY_SEPARATOR;
     }
     $result .= $path;
     $this->validatePath($result);
     return $result;
 }
 /**
  * Called before the controller action. You can use this method to configure and customize components
  * or perform logic that needs to happen before each controller action.
  *
  * @param \Cake\Event\Event $event An Event instance
  * @return void
  * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks
  */
 public function beforeFilter(Event $event)
 {
     $this->_controllerInstance = $event->subject();
     $this->_setTableInstance($this->_controllerInstance->request->params);
     // skip passing table fields if action is not supported by the plugin
     if (in_array($this->request->action, Configure::readOrFail('CsvMigrations.actions'))) {
         $this->_setTableFields();
     }
 }
 /**
  * Method that retrieves list field options.
  * @param string $listName list name
  * @return array
  */
 protected function _getListFieldOptions($listName)
 {
     $result = [];
     $path = Configure::readOrFail('CsvListsOptions.path') . $listName . '.csv';
     $listData = $this->_getCsvData($path);
     if (!empty($listData)) {
         $result = $this->_prepareListOptions($listData);
     }
     return $result;
 }
예제 #4
0
 /**
  * testReadOrFail method
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage Expected configuration key "This.Key.Does.Not.exist" not found
  * @return void
  */
 public function testReadOrFailThrowingException()
 {
     Configure::readOrFail('This.Key.Does.Not.exist');
 }
 /**
  * Method that retrieves table fields defined
  * in the csv file, based on specified action
  * @param  object $table  Table object
  * @param  string $action action name
  * @return array          table fields
  */
 protected function _getTableFields($table, $action = '')
 {
     $tableName = $table->table();
     if ('' === trim($action)) {
         $action = static::ASSOC_FIELDS_ACTION;
     }
     $path = Configure::readOrFail('CsvViews.path');
     $path .= Inflector::camelize($tableName) . DS . $action . '.csv';
     $result = $this->_getFieldsFromCsv($path, $action);
     $result = array_map(function ($v) {
         return $v[0];
     }, $result);
     return $result;
 }
 /**
  * Get all modules data.
  *
  * @return array Modules, fields and fields types.
  */
 protected function _csvData()
 {
     $result = [];
     $path = Configure::readOrFail('CsvMigrations.migrations.path');
     $csvFiles = $this->_getCsvFiles($path);
     /*
             covers case where CsvMigration configuration files reside in a plugin.
     */
     $plugin = $this->_getPluginNameFromPath($path);
     if (is_null($plugin)) {
         /*
                     covers case where CsvMigration model and controller reside in
                     a plugin (even if configuration files reside in the APP level).
         */
         $plugin = $this->_getPluginNameFromRegistryAlias();
     }
     $parser = new MigrationParser();
     foreach ($csvFiles as $csvModule => $paths) {
         if (!is_null($plugin)) {
             $csvModule = $plugin . '.' . $csvModule;
         }
         foreach ($paths as $path) {
             $result[$csvModule] = $parser->wrapFromPath($path);
         }
     }
     return $result;
 }
예제 #7
0
 /**
  * Used to get information stored in Configure. It's not
  * possible to store `null` values in Configure.
  *
  * Acts as a wrapper around Configure::read() and Configure::check().
  * The configure key/value pair fetched via this method is expected to exist.
  * In case it does not an exception will be thrown.
  *
  * Usage:
  * ```
  * Configure::readOrFail('Name'); will return all values for Name
  * Configure::readOrFail('Name.key'); will return only the value of Configure::Name[key]
  * ```
  *
  * @param string $name Variable to obtain. Use '.' to access array elements.
  * @return mixed Value stored in configure.
  * @throws \RuntimeException if the requested configuration is not set.
  */
 public function readOrFail($name)
 {
     return Configure::readOrFail($name);
 }