/**
  * Extract array of var in object
  * @param   Object $object
  * @returns array Array extracted of the object
  */
 public function extractArray($object, $isRecursive = false)
 {
     if (method_exists($object, "toArray")) {
         return $object->toArray();
     }
     $arrayCollection = new \ArrayIterator();
     $reflection = new \ReflectionClass($object);
     $vars = array_keys($reflection->getdefaultProperties());
     foreach ($vars as $key) {
         $value = $this->resolveGetNameMethod($key, $object);
         if ($value !== null) {
             if (is_object($value) && !$isRecursive) {
                 $arrayCollection->offsetSet($key, $this->extractArray($value, true));
             } else {
                 $arrayCollection->offsetSet($key, $value);
             }
         }
     }
     return $arrayCollection->getArrayCopy();
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function load($controller, $type = null)
 {
     list($prefix, $class) = $this->getControllerLocator($controller);
     $collection = $this->controllerReader->read(new \ReflectionClass($class));
     $collection->prependRouteControllersWithPrefix($prefix);
     $collection->setDefaultFormat($this->defaultFormat);
     $entityManager = $this->container->get('doctrine.orm.entity_manager');
     $inflector = $this->container->get('fos_rest.inflector');
     $reflection = new \ReflectionClass($controller);
     if ($reflection->isSubclassOf('uebb\\HateoasBundle\\Controller\\HateoasController')) {
         $defaultProperties = $reflection->getdefaultProperties();
         /** @var ClassMetadata $metadata */
         $metadata = $entityManager->getMetadataFactory()->getMetadataFor($defaultProperties['entityName']);
         foreach ($metadata->getAssociationNames() as $associationName) {
             if ($metadata->isCollectionValuedAssociation($associationName)) {
                 foreach (array('get', 'patch') as $method) {
                     if (!$reflection->hasMethod($method . ucfirst($associationName) . 'Action')) {
                         $resource = preg_split('/([A-Z][^A-Z]*)Controller/', $reflection->getShortName(), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
                         $routeName = $method . '_' . strtolower(implode('_', $resource)) . '_' . strtolower($associationName);
                         $urlParts = array();
                         $urlParts[] = $inflector->pluralize(strtolower(implode('_', $resource)));
                         $urlParts[] = '{id}';
                         $urlParts[] = strtolower($associationName);
                         $pattern = implode('/', $urlParts);
                         $defaults = array('_controller' => $prefix . $method . 'Linkcollection', 'rel' => $associationName);
                         $requirements = array('_method' => strtoupper($method));
                         $options = array();
                         $host = '';
                         $schemes = array();
                         $condition = null;
                         $route = new Route($pattern, $defaults, $requirements, $options, $host, $schemes, null, $condition);
                         $collection->add($routeName, $route);
                     }
                 }
             }
         }
     }
     return $collection;
 }
Esempio n. 3
0
 /**
  * @param String $resourceClass
  * @param String $action
  * @return mixed
  * @throws \Doctrine\Common\Persistence\Mapping\MappingException
  * @throws \Exception
  */
 public function resolveRouteName($resourceClass, $action, $args = array())
 {
     $key = serialize(array($resourceClass, $action, $args));
     if ($this->cache->contains('routes', $key)) {
         return $this->cache->fetch('routes', $key);
     }
     foreach ($this->router->getRouteCollection()->all() as $name => $route) {
         $defaults = $route->getDefaults();
         $parts = explode('::', $defaults['_controller']);
         if (count($parts) === 2) {
             $reflection = new \ReflectionClass($parts[0]);
             $defaultProperties = $reflection->getdefaultProperties();
             if (is_subclass_of($parts[0], '\\uebb\\HateoasBundle\\Controller\\HateoasController') && $parts[1] === $action && $this->entityManager->getMetadataFactory()->getMetadataFor($defaultProperties['entityName'])->getName() === $resourceClass) {
                 if ($args === array_intersect_key($defaults, $args)) {
                     $this->cache->save('routes', $key, $name);
                     return $name;
                 }
             }
         }
     }
     $this->cache->save('routes', $key, null);
     return null;
 }
Esempio n. 4
0
 protected function getChildClassVariables()
 {
     $objReflection = new \ReflectionClass($this);
     $arrVars = array_keys($objReflection->getdefaultProperties());
     $objReflection = new \ReflectionClass(__CLASS__);
     $arrParentVars = array_keys($objReflection->getdefaultProperties());
     $arrChildVars = array();
     foreach ($arrVars as $strKey) {
         if (!in_array($strKey, $arrParentVars)) {
             $arrChildVars[] = $strKey;
         }
     }
     return $arrChildVars;
 }
Esempio n. 5
0
 /**
  * Overload Extension support
  *  - enables setCOLNAME/getCOLNAME
  *  if you define a set/get method for the item it will be called.
  * otherwise it will just return/set the value.
  * NOTE this currently means that a few Names are NO-NO's 
  * eg. links,link,linksarray, from, Databaseconnection,databaseresult
  *
  * note 
  *  - set is automatically called by setFrom.
  *   - get is automatically called by toArray()
  *  
  * setters return true on success. = strings on failure
  * getters return the value!
  *
  * this fires off trigger_error - if any problems.. pear_error, 
  * has problems with 4.3.2RC2 here
  *
  * @access public
  * @return true?
  * @see overload
  */
 function _call($method, $params, &$return)
 {
     //$this->debug("ATTEMPTING OVERLOAD? $method");
     // ignore constructors : - mm
     if (strtolower($method) == strtolower(get_class($this))) {
         return true;
     }
     $type = strtolower(substr($method, 0, 3));
     $class = get_class($this);
     if ($type != 'set' && $type != 'get') {
         return false;
     }
     // deal with naming conflick of setFrom = this is messy ATM!
     if (strtolower($method) == 'set_from') {
         $return = $this->toValue('from', isset($params[0]) ? $params[0] : null);
         return true;
     }
     $element = substr($method, 3);
     // dont you just love php's case insensitivity!!!!
     $array = array_keys(get_class_vars($class));
     /* php5 version which segfaults on 5.0.3 */
     if (class_exists('ReflectionClass')) {
         $reflection = new ReflectionClass($class);
         $array = array_keys($reflection->getdefaultProperties());
     }
     if (!in_array($element, $array)) {
         // munge case
         foreach ($array as $k) {
             $case[strtolower($k)] = $k;
         }
         if (substr(phpversion(), 0, 1) == 5 && isset($case[strtolower($element)])) {
             trigger_error("PHP5 set/get calls should match the case of the variable", E_USER_WARNING);
             $element = strtolower($element);
         }
         // does it really exist?
         if (!isset($case[$element])) {
             return false;
         }
         // use the mundged case
         $element = $case[$element];
         // real case !
     }
     if ($type == 'get') {
         $return = $this->toValue($element, isset($params[0]) ? $params[0] : null);
         return true;
     }
     $return = $this->fromValue($element, $params[0]);
     return true;
 }
Esempio n. 6
0
 public function make(Model $_prClasse, $_prInsert = true, $_prCondicao = '')
 {
     $reflection = new ReflectionClass($_prClasse);
     $propertis = $reflection->getdefaultProperties();
     foreach ($propertis as $key => $value) {
         if ($_prClasse->get($key) === null or $key == 'chave') {
             continue;
         }
         if ($key == 'tabela') {
             if ($_prInsert) {
                 $this->insert($_prClasse->get($key));
             } else {
                 $this->update($_prClasse->get($key), $_prCondicao);
             }
         } else {
             if ($key != $_prClasse->get("chave")) {
                 $this->add($key, $_prClasse->get($key));
             }
         }
     }
     $this->geraSql();
 }
Esempio n. 7
0
 /**
  * Handles a [url] tag. Creates a link to another web page.
  *
  * @param	string	If tag has option, the displayable name. Else, the URL.
  * @param	string	If tag has option, the URL.
  *
  * @return	string	HTML representation of the tag.
  */
 function handle_bbcode_url($text, $link)
 {
     $rightlink = trim($link);
     if (empty($rightlink)) {
         // no option -- use param
         $rightlink = trim($text);
     }
     $rightlink = str_replace(array('`', '"', "'", '['), array('`', '"', ''', '['), $this->strip_smilies($rightlink));
     // remove double spaces -- fixes issues with wordwrap
     $rightlink = str_replace('  ', '', $rightlink);
     if (!preg_match('#^[a-z0-9]+(?<!about|javascript|vbscript|data):#si', $rightlink)) {
         $rightlink = "http://{$rightlink}";
     }
     if (!trim($link) or str_replace('  ', '', $text) == $rightlink) {
         $tmp = unhtmlspecialchars($rightlink);
         if (vbstrlen($tmp) > 55 and $this->is_wysiwyg() == false) {
             $text = htmlspecialchars_uni(vbchop($tmp, 36) . '...' . substr($tmp, -14));
         } else {
             // under the 55 chars length, don't wordwrap this
             $text = str_replace('  ', '', $text);
         }
     }
     static $current_url, $current_host, $allowed, $friendlyurls = array();
     if (!isset($current_url)) {
         $current_url = @vB_String::parseUrl($this->registry->options['bburl']);
     }
     $is_external = $this->registry->options['url_nofollow'];
     if ($this->registry->options['url_nofollow']) {
         if (!isset($current_host)) {
             $current_host = preg_replace('#:(\\d)+$#', '', VB_HTTP_HOST);
             $allowed = preg_split('#\\s+#', $this->registry->options['url_nofollow_whitelist'], -1, PREG_SPLIT_NO_EMPTY);
             $allowed[] = preg_replace('#^www\\.#i', '', $current_host);
             $allowed[] = preg_replace('#^www\\.#i', '', $current_url['host']);
         }
         $target_url = preg_replace('#^([a-z0-9]+:(//)?)#', '', $rightlink);
         foreach ($allowed as $host) {
             if (stripos($target_url, $host) !== false) {
                 $is_external = false;
             }
         }
     }
     // API need to convert link to vb:action/param1=val1/param2=val2...
     if (defined('VB_API') and VB_API === true) {
         $current_link = @vB_String::parseUrl($rightlink);
         if ($current_link !== false) {
             $current_link['host'] = strtolower($current_link['host']);
             $current_url['host'] = strtolower($current_url['host']);
             if (($current_link['host'] == $current_url['host'] or 'www.' . $current_link['host'] == $current_url['host'] or $current_link['host'] == 'www.' . $current_url['host']) and (!$current_url['path'] or stripos($current_link['path'], $current_url['path']) !== false)) {
                 // This is a vB link.
                 if ($current_link['path'] == $current_url['path'] or $current_link['path'] . '/' == $current_url['path'] or $current_link['path'] == $current_url['path'] . '/') {
                     $rightlink = 'vb:index';
                 } else {
                     // Get a list of declared friendlyurl classes
                     if (!$friendlyurls) {
                         require_once DIR . '/includes/class_friendly_url.php';
                         $classes = get_declared_classes();
                         foreach ($classes as $classname) {
                             if (strpos($classname, 'vB_Friendly_Url_') !== false) {
                                 $reflect = new ReflectionClass($classname);
                                 $props = $reflect->getdefaultProperties();
                                 if ($classname == 'vB_Friendly_Url_vBCms') {
                                     $props['idvar'] = $props['ignorelist'][] = $this->registry->options['route_requestvar'];
                                     $props['script'] = 'content.php';
                                     $props['rewrite_segment'] = 'content';
                                 }
                                 if ($props['idvar']) {
                                     $friendlyurls[$classname]['idvar'] = $props['idvar'];
                                     $friendlyurls[$classname]['idkey'] = $props['idkey'];
                                     $friendlyurls[$classname]['titlekey'] = $props['titlekey'];
                                     $friendlyurls[$classname]['ignorelist'] = $props['ignorelist'];
                                     $friendlyurls[$classname]['script'] = $props['script'];
                                     $friendlyurls[$classname]['rewrite_segment'] = $props['rewrite_segment'];
                                 }
                             }
                             $friendlyurls['vB_Friendly_Url_vBCms']['idvar'] = $this->registry->options['route_requestvar'];
                             $friendlyurls['vB_Friendly_Url_vBCms']['ignorelist'][] = $this->registry->options['route_requestvar'];
                             $friendlyurls['vB_Friendly_Url_vBCms']['script'] = 'content.php';
                             $friendlyurls['vB_Friendly_Url_vBCms']['rewrite_segment'] = 'content';
                             $friendlyurls['vB_Friendly_Url_vBCms2']['idvar'] = $this->registry->options['route_requestvar'];
                             $friendlyurls['vB_Friendly_Url_vBCms2']['ignorelist'][] = $this->registry->options['route_requestvar'];
                             $friendlyurls['vB_Friendly_Url_vBCms2']['script'] = 'list.php';
                             $friendlyurls['vB_Friendly_Url_vBCms2']['rewrite_segment'] = 'list';
                         }
                     }
                     /*
                      * 	FRIENDLY_URL_OFF
                      *	showthread.php?t=1234&p=2
                      *
                      *	FRIENDLY_URL_BASIC
                      *	showthread.php?1234-Thread-Title/page2&pp=2
                      *
                      *	FRIENDLY_URL_ADVANCED
                      *	showthread.php/1234-Thread-Title/page2?pp=2
                      *
                      *	FRIENDLY_URL_REWRITE
                      *	/threads/1234-Thread-Title/page2?pp=2
                      */
                     // Try to get the script name
                     // FRIENDLY_URL_OFF, FRIENDLY_URL_BASIC or FRIENDLY_URL_ADVANCED
                     $scriptname = '';
                     if (preg_match('#([^/]+)\\.php#si', $current_link['path'], $matches)) {
                         $scriptname = $matches[1];
                     } else {
                         // Build a list of rewrite_segments
                         foreach ($friendlyurls as $v) {
                             $rewritesegments .= "|{$v['rewrite_segment']}";
                         }
                         $pat = '#/(' . substr($rewritesegments, 1) . ')/#si';
                         if (preg_match($pat, $current_link['path'], $matches)) {
                             $uri = $matches[1];
                         }
                         // Decide the type of the url
                         $urltype = null;
                         foreach ($friendlyurls as $v) {
                             if ($v['rewrite_segment'] == $uri) {
                                 $urltype = $v;
                                 break;
                             }
                         }
                         // Convert $uri back to correct scriptname
                         $scriptname = str_replace('.php', '', $urltype['script']);
                     }
                     if ($scriptname) {
                         $oldrightlink = $rightlink;
                         $rightlink = "vb:{$scriptname}";
                         // Check if it's FRIENDLY_URL_BASIC or FRIENDLY_URL_ADVANCED
                         if (preg_match('#(?:\\?|/)(\\d+).*?(?:/page(\\d+)|$)#si', $oldrightlink, $matches)) {
                             // Decide the type of the url
                             $urltype = null;
                             foreach ($friendlyurls as $v) {
                                 if ($v['script'] == $scriptname . '.php') {
                                     $urltype = $v;
                                     break;
                                 }
                             }
                             if ($urltype) {
                                 $rightlink .= "/{$urltype['idvar']}={$matches['1']}";
                             }
                             if ($matches[2]) {
                                 $rightlink .= "/page=2";
                             }
                         }
                         if (preg_match_all('#([a-z0-9_]+)=([a-z0-9_\\+]+)#si', $current_link['query'], $matches)) {
                             foreach ($matches[0] as $match) {
                                 $rightlink .= "/{$match}";
                             }
                         }
                     }
                 }
             }
         }
     }
     // standard URL hyperlink
     return "<a href=\"{$rightlink}\" target=\"_blank\"" . ($is_external ? ' rel="nofollow"' : '') . ">{$text}</a>";
 }