create() public static méthode

public static create ( array $values = [] ) : self
$values array
Résultat self
 public function createClass($className)
 {
     $class = Object\ClassDefinition::getByName($className);
     if (!$class) {
         $result = Plugin::getEventManager()->trigger("install.class.getClass.{$className}", $this, array("className" => $className, "json" => $json), function ($v) {
             return $v instanceof Object\ClassDefinition;
         });
         if ($result->stopped()) {
             return $result->last();
         }
         $jsonFile = PIMCORE_PLUGINS_PATH . "/CoreShop/install/class-{$className}.json";
         $class = Object\ClassDefinition::create();
         $class->setName($className);
         $class->setUserOwner($this->_getUser()->getId());
         $json = file_get_contents($jsonFile);
         $result = Plugin::getEventManager()->trigger('install.class.preCreate', $this, array("className" => $className, "json" => $json), function ($v) {
             return !preg_match('/[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]/', preg_replace('/"(\\.|[^"\\\\])*"/', '', $v));
         });
         if ($result->stopped()) {
             $resultJson = $result->last();
             if ($resultJson) {
                 $json = $resultJson;
             }
         }
         Object\ClassDefinition\Service::importClassDefinitionFromJson($class, $json, true);
         return $class;
     }
     return $class;
 }
 /**
  * @todo refactor steps into proper methods instead of doing it all in the action
  * @throws Exception
  */
 public function indexAction()
 {
     // reachable via http://your.domain/plugin/Prototyper/admin/index
     $this->view->previewData = null;
     $this->view->csvText = $this->getParam('csv');
     $this->view->classname = $this->getParam('classname');
     $csvData = array();
     $rowNr = 0;
     $rows = str_getcsv($this->view->csvText, "\n");
     //parse the rows
     foreach ($rows as $row) {
         $rowNr++;
         $rowData = str_getcsv($row, ";");
         $csvData[] = $rowData;
         if ($rowNr == 1) {
             $fieldNames = array();
             $fieldTitles = array();
             foreach ($rowData as $cell) {
                 $fieldTitles[] = $cell;
                 $fieldNames[] = $this->getFieldName($cell);
             }
             $csvData[] = $fieldNames;
         }
         if ($rowNr > 10) {
             break;
         }
     }
     $this->view->previewTable = $csvData;
     $fieldList = array();
     foreach ($fieldNames as $fieldName) {
         $fieldTitle = array_shift($fieldTitles);
         ob_start();
         include __DIR__ . "/../classes/field.json.php";
         $fieldList[] = ob_get_clean();
     }
     $fields = implode(',', $fieldList);
     ob_start();
     include __DIR__ . "/../classes/object.json.php";
     $jsonText = ob_get_clean();
     if ($this->getParam('generate') != '') {
         $class = Object\ClassDefinition::getByName($this->correctClassname($this->getParam("classname")));
         if ($class == null) {
             $class = Object\ClassDefinition::create(array('name' => $this->correctClassname($this->getParam("classname")), 'userOwner' => $this->user->getId()));
             $class->save();
         }
         $class = Object\ClassDefinition::getById($class->getId());
         $success = Object\ClassDefinition\Service::importClassDefinitionFromJson($class, $jsonText);
         if ($success) {
             $this->view->successMessage = '<strong>Class generation successful.</strong>';
         }
     }
 }
Exemple #3
0
 /**
  * @param string $name
  * @return ClassDefinition
  * @throws \Exception
  */
 public function createClass($name)
 {
     $def = file_get_contents(sprintf('%s/class_%s.json', $this->baseDir, $name));
     $conf = json_decode($def, true);
     $layoutDefinitions = ClassDefinition\Service::generateLayoutTreeFromArray($conf['layoutDefinitions']);
     if (!$layoutDefinitions) {
         throw new \Exception('Unable to generate class layout for ' . $name);
     }
     $class = ClassDefinition::create();
     $class->setName($name);
     $class->setUserOwner($this->getUser()->getId());
     $class->setLayoutDefinitions($layoutDefinitions);
     $class->setIcon($conf['icon']);
     $class->setAllowInherit($conf['allowInherit']);
     $class->setAllowVariants($conf['allowVariants']);
     $class->setParentClass($conf['parentClass']);
     $class->setPreviewUrl($conf['previewUrl']);
     $class->setPropertyVisibility($conf['propertyVisibility']);
     $class->save();
     return $class;
 }
Exemple #4
0
 public function addAction()
 {
     $class = Object\ClassDefinition::create(['name' => $this->correctClassname($this->getParam("name")), 'userOwner' => $this->user->getId()]);
     $class->save();
     $this->_helper->json(["success" => true, "id" => $class->getId()]);
 }