Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
- Correção de bug que não atualizava o novo nome da extensão do arqui…
Browse files Browse the repository at this point in the history
…vo na função setSaveAs
  • Loading branch information
FernandoZueet committed Jan 16, 2018
1 parent 2292a1c commit 3311edf
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 45 deletions.
27 changes: 24 additions & 3 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,32 @@ public function validExecute(array $arrayExecutes)
//execute functions validates
$this->setClassExecutes($arrayExecutes);
$countArray = [];
$contFile = -1;
$contClass = -1;
foreach ($this->getFile() as $ifile) {
$contFile++; //count file
$contClass = -1;
foreach ($this->getClassExecutes() as $vld) {
if (array_key_exists($vld->getDirectory(), $countArray)) { //Equal directory count

$contClass++; //count class

//Equal directory count
if (array_key_exists($vld->getDirectory(), $countArray)) {
$countArray[$vld->getDirectory()]++;
} else {
$countArray[$vld->getDirectory()] = 1;
}
$this->setFileActive($ifile); //set file active container
$vld->valid($this); //valid class executes

//update name extension save as
if ($vld->getSaveAs()) {
$ifile = $this->getFileClass()->updateFile($this, $contFile, 'new_name', pathinfo($vld->getDirectory().'/'.$ifile['new_name'], PATHINFO_FILENAME).'.'.$vld->getSaveAs())[$contFile];
}

//set file active container
$this->setFileActive($ifile);

//valid class executes
$vld->valid($this);
}
}

Expand Down Expand Up @@ -467,11 +484,15 @@ public function execute() : bool
$contFile++; //count file
$contClass = -1;
foreach ($this->getClassExecutes() as $vld) {

$contClass++; //count class

if ($contClass >= 1 && $this->getUnionExecutes()) { //union executes functions
$ifile = $this->getFileClass()->updateFile($this, $contFile, 'tmp_name', $vld->getDirectory().'/'.$ifile['new_name'])[$contFile];
}

$this->setFileActive($ifile); //set file active container

if ($vld->execute($this)) { //execute functions
$return++; //count success
};
Expand Down
1 change: 1 addition & 0 deletions File.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function updateFile(Core $container, int $pos, string $indice, $newValue)
{
$file = $container->getFile();
$file[$pos][$indice] = $newValue;
$container->setFile($file);
return $file;
}

Expand Down
11 changes: 9 additions & 2 deletions Tests/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function TestUploadSimples()
$filesInput['name'][0] = 'upload_teste.webp';
$filesInput['size'][0] = '81123';
$filesInput['type'][0] = 'image/webp';

// $filesInput['tmp_name'][1] = 'C:\upload_teste2.webp';
// $filesInput['name'][1] = 'upload_teste.webp';
// $filesInput['size'][1] = '81123';
// $filesInput['type'][1] = 'image/webp';

//---------------------------------------------------------

Expand Down Expand Up @@ -53,7 +58,7 @@ public function TestUploadSimples()
* ->setHeight(100) - height (int)
*/
$resize = new \Upload\ResizeImage();
$resize->setDirectory('C:\upload')->setPorc(95)->setWidth(300)->setHeight(300);
$resize->setDirectory('C:\upload')->setSaveAs('jpg')->setPorc(95)->setWidth(300)->setHeight(300);

//---------------------------------------------------------

Expand All @@ -67,7 +72,7 @@ public function TestUploadSimples()
* ->validExecute([$upload2, $upload]) - array classes execute functions
*/
$core = new \Upload\Core();
$core->setMessage(new \Upload\Langs\PtBr())->setFile($filesInput ?? [])->setUploadMultiple(true)
$core->setMessage(new \Upload\Langs\PtBr())->setFile($filesInput ?? [])->setUploadMultiple(false)
->setObjValids([$validaJpg, $validaPng])
->validExecute([$resize]);

Expand All @@ -84,6 +89,8 @@ public function TestUploadSimples()

//---------------------------------------------------------

var_dump($core->getFile());

/**
* execute functions
*
Expand Down
6 changes: 1 addition & 5 deletions Upload/CropImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/FilterImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/FlipImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/GamaCorrectImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/ResizeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
}else{
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/RotateImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/TextImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//id image resource
$image = $imggd->imgCreateFrom($file, $file['tmp_name']);
Expand Down
6 changes: 1 addition & 5 deletions Upload/WatermarksImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ public function execute(Core $container) : bool
$file = $container->getFileActive();

//directory final
if ($this->getSaveAs()) {
$directory = $this->getDirectory().'/'.pathinfo($this->getDirectory().'/'.$file['new_name'], PATHINFO_FILENAME).'.'.$this->getSaveAs();
} else {
$directory = $this->getDirectory().'/'.$file['new_name'];
}
$directory = $this->getDirectory().'/'.$file['new_name'];

//reorganized image logo array
if (is_string($this->getImageLogo())) {
Expand Down

0 comments on commit 3311edf

Please sign in to comment.