Resolves any variation of masks/permissions to an integer.

@param string|int|array $masks

@param $object
@return int
778243
private function resolveMask($masks, $object)
    {
        $integerMask = 0;

        if (is_integer($masks)) {
            $integerMask = $masks;
        } elseif (is_string($masks)) {
            $permission = $this->permissionMap->getMasks($masks, $object);
            $integerMask = $this->resolveMask($permission, $object);
        } elseif (is_array($masks)) {
            foreach ($masks as $mask) {
                $integerMask += $this->resolveMask($mask, $object);
            }
        } else {
            throw new \RuntimeException('Not a valid mask type');
        }

        return $integerMask;
    }
1123639
protected function checkPermissionMask($selfError, $exists, $pathname, $mask)
    {
        return !(!$selfError && !$exists && !chmod($pathname, (int)$mask));
    }
722644
protected function isSecurityGranted($attributes, $object = null)
    {
        if (null === $this->getSecurityContext()->getToken())
        {
            return false;
        }

        return $this->getSecurityContext()->isGranted($attributes, $object);
    }
668505
protected function flushTransaction($object = null)
    {
        $violations = new ConstraintViolationList();

        try {
            $this->om->flush();

            if (null !== $this->connection && null === $object) {
                $this->connection->commit();
            }
        } catch (\Exception $e) {
            $this->flushTransactionException($e, $violations, $object);
        }

        return $violations;
    }
963313
public function defaults($object, $defaults)
    {
        if (is_array($defaults))
        {
            foreach ($defaults as $default)
            {
                $this->defaults($object, $default);
            }

            return $object;
        }

        foreach ($defaults as $key => $value)
        {
            if ( ! property_exists($object, $key))
            {
                $object->{$key} = $value;
            }
        }

        return $object;
    }
536636
public function normalize($object, $format = null, array $context = [])
    {
        $this->maxDepthHandler->handleMaxDepth($context);

        /** @var User $object */
        if ($this->byReferenceHandler->isByShortReference($context)) {
            return $object->getId();
        }

        if ($this->byReferenceHandler->isByReference($context)) {
            return [
                'id' => $object->getId(),
                'username' => $object->getUsername(),
            ];
        }

        try {
            return parent::normalize($object, $format, $context);
        } catch (CircularReferenceException $e) {
            return $object->getId();
        }
    }
643731
public function retornaValoresAtributosClassesMaes($object)
    {
        if (self::verificaSeEClasseFilha($object)) {
            
            $nomeClassesMae = self::retornaClassesMaes($object);
            
            $valores  = [];
            $iterator = 0;
            $limit    = count($nomeClassesMae);
            for ($iterator; $iterator < $limit; $iterator++) {
                $valores[$iterator] = self::pegaValoresAtributoDoObjeto(
                    $nomeClassesMae[$iterator]
                );
            }

            return $valores;
        }

        return false;
    }
189063
public function resolve($object, $language, TokenInterface $token)
    {
        if (!($object instanceof DomainObjectInterface)) {
            return array();
        }

        $permissionNames = array();

        if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
            if (!isset($this->superAdminPermissions[$token])) {
                $permissions = $this->permissionRegistry->get(get_class($object))->all();

                foreach ($permissions as $permission) {
                    $permissionNames[] = $permission->getName();
                }

                $this->superAdminPermissions[$token] = $permissionNames;
            }

            return $this->superAdminPermissions[$token];
        }

        if (!$this->authorizationChecker->isGranted(['permission' => 'VIEW', 'language' => $language], $object)) {
            return null;
        }

        $identity = HierarchicalObjectIdentity::fromDomainObject($object);
        $acl = $this->accessManager->findAcl($identity);

        $permissions = $acl->getEffectivePermissions($token, $language);

        foreach ($permissions as $permission) {
            $permissionNames[] = $permission->getName();
        }

        return $permissionNames;
    }
1079710
protected function doExtract($object)
    {
        $originalFieldNames = $this->metadata->getOriginalFieldNames();

        /*
        $filter = $object instanceof FilterProviderInterface
            ? $object->getFilter()
            : $this->filterComposite;
        */

        $data = [];
        if (! $this->metadata->hasCustomHydrator()) {

            $this->executeMethods($object, $this->metadata->getPreExtractListeners());

            foreach ($originalFieldNames as $originalFieldName) {
                $mappedFieldName = $this->metadata->getMappedFieldName($originalFieldName);

                if ($this->metadata->isNotManaged($mappedFieldName)) {
                    continue;
                }

                if ($this->metadata->isValueObject($mappedFieldName)) {
                    continue;
                }

                /*if ($filter && !$filter->filter($mappedFieldName)) {
                    continue;
                }*/

                try {
                    $value = $this->memberAccessStrategy->getValue($object, $mappedFieldName);             
                } catch (NotFoundMemberException $e) {
                    continue;
                }

                if (null === $value) {
                    $data[$originalFieldName] = null;
                    continue;
                }

                if ($fieldClass = $this->metadata->getClassOfMappedField($mappedFieldName)) {
                    $fieldHydrator = $this->objectManager->createHydratorFor($fieldClass);
                    $fieldValue = $value;

                    /*if (! is_array($fieldValue)) {
                        throw new ObjectMappingException(
                            sprintf(
                                'Cannot hydrate field "%s" of class "%s" from raw data.'
                                . ' Raw data should be an array but got "%s".', 
                                $mappedFieldName,
                                $fieldClass,
                                is_object($fieldValue) ? get_class($fieldValue) : gettype($fieldValue)
                                )
                        );
                    }   */
                    
                    reset($fieldValue);
                    if (0 !== count($fieldValue) && ! is_numeric(key($fieldValue))) {
                        $fieldRawData = $fieldHydrator->extract($fieldValue);
                        $data[$originalFieldName] = $fieldRawData;                              
                    } else {

                        $fieldRawData = [];
                        foreach ($fieldValue as $itemFieldValue) {              
                            $fieldRawData[] = $fieldHydrator->extract($itemFieldValue);                
                        }
                        $data[$originalFieldName] = $fieldRawData;
                    }   
                } else {
                    $value = $this->extractValue($mappedFieldName, $value, $object, $data);
                    $data[$originalFieldName] = $value;    
                }
            }
        } else {
            list($customHydratorClass, , $customExtractMethod) = $this->metadata->getCustomHydratorInfo();            
            $this->executeMethod($object, new ClassMetadata\Model\Method($customHydratorClass, $customExtractMethod, [$object]));
        }

        //Value objects extraction.
        foreach ($this->metadata->getFieldsWithValueObjects() as $mappedFieldName) {

            if ($this->metadata->isNotManaged($mappedFieldName)) {
                continue;
            }

            $info = $this->metadata->getValueObjectInfo($mappedFieldName);
            list($voClassName, $voResource, $voResourceType) = $info;

            $valueObjectHydrator = $this->objectManager->createHydratorFor($voClassName);
            $objectKey = $this->pushRuntimeConfiguration($mappedFieldName, $object, $voClassName, $voResourceType, $voResource);

            $valueObject = $this->memberAccessStrategy->getValue($object, $mappedFieldName);
            $valueObjectData = $valueObjectHydrator->extract($valueObject, $objectKey);
            $this->popRuntimeConfiguration();

            $data = array_merge($data, $valueObjectData);
        }

        $this->executeMethods($object, $this->metadata->getPostExtractListeners());

        return $data;
    }
524940
protected function isViewGranted($object)
    {
        if ($object instanceof FieldVote) {
            $eventName = ObjectFilterEvents::OBJECT_FIELD_VIEW_GRANTED;
            $event = new ObjectFieldViewGrantedEvent($object);
            $permission = 'perm_read';
        } else {
            $eventName = ObjectFilterEvents::OBJECT_VIEW_GRANTED;
            $event = new ObjectViewGrantedEvent($object);
            $permission = 'perm_view';
        }

        $this->dispatcher->dispatch($eventName, $event);

        if ($event->isSkipAuthorizationChecker()) {
            return $event->isGranted();
        }

        return $this->ac->isGranted($permission, $object);
    }
841308
public function allowUser($permissions, $object, $user = null)
	{
		// if no user is specified, default to the Auth one
		if(is_null($user))
		{
			$user = app('auth')->user();
		}
		
		if(!is_array($permissions))
		{
			$permissions = array($permissions);
		}
		
		foreach($permissions as $permission)
		{
			$this->allowSinglePermission($permission, $object, $user);
		}
	}
1123119
public function extract($object)
    {
        if (!$object instanceof BlockEntityInterface) {
            throw new Exception\InvalidArgumentException(
                '$object must be an instance of PlaygroundCms\Entity\BlockInterface'
            );
        }

        /* @var $object BlockInterface*/
        $data = parent::extract($object);
        //$data = $this->mapField('id', 'block_id', $data);
        return $data;
    }
964486
public function mask($mask = null){
        $mask = $mask !== null ? $mask : $this->mask;
        if(class_exists($mask)){
            return new $mask($this);
        }

        throw new MaskNotFoundException("Unknown mask provided: ".$mask);
    }
397495
public function canRender($object, string $context = null): int
    {
        if ($this->noDirectory) {
            return ChainableRendererInterface::CANNOT_RENDER;
        }
        $fileName = $this->getTemplateFileName($object, $context);

        if ($fileName) {
            return ChainableRendererInterface::CAN_RENDER_CLASS;
        } else {
            return ChainableRendererInterface::CANNOT_RENDER;
        }
    }
121988
private function doMerge($object, array &$visited)
    {
        $oid = spl_object_hash($object);

        if (isset($visited[$oid])) {
            return $visited[$oid];
        }

        $visited[$oid] = $object;

        /** @var DocumentMetadata $class */
        $class = $this->manager->getClassMetadata(get_class($object));
        $managedCopy = $object;

        if (self::STATE_MANAGED !== $this->getDocumentState($object, self::STATE_DETACHED)) {
            $this->manager->initializeObject($object);

            $id = $class->getSingleIdentifier($object);
            $managedCopy = null;

            if (null !== $id) {
                $managedCopy = $this->manager->find($class->name, $id);

                if (null !== $managedCopy && self::STATE_REMOVED === $this->getDocumentState($managedCopy)) {
                    throw new \InvalidArgumentException('Removed document detected during merge.');
                }

                $this->manager->initializeObject($managedCopy);
            }

            if (null === $managedCopy) {
                $managedCopy = $this->newInstance($class);
                if (null !== $id) {
                    $class->setIdentifierValue($managedCopy, $id);
                }

                $this->persistNew($class, $managedCopy);
            }

            foreach ($class->getReflectionClass()->getProperties() as $property) {
                $name = $property->name;
                $property->setAccessible(true);

                if (! isset($class->associationMappings[$name])) {
                    if (! $class->isIdentifier($name)) {
                        $property->setValue($managedCopy, $property->getValue($object));
                    }
                } else {
                    // @todo
                }
            }
        }

        $visited[spl_object_hash($managedCopy)] = $managedCopy;
        $this->cascadeMerge($object, $managedCopy, $visited);

        return $managedCopy;
    }
1167805
public static function mask($value, $mask)
    {
        if (!Int::is($value) || !Int::is($mask)) {
            throw new \InvalidArgumentException("Both parameters must be integers.");
        }

        return ($value & $mask);
    }
841102
public static function parseChartMask($mask)
    {
        $result     = [];
        $arrayParts = explode('|', $mask);
        foreach ($arrayParts as $partOfMask) {
            $arrayLib = explode('~', $partOfMask);
            $result[] = ['size' => (int)$arrayLib[0], 'suffixe' => $arrayLib[1]];
        }

        return $result;
    }