Beispiel #1
0
 /**
  * Internal building method builds all static services and some dynamic
  * services from file annotations, otherwise swagger info is loaded from
  * database or storage files for each service, if it exists.
  *
  * @throws \Exception
  */
 protected static function buildEventMaps()
 {
     \Log::info('Building event cache');
     //  Build event mapping from services in database
     //	Initialize the event map
     $processEventMap = [];
     $broadcastEventMap = [];
     //  Pull any custom swagger docs
     $result = ServiceModel::with(['serviceDocs' => function ($query) {
         $query->where('format', ApiDocFormatTypes::SWAGGER);
     }])->get();
     //	Spin through services and pull the events
     foreach ($result as $service) {
         $apiName = $service->name;
         try {
             if (empty($content = ServiceModel::getStoredContentForService($service))) {
                 throw new \Exception('  * No event content found for service.');
                 continue;
             }
             $serviceEvents = static::parseSwaggerEvents($apiName, $content);
             //	Parse the events while we get the chance...
             $processEventMap[$apiName] = ArrayUtils::get($serviceEvents, 'process', []);
             $broadcastEventMap[$apiName] = ArrayUtils::get($serviceEvents, 'broadcast', []);
             unset($content, $service, $serviceEvents);
         } catch (\Exception $ex) {
             \Log::error("  * System error building event map for service '{$apiName}'.\n{$ex->getMessage()}");
         }
     }
     static::$eventMap = ['process' => $processEventMap, 'broadcast' => $broadcastEventMap];
     //	Write event cache file
     \Cache::forever(static::EVENT_CACHE_KEY, static::$eventMap);
     \Log::info('Event cache build process complete');
 }
Beispiel #2
0
 /**
  * Sanitizes the app record description.json
  *
  * @param $record
  *
  * @throws \DreamFactory\Core\Exceptions\BadRequestException
  */
 private function sanitizeAppRecord(&$record)
 {
     if (!is_array($record)) {
         throw new BadRequestException('Invalid App data provided');
     }
     if (!isset($record['name'])) {
         throw new BadRequestException('No App name provided in description.json');
     }
     if (!isset($record['type'])) {
         $record['type'] = AppTypes::NONE;
     }
     if (isset($record['active']) && !isset($record['is_active'])) {
         $record['is_active'] = $record['active'];
         unset($record['active']);
     } else {
         if (!isset($record['is_active'])) {
             $record['is_active'] = true;
         }
     }
     if ($record['type'] === AppTypes::STORAGE_SERVICE) {
         if (!empty(ArrayUtils::get($record, 'storage_service_id'))) {
             $serviceRecord = Service::with('service_type_by_type')->whereId($record['storage_service_id'])->first();
             if (empty($serviceRecord)) {
                 throw new BadRequestException('Invalid Storage Service provided.');
             }
             $serviceType = $serviceRecord->getRelation('service_type_by_type');
             if (ServiceTypeGroups::FILE !== $serviceType->group) {
                 throw new BadRequestException('Invalid Storage Service provided.');
             }
         } else {
             $record['storage_service_id'] = $this->getDefaultStorageServiceId();
         }
         if (!empty(ArrayUtils::get($record, 'storage_container'))) {
             $record['storage_container'] = trim($record['storage_container'], '/');
         } else {
             $record['storage_container'] = Inflector::camelize($record['name']);
         }
     } else {
         $record['storage_service_id'] = null;
         $record['storage_container'] = null;
     }
     if (!isset($record['url'])) {
         $record['url'] = static::DEFAULT_URL;
     } else {
         $record['url'] = ltrim($record['url'], '/');
     }
     if (isset($record['path'])) {
         $record['path'] = ltrim($record['path'], '/');
     }
     if ($record['type'] === AppTypes::STORAGE_SERVICE || $record['type'] === AppTypes::PATH) {
         if (empty(ArrayUtils::get($record, 'path'))) {
             throw new BadRequestException('No Application Path provided in description.json');
         }
     } else {
         if ($record['type'] === AppTypes::URL) {
             if (empty(ArrayUtils::get($record, 'url'))) {
                 throw new BadRequestException('No Application URL provided in description.json');
             }
         }
     }
 }