Пример #1
0
 /**
  * Creates a new CMS event object for a given event name and subject. The following arguments must be given:
  * subject		object	The subject of the event. This is the core object you are going to manipulate.
  * eventClass	string	The Event class name. If you do not provide it Joomla\Cms\Events\<eventNameWithoutOnPrefix>
  *                      will be used.
  *
  * @param   string  $eventName  The name of the event, e.g. onTableBeforeLoad
  * @param   array   $arguments  Additional arguments to pass to the event
  *
  * @return  static
  *
  * @since   __DEPLOY_VERSION__
  * @throws  BadMethodCallException  If you do not provide a subject argument
  */
 public static function create($eventName, $arguments = [])
 {
     // Get the class name from the arguments, if specified
     $eventClassName = '';
     if (isset($arguments['eventClass'])) {
         $eventClassName = $arguments['eventClass'];
         unset($arguments['eventClass']);
     }
     /**
      * If the class name isn't set/found determine it from the event name, e.g. TableBeforeLoadEvent from
      * the onTableBeforeLoad event name.
      */
     if (empty($eventClassName) || !class_exists($eventClassName, true)) {
         $bareName = strpos($eventName, 'on') === 0 ? substr($eventName, 2) : $eventName;
         $parts = Normalise::fromCamelCase($bareName, true);
         $eventClassName = __NAMESPACE__ . '\\' . ucfirst(array_shift($parts)) . '\\';
         $eventClassName .= implode('', $parts);
         $eventClassName .= 'Event';
     }
     // Make sure a non-empty subject argument exists and that it is an object
     if (!isset($arguments['subject']) || empty($arguments['subject']) || !is_object($arguments['subject'])) {
         throw new BadMethodCallException("No subject given for the {$eventName} event");
     }
     // Create and return the event object
     if (class_exists($eventClassName, true)) {
         return new $eventClassName($eventName, $arguments);
     }
     return new GenericEvent($eventName, $arguments);
 }
Пример #2
0
 /**
  * Method to instantiate the form field object.
  *
  * @param   Form  $form  The form to attach to the form field object.
  *
  * @since   1.0
  */
 public function __construct(Form $form = null)
 {
     // If there is a form passed into the constructor set the form and form control properties.
     if ($form instanceof Form) {
         $this->form = $form;
         $this->formControl = $form->getFormControl();
     }
     // Detect the field type if not set
     if (!isset($this->type)) {
         $parts = Normalise::fromCamelCase(get_called_class(), true);
         if ($parts[0] == 'J') {
             $this->type = String::ucfirst($parts[count($parts) - 1], '_');
         } else {
             $this->type = String::ucfirst($parts[0], '_') . String::ucfirst($parts[count($parts) - 1], '_');
         }
     }
 }
Пример #3
0
 /**
  * Gets the identifier for an entity
  *
  * @param   object  $entity  The entity
  *
  * @return  array  The identifier as key-value pair(s)
  */
 protected function getIdentifier($entity)
 {
     $entityId = json_decode($this->entityRegistry->getEntityId($entity), true);
     if (is_array($entityId)) {
         $identifier = [];
         foreach ($entityId as $key => $value) {
             $key = strtolower(Normalise::toUnderscoreSeparated(Normalise::fromCamelCase($key)));
             $identifier[$key] = $value;
         }
         return $identifier;
     }
     $primary = $this->builder->getMeta(get_class($entity))->primary;
     return [$primary => $entityId];
 }
Пример #4
0
 /**
  * Load view class
  *
  * @param   string $class Class name
  */
 private function view($class)
 {
     if (!strstr(strtolower($class), 'view')) {
         return;
     }
     $scope = Factory::getApplication()->scope;
     // Load component specific files
     if ($this->appName($class) === $scope) {
         $parts = Normalise::fromCamelCase($class, true);
         $type = array_pop($parts);
         $path = JPATH_SITE . '/libraries/fabble/Views/' . JString::ucfirst($type) . '.php';
         $original = $type;
         if (file_exists($path)) {
             require_once $path;
             class_alias('\\Fabble\\Views\\' . $original, $class);
             return;
         }
     }
 }
Пример #5
0
 /**
  * @param   string $word A word
  *
  * @return  string
  */
 private function normalise($word)
 {
     return Normalise::toUnderscoreSeparated(strtolower(Normalise::fromCamelCase($word)));
 }