-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ValidYoutubeVideo Rule * Removed extra accidental line * Update ValidYoutubeVideo.php * Delete .gitignore * Revert "Delete .gitignore" This reverts commit 0e78d94. * Only request video id * Restore .gitignore to master original * Revert "Restore .gitignore to master original" This reverts commit ff7eced. * Update .gitignore * Update README.md
- Loading branch information
1 parent
2147f8b
commit be04bbe
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Alaouy\Youtube\Rules; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
use Alaouy\Youtube\Facades\Youtube; | ||
|
||
class ValidYoutubeVideo implements Rule | ||
{ | ||
/** | ||
* Create a new rule instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
try { | ||
$videoId = Youtube::parseVidFromURL($value); | ||
$video = Youtube::getVideoInfo($videoId, ['id']); | ||
} catch (\Exception $exception) { | ||
return false; | ||
} | ||
|
||
return $video != false; | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return 'The supplied URL does not look like a Youtube URL.'; | ||
} | ||
} |