public function generate($suggestion = null)
    {
        if (null !== $suggestion) {
            $this->dataStore->storeIdentity($suggestion, $this->mob);

            return $suggestion;
        }

        $exceptions = array();
        for ($i = 0; $i <= $this->maxRetries; $i++) {
            $generatedIdentity = null;
            try {
                $generatedIdentity = $this->generator->generateIdentity();
                $this->dataStore->storeIdentity($generatedIdentity, $this->mob);

                return $generatedIdentity;
            } catch (NonUniqueIdentityException $e) {
                // We expect non unique identity exceptions so this is fine.
                // Collect them and move on and try again if we still have
                // some tries left.
                $exceptions[] = $e;
            } catch (\Exception $e) {
                // All other exceptions are unexpected.
                throw new GenerateException($generatedIdentity, $this->mob, $exceptions, $e);
            }
        }

        throw new GenerateException(null, $this->mob, $exceptions);
    }
public function generate($suggestion = null)
    {
        if (null !== $suggestion) {
            $this->dataStore->storeIdentity($suggestion, $this->mob);

            return $suggestion;
        }

        $exceptions = array();
        for ($i = 0; $i <= $this->maxRetries; $i++) {
            $generatedIdentity = null;
            try {
                $generatedIdentity = $this->generator->generateIdentity();
                $this->dataStore->storeIdentity($generatedIdentity, $this->mob);

                return $generatedIdentity;
            } catch (NonUniqueIdentityException $e) {
                // We expect non unique identity exceptions so this is fine.
                // Collect them and move on and try again if we still have
                // some tries left.
                $exceptions[] = $e;
            } catch (\Exception $e) {
                // All other exceptions are unexpected.
                throw new GenerateException($generatedIdentity, $this->mob, $exceptions, $e);
            }
        }

        throw new GenerateException(null, $this->mob, $exceptions);
    }
public function generate ( $ suggestion = null ) { if ( null !== $ suggestion ) { $ this -> dataStore -> storeIdentity ( $ suggestion , $ this -> mob ) ; return $ suggestion ; } $ exceptions = array ( ) ; for ( $ i = 0 ; $ i <= $ this -> maxRetries ; $ i ++ ) { $ generatedIdentity = null ; try { $ generatedIdentity = $ this -> generator -> generateIdentity ( ) ; $ this -> dataStore -> storeIdentity ( $ generatedIdentity , $ this -> mob ) ; return $ generatedIdentity ; } catch ( NonUniqueIdentityException $ e ) { // We expect non unique identity exceptions so this is fine. // Collect them and move on and try again if we still have // some tries left. $ exceptions [ ] = $ e ; } catch ( \ Exception $ e ) { // All other exceptions are unexpected. throw new GenerateException ( $ generatedIdentity , $ this -> mob , $ exceptions , $ e ) ; } } throw new GenerateException ( null , $ this -> mob , $ exceptions ) ; }
Generate an identity string

@param string|null $suggestion

@return string

@throws \Dflydev\IdentityGenerator\Exception\Exception
Generate an identity string