Esempio n. 1
0
 /**
  * Create a new pagetype
  */
 public function actionNew()
 {
     $form = new \Foundation\Form();
     $form->setCSRFToken($this->getCSRFToken());
     $form->setAction($this->path("manage/elementtypes/new"));
     $field = $form->newField();
     $field->setLegend('New element type');
     $element = $field->newElement('TextInput', 'name');
     $element->setLabel('Name');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element->addFilter(new \Foundation\Form\Filter\Safe($element));
     $element = $field->newElement('TextInput', 'class');
     $element->setLabel('Class');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $form->newButton('submit', 'Add Element');
     $this->setVar('form', $form);
     if ($input = $form->processInput($this->post)) {
         //class_exists causes doctrine to try and load the class which fails so we look first if doctrine can load it and then
         //if that fails we use class exists with no auto_load so it just looks in existing includes
         if (\Doctrine\Common\ClassLoader::classExists(ltrim($input->get('class'), '\\')) or class_exists($input->get('class'), false)) {
             $elementType = new \Jazzee\Entity\ElementType();
             $elementType->setName($input->get('name'));
             $elementType->setClass($input->get('class'));
             $this->addMessage('success', $input->get('name') . " saved.");
             $this->_em->persist($elementType);
             $this->redirectPath('manage/elementtypes');
         } else {
             $this->addMessage('error', "That is not a valid class name.  The class must eithier by loadable by a Doctrine::classLoader registered in the autoload stack or already be included.");
         }
     }
 }
 public function testClassExists()
 {
     $this->assertFalse(ClassLoader::classExists('ClassLoaderTest\\ClassD'));
     $badLoader = function ($className) {
         require __DIR__ . '/ClassLoaderTest/ClassD.php';
         return true;
     };
     spl_autoload_register($badLoader);
     $this->assertTrue(ClassLoader::classExists('ClassLoaderTest\\ClassD'));
     spl_autoload_unregister($badLoader);
 }
Esempio n. 3
0
 public function testClassExistsWhenLoaderIsProtected()
 {
     require_once __DIR__ . '/ClassLoaderTest/ExternalLoader.php';
     // Test static call
     \ClassLoaderTest\ExternalLoader::registerStatic();
     $this->assertFalse(ClassLoader::classExists('ClassLoaderTest\\Class\\That\\Does\\Not\\Exist'));
     \ClassLoaderTest\ExternalLoader::unregisterStatic();
     // Test object
     $loader = new \ClassLoaderTest\ExternalLoader();
     $loader->register();
     $this->assertFalse(ClassLoader::classExists('ClassLoaderTest\\Class\\That\\Does\\Not\\Exist'));
     $loader->unregister();
 }
Esempio n. 4
0
 public function testClassExistsWithSilentAutoloader()
 {
     $test = $this;
     $silentLoader = function ($className) use($test) {
         $test->assertSame('ClassLoaderTest\\ClassE', $className);
         require __DIR__ . '/ClassLoaderTest/ClassE.php';
     };
     $additionalLoader = function () use($test) {
         $test->fail('Should not call this loader, class was already loaded');
     };
     $this->assertFalse(ClassLoader::classExists('ClassLoaderTest\\ClassE'));
     spl_autoload_register($silentLoader);
     spl_autoload_register($additionalLoader);
     $this->assertTrue(ClassLoader::classExists('ClassLoaderTest\\ClassE'));
     spl_autoload_unregister($additionalLoader);
     spl_autoload_unregister($silentLoader);
 }
Esempio n. 5
0
 /**
  * Finalize the mapping and make sure that it is consistent.
  *
  * @throws MappingException if inconsistencies are discovered.
  */
 public function validateClassMapping()
 {
     // associative array fields need a separate property to store the keys.
     // make sure that generated or specified name does not collide with an
     // existing mapping.
     $assocFields = array();
     foreach ($this->fieldMappings as $fieldName) {
         $mapping = $this->mappings[$fieldName];
         if (empty($mapping['assoc'])) {
             continue;
         }
         if (isset($this->mappings[$mapping['assoc']])) {
             throw MappingException::assocOverlappingFieldDefinition($this->name, $fieldName, $mapping['assoc']);
         }
         if (!empty($assocFields[$mapping['assoc']])) {
             throw MappingException::assocOverlappingAssocDefinition($this->name, $fieldName, $assocFields[$mapping['assoc']]);
         }
         $assocFields[$mapping['assoc']] = $fieldName;
     }
     if (!empty($this->versionNameField) && !$this->versionable) {
         throw new MappingException(sprintf("You cannot use the @VersionName annotation on the non-versionable document %s (field = %s)", $this->name, $this->versionNameField));
     }
     if (!empty($this->versionCreatedField) && !$this->versionable) {
         throw new MappingException(sprintf("You cannot use the @VersionCreated annotation on the non-versionable document %s (field = %s)", $this->name, $this->versionCreatedField));
     }
     if (count($this->translatableFields)) {
         if (!isset($this->localeMapping)) {
             throw new MappingException("You must define a locale mapping for translatable document '" . $this->name . "'");
         }
     }
     // we allow mixed referrers on non-referenceable documents. maybe the mix:referenceable is just not mapped
     if (count($this->referrersMappings)) {
         if (!$this->referenceable) {
             throw new MappingException('You can not have referrers mapped on document "' . $this->name . '" as the document is not referenceable');
         }
         foreach ($this->referrersMappings as $referrerName) {
             $mapping = $this->mappings[$referrerName];
             // only a santiy check with reflection. otherwise we could run into endless loops
             if (!ClassLoader::classExists($mapping['referringDocument'])) {
                 throw new MappingException(sprintf('Invalid referrer mapping on document "%s" for field "%s": The referringDocument class "%s" does not exist', $this->name, $mapping['fieldName'], $mapping['referringDocument']));
             }
             $reflection = new ReflectionClass($mapping['referringDocument']);
             if (!$reflection->hasProperty($mapping['referencedBy'])) {
                 throw new MappingException(sprintf('Invalid referrer mapping on document "%s" for field "%s": The referringDocument "%s" has no property "%s"', $this->name, $mapping['fieldName'], $mapping['referringDocument'], $mapping['referencedBy']));
             }
         }
     }
     $this->validateIdentifier();
 }
 /**
  * Validate association targets actually exist.
  *
  * @throws MappingException
  * @return void
  */
 public function validateAssocations()
 {
     foreach ($this->associationMappings as $mapping) {
         if (!ClassLoader::classExists($mapping['targetEntity'])) {
             throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $pdf_tool = $this->config('printable.settings')->get('pdf_tool');
     \Drupal::service('config.factory')->getEditable('printable.settings')->set('pdf_tool', $form_state->getValue('print_pdf_pdf_tool'))->set('save_pdf', $form_state->getValue('print_pdf_content_disposition'))->set('paper_size', (string) $form_state->getValue('print_pdf_paper_size'))->set('page_orientation', $form_state->getValue('print_pdf_page_orientation'))->set('pdf_location', $form_state->getValue('print_pdf_filename'))->save();
     if (ClassLoader::classExists('mikehaertl\\wkhtmlto\\Pdf') && $pdf_tool == 'wkhtmltopdf') {
         \Drupal::service('config.factory')->getEditable('printable.settings')->set('path_to_binary', $form_state->getValue('path_to_binary'))->save();
     }
 }
Esempio n. 8
0
 /**
  * Create a new pagetype
  */
 public function actionNew()
 {
     $form = new \Foundation\Form();
     $form->setCSRFToken($this->getCSRFToken());
     $form->setAction($this->path("manage/paymenttypes/new"));
     $field = $form->newField();
     $element = $field->newElement('TextInput', 'className');
     $element->setLabel('Class');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $form->newButton('submit', 'Next');
     if (isset($this->post['className'])) {
         $className = $this->post['className'];
         if (!isset($this->post['newtypeform'])) {
             $this->post = array();
             //reset $_POST so we don't try and validate the empty form
         }
         //class_exists causes doctrine to try and load the class which fails so we look first if doctrine can load it and then
         //if that fails we use class exists with no auto_load so it just looks in existing includes
         if (\Doctrine\Common\ClassLoader::classExists(ltrim($className, '\\')) or class_exists($className, false)) {
             $paymentType = new \Jazzee\Entity\PaymentType();
             $paymentClass = new $className($paymentType, $this);
             $form = $paymentClass->getSetupForm();
             $form->setAction($this->path("manage/paymenttypes/new"));
             $form->newHiddenElement('className', $className);
             $form->newHiddenElement('newtypeform', true);
         } else {
             $form->getElementByName('className')->addMessage('That is not a valid class name.  The class must eithier by loadable by a Doctrine::classLoader in the autoload stack or already be included.');
         }
     }
     $this->setVar('form', $form);
     if ($input = $form->processInput($this->post)) {
         if ($input->get('newtypeform')) {
             if ($this->_em->getRepository('Jazzee\\Entity\\PaymentType')->findBy(array('name' => $input->get('name')))) {
                 $form->getElementByName('name')->addMessage('That payment name has already been used.');
                 return false;
             }
             $paymentClass->setup($input);
             $this->_em->persist($paymentType);
             foreach ($paymentType->getVariables() as $var) {
                 $this->_em->persist($var);
             }
             $this->addMessage('success', $input->get('name') . ' saved.');
             $this->redirectPath('manage/paymenttypes');
         }
     }
 }