public function isCallable($method) { if (parent::isCallable($method)) { return true; } $class = U::explodeClass($this); return strpos($method, array_pop($class)) !== false; }
private function makeCall($context, $cmd, $service, $path = null) { $method = $service; if (!empty($path) && !is_numeric($path)) { $method = $path; $path = null; } return (object) array('context' => $context, 'http' => $cmd, 'service' => $service, 'method' => $method, 'function' => $cmd . U::dashedToCamelCase($method), 'path' => $path); }
/** * @param string $name * @param SwContext|null $parent * * @return SwContext|null */ public function get($name, $parent = null) { $module = S::$n->getContextModule($name); if (empty($module)) { return null; } $class = U::className($module::getNamespace(), 'context', $name); if (!class_exists($class)) { return null; } return $this->newContext($class, $parent, $module); }
public function testJSON() { $path = __DIR__ . '/test.json'; $content = array('test' => 'property', 'array' => array('also', 1, 'property')); $this->assertNotFalse(U::storeJSON($path, $content)); $store = S::$env['gt54']; S::$env['gt54'] = false; $this->assertNotFalse(U::storeJSON($path, $content)); S::$env['gt54'] = $store; $this->assertEquals((object) $content, U::getJSON($path)); $this->assertEquals($content, U::getJSON($path, true)); unlink($path); }
private function getServiceClassFallback($context, $service) { // Check whether we have a RestService in the context namespace $class = U::className($context->namespace, 'service', 'rest'); if (class_exists($class)) { return $class; } // Next up, try for a root service $class = U::className('saltwater', 'root', 'service', $service); if (class_exists($class)) { return $class; } // Fall back to the RedBean RestService // TODO: Needs to be decoupled return 'Saltwater\\RedBean\\Service\\Rest'; }
/** * @return string */ public static function getNamespace() { $class = get_called_class(); if (!empty($class::$namespace)) { return $class::$namespace; } return U::namespaceFromClass($class); }
/** * Find the module of a caller class * * @param array $caller * @param string $provider * * @return string module name */ public function find($caller, $provider) { list(, $salt, $namespace) = U::extractFromClass($caller); $is_provider = $salt == $provider; $bit = S::$n->registry->bit($salt); foreach (S::$n->modules->reverse() as $name => $module) { /** @var Module $module */ if ($this->check($module, $is_provider, $bit, $namespace)) { return $name; } } return null; }
/** * @param Context $context * @param string $cmd * @param string $service * @param string $path */ protected function push($context, $cmd, $service, $path = null) { $method = $service; if (!empty($path) && !is_numeric($path)) { $method = $path; $path = null; } $this->chain[] = (object) array('context' => $context, 'http' => $cmd, 'service' => $service, 'method' => $method, 'function' => $cmd . U::dashedToCamelCase($method), 'path' => $path); }
/** * Get Entity class name from a name plus a module * @param string $name * @param Module $module * * @return string */ private function getEntityClass($name, $module) { return U::className($module::getNamespace(), 'entity', $name); }