예제 #1
0
파일: Home.php 프로젝트: nima7r/phpfox-dist
 public function checkAppInstalled($params)
 {
     $App = new \Core\App();
     try {
         $_App = $App->get($params['id']);
         return ['installed' => 'yes', 'version' => $_App->vendor];
     } catch (\Exception $e) {
         return ['error' => true, 'message' => $e->getMessage()];
     }
 }
예제 #2
0
파일: App.php 프로젝트: JerwinPRO/phpfox
 /**
  * @param null $zip
  * @return App\Object
  * @throws mixed
  */
 public function import($zip = null, $download = false, $isUpgrade = false)
 {
     if ($zip === null || empty($zip)) {
         $zip = PHPFOX_DIR_FILE . 'static/import-' . uniqid() . '.zip';
         register_shutdown_function(function () use($zip) {
             unlink($zip);
         });
         file_put_contents($zip, file_get_contents('php://input'));
     }
     if ($download) {
         $zipUrl = $zip;
         $zip = PHPFOX_DIR_FILE . 'static/import-' . uniqid() . '.zip';
         register_shutdown_function(function () use($zip) {
             unlink($zip);
         });
         file_put_contents($zip, file_get_contents($zipUrl));
     }
     $archive = new \ZipArchive();
     $archive->open($zip);
     $json = $archive->getFromName('/app.json');
     $json = json_decode($json);
     if (!isset($json->id)) {
         throw error('Not a valid App to install.');
     }
     $base = PHPFOX_DIR_SITE . 'Apps/' . $json->id . '/';
     if (!is_dir($base)) {
         mkdir($base, 0777, true);
     }
     $archive->close();
     $appPath = $base . 'import-' . uniqid() . '.zip';
     copy($zip, $appPath);
     $newZip = new \ZipArchive();
     $newZip->open($appPath);
     $newZip->extractTo($base);
     $newZip->close();
     register_shutdown_function(function () use($appPath) {
         unlink($appPath);
     });
     $lockPath = $base . 'app.lock';
     if (!$isUpgrade && file_exists($lockPath)) {
         unlink($lockPath);
     }
     $isNew = false;
     if (file_exists($lockPath)) {
         $lock = json_decode(file_get_contents($lockPath));
         $lock->updated = PHPFOX_TIME;
         file_put_contents($lockPath, json_encode($lock, JSON_PRETTY_PRINT));
     } else {
         $isNew = true;
         $this->processJson($json);
         $lock = json_encode(['installed' => PHPFOX_TIME, 'version' => $json->version], JSON_PRETTY_PRINT);
         file_put_contents($lockPath, $lock);
     }
     $CoreApp = new \Core\App();
     $Object = $CoreApp->get($json->id);
     if ($isNew) {
         $Request = \Phpfox_Request::instance();
         $this->makeKey($Object, $Request->get('auth_id'), $Request->get('auth_key'));
     }
     return $Object;
 }
예제 #3
0
    $file = array_pop($parts) . '.php';
    $dir = strtolower(implode('/', $parts));
    require_once __DIR__ . '/' . $dir . '/' . $file;
});
################################################################################
$app = new Core\App();
$app->services['db'] = new \Core\DB('mysql:host=localhost;dbname=capp;charset=utf8', 'root', 'root');
$app->services['movies'] = new \Repository\Movies($app->services['db']);
$app->services['theaters'] = new \Repository\Theaters($app->services['db']);
$app->services['showtimes'] = new \Repository\Showtimes($app->services['db']);
################################################################################
$app->getError('404', function ($request, $response) {
    $response->setStatus(Core\Response::HTTP_NOT_FOUND)->setContent(array('code' => $response::HTTP_NOT_FOUND, 'error' => $response::$statusTexts[$response::HTTP_NOT_FOUND]));
});
################################################################################
$app->get('/api/v1/{type}', function ($type, $request, $response) use($app) {
    $date = $request->query->date;
    $included = explode(',', $request->query->include);
    $model = $app->services[$type]->findAllByDate($date);
    $resp = new Core\JsonApiResponse($model, $included);
    $response->setContent($resp->format());
});
$app->get('/api/v1/{type}/{id}', function ($type, $id, $request, $response) use($app) {
    $date = $request->query->date;
    $included = explode(',', $request->query->include);
    $model = $app->services[$type]->findOneByIdAndDate($id, $date);
    $resp = new Core\JsonApiResponse($model, $included);
    $response->setContent($resp->format());
});
################################################################################
$app->start();