示例#1
0
 public function __construct(Application $app)
 {
     $app->getAppInfo()->clearCache();
     $app->cache = $app->config = [];
     $app->collectorList = null;
     $app->getBootstrapInstance()->bootstrap($app);
 }
示例#2
0
 /**
  * Returns the active database connection
  *
  * @return  \Opis\Database\Connection
  */
 public static function getConnection()
 {
     if (static::$connection === null) {
         return static::$app->connection();
     }
     return static::$app->collect('Connections')->get(static::$connection);
 }
示例#3
0
 public function uninstall(Application $app)
 {
     $schema = $app->schema();
     $schema->drop('role_permissions');
     $schema->drop('user_roles');
     $schema->drop('permissions');
     $schema->drop('users');
     $schema->drop('roles');
 }
示例#4
0
 /**
  * Validate a CSRF token
  *
  * @param   string  $value  Token
  *
  * @return  boolean
  */
 public function validate($value)
 {
     $tokens = $this->app->session()->get($this->sessionKey, array());
     $key = array_search($value, $tokens);
     if ($key !== false) {
         unset($tokens[$key]);
         $this->app->session()->set($this->sessionKey, $tokens);
         return true;
     }
     return false;
 }
示例#5
0
 /**
  * Constructor
  * 
  * @param   \Opis\Colibri\Application $app
  */
 public function __construct(Application $app)
 {
     $this->app = $app;
     $specials = array('app' => $app, 'request' => $app->request(), 'response' => $app->response(), 't' => $app->getTranslator(), 'lang' => $app->getTranslator()->getLanguage(), 'view' => $app->getViewRouter());
     parent::__construct($app->collect('Routes'), $app->collect('Dispatchers'), null, $specials);
     $this->getRouteCollection()->notFound(function ($path) use($app) {
         return new NotFound($app->view('error.404', array('path' => $path)));
     })->accessDenied(function ($path) use($app) {
         return new AccessDenied($app->view('error.403', array('path' => $path)));
     });
     $this->getRouteCollection()->setRouter($this);
 }
示例#6
0
 /**
  * Translate a sentence
  * 
  * @param   string      $sentence
  * @param   array       $placeholders   (optional)
  * @param   string|null $lang           (optional)
  * 
  * @return  string
  */
 public function translate($sentence, $placeholders = array(), $lang = null)
 {
     if ($lang === null) {
         $lang = $this->language;
     }
     if (!isset($this->translations[$lang])) {
         $this->translations[$lang] = $this->app->translations()->read($lang, array());
     }
     $translation =& $this->translations[$lang];
     if (isset($translation[$sentence])) {
         $sentence = $translation[$sentence];
     }
     return $this->placeholder->replace($sentence, $placeholders);
 }
示例#7
0
 /**
  * Route path
  * 
  * @param   \Opis\HttpRouting\Path  $path
  * 
  * @return  mixed
  */
 public function route(BasePath $path)
 {
     $router = new AliasRouter($this->app->collect('RouteAliases'));
     $alias = $router->route(new AliasPath($path->path()));
     if ($alias !== null) {
         $path = new Path((string) $alias, $path->domain(), $path->method(), $path->isSecure(), $path->request());
     }
     $this->path = $path;
     $result = parent::route($path);
     $response = $path->request()->response();
     $response->body($result);
     $response->send();
     return $result;
 }
示例#8
0
 /**
  *  Get a list of commands
  * 
  * @return  array
  */
 public function commands()
 {
     $commands = array();
     $list = $this->app->collect('Commands')->getList();
     foreach ($list as $name => $builder) {
         try {
             $command = call_user_func_array($builder, array());
             if ($command instanceof Command) {
                 $command->setApp($this->app);
                 $commands[$name] = $command;
             }
         } catch (Excepion $e) {
         }
     }
     return $commands;
 }
示例#9
0
/**
 * @return Application
 */
function app() : Application
{
    static $app;
    if ($app === null) {
        $app = Application::getInstance();
    }
    return $app;
}
示例#10
0
 /**
  * Collect items
  * 
  * @param   string  $type
  * 
  * @return  @return  \Opis\Colibri\Collectors\AbstractCollector
  * 
  * @throws \Exception
  */
 public function collect($type)
 {
     if (null === $this->app->config()->read("collectors.{$type}")) {
         throw new \Exception('Unknown collector type "' . $type . '"');
     }
     $collector = $this->container()->make($type, array($this->app));
     return $this->dispatch(new CollectorEntry($type, $collector));
 }
示例#11
0
 /**
  * Unregister module's assets
  * 
  * @param   string   $module
  * 
  * @return  boolean
  */
 public function unregisterAssets($module)
 {
     $module = $this->toModuleId($module);
     if ($this->isEnabled($module)) {
         return false;
     }
     $path = $this->app->info()->assetsPath() . '/module/' . $module;
     if (!file_exists($path) || !is_link($path)) {
         return false;
     }
     return unlink($path);
 }
示例#12
0
 /**
  * Stringify
  * 
  * @return  string
  */
 public function __toString()
 {
     if ($this->renderedContent === null) {
         try {
             $this->renderedContent = $this->app->render($this);
             if (!is_string($this->renderedContent)) {
                 $this->renderedContent = (string) $this->renderedContent;
             }
         } catch (Exception $e) {
             $this->renderedContent = (string) $e;
         }
     }
     return $this->renderedContent;
 }
示例#13
0
 /**
  * Generates a CSRF token
  *
  * @return  string
  */
 public function csrfToken()
 {
     return $this->app->csrfToken();
 }
示例#14
0
 public function __construct()
 {
     $this->instances[Application::class] = Application::getInstance();
 }
示例#15
0
 /**
  * Uninstall the module
  * 
  * @return  boolean
  */
 public function uninstall()
 {
     return $this->app->getModuleManager()->uninstall($this->module);
 }
示例#16
0
 /**
  * Constructor
  * 
  * @param   \Opis\Colibri\Application   $app
  */
 public function __construct(Application $app)
 {
     $this->app = $app;
     parent::__construct($app->collect('Validators')->getList());
 }
示例#17
0
 /**
  * Validator's callback
  * 
  * @param   string  $token
  * @return  boolean
  */
 protected function validateCsrf($token)
 {
     return $this->app->csrfValidate($token);
 }
示例#18
0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================================ */
use Opis\Colibri\Application;
use Whoops\Run as WhoopsRun;
use Whoops\Handler\JsonResponseHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Handler\PlainTextHandler;
use Whoops\Util\Misc;
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('opcache.enable', 0);
$loader = (require_once 'vendor/autoload.php');
if (getenv('APP_PRODUCTION') === false) {
    $whoops = new WhoopsRun();
    if (Misc::isCommandLine()) {
        $whoops->pushHandler(new PlainTextHandler());
    } elseif (Misc::isAjaxRequest()) {
        $whoops->pushHandler(new JsonResponseHandler());
    } else {
        $whoops->pushHandler(new PrettyPageHandler());
    }
    $whoops->register();
}
$app = new Application(__DIR__, $loader);
return $app->bootstrap();
示例#19
0
 /**
  * Constructor
  * 
  * @param   \Opis\Colibri\Application   $app
  */
 public function __construct(Application $app)
 {
     $this->app = $this->param = $app;
     parent::__construct($app->collect('Views'), $app->collect('ViewEngines'));
 }
示例#20
0
 public function disable(Application $app)
 {
     $app->getCollectorManager()->unregisterCollector('permissions');
 }