Esempio n. 1
0
 public function isCallable($method)
 {
     if (parent::isCallable($method)) {
         return true;
     }
     $class = U::explodeClass($this);
     return strpos($method, array_pop($class)) !== false;
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 /**
  * @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);
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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';
 }
Esempio n. 6
0
 /**
  * @return string
  */
 public static function getNamespace()
 {
     $class = get_called_class();
     if (!empty($class::$namespace)) {
         return $class::$namespace;
     }
     return U::namespaceFromClass($class);
 }
Esempio n. 7
0
 /**
  * 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;
 }
Esempio n. 8
0
 /**
  * @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);
 }
Esempio n. 9
0
 /**
  * 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);
 }