repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.setServices | public function setServices(array $blockServices)
{
foreach ($blockServices as $name => $service) {
$this->add($name, $service);
}
} | php | public function setServices(array $blockServices)
{
foreach ($blockServices as $name => $service) {
$this->add($name, $service);
}
} | [
"public",
"function",
"setServices",
"(",
"array",
"$",
"blockServices",
")",
"{",
"foreach",
"(",
"$",
"blockServices",
"as",
"$",
"name",
"=>",
"$",
"service",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"service",
")",
";",
"}"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L100-L105 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.getServices | public function getServices()
{
foreach ($this->services as $name => $id) {
if (\is_string($id)) {
$this->load($id);
}
}
return $this->sortServices($this->services);
} | php | public function getServices()
{
foreach ($this->services as $name => $id) {
if (\is_string($id)) {
$this->load($id);
}
}
return $this->sortServices($this->services);
} | [
"public",
"function",
"getServices",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"services",
"as",
"$",
"name",
"=>",
"$",
"id",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L110-L119 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.getServicesByContext | public function getServicesByContext($context, $includeContainers = true)
{
if (!\array_key_exists($context, $this->contexts)) {
return [];
}
$services = [];
$containers = $this->container->getParameter('sonata.block.container.types');
foreach ($this->contexts[$context] as $name) {
if (!$includeContainers && \in_array($name, $containers, true)) {
continue;
}
$services[$name] = $this->getService($name);
}
return $this->sortServices($services);
} | php | public function getServicesByContext($context, $includeContainers = true)
{
if (!\array_key_exists($context, $this->contexts)) {
return [];
}
$services = [];
$containers = $this->container->getParameter('sonata.block.container.types');
foreach ($this->contexts[$context] as $name) {
if (!$includeContainers && \in_array($name, $containers, true)) {
continue;
}
$services[$name] = $this->getService($name);
}
return $this->sortServices($services);
} | [
"public",
"function",
"getServicesByContext",
"(",
"$",
"context",
",",
"$",
"includeContainers",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"contexts",
")",
")",
"{",
"return",
"[",
"]",... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L124-L143 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.getLoadedServices | public function getLoadedServices()
{
$services = [];
foreach ($this->services as $service) {
if (!$service instanceof BlockServiceInterface) {
continue;
}
$services[] = $service;
}
return $services;
} | php | public function getLoadedServices()
{
$services = [];
foreach ($this->services as $service) {
if (!$service instanceof BlockServiceInterface) {
continue;
}
$services[] = $service;
}
return $services;
} | [
"public",
"function",
"getLoadedServices",
"(",
")",
"{",
"$",
"services",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"services",
"as",
"$",
"service",
")",
"{",
"if",
"(",
"!",
"$",
"service",
"instanceof",
"BlockServiceInterface",
")",
"{",... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L148-L161 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.validate | public function validate(ErrorElement $errorElement, BlockInterface $block)
{
if (!$block->getId() && !$block->getType()) {
return;
}
if ($this->inValidate) {
return;
}
// As block can be nested, we only need to validate the main block, no the children
try {
$this->inValidate = true;
$this->get($block)->validateBlock($errorElement, $block);
$this->inValidate = false;
} catch (\Exception $e) {
$this->inValidate = false;
}
} | php | public function validate(ErrorElement $errorElement, BlockInterface $block)
{
if (!$block->getId() && !$block->getType()) {
return;
}
if ($this->inValidate) {
return;
}
// As block can be nested, we only need to validate the main block, no the children
try {
$this->inValidate = true;
$this->get($block)->validateBlock($errorElement, $block);
$this->inValidate = false;
} catch (\Exception $e) {
$this->inValidate = false;
}
} | [
"public",
"function",
"validate",
"(",
"ErrorElement",
"$",
"errorElement",
",",
"BlockInterface",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"$",
"block",
"->",
"getId",
"(",
")",
"&&",
"!",
"$",
"block",
"->",
"getType",
"(",
")",
")",
"{",
"return",
... | @todo: this function should be remove into a proper statefull object
{@inheritdoc} | [
"@todo",
":",
"this",
"function",
"should",
"be",
"remove",
"into",
"a",
"proper",
"statefull",
"object"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L168-L186 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.load | private function load($type)
{
if (!$this->has($type)) {
throw new \RuntimeException(sprintf('The block service `%s` does not exist', $type));
}
if (!$this->services[$type] instanceof BlockServiceInterface) {
$this->services[$type] = $this->container->get($type);
}
if (!$this->services[$type] instanceof BlockServiceInterface) {
throw new \RuntimeException(sprintf('The service %s does not implement BlockServiceInterface', $type));
}
return $this->services[$type];
} | php | private function load($type)
{
if (!$this->has($type)) {
throw new \RuntimeException(sprintf('The block service `%s` does not exist', $type));
}
if (!$this->services[$type] instanceof BlockServiceInterface) {
$this->services[$type] = $this->container->get($type);
}
if (!$this->services[$type] instanceof BlockServiceInterface) {
throw new \RuntimeException(sprintf('The service %s does not implement BlockServiceInterface', $type));
}
return $this->services[$type];
} | [
"private",
"function",
"load",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The block service `%s` does not exist'",
",",
"$",
"typ... | @param string $type
@throws \RuntimeException
@return BlockServiceInterface | [
"@param",
"string",
"$type"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L195-L210 |
sonata-project/SonataBlockBundle | src/Block/BlockServiceManager.php | BlockServiceManager.sortServices | private function sortServices($services)
{
uasort($services, static function ($a, $b) {
if ($a->getName() === $b->getName()) {
return 0;
}
return ($a->getName() < $b->getName()) ? -1 : 1;
});
return $services;
} | php | private function sortServices($services)
{
uasort($services, static function ($a, $b) {
if ($a->getName() === $b->getName()) {
return 0;
}
return ($a->getName() < $b->getName()) ? -1 : 1;
});
return $services;
} | [
"private",
"function",
"sortServices",
"(",
"$",
"services",
")",
"{",
"uasort",
"(",
"$",
"services",
",",
"static",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getName",
"(",
")",
"===",
"$",
"b",
"->",
"getN... | Sort alphabetically services.
@param array $services
@return array | [
"Sort",
"alphabetically",
"services",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockServiceManager.php#L219-L230 |
sonata-project/SonataBlockBundle | src/Block/Service/ContainerBlockService.php | ContainerBlockService.buildEditForm | public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$formMapper->add('enabled');
$formMapper->add('settings', ImmutableArrayType::class, [
'keys' => [
['code', TextType::class, [
'required' => false,
'label' => 'form.label_code',
]],
['layout', TextareaType::class, [
'label' => 'form.label_layout',
]],
['class', TextType::class, [
'required' => false,
'label' => 'form.label_class',
]],
['template', ContainerTemplateType::class, [
'label' => 'form.label_template',
]],
],
'translation_domain' => 'SonataBlockBundle',
]);
$formMapper->add('children', CollectionType::class, [], [
'admin_code' => 'sonata.page.admin.block',
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
]);
} | php | public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$formMapper->add('enabled');
$formMapper->add('settings', ImmutableArrayType::class, [
'keys' => [
['code', TextType::class, [
'required' => false,
'label' => 'form.label_code',
]],
['layout', TextareaType::class, [
'label' => 'form.label_layout',
]],
['class', TextType::class, [
'required' => false,
'label' => 'form.label_class',
]],
['template', ContainerTemplateType::class, [
'label' => 'form.label_template',
]],
],
'translation_domain' => 'SonataBlockBundle',
]);
$formMapper->add('children', CollectionType::class, [], [
'admin_code' => 'sonata.page.admin.block',
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
]);
} | [
"public",
"function",
"buildEditForm",
"(",
"FormMapper",
"$",
"formMapper",
",",
"BlockInterface",
"$",
"block",
")",
"{",
"$",
"formMapper",
"->",
"add",
"(",
"'enabled'",
")",
";",
"$",
"formMapper",
"->",
"add",
"(",
"'settings'",
",",
"ImmutableArrayType"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/Service/ContainerBlockService.php#L38-L68 |
sonata-project/SonataBlockBundle | src/Block/Service/ContainerBlockService.php | ContainerBlockService.execute | public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return $this->renderResponse($blockContext->getTemplate(), [
'block' => $blockContext->getBlock(),
'decorator' => $this->getDecorator($blockContext->getSetting('layout')),
'settings' => $blockContext->getSettings(),
], $response);
} | php | public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return $this->renderResponse($blockContext->getTemplate(), [
'block' => $blockContext->getBlock(),
'decorator' => $this->getDecorator($blockContext->getSetting('layout')),
'settings' => $blockContext->getSettings(),
], $response);
} | [
"public",
"function",
"execute",
"(",
"BlockContextInterface",
"$",
"blockContext",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"renderResponse",
"(",
"$",
"blockContext",
"->",
"getTemplate",
"(",
")",
",",
"[",
"'b... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/Service/ContainerBlockService.php#L73-L80 |
sonata-project/SonataBlockBundle | src/Block/Service/ContainerBlockService.php | ContainerBlockService.getDecorator | protected function getDecorator($layout)
{
$key = '{{ CONTENT }}';
if (false === strpos($layout, $key)) {
return [];
}
$segments = explode($key, $layout);
$decorator = [
'pre' => $segments[0] ?? '',
'post' => $segments[1] ?? '',
];
return $decorator;
} | php | protected function getDecorator($layout)
{
$key = '{{ CONTENT }}';
if (false === strpos($layout, $key)) {
return [];
}
$segments = explode($key, $layout);
$decorator = [
'pre' => $segments[0] ?? '',
'post' => $segments[1] ?? '',
];
return $decorator;
} | [
"protected",
"function",
"getDecorator",
"(",
"$",
"layout",
")",
"{",
"$",
"key",
"=",
"'{{ CONTENT }}'",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"layout",
",",
"$",
"key",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"segments",
... | Returns a decorator object/array from the container layout setting.
@param string $layout
@return array | [
"Returns",
"a",
"decorator",
"object",
"/",
"array",
"from",
"the",
"container",
"layout",
"setting",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/Service/ContainerBlockService.php#L112-L126 |
sonata-project/SonataBlockBundle | src/Menu/MenuRegistry.php | MenuRegistry.add | public function add($menu)
{
if ($menu instanceof MenuBuilderInterface) {
@trigger_error(
'Adding a '.MenuBuilderInterface::class.' is deprecated since 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
return;
}
$this->names[$menu] = $menu;
} | php | public function add($menu)
{
if ($menu instanceof MenuBuilderInterface) {
@trigger_error(
'Adding a '.MenuBuilderInterface::class.' is deprecated since 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
return;
}
$this->names[$menu] = $menu;
} | [
"public",
"function",
"add",
"(",
"$",
"menu",
")",
"{",
"if",
"(",
"$",
"menu",
"instanceof",
"MenuBuilderInterface",
")",
"{",
"@",
"trigger_error",
"(",
"'Adding a '",
".",
"MenuBuilderInterface",
"::",
"class",
".",
"' is deprecated since 3.9 and will be removed... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Menu/MenuRegistry.php#L48-L60 |
sonata-project/SonataBlockBundle | src/Twig/Extension/BlockExtension.php | BlockExtension.getFunctions | public function getFunctions()
{
return [
new TwigFunction(
'sonata_block_exists',
[$this->blockHelper, 'exists']
),
new TwigFunction(
'sonata_block_render',
[$this->blockHelper, 'render'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_render_event',
[$this->blockHelper, 'renderEvent'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_include_javascripts',
[$this->blockHelper, 'includeJavascripts'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_include_stylesheets',
[$this->blockHelper, 'includeStylesheets'],
['is_safe' => ['html']]
),
];
} | php | public function getFunctions()
{
return [
new TwigFunction(
'sonata_block_exists',
[$this->blockHelper, 'exists']
),
new TwigFunction(
'sonata_block_render',
[$this->blockHelper, 'render'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_render_event',
[$this->blockHelper, 'renderEvent'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_include_javascripts',
[$this->blockHelper, 'includeJavascripts'],
['is_safe' => ['html']]
),
new TwigFunction(
'sonata_block_include_stylesheets',
[$this->blockHelper, 'includeStylesheets'],
['is_safe' => ['html']]
),
];
} | [
"public",
"function",
"getFunctions",
"(",
")",
"{",
"return",
"[",
"new",
"TwigFunction",
"(",
"'sonata_block_exists'",
",",
"[",
"$",
"this",
"->",
"blockHelper",
",",
"'exists'",
"]",
")",
",",
"new",
"TwigFunction",
"(",
"'sonata_block_render'",
",",
"[",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Twig/Extension/BlockExtension.php#L40-L68 |
sonata-project/SonataBlockBundle | src/Exception/Renderer/InlineRenderer.php | InlineRenderer.render | public function render(\Exception $exception, BlockInterface $block, Response $response = null)
{
$parameters = [
'exception' => $exception,
'block' => $block,
];
$content = $this->templating->render($this->template, $parameters);
$response = $response ?: new Response();
$response->setContent($content);
return $response;
} | php | public function render(\Exception $exception, BlockInterface $block, Response $response = null)
{
$parameters = [
'exception' => $exception,
'block' => $block,
];
$content = $this->templating->render($this->template, $parameters);
$response = $response ?: new Response();
$response->setContent($content);
return $response;
} | [
"public",
"function",
"render",
"(",
"\\",
"Exception",
"$",
"exception",
",",
"BlockInterface",
"$",
"block",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"$",
"parameters",
"=",
"[",
"'exception'",
"=>",
"$",
"exception",
",",
"'block'",
"=>"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Exception/Renderer/InlineRenderer.php#L50-L63 |
sonata-project/SonataBlockBundle | src/Block/BlockRenderer.php | BlockRenderer.render | public function render(BlockContextInterface $blockContext, Response $response = null)
{
$block = $blockContext->getBlock();
if ($this->logger) {
$this->logger->info(sprintf('[cms::renderBlock] block.id=%d, block.type=%s ', $block->getId(), $block->getType()));
}
try {
$service = $this->blockServiceManager->get($block);
$service->load($block);
$response = $service->execute($blockContext, $this->createResponse($blockContext, $response));
if (!$response instanceof Response) {
$response = null;
throw new \RuntimeException('A block service must return a Response object');
}
$response = $this->addMetaInformation($response, $blockContext, $service);
} catch (\Exception $exception) {
if ($this->logger) {
$this->logger->error(sprintf(
'[cms::renderBlock] block.id=%d - error while rendering block - %s',
$block->getId(),
$exception->getMessage()
), compact('exception'));
}
// reseting the state object
$this->lastResponse = null;
$response = $this->exceptionStrategyManager->handleException($exception, $blockContext->getBlock(), $response);
}
return $response;
} | php | public function render(BlockContextInterface $blockContext, Response $response = null)
{
$block = $blockContext->getBlock();
if ($this->logger) {
$this->logger->info(sprintf('[cms::renderBlock] block.id=%d, block.type=%s ', $block->getId(), $block->getType()));
}
try {
$service = $this->blockServiceManager->get($block);
$service->load($block);
$response = $service->execute($blockContext, $this->createResponse($blockContext, $response));
if (!$response instanceof Response) {
$response = null;
throw new \RuntimeException('A block service must return a Response object');
}
$response = $this->addMetaInformation($response, $blockContext, $service);
} catch (\Exception $exception) {
if ($this->logger) {
$this->logger->error(sprintf(
'[cms::renderBlock] block.id=%d - error while rendering block - %s',
$block->getId(),
$exception->getMessage()
), compact('exception'));
}
// reseting the state object
$this->lastResponse = null;
$response = $this->exceptionStrategyManager->handleException($exception, $blockContext->getBlock(), $response);
}
return $response;
} | [
"public",
"function",
"render",
"(",
"BlockContextInterface",
"$",
"blockContext",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"$",
"block",
"=",
"$",
"blockContext",
"->",
"getBlock",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"logger",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockRenderer.php#L74-L111 |
sonata-project/SonataBlockBundle | src/Block/BlockRenderer.php | BlockRenderer.createResponse | protected function createResponse(BlockContextInterface $blockContext, Response $response = null)
{
if (null === $response) {
$response = new Response();
}
// set the ttl from the block instance, this can be changed by the BlockService
if (($ttl = $blockContext->getBlock()->getTtl()) > 0) {
$response->setTtl($ttl);
}
return $response;
} | php | protected function createResponse(BlockContextInterface $blockContext, Response $response = null)
{
if (null === $response) {
$response = new Response();
}
// set the ttl from the block instance, this can be changed by the BlockService
if (($ttl = $blockContext->getBlock()->getTtl()) > 0) {
$response->setTtl($ttl);
}
return $response;
} | [
"protected",
"function",
"createResponse",
"(",
"BlockContextInterface",
"$",
"blockContext",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"response",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
"... | @param BlockContextInterface $blockContext
@param Response $response
@return Response | [
"@param",
"BlockContextInterface",
"$blockContext",
"@param",
"Response",
"$response"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockRenderer.php#L119-L131 |
sonata-project/SonataBlockBundle | src/Block/BlockRenderer.php | BlockRenderer.addMetaInformation | protected function addMetaInformation(Response $response, BlockContextInterface $blockContext, BlockServiceInterface $service)
{
// a response exists, use it
if ($this->lastResponse && $this->lastResponse->isCacheable()) {
$response->setTtl($this->lastResponse->getTtl());
$response->setPublic();
} elseif ($this->lastResponse) { // not cacheable
$response->setPrivate();
$response->setTtl(0);
$response->headers->removeCacheControlDirective('s-maxage');
$response->headers->removeCacheControlDirective('maxage');
}
// no more children available in the stack, reseting the state object
if (!$blockContext->getBlock()->hasParent()) {
$this->lastResponse = null;
} else { // contains a parent so storing the response
$this->lastResponse = $response;
}
return $response;
} | php | protected function addMetaInformation(Response $response, BlockContextInterface $blockContext, BlockServiceInterface $service)
{
// a response exists, use it
if ($this->lastResponse && $this->lastResponse->isCacheable()) {
$response->setTtl($this->lastResponse->getTtl());
$response->setPublic();
} elseif ($this->lastResponse) { // not cacheable
$response->setPrivate();
$response->setTtl(0);
$response->headers->removeCacheControlDirective('s-maxage');
$response->headers->removeCacheControlDirective('maxage');
}
// no more children available in the stack, reseting the state object
if (!$blockContext->getBlock()->hasParent()) {
$this->lastResponse = null;
} else { // contains a parent so storing the response
$this->lastResponse = $response;
}
return $response;
} | [
"protected",
"function",
"addMetaInformation",
"(",
"Response",
"$",
"response",
",",
"BlockContextInterface",
"$",
"blockContext",
",",
"BlockServiceInterface",
"$",
"service",
")",
"{",
"// a response exists, use it",
"if",
"(",
"$",
"this",
"->",
"lastResponse",
"&... | This method is responsible to cascade ttl to the parent block.
@param Response $response
@param BlockContextInterface $blockContext
@param BlockServiceInterface $service
@return Response | [
"This",
"method",
"is",
"responsible",
"to",
"cascade",
"ttl",
"to",
"the",
"parent",
"block",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockRenderer.php#L142-L163 |
sonata-project/SonataBlockBundle | src/Block/BlockContext.php | BlockContext.getSetting | public function getSetting($name)
{
if (!\array_key_exists($name, $this->settings)) {
throw new \RuntimeException(sprintf('Unable to find the option `%s` (%s) - define the option in the related BlockServiceInterface', $name, $this->block->getType()));
}
return $this->settings[$name];
} | php | public function getSetting($name)
{
if (!\array_key_exists($name, $this->settings)) {
throw new \RuntimeException(sprintf('Unable to find the option `%s` (%s) - define the option in the related BlockServiceInterface', $name, $this->block->getType()));
}
return $this->settings[$name];
} | [
"public",
"function",
"getSetting",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockContext.php#L59-L66 |
sonata-project/SonataBlockBundle | src/Block/BlockContext.php | BlockContext.setSetting | public function setSetting($name, $value)
{
if (!\array_key_exists($name, $this->settings)) {
throw new \RuntimeException(sprintf('It\'s not possible add non existing setting `%s`.', $name));
}
$this->settings[$name] = $value;
return $this;
} | php | public function setSetting($name, $value)
{
if (!\array_key_exists($name, $this->settings)) {
throw new \RuntimeException(sprintf('It\'s not possible add non existing setting `%s`.', $name));
}
$this->settings[$name] = $value;
return $this;
} | [
"public",
"function",
"setSetting",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"settings",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockContext.php#L71-L80 |
sonata-project/SonataBlockBundle | src/DependencyInjection/Compiler/TweakCompilerPass.php | TweakCompilerPass.process | public function process(ContainerBuilder $container)
{
$manager = $container->getDefinition('sonata.block.manager');
$registry = $container->getDefinition('sonata.block.menu.registry');
$parameters = $container->getParameter('sonata_block.blocks');
$blockTypes = $container->getParameter('sonata_blocks.block_types');
foreach ($container->findTaggedServiceIds('sonata.block') as $id => $tags) {
$definition = $container->getDefinition($id);
$definition->setPublic(true);
if (!$definition->isAutowired()) {
$this->replaceBlockName($container, $definition, $id);
}
$blockId = $id;
// Only convert class service names
if (false !== strpos($blockId, '\\')) {
$convert = (new ConvertFromFqcn());
$blockId = $convert($blockId);
}
// Skip manual defined blocks
if (!isset($blockTypes[$blockId])) {
$contexts = $this->getContextFromTags($tags);
$blockTypes[$blockId] = [
'context' => $contexts,
];
}
$manager->addMethodCall('add', [$id, $id, isset($parameters[$id]) ? $parameters[$id]['contexts'] : []]);
}
foreach ($container->findTaggedServiceIds('knp_menu.menu') as $id => $tags) {
foreach ($tags as $attributes) {
if (empty($attributes['alias'])) {
throw new \InvalidArgumentException(sprintf('The alias is not defined in the "knp_menu.menu" tag for the service "%s"', $id));
}
$registry->addMethodCall('add', [$attributes['alias']]);
}
}
$services = [];
foreach ($container->findTaggedServiceIds('sonata.block.loader') as $id => $tags) {
$services[] = new Reference($id);
}
$container->getDefinition('sonata.block.loader.service')->replaceArgument(0, $blockTypes);
$container->getDefinition('sonata.block.loader.chain')->replaceArgument(0, $services);
$this->applyContext($container);
} | php | public function process(ContainerBuilder $container)
{
$manager = $container->getDefinition('sonata.block.manager');
$registry = $container->getDefinition('sonata.block.menu.registry');
$parameters = $container->getParameter('sonata_block.blocks');
$blockTypes = $container->getParameter('sonata_blocks.block_types');
foreach ($container->findTaggedServiceIds('sonata.block') as $id => $tags) {
$definition = $container->getDefinition($id);
$definition->setPublic(true);
if (!$definition->isAutowired()) {
$this->replaceBlockName($container, $definition, $id);
}
$blockId = $id;
// Only convert class service names
if (false !== strpos($blockId, '\\')) {
$convert = (new ConvertFromFqcn());
$blockId = $convert($blockId);
}
// Skip manual defined blocks
if (!isset($blockTypes[$blockId])) {
$contexts = $this->getContextFromTags($tags);
$blockTypes[$blockId] = [
'context' => $contexts,
];
}
$manager->addMethodCall('add', [$id, $id, isset($parameters[$id]) ? $parameters[$id]['contexts'] : []]);
}
foreach ($container->findTaggedServiceIds('knp_menu.menu') as $id => $tags) {
foreach ($tags as $attributes) {
if (empty($attributes['alias'])) {
throw new \InvalidArgumentException(sprintf('The alias is not defined in the "knp_menu.menu" tag for the service "%s"', $id));
}
$registry->addMethodCall('add', [$attributes['alias']]);
}
}
$services = [];
foreach ($container->findTaggedServiceIds('sonata.block.loader') as $id => $tags) {
$services[] = new Reference($id);
}
$container->getDefinition('sonata.block.loader.service')->replaceArgument(0, $blockTypes);
$container->getDefinition('sonata.block.loader.chain')->replaceArgument(0, $services);
$this->applyContext($container);
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"manager",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'sonata.block.manager'",
")",
";",
"$",
"registry",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'s... | {@inheritdoc} | [
"{"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/DependencyInjection/Compiler/TweakCompilerPass.php#L32-L86 |
sonata-project/SonataBlockBundle | src/DependencyInjection/Compiler/TweakCompilerPass.php | TweakCompilerPass.applyContext | public function applyContext(ContainerBuilder $container)
{
$definition = $container->findDefinition('sonata.block.context_manager');
foreach ($container->getParameter('sonata_block.blocks') as $service => $settings) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByType', [$service, $settings['settings'], true]);
}
}
foreach ($container->getParameter('sonata_block.blocks_by_class') as $class => $settings) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByClass', [$class, $settings['settings'], true]);
}
}
} | php | public function applyContext(ContainerBuilder $container)
{
$definition = $container->findDefinition('sonata.block.context_manager');
foreach ($container->getParameter('sonata_block.blocks') as $service => $settings) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByType', [$service, $settings['settings'], true]);
}
}
foreach ($container->getParameter('sonata_block.blocks_by_class') as $class => $settings) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByClass', [$class, $settings['settings'], true]);
}
}
} | [
"public",
"function",
"applyContext",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"definition",
"=",
"$",
"container",
"->",
"findDefinition",
"(",
"'sonata.block.context_manager'",
")",
";",
"foreach",
"(",
"$",
"container",
"->",
"getParameter",
"(... | Apply configurations to the context manager.
@param ContainerBuilder $container | [
"Apply",
"configurations",
"to",
"the",
"context",
"manager",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/DependencyInjection/Compiler/TweakCompilerPass.php#L93-L107 |
sonata-project/SonataBlockBundle | src/DependencyInjection/Compiler/TweakCompilerPass.php | TweakCompilerPass.replaceBlockName | private function replaceBlockName(ContainerBuilder $container, Definition $definition, $id)
{
$arguments = $definition->getArguments();
// Replace empty block id with service id
if ($this->serviceDefinitionNeedsFirstArgument($definition)) {
// NEXT_MAJOR: Remove the if block when Symfony 2.8 support will be dropped.
if (method_exists($definition, 'setArgument')) {
$definition->setArgument(0, $id);
return;
}
$definition->replaceArgument(0, $id);
return;
}
if ($id !== $arguments[0] && 0 !== strpos(
(string) $container->getParameterBag()->resolveValue($definition->getClass()),
'Sonata\\BlockBundle\\Block\\Service\\'
)) {
// NEXT_MAJOR: Remove deprecation notice
@trigger_error(
sprintf('Using service id %s different from block id %s is deprecated since 3.3 and will be removed in 4.0.', $id, $arguments[0]),
E_USER_DEPRECATED
);
}
} | php | private function replaceBlockName(ContainerBuilder $container, Definition $definition, $id)
{
$arguments = $definition->getArguments();
// Replace empty block id with service id
if ($this->serviceDefinitionNeedsFirstArgument($definition)) {
// NEXT_MAJOR: Remove the if block when Symfony 2.8 support will be dropped.
if (method_exists($definition, 'setArgument')) {
$definition->setArgument(0, $id);
return;
}
$definition->replaceArgument(0, $id);
return;
}
if ($id !== $arguments[0] && 0 !== strpos(
(string) $container->getParameterBag()->resolveValue($definition->getClass()),
'Sonata\\BlockBundle\\Block\\Service\\'
)) {
// NEXT_MAJOR: Remove deprecation notice
@trigger_error(
sprintf('Using service id %s different from block id %s is deprecated since 3.3 and will be removed in 4.0.', $id, $arguments[0]),
E_USER_DEPRECATED
);
}
} | [
"private",
"function",
"replaceBlockName",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Definition",
"$",
"definition",
",",
"$",
"id",
")",
"{",
"$",
"arguments",
"=",
"$",
"definition",
"->",
"getArguments",
"(",
")",
";",
"// Replace empty block id with ser... | Replaces the empty service name with the service id. | [
"Replaces",
"the",
"empty",
"service",
"name",
"with",
"the",
"service",
"id",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/DependencyInjection/Compiler/TweakCompilerPass.php#L112-L140 |
sonata-project/SonataBlockBundle | src/DependencyInjection/Compiler/TweakCompilerPass.php | TweakCompilerPass.getContextFromTags | private function getContextFromTags(array $tags)
{
return array_filter(array_map(static function (array $attribute) {
if (\array_key_exists('context', $attribute) && \is_string($attribute['context'])) {
return $attribute['context'];
}
return null;
}, $tags));
} | php | private function getContextFromTags(array $tags)
{
return array_filter(array_map(static function (array $attribute) {
if (\array_key_exists('context', $attribute) && \is_string($attribute['context'])) {
return $attribute['context'];
}
return null;
}, $tags));
} | [
"private",
"function",
"getContextFromTags",
"(",
"array",
"$",
"tags",
")",
"{",
"return",
"array_filter",
"(",
"array_map",
"(",
"static",
"function",
"(",
"array",
"$",
"attribute",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"'context'",
",",
"$"... | @param string[][]
@return string[] | [
"@param",
"string",
"[]",
"[]"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/DependencyInjection/Compiler/TweakCompilerPass.php#L156-L165 |
sonata-project/SonataBlockBundle | src/Block/BlockLoaderChain.php | BlockLoaderChain.exists | public function exists($type)
{
foreach ($this->loaders as $loader) {
if ($loader->exists($type)) {
return true;
}
}
return false;
} | php | public function exists($type)
{
foreach ($this->loaders as $loader) {
if ($loader->exists($type)) {
return true;
}
}
return false;
} | [
"public",
"function",
"exists",
"(",
"$",
"type",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"loaders",
"as",
"$",
"loader",
")",
"{",
"if",
"(",
"$",
"loader",
"->",
"exists",
"(",
"$",
"type",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
... | Check if a given block type exists.
@param string $type Block type to check for
@return bool | [
"Check",
"if",
"a",
"given",
"block",
"type",
"exists",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Block/BlockLoaderChain.php#L40-L49 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.includeJavascripts | public function includeJavascripts($media, $basePath = '')
{
$html = '';
foreach ($this->assets['js'] as $javascript) {
$html .= "\n".sprintf('<script src="%s%s" type="text/javascript"></script>', $basePath, $javascript);
}
return $html;
} | php | public function includeJavascripts($media, $basePath = '')
{
$html = '';
foreach ($this->assets['js'] as $javascript) {
$html .= "\n".sprintf('<script src="%s%s" type="text/javascript"></script>', $basePath, $javascript);
}
return $html;
} | [
"public",
"function",
"includeJavascripts",
"(",
"$",
"media",
",",
"$",
"basePath",
"=",
"''",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"[",
"'js'",
"]",
"as",
"$",
"javascript",
")",
"{",
"$",
"html",
".... | @param string $media Unused, only kept to not break existing code
@param string $basePath Base path to prepend to the stylesheet urls
@return array|string | [
"@param",
"string",
"$media",
"Unused",
"only",
"kept",
"to",
"not",
"break",
"existing",
"code",
"@param",
"string",
"$basePath",
"Base",
"path",
"to",
"prepend",
"to",
"the",
"stylesheet",
"urls"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L134-L142 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.includeStylesheets | public function includeStylesheets($media, $basePath = '')
{
if (0 === \count($this->assets['css'])) {
return '';
}
$html = sprintf("<style type='text/css' media='%s'>", $media);
foreach ($this->assets['css'] as $stylesheet) {
$html .= "\n".sprintf('@import url(%s%s);', $basePath, $stylesheet);
}
$html .= "\n</style>";
return $html;
} | php | public function includeStylesheets($media, $basePath = '')
{
if (0 === \count($this->assets['css'])) {
return '';
}
$html = sprintf("<style type='text/css' media='%s'>", $media);
foreach ($this->assets['css'] as $stylesheet) {
$html .= "\n".sprintf('@import url(%s%s);', $basePath, $stylesheet);
}
$html .= "\n</style>";
return $html;
} | [
"public",
"function",
"includeStylesheets",
"(",
"$",
"media",
",",
"$",
"basePath",
"=",
"''",
")",
"{",
"if",
"(",
"0",
"===",
"\\",
"count",
"(",
"$",
"this",
"->",
"assets",
"[",
"'css'",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"ht... | @param string $media The css media type to use: all|screen|...
@param string $basePath Base path to prepend to the stylesheet urls
@return array|string | [
"@param",
"string",
"$media",
"The",
"css",
"media",
"type",
"to",
"use",
":",
"all|screen|",
"...",
"@param",
"string",
"$basePath",
"Base",
"path",
"to",
"prepend",
"to",
"the",
"stylesheet",
"urls"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L150-L165 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.renderEvent | public function renderEvent($name, array $options = [])
{
$eventName = sprintf('sonata.block.event.%s', $name);
/** @var BlockEvent $event */
$event = $this->eventDispatcher->dispatch($eventName, new BlockEvent($options));
$content = '';
foreach ($event->getBlocks() as $block) {
$content .= $this->render($block);
}
if ($this->stopwatch) {
$this->traces['_events'][uniqid('', true)] = [
'template_code' => $name,
'event_name' => $eventName,
'blocks' => $this->getEventBlocks($event),
'listeners' => $this->getEventListeners($eventName),
];
}
return $content;
} | php | public function renderEvent($name, array $options = [])
{
$eventName = sprintf('sonata.block.event.%s', $name);
/** @var BlockEvent $event */
$event = $this->eventDispatcher->dispatch($eventName, new BlockEvent($options));
$content = '';
foreach ($event->getBlocks() as $block) {
$content .= $this->render($block);
}
if ($this->stopwatch) {
$this->traces['_events'][uniqid('', true)] = [
'template_code' => $name,
'event_name' => $eventName,
'blocks' => $this->getEventBlocks($event),
'listeners' => $this->getEventListeners($eventName),
];
}
return $content;
} | [
"public",
"function",
"renderEvent",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"eventName",
"=",
"sprintf",
"(",
"'sonata.block.event.%s'",
",",
"$",
"name",
")",
";",
"/** @var BlockEvent $event */",
"$",
"event",
"=",
... | @param string $name
@param array $options
@return string | [
"@param",
"string",
"$name",
"@param",
"array",
"$options"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L173-L196 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.render | public function render($block, array $options = [])
{
$blockContext = $this->blockContextManager->get($block, $options);
if (!$blockContext instanceof BlockContextInterface) {
return '';
}
$stats = [];
if ($this->stopwatch) {
$stats = $this->startTracing($blockContext->getBlock());
}
$service = $this->blockServiceManager->get($blockContext->getBlock());
$this->computeAssets($blockContext, $stats);
$useCache = $blockContext->getSetting('use_cache');
$cacheKeys = $response = false;
$cacheService = $useCache ? $this->getCacheService($blockContext->getBlock(), $stats) : false;
if ($cacheService) {
$cacheKeys = array_merge(
$service->getCacheKeys($blockContext->getBlock()),
$blockContext->getSetting('extra_cache_keys')
);
if ($this->stopwatch) {
$stats['cache']['keys'] = $cacheKeys;
}
// Please note, some cache handler will always return true (js for instance)
// This will allows to have a non cacheable block, but the global page can still be cached by
// a reverse proxy, as the generated page will never get the generated Response from the block.
if ($cacheService->has($cacheKeys)) {
$cacheElement = $cacheService->get($cacheKeys);
if ($this->stopwatch) {
$stats['cache']['from_cache'] = false;
}
if (!$cacheElement->isExpired() && $cacheElement->getData() instanceof Response) {
/* @var Response $response */
if ($this->stopwatch) {
$stats['cache']['from_cache'] = true;
}
$response = $cacheElement->getData();
}
}
}
if (!$response) {
$recorder = null;
if ($this->cacheManager) {
$recorder = $this->cacheManager->getRecorder();
if ($recorder) {
$recorder->add($blockContext->getBlock());
$recorder->push();
}
}
$response = $this->blockRenderer->render($blockContext);
$contextualKeys = $recorder ? $recorder->pop() : [];
if ($this->stopwatch) {
$stats['cache']['contextual_keys'] = $contextualKeys;
}
if ($response->isCacheable() && $cacheKeys && $cacheService) {
$cacheService->set($cacheKeys, $response, (int) $response->getTtl(), $contextualKeys);
}
}
if ($this->stopwatch) {
$stats['cache']['created_at'] = $response->getDate();
$stats['cache']['ttl'] = $response->getTtl() ?: 0;
$stats['cache']['age'] = $response->getAge();
}
// update final ttl for the whole Response
if ($this->cacheHandler) {
$this->cacheHandler->updateMetadata($response, $blockContext);
}
if ($this->stopwatch) {
$this->stopTracing($blockContext->getBlock(), $stats);
}
return $response->getContent();
} | php | public function render($block, array $options = [])
{
$blockContext = $this->blockContextManager->get($block, $options);
if (!$blockContext instanceof BlockContextInterface) {
return '';
}
$stats = [];
if ($this->stopwatch) {
$stats = $this->startTracing($blockContext->getBlock());
}
$service = $this->blockServiceManager->get($blockContext->getBlock());
$this->computeAssets($blockContext, $stats);
$useCache = $blockContext->getSetting('use_cache');
$cacheKeys = $response = false;
$cacheService = $useCache ? $this->getCacheService($blockContext->getBlock(), $stats) : false;
if ($cacheService) {
$cacheKeys = array_merge(
$service->getCacheKeys($blockContext->getBlock()),
$blockContext->getSetting('extra_cache_keys')
);
if ($this->stopwatch) {
$stats['cache']['keys'] = $cacheKeys;
}
// Please note, some cache handler will always return true (js for instance)
// This will allows to have a non cacheable block, but the global page can still be cached by
// a reverse proxy, as the generated page will never get the generated Response from the block.
if ($cacheService->has($cacheKeys)) {
$cacheElement = $cacheService->get($cacheKeys);
if ($this->stopwatch) {
$stats['cache']['from_cache'] = false;
}
if (!$cacheElement->isExpired() && $cacheElement->getData() instanceof Response) {
/* @var Response $response */
if ($this->stopwatch) {
$stats['cache']['from_cache'] = true;
}
$response = $cacheElement->getData();
}
}
}
if (!$response) {
$recorder = null;
if ($this->cacheManager) {
$recorder = $this->cacheManager->getRecorder();
if ($recorder) {
$recorder->add($blockContext->getBlock());
$recorder->push();
}
}
$response = $this->blockRenderer->render($blockContext);
$contextualKeys = $recorder ? $recorder->pop() : [];
if ($this->stopwatch) {
$stats['cache']['contextual_keys'] = $contextualKeys;
}
if ($response->isCacheable() && $cacheKeys && $cacheService) {
$cacheService->set($cacheKeys, $response, (int) $response->getTtl(), $contextualKeys);
}
}
if ($this->stopwatch) {
$stats['cache']['created_at'] = $response->getDate();
$stats['cache']['ttl'] = $response->getTtl() ?: 0;
$stats['cache']['age'] = $response->getAge();
}
// update final ttl for the whole Response
if ($this->cacheHandler) {
$this->cacheHandler->updateMetadata($response, $blockContext);
}
if ($this->stopwatch) {
$this->stopTracing($blockContext->getBlock(), $stats);
}
return $response->getContent();
} | [
"public",
"function",
"render",
"(",
"$",
"block",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"blockContext",
"=",
"$",
"this",
"->",
"blockContextManager",
"->",
"get",
"(",
"$",
"block",
",",
"$",
"options",
")",
";",
"if",
"(",
... | @param mixed $block
@param array $options
@return string|null | [
"@param",
"mixed",
"$block",
"@param",
"array",
"$options"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L216-L309 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.computeAssets | protected function computeAssets(BlockContextInterface $blockContext, array &$stats = null)
{
if ($blockContext->getBlock()->hasParent()) {
return;
}
$service = $this->blockServiceManager->get($blockContext->getBlock());
$assets = [
'js' => $service->getJavascripts('all'),
'css' => $service->getStylesheets('all'),
];
if (\count($assets['js']) > 0) {
@trigger_error(
'Defining javascripts assets inside a block is deprecated since 3.3.0 and will be removed in 4.0',
E_USER_DEPRECATED
);
}
if (\count($assets['css']) > 0) {
@trigger_error(
'Defining css assets inside a block is deprecated since 3.2.0 and will be removed in 4.0',
E_USER_DEPRECATED
);
}
if ($blockContext->getBlock()->hasChildren()) {
$iterator = new \RecursiveIteratorIterator(new RecursiveBlockIterator($blockContext->getBlock()->getChildren()));
foreach ($iterator as $block) {
$assets = [
'js' => array_merge($this->blockServiceManager->get($block)->getJavascripts('all'), $assets['js']),
'css' => array_merge($this->blockServiceManager->get($block)->getStylesheets('all'), $assets['css']),
];
}
}
if ($this->stopwatch) {
$stats['assets'] = $assets;
}
$this->assets = [
'js' => array_unique(array_merge($assets['js'], $this->assets['js'])),
'css' => array_unique(array_merge($assets['css'], $this->assets['css'])),
];
} | php | protected function computeAssets(BlockContextInterface $blockContext, array &$stats = null)
{
if ($blockContext->getBlock()->hasParent()) {
return;
}
$service = $this->blockServiceManager->get($blockContext->getBlock());
$assets = [
'js' => $service->getJavascripts('all'),
'css' => $service->getStylesheets('all'),
];
if (\count($assets['js']) > 0) {
@trigger_error(
'Defining javascripts assets inside a block is deprecated since 3.3.0 and will be removed in 4.0',
E_USER_DEPRECATED
);
}
if (\count($assets['css']) > 0) {
@trigger_error(
'Defining css assets inside a block is deprecated since 3.2.0 and will be removed in 4.0',
E_USER_DEPRECATED
);
}
if ($blockContext->getBlock()->hasChildren()) {
$iterator = new \RecursiveIteratorIterator(new RecursiveBlockIterator($blockContext->getBlock()->getChildren()));
foreach ($iterator as $block) {
$assets = [
'js' => array_merge($this->blockServiceManager->get($block)->getJavascripts('all'), $assets['js']),
'css' => array_merge($this->blockServiceManager->get($block)->getStylesheets('all'), $assets['css']),
];
}
}
if ($this->stopwatch) {
$stats['assets'] = $assets;
}
$this->assets = [
'js' => array_unique(array_merge($assets['js'], $this->assets['js'])),
'css' => array_unique(array_merge($assets['css'], $this->assets['css'])),
];
} | [
"protected",
"function",
"computeAssets",
"(",
"BlockContextInterface",
"$",
"blockContext",
",",
"array",
"&",
"$",
"stats",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"blockContext",
"->",
"getBlock",
"(",
")",
"->",
"hasParent",
"(",
")",
")",
"{",
"return"... | Traverse the parent block and its children to retrieve the correct list css and javascript only for main block.
@param BlockContextInterface $blockContext
@param array $stats | [
"Traverse",
"the",
"parent",
"block",
"and",
"its",
"children",
"to",
"retrieve",
"the",
"correct",
"list",
"css",
"and",
"javascript",
"only",
"for",
"main",
"block",
"."
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L327-L373 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.startTracing | protected function startTracing(BlockInterface $block)
{
if (null !== $this->stopwatch) {
$this->traces[$block->getId()] = $this->stopwatch->start(
sprintf('%s (id: %s, type: %s)', $block->getName(), $block->getId(), $block->getType())
);
}
return [
'name' => $block->getName(),
'type' => $block->getType(),
'duration' => false,
'memory_start' => memory_get_usage(true),
'memory_end' => false,
'memory_peak' => false,
'cache' => [
'keys' => [],
'contextual_keys' => [],
'handler' => false,
'from_cache' => false,
'ttl' => 0,
'created_at' => false,
'lifetime' => 0,
'age' => 0,
],
'assets' => [
'js' => [],
'css' => [],
],
];
} | php | protected function startTracing(BlockInterface $block)
{
if (null !== $this->stopwatch) {
$this->traces[$block->getId()] = $this->stopwatch->start(
sprintf('%s (id: %s, type: %s)', $block->getName(), $block->getId(), $block->getType())
);
}
return [
'name' => $block->getName(),
'type' => $block->getType(),
'duration' => false,
'memory_start' => memory_get_usage(true),
'memory_end' => false,
'memory_peak' => false,
'cache' => [
'keys' => [],
'contextual_keys' => [],
'handler' => false,
'from_cache' => false,
'ttl' => 0,
'created_at' => false,
'lifetime' => 0,
'age' => 0,
],
'assets' => [
'js' => [],
'css' => [],
],
];
} | [
"protected",
"function",
"startTracing",
"(",
"BlockInterface",
"$",
"block",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"stopwatch",
")",
"{",
"$",
"this",
"->",
"traces",
"[",
"$",
"block",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"this"... | @param BlockInterface $block
@return array | [
"@param",
"BlockInterface",
"$block"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L380-L410 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.getEventBlocks | protected function getEventBlocks(BlockEvent $event)
{
$results = [];
foreach ($event->getBlocks() as $block) {
$results[] = [$block->getId(), $block->getType()];
}
return $results;
} | php | protected function getEventBlocks(BlockEvent $event)
{
$results = [];
foreach ($event->getBlocks() as $block) {
$results[] = [$block->getId(), $block->getType()];
}
return $results;
} | [
"protected",
"function",
"getEventBlocks",
"(",
"BlockEvent",
"$",
"event",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"event",
"->",
"getBlocks",
"(",
")",
"as",
"$",
"block",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"[",
"... | @param BlockEvent $event
@return array | [
"@param",
"BlockEvent",
"$event"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L434-L443 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.getEventListeners | protected function getEventListeners($eventName)
{
$results = [];
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {
if ($listener instanceof \Closure) {
$results[] = '{closure}()';
} elseif (\is_object($listener[0])) {
$results[] = \get_class($listener[0]);
} elseif (\is_string($listener[0])) {
$results[] = $listener[0];
} else {
$results[] = 'Unknown type!';
}
}
return $results;
} | php | protected function getEventListeners($eventName)
{
$results = [];
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {
if ($listener instanceof \Closure) {
$results[] = '{closure}()';
} elseif (\is_object($listener[0])) {
$results[] = \get_class($listener[0]);
} elseif (\is_string($listener[0])) {
$results[] = $listener[0];
} else {
$results[] = 'Unknown type!';
}
}
return $results;
} | [
"protected",
"function",
"getEventListeners",
"(",
"$",
"eventName",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"eventDispatcher",
"->",
"getListeners",
"(",
"$",
"eventName",
")",
"as",
"$",
"listener",
")",
"{",
"i... | @param string $eventName
@return array | [
"@param",
"string",
"$eventName"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L450-L467 |
sonata-project/SonataBlockBundle | src/Templating/Helper/BlockHelper.php | BlockHelper.getCacheService | protected function getCacheService(BlockInterface $block, array &$stats = null)
{
if (!$this->cacheManager) {
return false;
}
// type by block class
$class = ClassUtils::getClass($block);
$cacheServiceId = isset($this->cacheBlocks['by_class'][$class]) ? $this->cacheBlocks['by_class'][$class] : false;
// type by block service
if (!$cacheServiceId) {
$cacheServiceId = isset($this->cacheBlocks['by_type'][$block->getType()]) ? $this->cacheBlocks['by_type'][$block->getType()] : false;
}
if (!$cacheServiceId) {
return false;
}
if ($this->stopwatch) {
$stats['cache']['handler'] = $cacheServiceId;
}
return $this->cacheManager->getCacheService($cacheServiceId);
} | php | protected function getCacheService(BlockInterface $block, array &$stats = null)
{
if (!$this->cacheManager) {
return false;
}
// type by block class
$class = ClassUtils::getClass($block);
$cacheServiceId = isset($this->cacheBlocks['by_class'][$class]) ? $this->cacheBlocks['by_class'][$class] : false;
// type by block service
if (!$cacheServiceId) {
$cacheServiceId = isset($this->cacheBlocks['by_type'][$block->getType()]) ? $this->cacheBlocks['by_type'][$block->getType()] : false;
}
if (!$cacheServiceId) {
return false;
}
if ($this->stopwatch) {
$stats['cache']['handler'] = $cacheServiceId;
}
return $this->cacheManager->getCacheService($cacheServiceId);
} | [
"protected",
"function",
"getCacheService",
"(",
"BlockInterface",
"$",
"block",
",",
"array",
"&",
"$",
"stats",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cacheManager",
")",
"{",
"return",
"false",
";",
"}",
"// type by block class",
"$"... | @param BlockInterface $block
@param array $stats
@return CacheAdapterInterface|false | [
"@param",
"BlockInterface",
"$block",
"@param",
"array",
"$stats"
] | train | https://github.com/sonata-project/SonataBlockBundle/blob/476049cbb193c4cef741d031cf8e9cb056268af8/src/Templating/Helper/BlockHelper.php#L475-L499 |
swaggest/php-json-schema | src/Constraint/Properties.php | Properties.& | public function &toArray()
{
if (!isset($this->__propertyToData[Schema::DEFAULT_MAPPING])) {
return $this->__arrayOfData;
}
if (null === $this->__mappedProperties) {
$properties = array();
foreach ($this->__arrayOfData as $propertyName => $property) {
if (isset($this->__propertyToData[Schema::DEFAULT_MAPPING][$propertyName])) {
$propertyName = $this->__propertyToData[Schema::DEFAULT_MAPPING][$propertyName];
}
$properties[$propertyName] = $property;
}
$this->__mappedProperties = $properties;
}
return $this->__mappedProperties;
} | php | public function &toArray()
{
if (!isset($this->__propertyToData[Schema::DEFAULT_MAPPING])) {
return $this->__arrayOfData;
}
if (null === $this->__mappedProperties) {
$properties = array();
foreach ($this->__arrayOfData as $propertyName => $property) {
if (isset($this->__propertyToData[Schema::DEFAULT_MAPPING][$propertyName])) {
$propertyName = $this->__propertyToData[Schema::DEFAULT_MAPPING][$propertyName];
}
$properties[$propertyName] = $property;
}
$this->__mappedProperties = $properties;
}
return $this->__mappedProperties;
} | [
"public",
"function",
"&",
"toArray",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"__propertyToData",
"[",
"Schema",
"::",
"DEFAULT_MAPPING",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"__arrayOfData",
";",
"}",
"if",
"(",
"... | Returns a map of properties by default data name
@return Schema[] | [
"Returns",
"a",
"map",
"of",
"properties",
"by",
"default",
"data",
"name"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Constraint/Properties.php#L51-L67 |
swaggest/php-json-schema | src/Structure/ClassStructureTrait.php | ClassStructureTrait.jsonSerialize | public function jsonSerialize()
{
$result = new \stdClass();
$schema = static::schema();
foreach ($schema->getProperties()->getDataKeyMap() as $propertyName => $dataName) {
$value = $this->$propertyName;
if ((null !== $value) || array_key_exists($propertyName, $this->__arrayOfData)) {
$result->$dataName = $value;
}
}
foreach ($schema->getNestedPropertyNames() as $name) {
/** @var ObjectItem $nested */
$nested = $this->$name;
if (null !== $nested) {
foreach ((array)$nested->jsonSerialize() as $key => $value) {
$result->$key = $value;
}
}
}
return $result;
} | php | public function jsonSerialize()
{
$result = new \stdClass();
$schema = static::schema();
foreach ($schema->getProperties()->getDataKeyMap() as $propertyName => $dataName) {
$value = $this->$propertyName;
if ((null !== $value) || array_key_exists($propertyName, $this->__arrayOfData)) {
$result->$dataName = $value;
}
}
foreach ($schema->getNestedPropertyNames() as $name) {
/** @var ObjectItem $nested */
$nested = $this->$name;
if (null !== $nested) {
foreach ((array)$nested->jsonSerialize() as $key => $value) {
$result->$key = $value;
}
}
}
return $result;
} | [
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"schema",
"=",
"static",
"::",
"schema",
"(",
")",
";",
"foreach",
"(",
"$",
"schema",
"->",
"getProperties",
"(",
")",
"->",
"getD... | todo skip validation during import | [
"todo",
"skip",
"validation",
"during",
"import"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Structure/ClassStructureTrait.php#L95-L116 |
swaggest/php-json-schema | src/Schema.php | Schema.unboolSchema | private static function unboolSchema($schema)
{
static $trueSchema;
static $falseSchema;
if (null === $trueSchema) {
$trueSchema = new Schema();
$trueSchema->__booleanSchema = true;
$falseSchema = new Schema();
$falseSchema->not = $trueSchema;
$falseSchema->__booleanSchema = false;
}
if ($schema === true) {
return $trueSchema;
} elseif ($schema === false) {
return $falseSchema;
} else {
return $schema;
}
} | php | private static function unboolSchema($schema)
{
static $trueSchema;
static $falseSchema;
if (null === $trueSchema) {
$trueSchema = new Schema();
$trueSchema->__booleanSchema = true;
$falseSchema = new Schema();
$falseSchema->not = $trueSchema;
$falseSchema->__booleanSchema = false;
}
if ($schema === true) {
return $trueSchema;
} elseif ($schema === false) {
return $falseSchema;
} else {
return $schema;
}
} | [
"private",
"static",
"function",
"unboolSchema",
"(",
"$",
"schema",
")",
"{",
"static",
"$",
"trueSchema",
";",
"static",
"$",
"falseSchema",
";",
"if",
"(",
"null",
"===",
"$",
"trueSchema",
")",
"{",
"$",
"trueSchema",
"=",
"new",
"Schema",
"(",
")",
... | Resolves boolean schema into Schema instance
@param mixed $schema
@return mixed|Schema | [
"Resolves",
"boolean",
"schema",
"into",
"Schema",
"instance"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Schema.php#L1318-L1338 |
swaggest/php-json-schema | src/Path/PointerUtil.php | PointerUtil.getSchemaPointer | public static function getSchemaPointer($path, $isURIFragmentId = false)
{
$result = self::getSchemaPointers($path, $isURIFragmentId);
return array_pop($result);
} | php | public static function getSchemaPointer($path, $isURIFragmentId = false)
{
$result = self::getSchemaPointers($path, $isURIFragmentId);
return array_pop($result);
} | [
"public",
"static",
"function",
"getSchemaPointer",
"(",
"$",
"path",
",",
"$",
"isURIFragmentId",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"getSchemaPointers",
"(",
"$",
"path",
",",
"$",
"isURIFragmentId",
")",
";",
"return",
"array_pop",
... | Builds JSON pointer to schema from processing path
Path example: #->properties:responses->additionalProperties:envvar->properties:schema
@param string $path
@param bool $isURIFragmentId
@return string | [
"Builds",
"JSON",
"pointer",
"to",
"schema",
"from",
"processing",
"path",
"Path",
"example",
":",
"#",
"-",
">",
"properties",
":",
"responses",
"-",
">",
"additionalProperties",
":",
"envvar",
"-",
">",
"properties",
":",
"schema"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Path/PointerUtil.php#L17-L21 |
swaggest/php-json-schema | src/Path/PointerUtil.php | PointerUtil.getSchemaPointers | public static function getSchemaPointers($path, $isURIFragmentId = false)
{
$items = explode('->', $path);
unset($items[0]);
$result = array();
$pointer = $isURIFragmentId ? '#' : '';
foreach ($items as $item) {
$parts = explode(':', $item);
if (isset($parts[0])) {
$schemaPaths = explode('[', $parts[0], 2);
if (isset($schemaPaths[1])) {
$schemaPaths[1] = substr(strtr($schemaPaths[1], array('~1' => '~', '~2' => ':')), 0, -1);
}
if ($schemaPaths[0] === Schema::PROP_REF) {
$result[] = $pointer . '/' . JsonPointer::escapeSegment(Schema::PROP_REF, $isURIFragmentId);
if ($schemaPaths[1][0] !== '#') { // Absolute URI.
$pointer = $schemaPaths[1];
} else {
$pointer = self::rebuildPointer($schemaPaths[1], $isURIFragmentId);
}
continue;
}
$pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[0], $isURIFragmentId);
if (isset($schemaPaths[1])) {
$pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[1], $isURIFragmentId);
} elseif (isset($parts[1])) {
$pointer .= '/' . JsonPointer::escapeSegment($parts[1], $isURIFragmentId);
}
}
}
if ($pointer === '') {
$pointer = '/';
}
$result[] = $pointer;
return $result;
} | php | public static function getSchemaPointers($path, $isURIFragmentId = false)
{
$items = explode('->', $path);
unset($items[0]);
$result = array();
$pointer = $isURIFragmentId ? '#' : '';
foreach ($items as $item) {
$parts = explode(':', $item);
if (isset($parts[0])) {
$schemaPaths = explode('[', $parts[0], 2);
if (isset($schemaPaths[1])) {
$schemaPaths[1] = substr(strtr($schemaPaths[1], array('~1' => '~', '~2' => ':')), 0, -1);
}
if ($schemaPaths[0] === Schema::PROP_REF) {
$result[] = $pointer . '/' . JsonPointer::escapeSegment(Schema::PROP_REF, $isURIFragmentId);
if ($schemaPaths[1][0] !== '#') { // Absolute URI.
$pointer = $schemaPaths[1];
} else {
$pointer = self::rebuildPointer($schemaPaths[1], $isURIFragmentId);
}
continue;
}
$pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[0], $isURIFragmentId);
if (isset($schemaPaths[1])) {
$pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[1], $isURIFragmentId);
} elseif (isset($parts[1])) {
$pointer .= '/' . JsonPointer::escapeSegment($parts[1], $isURIFragmentId);
}
}
}
if ($pointer === '') {
$pointer = '/';
}
$result[] = $pointer;
return $result;
} | [
"public",
"static",
"function",
"getSchemaPointers",
"(",
"$",
"path",
",",
"$",
"isURIFragmentId",
"=",
"false",
")",
"{",
"$",
"items",
"=",
"explode",
"(",
"'->'",
",",
"$",
"path",
")",
";",
"unset",
"(",
"$",
"items",
"[",
"0",
"]",
")",
";",
... | Builds JSON pointer to schema from processing path
Path example: #->properties:responses->additionalProperties:envvar->properties:schema
@param string $path
@param bool $isURIFragmentId
@return string[] | [
"Builds",
"JSON",
"pointer",
"to",
"schema",
"from",
"processing",
"path",
"Path",
"example",
":",
"#",
"-",
">",
"properties",
":",
"responses",
"-",
">",
"additionalProperties",
":",
"envvar",
"-",
">",
"properties",
":",
"schema"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Path/PointerUtil.php#L30-L66 |
swaggest/php-json-schema | src/Path/PointerUtil.php | PointerUtil.getDataPointer | public static function getDataPointer($path, $isURIFragmentId = false)
{
$items = explode('->', $path);
unset($items[0]);
$result = $isURIFragmentId ? '#' : '';
foreach ($items as $item) {
$parts = explode(':', $item);
if (isset($parts[1])) {
$result .= '/' . JsonPointer::escapeSegment($parts[1], $isURIFragmentId);
}
}
if ($result === '') {
return '/';
}
return $result;
} | php | public static function getDataPointer($path, $isURIFragmentId = false)
{
$items = explode('->', $path);
unset($items[0]);
$result = $isURIFragmentId ? '#' : '';
foreach ($items as $item) {
$parts = explode(':', $item);
if (isset($parts[1])) {
$result .= '/' . JsonPointer::escapeSegment($parts[1], $isURIFragmentId);
}
}
if ($result === '') {
return '/';
}
return $result;
} | [
"public",
"static",
"function",
"getDataPointer",
"(",
"$",
"path",
",",
"$",
"isURIFragmentId",
"=",
"false",
")",
"{",
"$",
"items",
"=",
"explode",
"(",
"'->'",
",",
"$",
"path",
")",
";",
"unset",
"(",
"$",
"items",
"[",
"0",
"]",
")",
";",
"$"... | Builds JSON pointer to data from processing path
Path example: #->properties:responses->additionalProperties:envvar->properties:schema
@param string $path
@param bool $isURIFragmentId
@return string | [
"Builds",
"JSON",
"pointer",
"to",
"data",
"from",
"processing",
"path",
"Path",
"example",
":",
"#",
"-",
">",
"properties",
":",
"responses",
"-",
">",
"additionalProperties",
":",
"envvar",
"-",
">",
"properties",
":",
"schema"
] | train | https://github.com/swaggest/php-json-schema/blob/29125e57ebb34c0a8dc40c637a2430dcc4b374ef/src/Path/PointerUtil.php#L76-L91 |
hekmatinasser/verta | src/Verta.php | Verta.parse | public static function parse($datetime, $timezone = null) {
$monthName = array_map(function ($value) {
return ' ' . $value . ' ';
}, self::$monthYear);
$monthValue = array_map(function ($value) {
return '-' . $value . '-';
}, range(1,12));
$datetime = str_replace($monthName, $monthValue, $datetime);
$parse = date_parse($datetime);
if($parse['error_count'] == 0){
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
$timezone = self::createTimeZone($timezone);
$datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
return new static($datetime);
}
else{
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
} | php | public static function parse($datetime, $timezone = null) {
$monthName = array_map(function ($value) {
return ' ' . $value . ' ';
}, self::$monthYear);
$monthValue = array_map(function ($value) {
return '-' . $value . '-';
}, range(1,12));
$datetime = str_replace($monthName, $monthValue, $datetime);
$parse = date_parse($datetime);
if($parse['error_count'] == 0){
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
$timezone = self::createTimeZone($timezone);
$datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
return new static($datetime);
}
else{
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"datetime",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"monthName",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"' '",
".",
"$",
"value",
".",
"' '",
";",
"}",
... | Create a Verta instance from a DateTime one
@param timestamp $datetime [optional]
@param bool $timezone [optional]
@return static | [
"Create",
"a",
"Verta",
"instance",
"from",
"a",
"DateTime",
"one"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L359-L380 |
hekmatinasser/verta | src/Verta.php | Verta.parseFormat | public static function parseFormat($format,$datetime, $timezone = null) {
$datetime = str_replace(self::$monthYear, range(1,12), $datetime);
$parse = date_parse_from_format($format, $datetime);
if($parse['error_count'] == 0 && self::isValideDate($parse['year'], $parse['month'], $parse['day']) && self::isValideTime($parse['hour'], $parse['minute'], $parse['second'])){
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
$timezone = self::createTimeZone($timezone);
$datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
return new static($datetime);
}
else{
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
} | php | public static function parseFormat($format,$datetime, $timezone = null) {
$datetime = str_replace(self::$monthYear, range(1,12), $datetime);
$parse = date_parse_from_format($format, $datetime);
if($parse['error_count'] == 0 && self::isValideDate($parse['year'], $parse['month'], $parse['day']) && self::isValideTime($parse['hour'], $parse['minute'], $parse['second'])){
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
$timezone = self::createTimeZone($timezone);
$datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
return new static($datetime);
}
else{
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
} | [
"public",
"static",
"function",
"parseFormat",
"(",
"$",
"format",
",",
"$",
"datetime",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"datetime",
"=",
"str_replace",
"(",
"self",
"::",
"$",
"monthYear",
",",
"range",
"(",
"1",
",",
"12",
")",
",... | Create a Verta instance from a DateTime one
@param string $format
@param string $datetime [optional]
@param bool $timezone [optional]
@return static | [
"Create",
"a",
"Verta",
"instance",
"from",
"a",
"DateTime",
"one"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L390-L405 |
hekmatinasser/verta | src/Verta.php | Verta.create | public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, $hour, $minute, $second, $timezone);
} | php | public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, $hour, $minute, $second, $timezone);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"t... | Create a new Verta instance from a specific date and time gregorain.
If any of feild are set to null their now() values will
be used.
@param int|null $year
@param int|null $month
@param int|null $day
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"new",
"Verta",
"instance",
"from",
"a",
"specific",
"date",
"and",
"time",
"gregorain",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L423-L426 |
hekmatinasser/verta | src/Verta.php | Verta.createDate | public static function createDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::create($year, $month, $day, null, null, null, $timezone);
} | php | public static function createDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::create($year, $month, $day, null, null, null, $timezone);
} | [
"public",
"static",
"function",
"createDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"year",
",",
"$",
... | Create a Verta from just a date gregorian.
@param int|null $year
@param int|null $month
@param int|null $day
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"from",
"just",
"a",
"date",
"gregorian",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L438-L441 |
hekmatinasser/verta | src/Verta.php | Verta.createTime | public static function createTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::create(null, null, null, $hour, $minute, $second, $timezone);
} | php | public static function createTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::create(null, null, null, $hour, $minute, $second, $timezone);
} | [
"public",
"static",
"function",
"createTime",
"(",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"null",
",",
"null",
... | Create a Verta instance from just a time gregorian.
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"instance",
"from",
"just",
"a",
"time",
"gregorian",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L453-L456 |
hekmatinasser/verta | src/Verta.php | Verta.createGregorian | public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$now = date('Y-n-j-G-i-s', time());
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
$year = $year === null ? intval($defaults['year']) : $year;
$month = $month === null ? intval($defaults['month']) : $month;
$day = $day === null ? intval($defaults['day']) : $day;
$hour = $hour === null ? intval($defaults['hour']) : $hour;
$minute = $minute === null ? intval($defaults['minute']) : $minute;
$second = $second === null ? intval($defaults['second']) : $second;
if (!checkdate($month, $day, $year) || !static::isValideTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return static::instance(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second), $timezone);
} | php | public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$now = date('Y-n-j-G-i-s', time());
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
$year = $year === null ? intval($defaults['year']) : $year;
$month = $month === null ? intval($defaults['month']) : $month;
$day = $day === null ? intval($defaults['day']) : $day;
$hour = $hour === null ? intval($defaults['hour']) : $hour;
$minute = $minute === null ? intval($defaults['minute']) : $minute;
$second = $second === null ? intval($defaults['second']) : $second;
if (!checkdate($month, $day, $year) || !static::isValideTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return static::instance(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second), $timezone);
} | [
"public",
"static",
"function",
"createGregorian",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
... | Create a new Verta instance from a specific date and time gregorain.
If any of feild are set to null their now() values will
be used.
@param int|null $year
@param int|null $month
@param int|null $day
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"new",
"Verta",
"instance",
"from",
"a",
"specific",
"date",
"and",
"time",
"gregorain",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L508-L526 |
hekmatinasser/verta | src/Verta.php | Verta.createGregorianDate | public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, null, null, null, $timezone);
} | php | public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, null, null, null, $timezone);
} | [
"public",
"static",
"function",
"createGregorianDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"createGregorian",
"(",
"$",
"yea... | Create a Verta from just a date gregorian.
@param int|null $year
@param int|null $month
@param int|null $day
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"from",
"just",
"a",
"date",
"gregorian",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L538-L541 |
hekmatinasser/verta | src/Verta.php | Verta.createGregorianTime | public static function createGregorianTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian(null, null, null, $hour, $minute, $second, $timezone);
} | php | public static function createGregorianTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian(null, null, null, $hour, $minute, $second, $timezone);
} | [
"public",
"static",
"function",
"createGregorianTime",
"(",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"createGregorian",
"(",
"null",... | Create a Verta instance from just a time gregorian.
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"instance",
"from",
"just",
"a",
"time",
"gregorian",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L553-L556 |
hekmatinasser/verta | src/Verta.php | Verta.createJalali | public static function createJalali($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$now = static::instance(null, $timezone)->format('Y-n-j-G-i-s');
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
$year = $year === null ? intval($defaults['year']) : $year;
$month = $month === null ? intval($defaults['month']) : $month;
$day = $day === null ? intval($defaults['day']) : $day;
$hour = $hour === null ? intval($defaults['hour']) : $hour;
$minute = $minute === null ? intval($defaults['minute']) : $minute;
$second = $second === null ? intval($defaults['second']) : $second;
if (!static::isValideDate($year, $month, $day) || !static::isValideTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return static::parse(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second));
} | php | public static function createJalali($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
$now = static::instance(null, $timezone)->format('Y-n-j-G-i-s');
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
$year = $year === null ? intval($defaults['year']) : $year;
$month = $month === null ? intval($defaults['month']) : $month;
$day = $day === null ? intval($defaults['day']) : $day;
$hour = $hour === null ? intval($defaults['hour']) : $hour;
$minute = $minute === null ? intval($defaults['minute']) : $minute;
$second = $second === null ? intval($defaults['second']) : $second;
if (!static::isValideDate($year, $month, $day) || !static::isValideTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return static::parse(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second));
} | [
"public",
"static",
"function",
"createJalali",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$"... | Create a new Verta instance from a specific date and time.
If any of feild are set to null their now() values will
be used.
@param int|null $year
@param int|null $month
@param int|null $day
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"new",
"Verta",
"instance",
"from",
"a",
"specific",
"date",
"and",
"time",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L575-L592 |
hekmatinasser/verta | src/Verta.php | Verta.createJalaliDate | public static function createJalaliDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createJalali($year, $month, $day, null, null, null, $timezone);
} | php | public static function createJalaliDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createJalali($year, $month, $day, null, null, null, $timezone);
} | [
"public",
"static",
"function",
"createJalaliDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"createJalali",
"(",
"$",
"year",
... | Create a Verta from just a date.
@param int|null $year
@param int|null $month
@param int|null $day
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"from",
"just",
"a",
"date",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L604-L607 |
hekmatinasser/verta | src/Verta.php | Verta.createJalaliTime | public static function createJalaliTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createJalali(null, null, null, $hour, $minute, $second, $timezone);
} | php | public static function createJalaliTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createJalali(null, null, null, $hour, $minute, $second, $timezone);
} | [
"public",
"static",
"function",
"createJalaliTime",
"(",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"createJalali",
"(",
"null",
","... | Create a Verta instance from just a time.
@param int|null $hour
@param int|null $minute
@param int|null $second
@param \DateTimeZone|string|null $timezone
@return static | [
"Create",
"a",
"Verta",
"instance",
"from",
"just",
"a",
"time",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L619-L622 |
hekmatinasser/verta | src/Verta.php | Verta.setDate | public function setDate($year, $month, $day)
{
list($year, $month, $day) = self::getGregorian($year, $month, $day);
return parent::setDate($year, $month, $day);
} | php | public function setDate($year, $month, $day)
{
list($year, $month, $day) = self::getGregorian($year, $month, $day);
return parent::setDate($year, $month, $day);
} | [
"public",
"function",
"setDate",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
")",
"{",
"list",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
")",
"=",
"self",
"::",
"getGregorian",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$"... | Sets the current date of the DateTime object to a different date.
Calls modify as a workaround for a php bug
@param int $year
@param int $month
@param int $day
@return static | [
"Sets",
"the",
"current",
"date",
"of",
"the",
"DateTime",
"object",
"to",
"a",
"different",
"date",
".",
"Calls",
"modify",
"as",
"a",
"workaround",
"for",
"a",
"php",
"bug"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L854-L859 |
hekmatinasser/verta | src/Verta.php | Verta.date | protected function date($format){
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = ($gWeek + 1);
if ($pWeek >= 7) {
$pWeek = 0;
}
if ($format == '\\') {
$format = '//';
}
$lenghFormat = strlen($format);
$i = 0;
$result = '';
while ($i < $lenghFormat) {
$par = $format{$i};
if ($par == '\\') {
$result .= $format{ ++$i};
$i ++;
continue;
}
switch ($par) {
# Day
case 'd':
$result .= sprintf('%02s', $pDay);
break;
case 'D':
$result .= substr(static::$dayWeek[$pWeek], 0, 2);
break;
case 'j':
$result .= $pDay;
break;
case 'l':
$result .= static::$dayWeek[$pWeek];
break;
case 'N':
$result .= $pWeek + 1;
break;
case 'w':
$result .= $pWeek;
break;
case 'z':
$result .= $this->daysYear($pMonth, $pDay);
break;
case 'S':
$result .= self::NUMBER_TH;
break;
# Week
case 'W':
$result .= ceil($this->daysYear($pMonth, $pDay) / 7);
break;
# Month
case 'F':
$result .= static::$monthYear[$pMonth-1];
break;
case 'm':
$result .= sprintf('%02s', $pMonth);
break;
case 'M':
$result .= substr(static::$monthYear[$pMonth-1], 0, 6);
break;
case 'n':
$result .= $pMonth;
break;
case 't':
$result .= static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1];
break;
# Years
case 'L':
$result .= intval($this->isLeapYear($pYear));
break;
case 'Y':
case 'o':
$result .= $pYear;
break;
case 'y':
$result .= substr($pYear, 2);
break;
# Time
case 'a':
case 'A':
if (date('a', $timestamp) == 'am') {
$result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM);
} else {
$result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM);
}
break;
case 'B':
case 'g':
case 'G':
case 'h':
case 'H':
case 's':
case 'u':
case 'i':
# Timezone
case 'e':
case 'I':
case 'O':
case 'P':
case 'T':
case 'Z':
$result .= date($par, $timestamp);
break;
# Full Date/Time
case 'c':
$result .= ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . date('H:i:s P', $timestamp));
break;
case 'r':
$result .= (substr(static::$dayWeek[$pWeek], 0, 2) . '، ' . $pDay . ' ' . substr(static::$monthYear[$pMonth], 0, 6) . ' ' . $pYear . ' ' . date('H:i:s P', $timestamp));
break;
case 'U':
$result .= $timestamp;
break;
default:
$result .= $par;
}
$i ++;
}
return $result;
} | php | protected function date($format){
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = ($gWeek + 1);
if ($pWeek >= 7) {
$pWeek = 0;
}
if ($format == '\\') {
$format = '//';
}
$lenghFormat = strlen($format);
$i = 0;
$result = '';
while ($i < $lenghFormat) {
$par = $format{$i};
if ($par == '\\') {
$result .= $format{ ++$i};
$i ++;
continue;
}
switch ($par) {
# Day
case 'd':
$result .= sprintf('%02s', $pDay);
break;
case 'D':
$result .= substr(static::$dayWeek[$pWeek], 0, 2);
break;
case 'j':
$result .= $pDay;
break;
case 'l':
$result .= static::$dayWeek[$pWeek];
break;
case 'N':
$result .= $pWeek + 1;
break;
case 'w':
$result .= $pWeek;
break;
case 'z':
$result .= $this->daysYear($pMonth, $pDay);
break;
case 'S':
$result .= self::NUMBER_TH;
break;
# Week
case 'W':
$result .= ceil($this->daysYear($pMonth, $pDay) / 7);
break;
# Month
case 'F':
$result .= static::$monthYear[$pMonth-1];
break;
case 'm':
$result .= sprintf('%02s', $pMonth);
break;
case 'M':
$result .= substr(static::$monthYear[$pMonth-1], 0, 6);
break;
case 'n':
$result .= $pMonth;
break;
case 't':
$result .= static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1];
break;
# Years
case 'L':
$result .= intval($this->isLeapYear($pYear));
break;
case 'Y':
case 'o':
$result .= $pYear;
break;
case 'y':
$result .= substr($pYear, 2);
break;
# Time
case 'a':
case 'A':
if (date('a', $timestamp) == 'am') {
$result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM);
} else {
$result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM);
}
break;
case 'B':
case 'g':
case 'G':
case 'h':
case 'H':
case 's':
case 'u':
case 'i':
# Timezone
case 'e':
case 'I':
case 'O':
case 'P':
case 'T':
case 'Z':
$result .= date($par, $timestamp);
break;
# Full Date/Time
case 'c':
$result .= ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . date('H:i:s P', $timestamp));
break;
case 'r':
$result .= (substr(static::$dayWeek[$pWeek], 0, 2) . '، ' . $pDay . ' ' . substr(static::$monthYear[$pMonth], 0, 6) . ' ' . $pYear . ' ' . date('H:i:s P', $timestamp));
break;
case 'U':
$result .= $timestamp;
break;
default:
$result .= $par;
}
$i ++;
}
return $result;
} | [
"protected",
"function",
"date",
"(",
"$",
"format",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"getTimestamp",
"(",
")",
";",
"list",
"(",
"$",
"gYear",
",",
"$",
"gMonth",
",",
"$",
"gDay",
",",
"$",
"gWeek",
")",
"=",
"explode",
"(",
... | The format of the outputted date string (jalali equivalent of php date() function)
@param string $format for example 'Y-m-d H:i:s'
@return string | [
"The",
"format",
"of",
"the",
"outputted",
"date",
"string",
"(",
"jalali",
"equivalent",
"of",
"php",
"date",
"()",
"function",
")"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L917-L1066 |
hekmatinasser/verta | src/Verta.php | Verta.dateWord | protected function dateWord($format){
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = ($gWeek + 1);
if ($pWeek >= 7) {
$pWeek = 0;
}
if ($format == '\\') {
$format = '//';
}
$lenghFormat = strlen($format);
$i = 0;
$result = '';
$word = new Notowo(0, 'fa');
while ($i < $lenghFormat) {
$par = $format{$i};
if ($par == '\\') {
$result .= $format{ ++$i};
$i ++;
continue;
}
switch ($par) {
# Day
case 'd':
case 'j':
$result .= $word->getWord(strval($pDay));
break;
case 'D':
$result .= substr(static::$dayWeek[$pWeek], 0, 2);
break;
case 'l':
$result .= static::$dayWeek[$pWeek];
break;
case 'N':
$result .= $word->getWord(strval($pWeek + 1));
break;
case 'w':
$result .= $word->getWord(strval($pWeek));
break;
case 'z':
$result .= $word->getWord(strval($this->daysYear($pMonth, $pDay)));
break;
case 'S':
$result .= self::NUMBER_TH;
break;
# Week
case 'W':
$result .= $word->getWord(strval(ceil($this->daysYear($pMonth, $pDay) / 7)));
break;
# Month
case 'F':
$result .= static::$monthYear[$pMonth-1];
break;
case 'm':
case 'n':
$result .= $word->getWord(strval($pMonth));
break;
case 'M':
$result .= substr(static::$monthYear[$pMonth-1], 0, 6);
break;
case 't':
$result .= $word->getWord(strval(static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1]));
break;
# Years
case 'L':
$result .= intval($this->isLeapYear($pYear));
break;
case 'Y':
case 'o':
$result .= $word->getWord(strval($pYear));
break;
case 'y':
$result .= $word->getWord(strval(substr($pYear, 2)));
break;
# Time
case 'a':
case 'A':
if (date('a', $timestamp) == 'am') {
$result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM);
} else {
$result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM);
}
break;
case 'B':
case 'g':
case 'G':
case 'h':
case 'H':
case 's':
case 'u':
case 'i':
$result .= $word->getWord(strval(date($par, $timestamp)));
break;
case 'e':
case 'I':
case 'O':
case 'P':
case 'T':
case 'Z':
$result .= date($par, $timestamp);
break;
# Full Date/Time
case 'c':
$result .= $this->dateWord('Y, m, d, H:i:s P');
break;
case 'r':
$result .= $this->dateWord('l Y, m, d, H:i:s P');
break;
case 'U':
$result .= $word->getWord(strval($timestamp));
break;
default:
$result .= $par;
}
$i ++;
}
return $result;
} | php | protected function dateWord($format){
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = ($gWeek + 1);
if ($pWeek >= 7) {
$pWeek = 0;
}
if ($format == '\\') {
$format = '//';
}
$lenghFormat = strlen($format);
$i = 0;
$result = '';
$word = new Notowo(0, 'fa');
while ($i < $lenghFormat) {
$par = $format{$i};
if ($par == '\\') {
$result .= $format{ ++$i};
$i ++;
continue;
}
switch ($par) {
# Day
case 'd':
case 'j':
$result .= $word->getWord(strval($pDay));
break;
case 'D':
$result .= substr(static::$dayWeek[$pWeek], 0, 2);
break;
case 'l':
$result .= static::$dayWeek[$pWeek];
break;
case 'N':
$result .= $word->getWord(strval($pWeek + 1));
break;
case 'w':
$result .= $word->getWord(strval($pWeek));
break;
case 'z':
$result .= $word->getWord(strval($this->daysYear($pMonth, $pDay)));
break;
case 'S':
$result .= self::NUMBER_TH;
break;
# Week
case 'W':
$result .= $word->getWord(strval(ceil($this->daysYear($pMonth, $pDay) / 7)));
break;
# Month
case 'F':
$result .= static::$monthYear[$pMonth-1];
break;
case 'm':
case 'n':
$result .= $word->getWord(strval($pMonth));
break;
case 'M':
$result .= substr(static::$monthYear[$pMonth-1], 0, 6);
break;
case 't':
$result .= $word->getWord(strval(static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1]));
break;
# Years
case 'L':
$result .= intval($this->isLeapYear($pYear));
break;
case 'Y':
case 'o':
$result .= $word->getWord(strval($pYear));
break;
case 'y':
$result .= $word->getWord(strval(substr($pYear, 2)));
break;
# Time
case 'a':
case 'A':
if (date('a', $timestamp) == 'am') {
$result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM);
} else {
$result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM);
}
break;
case 'B':
case 'g':
case 'G':
case 'h':
case 'H':
case 's':
case 'u':
case 'i':
$result .= $word->getWord(strval(date($par, $timestamp)));
break;
case 'e':
case 'I':
case 'O':
case 'P':
case 'T':
case 'Z':
$result .= date($par, $timestamp);
break;
# Full Date/Time
case 'c':
$result .= $this->dateWord('Y, m, d, H:i:s P');
break;
case 'r':
$result .= $this->dateWord('l Y, m, d, H:i:s P');
break;
case 'U':
$result .= $word->getWord(strval($timestamp));
break;
default:
$result .= $par;
}
$i ++;
}
return $result;
} | [
"protected",
"function",
"dateWord",
"(",
"$",
"format",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"getTimestamp",
"(",
")",
";",
"list",
"(",
"$",
"gYear",
",",
"$",
"gMonth",
",",
"$",
"gDay",
",",
"$",
"gWeek",
")",
"=",
"explode",
"("... | The format of the outputted date string (jalali equivalent of php date() function)
@param string $format for example 'Y-m-d H:i:s'
@return string | [
"The",
"format",
"of",
"the",
"outputted",
"date",
"string",
"(",
"jalali",
"equivalent",
"of",
"php",
"date",
"()",
"function",
")"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1074-L1220 |
hekmatinasser/verta | src/Verta.php | Verta.daysYear | protected function daysYear($month, $day) {
$days = 0;
for ($i = 1; $i < $month; $i ++) {
$days += static::$daysMonthJalali[$i];
}
return ($days + $day);
} | php | protected function daysYear($month, $day) {
$days = 0;
for ($i = 1; $i < $month; $i ++) {
$days += static::$daysMonthJalali[$i];
}
return ($days + $day);
} | [
"protected",
"function",
"daysYear",
"(",
"$",
"month",
",",
"$",
"day",
")",
"{",
"$",
"days",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"month",
";",
"$",
"i",
"++",
")",
"{",
"$",
"days",
"+=",
"static",
"::... | return day number from first day of year
@param int $month
@param int $day
@return type
@since 5.0.0 | [
"return",
"day",
"number",
"from",
"first",
"day",
"of",
"year"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1230-L1236 |
hekmatinasser/verta | src/Verta.php | Verta.formatDifference | public function formatDifference(Verta $v = null)
{
$difference = $this->diffSeconds($v);
$absolute = $difference < 0 ? self::POST : self::PRE;
$difference = abs($difference);
for ($j = 0; $difference >= static::$unitNumber[$j] and $j < count(static::$unitNumber) - 1; $j++) {
$difference /= static::$unitNumber[$j];
}
$difference = intval(round($difference));
if($difference === 0) {
return self::NOW;
}
return sprintf('%s %s %s', $difference, static::$unitName[$j], $absolute);
} | php | public function formatDifference(Verta $v = null)
{
$difference = $this->diffSeconds($v);
$absolute = $difference < 0 ? self::POST : self::PRE;
$difference = abs($difference);
for ($j = 0; $difference >= static::$unitNumber[$j] and $j < count(static::$unitNumber) - 1; $j++) {
$difference /= static::$unitNumber[$j];
}
$difference = intval(round($difference));
if($difference === 0) {
return self::NOW;
}
return sprintf('%s %s %s', $difference, static::$unitName[$j], $absolute);
} | [
"public",
"function",
"formatDifference",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"difference",
"=",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v",
")",
";",
"$",
"absolute",
"=",
"$",
"difference",
"<",
"0",
"?",
"self",
"::",
"POST",
... | get difference in all
@param Verta|null $v
@return string | [
"get",
"difference",
"in",
"all"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1413-L1429 |
hekmatinasser/verta | src/Verta.php | Verta.isLeapYear | public static function isLeapYear($year) {
$mod = ($year % 33);
if (($mod == 1) or ( $mod == 5) or ( $mod == 9) or ( $mod == 13) or ( $mod == 17) or ( $mod == 22) or ( $mod == 26) or ( $mod == 30)) {
return true;
}
return false;
} | php | public static function isLeapYear($year) {
$mod = ($year % 33);
if (($mod == 1) or ( $mod == 5) or ( $mod == 9) or ( $mod == 13) or ( $mod == 17) or ( $mod == 22) or ( $mod == 26) or ( $mod == 30)) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"isLeapYear",
"(",
"$",
"year",
")",
"{",
"$",
"mod",
"=",
"(",
"$",
"year",
"%",
"33",
")",
";",
"if",
"(",
"(",
"$",
"mod",
"==",
"1",
")",
"or",
"(",
"$",
"mod",
"==",
"5",
")",
"or",
"(",
"$",
"mod",
"=="... | check jalali the instance is a leap year
@param int $year
@return bool | [
"check",
"jalali",
"the",
"instance",
"is",
"a",
"leap",
"year"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1455-L1461 |
hekmatinasser/verta | src/Verta.php | Verta.isValideDate | public static function isValideDate($year, $month, $day) {
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month)-1];
return $year >= 1 && $year <= 32766
&& $month >= 1 && $month <= 12
&& $day >= 1 && $day <= $dayLastMonthJalali;
} | php | public static function isValideDate($year, $month, $day) {
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month)-1];
return $year >= 1 && $year <= 32766
&& $month >= 1 && $month <= 12
&& $day >= 1 && $day <= $dayLastMonthJalali;
} | [
"public",
"static",
"function",
"isValideDate",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
")",
"{",
"$",
"dayLastMonthJalali",
"=",
"static",
"::",
"isLeapYear",
"(",
"$",
"year",
")",
"&&",
"(",
"$",
"month",
"==",
"12",
")",
"?",
"30",
... | validate a jalali date (jalali equivalent of php checkdate() function)
@param int $month
@param int $day
@param int $year
@return bool | [
"validate",
"a",
"jalali",
"date",
"(",
"jalali",
"equivalent",
"of",
"php",
"checkdate",
"()",
"function",
")"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1471-L1476 |
hekmatinasser/verta | src/Verta.php | Verta.isValideTime | public static function isValideTime($hour, $minute, $second) {
return $hour >= 0 && $hour <= 24
&& $minute >= 0 && $minute <= 59
&& $second >= 0 && $second <= 59;
} | php | public static function isValideTime($hour, $minute, $second) {
return $hour >= 0 && $hour <= 24
&& $minute >= 0 && $minute <= 59
&& $second >= 0 && $second <= 59;
} | [
"public",
"static",
"function",
"isValideTime",
"(",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
")",
"{",
"return",
"$",
"hour",
">=",
"0",
"&&",
"$",
"hour",
"<=",
"24",
"&&",
"$",
"minute",
">=",
"0",
"&&",
"$",
"minute",
"<=",
"59",
... | validate a time
@param int $hour
@param int $minute
@param int $second
@return bool | [
"validate",
"a",
"time"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1486-L1490 |
hekmatinasser/verta | src/Verta.php | Verta.diffYears | public function diffYears(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return (int) $this->diff($v)->format('%r%y');
} | php | public function diffYears(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return (int) $this->diff($v)->format('%r%y');
} | [
"public",
"function",
"diffYears",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"?",
":",
"static",
"::",
"now",
"(",
"$",
"this",
"->",
"getTimezone",
"(",
")",
")",
";",
"return",
"(",
"int",
")",
"$",
"this",
"->",... | Get the difference in years
@param Verta|null $v
@return int | [
"Get",
"the",
"difference",
"in",
"years"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1499-L1504 |
hekmatinasser/verta | src/Verta.php | Verta.diffHours | public function diffHours(Verta $v = null)
{
return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
} | php | public function diffHours(Verta $v = null)
{
return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
} | [
"public",
"function",
"diffHours",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"return",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v",
")",
"/",
"static",
"::",
"SECONDS_PER_MINUTE",
"/",
"static",
"::",
"MINUTES_PER_HOUR",
... | Get the difference in hours
@param Verta|null $v
@return int | [
"Get",
"the",
"difference",
"in",
"hours"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1553-L1556 |
hekmatinasser/verta | src/Verta.php | Verta.diffSeconds | public function diffSeconds(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $v->getTimestamp() - $this->getTimestamp();
} | php | public function diffSeconds(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $v->getTimestamp() - $this->getTimestamp();
} | [
"public",
"function",
"diffSeconds",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"?",
":",
"static",
"::",
"now",
"(",
"$",
"this",
"->",
"getTimezone",
"(",
")",
")",
";",
"return",
"$",
"v",
"->",
"getTimestamp",
"("... | Get the difference in seconds
@param Verta|null $v
@return int | [
"Get",
"the",
"difference",
"in",
"seconds"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1577-L1582 |
hekmatinasser/verta | src/Verta.php | Verta.between | public function between(Verta $v1, Verta $v2, $equal = true)
{
if ($v1->gt($v2)) {
$temp = $v1;
$v1 = $v2;
$v2 = $temp;
}
if ($equal) {
return $this->gte($v1) && $this->lte($v2);
}
return $this->gt($v1) && $this->lt($v2);
} | php | public function between(Verta $v1, Verta $v2, $equal = true)
{
if ($v1->gt($v2)) {
$temp = $v1;
$v1 = $v2;
$v2 = $temp;
}
if ($equal) {
return $this->gte($v1) && $this->lte($v2);
}
return $this->gt($v1) && $this->lt($v2);
} | [
"public",
"function",
"between",
"(",
"Verta",
"$",
"v1",
",",
"Verta",
"$",
"v2",
",",
"$",
"equal",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"v1",
"->",
"gt",
"(",
"$",
"v2",
")",
")",
"{",
"$",
"temp",
"=",
"$",
"v1",
";",
"$",
"v1",
"=",
... | Determines if the instance is between two others
@param Verta $v1
@param Verta $v2
@param bool $equal Indicates if a > and < comparison should be used or <= or >=
@return bool | [
"Determines",
"if",
"the",
"instance",
"is",
"between",
"two",
"others"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1749-L1762 |
hekmatinasser/verta | src/Verta.php | Verta.closest | public function closest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) < $this->diffSeconds($v2) ? $v1 : $v2;
} | php | public function closest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) < $this->diffSeconds($v2) ? $v1 : $v2;
} | [
"public",
"function",
"closest",
"(",
"Verta",
"$",
"v1",
",",
"Verta",
"$",
"v2",
")",
"{",
"return",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v1",
")",
"<",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v2",
")",
"?",
"$",
"v1",
":",
"$",
... | Get the closest date from the instance.
@param Verta $v1
@param Verta $v2
@return static | [
"Get",
"the",
"closest",
"date",
"from",
"the",
"instance",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1772-L1775 |
hekmatinasser/verta | src/Verta.php | Verta.farthest | public function farthest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) > $this->diffSeconds($v2) ? $v1 : $v2;
} | php | public function farthest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) > $this->diffSeconds($v2) ? $v1 : $v2;
} | [
"public",
"function",
"farthest",
"(",
"Verta",
"$",
"v1",
",",
"Verta",
"$",
"v2",
")",
"{",
"return",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v1",
")",
">",
"$",
"this",
"->",
"diffSeconds",
"(",
"$",
"v2",
")",
"?",
"$",
"v1",
":",
"$",
... | Get the farthest date from the instance.
@param Verta $v1
@param Verta $v2
@return static | [
"Get",
"the",
"farthest",
"date",
"from",
"the",
"instance",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1785-L1788 |
hekmatinasser/verta | src/Verta.php | Verta.min | public function min(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->lt($v) ? $this : $v;
} | php | public function min(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->lt($v) ? $this : $v;
} | [
"public",
"function",
"min",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"?",
":",
"static",
"::",
"now",
"(",
"$",
"this",
"->",
"getTimezone",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"lt",
"(",
"$",
"v",... | Get the minimum instance between a given instance (default now) and the current instance.
@param Verta|null $v
@return static | [
"Get",
"the",
"minimum",
"instance",
"between",
"a",
"given",
"instance",
"(",
"default",
"now",
")",
"and",
"the",
"current",
"instance",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1797-L1802 |
hekmatinasser/verta | src/Verta.php | Verta.max | public function max(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->gt($v) ? $this : $v;
} | php | public function max(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->gt($v) ? $this : $v;
} | [
"public",
"function",
"max",
"(",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"?",
":",
"static",
"::",
"now",
"(",
"$",
"this",
"->",
"getTimezone",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"gt",
"(",
"$",
"v",... | Get the maximum instance between a given instance (default now) and the current instance.
@param Verta|null $v
@return static | [
"Get",
"the",
"maximum",
"instance",
"between",
"a",
"given",
"instance",
"(",
"default",
"now",
")",
"and",
"the",
"current",
"instance",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1825-L1830 |
hekmatinasser/verta | src/Verta.php | Verta.isSameAs | public function isSameAs($format, Verta $v = null)
{
$v = $v ?: static::now($this->timezone);
return $this->format($format) === $v->format($format);
} | php | public function isSameAs($format, Verta $v = null)
{
$v = $v ?: static::now($this->timezone);
return $this->format($format) === $v->format($format);
} | [
"public",
"function",
"isSameAs",
"(",
"$",
"format",
",",
"Verta",
"$",
"v",
"=",
"null",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"?",
":",
"static",
"::",
"now",
"(",
"$",
"this",
"->",
"timezone",
")",
";",
"return",
"$",
"this",
"->",
"format",
... | Compares the formatted values of the two dates.
@param string $format The date formats to compare.
@param Verta|null $v The instance to compare with or null to use current day.
@return bool | [
"Compares",
"the",
"formatted",
"values",
"of",
"the",
"two",
"dates",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L1984-L1989 |
hekmatinasser/verta | src/Verta.php | Verta.isSameMonth | public function isSameMonth(Verta $v = null, $ofSameYear = false)
{
$format = $ofSameYear ? 'Y-m' : 'm';
return $this->isSameAs($format, $v);
} | php | public function isSameMonth(Verta $v = null, $ofSameYear = false)
{
$format = $ofSameYear ? 'Y-m' : 'm';
return $this->isSameAs($format, $v);
} | [
"public",
"function",
"isSameMonth",
"(",
"Verta",
"$",
"v",
"=",
"null",
",",
"$",
"ofSameYear",
"=",
"false",
")",
"{",
"$",
"format",
"=",
"$",
"ofSameYear",
"?",
"'Y-m'",
":",
"'m'",
";",
"return",
"$",
"this",
"->",
"isSameAs",
"(",
"$",
"format... | Checks if the passed in date is in the same month as the instance month (and year if needed).
@param Verta|null $v The instance to compare with or null to use current day.
@param bool $ofSameYear Check if it is the same month in the same year.
@return bool | [
"Checks",
"if",
"the",
"passed",
"in",
"date",
"is",
"in",
"the",
"same",
"month",
"as",
"the",
"instance",
"month",
"(",
"and",
"year",
"if",
"needed",
")",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L2031-L2036 |
hekmatinasser/verta | src/Verta.php | Verta.addMonths | public function addMonths($value)
{
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-m-d-H-i-s'));
$month += $value;
if ($month > 12) {
$year += intval($month / 12);
$month = $month % 12;
}
elseif ($month < 1) {
$year += intval($month / 12) - 1;
$month = 12 + ($month % 12);
}
if($month == 0) {
$year--;
$month = 12;
}
if (($month > 6 && $month < 12 && $day == 31)) {
$day--;
}
else {
if ($month == 12 && ($day == 30 || $day == 31)) {
$day = self::isLeapYear($year) ? 30 : 29;
}
}
return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone());
} | php | public function addMonths($value)
{
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-m-d-H-i-s'));
$month += $value;
if ($month > 12) {
$year += intval($month / 12);
$month = $month % 12;
}
elseif ($month < 1) {
$year += intval($month / 12) - 1;
$month = 12 + ($month % 12);
}
if($month == 0) {
$year--;
$month = 12;
}
if (($month > 6 && $month < 12 && $day == 31)) {
$day--;
}
else {
if ($month == 12 && ($day == 30 || $day == 31)) {
$day = self::isLeapYear($year) ? 30 : 29;
}
}
return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone());
} | [
"public",
"function",
"addMonths",
"(",
"$",
"value",
")",
"{",
"list",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"this",
"->",
"fo... | Add months to the instance. Positive $value travels forward while
negative $value travels into the past.
@param int $value
@return static | [
"Add",
"months",
"to",
"the",
"instance",
".",
"Positive",
"$value",
"travels",
"forward",
"while",
"negative",
"$value",
"travels",
"into",
"the",
"past",
"."
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L2191-L2216 |
hekmatinasser/verta | src/Verta.php | Verta.startQuarter | public function startQuarter()
{
$month = ($this->quarter - 1) * static::MONTHS_PER_QUARTER + 1;
return $this->setDateTime($this->year, $month, 1, 0, 0, 0);
} | php | public function startQuarter()
{
$month = ($this->quarter - 1) * static::MONTHS_PER_QUARTER + 1;
return $this->setDateTime($this->year, $month, 1, 0, 0, 0);
} | [
"public",
"function",
"startQuarter",
"(",
")",
"{",
"$",
"month",
"=",
"(",
"$",
"this",
"->",
"quarter",
"-",
"1",
")",
"*",
"static",
"::",
"MONTHS_PER_QUARTER",
"+",
"1",
";",
"return",
"$",
"this",
"->",
"setDateTime",
"(",
"$",
"this",
"->",
"y... | Resets the date to the first day of the quarter and the time to 00:00:00
@return static | [
"Resets",
"the",
"date",
"to",
"the",
"first",
"day",
"of",
"the",
"quarter",
"and",
"the",
"time",
"to",
"00",
":",
"00",
":",
"00"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L2572-L2577 |
hekmatinasser/verta | src/Verta.php | Verta.getJalali | public static function getJalali($g_y, $g_m, $g_d) {
$gy = $g_y - 1600;
$gm = $g_m - 1;
$g_day_no = (365 * $gy + static::div($gy + 3, 4) - static::div($gy + 99, 100) + static::div($gy + 399, 400));
for ($i = 0; $i < $gm; ++$i) {
$g_day_no += static::$daysMonthGregorian[$i];
}
if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0)))
# leap and after Feb
$g_day_no ++;
$g_day_no += $g_d - 1;
$j_day_no = $g_day_no - 79;
$j_np = static::div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
$j_day_no = $j_day_no % 12053;
$jy = (979 + 33 * $j_np + 4 * static::div($j_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$j_day_no %= 1461;
if ($j_day_no >= 366) {
$jy += static::div($j_day_no - 1, 365);
$j_day_no = ($j_day_no - 1) % 365;
}
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
$j_day_no -= static::$daysMonthJalali[$i];
}
return array($jy, $i + 1, $j_day_no + 1);
} | php | public static function getJalali($g_y, $g_m, $g_d) {
$gy = $g_y - 1600;
$gm = $g_m - 1;
$g_day_no = (365 * $gy + static::div($gy + 3, 4) - static::div($gy + 99, 100) + static::div($gy + 399, 400));
for ($i = 0; $i < $gm; ++$i) {
$g_day_no += static::$daysMonthGregorian[$i];
}
if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0)))
# leap and after Feb
$g_day_no ++;
$g_day_no += $g_d - 1;
$j_day_no = $g_day_no - 79;
$j_np = static::div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
$j_day_no = $j_day_no % 12053;
$jy = (979 + 33 * $j_np + 4 * static::div($j_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$j_day_no %= 1461;
if ($j_day_no >= 366) {
$jy += static::div($j_day_no - 1, 365);
$j_day_no = ($j_day_no - 1) % 365;
}
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
$j_day_no -= static::$daysMonthJalali[$i];
}
return array($jy, $i + 1, $j_day_no + 1);
} | [
"public",
"static",
"function",
"getJalali",
"(",
"$",
"g_y",
",",
"$",
"g_m",
",",
"$",
"g_d",
")",
"{",
"$",
"gy",
"=",
"$",
"g_y",
"-",
"1600",
";",
"$",
"gm",
"=",
"$",
"g_m",
"-",
"1",
";",
"$",
"g_day_no",
"=",
"(",
"365",
"*",
"$",
"... | gregorian to jalali convertion
@param int $g_y
@param int $g_m
@param int $g_d
@return array | [
"gregorian",
"to",
"jalali",
"convertion"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L2621-L2645 |
hekmatinasser/verta | src/Verta.php | Verta.getGregorian | public static function getGregorian($j_y, $j_m, $j_d) {
$jy = $j_y - 979;
$jm = $j_m - 1;
$j_day_no = (365 * $jy + static::div($jy, 33) * 8 + static::div($jy % 33 + 3, 4));
for ($i = 0; $i < $jm; ++$i) {
$j_day_no += static::$daysMonthJalali[$i];
}
$j_day_no += $j_d - 1;
$g_day_no = $j_day_no + 79;
$gy = (1600 + 400 * static::div($g_day_no, 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400)
$g_day_no = $g_day_no % 146097;
$leap = 1;
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
$g_day_no --;
$gy += (100 * static::div($g_day_no, 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
$g_day_no = $g_day_no % 36524;
if ($g_day_no >= 365) {
$g_day_no ++;
} else {
$leap = 0;
}
}
$gy += (4 * static::div($g_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$g_day_no %= 1461;
if ($g_day_no >= 366) {
$leap = 0;
$g_day_no --;
$gy += static::div($g_day_no, 365);
$g_day_no = ($g_day_no % 365);
}
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i ++) {
$g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap));
}
return array($gy, $i + 1, $g_day_no + 1);
} | php | public static function getGregorian($j_y, $j_m, $j_d) {
$jy = $j_y - 979;
$jm = $j_m - 1;
$j_day_no = (365 * $jy + static::div($jy, 33) * 8 + static::div($jy % 33 + 3, 4));
for ($i = 0; $i < $jm; ++$i) {
$j_day_no += static::$daysMonthJalali[$i];
}
$j_day_no += $j_d - 1;
$g_day_no = $j_day_no + 79;
$gy = (1600 + 400 * static::div($g_day_no, 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400)
$g_day_no = $g_day_no % 146097;
$leap = 1;
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
$g_day_no --;
$gy += (100 * static::div($g_day_no, 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
$g_day_no = $g_day_no % 36524;
if ($g_day_no >= 365) {
$g_day_no ++;
} else {
$leap = 0;
}
}
$gy += (4 * static::div($g_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
$g_day_no %= 1461;
if ($g_day_no >= 366) {
$leap = 0;
$g_day_no --;
$gy += static::div($g_day_no, 365);
$g_day_no = ($g_day_no % 365);
}
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i ++) {
$g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap));
}
return array($gy, $i + 1, $g_day_no + 1);
} | [
"public",
"static",
"function",
"getGregorian",
"(",
"$",
"j_y",
",",
"$",
"j_m",
",",
"$",
"j_d",
")",
"{",
"$",
"jy",
"=",
"$",
"j_y",
"-",
"979",
";",
"$",
"jm",
"=",
"$",
"j_m",
"-",
"1",
";",
"$",
"j_day_no",
"=",
"(",
"365",
"*",
"$",
... | jalali to gregorian convertion
@param int $j_y
@param int $j_m
@param int $j_d
@return array | [
"jalali",
"to",
"gregorian",
"convertion"
] | train | https://github.com/hekmatinasser/verta/blob/14d06ab6cf915ac37a46663569c265387d313f5c/src/Verta.php#L2655-L2689 |
spatie/laravel-url-signer | src/UrlSignerServiceProvider.php | UrlSignerServiceProvider.register | public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/url-signer.php', 'url-signer');
$config = config('url-signer');
$this->app->singleton(UrlSignerContract::class, function () use ($config) {
return new UrlSigner(
$config['signatureKey'],
$config['parameters']['expires'],
$config['parameters']['signature']
);
});
$this->app->alias(UrlSignerContract::class, 'url-signer');
$this->app[Router::class]->aliasMiddleware('signedurl', ValidateSignature::class);
} | php | public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/url-signer.php', 'url-signer');
$config = config('url-signer');
$this->app->singleton(UrlSignerContract::class, function () use ($config) {
return new UrlSigner(
$config['signatureKey'],
$config['parameters']['expires'],
$config['parameters']['signature']
);
});
$this->app->alias(UrlSignerContract::class, 'url-signer');
$this->app[Router::class]->aliasMiddleware('signedurl', ValidateSignature::class);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/../config/url-signer.php'",
",",
"'url-signer'",
")",
";",
"$",
"config",
"=",
"config",
"(",
"'url-signer'",
")",
";",
"$",
"this",
"->",
"app",
... | Register the service provider. | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/spatie/laravel-url-signer/blob/1a6dcb8f4d367fd24a69991a8d90150c725bfcf8/src/UrlSignerServiceProvider.php#L36-L53 |
ralouphie/mimey | src/MimeMappingGenerator.php | MimeMappingGenerator.generateMapping | public function generateMapping()
{
$mapping = array();
$lines = explode("\n", $this->mime_types_text);
foreach ($lines as $line) {
$line = trim(preg_replace('~\\#.*~', '', $line));
$parts = $line ? array_values(array_filter(explode("\t", $line))) : array();
if (count($parts) === 2) {
$mime = trim($parts[0]);
$extensions = explode(' ', $parts[1]);
foreach ($extensions as $extension) {
$extension = trim($extension);
if ($mime && $extension) {
$mapping['mimes'][$extension][] = $mime;
$mapping['extensions'][$mime][] = $extension;
$mapping['mimes'][$extension] = array_unique($mapping['mimes'][$extension]);
$mapping['extensions'][$mime] = array_unique($mapping['extensions'][$mime]);
}
}
}
}
return $mapping;
} | php | public function generateMapping()
{
$mapping = array();
$lines = explode("\n", $this->mime_types_text);
foreach ($lines as $line) {
$line = trim(preg_replace('~\\#.*~', '', $line));
$parts = $line ? array_values(array_filter(explode("\t", $line))) : array();
if (count($parts) === 2) {
$mime = trim($parts[0]);
$extensions = explode(' ', $parts[1]);
foreach ($extensions as $extension) {
$extension = trim($extension);
if ($mime && $extension) {
$mapping['mimes'][$extension][] = $mime;
$mapping['extensions'][$mime][] = $extension;
$mapping['mimes'][$extension] = array_unique($mapping['mimes'][$extension]);
$mapping['extensions'][$mime] = array_unique($mapping['extensions'][$mime]);
}
}
}
}
return $mapping;
} | [
"public",
"function",
"generateMapping",
"(",
")",
"{",
"$",
"mapping",
"=",
"array",
"(",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"mime_types_text",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
"... | Read the given mime.types text and return a mapping compatible with the MimeTypes class.
@return array The mapping. | [
"Read",
"the",
"given",
"mime",
".",
"types",
"text",
"and",
"return",
"a",
"mapping",
"compatible",
"with",
"the",
"MimeTypes",
"class",
"."
] | train | https://github.com/ralouphie/mimey/blob/bafaa2c603dd070736bf8a37ea2daf5654d226f2/src/MimeMappingGenerator.php#L29-L51 |
ralouphie/mimey | src/MimeTypes.php | MimeTypes.getBuiltIn | protected static function getBuiltIn()
{
if (self::$built_in === null) {
self::$built_in = require(dirname(__DIR__) . '/mime.types.php');
}
return self::$built_in;
} | php | protected static function getBuiltIn()
{
if (self::$built_in === null) {
self::$built_in = require(dirname(__DIR__) . '/mime.types.php');
}
return self::$built_in;
} | [
"protected",
"static",
"function",
"getBuiltIn",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"built_in",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"built_in",
"=",
"require",
"(",
"dirname",
"(",
"__DIR__",
")",
".",
"'/mime.types.php'",
")",
";",
"... | Get the built-in mapping.
@return array The built-in mapping. | [
"Get",
"the",
"built",
"-",
"in",
"mapping",
"."
] | train | https://github.com/ralouphie/mimey/blob/bafaa2c603dd070736bf8a37ea2daf5654d226f2/src/MimeTypes.php#L102-L108 |
ralouphie/mimey | src/MimeMappingBuilder.php | MimeMappingBuilder.add | public function add($mime, $extension, $prepend_extension = true, $prepend_mime = true)
{
$existing_extensions = empty($this->mapping['extensions'][$mime]) ? array() : $this->mapping['extensions'][$mime];
$existing_mimes = empty($this->mapping['mimes'][$extension]) ? array() : $this->mapping['mimes'][$extension];
if ($prepend_extension) {
array_unshift($existing_extensions, $extension);
} else {
$existing_extensions[] = $extension;
}
if ($prepend_mime) {
array_unshift($existing_mimes, $mime);
} else {
$existing_mimes[] = $mime;
}
$this->mapping['extensions'][$mime] = array_unique($existing_extensions);
$this->mapping['mimes'][$extension] = array_unique($existing_mimes);
} | php | public function add($mime, $extension, $prepend_extension = true, $prepend_mime = true)
{
$existing_extensions = empty($this->mapping['extensions'][$mime]) ? array() : $this->mapping['extensions'][$mime];
$existing_mimes = empty($this->mapping['mimes'][$extension]) ? array() : $this->mapping['mimes'][$extension];
if ($prepend_extension) {
array_unshift($existing_extensions, $extension);
} else {
$existing_extensions[] = $extension;
}
if ($prepend_mime) {
array_unshift($existing_mimes, $mime);
} else {
$existing_mimes[] = $mime;
}
$this->mapping['extensions'][$mime] = array_unique($existing_extensions);
$this->mapping['mimes'][$extension] = array_unique($existing_mimes);
} | [
"public",
"function",
"add",
"(",
"$",
"mime",
",",
"$",
"extension",
",",
"$",
"prepend_extension",
"=",
"true",
",",
"$",
"prepend_mime",
"=",
"true",
")",
"{",
"$",
"existing_extensions",
"=",
"empty",
"(",
"$",
"this",
"->",
"mapping",
"[",
"'extensi... | Add a conversion.
@param string $mime The MIME type.
@param string $extension The extension.
@param bool $prepend_extension Whether this should be the preferred conversion for MIME type to extension.
@param bool $prepend_mime Whether this should be the preferred conversion for extension to MIME type. | [
"Add",
"a",
"conversion",
"."
] | train | https://github.com/ralouphie/mimey/blob/bafaa2c603dd070736bf8a37ea2daf5654d226f2/src/MimeMappingBuilder.php#L31-L47 |
ralouphie/mimey | src/MimeMappingBuilder.php | MimeMappingBuilder.save | public function save($file, $flags = null, $context = null)
{
return file_put_contents($file, $this->compile(), $flags, $context);
} | php | public function save($file, $flags = null, $context = null)
{
return file_put_contents($file, $this->compile(), $flags, $context);
} | [
"public",
"function",
"save",
"(",
"$",
"file",
",",
"$",
"flags",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"return",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"compile",
"(",
")",
",",
"$",
"flags",
",",
"$",
... | Save the current mapping to a file.
@param string $file The file to save to.
@param int $flags Flags for `file_put_contents`.
@param resource $context Context for `file_put_contents`.
@return int|bool The number of bytes that were written to the file, or false on failure. | [
"Save",
"the",
"current",
"mapping",
"to",
"a",
"file",
"."
] | train | https://github.com/ralouphie/mimey/blob/bafaa2c603dd070736bf8a37ea2daf5654d226f2/src/MimeMappingBuilder.php#L78-L81 |
orchestral/tenanti | src/Migrator/Notable.php | Notable.note | protected function note(...$message): void
{
if ($this->notice instanceof Notice) {
$this->notice->add($message);
}
} | php | protected function note(...$message): void
{
if ($this->notice instanceof Notice) {
$this->notice->add($message);
}
} | [
"protected",
"function",
"note",
"(",
"...",
"$",
"message",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"notice",
"instanceof",
"Notice",
")",
"{",
"$",
"this",
"->",
"notice",
"->",
"add",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | Raise a note event.
@param string $message
@return void | [
"Raise",
"a",
"note",
"event",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Notable.php#L37-L42 |
orchestral/tenanti | src/Migrator/Notable.php | Notable.resolveMigratorWithNotes | protected function resolveMigratorWithNotes(string $table): Migrator
{
$migrator = $this->resolveMigrator($table);
if ($this->notice instanceof Notice) {
$this->notice->mergeWith($migrator);
}
return $migrator;
} | php | protected function resolveMigratorWithNotes(string $table): Migrator
{
$migrator = $this->resolveMigrator($table);
if ($this->notice instanceof Notice) {
$this->notice->mergeWith($migrator);
}
return $migrator;
} | [
"protected",
"function",
"resolveMigratorWithNotes",
"(",
"string",
"$",
"table",
")",
":",
"Migrator",
"{",
"$",
"migrator",
"=",
"$",
"this",
"->",
"resolveMigrator",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"this",
"->",
"notice",
"instanceof",
"Not... | Resolve migrator with notable.
@param string $table
@return \Orchestra\Tenanti\Migrator\Migrator | [
"Resolve",
"migrator",
"with",
"notable",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Notable.php#L51-L60 |
orchestral/tenanti | src/Jobs/CreateTenant.php | CreateTenant.handle | public function handle()
{
if ($this->shouldBeFailed()) {
return;
}
$database = $this->config['database'] ?? null;
$migrator = $this->resolveMigrator();
if (! $this->shouldBeDelayed()) {
$migrator->runInstall($this->model, $database);
$migrator->runUp($this->model, $database);
$this->delete();
}
} | php | public function handle()
{
if ($this->shouldBeFailed()) {
return;
}
$database = $this->config['database'] ?? null;
$migrator = $this->resolveMigrator();
if (! $this->shouldBeDelayed()) {
$migrator->runInstall($this->model, $database);
$migrator->runUp($this->model, $database);
$this->delete();
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldBeFailed",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"database",
"=",
"$",
"this",
"->",
"config",
"[",
"'database'",
"]",
"??",
"null",
";",
"$",
"migrator",
"=... | Fire queue on creating a model.
@return void | [
"Fire",
"queue",
"on",
"creating",
"a",
"model",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Jobs/CreateTenant.php#L12-L27 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerQueuedCommand | protected function registerQueuedCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.queue', function (Application $app) {
return new QueuedCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerQueuedCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.queue', function (Application $app) {
return new QueuedCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerQueuedCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.queue'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"QueuedCommand",
"("... | Register the "queue" migration command.
@return void | [
"Register",
"the",
"queue",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L49-L54 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerInstallCommand | protected function registerInstallCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.install', function (Application $app) {
return new InstallCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerInstallCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.install', function (Application $app) {
return new InstallCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerInstallCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.install'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"InstallCommand",
... | Register the "install" migration command.
@return void | [
"Register",
"the",
"install",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L61-L66 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerMakeCommand | protected function registerMakeCommand(): void
{
$this->app->singleton('orchestra.tenanti.creator', function (Application $app) {
return new Creator($app->make('files'));
});
$this->app->singleton('orchestra.commands.tenanti.make', function (Application $app) {
// Once we have the migration creator registered, we will create the command
// and inject the creator. The creator is responsible for the actual file
// creation of the migrations, and may be extended by these developers.
return new MigrateMakeCommand(
$app->make('orchestra.tenanti'),
$app->make('orchestra.tenanti.creator'),
$app->make('composer')
);
});
} | php | protected function registerMakeCommand(): void
{
$this->app->singleton('orchestra.tenanti.creator', function (Application $app) {
return new Creator($app->make('files'));
});
$this->app->singleton('orchestra.commands.tenanti.make', function (Application $app) {
// Once we have the migration creator registered, we will create the command
// and inject the creator. The creator is responsible for the actual file
// creation of the migrations, and may be extended by these developers.
return new MigrateMakeCommand(
$app->make('orchestra.tenanti'),
$app->make('orchestra.tenanti.creator'),
$app->make('composer')
);
});
} | [
"protected",
"function",
"registerMakeCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.tenanti.creator'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"Creator",
"(",
"$",
"app... | Register the "make" migration command.
@return void | [
"Register",
"the",
"make",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L73-L89 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerMigrateCommand | protected function registerMigrateCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.migrate', function (Application $app) {
return new MigrateCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerMigrateCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.migrate', function (Application $app) {
return new MigrateCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerMigrateCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.migrate'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"MigrateCommand",
... | Register the "migrate" migration command.
@return void | [
"Register",
"the",
"migrate",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L96-L101 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerRollbackCommand | protected function registerRollbackCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.rollback', function (Application $app) {
return new RollbackCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerRollbackCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.rollback', function (Application $app) {
return new RollbackCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerRollbackCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.rollback'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"RollbackCommand"... | Register the "rollback" migration command.
@return void | [
"Register",
"the",
"rollback",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L108-L113 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerResetCommand | protected function registerResetCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.reset', function (Application $app) {
return new ResetCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerResetCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.reset', function (Application $app) {
return new ResetCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerResetCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.reset'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"ResetCommand",
"(",
... | Register the "reset" migration command.
@return void | [
"Register",
"the",
"reset",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L120-L125 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerRefreshCommand | protected function registerRefreshCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.refresh', function (Application $app) {
return new RefreshCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerRefreshCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.refresh', function (Application $app) {
return new RefreshCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerRefreshCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.refresh'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"RefreshCommand",
... | Register the "refresh" migration command.
@return void | [
"Register",
"the",
"refresh",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L132-L137 |
orchestral/tenanti | src/CommandServiceProvider.php | CommandServiceProvider.registerTinkerCommand | protected function registerTinkerCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.tinker', function (Application $app) {
return new TinkerCommand($app->make('orchestra.tenanti'));
});
} | php | protected function registerTinkerCommand(): void
{
$this->app->singleton('orchestra.commands.tenanti.tinker', function (Application $app) {
return new TinkerCommand($app->make('orchestra.tenanti'));
});
} | [
"protected",
"function",
"registerTinkerCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'orchestra.commands.tenanti.tinker'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"new",
"TinkerCommand",
"(... | Register the "tinker" migration command.
@return void | [
"Register",
"the",
"tinker",
"migration",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/CommandServiceProvider.php#L144-L149 |
orchestral/tenanti | src/Jobs/DeleteTenant.php | DeleteTenant.handle | public function handle()
{
if ($this->shouldBeFailed()) {
return;
}
$database = $this->config['database'] ?? null;
$migrator = $this->resolveMigrator();
if (! $this->shouldBeDelayed()) {
$migrator->runReset($this->model, $database);
$this->delete();
}
} | php | public function handle()
{
if ($this->shouldBeFailed()) {
return;
}
$database = $this->config['database'] ?? null;
$migrator = $this->resolveMigrator();
if (! $this->shouldBeDelayed()) {
$migrator->runReset($this->model, $database);
$this->delete();
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldBeFailed",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"database",
"=",
"$",
"this",
"->",
"config",
"[",
"'database'",
"]",
"??",
"null",
";",
"$",
"migrator",
"=... | Fire queue on deleting a model.
@return void | [
"Fire",
"queue",
"on",
"deleting",
"a",
"model",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Jobs/DeleteTenant.php#L12-L26 |
orchestral/tenanti | src/Tenantor.php | Tenantor.fromEloquent | public static function fromEloquent(string $name, Model $model, ?string $connection = null)
{
return static::make(
$name, $model->getKey(), $connection ?? $model->getConnectionName(), $model
);
} | php | public static function fromEloquent(string $name, Model $model, ?string $connection = null)
{
return static::make(
$name, $model->getKey(), $connection ?? $model->getConnectionName(), $model
);
} | [
"public",
"static",
"function",
"fromEloquent",
"(",
"string",
"$",
"name",
",",
"Model",
"$",
"model",
",",
"?",
"string",
"$",
"connection",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"make",
"(",
"$",
"name",
",",
"$",
"model",
"->",
"getKey",... | Make a tenantor instance.
@param string $name
@param \Illuminate\Database\Eloquent\Model $model
@param string|null $connection
@return static | [
"Make",
"a",
"tenantor",
"instance",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Tenantor.php#L19-L24 |
orchestral/tenanti | src/Tenantor.php | Tenantor.make | public static function make(string $name, $key, ?string $connection = null, ?Model $model = null)
{
return new static(\compact('name', 'key', 'connection', 'model'));
} | php | public static function make(string $name, $key, ?string $connection = null, ?Model $model = null)
{
return new static(\compact('name', 'key', 'connection', 'model'));
} | [
"public",
"static",
"function",
"make",
"(",
"string",
"$",
"name",
",",
"$",
"key",
",",
"?",
"string",
"$",
"connection",
"=",
"null",
",",
"?",
"Model",
"$",
"model",
"=",
"null",
")",
"{",
"return",
"new",
"static",
"(",
"\\",
"compact",
"(",
"... | Make a tenantor instance.
@param string $name
@param mixed $key
@param string|null $connection
@param \Illuminate\Database\Eloquent\Model|null $model
@return static | [
"Make",
"a",
"tenantor",
"instance",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Tenantor.php#L36-L39 |
orchestral/tenanti | src/Eloquent/Tenantee.php | Tenantee.setTenantor | public function setTenantor(?Tenantor $tenantor)
{
$this->tenantor = $tenantor;
$this->connection = $tenantor->getTenantConnectionName();
$this->setTable($this->getTenantTable());
return $this;
} | php | public function setTenantor(?Tenantor $tenantor)
{
$this->tenantor = $tenantor;
$this->connection = $tenantor->getTenantConnectionName();
$this->setTable($this->getTenantTable());
return $this;
} | [
"public",
"function",
"setTenantor",
"(",
"?",
"Tenantor",
"$",
"tenantor",
")",
"{",
"$",
"this",
"->",
"tenantor",
"=",
"$",
"tenantor",
";",
"$",
"this",
"->",
"connection",
"=",
"$",
"tenantor",
"->",
"getTenantConnectionName",
"(",
")",
";",
"$",
"t... | Get the tenantor associated with the model.
@param \Orchestra\Tenanti\Tenantor|null $tenantor
@return $this | [
"Get",
"the",
"tenantor",
"associated",
"with",
"the",
"model",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Eloquent/Tenantee.php#L50-L58 |
orchestral/tenanti | src/Console/BaseCommand.php | BaseCommand.getDriver | protected function getDriver(): string
{
$driver = $this->argument('driver') ?: $this->getDriverFromConfig();
if (! empty($driver)) {
return $driver;
}
throw new RuntimeException('Not enough arguments (missing: "driver").');
} | php | protected function getDriver(): string
{
$driver = $this->argument('driver') ?: $this->getDriverFromConfig();
if (! empty($driver)) {
return $driver;
}
throw new RuntimeException('Not enough arguments (missing: "driver").');
} | [
"protected",
"function",
"getDriver",
"(",
")",
":",
"string",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"argument",
"(",
"'driver'",
")",
"?",
":",
"$",
"this",
"->",
"getDriverFromConfig",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"driver... | Get driver argument or first driver in the config.
@return string | [
"Get",
"driver",
"argument",
"or",
"first",
"driver",
"in",
"the",
"config",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/BaseCommand.php#L51-L60 |
orchestral/tenanti | src/Console/BaseCommand.php | BaseCommand.getDriverFromConfig | protected function getDriverFromConfig(): ?string
{
$drivers = \array_keys($this->tenant->getConfig('drivers'));
if (\count($drivers) === 1) {
return $drivers[0];
}
return null;
} | php | protected function getDriverFromConfig(): ?string
{
$drivers = \array_keys($this->tenant->getConfig('drivers'));
if (\count($drivers) === 1) {
return $drivers[0];
}
return null;
} | [
"protected",
"function",
"getDriverFromConfig",
"(",
")",
":",
"?",
"string",
"{",
"$",
"drivers",
"=",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"tenant",
"->",
"getConfig",
"(",
"'drivers'",
")",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"drive... | Get first driver in the config.
@return string | [
"Get",
"first",
"driver",
"in",
"the",
"config",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/BaseCommand.php#L67-L76 |
orchestral/tenanti | src/Console/BaseCommand.php | BaseCommand.getArgumentsWithDriver | protected function getArgumentsWithDriver(...$arguments): array
{
\array_unshift($arguments, 'driver');
$resolvedArguments = [];
$this->validateMissingArguments($arguments);
if (empty($this->argument(\end($arguments)))) {
$driver = $this->getDriverFromConfig();
if (empty($driver)) {
throw new RuntimeException('Not enough arguments (missing: "driver").');
}
$resolvedArguments['driver'] = $driver;
for ($i = 1; $i < \count($arguments); $i++) {
$resolvedArguments[$arguments[$i]] = $this->argument($arguments[$i - 1]);
}
} else {
foreach ($arguments as $argument) {
$resolvedArguments[$argument] = $this->argument($argument);
}
}
return $resolvedArguments;
} | php | protected function getArgumentsWithDriver(...$arguments): array
{
\array_unshift($arguments, 'driver');
$resolvedArguments = [];
$this->validateMissingArguments($arguments);
if (empty($this->argument(\end($arguments)))) {
$driver = $this->getDriverFromConfig();
if (empty($driver)) {
throw new RuntimeException('Not enough arguments (missing: "driver").');
}
$resolvedArguments['driver'] = $driver;
for ($i = 1; $i < \count($arguments); $i++) {
$resolvedArguments[$arguments[$i]] = $this->argument($arguments[$i - 1]);
}
} else {
foreach ($arguments as $argument) {
$resolvedArguments[$argument] = $this->argument($argument);
}
}
return $resolvedArguments;
} | [
"protected",
"function",
"getArgumentsWithDriver",
"(",
"...",
"$",
"arguments",
")",
":",
"array",
"{",
"\\",
"array_unshift",
"(",
"$",
"arguments",
",",
"'driver'",
")",
";",
"$",
"resolvedArguments",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"validateMissin... | Get the required arguments when used with optional driver argument.
@return array | [
"Get",
"the",
"required",
"arguments",
"when",
"used",
"with",
"optional",
"driver",
"argument",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/BaseCommand.php#L83-L110 |
orchestral/tenanti | src/Console/BaseCommand.php | BaseCommand.validateMissingArguments | protected function validateMissingArguments(array $arguments): bool
{
$missingArguments = \array_filter($arguments, function ($argument) {
return empty($this->argument($argument));
});
if (\count($missingArguments) > 1) {
throw new RuntimeException(\sprintf('Not enough arguments (missing: "%s").', \implode(', ', $missingArguments)));
}
return true;
} | php | protected function validateMissingArguments(array $arguments): bool
{
$missingArguments = \array_filter($arguments, function ($argument) {
return empty($this->argument($argument));
});
if (\count($missingArguments) > 1) {
throw new RuntimeException(\sprintf('Not enough arguments (missing: "%s").', \implode(', ', $missingArguments)));
}
return true;
} | [
"protected",
"function",
"validateMissingArguments",
"(",
"array",
"$",
"arguments",
")",
":",
"bool",
"{",
"$",
"missingArguments",
"=",
"\\",
"array_filter",
"(",
"$",
"arguments",
",",
"function",
"(",
"$",
"argument",
")",
"{",
"return",
"empty",
"(",
"$... | Validate missing arguments.
@param array $arguments
@throws \Symfony\Component\Console\Exception\RuntimeException
@return bool | [
"Validate",
"missing",
"arguments",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/BaseCommand.php#L121-L132 |
orchestral/tenanti | src/Eloquent/Builder.php | Builder.newModelInstance | public function newModelInstance($attributes = [])
{
return \tap(parent::newModelInstance($attributes), function ($model) {
$model->setTenantor($this->tenantor);
});
} | php | public function newModelInstance($attributes = [])
{
return \tap(parent::newModelInstance($attributes), function ($model) {
$model->setTenantor($this->tenantor);
});
} | [
"public",
"function",
"newModelInstance",
"(",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"return",
"\\",
"tap",
"(",
"parent",
"::",
"newModelInstance",
"(",
"$",
"attributes",
")",
",",
"function",
"(",
"$",
"model",
")",
"{",
"$",
"model",
"->",
"s... | Create a new instance of the model being queried.
@param array $attributes
@return \Illuminate\Database\Eloquent\Model | [
"Create",
"a",
"new",
"instance",
"of",
"the",
"model",
"being",
"queried",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Eloquent/Builder.php#L24-L29 |
orchestral/tenanti | src/Console/ResetCommand.php | ResetCommand.handle | public function handle()
{
if (! $this->confirmToProceed()) {
return;
}
\tap($this->tenant->driver($this->getDriver()), function ($migrator) {
$this->setupMigrationOutput($migrator);
$migrator->reset(
$this->option('database'), $this->option('id'), $this->option('pretend', false)
);
});
} | php | public function handle()
{
if (! $this->confirmToProceed()) {
return;
}
\tap($this->tenant->driver($this->getDriver()), function ($migrator) {
$this->setupMigrationOutput($migrator);
$migrator->reset(
$this->option('database'), $this->option('id'), $this->option('pretend', false)
);
});
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"confirmToProceed",
"(",
")",
")",
"{",
"return",
";",
"}",
"\\",
"tap",
"(",
"$",
"this",
"->",
"tenant",
"->",
"driver",
"(",
"$",
"this",
"->",
"getDriver",
"(",
... | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/ResetCommand.php#L30-L43 |
orchestral/tenanti | src/Console/TinkerCommand.php | TinkerCommand.handle | public function handle()
{
$arguments = $this->getArgumentsWithDriver('id');
\tap($this->tenant->driver($arguments['driver']), function ($tenanti) use ($arguments) {
$tenanti->asDefaultConnection(
$tenanti->getModel()->findOrFail($arguments['id']), 'tinker'
);
});
$this->call('tinker');
} | php | public function handle()
{
$arguments = $this->getArgumentsWithDriver('id');
\tap($this->tenant->driver($arguments['driver']), function ($tenanti) use ($arguments) {
$tenanti->asDefaultConnection(
$tenanti->getModel()->findOrFail($arguments['id']), 'tinker'
);
});
$this->call('tinker');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getArgumentsWithDriver",
"(",
"'id'",
")",
";",
"\\",
"tap",
"(",
"$",
"this",
"->",
"tenant",
"->",
"driver",
"(",
"$",
"arguments",
"[",
"'driver'",
"]",
")",
... | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/TinkerCommand.php#L28-L39 |
orchestral/tenanti | src/Console/MigrateMakeCommand.php | MigrateMakeCommand.handle | public function handle()
{
$arguments = $this->getArgumentsWithDriver('name');
$driver = $arguments['driver'];
$name = $arguments['name'];
// It's possible for the developer to specify the tables to modify in this
// schema operation. The developer may also specify if this table needs
// to be freshly created so we can create the appropriate migrations.
$create = $this->input->getOption('create');
$table = $this->input->getOption('table');
if (! $table && \is_string($create)) {
$table = $create;
}
// Now we are ready to write the migration out to disk. Once we've written
// the migration out, we will dump-autoload for the entire framework to
// make sure that the migrations are registered by the class loaders.
$this->writeMigration($driver, $name, $table, $create);
$this->composer->dumpAutoloads();
} | php | public function handle()
{
$arguments = $this->getArgumentsWithDriver('name');
$driver = $arguments['driver'];
$name = $arguments['name'];
// It's possible for the developer to specify the tables to modify in this
// schema operation. The developer may also specify if this table needs
// to be freshly created so we can create the appropriate migrations.
$create = $this->input->getOption('create');
$table = $this->input->getOption('table');
if (! $table && \is_string($create)) {
$table = $create;
}
// Now we are ready to write the migration out to disk. Once we've written
// the migration out, we will dump-autoload for the entire framework to
// make sure that the migrations are registered by the class loaders.
$this->writeMigration($driver, $name, $table, $create);
$this->composer->dumpAutoloads();
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getArgumentsWithDriver",
"(",
"'name'",
")",
";",
"$",
"driver",
"=",
"$",
"arguments",
"[",
"'driver'",
"]",
";",
"$",
"name",
"=",
"$",
"arguments",
"[",
"'name... | Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/MigrateMakeCommand.php#L60-L82 |
orchestral/tenanti | src/Console/MigrateMakeCommand.php | MigrateMakeCommand.writeMigration | protected function writeMigration($driver, $name, $table, $create)
{
$migrator = $this->tenant->driver($driver);
$files = $this->creator->getFilesystem();
$path = $migrator->getMigrationPaths();
if (! $files->isDirectory($path)) {
$files->makeDirectory($path, 0755, true);
}
if ($this->tenant->getConfig("{$driver}.shared", true) === true) {
$table = Str::replace($migrator->getTablePrefix()."_{$table}", ['id' => '{$id}']);
}
$name = \implode('_', [$driver, 'tenant', $name]);
$file = \pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);
$this->line("<info>Created Migration:</info> $file");
} | php | protected function writeMigration($driver, $name, $table, $create)
{
$migrator = $this->tenant->driver($driver);
$files = $this->creator->getFilesystem();
$path = $migrator->getMigrationPaths();
if (! $files->isDirectory($path)) {
$files->makeDirectory($path, 0755, true);
}
if ($this->tenant->getConfig("{$driver}.shared", true) === true) {
$table = Str::replace($migrator->getTablePrefix()."_{$table}", ['id' => '{$id}']);
}
$name = \implode('_', [$driver, 'tenant', $name]);
$file = \pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);
$this->line("<info>Created Migration:</info> $file");
} | [
"protected",
"function",
"writeMigration",
"(",
"$",
"driver",
",",
"$",
"name",
",",
"$",
"table",
",",
"$",
"create",
")",
"{",
"$",
"migrator",
"=",
"$",
"this",
"->",
"tenant",
"->",
"driver",
"(",
"$",
"driver",
")",
";",
"$",
"files",
"=",
"$... | Write the migration file to disk.
@param string $driver
@param string $name
@param string $table
@param bool $create
@return string | [
"Write",
"the",
"migration",
"file",
"to",
"disk",
"."
] | train | https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/MigrateMakeCommand.php#L94-L113 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.