Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:33:49+00:00 2026-06-15T03:33:49+00:00

A user can post a music link , as the music provider can be

  • 0

A user can post a music link, as the music provider can be varied (Youtube, Deezer, Soundcloud, etc..), I have a custom validator and a custom setLink().
In my database, a link is the video’s id (Example for youtube : CWMYxYoaRBQ)

But the consequence is that my sfValidatorDoctrineUnique does not work anymore.

My validator :

<?php

class videoValidator extends sfValidatorUrl
{
  protected function configure($options = array(), $messages = array())
  {
    parent::configure($options, $messages);
    $this->setMessage('invalid', 'Error message.');
  }

  protected function doClean($url)
  {
    $videoProvider = new videoProvider($url);
    if (false === $videoProvider->isValid())
    {
      throw new sfValidatorError($this, 'invalid', array('value' => $url));
    }

    return $url;
  }
}

?>

My videoProvider class :

class videoProvider
{
  private $url;
  private $providers = array('youtube','deezer','soundcloud');
  private $youtubePattern = '%^# Match any youtube URL
      (?:https?://)?  # Optional scheme. Either http or https
      (?:www\.)?      # Optional www subdomain
      (?:             # Group host alternatives
        youtu\.be/    # Either youtu.be,
      | youtube\.com  # or youtube.com
        (?:           # Group path alternatives
          /embed/     # Either /embed/
        | /v/         # or /v/
        | /watch\?v=  # or /watch\?v=
        )             # End path alternatives.
      )               # End host alternatives.
      ([\w-]{10,12})  # Allow 10-12 for 11 char youtube id.
      $%x';
  private $deezerPattern = '/\d+/';
  private $soundcloudPattern = '[\w-]+/[\w-]+$';

  public function __construct($url)
  {
    $this->url = $url;
  }

  /**
   * @return true / false
   */
  private function checkYoutube()
  {
    return preg_match($this->youtubePattern, $this->url) ? true : false;
  }

  /**
   * @return true / false
   */
  private function checkDeezer()
  {
     // A Deezer URL has this format : http://www.deezer.com/track/61340079

     return preg_match($this->deezerPattern, $this->url) ? true : false;
  }

  /**
   * @return true / false
   */
  private function checkSoundcloud()
  {
     // A Soundcloud URL has this format : http://soundcloud.com/[A-Z Artist]/[A-Z Title]

     return preg_match($this->soundcloudPattern, $this->url) ? true : false;
  }

  /**
   * @return true / false
   */
  public function isValid()
  {
    // check all video provider as you do in your validator
    // so it will return true if it find one, otherwise false

    foreach ($this->providers as $provider)
    {
      $function = 'check'.ucfirst($provider);

      if (true === $this->$function())
      {
        return true;
      }
    }

    return false;
  }

  /**
   * @return string
   */
  public function getId()
  {
    if ($this->checkYoutube() && preg_match($this->youtubePattern, $this->url, $matches))
    {
      return $matches[1];
    }

    if ($this->checkDeezer() && preg_match($this->deezerPattern, $this->url, $matches))
    {
      return $matches[1];
    }

    if ($this->checkSoundcloud() && preg_match($this->deezerPattern, $this->url, $matches))
    {
      return $matches[1];
    }
  }

  /**
   * @return string
   */
  public function getProvider()
  {
    if ($this->checkYoutube())
    {
      return 'youtube';
    }

    if ($this->checkDeezer())
    {
      return 'deezer';
    }

    if ($this->checkSoundcloud())
    {
      return 'soundcloud';
    }
  }
}

My Song class :

class Song extends BaseSong
{
  public function setLink($value)
  {
    // only perform this tweak if the value is a http link
    if (preg_match('/^http/i', $value))
    {
      $videoProvider = new videoProvider($value);

      // define url id
      parent::_set('link', $videoProvider->getId());

      // define type id
      $provider = $videoProvider->getProvider();
      $type     = Doctrine_Core::getTable('Type')->findOneByName($provider);

      parent::_set('type_id', $type->getId());
     }
  }
}

What I think is sfValidatorDoctrineUnique tries to compare a full URL (Form field) to a video id (Database field). How can I fix it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:33:50+00:00Added an answer on June 15, 2026 at 3:33 am

    I think I found a solution, tested and working.

    class videoValidator extends sfValidatorUrl
    {
      protected function configure($options = array(), $messages = array())
      {
        parent::configure($options, $messages);
        $this->setMessage('invalid', 'Le lien n\'est pas valide. Veuillez entrer un lien Youtube, Deezer ou Soundcloud.');
      }
    
      protected function doClean($url)
      {
        $videoProvider = new videoProvider($url);
        if (false === $videoProvider->isValid())
        {
          throw new sfValidatorError($this, 'invalid', array('value' => $url));
        }
    
        $unique = Doctrine_Core::getTable('Song')->findOneByLink($videoProvider->getId());
        if (!empty($unique))
        {
          return $videoProvider->getId();
        }
        return $url;
      }
    }
    

    I return video’s id the video already exists in database. Then, I think that sfValidatorDoctrineUnique is able to perform its test.

    Does this seem logic to you ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed Android app. From app user can post [some results etc] on
We have a website wherein a user can post information from our website to
A user can create a post. Posts have comments. A comment must belong to
I have a form where an user can post a global notice into the
(new user can't post link, so I strip all http:// from every link in
I have a user feed of image posts. Each user can post single images,
i have created an application where user can post message to their own wall
I am doing a project where user can post text, i have used TinyText.
I'm writing a CMS that user can post some news and comments. I have
I have users, posts and comments. User can post only one comment to each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.