|
@@ -14,6 +14,7 @@ namespace Packagist\WebBundle\Entity;
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+use Symfony\Component\Validator\ExecutionContext;
|
|
|
|
|
|
/**
|
|
|
* @ORM\Entity
|
|
@@ -21,6 +22,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|
|
* name="package",
|
|
|
* uniqueConstraints={@ORM\UniqueConstraint(name="name_idx",columns={"name"})}
|
|
|
* )
|
|
|
+ * @Assert\Callback(methods={"isRepositoryValid","isPackageUnique"})
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
*/
|
|
|
class Package
|
|
@@ -56,6 +58,12 @@ class Package
|
|
|
*/
|
|
|
private $maintainers;
|
|
|
|
|
|
+ /**
|
|
|
+ * @ORM\Column()
|
|
|
+ * @Assert\NotBlank()
|
|
|
+ */
|
|
|
+ private $repository;
|
|
|
+
|
|
|
// dist-tags / rel or runtime?
|
|
|
|
|
|
/**
|
|
@@ -68,6 +76,11 @@ class Package
|
|
|
*/
|
|
|
private $updatedAt;
|
|
|
|
|
|
+ /**
|
|
|
+ * @ORM\Column(type="datetime", nullable="true")
|
|
|
+ */
|
|
|
+ private $crawledAt;
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->versions = new \Doctrine\Common\Collections\ArrayCollection();
|
|
@@ -90,6 +103,20 @@ class Package
|
|
|
return json_encode($data);
|
|
|
}
|
|
|
|
|
|
+ public function isRepositoryValid(ExecutionContext $context)
|
|
|
+ {
|
|
|
+ if (!preg_match('#^(git://.+|https?://github.com/[^/]+/[^/]+\.git)$#', $this->repository)) {
|
|
|
+ $propertyPath = $context->getPropertyPath() . '.repository';
|
|
|
+ $context->setPropertyPath($propertyPath);
|
|
|
+ $context->addViolation('This is not a valid git repository url', array(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isPackageUnique(ExecutionContext $context)
|
|
|
+ {
|
|
|
+ // TODO check for uniqueness of package name
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get id
|
|
|
*
|
|
@@ -160,6 +187,26 @@ class Package
|
|
|
return $this->createdAt;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set repository
|
|
|
+ *
|
|
|
+ * @param string $repository
|
|
|
+ */
|
|
|
+ public function setRepository($repository)
|
|
|
+ {
|
|
|
+ $this->repository = $repository;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get repository
|
|
|
+ *
|
|
|
+ * @return string $repository
|
|
|
+ */
|
|
|
+ public function getRepository()
|
|
|
+ {
|
|
|
+ return $this->repository;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Add versions
|
|
|
*
|
|
@@ -200,23 +247,43 @@ class Package
|
|
|
return $this->updatedAt;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Add maintainers
|
|
|
- *
|
|
|
- * @param Packagist\WebBundle\Entity\User $maintainers
|
|
|
- */
|
|
|
- public function addMaintainers(\Packagist\WebBundle\Entity\User $maintainers)
|
|
|
- {
|
|
|
- $this->maintainers[] = $maintainers;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get maintainers
|
|
|
- *
|
|
|
- * @return Doctrine\Common\Collections\Collection $maintainers
|
|
|
- */
|
|
|
- public function getMaintainers()
|
|
|
- {
|
|
|
- return $this->maintainers;
|
|
|
+ /**
|
|
|
+ * Set crawledAt
|
|
|
+ *
|
|
|
+ * @param datetime $crawledAt
|
|
|
+ */
|
|
|
+ public function setCrawledAt($crawledAt)
|
|
|
+ {
|
|
|
+ $this->crawledAt = $crawledAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get crawledAt
|
|
|
+ *
|
|
|
+ * @return datetime $crawledAt
|
|
|
+ */
|
|
|
+ public function getCrawledAt()
|
|
|
+ {
|
|
|
+ return $this->crawledAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add maintainers
|
|
|
+ *
|
|
|
+ * @param Packagist\WebBundle\Entity\User $maintainers
|
|
|
+ */
|
|
|
+ public function addMaintainers(\Packagist\WebBundle\Entity\User $maintainers)
|
|
|
+ {
|
|
|
+ $this->maintainers[] = $maintainers;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get maintainers
|
|
|
+ *
|
|
|
+ * @return Doctrine\Common\Collections\Collection $maintainers
|
|
|
+ */
|
|
|
+ public function getMaintainers()
|
|
|
+ {
|
|
|
+ return $this->maintainers;
|
|
|
}
|
|
|
}
|