sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
protected function verifyUploadedFile($file)
{
if (is_array($file['error'])) {
throw new BadRequestException("Only a single application package file is allowed for import.");
}
if (UPLOAD_ERR_OK !== ($error = $file['error'])) {
throw new InternalServerErrorException(... | Verifies the uploaed file for importing process.
@param $file
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function verifyImportFromUrl($url)
{
$extension = strtolower(pathinfo($url, PATHINFO_EXTENSION));
if (static::FILE_EXTENSION != $extension) {
throw new BadRequestException("Only package files ending with '" .
static::FILE_EXTENSION .
"' are allo... | Verifies file import from url.
@param $url
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
private function setZipFile($file)
{
$zip = new \ZipArchive();
if (true !== $zip->open($file)) {
throw new InternalServerErrorException('Error opening zip file.');
}
$this->zip = $zip;
$this->zipFilePath = $file;
} | Opens and sets the zip file for import.
@param string $file
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
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 (!i... | Sanitizes the app record description.json
@param $record
@throws \DreamFactory\Core\Exceptions\BadRequestException | entailment |
private function insertAppRecord(& $record, $ssId = null, $sc = null)
{
$record['storage_service_id'] = $ssId;
$record['storage_container'] = $sc;
$this->sanitizeAppRecord($record);
try {
$result = ServiceManager::handleRequest('system', Verbs::POST, 'app', ['fields' => ... | @param $record
@param null $ssId
@param null $sc
@return mixed
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
private function storeApplicationFiles($appInfo)
{
if (array_get($appInfo, 'type', AppTypes::NONE) === AppTypes::STORAGE_SERVICE) {
$appName = camelize(array_get($appInfo, 'name'));
$storageServiceId = array_get($appInfo, 'storage_service_id', $this->getDefaultStorageServiceId());
... | @param array $appInfo
@return array
@throws InternalServerErrorException
@throws NotFoundException | entailment |
public function importAppFromPackage($storageServiceId = null, $storageContainer = null, $record = null)
{
$record = (array)$record;
$data = $this->getAppInfo();
// merge in overriding parameters from request if given
$record = array_merge($data, $record);
\DB::beginTransac... | @param null | integer $storageServiceId
@param null | string $storageContainer
@param null | array $record
@return \DreamFactory\Core\Contracts\ServiceResponseInterface|mixed
@throws \DreamFactory\Core\Exceptions\BadRequestException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \Excepti... | entailment |
private function initExportZipFile($appName)
{
$zip = new \ZipArchive();
$tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$zipFileName = $tmpDir . $appName . '.' . static::FILE_EXTENSION;
$this->zip = $zip;
$this->zipFilePath = $zipFileName;
... | Initialize export zip file.
@param $appName
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
private function packageAppDescription($app)
{
$record = [
'name' => $app->name,
'description' => $app->description,
'is_active' => $app->is_active,
'type' => $app->type,
'path' ... | Package app info for export.
@param $app
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
private function packageAppFiles($app)
{
$appName = $app->name;
$zipFileName = $this->zipFilePath;
$storageServiceId = $app->storage_service_id;
$storageFolder = $app->storage_container;
if (empty($storageServiceId)) {
$storageServiceId = $this->getDefaultStorage... | Package app files for export.
@param $app
@return bool
@throws \DreamFactory\Core\Exceptions\ForbiddenException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\NotFoundException | entailment |
private function packageServices()
{
if (!empty($this->exportServices)) {
$services = [];
foreach ($this->exportServices as $serviceName) {
if (is_numeric($serviceName)) {
/** @type Service $service */
$service = Service::find(... | Package services for export.
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
private function packageSchemas()
{
if (!empty($this->exportSchemas)) {
$schemas = [];
foreach ($this->exportSchemas as $serviceName => $component) {
if (is_array($component)) {
$component = implode(',', $component);
}
... | Package schemas for export.
@return bool
@throws InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\RestException | entailment |
public function exportAppAsPackage($includeFiles = true, $includeData = false)
{
/** @type App $app */
$app = App::find($this->exportAppId);
if (empty($app)) {
throw new NotFoundException('App not found in database with app id - ' . $this->exportAppId);
}
$appNa... | @param bool|true $includeFiles
@param bool|false $includeData
@return null
@throws \DreamFactory\Core\Exceptions\NotFoundException
@throws \Exception | entailment |
public function getMethodAttribute($method)
{
if (is_array($method)) {
return $method;
} else {
if (is_string($method)) {
$method = (integer)$method;
}
}
return VerbsMask::maskToArray($method);
} | Converts verb masks to array of verbs (string) as needed.
@param $method
@return string | entailment |
public function setMethodAttribute($method)
{
if (is_array($method)) {
$action = 0;
foreach ($method as $verb) {
$action = $action | VerbsMask::toNumeric($verb);
}
} else {
$action = $method;
}
$this->attributes['method... | Converts methods array to verb masks
@param $method
@throws \DreamFactory\Core\Exceptions\NotImplementedException | entailment |
public function import()
{
\DB::beginTransaction();
try {
$imported = ($this->insertRole()) ?: false;
$imported = ($this->insertService()) ?: $imported;
$imported = ($this->insertRoleServiceAccess()) ?: $imported;
$imported = ($this->insertApp()) ?: $... | Imports the packages.
@throws \Exception
@return bool | entailment |
protected function insertRole()
{
$data = $this->package->getResourceFromZip('system/role.json');
$roles = $this->cleanDuplicates($data, 'system', 'role');
if (!empty($roles)) {
try {
foreach ($roles as $i => $role) {
$this->fixCommonFields($r... | Imports system/role
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertUser()
{
$data = $this->package->getResourceFromZip('system/user.json');
$users = $this->cleanDuplicates($data, 'system', 'user');
if (!empty($users)) {
try {
foreach ($users as $i => $user) {
$this->fixCommonFields($u... | Imports system/user
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\UnauthorizedException | entailment |
protected static function updateUserPassword($users)
{
if (!empty($users)) {
foreach ($users as $i => $user) {
if (isset($user['password'])) {
/** @type User $model */
$model = User::where('email', '=', $user['email'])->first();
... | Updates user password when package is secured with a password.
@param $users
@throws \DreamFactory\Core\Exceptions\BadRequestException | entailment |
protected function insertUserAppRole()
{
$usersInZip = $this->package->getResourceFromZip('system/user.json');
$imported = false;
if (!empty($usersInZip)) {
try {
foreach ($usersInZip as $uiz) {
$uar = $uiz['user_to_app_to_role_by_user_id'];
... | Imports user_to_app_to_role_by_user_id relation.
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertService()
{
$data = $this->package->getResourceFromZip('system/service.json');
$services = $this->cleanDuplicates($data, 'system', 'service');
if (!empty($services)) {
try {
foreach ($services as $i => $service) {
unse... | Imports system/service
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertRoleServiceAccess()
{
$rolesInZip = $this->package->getResourceFromZip('system/role.json');
$imported = false;
if (!empty($rolesInZip)) {
try {
foreach ($rolesInZip as $riz) {
$rsa = $riz['role_service_access_by_role_i... | Imports Role Service Access relations for role.
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function getErrorDetails(\Exception $e, $trace = false)
{
$msg = $e->getMessage();
if ($e instanceof DfException) {
$context = $e->getContext();
if (is_array($context)) {
$context = print_r($context, true);
}
if (!empty($conte... | Returns details from exception.
@param \Exception $e
@param bool $trace
@return string | entailment |
protected function isDuplicateRoleServiceAccess($rsa)
{
$roleId = array_get($rsa, 'role_id');
$serviceId = array_get($rsa, 'service_id');
$component = array_get($rsa, 'component');
$verbMask = array_get($rsa, 'verb_mask');
$requestorMask = array_get($rsa, 'requestor_mask');
... | Checks for duplicate role_service_access relation.
@param $rsa
@return bool | entailment |
protected function isDuplicateUserAppRole($uar)
{
$userId = $uar['user_id'];
$appId = $uar['app_id'];
$roleId = $uar['role_id'];
return UserAppRole::whereRaw(
"user_id = '$userId' AND
role_id = '$roleId' AND
app_id = '$appId'"
)->exists(... | Checks for duplicate user_to_app_to_role relation.
@param $uar
@return bool | entailment |
protected function insertApp()
{
$data = $this->package->getResourceFromZip('system/app.json');
$apps = $this->cleanDuplicates($data, 'system', 'app');
if (!empty($apps)) {
try {
foreach ($apps as $i => $app) {
$this->fixCommonFields($app);
... | Imports system/app
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertOtherResource()
{
$items = $this->package->getNonStorageServices();
$imported = false;
foreach ($items as $service => $resources) {
foreach ($resources as $resourceName => $details) {
try {
$api = $service . '/' . $res... | Imports resources that does not need to inserted in a specific order.
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertDbTableResources($service)
{
$data = $this->package->getResourceFromZip($service . '/_table' . '.json');
if (!empty($data)) {
foreach ($data as $table) {
$tableName = array_get($table, 'name');
$resource = '_table/' . $tableName;
... | Insert DB table data.
@param $service
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertEventScripts()
{
if (empty($data = $this->package->getResourceFromZip('system/event_script.json'))) {
// pre-2.3.0 version
$data = $this->package->getResourceFromZip('system/event.json');
}
$scripts = $this->cleanDuplicates($data, 'system', 'e... | Imports system/event_scripts.
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function insertGenericResources($service, $resource)
{
$data = $this->package->getResourceFromZip($service . '/' . $resource . '.json');
$merged = $this->mergeSchemas($service, $resource, $data);
$records = $this->cleanDuplicates($data, $service, $resource);
if (!empty($re... | Imports generic resources.
@param string $service
@param string $resource
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected function mergeSchemas($service, $resource, $data)
{
$merged = false;
if ('db/_schema' === $service . '/' . $resource) {
$payload =
(true === config('df.always_wrap_resources')) ? [config('df.resources_wrapper') => $data] : $data;
$result = ServiceMan... | Merges any schema changes.
@param $service
@param $resource
@param $data
@return bool | entailment |
protected function storeFiles()
{
$items = $this->package->getStorageServices();
$stored = false;
foreach ($items as $service => $resources) {
if (is_string($resources)) {
$resources = explode(',', $resources);
}
try {
/**... | Imports app files or other storage files from package. | entailment |
protected function getNewRoleId($oldRoleId)
{
if (empty($oldRoleId)) {
return null;
}
$roles = $this->package->getResourceFromZip('system/role.json');
$roleName = null;
foreach ($roles as $role) {
if ($oldRoleId === $role['id']) {
$rol... | Finds and returns the new role id by old id.
@param int $oldRoleId
@return int|null | entailment |
protected function getNewAppId($oldAppId)
{
if (empty($oldAppId)) {
return null;
}
$apps = $this->package->getResourceFromZip('system/app.json');
$appName = null;
foreach ($apps as $app) {
if ($oldAppId === $app['id']) {
$appName = $ap... | Finds and returns new App id by old App id.
@param $oldAppId
@return int|null | entailment |
protected function getNewServiceId($oldServiceId)
{
if (empty($oldServiceId)) {
return null;
}
$services = $this->package->getResourceFromZip('system/service.json');
$serviceName = null;
foreach ($services as $service) {
if ($oldServiceId === $service... | Finds and returns the new service id by old id.
@param int $oldServiceId
@return int|null | entailment |
protected function log($level, $msg, $context = [])
{
$this->log[$level][] = $msg;
\Log::log($level, $msg, $context);
} | Stores internal log and write to system log.
@param string $level
@param string $msg
@param array $context | entailment |
protected function fixCommonFields(array & $record, $unsetIdField = true)
{
if ($unsetIdField) {
unset($record['id']);
}
if (isset($record['last_modified_by_id'])) {
unset($record['last_modified_by_id']);
}
if (isset($record['created_by_id'])) {
... | Fix some common fields to make record ready for
inserting into db table.
@param array $record
@param bool $unsetIdField | entailment |
protected function unsetImportedRelations(array & $record)
{
foreach ($record as $key => $value) {
if (strpos($key, 'role_by_') !== false ||
strpos($key, 'service_by_') !== false ||
strpos($key, 'role_service_access_by_') !== false ||
strpos($key, ... | Unset relations from record that are already imported
such as Role, Service, Role_Service_Access.
@param array $record | entailment |
protected function cleanDuplicates($data, $service, $resource)
{
$cleaned = [];
if (!empty($data)) {
$rSeg = explode('/', $resource);
$api = $service . '/' . $resource;
switch ($api) {
case 'system/admin':
case 'system/user':
... | Removes records from packaged resource that already exists
in the target instance.
@param $data
@param $service
@param $resource
@return array
@throws \DreamFactory\Core\Exceptions\ForbiddenException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\RestException | entailment |
protected function throwExceptions(\Exception $e, $genericMsg = null, $trace = false)
{
$msg = 'An error occurred. ';
if(!empty($genericMsg)){
$msg = rtrim(trim($genericMsg), '.') . '. ';
}
$errorMessage = $this->getErrorDetails($e, $trace);
$msg .= $errorMessage;... | @param \Exception $e
@param null $genericMsg
@param bool $trace
@throws \DreamFactory\Core\Exceptions\ForbiddenException
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException | entailment |
protected static function patchExisting($service, $resource, $record, $key)
{
$api = $service . '/' . $resource;
$value = array_get($record, $key);
switch ($api) {
case 'system/event_script':
case 'system/custom':
case 'user/custom':
case $serv... | @param $service
@param $resource
@param $record
@param $key
@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
@throws \DreamFactory\Core\Exceptions\RestException | entailment |
protected function isDuplicate($service, $resource, $value, $key = 'name')
{
$api = $service . '/' . $resource;
switch ($api) {
case 'system/role':
return Role::where($key, $value)->exists();
case 'system/service':
return Service::where($key, $... | Checks to see if a resource record is a duplicate.
@param string $service
@param string $resource
@param mixed $value
@param string $key
@return bool
@throws \DreamFactory\Core\Exceptions\RestException | entailment |
public function handleResponse(Request $request, Response $response)
{
if ($response->getStatusCode() == 422) {
$errors = $response->getOriginalContent()['validation_errors'];
throw new HttpResponseException(
redirect()->back()->withInput($request->input())->withErro... | Handle a response from the dispatcher for the given request.
@param Request $request
@param Response $response
@return Response|mixed | entailment |
protected function bulkActionResponse(Collection $models, $transKey)
{
if ($models->count()) {
Forum::alert('success', $transKey, $models->count());
} else {
Forum::alert('warning', 'general.invalid_selection');
}
return redirect()->back();
} | Helper: Bulk action response.
@param Collection $models
@param string $transKey
@return \Illuminate\Http\RedirectResponse | entailment |
public function up()
{
$driver = Schema::getConnection()->getDriverName();
// Even though we take care of this scenario in the code,
// SQL Server does not allow potential cascading loops,
// so set the default no action and clear out created/modified by another user when deleting a ... | Run the migrations.
@return void | entailment |
public function down()
{
// Drop created tables in reverse order
// Lookup Keys
Schema::dropIfExists('lookup');
// System customizations
Schema::dropIfExists('system_custom');
// System Configuration
Schema::dropIfExists('system_config');
// File stor... | Reverse the migrations.
@return void | entailment |
public function render(array $assign_data = []) : string
{
extract($assign_data);
ob_start();
include $this->getPath();
$content = ob_get_contents();
ob_end_clean();
return $content;
} | 渲染html页面
- 在渲染页面之前应该要设置模板文件路径
@return string | entailment |
public function toArray()
{
$errorInfo['code'] = $this->getCode();
$errorInfo['context'] = $this->getContext();
$errorInfo['message'] = htmlentities($this->getMessage());
if (config('app.debug', false)) {
$trace = $this->getTraceAsString();
$trace = str_repla... | Convert this exception to array output
@return array | entailment |
public static function bulkCreate(array $records, array $params = [])
{
$records = static::fixRecords($records);
$params['admin'] = true;
return parent::bulkCreate($records, $params);
} | {@inheritdoc} | entailment |
public static function updateById($id, array $record, array $params = [])
{
$record = static::fixRecords($record);
$params['admin'] = true;
return parent::updateById($id, $record, $params);
} | {@inheritdoc} | entailment |
public static function updateByIds($ids, array $record, array $params = [])
{
$record = static::fixRecords($record);
$params['admin'] = true;
return parent::updateByIds($ids, $record, $params);
} | {@inheritdoc} | entailment |
public static function bulkUpdate(array $records, array $params = [])
{
$records = static::fixRecords($records);
$params['admin'] = true;
return parent::bulkUpdate($records, $params);
} | {@inheritdoc} | entailment |
public static function selectById($id, array $options = [], array $fields = ['*'])
{
$fields = static::cleanFields($fields);
$related = array_get($options, ApiOptions::RELATED, []);
if (is_string($related)) {
$related = explode(',', $related);
}
if ($model = stati... | {@inheritdoc} | entailment |
protected static function fixRecords(array $records)
{
if (!Arr::isAssoc($records)) {
foreach ($records as $key => $record) {
$record['is_sys_admin'] = 1;
$records[$key] = $record;
}
} else {
$records['is_sys_admin'] = 1;
}
... | Fixes supplied records to always set is_set_admin flag to true.
Encrypts passwords if it is supplied.
@param array $records
@return array | entailment |
protected static function createInternal($record, $params = [])
{
try {
/** @var App $model */
$key = array_get($record, 'api_key');
$uniqueKey = static::isApiKeyUnique($key);
$model = static::create($record);
if (empty($key) || !$uniqueKey) {
... | @param $record
@param array $params
@return array | entailment |
public static function isApiKeyUnique($key)
{
$model = static::whereApiKey($key)->first(['id']);
return (empty($model)) ? true : false;
} | Checks to see if an API Key is uniques or not
@param $key string
@return bool | entailment |
public static function getCachedInfo($id, $key = null, $default = null)
{
$cacheKey = 'app:' . $id;
try {
$result = \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () use ($id){
$app = App::whereId($id)->first();
if (empty($app)... | Returns app info cached, or reads from db if not present.
Pass in a key to return a portion/index of the cached data.
@param int $id
@param null|string $key
@param null $default
@return mixed|null | entailment |
public static function setApiKeyToAppId($api_key, $app_id)
{
$cacheKey = 'apikey2appid:' . $api_key;
\Cache::put($cacheKey, $app_id, \Config::get('df.default_cache_ttl'));
} | Use this primarily in middle-ware or where no session is established yet.
@param string $api_key
@param int $app_id | entailment |
public static function getAppIdByApiKey($api_key)
{
if (empty($api_key)) {
return null;
}
$cacheKey = 'apikey2appid:' . $api_key;
try {
return \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () use ($api_key){
return ... | Use this primarily in middle-ware or where no session is established yet.
@param string $api_key
@return int The app id | entailment |
public static function getApiKeyByAppId($id)
{
if (!empty($id)) {
// use local app caching
$key = static::getCachedInfo($id, 'api_key', null);
if (!is_null($key)) {
static::setApiKeyToAppId($key, $id);
return $key;
}
}
... | Use this primarily in middle-ware or where no session is established yet.
@param int $id
@return string|null The API key for the designated app or null if not found | entailment |
public static function getTypeByName($name)
{
/** @noinspection PhpUndefinedMethodInspection */
$typeRec = static::whereName($name)->get(['type'])->first();
return (isset($typeRec, $typeRec['type'])) ? $typeRec['type'] : null;
} | @param $name
@return null | entailment |
public function setConfigAttribute($value)
{
$this->config = (array)$value;
$localConfig = $this->getAttributeFromArray('config');
$localConfig = ($localConfig ? json_decode($localConfig, true) : []);
// take the type information and get the config_handler class
// set the co... | @param array|null $value
@throws \DreamFactory\Core\Exceptions\BadRequestException | entailment |
protected function getConfigHandler()
{
if (null !== $typeInfo = ServiceManager::getServiceType($this->type)) {
// lookup related service type config model
return $typeInfo->getConfigHandler();
}
return null;
} | Determine the handler for the extra config settings
@return \DreamFactory\Core\Contracts\ServiceConfigHandlerInterface|null
@throws \DreamFactory\Core\Exceptions\BadRequestException | entailment |
public static function cleanFields($fields)
{
$fields = parent::cleanFields($fields);
//If config is requested add id and type as they are need to pull config.
if (in_array('config', $fields)) {
$fields[] = 'id';
$fields[] = 'type';
}
//Removing conf... | Removes 'config' from field list if supplied as it chokes the model.
@param mixed $fields
@return array | entailment |
protected static function cleanResult($response, $fields)
{
$response = parent::cleanResult($response, $fields);
if (!is_array($fields)) {
$fields = explode(',', $fields);
}
//config is only available when both id and type is present. Therefore only show config if id and... | If fields is not '*' (all) then remove the empty 'config' property.
@param mixed $response
@param mixed $fields
@return array | entailment |
public function handle()
{
$path = $this->getPath();
if (is_file($path) || FileUtilities::url_exist($path)) {
$this->importPackage($path);
$this->printResult();
} elseif (is_dir($path)) {
$files = static::getFilesFromPath($path);
if (count($fi... | Runs the command. | entailment |
protected function printResult()
{
$errorCount = count($this->errors);
if ($errorCount > 0) {
$fileCount = count(static::getFilesFromPath($this->getPath()));
if ($errorCount < $fileCount) {
$this->warn('Not all files were imported successfully. See details bel... | Prints result. | entailment |
protected function importPackage($file)
{
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($extension === Packager::FILE_EXTENSION) {
$this->importOldPackage($file);
} else {
$package = new Package($file, $this->option('delete'), $this->option('passw... | Imports package.
@param $file
@throws \Exception | entailment |
protected function printImportLog()
{
if (count($this->importLog) > 0) {
$this->info('Import log');
$this->info('---------------------------------------------------------------------------------------');
foreach ($this->importLog as $il) {
$this->info('Imp... | Prints import log. | entailment |
protected static function getFilesFromPath($path)
{
$files = [];
$path = rtrim($path, '/') . DIRECTORY_SEPARATOR;
if (false !== $items = scandir($path)) {
foreach ($items as $item) {
$file = $path . $item;
if (is_file($file)) {
... | Returns packaged file(s) from import path.
@param $path
@return array | entailment |
public function addParameter(ParameterSchema $schema)
{
$key = strtolower($schema->name);
$this->parameters[$key] = $schema;
} | Sets the named parameter metadata.
@param ParameterSchema $schema | entailment |
public function getParameter($name)
{
$key = strtolower($name);
if (isset($this->parameters[$key])) {
return $this->parameters[$key];
}
return null;
} | Gets the named parameter metadata.
@param string $name parameter name
@return ParameterSchema metadata of the named parameter. Null if the named parameter does not exist. | entailment |
public static function checkExtensions($extensions)
{
if (empty($extensions)) {
$extensions = [];
} elseif (is_string($extensions)) {
$extensions = array_map('trim', explode(',', trim($extensions)));
}
foreach ($extensions as $extension) {
if (!ex... | @param string|array $extensions
@return bool Returns true if all required extensions are loaded, otherwise an exception is thrown
@throws ServiceUnavailableException | entailment |
public function setWidth(TcTable $table) {
if (!$this->width) {
$widths = [];
foreach ($table->getColumns() as $key => $column) {
$widths[$key] = $column['width'];
}
unset($widths[$this->columnIndex]);
$this->width = $this->getRemaining... | Check the max width of the stretched column. This method is called just
before we start to add data rows
@param TcTable $table
@return void | entailment |
private function getRemainingColumnWidth(TcTable $table, $width) {
if (!$this->maxWidth) {
$margins = $table->getPdf()->getMargins();
$content_width = $table->getPdf()->getPageWidth() - $margins['left'] - $margins['right'];
} else {
$content_width = $this->maxWidth;
... | Get the remaining width available, taking into account margins and
other cells width or the specified maxwidth if any.
@param TcTable $table
@param array|float $width sum of all other cells width
@return float | entailment |
public function output(Debug $plugin, array $data) {
$tmp = !$this->printObjects ? $this->purgeObjects($data, 0) : $data;
echo "<pre>";
print_r(
array_merge(
['event' => $plugin->getEventInvoker()],
$tmp
)
);
echo "</pre>";
... | {@inheritDocs} | entailment |
private function purgeObjects(array $data, $level) {
$tmp = [];
foreach ($data as $k => $v) {
if (is_array($v)) {
$tmp[$k] = ($this->deepLevel !== null && $level <= $this->deepLevel) || $this->deepLevel === null
? $this->purgeObjects($v, ++$level)
... | Replace objects by their classname, so the print_r function won't print
the whole object tree (which can be huge sometimes)
@param array $data
@param int $level
@return array | entailment |
public static function getConfig($id, $local_config = null, $protect = true)
{
$config = parent::getConfig($id, $local_config, $protect);
$serviceEventMaps = ServiceEventMap::whereServiceId($id)->get();
$maps = [];
/** @var ServiceEventMap $map */
foreach ($serviceEventMaps ... | {@inheritdoc} | entailment |
public static function setConfig($id, $config, $local_config = null)
{
if (isset($config['service_event_map'])) {
$maps = $config['service_event_map'];
if (!is_array($maps)) {
throw new BadRequestException('Service to Event map must be an array.');
}
... | {@inheritdoc} | entailment |
public static function getConfigSchema()
{
$schema = parent::getConfigSchema();
$schema[] = [
'name' => 'service_event_map',
'label' => 'Service Event',
'description' => 'Select event(s) to be used by this service.',
'type' => 'arra... | {@inheritdoc} | entailment |
public function index(Request $request)
{
$categories = $this->api('category.index')
->parameters(['where' => ['category_id' => 0], 'orderBy' => 'weight', 'orderDir' => 'asc', 'with' => ['categories', 'threads']])
->get();
event(new UserViewingI... | GET: Return an index of categories view (the forum index).
@param Request $request
@return \Illuminate\Http\Response | entailment |
public function show(Request $request)
{
$category = $this->api('category.fetch', $request->route('category'))->get();
event(new UserViewingCategory($category));
$categories = [];
if (Gate::allows('moveCategories')) {
$categories = $this->api('category.index')->paramete... | GET: Return a category view.
@param Request $request
@return \Illuminate\Http\Response | entailment |
public function store(Request $request)
{
$category = $this->api('category.store')->parameters($request->all())->post();
Forum::alert('success', 'categories.created');
return redirect(Forum::route('category.show', $category));
} | POST: Store a new category.
@param Request $request
@return \Illuminate\Http\RedirectResponse | entailment |
public function destroy(Request $request)
{
$this->api('category.delete', $request->route('category'))->parameters($request->all())->delete();
Forum::alert('success', 'categories.deleted', 1);
return redirect(config('forum.routing.prefix'));
} | DELETE: Delete a category.
@param Request $request
@return \Illuminate\Http\RedirectResponse | entailment |
public function validate($data, $throwException = true)
{
if (empty($rules = $this->getRules())) {
return true;
} else {
$validator = Validator::make($data, $rules, $this->validationMessages);
if ($validator->fails()) {
$this->errors($validator->e... | Validates data based on $this->rules.
@param array $data
@param bool|true $throwException
@return bool
@throws \DreamFactory\Core\Exceptions\BadRequestException | entailment |
public function getFromCache($key, $default = null)
{
$key = $this->getConfigBasedCachePrefix() . $key;
return $this->getFromCacheOld($key, $default);
} | @param string $key
@param mixed $default
@return mixed The value of cache associated with the given type, id and key | entailment |
public function rememberCache($key, $callback)
{
$key = $this->getConfigBasedCachePrefix() . $key;
return $this->rememberCacheOld($key, $callback);
} | @param string $key
@param mixed $callback
@return mixed | entailment |
public function rememberCacheForever($key, $callback)
{
$key = $this->getConfigBasedCachePrefix() . $key;
return $this->rememberCacheForeverOld($key, $callback);
} | @param string $key
@param mixed $callback
@return mixed | entailment |
public function getService($name)
{
// If we haven't created this service, we'll create it based on the config provided.
// todo: Caching the service is causing some strange PHP7 only memory issues.
// if (!isset($this->services[$name])) {
$service = $this->makeService($name);
// ... | Get a service instance.
@param string $name
@return \DreamFactory\Core\Contracts\ServiceInterface
@throws \DreamFactory\Core\Exceptions\NotFoundException | entailment |
public function getServiceIdByName($name)
{
$map = array_flip($this->getServiceIdNameMap());
if (array_key_exists($name, $map)) {
return $map[$name];
}
return null;
} | Get a service identifier by its name.
@param string $name
@return int|null | entailment |
public function getServiceNameById($id)
{
$map = $this->getServiceIdNameMap();
if (array_key_exists($id, $map)) {
return $map[$id];
}
return null;
} | Get a service name by its identifier.
@param int $id
@return string | entailment |
public function getServiceById($id)
{
if ($name = $this->getServiceNameById($id)) {
return $this->getService($name);
}
return null;
} | Get a service instance by its identifier.
@param int $id
@return \DreamFactory\Core\Contracts\ServiceInterface
@throws \DreamFactory\Core\Exceptions\NotFoundException | entailment |
public function getServiceNamesByType($types, $only_active = false)
{
$names = [];
$map = $this->getServiceNameTypeMap($only_active);
if (is_string($types)) {
$types = array_map('trim', explode(',', trim($types, ',')));
}
foreach ($map as $name => $type) {
... | Return all of the created service names by type.
@param string|array $types
@param bool $only_active
@return array | entailment |
public function getServiceNamesByGroup($group, $only_active = false)
{
$types = $this->getServiceTypeNames($group);
return $this->getServiceNamesByType($types, $only_active);
} | Return all of the created service names.
@param string|array $group
@param bool $only_active
@return array | entailment |
public function getServiceList($fields = null, $only_active = false)
{
$allowed = ['id', 'name', 'label', 'description', 'is_active', 'type'];
if (empty($fields)) {
$fields = $allowed;
} elseif (is_string($fields)) {
$fields = array_map('trim', explode(',', trim($fiel... | Return all of the created service info.
@param array|string $fields
@param bool $only_active
@return array | entailment |
public function getServiceListByGroup($group, $fields = null, $only_active = false)
{
$types = $this->getServiceTypeNames($group);
return $this->getServiceListByType($types, $fields, $only_active);
} | Return all of the created service info.
@param string|array $group
@param array|string $fields
@param bool $only_active
@return array | entailment |
public function purge($name)
{
try {
if ($service = $this->getService($name)) {
if ($service instanceof CacheInterface) {
$service->flush();
}
}
} catch (\Exception $ex) {
// could be due to purge triggered by Se... | Disconnect from the given service and remove from local cache.
@param string $name
@return void | entailment |
public function getServiceType($name)
{
if (isset($this->types[$name])) {
return $this->types[$name];
}
return null;
} | Return the service type info.
@param string $name
@return \DreamFactory\Core\Contracts\ServiceTypeInterface | entailment |
public function getServiceTypes($group = null)
{
ksort($this->types, SORT_NATURAL); // sort by name for display
if (!empty($group)) {
if (!empty($group) && !is_array($group)) {
$group = array_map('trim', explode(',', trim($group, ',')));
}
$group =... | Return all of the known service types.
@param string $group
@return \DreamFactory\Core\Contracts\ServiceTypeInterface[] | entailment |
public function isAccessException($service, $component, $action)
{
if (is_string($action)) {
$action = VerbsMask::toNumeric($action);
}
if ($serviceType = $this->getServiceTypeByName($service)) {
if ($typeObj = $this->getServiceType($serviceType)) {
if... | Check for a service access exception.
@param string $service
@param string $component
@param int|string $action
@return boolean True if this is a routing access exception, false otherwise
@throws \DreamFactory\Core\Exceptions\NotFoundException
@throws \DreamFactory\Core\Exceptions\NotImplementedException | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.