Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/DataSync/docs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/DataSync/docs/03_The_Which_Method.md
# The "Which" Method

The `which` method is nothing more than a super getter.
It allows you to get any "hidden" property of the job you are creating.  
Just call the `which('some_property')` from your job.

In order to know what properties you have access to,
just have a look at the properties of `\Soon\DataSync\Model\Sync`.
   
A good example of `which` usage is the following:

```php
// In your job class
private function readFileContent()
{
    $this->from('local', ['filepath' => '~/LICENSE.txt']);
    var_dump($this->which('transferType')->pull());
}
```

First, `$this->from('local', ['filepath' => '~/LICENSE.txt']);` tells DataSync to prepare an import of the LICENSE.txt file located in the Magento root dir.
This means that DataSync creates a new local TransferType (@see `\Soon\DataSync\Model\Sync::prepareTransferType`) and populates the `private $transferType` property
with an instance of `\Soon\DataSync\Model\Transfer\Type\Local`.

Then, as the `which` method gives us access to any property... we can access the TransferType (stored in `$transferType`)
by just doing:

`$this->which('transferType') // returns the instance of \Soon\DataSync\Model\Transfer\Type\Local`

And we can chain this with the `pull()` public method from `\Soon\DataSync\Model\Transfer\Type\Local`.

A clean and clever way to read the content of any file... even remote ones! Like this:

```php
$remotePdfContent = $this->from('ftp',
        ['filepath' => 'some-pdf.pdf', host' => '1.2.3.4', 'user' => 'username', 'password' => 'pw']
    )
    ->which('transferType')
    ->pull();
```

Spamworldpro Mini