Skip to content

Commit

Permalink
Merge branch 'develop' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Mar 30, 2022
2 parents 4a8f566 + 4fbab7e commit 7a55062
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
27 changes: 16 additions & 11 deletions src/Database/Attach/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class File extends Model

/**
* @var mixed data is a local file name or an instance of an uploaded file,
* objects of the \Symfony\Component\HttpFoundation\File\UploadedFile class.
* objects of the UploadedFile class.
*/
public $data = null;

Expand All @@ -96,7 +96,8 @@ class File extends Model

/**
* fromPost creates a file object from a file an uploaded file
* @param Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
* @param UploadedFile $uploadedFile
* @return $this
*/
public function fromPost($uploadedFile)
{
Expand All @@ -121,15 +122,18 @@ public function fromPost($uploadedFile)

/**
* fromFile creates a file object from a file on the disk
* @param string $filePath
* @param string $filename
* @return $this
*/
public function fromFile($filePath)
public function fromFile($filePath, $filename = null)
{
if ($filePath === null) {
return;
}

$file = new FileObj($filePath);
$this->file_name = $file->getFilename();
$this->file_name = empty($filename) ? $file->getFilename() : $filename;
$this->file_size = $file->getSize();
$this->content_type = $file->getMimeType();
$this->disk_name = $this->getDiskName();
Expand All @@ -141,29 +145,30 @@ public function fromFile($filePath)

/**
* fromData creates a file object from raw data
* @param $data string Raw data
* @param $filename string Filename
* @param string $data
* @param string $filename
*/
public function fromData($data, $filename)
{
if ($data === null) {
return;
}

$tempPath = temp_path($filename);
$tempName = str_replace('.', '', uniqid('', true)) . '.tmp';
$tempPath = temp_path($tempName);
FileHelper::put($tempPath, $data);

$file = $this->fromFile($tempPath);
$file = $this->fromFile($tempPath, basename($filename));
FileHelper::delete($tempPath);

return $file;
}

/**
* fromUrl creates a file object from url
* @param $url string URL
* @param $filename string Filename
* @return $this
* @param string $url
* @param string $filename
* @return self
*/
public function fromUrl($url, $filename = null)
{
Expand Down
41 changes: 40 additions & 1 deletion src/Element/Filter/ScopeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* @method ScopeDefinition scopeName(string $name) scopeName for this scope
* @method ScopeDefinition label(string $label) label for this scope
* @method ScopeDefinition value(mixed $value) current value for this scope
* @method ScopeDefinition nameFrom(string $column) nameFrom column to use for the display name
* @method ScopeDefinition nameFrom(string $column) nameFrom model attribute to use for the display name
* @method ScopeDefinition valueFrom(mixed $value) valueFrom model attribute to use for the source value
* @method ScopeDefinition descriptionFrom(string $column) descriptionFrom column to use for the description
* @method ScopeDefinition options(mixed $options) options for the scope
* @method ScopeDefinition dependsOn(array $scopes) dependsOn other scopes, when the other scopes are modified, this scope will update
Expand All @@ -36,6 +37,20 @@ public function displayAs($type): ScopeDefinition
return $this->type($type ?: $this->type);
}

/**
* scopeName sets the default value for valueFrom
*/
public function scopeName($value): ScopeDefinition
{
$this->attributes['scopeName'] = $value;

if (!isset($this->attributes['valueFrom'])) {
$this->attributes['valueFrom'] = $value;
}

return $this;
}

/**
* hasOptions returns true if options have been specified
*/
Expand All @@ -44,6 +59,30 @@ public function hasOptions(): bool
return $this->options !== null;
}

/**
* options get/set for dropdowns, radio lists and checkbox lists
* @return array|self
*/
public function options($value = null)
{
if ($value === null) {
if (is_array($this->options)) {
return $this->options;
}

if (is_callable($this->options)) {
$callable = $this->options;
return $callable();
}

return [];
}

$this->attributes['options'] = $value;

return $this;
}

/**
* setScopeValue
*/
Expand Down
17 changes: 14 additions & 3 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,22 @@ public function make($abstract, array $parameters = [])

$this->loadDeferredProviderIfNeeded($abstract);

if ($parameters) {
return $this->make(Maker::class)->make($abstract, $parameters);
// Numerical array suggests makeWithArgs, otherwise associative is makeWith params
if ($parameters && array_keys($parameters) === range(0, count($parameters) - 1)) {
return $this->makeWithArgs($abstract, $parameters);
}

return parent::make($abstract);
return parent::make($abstract, $parameters);
}

/**
* makeWithArgs uses the Maker class to resolve interfaces where manual args are
* passed in addition to resolved paramters.
* @return mixed
*/
public function makeWithArgs($abstract, array $args = [])
{
return $this->make(Maker::class)->make($abstract, $args);
}

/**
Expand Down

0 comments on commit 7a55062

Please sign in to comment.