/** * Get the root URL for the application * * This includes : currently used protocol, server name and uri base * If object or class name is set, path to this object or class name is added to the URL * * @example without class name : 'https://saf.re/saf' * @example with the class name of User : '******' * @example with a User object of id = 1 : 'https://saf.re/saf/SAF/Framework/User/1' * @param $object object|string object or class name * @return string */ public static function getUrl($object = null) { return (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . Paths::$uri_base . (isset($object) ? SL . Names::classToUri($object) : ''); }
/** * Delete an object * * @param $parameters mixed[] * - first : the deleted object * - other parameters are not sent to the delete controller (only as_widget is kept) * @return mixed */ private function deleteObject($parameters) { $object = array_shift($parameters); $controller_uri = SL . Names::classToUri(get_class($object)) . SL . Dao::getObjectIdentifier($object) . SL . Feature::F_DELETE; return (new Main())->runController($controller_uri, $parameters); }
/** * Generates a link for to an object and feature, using parameters if needed * * @param $object object|string linked object or class name * @param $feature string linked feature name * @param $parameters string|string[]|object|object[] optional parameters list * @param $arguments string|string[] optional arguments list * @return string */ public function link($object, $feature = null, $parameters = null, $arguments = null) { // class name : not Built, not Set $class_names = is_string($object) ? $object : get_class($object); $class_name = Names::setToClass($class_names, false); $set_class = $class_name != $class_names; while (Builder::isBuilt($class_name)) { $class_name = get_parent_class($class_name); } if ($set_class) { $class_name = Names::classToSet($class_name); } // build uri $link = str_replace(BS, SL, is_object($object) && Dao::getObjectIdentifier($object) ? $class_name . SL . Dao::getObjectIdentifier($object) : $class_name); if (isset($feature)) { $link .= SL . $feature; } if (isset($parameters)) { if (!is_array($parameters)) { $parameters = [$parameters]; } foreach ($parameters as $key => $value) { if (!is_numeric($key)) { $link .= SL . $key; } if (is_object($value)) { $link .= SL . Names::classToUri(get_class($value)) . SL . Dao::getObjectIdentifier($value); } else { $link .= SL . $value; } } } // build arguments if (!empty($arguments)) { if (!is_array($arguments)) { $link .= '?' . urlencode($arguments); } else { $link .= '?'; $first = true; foreach ($arguments as $key => $value) { if ($first) { $first = false; } else { $link .= '&'; } $link .= $key . '=' . urlencode($value); } } } return SL . $link; }