コード例 #1
0
 /**
  * Generate a shortcode from the Model object.
  *
  * @param string $slug
  * @param Model $object
  *
  * @return string
  */
 public static function shortCodeGenerator($slug, Model $object)
 {
     $reflector = new ReflectionClass(get_class($object));
     $shortcodeTmp = '';
     foreach ($reflector->getProperties() as $property) {
         $method = 'get' . ucfirst($property->getName());
         $value = null;
         if ($reflector->hasMethod($method)) {
             $value = $reflector->getMethod($method)->invoke($object);
             if ($value === false) {
                 $value = '0';
             }
             if (is_array($value)) {
                 $value = implode(',', $value);
             }
             if ($value != null) {
                 $shortcodeTmp .= Helper::ccToUnderscore($property->getName()) . '="' . $value . '" ';
             }
         }
     }
     $shortcode = '[' . $slug . ' ' . rtrim($shortcodeTmp) . ']';
     return $shortcode;
 }