예제 #1
0
 /**
  * Constructs a new validator instance, initializing the error message.
  *
  * @param ContainerBuilder $container The current service manager instance.
  * @param string         $errorMessage   The error message to report if the field's data does not validate.
  *
  * @throws InvalidArgumentException Thrown if the error message is not a string or is empty.
  */
 public function __construct(ContainerBuilder $container, $errorMessage = null)
 {
     parent::__construct($container);
     if (isset($errorMessage)) {
         if (is_string($errorMessage) && !empty($errorMessage)) {
             $this->errorMessage = $errorMessage;
         } else {
             throw new \InvalidArgumentException($this->__('An invalid error message was supplied.'));
         }
     } else {
         $this->errorMessage($this->__('The value supplied was not valid.'));
     }
 }
예제 #2
0
 /**
  * Constructs a new validator instance, initializing the error message.
  *
  * @param Zikula_ServiceManager $serviceManager The current service manager instance.
  * @param string                $errorMessage   The error message to report if the field's data does not validate.
  *
  * @throws \InvalidArgumentException Thrown if the error message is not a string or is empty.
  */
 public function __construct(\Zikula_ServiceManager $serviceManager, $errorMessage = null)
 {
     parent::__construct($serviceManager, ModUtil::getModule('ZikulaUsersModule'));
     if (isset($errorMessage)) {
         if (is_string($errorMessage) && !empty($errorMessage)) {
             $this->errorMessage = $errorMessage;
         } else {
             throw new \InvalidArgumentException($this->__('An invalid error message was supplied.'));
         }
     } else {
         $this->errorMessage($this->__('The value supplied was not valid.'));
     }
 }
예제 #3
0
 public function __construct(Zikula_ServiceManager $serviceManager, \Zikula\Core\AbstractModule $bundle = null)
 {
     parent::__construct($serviceManager, $bundle);
     if ($bundle !== null) {
         // Get bundle from route.
         $module = $bundle->getName();
         // Load module.
         \ModUtil::load($module);
         // Set legacy to true, as the Controller's response will not have the theme around it otherwise.
         // See Zikula\Bundle\CoreBundle\EventListener\ThemeListener::onKernelResponse() - The only place it is used.
         $request = $serviceManager->get("request");
         $request->attributes->set('_legacy', true);
     }
 }
예제 #4
0
 /**
  * Construct a new form data container instance, initializing the id value.
  *
  * @param string         $formId         A value for the form's id attribute.
  * @param ContainerBuilder $container The current service manager instance.
  *
  * @throws \InvalidArgumentException Thrown if the specified form id is not valid.
  */
 public function __construct($formId, ContainerBuilder $container = null)
 {
     if (!isset($container)) {
         $container = ServiceUtil::getManager();
     }
     parent::__construct($container);
     $formId = trim($formId);
     if (!isset($formId) || !is_string($formId) || empty($formId)) {
         throw new \InvalidArgumentException($this->__('Invalid form id.'));
     } elseif (!preg_match('/^[a-z][a-z0-9_]*$/', $formId)) {
         throw new \InvalidArgumentException($this->__f('The form id \'%1$s\' contains invalid characters.', array($formId)));
     }
     $this->formId = $formId;
     $this->fieldIds = array();
     $this->formFields = array();
 }
예제 #5
0
파일: Field.php 프로젝트: Silwereth/core
 /**
  * Build a new form data container field.
  *
  * @param AbstractFormData         $formContainer  The parent form data container.
  * @param string                   $fieldName      The name of the field.
  * @param mixed                    $initialValue   The initial value of the field.
  * @param mixed                    $defaultValue   The defaule value for the field.
  * @param \Zikula_ServiceManager   $serviceManager The current service manager instance.
  *
  * @throws \InvalidArgumentException Thrown if any of the parameters are not valid.
  */
 public function __construct(AbstractFormData $formContainer, $fieldName, $initialValue = null, $defaultValue = null, \Zikula_ServiceManager $serviceManager = null)
 {
     if (!isset($serviceManager)) {
         $serviceManager = ServiceUtil::getManager();
     }
     parent::__construct($serviceManager);
     if (!isset($formContainer)) {
         throw new \InvalidArgumentException($this->__('Invalid form container.'));
     } else {
         $this->formContainer = $formContainer;
     }
     $fieldName = trim($fieldName);
     if (!isset($fieldName) || !is_string($fieldName) || empty($fieldName)) {
         throw new \InvalidArgumentException($this->__f('Invalid field name: \'%1$s\'.', array($fieldName)));
     } elseif (!preg_match('/^[a-zA-Z][a-zA-Z0-9_\\x7f-\\xff]*(\\[(\\d+|[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\])*$/', $fieldName)) {
         throw new \InvalidArgumentException($this->__f('The field name \'%1$s\' contains invalid characters.', array($fieldName)));
     } else {
         $this->fieldName = $fieldName;
         $this->fieldId = preg_replace('/[^a-z0-9_]/', '_', mb_strtolower($fieldName));
     }
     $this->data = $initialValue;
     $this->defaultValue = $defaultValue;
     $this->nullAllowed = false;
     $this->hasBeenValidated = false;
     $this->validators = array();
 }