src/Model/Behavior/TokenizeBehavior.php
public function tokenize($id, array $data = [])
    {
        $assoc = $this->getConfig('associationAlias');

        $tokenData = [
            'foreign_alias' => $this->_table->getAlias(),
            'foreign_table' => $this->_table->getTable(),
            'foreign_key' => $id,
            'foreign_data' => $data,
        ];
        $tokenData = array_filter($tokenData);
        if (!isset($tokenData['foreign_data'])) {
            $tokenData['foreign_data'] = [];
        }

        $table = $this->_table->$assoc;
        $token = $table->newEntity($tokenData);

        if (!$table->save($token)) {
            throw new \RuntimeException();
        }

        return $token;
    }
public function tokenize($id, array $data = [])
    {
        $assoc = $this->getConfig('associationAlias');

        $tokenData = [
            'foreign_alias' => $this->_table->getAlias(),
            'foreign_table' => $this->_table->getTable(),
            'foreign_key' => $id,
            'foreign_data' => $data,
        ];
        $tokenData = array_filter($tokenData);
        if (!isset($tokenData['foreign_data'])) {
            $tokenData['foreign_data'] = [];
        }

        $table = $this->_table->$assoc;
        $token = $table->newEntity($tokenData);

        if (!$table->save($token)) {
            throw new \RuntimeException();
        }

        return $token;
    }
public function tokenize ( $ id , array $ data = [ ] ) { $ assoc = $ this -> getConfig ( 'associationAlias' ) ; $ tokenData = [ 'foreign_alias' => $ this -> _table -> getAlias ( ) , 'foreign_table' => $ this -> _table -> getTable ( ) , 'foreign_key' => $ id , 'foreign_data' => $ data , ] ; $ tokenData = array_filter ( $ tokenData ) ; if ( ! isset ( $ tokenData [ 'foreign_data' ] ) ) { $ tokenData [ 'foreign_data' ] = [ ] ; } $ table = $ this -> _table -> $ assoc ; $ token = $ table -> newEntity ( $ tokenData ) ; if ( ! $ table -> save ( $ token ) ) { throw new \ RuntimeException ( ) ; } return $ token ; }
Creates a token for a data sample.

@param int|string $id Id
@param array $data Data
@return mixed
Creates a token for a data sample .