예제 #1
0
 public function __construct($config)
 {
     parent::__construct($config);
     $app = \Bono\App::getInstance();
     $d = explode(DIRECTORY_SEPARATOR . 'src', __DIR__);
     $this->addBaseDirectory($d[0], 5);
     $this->resolveAssetPath('vendor/img');
     $appConfig = $app->config('application');
     $app->filter('page.title', function ($key) use($app, $appConfig) {
         if (isset($app->controller)) {
             $module = Inflector::humanize($app->controller->getClass());
             return $key . ' - ' . $module;
         }
         return $key;
     });
     $app->filter('page.header', function ($key) use($appConfig) {
         if (isset($appConfig['title'])) {
             return $appConfig['title'];
         }
         return $key;
     });
     $app->filter('page.subheader', function ($key) use($app, $appConfig) {
         if (isset($app->controller)) {
             return Inflector::humanize($app->controller->getClass());
         }
         if (isset($appConfig['subtitle'])) {
             return $appConfig['subtitle'];
         }
         return $key;
     });
 }
예제 #2
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     if (!isset($options['name'])) {
         throw new \Exception('[Norm/Collection] Missing name, check collection configuration!');
     }
     $this->clazz = Inflector::classify($options['name']);
     $this->name = Inflector::tableize($this->clazz);
     if (isset($options['connection'])) {
         $this->connection = $options['connection'];
         unset($options['connection']);
         $options['debug'] = $this->connection->option('debug') ? true : false;
     }
     if (isset($options['observers'])) {
         foreach ($options['observers'] as $Observer => $observerOptions) {
             if (is_int($Observer)) {
                 $Observer = $observerOptions;
                 $observerOptions = null;
             }
             if (is_string($Observer)) {
                 $Observer = new $Observer($observerOptions);
             }
             $this->observe($Observer);
         }
     }
     if (isset($options['schema'])) {
         $this->schema = new Object($options['schema']);
         unset($options['schema']);
     } else {
         $this->schema = new Object();
     }
     $this->options = $options;
     $this->applyHook('initialized', $this);
     $this->resetCache();
 }
예제 #3
0
 public function __construct($name = null, $label = null)
 {
     if (is_null($label)) {
         $label = Inflector::humanize($name);
     }
     $this->set('name', $name);
     $this->set('label', $label);
     if (!empty($name) && $name[0] === '$') {
         $this->set('hidden', true);
     }
 }
예제 #4
0
 public function __construct(App $app, array $options = [])
 {
     // detect collection if not specified
     if (!isset($options['collection'])) {
         $explodedUri = explode('/', $options['uri']);
         $lastSegment = end($explodedUri);
         $options['collection'] = Inflector::humanize($lastSegment);
     }
     $options['name'] = strtolower($options['collection']);
     $this->addMiddleware([$this, 'innerMiddleware']);
     parent::__construct($app, $options);
 }
예제 #5
0
 /**
  * Constructor
  *
  * @param [type] $app     [description]
  * @param [type] $baseUri [description]
  */
 public function __construct($app, $baseUri)
 {
     $this->app = $app;
     $this->request = $app->request;
     $this->response = $app->response;
     $this->baseUri = $baseUri;
     $exploded = explode('/', $baseUri);
     $clazz = $this->clazz = Inflector::classify(end($exploded));
     $controller = $this;
     $response = $this->response;
     $app->filter('controller', function () use($controller) {
         return $controller;
     });
     $app->filter('controller.name', function () use($clazz) {
         return $clazz;
     });
     $app->filter('controller.uri', function ($uri) use($controller, $app) {
         if (strpos($uri, ':id')) {
             $params = $app->router->getCurrentRoute()->getParams();
             $uri = str_replace(':id', $params['id'] ?: 'null', $uri);
         }
         return $controller->getBaseUri() . $uri;
     });
     $app->filter('controller.url', function ($uri) use($controller, $app) {
         return URL::site(f('controller.uri', $uri));
     });
     $app->filter('controller.urlWithQuery', function ($uri) use($controller, $app) {
         return f('controller.url', $uri) . ($app->environment['QUERY_STRING'] ? '?' . $app->environment['QUERY_STRING'] : '');
     });
     $app->filter('controller.redirectUrl', function ($uri) use($controller) {
         return $controller->getRedirectUri();
     });
     $app->hook('bono.controller.before', function ($options) use($app, $controller, $response) {
         $template = $controller->getTemplate($options['method']);
         $response->template($template);
     });
     $app->hook('bono.controller.after', function ($options) use($app, $controller, $response) {
         $response->data($controller->data());
     });
     $this->mapRoute();
 }
예제 #6
0
 protected function humanize($name)
 {
     return Inflector::classify($name);
 }
예제 #7
0
 /**
  * Register a route model.
  *
  * @param string $key
  *
  * @return mixed
  */
 public function routeModel($key)
 {
     if (!isset($this->routeModels[$key])) {
         $Clazz = Inflector::classify($key);
         $collection = Norm::factory($this->schema($key)->get('foreign'));
         $this->routeModels[$key] = $collection->findOne($this->routeData($key));
     }
     return $this->routeModels[$key];
 }
예제 #8
0
 public function find()
 {
     $entries = array();
     $baseDir = $this->getBaseDir();
     $lockFile = $this->getLockFile();
     $lock = '';
     if (is_readable($lockFile)) {
         $lock = trim(file_get_contents($lockFile));
         if ($lock) {
             $lock = \DateTime::createFromFormat('YmdHis', $lock);
         }
     }
     if (is_dir($baseDir)) {
         if ($dh = opendir($baseDir)) {
             while (($file = readdir($dh)) !== false) {
                 $path = $baseDir . '/' . $file;
                 $pinfo = pathinfo($path);
                 if (filetype($path) === 'file' && strtolower($pinfo['extension']) === 'php') {
                     $f = explode('_', $pinfo['filename']);
                     $st = $f[1];
                     $t = \DateTime::createFromFormat('YmdHis', $f[1]);
                     $f = Inflector::humanize($f[0]);
                     $c = $pinfo['filename'];
                     $s = 'N';
                     if (isset($lock)) {
                         if ($t <= $lock) {
                             $s = 'Y';
                         }
                     }
                     $entries[] = array('class' => $c, 'title' => $f, 'time' => $t, 'stime' => $st, 'status' => $s, 'path' => $path);
                 }
             }
             closedir($dh);
         }
     }
     usort($entries, function ($a, $b) {
         return $a['time'] < $b['time'];
     });
     return $entries;
 }