/** * Retrieve the table name for this DAO * * @return string */ public function getTableName() { if ($this->_tableName === null) { $class = get_called_class(); $ns = Objects::getNamespace($class); $dirs = $this->getTableNameExcludeDirs(); foreach ($dirs as $dir) { $ns = ltrim(Strings::offset($ns, $dir), '\\'); } $this->_tableName = trim(Inflector::tableize(implode('_', [Strings::stringToUnderScore($ns), Inflector::pluralize(Objects::classShortname($class))])), '_ '); $this->_tableName = str_replace('__', '_', $this->_tableName); } return $this->_tableName; }
/** * This will return the namespace of the passed object/class * * @param object|string $source * * @return string * * @deprecated */ function get_namespace($source) { return \Packaged\Helpers\Objects::getNamespace($source); }
public function testGetNamespace() { $expectations = [[null, ''], ['', ''], ['Strings', ''], ['\\Packaged\\Helpers\\Strings', '\\Packaged\\Helpers'], [new \Packaged\Helpers\Strings(), '\\Packaged\\Helpers']]; foreach ($expectations as $expect) { $this->assertEquals($expect[1], Objects::getNamespace($expect[0])); } }
/** * Execute a route and attempt to generate a response * * @param IRoute $route * @param Request $request * @param int $type * @param bool $catch * * @return CubexResponse|null|Response * @throws \Exception */ public function executeRoute(IRoute $route, Request $request, $type = self::MASTER_REQUEST, $catch = true) { $value = $route->getValue(); $this->_processParams = $params = $route->getRouteData(); //If the action has returned a valid response, lets send that back if ($value instanceof Response) { return $value; } //Attempt to see if the route is a callable if (is_callable($value)) { $value = $this->_getCallableResult($value, $params); } else { if (is_scalar($value)) { //If is fully qualified class, create class $match = '/^(\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)+$/'; if (stripos($value, '\\') !== false && preg_match($match, $value)) { $class = $value; $nsClass = Path::buildWindows(Objects::getNamespace($this), $value); try { if (class_exists($nsClass)) { $value = $this->getCubex()->make($nsClass); } else { $value = $this->getCubex()->make($class); } } catch (\Exception $e) { if (!$catch) { throw new \RuntimeException("Your route provides an invalid class '{$class}'"); } else { return null; } } } else { $call = $this->attemptCallable($value); if ($call !== null) { $value = $this->_getCallableResult($call, $params); } else { //Attempt to see if the route is a redirect $url = $this->attemptUrl($value, $request); if ($url !== null) { //Redirect to url return new RedirectResponse($url['url'], $url['code']); } else { //look for method names $method = $this->attemptMethod($value, $request); if ($method !== null) { $value = $this->_getCallableResult([$this, $method], $params); } } } } } } if ($value instanceof CubexKernel) { $value->_pathProcessed = Path::buildUnix($this->_pathProcessed, $route->getMatchedPath()); $value->_processParams = $params; } return $this->_processResponse($value, $request, $type, $catch, $params); }