pluralize() public static method

public static pluralize ( $string )
Beispiel #1
0
 /**
  * Function to save properties directly which do not update via a POST
  *
  * This is called automatically from the save method for things like adding contacts to ContactGroups
  *
  * @param Object $object
  * @throws Exception
  */
 private function savePropertiesDirectly(Object $object)
 {
     foreach ($object::getProperties() as $property_name => $meta) {
         if ($meta[Object::KEY_SAVE_DIRECTLY] && $object->isPropertyDirty($property_name)) {
             //Then actually save
             $property_objects = $object->{$property_name};
             $property_type = get_class(current($property_objects));
             $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI()));
             $request = new Request($this, $url, Request::METHOD_PUT);
             $property_array = array();
             foreach ($property_objects as $property_object) {
                 $property_array[] = $property_object->toStringArray();
             }
             $root_node_name = Helpers::pluralize($property_type::getRootNodeName());
             $request->setBody(Helpers::arrayToXML(array($root_node_name => $property_array)));
             $request->send();
             $response = $request->getResponse();
             foreach ($response->getElements() as $element_index => $element) {
                 if ($response->getErrorsForElement($element_index) === null) {
                     $property_objects[$element_index]->fromStringArray($element);
                     $property_objects[$element_index]->setClean();
                 }
             }
             //Set it clean so the following save might have nothing to do.
             $object->setClean($property_name);
         }
     }
 }
Beispiel #2
0
 /**
  * Search for an entity based on a term. Search by class name, FQ class name - both as-is, plural and singular
  *
  * Crude.
  *
  * @param $key
  * @param string $namespace_hint
  * @return null
  */
 public function searchByKey($key, $namespace_hint = '')
 {
     if (!$this->isIndexed()) {
         $this->buildSearchIndex();
     }
     //Yuck
     $plural_key = Helpers::pluralize($key);
     $singular_key = Helpers::singularize($key);
     $ns_key = sprintf('%s\\%s', $namespace_hint, $key);
     $plural_ns_key = Helpers::pluralize($ns_key);
     $singular_ns_key = Helpers::singularize($ns_key);
     if (isset($this->search_keys[$ns_key])) {
         return $this->search_keys[$ns_key];
     } elseif (isset($this->search_keys[$plural_ns_key])) {
         return $this->search_keys[$plural_ns_key];
     } elseif (isset($this->search_keys[$singular_ns_key])) {
         return $this->search_keys[$singular_ns_key];
     } elseif (isset($this->search_keys[$key])) {
         return $this->search_keys[$key];
     } elseif (isset($this->search_keys[$plural_key])) {
         return $this->search_keys[$plural_key];
     } elseif (isset($this->search_keys[$singular_key])) {
         return $this->search_keys[$singular_key];
     } else {
         return null;
     }
 }